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

ConfigHeader.h
Line Branch Exec Source
1 #ifndef CONFIG_HEADER_H
2 #define CONFIG_HEADER_H
3 #include <stdint.h>
4
5 // The header of a shades.cfg file: its version and how many records of each
6 // kind follow, and their sizes. Kept free of the file system so it can be
7 // unit tested on the PC (pio test -e native).
8 struct config_header_t {
9 uint8_t version = 1;
10 uint8_t repeaterRecords = 0;
11 uint8_t repeaterRecordSize = 0;
12 uint8_t roomRecords = 0;
13 uint16_t roomRecordSize = 0;
14 uint16_t shadeRecordSize = 0;
15 uint8_t shadeRecords = 0;
16 uint16_t groupRecordSize = 0;
17 uint8_t groupRecords = 0;
18 uint16_t settingsRecordSize = 0;
19 uint16_t netRecordSize = 0;
20 uint16_t transRecordSize = 0;
21 char serverId[10] = ""; // This must match the server id size in the ConfigSettings.
22 int8_t length = 0;
23 };
24
25 // The bytes of the shade model's records, which follow the header in this
26 // order: rooms, shades, groups. A restore that leaves the shades out skips
27 // this many bytes.
28 5 inline uint32_t shadeModelBytes(const config_header_t &header) {
29 5 return static_cast<uint32_t>(header.roomRecords) * header.roomRecordSize
30 5 + static_cast<uint32_t>(header.shadeRecords) * header.shadeRecordSize
31 5 + static_cast<uint32_t>(header.groupRecords) * header.groupRecordSize;
32 }
33 // The file size the header adds up to, counting only the records its version
34 // has. Backups written before the transceiver record's size was corrected
35 // declare it 6 bytes short, so a mismatch alone doesn't make a file invalid.
36 7 inline uint32_t expectedFileBytes(const config_header_t &header) {
37 7 uint32_t bytes = static_cast<uint32_t>(header.length)
38 7 + static_cast<uint32_t>(header.shadeRecords) * header.shadeRecordSize;
39
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 time.
7 if(header.version > 10) bytes += static_cast<uint32_t>(header.groupRecords) * header.groupRecordSize;
40
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 if(header.version >= 19) bytes += static_cast<uint32_t>(header.roomRecords) * header.roomRecordSize;
41
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 if(header.version > 13) bytes += header.settingsRecordSize + header.netRecordSize + header.transRecordSize;
42
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 if(header.version >= 21) bytes += static_cast<uint32_t>(header.repeaterRecords) * header.repeaterRecordSize;
43 7 return bytes;
44 }
45 #endif
46