Communication Protocol based on Streams. Uses Multiplexing to differentiate data channels. It is originally being developed for the communication between the RadonUlzer and the DroidControlShip projects.
pio pkg install --library "gabryelreyes/SerialMuxProt@^2.0.0"
lib_deps
manually:lib_deps =
gabryelreyes/SerialMuxProt@^2.0.0
cd python/SerialMuxProt
pip
:pip install .
The Protocol sends and received Frames of the following form:
/** Data container of the Frame Fields */
typedef union _Frame
{
/** Frame Fields */
struct _Fields
{
/** Header */
union _Header
{
/** Header Fields Struct */
struct _HeaderFields
{
/** Channel ID */
uint8_t m_channel;
/** Channel DLC */
uint8_t m_dlc;
/** Frame Checksum */
uint8_t m_checksum;
} __attribute__((packed)) headerFields; /**< Header Fields */
/** Raw Header Data*/
uint8_t rawHeader[HEADER_LEN];
} __attribute__((packed)) header; /**< Header */
/** Payload */
struct _Payload
{
/** Data of the Frame */
uint8_t m_data[MAX_DATA_LEN];
} __attribute__((packed)) payload; /**< Payload */
} __attribute__((packed)) fields; /**< Frame Fields */
/** Raw Frame Data */
uint8_t raw[MAX_FRAME_LEN] = {0U};
} __attribute__((packed)) Frame; /**< Frame */
/**
* Channel Definition.
*/
struct Channel
{
char m_name[CHANNEL_NAME_MAX_LEN]; /**< Name of the channel. */
uint8_t m_dlc; /**< Payload length of channel */
ChannelCallback m_callback; /**< Callback to provide received data to the application. */
/**
* Channel Constructor.
*/
Channel() : m_name{0U}, m_dlc(0U), m_callback(nullptr)
{
}
};
/**
* Channel Notification Prototype Callback.
* Provides the received data in the respective channel to the application.
*
* @param[in] payload Received data.
* @param[in] payloadSize Size of the received data.
* @param[in] userData User data provided by the application.
*/
typedef void (*ChannelCallback)(const uint8_t* payload, const uint8_t payloadSize, void* userData);
userData
pointer specified in the constructor is passed to the application.It is possible to register EventCallback
callbacks for the Synced and DeSynced events. These will be called once an event is triggered to notify the user.
/**
* Event Notification Prototype Callback.
* Provides a notification to the application on the event it is registered to.
*
* @param[in] userData User data provided by the application.
*/
typedef void (*EventCallback)(void* userData);
/* Called on Sync. */
bool registerOnSyncedCallback(EventCallback callback);
/* Called on DeSync. */
bool registerOnDeSyncedCallback(EventCallback callback);
The SerialMuxChannels.h
file should be used to define the structures and channel information to be shared between two instances of the SerialMuxServer.
This file defines the Channel Names, DLCs, and the data structures of the payloads.
It is important to note that the structs must include the packed
attribute in order to ensure the access to the data correctly.
A sample file can be found in here.