Skip to content

Commit

Permalink
Merge pull request #170 from capboyaryan/in_865
Browse files Browse the repository at this point in the history
Adding support for IN_865
  • Loading branch information
wero1414 authored Aug 30, 2023
2 parents 82da458 + 77536c9 commit b69410f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/arduino-rfm/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
//#define EU_868
//#define US_915
//#define AU_915
#define IN_865

// Define max payload size used for this node
#define MAX_UPLINK_PAYLOAD_SIZE 220
#define MAX_DOWNLINK_PAYLOAD_SIZE 220

#if !defined(AS_923) && !defined(AS_923_2) && !defined(EU_868) && !defined(US_915) && !defined(AU_915)
#if !defined(AS_923) && !defined(AS_923_2) && !defined(EU_868) && !defined(US_915) && !defined(AU_915) &&!defined(IN_865)
#define US_915 // Define default Region
#endif

Expand Down
11 changes: 11 additions & 0 deletions src/arduino-rfm/LoRaMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command,
unsigned char rx1_dr = LoRa_Settings->Datarate_Tx+10;
#elif defined(EU_868)
unsigned char rx1_dr = LoRa_Settings->Datarate_Tx;
#elif defined(IN_865)
unsigned char rx1_dr = LoRa_Settings->Datarate_Tx;
#else // AS_923 and AS_923_2
unsigned char rx1_dr = LoRa_Settings->Datarate_Tx;
#endif
Expand All @@ -103,6 +105,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command,
#elif defined(EU_868)
LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 923.3 MHZ
LoRa_Settings->Datarate_Rx = SF12BW125; //set RX2 datarate 12
#elif defined(IN_865)
LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 866.550 MHZ
LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10
#elif defined(AS_923) || defined(AS_923_2)
LoRa_Settings->Channel_Rx = 0x00; // set Rx2 channel 923.2 (AS_923) or 921.4 (AS_923_2)
LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10
Expand Down Expand Up @@ -141,6 +146,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command,
#elif defined(EU_868)
LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 923.3 MHZ
LoRa_Settings->Datarate_Rx = SF12BW125; //set RX2 datarate 12
#elif defined(IN_865)
LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 866.550 MHZ
LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10
#elif defined(AS_923) || defined(AS_923_2)
LoRa_Settings->Channel_Rx = 0x00; // set Rx2 channel 923.2 (AS_923) or 921.4 (AS_923_2)
LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10
Expand All @@ -166,6 +174,9 @@ void LORA_Cycle(sBuffer *Data_Tx, sBuffer *Data_Rx, RFM_command_t *RFM_Command,
#elif defined(EU_868)
LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 923.3 MHZ
LoRa_Settings->Datarate_Rx = SF12BW125; //set RX2 datarate 12
#elif defined(IN_865)
LoRa_Settings->Channel_Rx = CHRX2; // set Rx2 channel 866.550 MHZ
LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10
#elif defined(AS_923) || defined(AS_923_2)
LoRa_Settings->Channel_Rx = 0x00; // set Rx2 channel 923.2 (AS_923) or 921.4 (AS_923_2)
LoRa_Settings->Datarate_Rx = SF10BW125; //set RX2 datarate 10
Expand Down
39 changes: 37 additions & 2 deletions src/arduino-rfm/RFM95.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@
{ 0xD8, 0xF9, 0xBE }, //Channel [7], 867.9 MHz / 61.035 Hz = 14219710 = 0xD8F9BE
{ 0xD9, 0x61, 0xBE }, // RX2 Receive channel 869.525 MHz / 61.035 Hz = 14246334 = 0xD961BE
};
#elif defined(IN_865)
static const PROGMEM unsigned char LoRa_Frequency[4][3] = {
{ 0xD8, 0x44, 0x24 }, //Channel [0], 865.0625 MHz / 61.035 Hz = 14173220 = 0xD84424
{ 0xD8, 0x59, 0xE7 }, //Channel [1], 865.4025 MHz / 61.035 Hz = 14178791 = 0xD859E7
{ 0xD8, 0x7F, 0x2F }, //Channel [2], 865.9850 MHz / 61.035 Hz = 14188335 = 0xD87F2F
{ 0xD8, 0xA3, 0x58 }, // RX2 Receive channel 866.550 MHz / 61.035 Hz = 14197592 = 0xD8A358
};
#endif

/*
Expand Down Expand Up @@ -326,7 +333,7 @@ static void RFM_change_SF_BW(unsigned char _SF, unsigned char _BW)
RFM_Write(RFM_REG_MODEM_CONFIG2, (_SF << 4) | 0b0100); //SFx CRC On
RFM_Write(RFM_REG_MODEM_CONFIG1,(_BW << 4) | 0x02); //x kHz 4/5 coding rate explicit header mode

#ifdef EU_868
#if defined(EU_868) || defined(IN_865)
if(_SF>10)
RFM_Write(RFM_REG_MODEM_CONFIG3, 0b1100); //Low datarate optimization on AGC auto on
else
Expand Down Expand Up @@ -418,6 +425,27 @@ static void RFM_Change_Datarate(unsigned char Datarate)
RFM_change_SF_BW(7,0x09);
break;
}
#elif defined(IN_865)
switch (Datarate) {
case 0x00: // SF12BW125
RFM_change_SF_BW(12,0x07);
break;
case 0x01: // SF11BW125
RFM_change_SF_BW(11,0x07);
break;
case 0x02: // SF10BW125
RFM_change_SF_BW(10,0x07);
break;
case 0x03: // SF9BW125
RFM_change_SF_BW(9,0x07);
break;
case 0x04: // SF8BW125
RFM_change_SF_BW(8,0x07);
break;
case 0x05: // SF7BW125
RFM_change_SF_BW(7,0x07);
break;
}
#else //EU_868 or AS_923 or AS_923_2
switch (Datarate) {
case 0x00: // SF12BW125
Expand Down Expand Up @@ -466,6 +494,10 @@ static void RFM_Change_Channel(unsigned char Channel)
if (Channel <= 0x08)
for(unsigned char i = 0 ; i < 3 ; ++i)
RFM_Write(RFM_REG_FR_MSB + i, pgm_read_byte(&(LoRa_Frequency[Channel][i])));
#elif defined(IN_865)
if( Channel <= 0x03)
for(unsigned char i = 0 ; i < 3 ; ++i)
RFM_Write(RFM_REG_FR_MSB + i, pgm_read_byte(&(LoRa_Frequency[Channel][i])));
#else //US915 or AU_915
if (Channel <= 0x07)
for(unsigned char i = 0 ; i < 3 ; ++i)
Expand Down Expand Up @@ -711,9 +743,12 @@ void RFM_Continuous_Receive(sSettings *LoRa_Settings)

//Change Datarate and channel.
// This depends on regional parameters
#ifdef EU_868
#if defined(EU_868)
RFM_Change_Datarate(SF12BW125);
RFM_Change_Channel(CHRX2);
#elif defined(IN_865)
RFM_Change_Datarate(SF10BW125);
RFM_Change_Channel(CHRX2);
#else
//Datarate for downlink should be 8 but testing on 10
//LoRa_Settings->Datarate_Rx=10;
Expand Down
11 changes: 11 additions & 0 deletions src/arduino-rfm/Struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,17 @@ typedef enum {
CH0 = 0,
CH1 = 1,
CH2 = 2,
#ifndef IN_865 //IN_865 only supports 3 channels
CH3 = 3,
CH4 = 4,
CH5 = 5,
CH6 = 6,
CH7 = 7,
#endif
#ifdef EU_868
CHRX2 = 8,
#elif defined(IN_865)
CHRX2 = 3,
#else
CH8 = 8,
#endif
Expand Down Expand Up @@ -158,6 +162,13 @@ typedef enum {
SF8BW125 = 0x04,
SF7BW125 = 0x05,
SF7BW250 = 0x06
#elif defined(IN_865)
SF12BW125 = 0x00,
SF11BW125 = 0x01,
SF10BW125 = 0x02,
SF9BW125 = 0x03,
SF8BW125 = 0x04,
SF7BW125 = 0x05
#endif
} dataRates_t;

Expand Down
7 changes: 7 additions & 0 deletions src/arduino-rfm/lorawan-arduino-rfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ bool LoRaWANClass::init(void)
LoRa_Settings.Datarate_Rx = 0x02; //set to SF10 BW 125 kHz
#elif defined(EU_868)
LoRa_Settings.Datarate_Rx = 0x03; //set to SF9 BW 125 kHz
#elif defined(IN_865)
LoRa_Settings.Datarate_Rx = 0x02; //set to SF10 BW 125 kHz
#else //US_915 or AU_915
LoRa_Settings.Datarate_Rx = 0x0C; //set to SF8 BW 500 kHz
#endif
Expand Down Expand Up @@ -347,6 +349,8 @@ void LoRaWANClass::setChannel(unsigned char channel)
LoRa_Settings.Channel_Rx = channel + 0x08;
#elif defined(EU_868)
LoRa_Settings.Channel_Rx = channel;
#elif defined(IN_865)
LoRa_Settings.Channel_Rx = channel;
#elif defined(AS_923) || defined(AS_923_2)
LoRa_Settings.Channel_Rx = channel;
#endif
Expand Down Expand Up @@ -468,6 +472,9 @@ void LoRaWANClass::randomChannel()
#elif defined(EU_868)
freq_idx = random(0,8);
LoRa_Settings.Channel_Rx=freq_idx; // same rx and tx channel
#elif defined(IN_865)
freq_idx = random(0,3);
LoRa_Settings.Channel_Rx=freq_idx; // same rx and tx channel
#else // US_915 or AU_915
freq_idx = random(0, 8);
LoRa_Settings.Channel_Rx = freq_idx + 0x08;
Expand Down

0 comments on commit b69410f

Please sign in to comment.