|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Implementation of the main OpenLCB protocol state machine dispatcher. More...
Functions | |
| void | OpenLcbMainStatemachine_initialize (const interface_openlcb_main_statemachine_t *interface_openlcb_main_statemachine) |
| Stores the callback interface and wires up the outgoing message buffer. | |
| bool | OpenLcbMainStatemachine_does_node_process_msg (openlcb_statemachine_info_t *statemachine_info) |
| Returns true if the node should process this message. | |
| void | OpenLcbMainStatemachine_load_interaction_rejected (openlcb_statemachine_info_t *statemachine_info) |
| Builds an Optional Interaction Rejected response for the current message. | |
| void | OpenLcbMainStatemachine_process_main_statemachine (openlcb_statemachine_info_t *statemachine_info) |
| Routes incoming message to the correct protocol handler based on MTI. | |
| bool | OpenLcbMainStatemachine_handle_outgoing_openlcb_message (void) |
| Sends the pending outgoing message if one is valid. | |
| bool | OpenLcbMainStatemachine_handle_try_reenumerate (void) |
| Re-dispatches the current message when a handler requests multi-message enumeration. | |
| bool | OpenLcbMainStatemachine_handle_try_pop_next_incoming_openlcb_message (void) |
| Pops the next incoming message from the receive FIFO when idle. | |
| bool | OpenLcbMainStatemachine_handle_try_enumerate_first_node (void) |
| Begins node enumeration by fetching the first node and dispatching the message. | |
| bool | OpenLcbMainStatemachine_handle_try_enumerate_next_node (void) |
| Advances to the next node and dispatches the current message. | |
| void | OpenLcbMainStatemachine_run (void) |
| Runs one iteration of the main state machine dispatch loop. | |
| openlcb_statemachine_info_t * | OpenLcbMainStatemachine_get_statemachine_info (void) |
| Returns pointer to internal state. For unit testing only. | |
Implementation of the main OpenLCB protocol state machine dispatcher.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This file implements the central message routing and processing engine for OpenLCB protocol handling. The state machine provides a unified dispatch mechanism that routes incoming messages to appropriate protocol handlers based on Message Type Indicator (MTI) values.
Architecture: The implementation uses a single static state machine context that maintains:
Processing model: Messages are processed through node enumeration, where each incoming message is evaluated against every active node in the system. Nodes can filter messages based on addressing (global vs addressed) and node state.
The main processing loop (run function) operates in priority order:
Protocol support:
Thread safety: Resource locking callbacks protect access to shared buffer pools and FIFOs.
| void OpenLcbMainStatemachine_initialize | ( | const interface_openlcb_main_statemachine_t * | interface_openlcb_main_statemachine | ) |
Stores the callback interface and wires up the outgoing message buffer.
Stores the callback interface and prepares internal state.
Algorithm:
* @param interface_openlcb_main_statemachine Pointer to populated interface structure *
| bool OpenLcbMainStatemachine_does_node_process_msg | ( | openlcb_statemachine_info_t * | statemachine_info | ) |
Returns true if the node should process this message.
Address filter. Returns true if the node should process this message.
Algorithm:
* @param statemachine_info Pointer to state machine context *
| void OpenLcbMainStatemachine_load_interaction_rejected | ( | openlcb_statemachine_info_t * | statemachine_info | ) |
Builds an Optional Interaction Rejected response for the current message.
Builds an Interaction Rejected response for the current incoming message. Internal use.
Algorithm:
* @param statemachine_info Pointer to state machine context *
| void OpenLcbMainStatemachine_process_main_statemachine | ( | openlcb_statemachine_info_t * | statemachine_info | ) |
Routes incoming message to the correct protocol handler based on MTI.
MTI dispatcher. Routes incoming message to the correct handler.
Algorithm:
* @param statemachine_info Pointer to state machine context with message and node information *
| bool OpenLcbMainStatemachine_handle_outgoing_openlcb_message | ( | void | ) |
Sends the pending outgoing message if one is valid.
Tries to send the pending message. Returns true if one was pending.
Algorithm:
| bool OpenLcbMainStatemachine_handle_try_reenumerate | ( | void | ) |
Re-dispatches the current message when a handler requests multi-message enumeration.
Re-enters the state processor if the enumerate flag is set.
Algorithm:
| bool OpenLcbMainStatemachine_handle_try_pop_next_incoming_openlcb_message | ( | void | ) |
Pops the next incoming message from the receive FIFO when idle.
Pops the next message from the FIFO (thread-safe). Returns true if popped.
Algorithm:
| bool OpenLcbMainStatemachine_handle_try_enumerate_first_node | ( | void | ) |
Begins node enumeration by fetching the first node and dispatching the message.
Starts node enumeration from the first node. Returns true if processed.
Algorithm:
| bool OpenLcbMainStatemachine_handle_try_enumerate_next_node | ( | void | ) |
Advances to the next node and dispatches the current message.
Advances to the next node; frees message at end. Returns true if processed.
Algorithm:
| void OpenLcbMainStatemachine_run | ( | void | ) |
Runs one iteration of the main state machine dispatch loop.
Runs one non-blocking step of protocol processing.
Algorithm:
| openlcb_statemachine_info_t * OpenLcbMainStatemachine_get_statemachine_info | ( | void | ) |
Returns pointer to internal state. For unit testing only.
Returns pointer to internal static state machine info. For unit testing only — do not modify.
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License