supla-device
Loading...
Searching...
No Matches
multi_ds_handler_base.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 This program 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 General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15*/
16
17#ifndef SRC_SUPLA_SENSOR_MULTI_DS_HANDLER_BASE_H_
18#define SRC_SUPLA_SENSOR_MULTI_DS_HANDLER_BASE_H_
19
20#include <SuplaDevice.h>
21#include <supla/element.h>
22#include <supla/log_wrapper.h>
23#include <supla/local_action.h>
24#include <supla/device/subdevice_pairing_handler.h>
25#include <supla/device/channel_conflict_resolver.h>
26
27#include "multi_ds_sensor.h"
28
29#define MUTLI_DS_DEFAULT_PAIRING_DURATION_SEC 5
30#define MULTI_DS_MAX_DEVICES_COUNT 10
31#define MULTI_DS_MAX_ACTIONS 10
32
33namespace Supla {
34
35namespace Sensor {
36
37enum class MultiDsState {
38 READY,
39 PARING
40};
41
42class MultiDsHandlerBase : public Element,
45 public:
46 explicit MultiDsHandlerBase(SuplaDeviceClass *sdc, uint8_t pin);
47 virtual ~MultiDsHandlerBase();
48
49 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
50 void iterateAlways() override;
51 bool iterateConnected() override;
52 void onLoadConfig(SuplaDeviceClass *sdc) override;
53 void onInit() override;
54
55 bool startPairing(Supla::Protocol::SuplaSrpc *srpc,
56 TCalCfg_SubdevicePairingResult *result) override;
57
58 bool onChannelConflictReport(
59 uint8_t *channelReport,
60 uint8_t channelReportSize,
61 bool hasConflictInvalidType,
62 bool hasConflictChannelMissingOnServer,
63 bool hasConflictChannelMissingOnDevice) override;
64
65 virtual double getTemperature(const uint8_t *address) = 0;
66
75 void setMaxDeviceCount(uint8_t count);
76
89 void setChannelNumberOffset(uint8_t offset);
90
104 void setUseSubDevices(bool useSubDevices);
105
114 void setPairingTimeout(uint8_t timeout);
115
120
139
140 protected:
141 SuplaDeviceClass *sdc = nullptr;
142 MultiDsSensor *sensors[MULTI_DS_MAX_DEVICES_COUNT] = {};
143 Supla::Sensor::MultiDsSensor *addDevice(DeviceAddress deviceAddress,
144 int channelNumber = -1,
145 int subDeviceId = -1);
146 virtual int refreshSensorsCount() = 0;
147 virtual void requestTemperatures() = 0;
148 virtual bool getSensorAddress(uint8_t *address, int index) = 0;
149
150 private:
151 void notifySrpcAboutParingEnd(int pairingResult, const char *name = nullptr);
152 void addressToString(char *buffor, uint8_t bufforLength, uint8_t *address);
153 void initialSensorSearch();
154
155 uint8_t pin;
156 Supla::Protocol::SuplaSrpc *srpc = nullptr;
157 MultiDsState state = MultiDsState::READY;
158
159 uint32_t pairingStartTimeMs = 0;
160 uint32_t helperTimeMs = 0;
161 uint32_t lastBusReadTime = 0;
162
163 uint8_t maxDeviceCount = MULTI_DS_MAX_DEVICES_COUNT;
164 uint8_t pairingTimeout = MUTLI_DS_DEFAULT_PAIRING_DURATION_SEC;
165 int channelNumberOffset = -1;
166 bool useSubDevices = true;
167 bool channelStateDisabled = false;
168 bool anySensorLoaded = false;
169 bool searchFirstDevice = false;
170};
171
172}; // namespace Sensor
173}; // namespace Supla
174
175#endif // SRC_SUPLA_SENSOR_MULTI_DS_HANDLER_BASE_H_
Definition multi_ds_sensor.h:41
Definition SuplaDevice.h:162
Definition channel_conflict_resolver.h:27
Definition subdevice_pairing_handler.h:32
Definition supla_srpc.h:55
void setChannelNumberOffset(uint8_t offset)
Sets the offset for channel number.
Definition multi_ds_handler_base.cpp:353
void setUseSubDevices(bool useSubDevices)
Sets the channel number offset for paired thermometers.
Definition multi_ds_handler_base.cpp:357
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition multi_ds_handler_base.cpp:52
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition multi_ds_handler_base.cpp:99
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition multi_ds_handler_base.cpp:187
void setPairingTimeout(uint8_t timeout)
Sets the timeout for the pairing process.
Definition multi_ds_handler_base.cpp:361
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition multi_ds_handler_base.cpp:89
void setMaxDeviceCount(uint8_t count)
Sets the maximum number of DS18B20 devices handled by this instance.
Definition multi_ds_handler_base.cpp:345
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition multi_ds_handler_base.cpp:112
void disableSensorsChannelState()
Disables channel state in all thermometers managed by this handler.
Definition multi_ds_handler_base.cpp:365
void searchForFirstSensorDuringInitialization()
Sets automatic single-sensor initialization mode.
Definition multi_ds_handler_base.cpp:369
Definition multi_ds_sensor.h:41
Definition proto.h:2249