Skip to content

Commit

Permalink
Merge pull request #190 from sacua/CustomRxDelay
Browse files Browse the repository at this point in the history
Custom Rx Delay and Window
  • Loading branch information
REGIOIGER authored May 2, 2024
2 parents 5309766 + 19e53db commit d6a83ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/arduino-rfm/LoRaMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 13 additions & 9 deletions src/arduino-rfm/Struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions src/arduino-rfm/lorawan-arduino-rfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -399,6 +405,7 @@ unsigned char LoRaWANClass::getDataRate()
{
return LoRa_Settings.Datarate_Tx;
}

void LoRaWANClass::setTxPower1(unsigned char power_idx)
{
unsigned char RFM_Data;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/arduino-rfm/lorawan-arduino-rfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d6a83ea

Please sign in to comment.