supla-device
Loading...
Searching...
No Matches
general_purpose_channel_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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_SENSOR_GENERAL_PURPOSE_CHANNEL_BASE_H_
20#define SRC_SUPLA_SENSOR_GENERAL_PURPOSE_CHANNEL_BASE_H_
21
22#include <supla/channel_element.h>
23
24namespace Supla {
25namespace Sensor {
26
28
37class GeneralPurposeChannelBase : public ChannelElement {
38 public:
39#pragma pack(push, 1)
41 int32_t divider = 0;
42 int32_t multiplier = 0;
43 int64_t added = 0;
44 uint8_t precision = 0;
45 uint8_t noSpaceBeforeValue = 0;
46 uint8_t noSpaceAfterValue = 0;
47 uint8_t keepHistory = 0;
48 uint8_t chartType = 0;
49 uint16_t refreshIntervalMs = 0;
50 char unitBeforeValue[SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {};
51 char unitAfterValue[SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {};
52 };
53#pragma pack(pop)
54
63 explicit GeneralPurposeChannelBase(MeasurementDriver *driver = nullptr,
64 bool addMemoryVariableDriver = true);
65
70
79 double getCalculatedValue();
80
87 void getFormattedValue(char *result, int maxSize);
88
96 virtual double getValue();
97
104 virtual void setValue(const double &value);
105
110 void onInit() override;
111
118 void onLoadConfig(SuplaDeviceClass *sdc) override;
119
123 void iterateAlways() override;
124
136 uint8_t applyChannelConfig(TSD_ChannelConfig *result, bool local) override;
137
144 void fillChannelConfig(void *channelConfig, int *size) override;
145
158
163 void setDefaultValueDivider(int32_t divider);
164
170 void setDefaultValueMultiplier(int32_t multiplier);
171
177 void setDefaultValueAdded(int64_t added);
178
184 void setDefaultValuePrecision(uint8_t precision);
185
191 void setDefaultUnitBeforeValue(const char *unit);
192
198 void setDefaultUnitAfterValue(const char *unit);
200
204
209 int32_t getDefaultValueDivider() const;
210
216 int32_t getDefaultValueMultiplier() const;
217
223 int64_t getDefaultValueAdded() const;
224
230 uint8_t getDefaultValuePrecision() const;
231
237 void getDefaultUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]);
238
244 void getDefaultUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]);
246
259
266 void setRefreshIntervalMs(int32_t intervalMs, bool local = true);
267
274 void setValueDivider(int32_t divider, bool local = true);
275
282 void setValueMultiplier(int32_t multiplier, bool local = true);
283
290 void setValueAdded(int64_t added, bool local = true);
291
298 void setValuePrecision(uint8_t precision, bool local = true);
299
306 void setUnitBeforeValue(const char *unit, bool local = true);
307
314 void setUnitAfterValue(const char *unit, bool local = true);
315
323 void setNoSpaceBeforeValue(uint8_t noSpaceBeforeValue, bool local = true);
324
332 void setNoSpaceAfterValue(uint8_t noSpaceAfterValue, bool local = true);
333 // Sets keep history flag
334
342 void setKeepHistory(uint8_t keepHistory, bool local = true);
343
344 // Sets chart type. Allowed values:
345 // For Measurement channel:
346 // SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_LINEAR
347 // SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_BAR
348 // SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_CANDLE
349 // For Meter channel:
350 // SUPLA_GENERAL_PURPOSE_METER_CHART_TYPE_BAR
351 // SUPLA_GENERAL_PURPOSE_METER_CHART_TYPE_LINEAR
365 void setChartType(uint8_t chartType, bool local = true);
367
371
376 uint16_t getRefreshIntervalMs() const;
377
383 int32_t getValueDivider() const;
384
390 int32_t getValueMultiplier() const;
391
397 int64_t getValueAdded() const;
398
404 uint8_t getValuePrecision() const;
405
411 void getUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const;
412
418 void getUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const;
419
425 uint8_t getNoSpaceBeforeValue() const;
426
432 uint8_t getNoSpaceAfterValue() const;
433
439 uint8_t getKeepHistory() const;
440
446 uint8_t getChartType() const;
448
449 protected:
450 void saveConfig();
451 virtual void setChannelRefreshIntervalMs(uint16_t intervalMs);
452
453 MeasurementDriver *driver = nullptr;
454 uint16_t refreshIntervalMs = 5000;
455 uint32_t lastReadTime = 0;
456 bool deleteDriver = false;
457
458 int32_t defaultValueDivider = 0; // 0.001 units; 0 is considered as 1
459 int32_t defaultValueMultiplier = 0; // 0.001 units; 0 is considered as 1
460 int64_t defaultValueAdded = 0; // 0.001 units
461 uint8_t defaultValuePrecision = 0; // 0 - 4 decimal points
462 // Default unit (before value) - UTF8 including the terminating null byte '\0'
463 char defaultUnitBeforeValue[SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {};
464 // Default unit (after value) - UTF8 including the terminating null byte '\0'
465 char defaultUnitAfterValue[SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {};
466
467 GPMCommonConfig commonConfig = {};
468};
469
470}; // namespace Sensor
471}; // namespace Supla
472
473#endif // SRC_SUPLA_SENSOR_GENERAL_PURPOSE_CHANNEL_BASE_H_
GeneralPurposeChannelBase(MeasurementDriver *driver=nullptr, bool addMemoryVariableDriver=true)
Constructor.
Definition general_purpose_channel_base.cpp:33
Definition SuplaDevice.h:93
void getDefaultUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])
Returns default unit which is displayed after value.
Definition general_purpose_channel_base.cpp:241
uint8_t getValuePrecision() const
Returns precision (number of decimal places)
Definition general_purpose_channel_base.cpp:261
void setValueMultiplier(int32_t multiplier, bool local=true)
Sets value multiplier.
Definition general_purpose_channel_base.cpp:344
void setDefaultValueAdded(int64_t added)
Sets default value added.
Definition general_purpose_channel_base.cpp:187
void setChartType(uint8_t chartType, bool local=true)
Sets chart type.
Definition general_purpose_channel_base.cpp:444
void setValueAdded(int64_t added, bool local=true)
Sets value added.
Definition general_purpose_channel_base.cpp:355
void onInit() override
Supla::Element::onInit() - called by SuplaDeviceClass::begin() during initialization.
Definition general_purpose_channel_base.cpp:160
int64_t getDefaultValueAdded() const
Returns default value added.
Definition general_purpose_channel_base.cpp:225
void getDefaultUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])
Returns default unit which is displayed before value.
Definition general_purpose_channel_base.cpp:233
void setNoSpaceAfterValue(uint8_t noSpaceAfterValue, bool local=true)
Sets no space after value.
Definition general_purpose_channel_base.cpp:422
int32_t getDefaultValueMultiplier() const
Returns default value multiplier.
Definition general_purpose_channel_base.cpp:221
void setDefaultUnitBeforeValue(const char *unit)
Sets default unit which is displayed before value.
Definition general_purpose_channel_base.cpp:199
GeneralPurposeChannelBase(MeasurementDriver *driver=nullptr, bool addMemoryVariableDriver=true)
Constructor.
Definition general_purpose_channel_base.cpp:33
void setKeepHistory(uint8_t keepHistory, bool local=true)
Sets keep history flag.
Definition general_purpose_channel_base.cpp:433
void getUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const
Returns unit which is displayed after value.
Definition general_purpose_channel_base.cpp:275
double getCalculatedValue()
Returns calculated value, which is result of the following operations:
Definition general_purpose_channel_base.cpp:52
int64_t getValueAdded() const
Returns value added.
Definition general_purpose_channel_base.cpp:257
void setDefaultUnitAfterValue(const char *unit)
Sets default unit which is displayed after value.
Definition general_purpose_channel_base.cpp:208
uint8_t getNoSpaceAfterValue() const
Returns no space after value.
Definition general_purpose_channel_base.cpp:287
void iterateAlways() override
Supla::Element::iterateAlways() - called by SuplaDeviceClass::iterate()
Definition general_purpose_channel_base.cpp:167
void onLoadConfig(SuplaDeviceClass *sdc) override
Supla::Element::onLoadConfig() - called by SuplaDeviceClass::loadConfig() during initialization.
Definition general_purpose_channel_base.cpp:114
void setDefaultValueDivider(int32_t divider)
Sets default value divider.
Definition general_purpose_channel_base.cpp:174
uint8_t getChartType() const
Returns chart type.
Definition general_purpose_channel_base.cpp:295
uint8_t getKeepHistory() const
Returns keep history flag.
Definition general_purpose_channel_base.cpp:291
uint8_t getNoSpaceBeforeValue() const
Returns no space before value.
Definition general_purpose_channel_base.cpp:283
void fillChannelConfig(void *channelConfig, int *size) override
Fills Channel Config.
Definition general_purpose_channel_base.cpp:510
void getFormattedValue(char *result, int maxSize)
Returns formatted value as char array (including units, precision, etc.)
Definition general_purpose_channel_base.cpp:71
void setRefreshIntervalMs(int32_t intervalMs, bool local=true)
Sets refresh interval in milliseconds.
Definition general_purpose_channel_base.cpp:315
int32_t getValueDivider() const
Returns value divider.
Definition general_purpose_channel_base.cpp:249
uint8_t applyChannelConfig(TSD_ChannelConfig *result, bool local) override
Applies new Channel Config (i.e.
Definition general_purpose_channel_base.cpp:454
int32_t getDefaultValueDivider() const
Returns default value divider.
Definition general_purpose_channel_base.cpp:217
void getUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const
Returns unit which is displayed before value.
Definition general_purpose_channel_base.cpp:265
void setUnitAfterValue(const char *unit, bool local=true)
Sets unit which is displayed after value.
Definition general_purpose_channel_base.cpp:394
void setValueDivider(int32_t divider, bool local=true)
Sets value divider.
Definition general_purpose_channel_base.cpp:334
void setUnitBeforeValue(const char *unit, bool local=true)
Sets unit which is displayed before value.
Definition general_purpose_channel_base.cpp:376
virtual ~GeneralPurposeChannelBase()
Destructor.
Definition general_purpose_channel_base.cpp:44
virtual void setValue(const double &value)
Method used to set new value for channel with driver which accepts MeasurementDriver::setValue() meth...
Definition general_purpose_channel_base.cpp:569
void setDefaultValuePrecision(uint8_t precision)
Sets default precision (number of decimal places)
Definition general_purpose_channel_base.cpp:192
int32_t getValueMultiplier() const
Returns value multiplier.
Definition general_purpose_channel_base.cpp:253
void setNoSpaceBeforeValue(uint8_t noSpaceBeforeValue, bool local=true)
Sets no space before value.
Definition general_purpose_channel_base.cpp:411
void setDefaultValueMultiplier(int32_t multiplier)
Sets default value multiplier.
Definition general_purpose_channel_base.cpp:180
void setValuePrecision(uint8_t precision, bool local=true)
Sets precision.
Definition general_purpose_channel_base.cpp:365
uint16_t getRefreshIntervalMs() const
Returns refresh interval in milliseconds.
Definition general_purpose_channel_base.cpp:299
virtual double getValue()
Method used to obtain new value for channel.
Definition general_purpose_channel_base.cpp:153
uint8_t getDefaultValuePrecision() const
Returns default precision (number of decimal places)
Definition general_purpose_channel_base.cpp:229
Definition measurement_driver.h:24
Definition general_purpose_channel_base.h:40
Definition general_purpose_channel_base.h:40
Definition proto.h:2912