|
LightHub 4.6.0
Open-source smart home controller firmware
|
A single LightHub item (virtual channel). More...
#include <item.h>
Public Member Functions | |
| Item (char *name, aJsonObject *_items=items) | |
| Create an item by name from the items object. | |
| Item (aJsonObject *obj, aJsonObject *_items=items) | |
| Adopt an existing items-array element as this item. | |
| Item (uint16_t num, uint8_t subItem, aJsonObject *_items=items) | |
| Create an item by CAN id (CANDRV builds). | |
| ~Item () | |
| boolean | isValid () |
| boolean | Setup () |
| void | Stop () |
| int | Ctrl (itemCmd cmd, char *subItem=NULL, uint8_t flags=0, bool authorized=false) |
| Main control entry point: execute a command/value on this item. | |
| int | Ctrl (char *payload, char *subItem=NULL, int remoteID=0) |
| int | remoteCtrl (itemCmd cmd, int remoteID, char *subItem=NULL, char *authToken=NULL) |
| int | getArg (short n=0) |
| float | getFloatArg (short n=0) |
| short | getArgCount () |
| long int | getVal () |
| uint8_t | getSubtype () |
| uint8_t | getCmd () |
| long int | getExt () |
| void | setExt (long int par) |
| chPersistent * | getPersistent () |
| chPersistent * | setPersistent (chPersistent *par) |
| void | setCmd (uint8_t cmdValue) |
| uint32_t | getFlag (uint32_t flag=FLAG_MASK) |
| void | setFlag (uint32_t flag) |
| void | clearFlag (uint32_t flag) |
| void | setVal (long int par) |
| void | setFloatVal (float par) |
| void | setSubtype (uint8_t par) |
| int | Poll (int cause) |
| int | SendStatus (long sendFlags, char *subItem=NULL) |
| int | SendStatusImmediate (itemCmd st, long sendFlags, char *subItem=NULL, bool tetain=true) |
| int | isActive () |
| int | getChanType () |
| int | On () |
| int | Off () |
| int | Toggle () |
| int | scheduleCommand (itemCmd cmd, bool authorized) |
| int | scheduleOppositeCommand (itemCmd cmd, short isActiveNow, bool authorized) |
| int | isScheduled () |
| char * | getSubItemStrById (uint8_t subItem) |
| uint8_t | getSubitemId (char *subItem) |
Public Attributes | |
| aJsonObject * | rootItems |
| Pointers into the items JSON tree (root object, item array, its arg/val/ext elements). | |
| aJsonObject * | itemArr |
| aJsonObject * | itemArg |
| aJsonObject * | itemVal |
| aJsonObject * | itemExt |
| uint8_t | itemType |
| Channel type (CH_*) resolved from I_TYPE. | |
| abstractOut * | driver |
| Linked output driver instance (shared per channel type) or NULL. | |
Protected Member Functions | |
| bool | digGroup (aJsonObject *itemArr, itemCmd *cmd=NULL, char *subItem=NULL, bool authorized=false, uint8_t ctrlFlags=0) |
| long int | limitSetValue () |
| int | VacomSetFan (itemCmd st) |
| int | VacomSetHeat (itemCmd st) |
| int | modbusDimmerSet (itemCmd st) |
| int | modbusDimmerSet (int addr, uint16_t _reg, int _regType, int _mask, uint16_t value) |
| void | mb_fail (int result=0) |
| void | Parse () |
| int | checkModbusDimmer () |
| int | checkModbusDimmer (int data) |
| int | checkRetry () |
| void | sendDelayedStatus () |
| int | checkFM () |
Protected Attributes | |
| char | defaultSubItem [16] |
| int | defaultSuffixCode |
A single LightHub item (virtual channel).
Item wraps one entry of the global items JSON object: a virtual channel of a given type (CH_*) with its arguments, current value, last command, optional extension data and a driver instance. Items are the core abstraction of the system: physical outputs (relays, DMX, Modbus, AC), groups and services are all items, addressed by name ("name", "name/subItem" or "name/subItem/suffix").
All external control is funneled through the Ctrl() overloads; the resulting state is published to MQTT (and CAN when enabled) via SendStatus()/SendStatusImmediate().
| Item::Item | ( | char * | name, |
| aJsonObject * | _items = items ) |
| Item::Item | ( | aJsonObject * | obj, |
| aJsonObject * | _items = items ) |
Adopt an existing items-array element as this item.
| obj | - pointer to the item array inside the items object |
| Item::Item | ( | uint16_t | num, |
| uint8_t | subItem, | ||
| aJsonObject * | _items = items ) |
Create an item by CAN id (CANDRV builds).
| num | - CAN identifier of the item |
| subItem | - default subItem id, optionally OR'ed with SUBITEM_IS_COMMAND |
| Item::~Item | ( | ) |
Destructor: releases the driver if it is not shared with another item.
|
protected |
(Legacy) Poll Vacom fan motor registers and publish the state as JSON.
|
protected |
(Legacy) Poll the Modbus dimmer register and update stored value/status.
|
protected |
(Legacy) Compare a polled Modbus register data with the stored value and resync status.
|
protected |
Retry the last failed transaction if FLAG_SEND_RETRY is set.
| void Item::clearFlag | ( | uint32_t | flag | ) |
Clear FLAG_* bits in I_CMD, preserving the CMD_* bits.
| int Item::Ctrl | ( | char * | payload, |
| char * | subItem = NULL, | ||
| int | remoteID = 0 ) |
Parse a text payload (command word, number, color, optional "token@command" authorization prefix) and route it to Ctrl(itemCmd, ...).
| remoteID | - if non-zero, forward the command to that remote node via CAN |
possible problem here with truncated default
| int Item::Ctrl | ( | itemCmd | cmd, |
| char * | subItem = NULL, | ||
| uint8_t | flags = 0, | ||
| bool | authorized = false ) |
Main control entry point: execute a command/value on this item.
| cmd | - command and/or value (see itemCmd) |
| subItem | - subchannel name or NULL (default subItem is used) |
| flags | - CTRL_* group execution flags |
| authorized | - true if the caller is authorized (unlocks DISABLE, etc.) |
possible problem here with truncated default
DELAYED COMMANDS processing
Common (GRP & NO GRP) commands
bool oppositeCommandToBeSchedulled = (suffixCode==S_CMD) && allowRecursion && cmd.isValue();
rest of Legacy monolite core code (to be refactored ) BEGIN ///
rest of Legacy monolite core code (to be refactored ) END ///
|
protected |
Recursively walk a group's member list. If cmd is given - execute it on every member (non-recursively); otherwise check members' activity and return true if any is active.
| int Item::getArg | ( | short | n = 0 | ) |
| short Item::getArgCount | ( | ) |
| int Item::getChanType | ( | ) |
| uint8_t Item::getCmd | ( | ) |
| long int Item::getExt | ( | ) |
| uint32_t Item::getFlag | ( | uint32_t | flag = FLAG_MASK | ) |
| float Item::getFloatArg | ( | short | n = 0 | ) |
| chPersistent * Item::getPersistent | ( | ) |
| uint8_t Item::getSubitemId | ( | char * | subItem | ) |
| char * Item::getSubItemStrById | ( | uint8_t | subItem | ) |
| uint8_t Item::getSubtype | ( | ) |
| long int Item::getVal | ( | ) |
| int Item::isActive | ( | ) |
| int Item::isScheduled | ( | ) |
| boolean Item::isValid | ( | ) |
|
protected |
|
protected |
Mark the last Modbus transaction as failed (sets FLAG_SEND_RETRY).
|
protected |
(Legacy) Low-level Modbus write of value to register _reg of slave addr.
|
protected |
(Legacy) Write dimmer value to the Modbus register of this item.
|
inline |
Turn the channel OFF.
|
inline |
Turn the channel ON.
|
protected |
Parse the item array: resolve type, arg/val/cmd/ext elements and the driver.
| int Item::Poll | ( | int | cause | ) |
Periodic poll of the item. Fires armed delayed (S_DELAYED) commands, retries failed transactions and delegates to the driver.
| cause | - POLLING_SLOW/POLLING_FAST/POLLING_INT/POLLING_1S |
| int Item::remoteCtrl | ( | itemCmd | cmd, |
| int | remoteID, | ||
| char * | subItem = NULL, | ||
| char * | authToken = NULL ) |
Forward a command to a remote LightHub node over CAN.
| cmd | - command to send, |
| remoteID | - target node id |
| authToken | - optional authorization token |
| int Item::scheduleCommand | ( | itemCmd | cmd, |
| bool | authorized ) |
Arm a delayed command: execute cmd's command code after the delay stored in cmd parameter (ms).
| authorized | - stored with the timer. |
| int Item::scheduleOppositeCommand | ( | itemCmd | cmd, |
| short | isActiveNow, | ||
| bool | authorized ) |
Arm the opposite command after the given delay (momentary action): e.g. CMD_ON -> CMD_OFF after N ms, CMD_XON -> CMD_XOFF, etc.
| isActiveNow | - current activity state of the channel |
|
protected |
Publish a pending (deferred) status if the network is up.
| int Item::SendStatus | ( | long | sendFlags, |
| char * | subItem = NULL ) |
Publish current command/value/flags to MQTT.
| sendFlags | - FLAG_COMMAND/FLAG_PARAMETERS/FLAG_FLAGS and FLAG_SEND_IMMEDIATE/FLAG_SEND_DEFFERED options Defers the publish (sets a pending flag) if the network is busy or RAM is low. |
| int Item::SendStatusImmediate | ( | itemCmd | st, |
| long | sendFlags, | ||
| char * | subItem = NULL, | ||
| bool | tetain = true ) |
Publish the given status to MQTT immediately without deferral.
subItem
| void Item::setCmd | ( | uint8_t | cmdValue | ) |
Store a command code in I_CMD, preserving the FLAG_* bits.
| void Item::setExt | ( | long int | par | ) |
Store an integer extension value in I_EXT.
| void Item::setFlag | ( | uint32_t | flag | ) |
Set FLAG_* bits in I_CMD, preserving the CMD_* bits.
| void Item::setFloatVal | ( | float | par | ) |
Store a float value in I_VAL (only if I_VAL is a scalar).
| chPersistent * Item::setPersistent | ( | chPersistent * | par | ) |
Attach driver-persistent data to I_EXT.
| void Item::setSubtype | ( | uint8_t | par | ) |
Store the storage subtype (ST_*) of I_VAL.
| boolean Item::Setup | ( | ) |
Initialize the driver hardware.
| void Item::setVal | ( | long int | par | ) |
Store an integer value in I_VAL (only if I_VAL is a scalar).
| void Item::Stop | ( | ) |
Stop the driver and release its hardware resources.
|
inline |
Toggle the channel ON/OFF.
|
protected |
(Legacy) Set Vacom fan speed over Modbus.
|
protected |
(Legacy) Set Vacom heat temperature over Modbus.
|
protected |
|
protected |
| abstractOut* Item::driver |
Linked output driver instance (shared per channel type) or NULL.
| aJsonObject * Item::itemArg |
| aJsonObject * Item::itemArr |
| aJsonObject * Item::itemExt |
| uint8_t Item::itemType |
Channel type (CH_*) resolved from I_TYPE.
| aJsonObject * Item::itemVal |
| aJsonObject* Item::rootItems |
Pointers into the items JSON tree (root object, item array, its arg/val/ext elements).