src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
1 / 1
100.0%
Branches:
-
-%
Functions:
1 / 1
100.0%

ProtoSettings.h
Line Branch Exec Source
1 #ifndef PROTO_SETTINGS_H
2 #define PROTO_SETTINGS_H
3 #include <stdint.h>
4 #include <ArduinoJson.h>
5 #include "ProtoSchema.h"
6
7 // Socket protocol 2's settings ops (docs/PROTOCOL.md): the sections that
8 // getSettings and saveSettings name, and what a save's payload becomes. A
9 // save is the settings route's request: its payload, in full names, is what
10 // loop() hands to the settings' own fromJSON(), so the rules stay in one
11 // place. Kept free of the settings and the web server so it can be unit
12 // tested on the PC (pio test -e native).
13
14 enum class settings_section_t : uint8_t {
15 general, // hostname, SSDP and the clock
16 network, // the connection, WiFi, Ethernet and the IP address
17 mqtt,
18 security,
19 radio
20 };
21 // The settings each part of a section belongs to, which loop() saves only
22 // when a field of it was sent.
23 enum class settings_part_t : uint8_t {
24 general, // ConfigSettings: hostname, ssdpBroadcast
25 ntp, // NTPSettings
26 conn, // ConfigSettings: connType
27 wifi, // WifiSettings
28 ethernet, // EthernetSettings
29 ip, // IPSettings
30 mqtt, // MQTTSettings
31 security, // SecuritySettings
32 radio // transceiver_config_t
33 };
34 const char *settingsSectionName(settings_section_t section);
35 // The section that payload d names in section. nullptr when it is good;
36 // otherwise what is wrong with it, for a bad request reply.
37 const char *parseSettingsSection(JsonObjectConst d, settings_section_t &section);
38 // saveSettings: the section d names, and in doc its fields under the names
39 // the route reads. Each is checked against its kind and its range or length,
40 // so nothing is cut short or wraps. An address may be "" to clear it. As
41 // with every op, only what was sent is in it; a field the section doesn't
42 // save, such as hasPassword, is refused. Without hasEthernet the Ethernet
43 // fields are refused too. nullptr when it is good; otherwise what is wrong.
44 const char *expandSettingsPayload(JsonObjectConst d, bool hasEthernet, settings_section_t &section, JsonDocument &doc);
45 // The parts that a save's request (from expandSettingsPayload) sets, as bits
46 // 1 << settings_part_t. A route name such as hostname means another setting
47 // in another section, hence the section.
48 uint16_t settingsParts(settings_section_t section, JsonObjectConst request);
49 2 inline bool settingsSets(uint16_t parts, settings_part_t part) { return parts & (1u << static_cast<uint8_t>(part)); }
50 #endif
51