Adding New UART Messages¶
Messaging Structure¶
Each message consists of a get and an update ID:
Get ID: Used to request data from the other microcontroller.
Update ID: Used to set data received from the other microcontroller.
Each message must have both a get and an update ID; however, every message ID must be unique. Every message ID also has an associated message handler—this is the code that executes on the microcontroller when a message is received from the other microcontroller.
Declare Message ID(s)¶
Navigate to the
srcfolder and open the fileuart_commands.h.Locate the namespace
UART_command_names.Declare your message ID(s) within this namespace.
Declare Message Handler¶
In the same file (
uart_commands.h), locate the namespaceUART_command_handlers.Create your message handler function with the following signature:
static inline void your_function_name(UARTHandler* handler, ExoData* exo_data, UART_msg_t msg)
Replace
your_function_namewith the appropriate function name for your new message.
Add Your Function to the List of Callable Functions¶
Again in
uart_commands.h, locate the namespaceUART_command_utils.Within that namespace, find the function named
handle_msg.Add a switch case (or cases) for your new message ID(s) in the
handle_msgfunction, so that your handler is called when the corresponding message is received.
Done¶
You have now integrated your new UART message! Test your new function to ensure it handles messages as expected.