async rx mode

This commit is contained in:
Pawel Spychalski (DzikuVx)
2017-12-17 09:33:04 +01:00
parent a7c2e13b10
commit e8f1976a2d
3 changed files with 28 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
#define DEVICE_MODE_TX
// #define DEVICE_MODE_RX
#define FEATURE_TX_OLED
// #define FEATURE_TX_OLED
// #define FORCE_TX_WITHOUT_INPUT
// #define DEBUG_SERIAL
@@ -168,6 +168,7 @@ void setup(void)
//Setup ISR callback and start receiving
LoRa.onReceive(onReceive);
LoRa.receive();
radioState.deviceState = RADIO_STATE_RX;
#ifdef DEVICE_MODE_RX
//initiallize default ppm values
@@ -261,9 +262,23 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) {
}
#endif
/*
*
* Main loop starts here!
*
*/
void loop(void)
{
/*
* Detect the moment when radio module stopped transmittig and put it
* back in to receive state
*/
if (radioState.deviceState == RADIO_STATE_TX && !LoRa.isTransmitting()) {
LoRa.receive();
radioState.deviceState = RADIO_STATE_RX;
}
if (radioState.bytesToRead != NO_DATA_TO_READ) {
LoRa.read(tmpBuffer, radioState.bytesToRead);
@@ -277,6 +292,7 @@ void loop(void)
//After reading, flush radio buffer, we have no need for whatever might be over there
LoRa.sleep();
LoRa.receive();
radioState.deviceState = RADIO_STATE_RX;
radioState.bytesToRead = NO_DATA_TO_READ;
}
@@ -404,9 +420,11 @@ void loop(void)
qspEncodeFrame(&qsp, tmpBuffer, &size);
//Sent it to radio in one SPI transaction
LoRa.write(tmpBuffer, size);
LoRa.endPacket();
//After ending packet, put device into receive mode again
LoRa.receive();
LoRa.endPacketAsync();
//Set state to be able to detect the moment when TX is done
radioState.deviceState = RADIO_STATE_TX;
transmitPayload = false;
}
@@ -515,6 +533,7 @@ void onReceive(int packetSize)
*/
LoRa.sleep();
LoRa.receive();
radioState.deviceState = RADIO_STATE_RX;
}
}
}

2
lora.h
View File

@@ -27,7 +27,7 @@ public:
int endPacket();
void endPacketAsync();
bool isTransmitting()
bool isTransmitting();
int parsePacket(int size = 0);
int packetRssi();

View File

@@ -74,6 +74,9 @@ enum debugConfigFlags {
#define NO_DATA_TO_READ -1
#define RADIO_STATE_TX 1
#define RADIO_STATE_RX 2
struct RadioState_t {
uint32_t frequency = 867000000;
uint32_t loraBandwidth = 250000;
@@ -83,6 +86,7 @@ struct RadioState_t {
int8_t bytesToRead = -1;
uint8_t rssi = 0;
uint8_t snr = 0;
uint8_t deviceState = RADIO_STATE_RX;
};
struct TxDeviceState_t {