src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 5
100.0%
Branches:
6 / 6
100.0%
Functions:
2 / 2
100.0%

RollingCode.h
Line Branch Exec Source
1 #ifndef ROLLING_CODE_H
2 #define ROLLING_CODE_H
3 #include <stdint.h>
4
5 // Working out a remote's next rolling code (src/SomfyRemote.cpp) and the one
6 // it goes on with after a load (src/ConfigFile.cpp). Kept free of NVS
7 // so it can be unit tested on the PC (pio test -e native).
8
9 // The code the next frame uses. It is only read here and consumed once the
10 // frame using it has been queued. synced says last matches what is stored for
11 // this address, so the store is only read through loadStored until a code has
12 // been written.
13 template<typename LoadStored>
14 8 inline uint16_t nextRollingCode(bool synced, uint16_t last, LoadStored loadStored) {
15
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 return (uint16_t)((synced ? last : loadStored()) + 1);
16 }
17 // The rolling code a remote goes on with after shades.cfg or a backup is
18 // read. NVS holds the last code sent and shades.cfg the code when it was
19 // saved, so a load keeps the higher. A restore takes the backup's code even
20 // when it is lower. A motor ignores codes below the last one it heard, so
21 // after restoring an older backup to the same device it ignores the remote
22 // until the codes pass that one.
23 4 inline uint16_t rollingCodeAfterLoad(uint16_t stored, uint16_t inFile, bool restoring) {
24
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(restoring) return inFile;
25
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 return stored > inFile ? stored : inFile;
26 }
27 #endif
28