mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-11-20 15:52:12 +01:00
- A group in a backup from before version 23 has no rolling code, and a restore wrote 0 to NVS for it. It keeps the code NVS has. - A restore reads each record into one that starts as the shade, group or settings it replaces, so what an older version lacks stays as it was (the update check below version 20 among them), as before. - restoreFile and loadFile read the rooms, shades and groups through one readModel(); the settings, network and radio are applied by helpers. - The shade's tilt is forgotten where the shades are written, not in the conversion to a record. - rollingCodeAfterLoad moves to RollingCode.h and its tests to test_rollingcode. - The topics a deleted shade or group clears are one list each (MqttTopics.h), tested against what is published. - e2e: a restore of the shades brings back every shade and group, and the README has the rollback check by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
1.3 KiB
C++
27 lines
1.3 KiB
C++
#ifndef ROLLING_CODE_H
|
|
#define ROLLING_CODE_H
|
|
#include <stdint.h>
|
|
|
|
// Working out a remote's next rolling code (src/SomfyRemote.cpp) and the one
|
|
// it goes on with after a load (src/ConfigFile.cpp). Kept free of NVS
|
|
// so it can be unit tested on the PC (pio test -e native).
|
|
|
|
// The code the next frame uses. It is only read here and consumed once the
|
|
// frame using it has been queued. synced says last matches what is stored for
|
|
// this address, so the store is only read through loadStored until a code has
|
|
// been written.
|
|
template<typename LoadStored>
|
|
inline uint16_t nextRollingCode(bool synced, uint16_t last, LoadStored loadStored) {
|
|
return (uint16_t)((synced ? last : loadStored()) + 1);
|
|
}
|
|
// The rolling code a remote goes on with after shades.cfg or a backup is
|
|
// read. NVS holds the last code sent and shades.cfg the code when it was
|
|
// saved, so a load keeps the higher. A restore takes the backup's code even
|
|
// when it is lower. A motor ignores codes below the last one it heard, so
|
|
// after restoring an older backup to the same device it ignores the remote
|
|
// until the codes pass that one.
|
|
inline uint16_t rollingCodeAfterLoad(uint16_t stored, uint16_t inFile, bool restoring) {
|
|
if(restoring) return inFile;
|
|
return stored > inFile ? stored : inFile;
|
|
}
|
|
#endif
|