supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
suplet
definition.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_SUPLET_DEFINITION_H_
20
#define SRC_SUPLA_SUPLET_DEFINITION_H_
21
22
#include <stdint.h>
23
#include <supla-common/proto.h>
24
#include <supla/suplet/channel_map.h>
25
26
namespace
Supla {
27
class
Element
;
28
29
namespace
Suplet {
30
31
struct
Definition
;
32
struct
InstanceRecord
;
33
34
class
RuntimeHandler
{
35
public
:
36
virtual
~RuntimeHandler
() =
default
;
37
38
virtual
bool
createElements(
const
Definition
&definition,
39
const
InstanceRecord
&instance,
40
Supla::Element
**created,
41
uint8_t createdSize,
42
ChannelMap
*createdChannelMap) = 0;
43
};
44
45
enum class
Category : uint8_t {
46
Unknown = 0,
47
Virtual = 1,
48
Aggregate = 2,
49
Modbus = 3,
50
HttpIntegration = 4,
51
};
52
53
enum class
Kind : uint8_t {
54
Unknown = 0,
55
VirtualRelay = 1,
56
VirtualBinarySensor = 2,
57
ThermometerGroup = 3,
58
ModbusRtu = 4,
59
HttpInverter = 5,
60
};
61
62
enum class
ChannelKind : uint8_t {
63
Unknown = 0,
64
VirtualRelay = 1,
65
VirtualBinarySensor = 2,
66
VirtualThermometer = 3,
67
};
68
69
enum class
ParameterType : uint8_t {
70
Unknown = 0,
71
Bool = 1,
72
UInt8 = 2,
73
UInt16 = 3,
74
Int16 = 4,
75
String = 5,
76
Secret = 6,
77
Enum = 7,
78
ChannelList = 8,
79
};
80
81
enum class
ParameterLifecycle : uint8_t {
82
Editable = 0,
83
CreateOnly = 1,
84
ReadOnly = 2,
85
Secret = 3,
86
};
87
88
struct
Capability
{
89
Category category = Category::Unknown;
90
Kind kind = Kind::Unknown;
91
uint32_t definitionId = 0;
92
uint16_t minDefinitionVersion = 0;
93
uint16_t maxDefinitionVersion = 0;
94
uint8_t minSchemaVersion = 1;
95
uint8_t maxSchemaVersion = 1;
96
uint8_t handlerVersion = 1;
97
uint8_t maxInstances = 1;
98
uint8_t supportsDownloadedDefinition = 0;
99
};
100
101
struct
ChannelDefinition
{
102
uint8_t channelId = kInvalidChannelId;
103
ChannelKind kind = ChannelKind::Unknown;
104
int32_t defaultFunction = 0;
105
const
char
*caption =
nullptr
;
106
};
107
108
struct
ParameterDefinition
{
109
const
char
*key =
nullptr
;
110
ParameterType type = ParameterType::Unknown;
111
ParameterLifecycle lifecycle = ParameterLifecycle::Editable;
112
int32_t min = INT32_MIN;
113
int32_t max = INT32_MAX;
114
int32_t defaultNumber = 0;
115
const
char
*defaultText =
nullptr
;
116
const
char
*enumValues =
nullptr
;
117
uint8_t required = 0;
118
uint8_t hasDefault = 0;
119
uint8_t affectsTopology = 0;
120
};
121
122
constexpr
uint32_t kInvalidDefinitionId = 0;
123
constexpr
uint32_t kServerDefinitionIdMin = 1000;
124
125
inline
bool
isValidDefinitionId(uint32_t definitionId) {
126
return
definitionId != kInvalidDefinitionId;
127
}
128
129
inline
bool
isServerDefinitionId(uint32_t definitionId) {
130
return
definitionId >= kServerDefinitionIdMin;
131
}
132
133
inline
bool
isFirmwarePrivateDefinitionId(uint32_t definitionId) {
134
return
definitionId > kInvalidDefinitionId &&
135
definitionId < kServerDefinitionIdMin;
136
}
137
138
struct
Definition
{
139
Category category = Category::Unknown;
140
Kind kind = Kind::Unknown;
141
uint8_t schemaVersion = 1;
142
uint8_t handlerVersion = 1;
143
uint32_t definitionId = 0;
144
uint16_t definitionVersion = 0;
145
uint8_t maxInstances = 1;
146
const
char
*name =
nullptr
;
147
const
ChannelDefinition
*channels =
nullptr
;
148
uint8_t channelCount = 0;
149
const
ParameterDefinition
*parameters =
nullptr
;
150
uint8_t parameterCount = 0;
151
RuntimeHandler
*runtimeHandler =
nullptr
;
152
const
char
*definitionJson =
nullptr
;
153
uint16_t definitionJsonSize = 0;
154
};
155
156
bool
getDefinitionChannelIds(
const
Definition
&definition,
157
uint8_t *output,
158
uint8_t outputSize);
159
160
}
// namespace Suplet
161
}
// namespace Supla
162
163
#endif
// SRC_SUPLA_SUPLET_DEFINITION_H_
Supla::Element
Base class for all elements of SuplaDevice.
Definition
element.h:42
Supla::Suplet::ChannelMap
Definition
channel_map.h:40
Supla::Suplet::RuntimeHandler
Definition
definition.h:34
Supla::Suplet::Capability
Definition
definition.h:88
Supla::Suplet::ChannelDefinition
Definition
definition.h:101
Supla::Suplet::Definition
Definition
definition.h:138
Supla::Suplet::InstanceRecord
Definition
storage.h:33
Supla::Suplet::ParameterDefinition
Definition
definition.h:108
Generated by
1.17.0