knx
ETS configurable knx-stack
property.cpp
Go to the documentation of this file.
1 #include "property.h"
2 #include "bits.h"
3 
4 #include <cstring>
5 
7 {
8  return _id;
9 }
10 
12 {
13  return _writeEnable;
14 }
15 
17 {
18  return _type;
19 }
20 
21 uint16_t Property::MaxElements() const
22 {
23  return _maxElements;
24 }
25 
26 uint8_t Property::Access() const
27 {
28  return _access;
29 }
30 
31 uint8_t Property::ElementSize() const
32 {
33  switch (_type)
34  {
35  case PDT_CHAR:
36  case PDT_CONTROL: // is actually 10 if written, but this is always handled with a callback
37  case PDT_GENERIC_01:
38  case PDT_UNSIGNED_CHAR:
39  case PDT_BITSET8:
40  case PDT_BINARY_INFORMATION: // only 1 bit really
41  case PDT_ENUM8:
42  case PDT_SCALING:
43  return 1;
44 
45  case PDT_GENERIC_02:
46  case PDT_INT:
47  case PDT_KNX_FLOAT:
48  case PDT_UNSIGNED_INT:
49  case PDT_VERSION:
50  case PDT_BITSET16:
51  return 2;
52 
53  case PDT_DATE:
54  case PDT_ESCAPE:
55  case PDT_FUNCTION:
56  case PDT_GENERIC_03:
57  case PDT_NE_FL:
58  case PDT_NE_VL:
60  case PDT_TIME:
61  case PDT_UTF8:
62  return 3;
63 
64  case PDT_FLOAT:
65  case PDT_GENERIC_04:
66  case PDT_LONG:
67  case PDT_UNSIGNED_LONG:
68  return 4;
69 
70  case PDT_GENERIC_05:
72  return 5;
73 
74  case PDT_GENERIC_06:
75  case PDT_ALARM_INFO:
76  return 6;
77 
78  case PDT_GENERIC_07:
79  return 7;
80 
81  case PDT_DATE_TIME:
82  case PDT_DOUBLE:
83  case PDT_GENERIC_08:
84  return 8;
85 
86  case PDT_GENERIC_09:
87  return 9;
88 
89  case PDT_CHAR_BLOCK:
90  case PDT_GENERIC_10:
91  return 10;
92 
93  case PDT_GENERIC_11:
94  return 11;
95 
96  case PDT_GENERIC_12:
97  return 12;
98 
99  case PDT_GENERIC_13:
100  return 13;
101 
102  case PDT_GENERIC_14:
103  return 14;
104 
105  case PDT_GENERIC_15:
106  return 15;
107 
108  case PDT_GENERIC_16:
109  return 16;
110 
111  case PDT_GENERIC_17:
112  return 17;
113 
114  case PDT_GENERIC_18:
115  return 18;
116 
117  case PDT_GENERIC_19:
118  return 19;
119 
120  case PDT_GENERIC_20:
121  return 20;
122 
123  default:
124  return 0;
125  }
126 }
127 
128 Property::Property(PropertyID id, bool writeEnable, PropertyDataType type,
129  uint16_t maxElements, uint8_t access)
130  : _id(id), _writeEnable(writeEnable), _type(type), _maxElements(maxElements), _access(access)
131 {}
132 
134 {}
135 
136 
137 uint8_t Property::read(uint8_t& value) const
138 {
139  if (ElementSize() != 1)
140  return 0;
141 
142  return read(1, 1, &value);
143 }
144 
145 
146 uint8_t Property::read(uint16_t& value) const
147 {
148  if (ElementSize() != 2)
149  return 0;
150 
151  uint8_t data[2];
152  uint8_t count = read(1, 1, data);
153 
154  if (count > 0)
155  {
156  popWord(value, data);
157  }
158 
159  return count;
160 }
161 
162 
163 uint8_t Property::read(uint32_t& value) const
164 {
165  if (ElementSize() != 4)
166  return 0;
167 
168  uint8_t data[4];
169  uint8_t count = read(1, 1, data);
170 
171  if (count > 0)
172  {
173  popInt(value, data);
174  }
175 
176  return count;
177 }
178 
179 uint8_t Property::read(uint8_t* value) const
180 {
181  return read(1, 1, value);
182 }
183 
184 uint8_t Property::write(uint8_t value)
185 {
186  if (ElementSize() != 1)
187  return 0;
188 
189  return write(1, 1, &value);
190 }
191 
192 
193 uint8_t Property::write(uint16_t value)
194 {
195  if (ElementSize() != 2)
196  return 0;
197 
198  uint8_t data[2];
199  pushWord(value, data);
200  return write(1, 1, data);
201 }
202 
203 
204 uint8_t Property::write(uint32_t value)
205 {
206  if (ElementSize() != 4)
207  return 0;
208 
209  uint8_t data[4];
210  pushInt(value, data);
211  return write(1, 1, data);
212 }
213 
214 
215 uint8_t Property::write(const uint8_t* value)
216 {
217  return write(1, 1, value);
218 }
219 
220 
221 uint8_t Property::write(uint16_t position, uint16_t value)
222 {
223  if (ElementSize() != 2)
224  return 0;
225 
226  uint8_t data[2];
227  pushWord(value, data);
228  return write(position, 1, data);
229 }
230 
231 void Property::command(uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength)
232 {
233  (void)data;
234  (void)length;
235  (void)resultData;
236  resultLength = 0;
237 }
238 
239 void Property::state(uint8_t* data, uint8_t length, uint8_t* resultData, uint8_t& resultLength)
240 {
241  (void)data;
242  (void)length;
243  (void)resultData;
244  resultLength = 0;
245 }
uint8_t * pushInt(uint32_t i, uint8_t *data)
Definition: bits.cpp:72
uint8_t * pushWord(uint16_t w, uint8_t *data)
Definition: bits.cpp:64
const uint8_t * popInt(uint32_t &i, const uint8_t *data)
Definition: bits.cpp:41
const uint8_t * popWord(uint16_t &w, const uint8_t *data)
Definition: bits.cpp:34
virtual ~Property()
Definition: property.cpp:133
PropertyDataType _type
Definition: property.h:289
virtual uint8_t read(uint16_t start, uint8_t count, uint8_t *data) const =0
uint8_t ElementSize() const
Definition: property.cpp:31
virtual void state(uint8_t *data, uint8_t length, uint8_t *resultData, uint8_t &resultLength)
Definition: property.cpp:239
PropertyID _id
Definition: property.h:287
uint8_t Access() const
Definition: property.cpp:26
uint8_t _access
Definition: property.h:291
Property(PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements, uint8_t access)
Definition: property.cpp:128
uint16_t _maxElements
Definition: property.h:290
PropertyID Id() const
Definition: property.cpp:6
bool _writeEnable
Definition: property.h:288
virtual uint8_t write(uint16_t start, uint8_t count, const uint8_t *data)=0
uint16_t MaxElements() const
Definition: property.cpp:21
virtual void command(uint8_t *data, uint8_t length, uint8_t *resultData, uint8_t &resultLength)
Definition: property.cpp:231
bool WriteEnable() const
Definition: property.cpp:11
PropertyDataType Type() const
Definition: property.cpp:16
PropertyID
Definition: property.h:70
PropertyDataType
The data type of a property.
Definition: property.h:17
@ PDT_GENERIC_12
length: 12
Definition: property.h:46
@ PDT_CONTROL
length: 1 read, 10 write
Definition: property.h:18
@ PDT_GENERIC_16
length: 16
Definition: property.h:50
@ PDT_INT
length: 2
Definition: property.h:21
@ PDT_BITSET16
length: 3
Definition: property.h:60
@ PDT_ESCAPE
length: 3
Definition: property.h:66
@ PDT_GENERIC_11
length: 11
Definition: property.h:45
@ PDT_GENERIC_08
length: 8
Definition: property.h:42
@ PDT_GENERIC_13
length: 13
Definition: property.h:47
@ PDT_DATE_TIME
length: 8
Definition: property.h:33
@ PDT_GENERIC_18
length: 18
Definition: property.h:52
@ PDT_POLL_GROUP_SETTING
length: 3
Definition: property.h:31
@ PDT_BINARY_INFORMATION
length: 3
Definition: property.h:58
@ PDT_GENERIC_17
length: 17
Definition: property.h:51
@ PDT_UNSIGNED_LONG
length: 4
Definition: property.h:27
@ PDT_TIME
length: 3
Definition: property.h:25
@ PDT_DATE
length: 3
Definition: property.h:24
@ PDT_FLOAT
length: 4
Definition: property.h:28
@ PDT_KNX_FLOAT
length: 2
Definition: property.h:23
@ PDT_CHAR
length: 1
Definition: property.h:19
@ PDT_GENERIC_06
length: 6
Definition: property.h:40
@ PDT_CHAR_BLOCK
length: 10
Definition: property.h:30
@ PDT_SCALING
length: 3
Definition: property.h:62
@ PDT_GENERIC_02
length: 2
Definition: property.h:36
@ PDT_GENERIC_03
length: 3
Definition: property.h:37
@ PDT_DOUBLE
length: 8
Definition: property.h:29
@ PDT_BITSET8
length: 3
Definition: property.h:59
@ PDT_ENUM8
length: 3
Definition: property.h:61
@ PDT_GENERIC_10
length: 10
Definition: property.h:44
@ PDT_GENERIC_14
length: 14
Definition: property.h:48
@ PDT_NE_FL
length: 3
Definition: property.h:64
@ PDT_VERSION
length: 3
Definition: property.h:56
@ PDT_FUNCTION
length: 3
Definition: property.h:65
@ PDT_SHORT_CHAR_BLOCK
length: 5
Definition: property.h:32
@ PDT_GENERIC_19
length: 19
Definition: property.h:53
@ PDT_GENERIC_04
length: 4
Definition: property.h:38
@ PDT_NE_VL
length: 3
Definition: property.h:63
@ PDT_UTF8
length: 3
Definition: property.h:55
@ PDT_GENERIC_15
length: 15
Definition: property.h:49
@ PDT_LONG
length: 4
Definition: property.h:26
@ PDT_GENERIC_20
length: 20
Definition: property.h:54
@ PDT_UNSIGNED_INT
length: 2
Definition: property.h:22
@ PDT_GENERIC_05
length: 5
Definition: property.h:39
@ PDT_UNSIGNED_CHAR
length: 1
Definition: property.h:20
@ PDT_GENERIC_09
length: 9
Definition: property.h:43
@ PDT_GENERIC_01
length: 1
Definition: property.h:35
@ PDT_ALARM_INFO
length: 3
Definition: property.h:57
@ PDT_GENERIC_07
length: 7
Definition: property.h:41