Beaconmode FrameCounter Persistance Fix Part 2

This commit is contained in:
seiichiro 2020-04-21 21:39:34 +02:00
parent a37dba6ae9
commit f338cce56d

View file

@ -170,15 +170,11 @@ void setup()
// Get the Last Saved (=Highest) Frame Counter
uint16_t Frame_Counter_Sv = 0x00000000;
uint8_t eeprom_addr = 0x0000;
bool value_found = 0;
EEPROM.get(eeprom_addr, Frame_Counter_Sv);
while (eeprom_addr < 32*sizeof(Frame_Counter_Tx)) {
if (Frame_Counter_Sv != 0x0000)
value_found = 1;
if (Frame_Counter_Sv > Frame_Counter_Tx) {
Frame_Counter_Tx = Frame_Counter_Sv;
} else {
if (value_found)
break;
}
eeprom_addr += sizeof(Frame_Counter_Tx);
@ -253,17 +249,17 @@ void loop()
unsigned char Frame_Port =0x07;
for (int i = SF7BW125; i<=SF12BW125; i++) {
lora_data tdata = data;
lora.Send_Data((unsigned char *)&tdata, sizeof(tdata), Frame_Counter_Tx, static_cast<lora_dr>(i), Frame_Port);
Frame_Counter_Tx++;
// Some FrameCounter Trickery to not write the value to EEPROM 6 Times but still have a working WearLeveling
lora.Send_Data((unsigned char *)&tdata, sizeof(tdata), i+(Frame_Counter_Tx*6), static_cast<lora_dr>(i), Frame_Port);
Frame_Port++;
delay(25);
}
#else
// Send LoRa Packet, Increment Frame Counter
lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01);
Frame_Counter_Tx++;
#endif
// Save the next FrameCounter to EEPROM
Frame_Counter_Tx++;
EEPROM.put(calcEepromAddr(Frame_Counter_Tx), Frame_Counter_Tx);
#endif