supla-device
Loading...
Searching...
No Matches
GeneralPurposeChannelBase Class Reference

Base class for General Purpose Measurement (GPM/KPOP) and General Purpose Meter (GPM/KLOP) More...

#include <general_purpose_channel_base.h>

Inheritance diagram for GeneralPurposeChannelBase:
Collaboration diagram for GeneralPurposeChannelBase:

Classes

struct  GPMCommonConfig
 

Public Member Functions

 GeneralPurposeChannelBase (MeasurementDriver *driver=nullptr, bool addMemoryVariableDriver=true)
 Constructor.
 
virtual ~GeneralPurposeChannelBase ()
 Destructor.
 
double getCalculatedValue ()
 Returns calculated value, which is result of the following operations:
 
void getFormattedValue (char *result, int maxSize)
 Returns formatted value as char array (including units, precision, etc.)
 
virtual double getValue ()
 Method used to obtain new value for channel.
 
virtual void setValue (const double &value)
 Method used to set new value for channel with driver which accepts MeasurementDriver::setValue() method.
 
void onInit () override
 Supla::Element::onInit() - called by SuplaDeviceClass::begin() during initialization.
 
void onLoadConfig (SuplaDeviceClass *sdc) override
 Supla::Element::onLoadConfig() - called by SuplaDeviceClass::loadConfig() during initialization.
 
void iterateAlways () override
 Supla::Element::iterateAlways() - called by SuplaDeviceClass::iterate()
 
uint8_t applyChannelConfig (TSD_ChannelConfig *result, bool local) override
 Applies new Channel Config (i.e.
 
void fillChannelConfig (void *channelConfig, int *size) override
 Fills Channel Config.
 
Setters for default values.

Default parameters should be configured in software.

GPM doesn't store it by itself. Defualt values are applied by server as first default configuration when channel is registered for the first time and configuration for those parameters is not set. If default value stored on server is different from current channel's configuration, it will be applied. However current configuration value will not be overwritten. Use "reset to defaults" button on Supla Cloud to reset configuration to default values.

void setDefaultValueDivider (int32_t divider)
 Sets default value divider.
 
void setDefaultValueMultiplier (int32_t multiplier)
 Sets default value multiplier.
 
void setDefaultValueAdded (int64_t added)
 Sets default value added.
 
void setDefaultValuePrecision (uint8_t precision)
 Sets default precision (number of decimal places)
 
void setDefaultUnitBeforeValue (const char *unit)
 Sets default unit which is displayed before value.
 
void setDefaultUnitAfterValue (const char *unit)
 Sets default unit which is displayed after value.
 
Getters for default values.
int32_t getDefaultValueDivider () const
 Returns default value divider.
 
int32_t getDefaultValueMultiplier () const
 Returns default value multiplier.
 
int64_t getDefaultValueAdded () const
 Returns default value added.
 
uint8_t getDefaultValuePrecision () const
 Returns default precision (number of decimal places)
 
void getDefaultUnitBeforeValue (char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])
 Returns default unit which is displayed before value.
 
void getDefaultUnitAfterValue (char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])
 Returns default unit which is displayed after value.
 
Setters for modification of current channel configuration.

Each call to setters will modify channel config and send it to Supla Server.

This shouldn't be used as a channel config setup step, because on each device startup it will overwrite user's configuration.

local parameter should be set to true if method is called locally by device. False is used when called as a result of processing SetChannelConfig from server. When local is true, channel configuration will be sent to Supla Server.

void setRefreshIntervalMs (int32_t intervalMs, bool local=true)
 Sets refresh interval in milliseconds.
 
void setValueDivider (int32_t divider, bool local=true)
 Sets value divider.
 
void setValueMultiplier (int32_t multiplier, bool local=true)
 Sets value multiplier.
 
void setValueAdded (int64_t added, bool local=true)
 Sets value added.
 
void setValuePrecision (uint8_t precision, bool local=true)
 Sets precision.
 
void setUnitBeforeValue (const char *unit, bool local=true)
 Sets unit which is displayed before value.
 
void setUnitAfterValue (const char *unit, bool local=true)
 Sets unit which is displayed after value.
 
void setNoSpaceBeforeValue (uint8_t noSpaceBeforeValue, bool local=true)
 Sets no space before value.
 
void setNoSpaceAfterValue (uint8_t noSpaceAfterValue, bool local=true)
 Sets no space after value.
 
void setKeepHistory (uint8_t keepHistory, bool local=true)
 Sets keep history flag.
 
void setChartType (uint8_t chartType, bool local=true)
 Sets chart type.
 
Getters for current channel configuration parameters.
uint16_t getRefreshIntervalMs () const
 Returns refresh interval in milliseconds.
 
int32_t getValueDivider () const
 Returns value divider.
 
int32_t getValueMultiplier () const
 Returns value multiplier.
 
int64_t getValueAdded () const
 Returns value added.
 
uint8_t getValuePrecision () const
 Returns precision (number of decimal places)
 
void getUnitBeforeValue (char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const
 Returns unit which is displayed before value.
 
void getUnitAfterValue (char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const
 Returns unit which is displayed after value.
 
uint8_t getNoSpaceBeforeValue () const
 Returns no space before value.
 
uint8_t getNoSpaceAfterValue () const
 Returns no space after value.
 
uint8_t getKeepHistory () const
 Returns keep history flag.
 
uint8_t getChartType () const
 Returns chart type.
 
- Public Member Functions inherited from Supla::ChannelElement
 ChannelElement (int channelNumber=-1)
 
ChannelgetChannel () override
 
const ChannelgetChannel () const override
 Returns pointer to main channel.
 
- Public Member Functions inherited from Supla::ElementWithChannelActions
void addAction (uint16_t action, ActionHandler &client, uint16_t event, bool alwaysEnabled=false) override
 
void addAction (uint16_t action, ActionHandler *client, uint16_t event, bool alwaysEnabled=false) override
 
virtual void addAction (uint16_t action, ActionHandler &client, Supla::Condition *condition, bool alwaysEnabled=false)
 
virtual void addAction (uint16_t action, ActionHandler *client, Supla::Condition *condition, bool alwaysEnabled=false)
 
bool isEventAlreadyUsed (uint16_t event, bool ignoreAlwaysEnabled) override
 
void onRegistered (Supla::Protocol::SuplaSrpc *suplaSrpc) override
 Method called each time when device successfully registers to Supla server.
 
bool iterateConnected () override
 Method called on each SuplaDevice iteration when device is connected and registered to Supla server or other protocol.
 
void handleChannelConfigFinished () override
 Handles "channel config finished" message from server.
 
uint8_t handleChannelConfig (TSD_ChannelConfig *result, bool local) override
 Handles "set channel config" request from server.
 
void handleSetChannelConfigResult (TSDS_SetChannelConfigResult *result) override
 Handles "set channel config" reply from server.
 
void purgeConfig () override
 Removes all configration data related to the element from Storage::Config.
 
void clearChannelConfigChangedFlag ()
 
void runAction (uint16_t event) const override
 
virtual bool setAndSaveFunction (_supla_int_t channelFunction)
 
virtual bool loadFunctionFromConfig ()
 
virtual bool saveConfigChangeFlag ()
 
virtual bool loadConfigChangeFlag ()
 
bool isAnyUpdatePending () override
 Returns true if any update is pending.
 
virtual void fillChannelOcrConfig (void *channelConfig, int *size)
 
void triggerSetChannelConfig ()
 
- Public Member Functions inherited from Supla::Element
Elementnext ()
 Returns next Element from the list.
 
virtual void onLoadState ()
 Second method called on element in SuplaDevice.begin().
 
virtual void onSaveState ()
 Method called periodically during SuplaDevice iteration.
 
virtual bool iterateConnected (void *ptr)
 deprecated
 
virtual void onTimer ()
 Method called on timer interupt.
 
virtual void onFastTimer ()
 Method called on fast timer interupt.
 
virtual void onSoftReset ()
 Method called when device soft restart is triggered.
 
virtual void onDeviceConfigChange (uint64_t fieldBit)
 Method called when device config is changed.
 
virtual int32_t handleNewValueFromServer (TSD_SuplaChannelNewValue *newValue)
 Handles "new value" request from server.
 
virtual void fillSuplaChannelNewValue (TSD_SuplaChannelNewValue *value)
 Fills TSD_SuplaChannelNewValue based on current state.
 
virtual void handleGetChannelState (TDSC_ChannelState *channelState)
 Handles "get channel state (i)" request from server.
 
virtual int handleCalcfgFromServer (TSD_DeviceCalCfgRequest *request)
 Handles CALCFG requests from server.
 
virtual uint8_t handleWeeklySchedule (TSD_ChannelConfig *newWeeklySchedule, bool altSchedule=false, bool local=false)
 Handles "set channel config" with "weekly schedule" type request from server.
 
int getChannelNumber () const
 Returns channel number.
 
int getSecondaryChannelNumber () const
 Returns secondary channel number.
 
virtual bool isOwnerOfSubDeviceId (int subDeviceId) const
 Returns true if element is owner of subDeviceId.
 
virtual const ChannelgetSecondaryChannel () const
 Returns pointer to secondary channel.
 
virtual ChannelgetSecondaryChannel ()
 
virtual void generateKey (char *output, const char *key) const
 Generates key used for Config.
 
ElementdisableChannelState ()
 Disables channel state (i) function.
 
bool isChannelStateEnabled () const
 Returns true if channel state (i) function is enabled.
 
void setInitialCaption (const char *caption, bool secondaryChannel=false)
 Sets initial caption.
 
void setDefaultFunction (int32_t defaultFunction)
 Sets default channel's function.
 
- Public Member Functions inherited from Supla::LocalAction
virtual ActionHandlerClientgetHandlerForFirstClient (uint16_t event)
 
virtual ActionHandlerClientgetHandlerForClient (ActionHandler *client, uint16_t event)
 
virtual void disableOtherClients (const ActionHandler &client, uint16_t event)
 
virtual void enableOtherClients (const ActionHandler &client, uint16_t event)
 
virtual void disableOtherClients (const ActionHandler *client, uint16_t event)
 
virtual void enableOtherClients (const ActionHandler *client, uint16_t event)
 
virtual void disableAction (int32_t action, ActionHandler *client, int32_t event)
 
virtual void enableAction (int32_t action, ActionHandler *client, int32_t event)
 
virtual bool disableActionsInConfigMode ()
 

Protected Member Functions

void saveConfig ()
 
virtual void setChannelRefreshIntervalMs (uint16_t intervalMs)
 
- Protected Member Functions inherited from Supla::ElementWithChannelActions
virtual bool hasOcrConfig () const
 
virtual bool isOcrConfigMissing () const
 
virtual void clearOcrConfig ()
 

Protected Attributes

MeasurementDriver * driver = nullptr
 
uint16_t refreshIntervalMs = 5000
 
uint32_t lastReadTime = 0
 
bool deleteDriver = false
 
int32_t defaultValueDivider = 0
 
int32_t defaultValueMultiplier = 0
 
int64_t defaultValueAdded = 0
 
uint8_t defaultValuePrecision = 0
 
char defaultUnitBeforeValue [SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {}
 
char defaultUnitAfterValue [SUPLA_GENERAL_PURPOSE_UNIT_SIZE] = {}
 
GPMCommonConfig commonConfig = {}
 
- Protected Attributes inherited from Supla::ChannelElement
Channel channel
 
- Protected Attributes inherited from Supla::ElementWithChannelActions
Supla::ChannelConfigState channelConfigState
 
bool configFinishedReceived = false
 
uint8_t setChannelConfigAttempts = 0
 
- Protected Attributes inherited from Supla::Element
ElementnextPtr = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Supla::Element
static Elementbegin ()
 Returns first Element (based on creation order)
 
static Elementlast ()
 Returns last Element (based on creation order)
 
static ElementgetElementByChannelNumber (int channelNumber)
 Returns Element by channel number.
 
static ElementgetOwnerOfSubDeviceId (int subDeviceId)
 Returns Element which owns given subDeviceId.
 
static bool IsAnyUpdatePending ()
 Checks if any element has pending update for remote server.
 
static void NotifyElementsAboutConfigChange (uint64_t fieldBit)
 Notifies all elements about device config change.
 
static bool IsInvalidPtrSet ()
 When "invalid pointer" is set, previously obtained Element pointer may be invalid.
 
static void ClearInvalidPtr ()
 Clears "invalid pointer" flag.
 
- Static Public Member Functions inherited from Supla::LocalAction
static void DeleteActionsHandledBy (const ActionHandler *client)
 
static void DeleteActionsTriggeredBy (const LocalAction *action)
 
static void NullifyActionsHandledBy (const ActionHandler *client)
 
static ActionHandlerClientgetClientListPtr ()
 
- Static Protected Attributes inherited from Supla::Element
static ElementfirstPtr = nullptr
 
static bool invalidatePtr = false
 

Detailed Description

Base class for General Purpose Measurement (GPM/KPOP) and General Purpose Meter (GPM/KLOP)

GPM can have either MeasurementDriver provided which is used to obtain value for a channel, or derived class can be used, which implements getValue method.

Constructor & Destructor Documentation

◆ GeneralPurposeChannelBase()

GeneralPurposeChannelBase::GeneralPurposeChannelBase ( MeasurementDriver * driver = nullptr,
bool addMemoryVariableDriver = true )
explicit

Constructor.

Parameters
driver(optional) pointer to MeasurementDriver instance.
addMemoryVariableDriver(optional) if true, MemoryVariableDriver will be added to channel, which works as virtual sensors.

Member Function Documentation

◆ applyChannelConfig()

uint8_t GeneralPurposeChannelBase::applyChannelConfig ( TSD_ChannelConfig * result,
bool local )
overridevirtual

Applies new Channel Config (i.e.

received from Supla Server)

Parameters
resultpointer to TSD_ChannelConfig which should contain TChannelConfig_GeneralPurposeMeasurement or TChannelConfig_GeneralPurposeMeter class with configuration.
localset to true if method is called locally by device. Use false if method is called as a result of Supla Server message.
Returns
result of operation (see proto.h SUPLA_CONFIG_RESULT_*)

Reimplemented from Supla::ElementWithChannelActions.

◆ fillChannelConfig()

void GeneralPurposeChannelBase::fillChannelConfig ( void * channelConfig,
int * size )
overridevirtual

Fills Channel Config.

Parameters
channelConfigpointer to TSD_ChannelConfig to be filled.
sizewritten config size is stored here.

Reimplemented from Supla::ElementWithChannelActions.

◆ getCalculatedValue()

double GeneralPurposeChannelBase::getCalculatedValue ( )

Returns calculated value, which is result of the following operations:

  • value divider
  • value multiplier
  • value added
Returns
calculated value

◆ getChartType()

uint8_t GeneralPurposeChannelBase::getChartType ( ) const

Returns chart type.

Returns
chart type (
See also
setChartType())

◆ getDefaultUnitAfterValue()

void GeneralPurposeChannelBase::getDefaultUnitAfterValue ( char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])

Returns default unit which is displayed after value.

Parameters
unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]result is stored into this

◆ getDefaultUnitBeforeValue()

void GeneralPurposeChannelBase::getDefaultUnitBeforeValue ( char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE])

Returns default unit which is displayed before value.

Parameters
unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]result is stored into this

◆ getDefaultValueAdded()

int64_t GeneralPurposeChannelBase::getDefaultValueAdded ( ) const

Returns default value added.

Returns
default value added in 0.001 units

◆ getDefaultValueDivider()

int32_t GeneralPurposeChannelBase::getDefaultValueDivider ( ) const

Returns default value divider.

Returns
default value divider in 0.001 units

◆ getDefaultValueMultiplier()

int32_t GeneralPurposeChannelBase::getDefaultValueMultiplier ( ) const

Returns default value multiplier.

Returns
default value multiplier in 0.001 units

◆ getDefaultValuePrecision()

uint8_t GeneralPurposeChannelBase::getDefaultValuePrecision ( ) const

Returns default precision (number of decimal places)

Returns
default precision in range 0-4

◆ getFormattedValue()

void GeneralPurposeChannelBase::getFormattedValue ( char * result,
int maxSize )

Returns formatted value as char array (including units, precision, etc.)

Parameters
resultpointer to char array
maxSizesize of provided char array

◆ getKeepHistory()

uint8_t GeneralPurposeChannelBase::getKeepHistory ( ) const

Returns keep history flag.

Returns
keep history flag - 1 = keep history, 0 = don't keep history

◆ getNoSpaceAfterValue()

uint8_t GeneralPurposeChannelBase::getNoSpaceAfterValue ( ) const

Returns no space after value.

Returns
no space after value - 1 = no space, 0 = space

◆ getNoSpaceBeforeValue()

uint8_t GeneralPurposeChannelBase::getNoSpaceBeforeValue ( ) const

Returns no space before value.

Returns
no space before value - 1 = no space, 0 = space

◆ getRefreshIntervalMs()

uint16_t GeneralPurposeChannelBase::getRefreshIntervalMs ( ) const

Returns refresh interval in milliseconds.

Returns
refresh interval in milliseconds

◆ getUnitAfterValue()

void GeneralPurposeChannelBase::getUnitAfterValue ( char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const

Returns unit which is displayed after value.

Parameters
unitafter value - max 15 bytes including terminating null byte

◆ getUnitBeforeValue()

void GeneralPurposeChannelBase::getUnitBeforeValue ( char unit[SUPLA_GENERAL_PURPOSE_UNIT_SIZE]) const

Returns unit which is displayed before value.

Parameters
unitbefore value - max 15 bytes including terminating null byte

◆ getValue()

double GeneralPurposeChannelBase::getValue ( )
virtual

Method used to obtain new value for channel.

For custom sensor, please provide either class that inherits from Supla::Sensor::MeasurementDriver or override below getValue() method

Returns
new raw measurment value

◆ getValueAdded()

int64_t GeneralPurposeChannelBase::getValueAdded ( ) const

Returns value added.

Returns
value added in 0.001 units

◆ getValueDivider()

int32_t GeneralPurposeChannelBase::getValueDivider ( ) const

Returns value divider.

Returns
value divider in 0.001 units

◆ getValueMultiplier()

int32_t GeneralPurposeChannelBase::getValueMultiplier ( ) const

Returns value multiplier.

Returns
value multiplier in 0.001 units

◆ getValuePrecision()

uint8_t GeneralPurposeChannelBase::getValuePrecision ( ) const

Returns precision (number of decimal places)

Returns
precision in range 0-4

◆ iterateAlways()

void GeneralPurposeChannelBase::iterateAlways ( )
overridevirtual

Supla::Element::iterateAlways() - called by SuplaDeviceClass::iterate()

Reimplemented from Supla::Element.

◆ onInit()

void GeneralPurposeChannelBase::onInit ( )
overridevirtual

Supla::Element::onInit() - called by SuplaDeviceClass::begin() during initialization.

Reimplemented from Supla::Element.

◆ onLoadConfig()

void GeneralPurposeChannelBase::onLoadConfig ( SuplaDeviceClass * sdc)
overridevirtual

Supla::Element::onLoadConfig() - called by SuplaDeviceClass::loadConfig() during initialization.

Parameters
sdcpointer to SuplaDeviceClass

Reimplemented from Supla::Element.

◆ setChartType()

void GeneralPurposeChannelBase::setChartType ( uint8_t chartType,
bool local = true )

Sets chart type.

For Measurement channel: SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_LINEAR SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_BAR SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_CANDLE For Meter channel: SUPLA_GENERAL_PURPOSE_METER_CHART_TYPE_BAR SUPLA_GENERAL_PURPOSE_METER_CHART_TYPE_LINEAR

Parameters
chartType
local

◆ setDefaultUnitAfterValue()

void GeneralPurposeChannelBase::setDefaultUnitAfterValue ( const char * unit)

Sets default unit which is displayed after value.

Parameters
unitafter value - max 15 bytes including terminating null byte

◆ setDefaultUnitBeforeValue()

void GeneralPurposeChannelBase::setDefaultUnitBeforeValue ( const char * unit)

Sets default unit which is displayed before value.

Parameters
unitbefore value - max 15 bytes including terminating null byte

◆ setDefaultValueAdded()

void GeneralPurposeChannelBase::setDefaultValueAdded ( int64_t added)

Sets default value added.

Parameters
addedvalue in 0.001 units.

◆ setDefaultValueDivider()

void GeneralPurposeChannelBase::setDefaultValueDivider ( int32_t divider)

Sets default value divider.

Parameters
dividervalue in 0.001 units. 0 is ignored

◆ setDefaultValueMultiplier()

void GeneralPurposeChannelBase::setDefaultValueMultiplier ( int32_t multiplier)

Sets default value multiplier.

Parameters
multipliervalue in 0.001 units. 0 is ignored

◆ setDefaultValuePrecision()

void GeneralPurposeChannelBase::setDefaultValuePrecision ( uint8_t precision)

Sets default precision (number of decimal places)

Parameters
precisionvalue in range 0-4

◆ setKeepHistory()

void GeneralPurposeChannelBase::setKeepHistory ( uint8_t keepHistory,
bool local = true )

Sets keep history flag.

If set to 1, history of values will be stored on server.

Parameters
keepHistory
local

◆ setNoSpaceAfterValue()

void GeneralPurposeChannelBase::setNoSpaceAfterValue ( uint8_t noSpaceAfterValue,
bool local = true )

Sets no space after value.

If set to 1, there will be no space added between value and unit after value

Parameters
noSpaceAfterValue
local

◆ setNoSpaceBeforeValue()

void GeneralPurposeChannelBase::setNoSpaceBeforeValue ( uint8_t noSpaceBeforeValue,
bool local = true )

Sets no space before value.

If set to 1, there will be no space added between value and unit before value

Parameters
noSpaceBeforeValue
local

◆ setRefreshIntervalMs()

void GeneralPurposeChannelBase::setRefreshIntervalMs ( int32_t intervalMs,
bool local = true )

Sets refresh interval in milliseconds.

Parameters
intervalMsin milliseconds in 0-65535 range
local

◆ setUnitAfterValue()

void GeneralPurposeChannelBase::setUnitAfterValue ( const char * unit,
bool local = true )

Sets unit which is displayed after value.

Parameters
unitafter value - max 15 bytes including terminating null byte
local

◆ setUnitBeforeValue()

void GeneralPurposeChannelBase::setUnitBeforeValue ( const char * unit,
bool local = true )

Sets unit which is displayed before value.

Parameters
unitbefore value - max 15 bytes including terminating null byte
local

◆ setValue()

void GeneralPurposeChannelBase::setValue ( const double & value)
virtual

Method used to set new value for channel with driver which accepts MeasurementDriver::setValue() method.

Parameters
value

◆ setValueAdded()

void GeneralPurposeChannelBase::setValueAdded ( int64_t added,
bool local = true )

Sets value added.

Parameters
addedin 0.001 units
local

◆ setValueDivider()

void GeneralPurposeChannelBase::setValueDivider ( int32_t divider,
bool local = true )

Sets value divider.

Parameters
dividerin 0.001. 0 is ignored
local

◆ setValueMultiplier()

void GeneralPurposeChannelBase::setValueMultiplier ( int32_t multiplier,
bool local = true )

Sets value multiplier.

Parameters
multiplierin 0.001. 0 is ignored
local

◆ setValuePrecision()

void GeneralPurposeChannelBase::setValuePrecision ( uint8_t precision,
bool local = true )

Sets precision.

Parameters
precisionin range 0-4 (number of decimal places)
local

The documentation for this class was generated from the following files: