Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::LispDevice Class Reference

#include <LispDevice.h>

Inheritance diagram for uniot::LispDevice:
[legend]

Public Member Functions

 LispDevice ()
 Constructs a LispDevice instance.
 
virtual void syncSubscriptions () override
 Sets up MQTT topic subscriptions for the device.
 
unLispgetLisp ()
 Provides access to the unLisp interpreter instance.
 
void setEventInterceptor (LispEventInterceptor interceptor)
 
void publishLispEvent (const String &eventID, int32_t value)
 
void runStoredCode ()
 Loads and executes previously stored code from persistent storage.
 
bool store ()
 Stores the current script state to persistent storage.
 
virtual void onEventReceived (unsigned int topic, int msg) override
 Processes events received from the unLisp interpreter.
 
virtual void handle (const String &topic, const Bytes &payload) override
 Processes MQTT messages received on subscribed topics.
 
void handleScript (const Bytes &payload)
 Processes script payloads received via MQTT.
 
void handleEvent (const Bytes &payload)
 Processes event payloads received via MQTT.
 
- Public Member Functions inherited from uniot::MQTTDevice
 MQTTDevice ()
 Constructs a new MQTTDevice instance.
 
virtual ~MQTTDevice ()
 Virtual destructor that handles cleanup and unregistration from MQTTKit.
 
const String & getDeviceId () const
 Gets the device identifier.
 
const String & getOwnerId () const
 Gets the owner identifier.
 
const String & subscribe (const String &topic)
 Subscribes to a specific MQTT topic.
 
const String & subscribeDevice (const String &subTopic)
 Subscribes to a device-specific subtopic.
 
const String & subscribeGroup (const String &groupId, const String &subTopic)
 Subscribes to a group-specific subtopic.
 
bool unsubscribe (const String &topic)
 Unsubscribes from a specific topic.
 
void unsubscribeFromAll ()
 Unsubscribes from all subscribed topics.
 
bool isSubscribed (const String &topic)
 Checks if the device is subscribed to a given topic.
 
bool isTopicMatch (const String &storedTopic, const String &incomingTopic) const
 Determines if a stored topic matches an incoming topic string using MQTT wildcards.
 
void publish (const String &topic, const Bytes &payload, bool retained=false, bool sign=false)
 Publishes a message to a specific topic.
 
void publishDevice (const String &subTopic, const Bytes &payload, bool retained=false, bool sign=false)
 Publishes a message to a device-specific subtopic.
 
void publishGroup (const String &groupId, const String &subTopic, const Bytes &payload, bool retained=false, bool sign=false)
 Publishes a message to a group-specific subtopic.
 
void publishEmptyDevice (const String &subTopic)
 Publishes an empty message to a device-specific subtopic with retained flag set.
 
- Public Member Functions inherited from uniot::CBORStorage
 CBORStorage (const String &path)
 Constructs a new CBORStorage object.
 
virtual ~CBORStorage ()
 Virtual destructor.
 
CBORObjectobject ()
 Get access to the underlying CBORObject.
 
virtual bool restore () override
 Restore the CBOR object from the filesystem.
 
virtual bool clean () override
 Clean the CBOR object and remove the storage file.
 
- Public Member Functions inherited from uniot::Storage
 Storage (const String &path)
 Constructs a Storage object for a specific file.
 
virtual ~Storage ()
 Destructor.
 
- Public Member Functions inherited from uniot::EventListener< unsigned int, int, Bytes >
virtual ~EventListener ()=default
 Virtual destructor.
 
virtual type_id getTypeId () const override
 Get the type ID of this class for RTTI.
 
EventListenerlistenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListenerstopListeningToEvent (unsigned int topic)
 Unsubscribe from events of a specific topic.
 
bool isListeningToEvent (unsigned int topic)
 Check if this listener is subscribed to a specific topic.
 
virtual ~EventListener ()=default
 Virtual destructor.
 
virtual type_id getTypeId () const override
 Get the type ID of this class for RTTI.
 
EventListenerlistenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListenerstopListeningToEvent (unsigned int topic)
 Unsubscribe from events of a specific topic.
 
bool isListeningToEvent (unsigned int topic)
 Check if this listener is subscribed to a specific topic.
 
- Public Member Functions inherited from uniot::EventEmitter< unsigned int, int, Bytes >
virtual ~EventEmitter ()=default
 Virtual destructor to ensure proper cleanup of derived classes.
 
void emitEvent (unsigned int topic, int msg)
 Emits an event to all registered event buses.
 
virtual ~EventEmitter ()=default
 Virtual destructor to ensure proper cleanup of derived classes.
 
void emitEvent (unsigned int topic, int msg)
 Emits an event to all registered event buses.
 
- Public Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data >
virtual ~EventEntity ()
 Destructor - disconnects from all connected EventBus instances.
 
bool sendDataToChannel (T_topic channel, T_data data)
 Sends data to a specific channel on all connected EventBus instances.
 
void receiveDataFromChannel (T_topic channel, DataChannelCallback callback)
 Receives data from a specific channel on all connected EventBus instances.
 

Additional Inherited Members

- Public Types inherited from uniot::EventEntity< T_topic, T_msg, T_data >
using DataChannelCallback = std::function<void(unsigned int, bool, T_data)>
 Callback type for handling data received from channels.
 
- Static Public Member Functions inherited from uniot::Storage
static void unmount ()
 Explicitly unmounts the filesystem.
 
- Protected Member Functions inherited from uniot::Storage
void setPath (const String &path)
 Sets the file path, ensuring it starts with "/".
 
- Protected Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data >
bool connectUnique (EventBus< T_topic, T_msg, T_data > *eventBus)
 Connects to an EventBus instance if not already connected.
 
- Protected Attributes inherited from uniot::CBORStorage
CBORObject mCbor
 The CBOR object used for data serialization/deserialization.
 
- Protected Attributes inherited from uniot::Storage
Bytes mData
 The byte array containing the data to be stored or the loaded data.
 
String mPath
 The file path where data is stored.
 
- Protected Attributes inherited from uniot::EventEntity< T_topic, T_msg, T_data >
IterableQueue< EventBus< T_topic, T_msg, T_data > * > mEventBusQueue
 Queue of EventBus instances this entity is connected to.
 

Constructor & Destructor Documentation

◆ LispDevice()

uniot::LispDevice::LispDevice ( )
inline

Constructs a LispDevice instance.

Initializes the device with default settings and registers event listeners for unLisp message, request, and event outputs.

Member Function Documentation

◆ getLisp()

unLisp & uniot::LispDevice::getLisp ( )
inline

Provides access to the unLisp interpreter instance.

Return values
unLisp&The unLisp interpreter instance

◆ handle()

virtual void uniot::LispDevice::handle ( const String & topic,
const Bytes & payload )
inlineoverridevirtual

Processes MQTT messages received on subscribed topics.

Routes incoming messages to appropriate handlers based on topic matching.

Parameters
topicThe MQTT topic of the received message
payloadThe message payload data

Implements uniot::MQTTDevice.

◆ handleEvent()

void uniot::LispDevice::handleEvent ( const Bytes & payload)
inline

Processes event payloads received via MQTT.

Forwards valid events to the unLisp interpreter for processing.

Parameters
payloadCBOR encoded payload containing event data

◆ handleScript()

void uniot::LispDevice::handleScript ( const Bytes & payload)
inline

Processes script payloads received via MQTT.

Extracts script code, persistence flag, and calculates checksum. Determines whether to run the script based on current state and script identity. If executed, stores the script state for potential future use.

Parameters
payloadCBOR encoded payload containing script and execution parameters

◆ onEventReceived()

virtual void uniot::LispDevice::onEventReceived ( unsigned int topic,
int msg )
inlineoverridevirtual

Processes events received from the unLisp interpreter.

Handles various event types including errors, logs, debug messages, and system events from the unLisp environment.

Parameters
topicThe event topic identifier
msgThe message identifier within the topic

Implements uniot::EventListener< unsigned int, int, Bytes >.

◆ publishLispEvent()

void uniot::LispDevice::publishLispEvent ( const String & eventID,
int32_t value )
inline

◆ runStoredCode()

void uniot::LispDevice::runStoredCode ( )
inline

Loads and executes previously stored code from persistent storage.

Restores code, persistence flag, and checksum from CBOR storage. If persistence is enabled and code exists, runs the stored code.

◆ setEventInterceptor()

void uniot::LispDevice::setEventInterceptor ( LispEventInterceptor interceptor)
inline

◆ store()

bool uniot::LispDevice::store ( )
inlinevirtual

Stores the current script state to persistent storage.

Saves persistence flag, checksum, and code (if persistence is enabled) to the CBOR storage.

Return values
trueStorage operation was successful
falseStorage operation failed

Reimplemented from uniot::CBORStorage.

◆ syncSubscriptions()

virtual void uniot::LispDevice::syncSubscriptions ( )
inlineoverridevirtual

Sets up MQTT topic subscriptions for the device.

Subscribes to device-specific script topics and group-wide event topics to receive scripts and events from the MQTT broker.

Implements uniot::MQTTDevice.


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