LoRa node acquiring random float value and sending to LoRa Server - Working ok
Fork of SX1276GenericLib by
Diff: sx1276/sx1276.cpp
- Revision:
- 55:00c1f5b83920
- Parent:
- 54:0d8ea87fbab9
- Child:
- 56:4fddac05ac07
--- a/sx1276/sx1276.cpp Fri May 19 11:50:12 2017 +0200 +++ b/sx1276/sx1276.cpp Fri May 19 15:55:19 2017 +0200 @@ -23,7 +23,7 @@ -const FskBandwidth_t SX1276::FskBandwidths[] = +const SX1276::BandwidthMap SX1276::FskBandwidths[] = { { 2600 , 0x17 }, { 3100 , 0x0F }, @@ -49,6 +49,21 @@ { 300000, 0x00 }, // Invalid Bandwidth }; +const SX1276::BandwidthMap SX1276::LoRaBandwidths[] = +{ + { 7800, 0 }, // 7.8 kHz requires TCXO + { 10400, 1 }, // 10.4 kHz requires TCXO + { 15600, 2 }, // 15.6 kHz requires TCXO + { 20800, 3 }, // 20.8 kHz requires TCXO + { 31200, 4 }, // 31.2 kHz requires TCXO + { 41400, 5 }, // 41.4 kHz requires TCXO + { 62500, 6 }, // 62.5 kHz requires TCXO + { 125000, 7 }, // the LoRa protocol default + { 250000, 8 }, + { 250000, 9 }, + { 0 , 10 }, // Invalid Bandwidth, reserved + }; + /*! @@ -57,7 +72,7 @@ * @remark Can be automatically generated by the SX1276 GUI (not yet implemented) */ -const RadioRegisters_t SX1276::RadioRegsInit[] = { +const SX1276::RadioRegisters SX1276::RadioRegsInit[] = { { MODEM_FSK , REG_LNA , 0x23 }, { MODEM_FSK , REG_RXCONFIG , 0x1E }, { MODEM_FSK , REG_RSSICONFIG , 0xD2 }, @@ -116,7 +131,7 @@ void SX1276::RadioRegistersInit( ) { uint8_t i = 0; - for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ ) + for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters ); i++ ) { SetModem( RadioRegsInit[i].Modem ); Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value ); @@ -246,7 +261,7 @@ { uint8_t i; - for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( FskBandwidth_t ) ) - 1; i++ ) + for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( BandwidthMap ) ) - 1; i++ ) { if( ( bandwidth >= FskBandwidths[i].bandwidth ) && ( bandwidth < FskBandwidths[i + 1].bandwidth ) ) { @@ -257,6 +272,27 @@ while( 1 ); } +/*! + * Returns the known LoRa bandwidth registers value + * + * \param [IN] bandwidth Bandwidth value in Hz + * \retval regValue Bandwidth register value. + */ +uint8_t SX1276::GetLoRaBandwidthRegValue( uint32_t bandwidth ) +{ + uint8_t i; + + for( i = 0; i < ( sizeof( LoRaBandwidths ) / sizeof( BandwidthMap ) ) - 1; i++ ) + { + if( ( bandwidth >= LoRaBandwidths[i].bandwidth ) && ( bandwidth < LoRaBandwidths[i + 1].bandwidth ) ) + { + return LoRaBandwidths[i].RegValue; + } + } + // ERROR: Value not found + while( 1 ); +} + void SX1276::SetRxConfig( RadioModems_t modem, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, @@ -313,6 +349,7 @@ break; case MODEM_LORA: { + bandwidth = GetLoRaBandwidthRegValue(bandwidth); if( bandwidth > LORA_BANKWIDTH_500kHz ) { // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported @@ -473,6 +510,7 @@ case MODEM_LORA: { this->settings.LoRa.Power = power; + bandwidth = GetLoRaBandwidthRegValue(bandwidth); if( bandwidth > LORA_BANKWIDTH_500kHz ) { // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported