supla-device
Loading...
Searching...
No Matches
config.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_STORAGE_CONFIG_H_
20#define SRC_SUPLA_STORAGE_CONFIG_H_
21
22#include <stddef.h>
23#include <stdint.h>
24
25#include "storage.h"
26
27#define SUPLA_CONFIG_MAX_KEY_SIZE 16
28
29#define MAX_SSID_SIZE 33 // actual SSID should be at most 32 bytes
30 // but we add here extra byte for null
31 // termination
32#define MAX_WIFI_PASSWORD_SIZE 64
33#define MQTT_CLIENTID_MAX_SIZE 23
34#define MQTT_USERNAME_MAX_SIZE 256
35#define MQTT_PASSWORD_MAX_SIZE 256
36
37namespace Supla {
38
39enum DeviceMode : uint8_t {
40 DEVICE_MODE_NOT_SET = 0,
41 DEVICE_MODE_TEST = 1,
42 DEVICE_MODE_NORMAL = 2,
43 DEVICE_MODE_CONFIG = 3,
44 DEVICE_MODE_SW_UPDATE = 4
45};
46
47class Config {
48 public:
49 Config();
50 virtual ~Config();
51 virtual bool init() = 0;
52 virtual void removeAll() = 0;
53 virtual bool isMinimalConfigReady(bool showLogs = true);
54 virtual bool isConfigModeSupported();
55
56 // Override this method and setup all default value if needed
57 virtual void initDefaultDeviceConfig();
58
59 // Generic getters and setters
60 virtual bool setString(const char* key, const char* value) = 0;
61 virtual bool getString(const char* key, char* value, size_t maxSize) = 0;
62 virtual int getStringSize(const char* key) = 0;
63
64 virtual bool setBlob(const char* key, const char* value, size_t blobSize) = 0;
65 virtual bool getBlob(const char* key, char* value, size_t blobSize) = 0;
66
67 virtual bool getInt8(const char* key, int8_t* result) = 0;
68 virtual bool getUInt8(const char* key, uint8_t* result) = 0;
69 virtual bool getInt32(const char* key, int32_t* result) = 0;
70 virtual bool getUInt32(const char* key, uint32_t* result) = 0;
71
72 virtual bool setInt8(const char* key, const int8_t value) = 0;
73 virtual bool setUInt8(const char* key, const uint8_t value) = 0;
74 virtual bool setInt32(const char* key, const int32_t value) = 0;
75 virtual bool setUInt32(const char* key, const uint32_t value) = 0;
76 virtual bool eraseKey(const char* key) = 0;
77
78 static void generateKey(char *, int, const char *);
79
80 virtual void commit();
81 virtual void saveWithDelay(uint32_t delayMs);
82 virtual void saveIfNeeded();
83
84 // Device generic config
85 virtual bool generateGuidAndAuthkey();
86 virtual bool setDeviceName(const char* name);
87 virtual bool setDeviceMode(enum Supla::DeviceMode mode);
88 virtual bool setGUID(const char* guid);
89 virtual bool getDeviceName(char* result);
90 virtual enum Supla::DeviceMode getDeviceMode();
91 virtual bool getGUID(char* result);
92 virtual bool getSwUpdateServer(char* url);
93 virtual bool isSwUpdateBeta();
94 virtual bool setSwUpdateServer(const char* url);
95 virtual bool setSwUpdateBeta(bool enabled);
96 virtual bool getCustomCA(char* result, int maxSize);
97 virtual int getCustomCASize();
98 virtual bool setCustomCA(const char* customCA);
99
100 // Supla protocol config
101 virtual bool setSuplaCommProtocolEnabled(bool enabled);
102 virtual bool setSuplaServer(const char* server);
103 virtual bool setSuplaServerPort(int32_t port);
104 virtual bool setEmail(const char* email);
105 virtual bool setAuthKey(const char* authkey);
106 virtual bool isSuplaCommProtocolEnabled();
107 virtual bool getSuplaServer(char* result);
108 virtual int32_t getSuplaServerPort();
109 virtual bool getEmail(char* result);
110 virtual bool getAuthKey(char* result);
111
112 // MQTT protocol config
113 virtual bool setMqttCommProtocolEnabled(bool enabled);
114 virtual bool setMqttServer(const char* server);
115 virtual bool setMqttServerPort(int32_t port);
116 virtual bool setMqttUser(const char* user);
117 virtual bool setMqttPassword(const char* password);
118 virtual bool setMqttQos(int32_t qos);
119 virtual bool isMqttCommProtocolEnabled();
120 virtual bool setMqttTlsEnabled(bool enabled);
121 virtual bool isMqttTlsEnabled();
122 virtual bool setMqttAuthEnabled(bool enabled);
123 virtual bool isMqttAuthEnabled();
124 virtual bool setMqttRetainEnabled(bool enabled);
125 virtual bool isMqttRetainEnabled();
126 virtual bool getMqttServer(char* result);
127 virtual int32_t getMqttServerPort();
128 virtual bool getMqttUser(char* result);
129 virtual bool getMqttPassword(char* result);
130 virtual int32_t getMqttQos();
131 virtual bool setMqttPrefix(const char* prefix);
132 virtual bool getMqttPrefix(char* result);
133
134 // WiFi config
135 virtual bool setWiFiSSID(const char* ssid);
136 virtual bool setWiFiPassword(const char* password);
137 virtual bool setAltWiFiSSID(const char* ssid);
138 virtual bool setAltWiFiPassword(const char* password);
139 virtual bool getWiFiSSID(char* result);
140 virtual bool getWiFiPassword(char* result);
141 virtual bool getAltWiFiSSID(char* result);
142 virtual bool getAltWiFiPassword(char* result);
143
144 virtual bool isDeviceConfigChangeFlagSet();
145 virtual bool isDeviceConfigChangeReadyToSend();
146 virtual bool setDeviceConfigChangeFlag();
147 virtual bool clearDeviceConfigChangeFlag();
148
149 virtual bool setChannelConfigChangeFlag(int channelNo, int configType = 0);
150 virtual bool clearChannelConfigChangeFlag(int channelNo, int configType = 0);
151 virtual bool isChannelConfigChangeFlagSet(int channelNo, int configType = 0);
152
153 protected:
154 virtual int getBlobSize(const char* key) = 0;
155 uint32_t saveDelayTimestamp = 0;
156 uint32_t deviceConfigUpdateDelayTimestamp = 0;
157 uint32_t saveDelayMs = 0;
158 int8_t deviceConfigChangeFlag = -1;
159};
160}; // namespace Supla
161
162#endif // SRC_SUPLA_STORAGE_CONFIG_H_