|
LightHub 4.6.0
Open-source smart home controller firmware
|
Utility helpers of LightHub. More...
#include <Arduino.h>#include <IPAddress.h>#include "aJSON.h"#include "options.h"#include "item.h"#include "Streaming.h"Go to the source code of this file.
Macros | |
| #define | Q(x) |
| #define | QUOTE(x) |
| #define | VALUE_TO_STRING(x) |
| #define | VALUE(x) |
| #define | VAR_NAME_VALUE(var) |
| #define | serialParamType uint16_t |
| Type for a serial parameter (uint32 on ESP32, uint16 elsewhere). | |
Enumerations | |
| enum | topicType { T_ROOT = 4 , T_DEV = 1 , T_BCST = 2 , T_OUT = 3 } |
Functions | |
| void | PrintBytes (uint8_t *addr, uint8_t count, bool newline) |
| void | SetBytes (uint8_t *addr, uint8_t count, char *out) |
| bool | SetAddr (char *in, uint8_t *addr) |
| uint8_t | HEX2DEC (char i, bool *err) |
| long | getIntFromStr (char **chan) |
| itemCmd | getNumber (char **chan) |
| unsigned long | freeRam () |
| void | parseBytes (const char *str, char separator, byte *bytes, int maxBytes, int base) |
| int | log (const char *str,...) |
| void | printFloatValueToStr (char *valstr, float value) |
| uint32_t | ReadUniqueID (uint32_t *pdwUniqueID) |
| int | _inet_aton (const char *aIPAddrString, IPAddress &aResult) |
| char * | _inet_ntoa_r (IPAddress addr, char *buf, int buflen) |
| void | printIPAddress (IPAddress ipAddress) |
| char * | setTopic (char *buf, int8_t buflen, topicType tt, const char *suffix=NULL) |
| void | printUlongValueToStr (char *valstr, unsigned long value) |
| void | scan_i2c_bus () |
| void | softRebootFunc () |
| bool | isTimeOver (uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t modulo=0) |
| bool | executeCommand (aJsonObject *cmd, int8_t toggle=-1) |
| bool | executeCommand (aJsonObject *cmd, int8_t toggle, itemCmd _itemCmd, aJsonObject *defaultItem=NULL, aJsonObject *defaultEmit=NULL, aJsonObject *defaultCan=NULL) |
| Execute a JSON command object: control an item (Ctrl), publish an emit topic (MQTT) and/or send a CAN command. | |
| itemCmd | mapInt (int32_t arg, aJsonObject *map) |
| uint32_t | millisNZ (uint8_t shift=0, uint32_t mask=0xFFFFFFFFUL) |
| serialParamType | str2SerialParam (char *str) |
| String | toString (const IPAddress &address) |
| bool | getPinVal (uint8_t pin) |
| int | str2regSize (char *str) |
| Преобразует строку в тип регистра. | |
| bool | checkToken (char *token, char *data) |
| bool | isProtectedPin (short pin) |
| bool | i2cReset () |
| uint16_t | getCRC (aJsonObject *in) |
| char * | getStringFromJson (aJsonObject *a, int i) |
| char * | getStringFromJson (aJsonObject *a, const char *name) |
| long | getIntFromJson (aJsonObject *a, int i, long def=0) |
| long | getIntFromJson (aJsonObject *a, const char *name, long def=0) |
| float | getFloatFromJson (aJsonObject *a, int i, float def=0.0) |
| float | getFloatFromJson (aJsonObject *a, const char *name, float def=0.0) |
| long | getIntFromJson (aJsonObject *a, const char *name, int i, long def) |
| float | getFloatFromJson (aJsonObject *a, const char *name, int i, float def) |
| void | setupInPin (short pin) |
| bool | readInPin (short pin) |
| void | writeOutPin (short pin, bool val) |
| template<typename Type> | |
| aJsonObject * | getCreateObject (aJsonObject *a, int n, Type def) |
| aJsonObject * | getCreateObject (aJsonObject *a, int n) |
| template<typename Type> | |
| aJsonObject * | getCreateObject (aJsonObject *a, const char *name, Type def) |
| aJsonObject * | getCreateObject (aJsonObject *a, const char *name) |
| template<typename Type> | |
| aJsonObject * | setValToJson (aJsonObject *a, int n, Type val) |
| template<typename Type> | |
| aJsonObject * | setValToJson (aJsonObject *a, const char *name, Type val) |
| template<typename Type> | |
| aJsonObject * | getCreateObject (aJsonObject *a, const char *name, int n, Type def) |
Utility helpers of LightHub.
Miscellaneous platform and protocol helpers: JSON (aJSON) getters and object creation, command execution (executeCommand), MQTT topic building (setTopic), number/byte/string parsing, IP address utilities, CRC16 of JSON objects, pin access and logging.
| #define Q | ( | x | ) |
| #define serialParamType uint16_t |
Type for a serial parameter (uint32 on ESP32, uint16 elsewhere).
| #define VALUE | ( | x | ) |
| #define VALUE_TO_STRING | ( | x | ) |
| #define VAR_NAME_VALUE | ( | var | ) |
| enum topicType |
MQTT topic prefix types used by setTopic(): T_ROOT - root topic only, T_DEV - device topic, T_BCST - broadcast (incoming) topic, T_OUT - output (status) topic.
| Enumerator | |
|---|---|
| T_ROOT | |
| T_DEV | |
| T_BCST | |
| T_OUT | |
| int _inet_aton | ( | const char * | aIPAddrString, |
| IPAddress & | aResult ) |
Convert an IP address string to an IPAddress.
| char * _inet_ntoa_r | ( | IPAddress | addr, |
| char * | buf, | ||
| int | buflen ) |
Convert an IPAddress to a string in buf.
Same as ipaddr_ntoa, but reentrant since a user-supplied buffer is used.
| addr | ip address in network order to convert |
| buf | target buffer where the string is stored |
| buflen | length of buf |
| bool checkToken | ( | char * | token, |
| char * | data ) |
Validate an authorization token against data.
| bool executeCommand | ( | aJsonObject * | cmd, |
| int8_t | toggle, | ||
| itemCmd | _itemCmd, | ||
| aJsonObject * | defaultItem = NULL, | ||
| aJsonObject * | defaultEmit = NULL, | ||
| aJsonObject * | defaultCan = NULL ) |
Execute a JSON command object: control an item (Ctrl), publish an emit topic (MQTT) and/or send a CAN command.
| cmd | - command object: array (iterate), object with item/emit/can/ icmd/irev/ecmd/erev/act fields, or a legacy string |
| toggle | - 0: use icmd/ecmd, 1: use irev/erev, -1: no toggle |
| _itemCmd | - itemCmd value to send when no command string is given |
| defaultItem/defaultEmit/defaultCan | - fallback targets |
ChangeMe - if no '/' in addr - template not working
| bool executeCommand | ( | aJsonObject * | cmd, |
| int8_t | toggle = -1 ) |
Execute a JSON command object with an empty itemCmd.
| toggle | - 0: use icmd/ecmd, 1: use irev/erev, -1: no toggle |
| unsigned long freeRam | ( | ) |
| uint16_t getCRC | ( | aJsonObject * | in | ) |
| aJsonObject * getCreateObject | ( | aJsonObject * | a, |
| const char * | name ) |
| aJsonObject * getCreateObject | ( | aJsonObject * | a, |
| const char * | name, | ||
| int | n, | ||
| Type | def ) |
| aJsonObject * getCreateObject | ( | aJsonObject * | a, |
| const char * | name, | ||
| Type | def ) |
| aJsonObject * getCreateObject | ( | aJsonObject * | a, |
| int | n ) |
| aJsonObject * getCreateObject | ( | aJsonObject * | a, |
| int | n, | ||
| Type | def ) |
| float getFloatFromJson | ( | aJsonObject * | a, |
| const char * | name, | ||
| float | def = 0.0 ) |
| float getFloatFromJson | ( | aJsonObject * | a, |
| const char * | name, | ||
| int | i, | ||
| float | def ) |
| float getFloatFromJson | ( | aJsonObject * | a, |
| int | i, | ||
| float | def = 0.0 ) |
| long getIntFromJson | ( | aJsonObject * | a, |
| const char * | name, | ||
| int | i, | ||
| long | def ) |
| long getIntFromJson | ( | aJsonObject * | a, |
| const char * | name, | ||
| long | def = 0 ) |
| long getIntFromJson | ( | aJsonObject * | a, |
| int | i, | ||
| long | def = 0 ) |
| long getIntFromStr | ( | char ** | chan | ) |
Parse an integer from *chan, advancing the pointer past it (after ',').
| itemCmd getNumber | ( | char ** | chan | ) |
Parse a typed number (int / tens / float) from *chan into an itemCmd.
| bool getPinVal | ( | uint8_t | pin | ) |
| char * getStringFromJson | ( | aJsonObject * | a, |
| const char * | name ) |
| char * getStringFromJson | ( | aJsonObject * | a, |
| int | i ) |
| uint8_t HEX2DEC | ( | char | i, |
| bool * | err ) |
Convert one hex digit to decimal, setting err on failure.
| bool i2cReset | ( | ) |
Recover the I2C bus by toggling SCL.
| bool isProtectedPin | ( | short | pin | ) |
| bool isTimeOver | ( | uint32_t | timestamp, |
| uint32_t | currTime, | ||
| uint32_t | time, | ||
| uint32_t | modulo = 0 ) |
| int log | ( | const char * | str, |
| ... ) |
Log a formatted message to the debug serial.
| uint32_t millisNZ | ( | uint8_t | shift = 0, |
| uint32_t | mask = 0xFFFFFFFFUL ) |
| void parseBytes | ( | const char * | str, |
| char | separator, | ||
| byte * | bytes, | ||
| int | maxBytes, | ||
| int | base ) |
Parse a delimited hex string into a byte array.
| void PrintBytes | ( | uint8_t * | addr, |
| uint8_t | count, | ||
| bool | newline ) |
Print count bytes from addr to the debug serial as hex.
| void printFloatValueToStr | ( | char * | valstr, |
| float | value ) |
Convert a float to a fixed-format string for MQTT publishing.
| void printIPAddress | ( | IPAddress | ipAddress | ) |
Print an IP address to the debug serial.
| void printUlongValueToStr | ( | char * | valstr, |
| unsigned long | value ) |
Convert an unsigned long to a string for MQTT publishing.
| bool readInPin | ( | short | pin | ) |
| uint32_t ReadUniqueID | ( | uint32_t * | pdwUniqueID | ) |
Read the chip unique id (MAC) into 32-bit words.
| void scan_i2c_bus | ( | ) |
Scan the I2C bus and log the found devices.
| bool SetAddr | ( | char * | in, |
| uint8_t * | addr ) |
Parse a hex string (AA:BB:...) into a MAC/EUI byte buffer.
| void SetBytes | ( | uint8_t * | addr, |
| uint8_t | count, | ||
| char * | out ) |
Format count bytes from addr as a hex string into out.
| char * setTopic | ( | char * | buf, |
| int8_t | buflen, | ||
| topicType | tt, | ||
| const char * | suffix = NULL ) |
Build the full MQTT topic prefix of the given type in buf.
| void setupInPin | ( | short | pin | ) |
Configure a pin as an input.
| aJsonObject * setValToJson | ( | aJsonObject * | a, |
| const char * | name, | ||
| Type | val ) |
| aJsonObject * setValToJson | ( | aJsonObject * | a, |
| int | n, | ||
| Type | val ) |
| void softRebootFunc | ( | ) |
Perform a soft reboot of the device.
| int str2regSize | ( | char * | str | ) |
Преобразует строку в тип регистра.
Parse a register size string (Modbus).
| str | Строка с типом регистра. |
| serialParamType str2SerialParam | ( | char * | str | ) |
Parse a serial parameter string (e.g. baud rate / parity) to its code.
| String toString | ( | const IPAddress & | address | ) |
| void writeOutPin | ( | short | pin, |
| bool | val ) |
Write a value to an output pin.