BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
VPTDevice.h
1 #pragma once
2 
3 #include <list>
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 #include <Poco/JSON/Object.h>
9 #include <Poco/Mutex.h>
10 #include <Poco/Net/HTTPRequest.h>
11 #include <Poco/Net/SocketAddress.h>
12 #include <Poco/SharedPtr.h>
13 #include <Poco/Timespan.h>
14 
15 #include "core/DeviceCache.h"
16 #include "core/PollableDevice.h"
17 #include "model/DeviceDescription.h"
18 #include "model/DeviceID.h"
19 #include "model/GatewayID.h"
20 #include "model/ModuleID.h"
21 #include "model/ModuleType.h"
22 #include "model/RefreshTime.h"
23 #include "model/SensorData.h"
24 #include "net/HTTPEntireResponse.h"
25 #include "util/Loggable.h"
26 
27 namespace BeeeOn {
28 
36 class VPTDevice : public PollableDevice, protected Loggable {
37 public:
38  typedef Poco::SharedPtr<VPTDevice> Ptr;
39 
40  static const std::vector<std::string> REG_BOILER_OPER_TYPE;
41  static const std::vector<std::string> REG_BOILER_OPER_MODE;
42  static const std::vector<std::string> REG_MAN_ROOM_TEMP;
43  static const std::vector<std::string> REG_MAN_WATER_TEMP;
44  static const std::vector<std::string> REG_MAN_TUV_TEMP;
45  static const std::vector<std::string> REG_MOD_WATER_TEMP;
46 
47  static const std::list<ModuleType> ZONE_MODULE_TYPES;
48  static const std::list<ModuleType> BOILER_MODULE_TYPES;
49 
50  static const int COUNT_OF_ZONES;
51 
52  enum Action {
53  PAIR = 0x01,
54  READ,
55  SET
56  };
57 
67  VPTDevice(
68  const Poco::Net::SocketAddress& address,
69  const Poco::Timespan& httpTimeout,
70  const Poco::Timespan& pingTimeout,
71  const GatewayID& id,
72  const RefreshTime& refresh,
73  const DeviceCache::Ptr deviceCache);
74 
75  DeviceID id() const override;
76  RefreshTime refresh() const override;
77  DeviceID boilerID() const;
78  Poco::Net::SocketAddress address() const;
79  void setAddress(const Poco::Net::SocketAddress& address);
80  void setPassword(const std::string& pwd);
81  Poco::FastMutex& lock();
82 
83  void poll(Distributor::Ptr distributor) override;
84 
89  std::string generateStamp(const Action action);
90 
95  void stampVPT(const Action action);
96 
103  void requestModifyState(const DeviceID& id, const ModuleID module,
104  const double value);
105 
110  std::vector<SensorData> requestValues();
111 
115  std::vector<DeviceDescription> descriptions(const RefreshTime& refresh) const;
116 
120  bool operator==(const VPTDevice& other) const;
121 
126  static DeviceID createSubdeviceID(const int zone, const DeviceID& id);
127 
131  static DeviceID omitSubdeviceFromDeviceID(const DeviceID& id);
132 
136  static int extractSubdeviceFromDeviceID(const DeviceID& id);
137 
138  static std::string extractNonce(const std::string& response);
139  static std::string generateHashPassword(const std::string& pwd, const std::string& response);
140 
141 private:
145  void buildDeviceID();
146 
147  void requestSetModBoilerOperationType(const int zone, const double value);
148  void requestSetModBoilerOperationMode(const int zone, const double value);
149  void requestSetManualRoomTemperature(const int zone, const double value);
150  void requestSetManualWaterTemperature(const int zone, const double value);
151  void requestSetManualTUVTemperature(const int zone, const double value);
152  void requestSetModWaterTemperature(const int zone, const double value);
153 
154  std::string parseZoneAttrFromJson(const std::string& json, const int zone, const std::string& key);
155 
156  HTTPEntireResponse prepareAndSendRequest(const std::string& registr, const std::string& value);
157 
164  HTTPEntireResponse sendSetRequest(Poco::Net::HTTPRequest& request);
165  HTTPEntireResponse sendRequest(Poco::Net::HTTPRequest& request, const Poco::Timespan& timeout) const;
166 
167 private:
172  DeviceID m_boilerId;
173  Poco::Net::SocketAddress m_address;
174  std::string m_password;
175 
176  RefreshTime m_refresh;
177  Poco::Timespan m_pingTimeout;
178  Poco::Timespan m_httpTimeout;
179 
180  GatewayID m_gatewayID;
181  Poco::FastMutex m_lock;
182 
183  DeviceCache::Ptr m_deviceCache;
184 };
185 
186 }
RefreshTime represents time of refreshing values from sensors. E.g. sensors are polled periodically o...
Definition: RefreshTime.h:24
DeviceID id() const override
Definition: VPTDevice.cpp:128
static DeviceID omitSubdeviceFromDeviceID(const DeviceID &id)
Returns DeviceID of real VPT.
Definition: VPTDevice.cpp:477
Definition: HTTPEntireResponse.h:13
static int extractSubdeviceFromDeviceID(const DeviceID &id)
Extracts subdevice number from DeviceID.
Definition: VPTDevice.cpp:484
Definition: ModuleID.h:12
std::vector< SensorData > requestValues()
Gathers data from all sensors of subdevices.
Definition: VPTDevice.cpp:518
bool operator==(const VPTDevice &other) const
Compares two VPTs based on DeviceID.
Definition: VPTDevice.cpp:223
std::vector< DeviceDescription > descriptions(const RefreshTime &refresh) const
Returns list of new device commands of all subdevices.
Definition: VPTDevice.cpp:532
Definition: Loggable.h:19
void requestModifyState(const DeviceID &id, const ModuleID module, const double value)
Definition: VPTDevice.cpp:242
static DeviceID createSubdeviceID(const int zone, const DeviceID &id)
Creates DeviceID from VPT DeviceID and number of zone.
Definition: VPTDevice.cpp:472
void poll(Distributor::Ptr distributor) override
Perform polling for data and ship them via the given distributor.
Definition: VPTDevice.cpp:163
VPTDevice(const Poco::Net::SocketAddress &address, const Poco::Timespan &httpTimeout, const Poco::Timespan &pingTimeout, const GatewayID &id, const RefreshTime &refresh, const DeviceCache::Ptr deviceCache)
Connects to specified address to fetch information for creating VPT Device. If the device do not resp...
Definition: VPTDevice.cpp:111
std::string generateStamp(const Action action)
Creates a stamp that consists of gateway id, IP address of gateway&#39;s interface from whitch the VPT is...
Definition: VPTDevice.cpp:173
RefreshTime refresh() const override
Regular period telling how often to call the method PollableDevice::poll(). The refresh must contain ...
Definition: VPTDevice.cpp:133
Definition: DeviceID.h:17
PollableDevice is a device that is necessary to poll regularly for data. The polling can take some ti...
Definition: PollableDevice.h:18
Definition: GatewayID.h:14
The class represents Thermona Regulator VPT LAN v1.0. It provides functions to control the VPT and to...
Definition: VPTDevice.h:36
void stampVPT(const Action action)
Sends stamp with aciton to the VPT. It serves to verify that the gateway communicates with the VPT...
Definition: VPTDevice.cpp:207