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 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
137 bool local) override;
138
145 void fillChannelConfig(void *channelConfig,
146 int *size,
147 uint8_t configType) override;
148
161
166 void setDefaultValueDivider(int32_t divider);
167
173 void setDefaultValueMultiplier(int32_t multiplier);
174
180 void setDefaultValueAdded(int64_t added);
181
187 void setDefaultValuePrecision(uint8_t precision);
188
194 void setDefaultUnitBeforeValue(const char *unit);
195
201 void setDefaultUnitAfterValue(const char *unit);
203
207
212 int32_t getDefaultValueDivider() const;
213
219 int32_t getDefaultValueMultiplier() const;
220
226 int64_t getDefaultValueAdded() const;
227
233 uint8_t getDefaultValuePrecision() const;
234
240 void getDefaultUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]);
241
247 void getDefaultUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]);
249
262
269 void setRefreshIntervalMs(int32_t intervalMs, bool local = true);
270
277 void setValueDivider(int32_t divider, bool local = true);
278
285 void setValueMultiplier(int32_t multiplier, bool local = true);
286
293 void setValueAdded(int64_t added, bool local = true);
294
301 void setValuePrecision(uint8_t precision, bool local = true);
302
309 void setUnitBeforeValue(const char *unit, bool local = true);
310
317 void setUnitAfterValue(const char *unit, bool local = true);
318
326 void setNoSpaceBeforeValue(uint8_t noSpaceBeforeValue, bool local = true);
327
335 void setNoSpaceAfterValue(uint8_t noSpaceAfterValue, bool local = true);
336 // Sets keep history flag
337
345 void setKeepHistory(uint8_t keepHistory, bool local = true);
346
347 // Sets chart type. Allowed values:
348 // For Measurement channel:
349 // SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_LINEAR
350 // SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_BAR
351 // SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_CANDLE
352 // For Meter channel:
353 // SUPLA_GENERAL_PURPOSE_METER_CHART_TYPE_BAR
354 // SUPLA_GENERAL_PURPOSE_METER_CHART_TYPE_LINEAR
368 void setChartType(uint8_t chartType, bool local = true);
370
374
379 uint16_t getRefreshIntervalMs() const;
380
386 int32_t getValueDivider() const;
387
393 int32_t getValueMultiplier() const;
394
400 int64_t getValueAdded() const;
401
407 uint8_t getValuePrecision() const;
408
414 void getUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const;
415
421 void getUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const;
422
428 uint8_t getNoSpaceBeforeValue() const;
429
435 uint8_t getNoSpaceAfterValue() const;
436
442 uint8_t getKeepHistory() const;
443
449 uint8_t getChartType() const;
451
452 protected:
453 void saveConfig();
454 virtual void setChannelRefreshIntervalMs(uint16_t intervalMs);
455
456 MeasurementDriver *driver = nullptr;
457 uint16_t refreshIntervalMs = 5000;
458 uint32_t lastReadTime = 0;
459 bool deleteDriver = false;
460
461 int32_t defaultValueDivider = 0; // 0.001 units; 0 is considered as 1
462 int32_t defaultValueMultiplier = 0; // 0.001 units; 0 is considered as 1
463 int64_t defaultValueAdded = 0; // 0.001 units
464 uint8_t defaultValuePrecision = 0; // 0 - 4 decimal points
465 // Default unit (before value) - UTF8 including the terminating null byte '\0'
466 char defaultUnitBeforeValue[SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {};
467 // Default unit (after value) - UTF8 including the terminating null byte '\0'
468 char defaultUnitAfterValue[SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {};
469
470 GPMCommonConfig commonConfig = {};
471};
472
473}; // namespace Sensor
474}; // namespace Supla
475
476#endif // SRC_SUPLA_SENSOR_GENERAL_PURPOSE_CHANNEL_BASE_H_
GeneralPurposeChannelBase(MeasurementDriver *driver=nullptr, bool addMemoryVariableDriver=true)
Constructor.
Definition general_purpose_channel_base.cpp:34
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:243
Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result, bool local) override
Applies new Channel Config (i.e.
Definition general_purpose_channel_base.cpp:456
uint8_t getValuePrecision() const
Returns precision (number of decimal places)
Definition general_purpose_channel_base.cpp:263
void setValueMultiplier(int32_t multiplier, bool local=true)
Sets value multiplier.
Definition general_purpose_channel_base.cpp:346
void setDefaultValueAdded(int64_t added)
Sets default value added.
Definition general_purpose_channel_base.cpp:189
void setChartType(uint8_t chartType, bool local=true)
Sets chart type.
Definition general_purpose_channel_base.cpp:446
void setValueAdded(int64_t added, bool local=true)
Sets value added.
Definition general_purpose_channel_base.cpp:357
void onInit() override
Supla::Element::onInit() - called by SuplaDeviceClass::begin() during initialization.
Definition general_purpose_channel_base.cpp:162
int64_t getDefaultValueAdded() const
Returns default value added.
Definition general_purpose_channel_base.cpp:227
void getDefaultUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])
Returns default unit which is displayed before value.
Definition general_purpose_channel_base.cpp:235
void setNoSpaceAfterValue(uint8_t noSpaceAfterValue, bool local=true)
Sets no space after value.
Definition general_purpose_channel_base.cpp:424
int32_t getDefaultValueMultiplier() const
Returns default value multiplier.
Definition general_purpose_channel_base.cpp:223
void setDefaultUnitBeforeValue(const char *unit)
Sets default unit which is displayed before value.
Definition general_purpose_channel_base.cpp:201
GeneralPurposeChannelBase(MeasurementDriver *driver=nullptr, bool addMemoryVariableDriver=true)
Constructor.
Definition general_purpose_channel_base.cpp:34
void setKeepHistory(uint8_t keepHistory, bool local=true)
Sets keep history flag.
Definition general_purpose_channel_base.cpp:435
void getUnitAfterValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const
Returns unit which is displayed after value.
Definition general_purpose_channel_base.cpp:277
double getCalculatedValue()
Returns calculated value, which is result of the following operations:
Definition general_purpose_channel_base.cpp:54
int64_t getValueAdded() const
Returns value added.
Definition general_purpose_channel_base.cpp:259
void setDefaultUnitAfterValue(const char *unit)
Sets default unit which is displayed after value.
Definition general_purpose_channel_base.cpp:210
uint8_t getNoSpaceAfterValue() const
Returns no space after value.
Definition general_purpose_channel_base.cpp:289
void iterateAlways() override
Supla::Element::iterateAlways() - called by SuplaDeviceClass::iterate()
Definition general_purpose_channel_base.cpp:169
void onLoadConfig(SuplaDeviceClass *sdc) override
Supla::Element::onLoadConfig() - called by SuplaDeviceClass::loadConfig() during initialization.
Definition general_purpose_channel_base.cpp:116
void setDefaultValueDivider(int32_t divider)
Sets default value divider.
Definition general_purpose_channel_base.cpp:176
uint8_t getChartType() const
Returns chart type.
Definition general_purpose_channel_base.cpp:297
uint8_t getKeepHistory() const
Returns keep history flag.
Definition general_purpose_channel_base.cpp:293
void fillChannelConfig(void *channelConfig, int *size, uint8_t configType) override
Fills Channel Config.
Definition general_purpose_channel_base.cpp:508
uint8_t getNoSpaceBeforeValue() const
Returns no space before value.
Definition general_purpose_channel_base.cpp:285
void getFormattedValue(char *result, int maxSize)
Returns formatted value as char array (including units, precision, etc.)
Definition general_purpose_channel_base.cpp:73
void setRefreshIntervalMs(int32_t intervalMs, bool local=true)
Sets refresh interval in milliseconds.
Definition general_purpose_channel_base.cpp:317
int32_t getValueDivider() const
Returns value divider.
Definition general_purpose_channel_base.cpp:251
int32_t getDefaultValueDivider() const
Returns default value divider.
Definition general_purpose_channel_base.cpp:219
void getUnitBeforeValue(char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const
Returns unit which is displayed before value.
Definition general_purpose_channel_base.cpp:267
void setUnitAfterValue(const char *unit, bool local=true)
Sets unit which is displayed after value.
Definition general_purpose_channel_base.cpp:396
void setValueDivider(int32_t divider, bool local=true)
Sets value divider.
Definition general_purpose_channel_base.cpp:336
void setUnitBeforeValue(const char *unit, bool local=true)
Sets unit which is displayed before value.
Definition general_purpose_channel_base.cpp:378
virtual ~GeneralPurposeChannelBase()
Destructor.
Definition general_purpose_channel_base.cpp:46
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:572
void setDefaultValuePrecision(uint8_t precision)
Sets default precision (number of decimal places)
Definition general_purpose_channel_base.cpp:194
int32_t getValueMultiplier() const
Returns value multiplier.
Definition general_purpose_channel_base.cpp:255
void setNoSpaceBeforeValue(uint8_t noSpaceBeforeValue, bool local=true)
Sets no space before value.
Definition general_purpose_channel_base.cpp:413
void setDefaultValueMultiplier(int32_t multiplier)
Sets default value multiplier.
Definition general_purpose_channel_base.cpp:182
void setValuePrecision(uint8_t precision, bool local=true)
Sets precision.
Definition general_purpose_channel_base.cpp:367
uint16_t getRefreshIntervalMs() const
Returns refresh interval in milliseconds.
Definition general_purpose_channel_base.cpp:301
virtual double getValue()
Method used to obtain new value for channel.
Definition general_purpose_channel_base.cpp:155
uint8_t getDefaultValuePrecision() const
Returns default precision (number of decimal places)
Definition general_purpose_channel_base.cpp:231
Definition measurement_driver.h:24
Definition general_purpose_channel_base.h:40
Definition general_purpose_channel_base.h:40
Definition proto.h:2987