libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Parameter.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 DEVICEPARAMETER_H_
32 #define DEVICEPARAMETER_H_
33 
34 #include "ParameterCast.h"
35 #include "Logical.h"
36 #include "Physical.h"
37 #include "../Systems/Role.h"
38 #include "UnitCode.h"
39 #include <string>
40 #include <set>
41 
42 using namespace rapidxml;
44 
45 namespace BaseLib {
46 
47 class SharedObjects;
48 
49 namespace DeviceDescription {
50 
51 class Parameter;
53 typedef std::shared_ptr<ParameterGroup> PParameterGroup;
54 
55 typedef std::shared_ptr<Parameter> PParameter;
56 typedef std::map<std::string, PParameter> Parameters;
57 typedef std::string ParameterRole;
58 typedef std::unordered_map<uint64_t, Role> ParameterRoles;
59 
60 class Parameter : public std::enable_shared_from_this<Parameter> {
61  public:
62  class Packet {
63  public:
65  enum Enum { none, e, g, l, ge, le };
66  };
67 
68  struct Type {
69  enum Enum { none = 0, get = 1, set = 2, event = 3 };
70  };
71 
72  std::string id;
73  Type::Enum type = Type::none;
74  std::vector<std::string> autoReset;
75  std::pair<std::string, int32_t> delayedAutoReset;
76  std::string responseId;
77  ConditionOperator::Enum conditionOperator = ConditionOperator::none;
78  int32_t conditionValue = -1;
79  int32_t delay = -1;
80 
81  Packet() = default;
82  virtual ~Packet() = default;
83 
84  bool checkCondition(int32_t value);
85  };
86 
87  //Attributes
88  std::string id;
89 
90  //Properties
91  bool readable = true;
92  bool writeable = true;
93  bool readOnInit = false;
94  bool transmitted = true;
95 
99  bool addonWriteable = true;
100 
101  bool password = false;
102  bool visible = true;
103  bool internal = false;
104  bool parameterGroupSelector = false;
105  bool service = false;
106  bool serviceInverted = false;
107  bool sticky = false;
108  bool transform = false;
109  bool isSignedSet = false;
110  bool isSigned = false;
111 
115  std::string control;
116 
120  std::string unit;
124  UnitCode unit_code = UnitCode::kUndefined;
125  bool mandatory = false;
126  std::string formFieldType;
127  int32_t formPosition = -1;
128  std::string metadata;
129  bool resetAfterRestart = false;
130  int32_t priority = -1;
131 
136  bool ccu2Visible = true;
137 
141  std::string linkedParameter;
143  ParameterRoles roles;
144 
145  //Elements
146  std::shared_ptr<ILogical> logical;
147  std::shared_ptr<IPhysical> physical;
148  std::vector<std::shared_ptr<Packet>> getPackets;
149  std::vector<std::shared_ptr<Packet>> setPackets;
150  std::vector<std::shared_ptr<Packet>> eventPackets;
151 
152  //Helpers
153  bool hasDelayedAutoResetParameters = false;
154 
155  explicit Parameter(BaseLib::SharedObjects *baseLib, const PParameterGroup &parent);
156  virtual ~Parameter();
157 
158  void parseXml(xml_node *node);
159 
160  //Helpers
169  PVariable convertFromPacket(const std::vector<uint8_t> &data, const Role &role, bool isEvent);
170 
178  void convertToPacket(const PVariable &value, const Role &role, std::vector<uint8_t> &convertedValue);
179 
187  void convertToPacket(const std::string &value, const Role &role, std::vector<uint8_t> &convertedValue);
188 
189  void adjustBitPosition(std::vector<uint8_t> &data);
190 
191  PParameterGroup parent();
192  protected:
193  BaseLib::SharedObjects *_bl = nullptr;
194 
195  //Helpers
196  std::weak_ptr<ParameterGroup> _parent;
197 
204  void reverseData(const std::vector<uint8_t> &data, std::vector<uint8_t> &reversedData);
205 };
206 
207 }
208 }
209 
210 #endif
std::shared_ptr< IPhysical > physical
Definition: Parameter.h:147
std::string control
UI control to use for displaying this parameter.
Definition: Parameter.h:115
std::vector< std::shared_ptr< Packet > > getPackets
Definition: Parameter.h:148
std::unordered_map< uint64_t, Role > ParameterRoles
Definition: Parameter.h:58
This is the base library main class.
Definition: BaseLib.h:95
std::string id
Definition: Parameter.h:72
Definition: BaseLib.cpp:34
std::vector< std::shared_ptr< Packet > > eventPackets
Definition: Parameter.h:150
ParameterRoles roles
Definition: Parameter.h:143
std::pair< std::string, int32_t > delayedAutoReset
Definition: Parameter.h:75
std::string linkedParameter
When parameters are linked together, logical changes of one parameter change the other to the same va...
Definition: Parameter.h:141
std::string unit
The unit of the variable like "°C" or "km/h".
Definition: Parameter.h:120
PVariable value
Definition: UiElements.h:217
UnitCode
Definition: UnitCode.h:35
std::shared_ptr< ParameterGroup > PParameterGroup
Definition: Parameter.h:52
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
Definition: Role.h:34
Casts casts
Definition: Parameter.h:142
std::string formFieldType
Definition: Parameter.h:126
std::weak_ptr< ParameterGroup > _parent
Definition: Parameter.h:196
std::string id
Definition: Parameter.h:88
std::string ParameterRole
Definition: Parameter.h:57
Definition: ParameterCast.cpp:39
Definition: ParameterGroup.h:58
std::vector< std::string > autoReset
Definition: Parameter.h:74
Class representing a node of XML document.
Definition: rapidxml.h:539
Definition: BinaryPayload.h:38
Definition: Parameter.h:60
std::vector< PICast > Casts
Definition: ParameterCast.h:469
std::shared_ptr< Parameter > PParameter
Definition: Parameter.h:55
std::vector< std::shared_ptr< Packet > > setPackets
Definition: Parameter.h:149
std::map< std::string, PParameter > Parameters
Definition: Parameter.h:56
std::string metadata
Definition: Parameter.h:128
std::string responseId
Definition: Parameter.h:76
std::shared_ptr< ILogical > logical
Definition: Parameter.h:146