forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationKeyValue.h
More file actions
89 lines (65 loc) · 1.95 KB
/
ConfigurationKeyValue.h
File metadata and controls
89 lines (65 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#ifndef CONFIGURATIONKEYVALUE_H
#define CONFIGURATIONKEYVALUE_H
#include <ArduinoJson.h>
#include <memory>
#define MO_CONFIG_MAX_VALSTRSIZE 128
#ifndef MO_CONFIG_EXT_PREFIX
#define MO_CONFIG_EXT_PREFIX "Cst_"
#endif
#ifndef MO_CONFIG_TYPECHECK
#define MO_CONFIG_TYPECHECK 1 //enable this for debugging
#endif
namespace MicroOcpp {
using revision_t = uint16_t;
enum class TConfig : uint8_t {
Int,
Bool,
String
};
template<class T>
TConfig convertType();
class Configuration {
protected:
revision_t value_revision = 0; //write access counter; used to check if this config has been changed
private:
bool rebootRequired = false;
enum class Mutability : uint8_t {
ReadWrite,
ReadOnly,
WriteOnly,
None
};
Mutability mutability = Mutability::ReadWrite;
public:
virtual ~Configuration();
virtual bool setKey(const char *key) = 0;
virtual const char *getKey() = 0;
virtual void setInt(int);
virtual void setBool(bool);
virtual bool setString(const char*);
virtual int getInt();
virtual bool getBool();
virtual const char *getString(); //always returns c-string (empty if undefined)
virtual TConfig getType() = 0;
virtual revision_t getValueRevision();
void setRebootRequired();
bool isRebootRequired();
void setReadOnly();
bool isReadOnly();
bool isReadable();
void setWriteOnly();
};
/*
* Default implementations of the Configuration interface.
*
* How to use custom implementations: for each OCPP config, pass a config instance to the OCPP lib
* before its initialization stage. Then the library won't create new config objects but
*/
std::unique_ptr<Configuration> makeConfiguration(TConfig type, const char *key);
const char *serializeTConfig(TConfig type);
bool deserializeTConfig(const char *serialized, TConfig& out);
} //end namespace MicroOcpp
#endif