diff --git a/src/arduino-rfm/LoRaMAC.cpp b/src/arduino-rfm/LoRaMAC.cpp index 1ceff08..147b79d 100644 --- a/src/arduino-rfm/LoRaMAC.cpp +++ b/src/arduino-rfm/LoRaMAC.cpp @@ -65,10 +65,10 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command, sLoRa_Session *Session_Data, sLoRa_OTAA *OTAA_Data, sLoRa_Message *Message_Rx, sSettings *LoRa_Settings, msg_t *upMsg_Type) { - static const unsigned int Receive_Delay_1 = 1000; - static const unsigned int Receive_Delay_2 = 2000; // Receive_Delay_2 >= Receive_Delay_1 + RX1_Window - static const unsigned int RX1_Window = 1000; - static const unsigned int RX2_Window = 1000; + static const unsigned int Receive_Delay_1 = LoRa_Settings->Rx1_Delay; + static const unsigned int Receive_Delay_2 = LoRa_Settings->Rx2_Delay; + static const unsigned int RX1_Window = LoRa_Settings->RX1_Window; + static const unsigned int RX2_Window = LoRa_Settings->RX2_Window; unsigned long prevTime = 0; unsigned char rx1_ch = LoRa_Settings->Channel_Rx; diff --git a/src/arduino-rfm/Struct.h b/src/arduino-rfm/Struct.h index c2d4fdb..330c063 100644 --- a/src/arduino-rfm/Struct.h +++ b/src/arduino-rfm/Struct.h @@ -85,15 +85,19 @@ typedef struct{ //Struct used for storing settings of the mote typedef struct { - unsigned char Confirm; //0x00 Unconfirmed, 0x01 Confirmed - unsigned char Mport; //Port 1-223 - unsigned char Mote_Class; //0x00 Class A, 0x01 Class C - unsigned char Datarate_Tx; //See RFM file - unsigned char Datarate_Rx; //See RFM file - unsigned char Channel_Tx; //See RFM file - unsigned char Channel_Rx; //See RFM filed - unsigned char Channel_Hopping; //0x00 No hopping, 0x01 Hopping - unsigned char Transmit_Power; //0x00 to 0x0F + unsigned char Confirm; //0x00 Unconfirmed, 0x01 Confirmed + unsigned char Mport; //Port 1-223 + unsigned char Mote_Class; //0x00 Class A, 0x01 Class C + unsigned char Datarate_Tx; //See RFM file + unsigned char Datarate_Rx; //See RFM file + unsigned char Channel_Tx; //See RFM file + unsigned char Channel_Rx; //See RFM filed + unsigned char Channel_Hopping; //0x00 No hopping, 0x01 Hopping + unsigned char Transmit_Power; //0x00 to 0x0F + unsigned int Rx1_Delay; + unsigned int Rx2_Delay; // Rx2_Delay >= Rx1_Delay + RX1_Window + unsigned int RX1_Window; + unsigned int RX2_Window; } sSettings; typedef enum { diff --git a/src/arduino-rfm/lorawan-arduino-rfm.cpp b/src/arduino-rfm/lorawan-arduino-rfm.cpp index 57b60b4..eee2682 100644 --- a/src/arduino-rfm/lorawan-arduino-rfm.cpp +++ b/src/arduino-rfm/lorawan-arduino-rfm.cpp @@ -111,6 +111,12 @@ bool LoRaWANClass::init(void) LoRa_Settings.Confirm = 0x00; //0x00 unconfirmed, 0x01 confirmed LoRa_Settings.Channel_Hopping = 0x00; //0x00 no channel hopping, 0x01 channel hopping + // Set default rx delay and window + LoRa_Settings.Rx1_Delay = 1000; // Thing stack seems to be 5000 ms (so Rx2_delay 6000 ms) + LoRa_Settings.Rx2_Delay = 2000; // Rx2_Delay >= Rx1_Delay + RX1_Window + LoRa_Settings.RX1_Window = 1000; + LoRa_Settings.RX2_Window = 1000; + // Initialise buffer for data to transmit memset(Data_Tx, 0x00, sizeof(Data_Tx)); Buffer_Tx.Data = Data_Tx; @@ -399,6 +405,7 @@ unsigned char LoRaWANClass::getDataRate() { return LoRa_Settings.Datarate_Tx; } + void LoRaWANClass::setTxPower1(unsigned char power_idx) { unsigned char RFM_Data; @@ -407,6 +414,28 @@ void LoRaWANClass::setTxPower1(unsigned char power_idx) RFM_Write(RFM_REG_PA_CONFIG, RFM_Data); } +void LoRaWANClass::setRx1Delay(unsigned int ms) +{ + LoRa_Settings.Rx1_Delay = ms; + LoRa_Settings.Rx2_Delay = max(LoRa_Settings.Rx2_Delay,LoRa_Settings.Rx1_Delay + LoRa_Settings.RX1_Window); +} + +void LoRaWANClass::setRx2Delay(unsigned int ms) +{ + LoRa_Settings.Rx2_Delay = max(ms,LoRa_Settings.Rx1_Delay + LoRa_Settings.RX1_Window); +} + +void LoRaWANClass::setRx1Window(unsigned int ms) +{ + LoRa_Settings.RX1_Window = ms; + LoRa_Settings.Rx2_Delay = max(LoRa_Settings.Rx2_Delay,LoRa_Settings.Rx1_Delay + LoRa_Settings.RX1_Window); +} + +void LoRaWANClass::setRx2Window(unsigned int ms) +{ + LoRa_Settings.RX2_Window = ms; +} + int LoRaWANClass::readData(char *outBuff) { int res = 0; diff --git a/src/arduino-rfm/lorawan-arduino-rfm.h b/src/arduino-rfm/lorawan-arduino-rfm.h index 0d92054..b738312 100644 --- a/src/arduino-rfm/lorawan-arduino-rfm.h +++ b/src/arduino-rfm/lorawan-arduino-rfm.h @@ -79,6 +79,10 @@ class LoRaWANClass unsigned char getDataRate(); void setTxPower1(unsigned char power_idx); void setTxPower(int level, txPin_t pinTx); + void setRx1Delay(unsigned int ms); + void setRx2Delay(unsigned int ms); + void setRx1Window(unsigned int ms); + void setRx2Window(unsigned int ms); int getRssi(); int readData(char *outBuff); bool readAck(void);