libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
ParameterCast.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 DEVICEPARAMETERCAST_H_
32 #define DEVICEPARAMETERCAST_H_
33 
34 #include "../Variable.h"
35 #include <string>
36 
37 using namespace rapidxml;
38 
39 namespace BaseLib
40 {
41 
42 namespace Rpc
43 {
44  class RpcEncoder;
45  class RpcDecoder;
46 }
47 
48 namespace DeviceDescription
49 {
50 
51 class Parameter;
52 typedef std::shared_ptr<Parameter> PParameter;
53 
54 namespace ParameterCast
55 {
56 
57 class ICast
58 {
59 public:
60  explicit ICast(BaseLib::SharedObjects* baseLib);
61  explicit ICast(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
62  virtual ~ICast() = default;
63 
64  virtual bool needsBinaryPacketData() { return false; }
65  virtual void fromPacket(PVariable& value);
66  virtual void toPacket(PVariable& value);
67 protected:
68  BaseLib::SharedObjects* _bl = nullptr;
69  const std::weak_ptr<Parameter> _parameter;
70 };
71 
72 class DecimalIntegerScale : public ICast
73 {
74 public:
76  explicit DecimalIntegerScale(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
77  ~DecimalIntegerScale() override = default;
78 
79  void fromPacket(PVariable& value) override;
80  void toPacket(PVariable& value) override;
81 
82  //Elements
83  double factor = 1.0;
84  double offset = 0;
85 };
86 
87 
89 {
90 public:
92  explicit DecimalIntegerInverseScale(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
93  ~DecimalIntegerInverseScale() override = default;
94 
95  void fromPacket(PVariable& value) override;
96  void toPacket(PVariable& value) override;
97 
98  //Elements
99  double factor = 1.0;
100 };
101 
102 
103 class DecimalStringScale : public ICast
104 {
105 public:
106  explicit DecimalStringScale(BaseLib::SharedObjects* baseLib);
107  explicit DecimalStringScale(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
108  ~DecimalStringScale() override = default;
109 
110  void fromPacket(PVariable& value) override;
111  void toPacket(PVariable& value) override;
112 
113  //Elements
114  double factor = 1.0;
115 };
116 
118 {
119 public:
120  struct Operation
121  {
122  enum Enum { none = 0, division = 1, multiplication = 2 };
123  };
124 
125  explicit IntegerIntegerScale(BaseLib::SharedObjects* baseLib);
126  explicit IntegerIntegerScale(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
127  ~IntegerIntegerScale() override = default;
128 
129  void fromPacket(PVariable& value) override;
130  void toPacket(PVariable& value) override;
131 
132  //Elements
133  Operation::Enum operation = Operation::none;
134  double factor = 10;
135  int32_t offset = 0;
136 };
137 
138 class IntegerOffset : public ICast
139 {
140 public:
141  explicit IntegerOffset(BaseLib::SharedObjects* baseLib);
142  explicit IntegerOffset(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
143  ~IntegerOffset() override = default;
144 
145  void fromPacket(PVariable& value) override;
146  void toPacket(PVariable& value) override;
147 
148  //Elements
149  bool directionToPacket = true;
150  bool addOffset = false;
151  int32_t offset = 0;
152 };
153 
154 class DecimalOffset : public ICast
155 {
156 public:
157  explicit DecimalOffset(BaseLib::SharedObjects* baseLib);
158  explicit DecimalOffset(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
159  ~DecimalOffset() override = default;
160 
161  void fromPacket(PVariable& value) override;
162  void toPacket(PVariable& value) override;
163 
164  //Elements
165  bool directionToPacket = true;
166  bool addOffset = false;
167  double offset = 0;
168 };
169 
170 class IntegerIntegerMap : public ICast
171 {
172 public:
173  struct Direction
174  {
175  enum Enum { none = 0, fromDevice = 1, toDevice = 2, both = 3 };
176  };
177 
178  explicit IntegerIntegerMap(BaseLib::SharedObjects* baseLib);
179  explicit IntegerIntegerMap(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
180  ~IntegerIntegerMap() override = default;
181 
182  void fromPacket(PVariable& value) override;
183  void toPacket(PVariable& value) override;
184 
185  //Elements
186  Direction::Enum direction = Direction::none;
187  std::map<int32_t, int32_t> integerValueMapFromDevice;
188  std::map<int32_t, int32_t> integerValueMapToDevice;
189 };
190 
191 class BooleanInteger : public ICast
192 {
193 public:
194  explicit BooleanInteger(BaseLib::SharedObjects* baseLib);
195  explicit BooleanInteger(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
196  ~BooleanInteger() override = default;
197 
198  void fromPacket(PVariable& value) override;
199  void toPacket(PVariable& value) override;
200 
201  //Elements
202  int32_t trueValue = 0;
203  int32_t falseValue = 0;
204  bool invert = false;
205  int32_t threshold = 1;
206 };
207 
208 class BooleanDecimal : public ICast
209 {
210 public:
211  explicit BooleanDecimal(BaseLib::SharedObjects* baseLib);
212  explicit BooleanDecimal(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
213  ~BooleanDecimal() override = default;
214 
215  void fromPacket(PVariable& value) override;
216  void toPacket(PVariable& value) override;
217 
218  //Elements
219  double trueValue = 0;
220  double falseValue = 0;
221  bool invert = false;
222  double threshold = 1;
223 };
224 
225 class BooleanString : public ICast
226 {
227 public:
228  explicit BooleanString(BaseLib::SharedObjects* baseLib);
229  explicit BooleanString(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
230  ~BooleanString() override = default;
231 
232  void fromPacket(PVariable& value) override;
233  void toPacket(PVariable& value) override;
234 
235  //Elements
236  std::string trueValue;
237  std::string falseValue;
238  bool invert = false;
239 };
240 
241 class DecimalConfigTime : public ICast
242 {
243 public:
244  explicit DecimalConfigTime(BaseLib::SharedObjects* baseLib);
245  explicit DecimalConfigTime(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
246  ~DecimalConfigTime() override = default;
247 
248  void fromPacket(PVariable& value) override;
249  void toPacket(PVariable& value) override;
250 
251  //Elements
252  std::vector<double> factors;
253  double valueSize = 0;
254 };
255 
256 class IntegerTinyFloat : public ICast
257 {
258 public:
259  explicit IntegerTinyFloat(BaseLib::SharedObjects* baseLib);
260  explicit IntegerTinyFloat(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
261  ~IntegerTinyFloat() override = default;
262 
263  void fromPacket(PVariable& value) override;
264  void toPacket(PVariable& value) override;
265 
266  //Elements
267  int32_t mantissaStart = 5;
268  int32_t mantissaSize = 11;
269  int32_t exponentStart = 0;
270  int32_t exponentSize = 5;
271 };
272 
274 {
275 public:
277  explicit StringUnsignedInteger(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
278  ~StringUnsignedInteger() override = default;
279 
280  void fromPacket(PVariable& value) override;
281  void toPacket(PVariable& value) override;
282 };
283 
284 class BlindTest : public ICast
285 {
286 public:
287  explicit BlindTest(BaseLib::SharedObjects* baseLib);
288  explicit BlindTest(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
289  ~BlindTest() override = default;
290 
291  void fromPacket(PVariable& value) override;
292  void toPacket(PVariable& value) override;
293 
294  //Elements
295  int32_t value = 0;
296 };
297 
298 class OptionString : public ICast
299 {
300 public:
301  explicit OptionString(BaseLib::SharedObjects* baseLib);
302  explicit OptionString(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
303  ~OptionString() override = default;
304 
305  void fromPacket(PVariable& value) override;
306  void toPacket(PVariable& value) override;
307 };
308 
309 class OptionInteger : public ICast
310 {
311 public:
312  explicit OptionInteger(BaseLib::SharedObjects* baseLib);
313  explicit OptionInteger(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
314  ~OptionInteger() override = default;
315 
316  void fromPacket(PVariable& value) override;
317  void toPacket(PVariable& value) override;
318 
319  //Elements
320  std::map<int32_t, int32_t> valueMapFromDevice;
321  std::map<int32_t, int32_t> valueMapToDevice;
322 };
323 
325 {
326 public:
328  explicit StringJsonArrayDecimal(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
329  ~StringJsonArrayDecimal() override = default;
330 
331  void fromPacket(PVariable& value) override;
332  void toPacket(PVariable& value) override;
333 };
334 
335 class RpcBinary : public ICast
336 {
337 public:
338  explicit RpcBinary(BaseLib::SharedObjects* baseLib);
339  explicit RpcBinary(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
340  ~RpcBinary() override = default;
341 
342  bool needsBinaryPacketData() override { return true; }
343  void fromPacket(PVariable& value) override;
344  void toPacket(PVariable& value) override;
345 private:
346  //Helpers
347  std::shared_ptr<BaseLib::Rpc::RpcDecoder> _binaryDecoder;
348  std::shared_ptr<BaseLib::Rpc::RpcEncoder> _binaryEncoder;
349 };
350 
351 class Toggle : public ICast
352 {
353 public:
354  explicit Toggle(BaseLib::SharedObjects* baseLib);
355  explicit Toggle(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
356  ~Toggle() override = default;
357 
358  void fromPacket(PVariable& value) override;
359  void toPacket(PVariable& value) override;
360 
361  //Elements
362  std::string parameter;
363  int32_t on = 200;
364  int32_t off = 0;
365 };
366 
367 class CcrtdnParty : public ICast
368 {
369 public:
370  explicit CcrtdnParty(BaseLib::SharedObjects* baseLib);
371  explicit CcrtdnParty(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
372  ~CcrtdnParty() override = default;
373 
374  bool needsBinaryPacketData() override { return true; }
375  void fromPacket(PVariable& value) override;
376  void toPacket(PVariable& value) override;
377 };
378 
379 class Cfm : public ICast
380 {
381 public:
382  explicit Cfm(BaseLib::SharedObjects* baseLib);
383  explicit Cfm(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
384  ~Cfm() override = default;
385 
386  bool needsBinaryPacketData() override { return true; }
387  void fromPacket(PVariable& value) override;
388  void toPacket(PVariable& value) override;
389 };
390 
391 class StringReplace : public ICast
392 {
393 public:
394  explicit StringReplace(BaseLib::SharedObjects* baseLib);
395  explicit StringReplace(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
396  ~StringReplace() override = default;
397 
398  void fromPacket(PVariable& value) override;
399  void toPacket(PVariable& value) override;
400 
401  //Elements
402  std::string search;
403  std::string replace;
404 };
405 
406 class HexStringByteArray : public ICast
407 {
408 public:
409  explicit HexStringByteArray(BaseLib::SharedObjects* baseLib);
410  explicit HexStringByteArray(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
411  ~HexStringByteArray() override = default;
412 
413  void fromPacket(PVariable& value) override;
414  void toPacket(PVariable& value) override;
415 };
416 
417 class TimeStringSeconds : public ICast
418 {
419 public:
420  explicit TimeStringSeconds(BaseLib::SharedObjects* baseLib);
421  explicit TimeStringSeconds(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
422  ~TimeStringSeconds() override = default;
423 
424  void fromPacket(PVariable& value) override;
425  void toPacket(PVariable& value) override;
426 };
427 
428 class Invert : public ICast
429 {
430 public:
431  explicit Invert(BaseLib::SharedObjects* baseLib);
432  explicit Invert(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
433  ~Invert() override = default;
434 
435  void fromPacket(PVariable& value) override;
436  void toPacket(PVariable& value) override;
437 };
438 
439 class Round : public ICast
440 {
441 public:
442  explicit Round(BaseLib::SharedObjects* baseLib);
443  explicit Round(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
444  ~Round() override = default;
445 
446  void fromPacket(PVariable& value) override;
447  void toPacket(PVariable& value) override;
448 
449  //Elements
450  bool roundToPoint5 = false;
451  int32_t decimalPlaces = 1;
452 };
453 
454 class Generic : public ICast
455 {
456 public:
457  explicit Generic(BaseLib::SharedObjects* baseLib);
458  explicit Generic(BaseLib::SharedObjects* baseLib, xml_node* node, const PParameter& parameter);
459  ~Generic() override = default;
460 
461  void fromPacket(PVariable& value) override;
462  void toPacket(PVariable& value) override;
463 
464  //Elements
465  std::string type;
466 };
467 
468 typedef std::shared_ptr<ICast> PICast;
469 typedef std::vector<PICast> Casts;
470 typedef std::shared_ptr<BlindTest> PBlindTest;
471 typedef std::shared_ptr<BooleanInteger> PBooleanInteger;
472 typedef std::shared_ptr<BooleanDecimal> PBooleanDecimal;
473 typedef std::shared_ptr<BooleanString> PBooleanString;
474 typedef std::shared_ptr<CcrtdnParty> PCcrtdnParty;
475 typedef std::shared_ptr<Cfm> PCfm;
476 typedef std::shared_ptr<DecimalConfigTime> PDecimalConfigTime;
477 typedef std::shared_ptr<DecimalIntegerScale> PDecimalIntegerScale;
478 typedef std::shared_ptr<DecimalIntegerInverseScale> PDecimalIntegerInverseScale;
479 typedef std::shared_ptr<DecimalStringScale> PDecimalStringScale;
480 typedef std::shared_ptr<IntegerIntegerMap> PIntegerIntegerMap;
481 typedef std::shared_ptr<IntegerIntegerScale> PIntegerIntegerScale;
482 typedef std::shared_ptr<IntegerOffset> PIntegerOffset;
483 typedef std::shared_ptr<DecimalOffset> PDecimalOffset;
484 typedef std::shared_ptr<IntegerTinyFloat> PIntegerTinyFloat;
485 typedef std::shared_ptr<OptionString> POptionString;
486 typedef std::shared_ptr<OptionInteger> POptionInteger;
487 typedef std::shared_ptr<RpcBinary> PRpcBinary;
488 typedef std::shared_ptr<StringJsonArrayDecimal> PStringJsonArrayDecimal;
489 typedef std::shared_ptr<StringUnsignedInteger> PStringUnsignedInteger;
490 typedef std::shared_ptr<Toggle> PToggle;
491 typedef std::shared_ptr<StringReplace> PStringReplace;
492 typedef std::shared_ptr<HexStringByteArray> PHexStringByteArray;
493 typedef std::shared_ptr<TimeStringSeconds> PTimeStringSeconds;
494 typedef std::shared_ptr<Invert> PInvert;
495 typedef std::shared_ptr<Round> PRound;
496 typedef std::shared_ptr<Generic> PGeneric;
497 
498 }
499 }
500 }
501 #endif
std::map< int32_t, int32_t > valueMapToDevice
Definition: ParameterCast.h:321
std::shared_ptr< DecimalIntegerInverseScale > PDecimalIntegerInverseScale
Definition: ParameterCast.h:478
std::shared_ptr< BlindTest > PBlindTest
Definition: ParameterCast.h:470
bool needsBinaryPacketData() override
Definition: ParameterCast.h:342
std::shared_ptr< IntegerIntegerScale > PIntegerIntegerScale
Definition: ParameterCast.h:481
This is the base library main class.
Definition: BaseLib.h:95
std::shared_ptr< TimeStringSeconds > PTimeStringSeconds
Definition: ParameterCast.h:493
Definition: RpcDecoder.h:55
const std::weak_ptr< Parameter > _parameter
Definition: ParameterCast.h:69
std::shared_ptr< IntegerOffset > PIntegerOffset
Definition: ParameterCast.h:482
std::shared_ptr< Round > PRound
Definition: ParameterCast.h:495
std::shared_ptr< StringJsonArrayDecimal > PStringJsonArrayDecimal
Definition: ParameterCast.h:488
std::vector< double > factors
Definition: ParameterCast.h:252
std::shared_ptr< IntegerIntegerMap > PIntegerIntegerMap
Definition: ParameterCast.h:480
std::shared_ptr< DecimalStringScale > PDecimalStringScale
Definition: ParameterCast.h:479
Definition: BaseLib.cpp:34
bool needsBinaryPacketData() override
Definition: ParameterCast.h:386
std::shared_ptr< Toggle > PToggle
Definition: ParameterCast.h:490
std::shared_ptr< DecimalOffset > PDecimalOffset
Definition: ParameterCast.h:483
virtual bool needsBinaryPacketData()
Definition: ParameterCast.h:64
std::shared_ptr< BooleanString > PBooleanString
Definition: ParameterCast.h:473
std::shared_ptr< BooleanDecimal > PBooleanDecimal
Definition: ParameterCast.h:472
std::shared_ptr< RpcBinary > PRpcBinary
Definition: ParameterCast.h:487
std::string trueValue
Definition: ParameterCast.h:236
std::string parameter
Definition: ParameterCast.h:362
std::shared_ptr< HexStringByteArray > PHexStringByteArray
Definition: ParameterCast.h:492
std::map< int32_t, int32_t > valueMapFromDevice
Definition: ParameterCast.h:320
PVariable value
Definition: UiElements.h:217
bool needsBinaryPacketData() override
Definition: ParameterCast.h:374
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
std::shared_ptr< DecimalConfigTime > PDecimalConfigTime
Definition: ParameterCast.h:476
std::shared_ptr< ICast > PICast
Definition: ParameterCast.h:468
Definition: ParameterCast.h:379
Definition: RpcEncoder.h:48
std::shared_ptr< StringReplace > PStringReplace
Definition: ParameterCast.h:491
std::shared_ptr< OptionString > POptionString
Definition: ParameterCast.h:485
std::string type
Definition: ParameterCast.h:465
std::shared_ptr< BooleanInteger > PBooleanInteger
Definition: ParameterCast.h:471
std::string replace
Definition: ParameterCast.h:403
std::map< int32_t, int32_t > integerValueMapToDevice
Definition: ParameterCast.h:188
std::string falseValue
Definition: ParameterCast.h:237
Class representing a node of XML document.
Definition: rapidxml.h:539
std::map< int32_t, int32_t > integerValueMapFromDevice
Definition: ParameterCast.h:187
Definition: BinaryPayload.h:38
std::shared_ptr< Cfm > PCfm
Definition: ParameterCast.h:475
std::shared_ptr< StringUnsignedInteger > PStringUnsignedInteger
Definition: ParameterCast.h:489
std::string search
Definition: ParameterCast.h:402
std::vector< PICast > Casts
Definition: ParameterCast.h:469
std::shared_ptr< Parameter > PParameter
Definition: Parameter.h:55
std::shared_ptr< Invert > PInvert
Definition: ParameterCast.h:494
std::shared_ptr< OptionInteger > POptionInteger
Definition: ParameterCast.h:486
std::shared_ptr< CcrtdnParty > PCcrtdnParty
Definition: ParameterCast.h:474
std::shared_ptr< IntegerTinyFloat > PIntegerTinyFloat
Definition: ParameterCast.h:484
std::shared_ptr< Generic > PGeneric
Definition: ParameterCast.h:496
std::shared_ptr< DecimalIntegerScale > PDecimalIntegerScale
Definition: ParameterCast.h:477