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