libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
HmDevice.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef HMDEVICE_H_
32 #define HMDEVICE_H_
33 
34 #include <string>
35 #include <vector>
36 #include <map>
37 #include <unordered_map>
38 #include <cmath>
39 #include <memory>
40 
41 #include "../../Systems/Packet.h"
42 #include "HmLogicalParameter.h"
43 #include "HmPhysicalParameter.h"
44 #include "../../Encoding/RpcEncoder.h"
45 #include "../../Encoding/RpcDecoder.h"
46 
47 namespace BaseLib
48 {
49 
50 class SharedObjects;
51 class Variable;
52 
53 namespace HmDeviceDescription
54 {
55 
56 class HomeMaticParameter;
57 class ParameterSet;
58 class Device;
59 
61 {
62 public:
63  std::string id;
64  std::string value;
65 
68  virtual ~DescriptionField() {}
69 };
70 
72 {
73 public:
74  std::vector<DescriptionField> fields;
75 
78  virtual ~ParameterDescription() {}
79 };
80 
82 {
83 public:
84  struct Type
85  {
86  enum Enum { none, toggle, floatIntegerScale, integerIntegerScale, floatUint8StringScale, booleanInteger, booleanDecimal, booleanString, integerIntegerMap, floatConfigTime, optionInteger, integerTinyFloat, stringUnsignedInteger, blindTest, cfm, ccrtdnParty, optionString, stringJsonArrayFloat, rpcBinary, hexstringBytearray };
87  };
88  Type::Enum type = Type::Enum::none;
89  std::unordered_map<int32_t, int32_t> integerValueMapDevice;
90  std::unordered_map<int32_t, int32_t> integerValueMapParameter;
91  double factor = 0;
92  std::vector<double> factors;
93  int32_t div = 0;
94  int32_t mul = 0;
95  int32_t threshold = 1;
96  int32_t valueFalse = 0;
97  int32_t valueTrue = 0;
98  std::string stringValueFalse = "false";
99  std::string stringValueTrue = "true";
100  double offset = 0;
101  double valueSize = 0;
102  int32_t mantissaStart = 5;
103  int32_t mantissaSize = 11;
104  int32_t exponentStart = 0;
105  int32_t exponentSize = 5;
106  std::string stringValue;
107  int32_t on = 200;
108  int32_t off = 0;
109  bool invert = false;
110  bool fromDevice = true;
111  bool toDevice = true;
112 
115  virtual ~ParameterConversion() {}
116  virtual void fromPacket(std::shared_ptr<Variable> value);
117  virtual void toPacket(std::shared_ptr<Variable> value);
118 protected:
119  BaseLib::SharedObjects* _bl = nullptr;
120  HomeMaticParameter* _parameter = nullptr;
121 private:
123  ParameterConversion& operator=(const ParameterConversion&);
124 };
125 
127 {
128 public:
130  {
131  enum Enum { e, g, l, ge, le };
132  };
133  struct Operations
134  {
135  enum Enum { none = 0, read = 1, write = 2, event = 4, addonWrite = 16 };
136  };
137  struct UIFlags
138  {
139  enum Enum { none = 0, visible = 1, internal = 2, transform = 4, service = 8, sticky = 0x10, invisible = 0x20 };
140  };
141  uint32_t _bitmask[8] = {0xFF, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F};
142  ParameterSet* parentParameterSet = nullptr;
143  double index = 0;
144  double size = 0;
145  double index2 = 0;
146  double size2 = 0;
147  int32_t index2Offset = -1;
148  bool isSigned = false;
149  bool hidden = false;
150  BooleanOperator::Enum booleanOperator = BooleanOperator::Enum::e;
152  UIFlags::Enum uiFlags = UIFlags::Enum::visible;
153  PhysicalParameter::Type::Enum type = PhysicalParameter::Type::Enum::none;
154  int32_t constValue = -1;
155  std::string constValueString;
156  std::string id;
157  std::string param;
158  std::string additionalParameter;
159  std::string control;
160  std::shared_ptr<LogicalParameter> logicalParameter;
161  std::shared_ptr<PhysicalParameter> physicalParameter;
162  std::vector<std::shared_ptr<ParameterConversion>> conversion;
164  bool omitIfSet = false;
165  int32_t omitIf = 0;
166  bool loopback = false;
167  bool hasDominoEvents = false;
168  int32_t mask = -1;
169  std::string field;
170  std::string subfield;
171 
173  HomeMaticParameter(BaseLib::SharedObjects* baseLib, xml_node* node, bool checkForID = false);
174  virtual ~HomeMaticParameter() {}
175  virtual bool checkCondition(int32_t value);
176 
184  virtual std::shared_ptr<Variable> convertFromPacket(std::vector<uint8_t>& data, bool isEvent = false);
185 
192  virtual void convertToPacket(const std::shared_ptr<Variable> value, std::vector<uint8_t>& convertedValue);
193 
200  virtual void convertToPacket(std::string value, std::vector<uint8_t>& convertedValue);
201 
208  virtual void reverseData(const std::vector<uint8_t>& data, std::vector<uint8_t>& reversedData);
209  virtual void adjustBitPosition(std::vector<uint8_t>& data);
210 protected:
211  BaseLib::SharedObjects* _bl = nullptr;
212  std::shared_ptr<Rpc::RpcDecoder> _binaryDecoder;
213  std::shared_ptr<Rpc::RpcEncoder> _binaryEncoder;
214 };
215 
217 {
218 public:
220  {
221  enum Enum { e, g, l, ge, le };
222  };
223  std::string name;
224  std::string id;
225  std::vector<HomeMaticParameter> parameters;
226  bool updatable = false;
227  int32_t priority = 0;
228  int32_t firmware = -1;
229  int32_t typeID = -1;
230  BooleanOperator::Enum booleanOperator = BooleanOperator::Enum::e;
231  Device* device = nullptr;
232 
234  DeviceType(BaseLib::SharedObjects* baseLib, xml_node* typeNode);
235  virtual ~DeviceType() {}
236 
237  virtual bool matches(int32_t family, std::string typeID);
238  virtual bool matches(uint32_t typeNumber, uint32_t firmwareVersion);
239  virtual bool checkFirmwareVersion(int32_t version);
240 protected:
241  BaseLib::SharedObjects* _bl = nullptr;
242 private:
243  DeviceType(const DeviceType&);
244  DeviceType& operator=(const DeviceType&);
245 };
246 
247 typedef std::vector<std::pair<std::string, std::string>> DefaultValue;
249 {
250 public:
251  struct Type
252  {
253  enum Enum { none = 0, master = 1, values = 2, link = 3 };
254  };
255  Type::Enum type = Type::Enum::none;
256  std::string id;
257  std::vector<std::shared_ptr<HomeMaticParameter>> parameters;
258  std::map<std::string, DefaultValue> defaultValues;
259  std::map<uint32_t, uint32_t> lists;
260  std::string subsetReference;
261  int32_t addressStart = -1;
262  int32_t addressStep = -1;
263  int32_t count = -1;
264  std::string peerParam;
265  std::string channelParam;
266  int32_t channelOffset = -1;
267  int32_t peerAddressOffset = -1;
268  int32_t peerChannelOffset = -1;
269 
271  ParameterSet(BaseLib::SharedObjects* baseLib, xml_node* parameterSetNode);
272  virtual ~ParameterSet() {}
273  virtual void init(xml_node* parameterSetNode);
274  virtual std::vector<std::shared_ptr<HomeMaticParameter>> getIndices(uint32_t startIndex, uint32_t endIndex, int32_t list);
275  virtual std::vector<std::shared_ptr<HomeMaticParameter>> getList(int32_t list);
276  virtual std::shared_ptr<HomeMaticParameter> getIndex(double index);
277  virtual std::shared_ptr<HomeMaticParameter> getParameter(std::string id);
278  virtual std::string typeString();
279  static ParameterSet::Type::Enum typeFromString(std::string type);
280 protected:
281  BaseLib::SharedObjects* _bl = nullptr;
282 };
283 
285 {
286 public:
287  std::string id;
288  std::string value;
289 
291  EnforceLink(BaseLib::SharedObjects* baseLib, xml_node* parameterSetNode);
292  virtual ~EnforceLink() {}
293  virtual std::shared_ptr<Variable> getValue(LogicalParameter::Type::Enum type);
294 protected:
295  BaseLib::SharedObjects* _bl = nullptr;
296 };
297 
298 class LinkRole
299 {
300 public:
301  std::vector<std::string> sourceNames;
302  std::vector<std::string> targetNames;
303 
304  LinkRole() {}
305  LinkRole(BaseLib::SharedObjects* baseLib, xml_node* parameterSetNode);
306  virtual ~LinkRole() {}
307 };
308 
310 {
311 public:
312  struct UIFlags
313  {
314  enum Enum { none = 0, visible = 1, internal = 2, dontdelete = 8 };
315  };
316  struct Direction
317  {
318  enum Enum { none = 0, sender = 1, receiver = 2 };
319  };
320  Device* parentDevice = nullptr;
321  int32_t physicalIndexOffset = 0;
322  std::string type;
323  UIFlags::Enum uiFlags = UIFlags::Enum::visible;
324  Direction::Enum direction = Direction::Enum::none;
325  std::string channelClass;
326  uint32_t startIndex = 0;
327  uint32_t count = 1;
328  bool hasTeam = false;
329  bool aesDefault = false;
330  bool aesAlways = false;
331  bool aesCBC = false;
332  bool hidden = false;
333  bool autoregister = false;
334  bool paired = false;
335  double countFromSysinfo = -1;
336  double countFromSysinfoSize = 1;
337  std::string countFromVariable;
338  std::string function;
339  std::string pairFunction1;
340  std::string pairFunction2;
341  std::string teamTag;
342  std::map<ParameterSet::Type::Enum, std::shared_ptr<ParameterSet>> parameterSets;
343  std::shared_ptr<LinkRole> linkRoles;
344  std::vector<std::shared_ptr<EnforceLink>> enforceLinks;
345  std::shared_ptr<HomeMaticParameter> specialParameter;
346  std::vector<std::shared_ptr<DeviceChannel>> subconfigs;
347 
349  DeviceChannel(BaseLib::SharedObjects* baseLib, xml_node* node, uint32_t& index);
350  virtual ~DeviceChannel() {}
351 protected:
352  BaseLib::SharedObjects* _bl = nullptr;
353 private:
355  DeviceChannel& operator=(const DeviceChannel&);
356 };
357 
359 {
360 public:
361  struct Direction
362  {
363  enum Enum { none, toDevice, fromDevice };
364  };
366  {
367  enum Enum { none = 0, broadcast = 1, central = 2, other = 4 };
368  };
369 
370  Direction::Enum direction = Direction::Enum::none;
371  AllowedReceivers::Enum allowedReceivers = AllowedReceivers::Enum::none;
372  std::string id;
373  bool isEvent = false;
374  bool doubleSend = false;
375  uint32_t type = 0;
376  int32_t subtype = -1;
377  int32_t subtypeIndex = -1;
378  double subtypeFieldSize = 1.0;
379  int32_t responseType = -1;
380  int32_t responseSubtype = -1;
381  int32_t channelField = -1;
382  double channelFieldSize = 1.0;
383  int32_t channelIndexOffset = 0;
384  int32_t fixedChannel = -1;
385  int32_t size = -1;
386  int32_t splitAfter = -1;
387  int32_t maxPackets = -1;
388  std::list<HomeMaticParameter> parameters;
389  std::vector<std::shared_ptr<HomeMaticParameter>> associatedValues;
390  std::string function1;
391  std::string function2;
392  std::string metaString1;
393  std::string metaString2;
394 
397  virtual ~DeviceFrame() {}
398 protected:
399  BaseLib::SharedObjects* _bl = nullptr;
400 };
401 
403 {
404 public:
405  struct StartType
406  {
407  enum Enum { none, once, interval, permanent };
408  };
409 
410  StartType::Enum startType = StartType::none;
411  std::string path;
412  std::vector<std::string> arguments;
413  uint32_t interval = 0;
414 
417  virtual ~DeviceProgram() {}
418 protected:
419  BaseLib::SharedObjects* _bl = nullptr;
420 };
421 
422 class Device
423 {
424 public:
425  struct UIFlags
426  {
427  enum Enum { none = 0, visible = 1, internal = 2, dontdelete = 8 };
428  };
429  struct RXModes
430  {
431  enum Enum { none = 0, always = 1, burst = 2, config = 4, wakeUp = 8, lazyConfig = 16, wakeUp2 = 32 };
432  };
433 
434  bool loaded() { return _loaded; }
435  bool hasBattery = false;
436  int32_t family = 0;
437  uint32_t version = 0;
438  uint32_t cyclicTimeout = 0;
439  int32_t eepSize = 1024;
440  std::shared_ptr<ParameterSet> parameterSet;
441  std::map<uint32_t, std::shared_ptr<DeviceChannel>> channels;
442  std::vector<std::shared_ptr<DeviceType>> supportedTypes;
443  std::multimap<uint32_t, std::shared_ptr<DeviceFrame>> framesByMessageType;
444  std::multimap<std::string, std::shared_ptr<DeviceFrame>> framesByFunction1;
445  std::multimap<std::string, std::shared_ptr<DeviceFrame>> framesByFunction2;
446  std::map<std::string, std::shared_ptr<DeviceFrame>> framesByID;
447  std::map<int32_t, std::map<std::string, std::shared_ptr<DeviceFrame>>> valueRequestFrames;
448  std::shared_ptr<DeviceProgram> runProgram;
449  RXModes::Enum rxModes = RXModes::Enum::always;
450  UIFlags::Enum uiFlags = UIFlags::Enum::visible;
451  int32_t countFromSysinfoIndex = -1;
452  double countFromSysinfoSize = 1;
453  std::string deviceClass;
454  bool supportsAES = false;
455  bool peeringSysinfoExpectChannel = true;
456  bool needsTime = false;
457  std::shared_ptr<Device> team;
458 
459  Device(BaseLib::SharedObjects* baseLib, int32_t family);
460  Device(BaseLib::SharedObjects* baseLib, int32_t family, std::string xmlFilename);
461  virtual ~Device();
462  virtual std::shared_ptr<DeviceType> getType(uint32_t typeNumber, int32_t firmwareVersion);
463  virtual int32_t getCountFromSysinfo() { return _countFromSysinfo; }
464  virtual void setCountFromSysinfo(int32_t countFromSysinfo);
465 protected:
466  BaseLib::SharedObjects* _bl = nullptr;
467  bool _loaded = false;
468  int32_t _countFromSysinfo = -1;
469 
470  virtual void load(std::string xmlFilename);
471  virtual void parseXML(xml_node* node, std::string& xmlFilename);
472 };
473 }
474 }
475 #endif /* DEVICE_H_ */
std::string id
Definition: HmDevice.h:156
std::shared_ptr< Rpc::RpcDecoder > _binaryDecoder
Definition: HmDevice.h:212
Enum
Definition: HmPhysicalParameter.h:99
virtual ~DeviceProgram()
Definition: HmDevice.h:417
std::string function1
Definition: HmDevice.h:390
std::string field
Definition: HmDevice.h:169
Enum
Definition: HmLogicalParameter.h:67
std::shared_ptr< HomeMaticParameter > specialParameter
Definition: HmDevice.h:345
std::string function2
Definition: HmDevice.h:391
std::shared_ptr< DeviceProgram > runProgram
Definition: HmDevice.h:448
std::shared_ptr< LogicalParameter > logicalParameter
Definition: HmDevice.h:160
This is the base library main class.
Definition: BaseLib.h:95
std::string value
Definition: HmDevice.h:64
std::map< uint32_t, std::shared_ptr< DeviceChannel > > channels
Definition: HmDevice.h:441
std::string path
Definition: HmDevice.h:411
std::string teamTag
Definition: HmDevice.h:341
std::string additionalParameter
Definition: HmDevice.h:158
std::list< HomeMaticParameter > parameters
Definition: HmDevice.h:388
std::shared_ptr< Device > team
Definition: HmDevice.h:457
Definition: BaseLib.cpp:34
std::vector< std::shared_ptr< HomeMaticParameter > > associatedValues
Definition: HmDevice.h:389
std::vector< std::shared_ptr< EnforceLink > > enforceLinks
Definition: HmDevice.h:344
std::vector< std::shared_ptr< DeviceChannel > > subconfigs
Definition: HmDevice.h:346
std::shared_ptr< Rpc::RpcEncoder > _binaryEncoder
Definition: HmDevice.h:213
std::map< ParameterSet::Type::Enum, std::shared_ptr< ParameterSet > > parameterSets
Definition: HmDevice.h:342
std::string id
Definition: HmDevice.h:224
bool loaded()
Definition: HmDevice.h:434
std::vector< std::pair< std::string, std::string > > DefaultValue
Definition: HmDevice.h:247
virtual int32_t getCountFromSysinfo()
Definition: HmDevice.h:463
Definition: HmDevice.h:422
std::vector< std::shared_ptr< HomeMaticParameter > > parameters
Definition: HmDevice.h:257
std::unordered_map< int32_t, int32_t > integerValueMapDevice
Definition: HmDevice.h:89
std::map< std::string, DefaultValue > defaultValues
Definition: HmDevice.h:258
std::string deviceClass
Definition: HmDevice.h:453
std::shared_ptr< PhysicalParameter > physicalParameter
Definition: HmDevice.h:161
std::vector< DescriptionField > fields
Definition: HmDevice.h:74
std::string control
Definition: HmDevice.h:159
std::string subfield
Definition: HmDevice.h:170
std::string id
Definition: HmDevice.h:372
std::string stringValue
Definition: HmDevice.h:106
ParameterDescription description
Definition: HmDevice.h:163
std::string name
Definition: HmDevice.h:223
std::multimap< std::string, std::shared_ptr< DeviceFrame > > framesByFunction2
Definition: HmDevice.h:445
virtual ~ParameterSet()
Definition: HmDevice.h:272
std::string id
Definition: HmDevice.h:256
std::map< uint32_t, uint32_t > lists
Definition: HmDevice.h:259
DescriptionField()
Definition: HmDevice.h:66
virtual ~HomeMaticParameter()
Definition: HmDevice.h:174
virtual ~ParameterConversion()
Definition: HmDevice.h:115
std::string peerParam
Definition: HmDevice.h:264
std::string pairFunction2
Definition: HmDevice.h:340
std::string pairFunction1
Definition: HmDevice.h:339
virtual ~DeviceType()
Definition: HmDevice.h:235
std::multimap< uint32_t, std::shared_ptr< DeviceFrame > > framesByMessageType
Definition: HmDevice.h:443
virtual ~DeviceChannel()
Definition: HmDevice.h:350
std::string metaString1
Definition: HmDevice.h:392
std::string subsetReference
Definition: HmDevice.h:260
std::vector< std::shared_ptr< ParameterConversion > > conversion
Definition: HmDevice.h:162
std::shared_ptr< ParameterSet > parameterSet
Definition: HmDevice.h:440
std::vector< HomeMaticParameter > parameters
Definition: HmDevice.h:225
virtual ~ParameterDescription()
Definition: HmDevice.h:78
std::multimap< std::string, std::shared_ptr< DeviceFrame > > framesByFunction1
Definition: HmDevice.h:444
std::shared_ptr< LinkRole > linkRoles
Definition: HmDevice.h:343
std::string countFromVariable
Definition: HmDevice.h:337
std::string param
Definition: HmDevice.h:157
std::string metaString2
Definition: HmDevice.h:393
std::vector< std::string > arguments
Definition: HmDevice.h:412
std::map< std::string, std::shared_ptr< DeviceFrame > > framesByID
Definition: HmDevice.h:446
virtual ~DeviceFrame()
Definition: HmDevice.h:397
std::string channelParam
Definition: HmDevice.h:265
std::string constValueString
Definition: HmDevice.h:155
std::vector< std::shared_ptr< DeviceType > > supportedTypes
Definition: HmDevice.h:442
virtual ~DescriptionField()
Definition: HmDevice.h:68
Class representing a node of XML document.
Definition: rapidxml.h:539
std::map< int32_t, std::map< std::string, std::shared_ptr< DeviceFrame > > > valueRequestFrames
Definition: HmDevice.h:447
std::unordered_map< int32_t, int32_t > integerValueMapParameter
Definition: HmDevice.h:90
std::string type
Definition: HmDevice.h:322
std::string id
Definition: HmDevice.h:63
std::string channelClass
Definition: HmDevice.h:325
std::vector< double > factors
Definition: HmDevice.h:92