Uniot Core
0.9.0
Loading...
Searching...
No Matches
Common

Common utilities and macros for the Uniot Core. More...

Collaboration diagram for Common:

Classes

struct  FourCC< a, b, c, d >
 Creates a four-character code (FourCC) value from template parameters. More...
 

Macros

#define UNIOT_SEMVER_TO_INT(major, minor, patch)
 Packs a semantic version into one integer.
 
#define UNIOT_CORE_VERSION   UNIOT_SEMVER_TO_INT(0, 9, 0)
 Version of Uniot Core, reported in the device's status packet.
 
#define UNIOT_MQTT_HOST   "mqtt.uniot.io"
 Hostname of the MQTT broker the device connects to.
 
#define UNIOT_MQTT_PORT   1883
 TCP port of the MQTT broker.
 
#define UNIOT_WIFI_AP_PREFIX   "UNIOT"
 Prefix for the generated configuration AP SSID.
 
#define UNIOT_WIFI_AP_PASSWORD   ""
 WPA2 password for the configuration AP.
 
#define UNIOT_WIFI_REBOOT_RESET_COUNT   5
 Consecutive reboots that reset the stored network configuration.
 
#define UNIOT_WIFI_REBOOT_WINDOW_MS   10000
 How long after boot a reboot still counts towards the reset, in ms.
 
#define UNIOT_LISP_HEAP   24576
 Bytes of heap the Lisp interpreter is given at startup.
 
#define UNIOT_LISP_MAX_EVAL_STACK   1280
 Bytes of C stack an evaluation may spend before a script is abandoned.
 
#define UNIOT_WIFI_NO_SLEEP   0
 Keep the WiFi radio awake between beacon intervals (ESP32 only).
 
#define COUNT_OF(arr)
 Calculates the number of elements in a statically allocated array.
 
#define ARRAY_ELEMENT_SAFE(arr, index)
 Provides safe array access with bounds checking.
 
#define FOURCC(name)
 Creates a FourCC constant from a string literal.
 
#define ALIAS_IMPLICIT_FUNCTION(high, low)
 Creates an alias for a function that forwards all arguments implicitly.
 
#define ALIAS_EXPLICIT_FUNCTION(high, low)
 Creates an alias for a template function that forwards all arguments explicitly.
 

Functions

template<typename... Args>
void UNUSED (Args &&...args)
 Utility function to mark function parameters as intentionally unused.
 
uint32_t CRC32 (const void *data, size_t length, uint32_t crc=0)
 Calculates CRC32-C (Castagnoli) checksum for data integrity verification.
 
template<typename T>
using uniot::UniquePointer = std::unique_ptr<T>
 Type alias for std::unique_ptr with cleaner syntax.
 
template<typename T>
using uniot::SharedPointer = std::shared_ptr<T>
 Type alias for std::shared_ptr with cleaner syntax.
 
template<typename T_First, typename T_Second>
using uniot::Pair = std::pair<T_First, T_Second>
 Type alias for std::pair with cleaner syntax.
 
template<typename T, typename... Args>
auto uniot::MakeShared (Args &&...args) -> decltype(std::make_shared< T >(std::forward< Args >(args)...))
 Creates a shared pointer instance, alias for std::make_shared.
 
template<typename T, typename... Args>
auto uniot::MakeUnique (Args &&...args) -> decltype(std::make_unique< T >(std::forward< Args >(args)...))
 Creates a unique pointer instance, alias for std::make_unique.
 
template<typename... Args>
auto uniot::MakePair (Args &&...args) -> decltype(std::make_pair(std::forward< Args >(args)...))
 Creates a pair instance, alias for std::make_pair.
 

Detailed Description

Common utilities and macros for the Uniot Core.

Macro Definition Documentation

◆ ALIAS_EXPLICIT_FUNCTION

#define ALIAS_EXPLICIT_FUNCTION ( high,
low )
Value:
template <typename T, typename... Args> \
inline auto high(Args &&...args) -> decltype(low<T>(std::forward<Args>(args)...)) { \
return low<T>(std::forward<Args>(args)...); \
}

Creates an alias for a template function that forwards all arguments explicitly.

Similar to ALIAS_IMPLICIT_FUNCTION but maintains the explicit template parameter.

Parameters
highNew function name
lowOriginal function being aliased

◆ ALIAS_IMPLICIT_FUNCTION

#define ALIAS_IMPLICIT_FUNCTION ( high,
low )
Value:
template <typename... Args> \
inline auto high(Args &&...args) -> decltype(low(std::forward<Args>(args)...)) { \
return low(std::forward<Args>(args)...); \
}

Creates an alias for a function that forwards all arguments implicitly.

Used to expose standard library functions through a custom namespace with the same parameter forwarding behavior.

Parameters
highNew function name
lowOriginal function being aliased

◆ ARRAY_ELEMENT_SAFE

#define ARRAY_ELEMENT_SAFE ( arr,
index )
Value:
((arr)[(((index) < COUNT_OF(arr)) ? (index) : (COUNT_OF(arr) - 1))])
#define COUNT_OF(arr)
Calculates the number of elements in a statically allocated array.
Definition Common.h:241

Provides safe array access with bounds checking.

Returns the element at the specified index if within bounds, otherwise returns the last element.

◆ COUNT_OF

#define COUNT_OF ( arr)
Value:
(sizeof(arr) / sizeof(arr[0]))

Calculates the number of elements in a statically allocated array.

◆ FOURCC

#define FOURCC ( name)
Value:
FourCC<ARRAY_ELEMENT_SAFE(#name, 0), ARRAY_ELEMENT_SAFE(#name, 1), ARRAY_ELEMENT_SAFE(#name, 2), ARRAY_ELEMENT_SAFE(#name, 3)>::Value
#define ARRAY_ELEMENT_SAFE(arr, index)
Provides safe array access with bounds checking.
Definition Common.h:250
Creates a four-character code (FourCC) value from template parameters.
Definition Common.h:196

Creates a FourCC constant from a string literal.

Uses up to the first four characters of the string to create a unique identifier. If the string has fewer than 4 characters, the remaining positions will be filled with the last character.

◆ UNIOT_CORE_VERSION

#define UNIOT_CORE_VERSION   UNIOT_SEMVER_TO_INT(0, 9, 0)

Version of Uniot Core, reported in the device's status packet.

Neither this nor UNIOT_SEMVER_TO_INT is guarded, so a sketch cannot redefine them: they describe the core that is running, not something a sketch chooses. Keep this in step with the version in library.json.

◆ UNIOT_LISP_HEAP

#define UNIOT_LISP_HEAP   24576

Bytes of heap the Lisp interpreter is given at startup.

Allocated once in lisp_create() and never grown, so it is a fixed claim on system heap for the life of the machine. Creating a machine costs ~3150 bytes before a script runs, so what a script actually has is this value less that. The library refuses anything above 65535.

◆ UNIOT_LISP_MAX_EVAL_STACK

#define UNIOT_LISP_MAX_EVAL_STACK   1280

Bytes of C stack an evaluation may spend before a script is abandoned.

Interpreter recursion runs on the C stack, and overrunning it resets the device rather than raising an error. The budget is in bytes, not levels of nesting, since a level that prints costs several times what a bare call costs.

It is not simply the stack that is free. The guard measures from where lisp_eval() was entered and stops seeing anything once a primitive or the error path takes over, so the true peak is the budget plus roughly 600 bytes paid afterwards, during unwinding. Each value below is measured on target against the full firmware, not the standalone tool, with the probe in src/main.cpp; measure a budget before changing it rather than scaling it from another part.

Keep the ESP32 branches separate: defined(ESP32) is true for the C3, so collapsing them means a retune of one silently retunes the other.

◆ UNIOT_MQTT_HOST

#define UNIOT_MQTT_HOST   "mqtt.uniot.io"

Hostname of the MQTT broker the device connects to.

◆ UNIOT_MQTT_PORT

#define UNIOT_MQTT_PORT   1883

TCP port of the MQTT broker.

◆ UNIOT_SEMVER_TO_INT

#define UNIOT_SEMVER_TO_INT ( major,
minor,
patch )
Value:
((major * 10000) + (minor * 100) + patch)

Packs a semantic version into one integer.

Uses the same formula as uniot-lisp's SEMVER_TO_INT, so a core version and an interpreter version are comparable and read the same way. It carries its own name so that including both headers cannot make one definition silently stand for the other.

◆ UNIOT_WIFI_AP_PASSWORD

#define UNIOT_WIFI_AP_PASSWORD   ""

WPA2 password for the configuration AP.

An empty string creates an open network. WPA2 requires at least 8 characters; a shorter non-empty password makes softAP() fail and no configuration AP is started.

◆ UNIOT_WIFI_AP_PREFIX

#define UNIOT_WIFI_AP_PREFIX   "UNIOT"

Prefix for the generated configuration AP SSID.

The full SSID is "PREFIX-DEVICEID", upper-cased.

◆ UNIOT_WIFI_NO_SLEEP

#define UNIOT_WIFI_NO_SLEEP   0

Keep the WiFi radio awake between beacon intervals (ESP32 only).

Set to 1 to disable modem sleep once the station associates. This avoids association drops caused by missed DTIM beacons on a marginal link, at the cost of a significantly higher idle current. Leave at 0 on battery devices.

◆ UNIOT_WIFI_REBOOT_RESET_COUNT

#define UNIOT_WIFI_REBOOT_RESET_COUNT   5

Consecutive reboots that reset the stored network configuration.

Each reboot within UNIOT_WIFI_REBOOT_WINDOW_MS of the last one increments a counter held in ctrl.cbor; reaching this many clears the credentials. It is the only reset path on a device with no button, so it is a deliberate gesture – power-cycling this many times in quick succession – and the count trades ease of use against wiping a device by accident on flaky power.

This is the count used once the mechanism is switched on, not whether it is on. UniotCore leaves reboot-reset disabled until configWiFiResetOnReboot() asks for it, precisely because of that accidental-wipe risk; this value is what that call uses when given no count of its own.

◆ UNIOT_WIFI_REBOOT_WINDOW_MS

#define UNIOT_WIFI_REBOOT_WINDOW_MS   10000

How long after boot a reboot still counts towards the reset, in ms.

Staying up longer than this clears the counter, so ordinary restarts do not accumulate towards a reset. Ignored when the count is UINT8_MAX.

Typedef Documentation

◆ Pair

template<typename T_First, typename T_Second>
using uniot::Pair = std::pair<T_First, T_Second>

Type alias for std::pair with cleaner syntax.

Template Parameters
T_FirstType of the first element
T_SecondType of the second element

◆ SharedPointer

template<typename T>
using uniot::SharedPointer = std::shared_ptr<T>

Type alias for std::shared_ptr with cleaner syntax.

Template Parameters
TType of the managed object

◆ UniquePointer

template<typename T>
using uniot::UniquePointer = std::unique_ptr<T>

Type alias for std::unique_ptr with cleaner syntax.

Template Parameters
TType of the managed object

Function Documentation

◆ CRC32()

uint32_t CRC32 ( const void * data,
size_t length,
uint32_t crc = 0 )
inline

Calculates CRC32-C (Castagnoli) checksum for data integrity verification.

This function implements the CRC-32C polynomial used in iSCSI standard.

Parameters
dataPointer to data buffer
lengthSize of data buffer in bytes
crcInitial CRC value (defaults to 0)
Return values
uint32_tCRC32 checksum value

◆ MakePair()

template<typename... Args>
auto uniot::MakePair ( Args &&... args) -> decltype(std::make_pair(std::forward<Args>(args)...))
inline

Creates a pair instance, alias for std::make_pair.

◆ MakeShared()

template<typename T, typename... Args>
auto uniot::MakeShared ( Args &&... args) -> decltype(std::make_shared<T>(std::forward<Args>(args)...))
inline

Creates a shared pointer instance, alias for std::make_shared.

◆ MakeUnique()

template<typename T, typename... Args>
auto uniot::MakeUnique ( Args &&... args) -> decltype(std::make_unique<T>(std::forward<Args>(args)...))
inline

Creates a unique pointer instance, alias for std::make_unique.

◆ UNUSED()

template<typename... Args>
void UNUSED ( Args &&... args)
inline

Utility function to mark function parameters as intentionally unused.

Prevents compiler warnings about unused parameters by explicitly consuming them.

Template Parameters
ArgsVariadic template parameter types
Parameters
argsParameters to mark as used