kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Reset the LoRaWAN state when new AppKey supplied
rodzic
d224f7a6a7
commit
65def379fc
|
@ -63,12 +63,14 @@ void app_main(void)
|
|||
}
|
||||
#endif
|
||||
#ifdef WITH_LORAWAN
|
||||
WANdev.Reset(getUniqueID(), Parameters.AppKey); // set default LoRaWAN config.
|
||||
if(WANdev.ReadFromNVS()!=ESP_OK) // if can't read the LoRaWAN setup from NVS
|
||||
{ WANdev.WriteToNVS(); } // then store the default
|
||||
if( /* WANdev.State<2 && */ memcmp(WANdev.AppKey, Parameters.AppKey, 16)) // if LoRaWAN key different from the one in Parameters
|
||||
{ WANdev.Reset(getUniqueID(), Parameters.AppKey); // then reset LoRaWAN to this key
|
||||
WANdev.WriteToNVS(); } // and save LoRaWAN config. to NVS
|
||||
WANdev.Reset(getUniqueID(), Parameters.AppKey); // set default LoRaWAN config.
|
||||
if(WANdev.ReadFromNVS()!=ESP_OK) // if can't read the LoRaWAN setup from NVS
|
||||
{ WANdev.WriteToNVS(); } // then store the default
|
||||
if(Parameters.hasAppKey())
|
||||
{ if(!Parameters.sameAppKey(WANdev.AppKey)) // if LoRaWAN key different from the one in Parameters
|
||||
{ WANdev.Reset(getUniqueID(), Parameters.AppKey); // then reset LoRaWAN to this key
|
||||
WANdev.WriteToNVS(); } // and save LoRaWAN config. to NVS
|
||||
Parameters.clrAppKey(); }
|
||||
#endif
|
||||
|
||||
CONS_UART_SetBaudrate(Parameters.CONbaud);
|
||||
|
|
|
@ -156,6 +156,19 @@ class FlashParameters
|
|||
|
||||
static const uint32_t CheckInit = 0x89ABCDEF;
|
||||
|
||||
#ifdef WITH_LORAWAN
|
||||
bool hasAppKey(void) const
|
||||
{ uint8_t Sum=AppKey[0];
|
||||
for(int Idx=1; Idx<16; Idx++)
|
||||
{ if(Sum!=0) break;
|
||||
Sum|=AppKey[Idx]; }
|
||||
return Sum!=0; }
|
||||
|
||||
void clrAppKey(void) { for(int Idx=0; Idx<16; Idx++) AppKey[Idx]=0; }
|
||||
void cpyAppKey(uint8_t *Key) { memcpy(Key, AppKey, 16); }
|
||||
bool sameAppKey(const uint8_t *RefKey) const { return memcmp(AppKey, RefKey, 16)==0; }
|
||||
#endif
|
||||
|
||||
uint32_t static calcCheckSum(volatile uint32_t *Word, uint32_t Words) // calculate check-sum of pointed data
|
||||
{ uint32_t Check=CheckInit;
|
||||
for(uint32_t Idx=0; Idx<Words; Idx++)
|
||||
|
@ -209,7 +222,7 @@ class FlashParameters
|
|||
FreqPlan = DEFAULT_FreqPlan; // [0..5]
|
||||
PPSdelay = DEFAULT_PPSdelay; // [ms]
|
||||
#ifdef WITH_LORAWAN
|
||||
for(uint8_t Idx=0; Idx<16; Idx++) AppKey[Idx]=0;
|
||||
clrAppKey();
|
||||
#endif
|
||||
#ifdef WITH_ENCRYPT
|
||||
for(uint8_t Idx=0; Idx<4; Idx++) EncryptKey[Idx]=0;
|
||||
|
|
Ładowanie…
Reference in New Issue