|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Implementation of the main CAN state machine dispatcher. More...
Functions | |
| void | CanMainStatemachine_initialize (const interface_can_main_statemachine_t *interface_can_main_statemachine) |
| Initializes the CAN main state machine. | |
| can_statemachine_info_t * | CanMainStateMachine_get_can_statemachine_info (void) |
| Returns a pointer to the internal state machine context (for testing/debugging). | |
| bool | CanMainStatemachine_handle_duplicate_aliases (void) |
| Checks for the has_duplicate_alias flag; resolves any duplicates found. | |
| bool | CanMainStatemachine_handle_outgoing_can_message (void) |
| Pops and transmits one CAN frame from the outgoing FIFO. | |
| bool | CanMainStatemachine_handle_login_outgoing_can_message (void) |
| Transmits the pending login frame (CID/RID/AMD) if one is flagged as valid. | |
| bool | CanMainStatemachine_handle_try_enumerate_first_node (void) |
| Starts node enumeration by fetching and processing the first node. | |
| bool | CanMainStatemachine_handle_try_enumerate_next_node (void) |
| Advances node enumeration to the next node. | |
| bool | CanMainStatemachine_handle_listener_verification (void) |
| Probes one listener alias for staleness and queues an AME if due. | |
| void | CanMainStateMachine_run (void) |
| Executes one cooperative iteration of the main CAN state machine. | |
Implementation of the main CAN 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.
Coordinates duplicate alias detection, CAN and login frame transmission, and node enumeration. Uses a cooperative multitasking pattern — each function does one unit of work and returns so other application code can run.
| void CanMainStatemachine_initialize | ( | const interface_can_main_statemachine_t * | interface_can_main_statemachine | ) |
Initializes the CAN main state machine.
Registers the dependency-injection interface and prepares internal buffers.
Stores the interface pointer, clears the static login frame buffer, links it to the state machine context, and zeroes all context flags.
* @param interface_can_main_statemachine Pointer to the populated dependency interface. *
| can_statemachine_info_t * CanMainStateMachine_get_can_statemachine_info | ( | void | ) |
Returns a pointer to the internal state machine context (for testing/debugging).
Returns a pointer to the internal state machine context.
| bool CanMainStatemachine_handle_duplicate_aliases | ( | void | ) |
Checks for the has_duplicate_alias flag; resolves any duplicates found.
Scans the alias table, unregisters duplicates, and resets affected nodes.
Locks shared resources, reads the flag, calls _process_duplicate_aliases() if needed, then unlocks.
| bool CanMainStatemachine_handle_outgoing_can_message | ( | void | ) |
Pops and transmits one CAN frame from the outgoing FIFO.
Pops one message from the outgoing CAN FIFO and attempts transmission.
Algorithm:
| bool CanMainStatemachine_handle_login_outgoing_can_message | ( | void | ) |
Transmits the pending login frame (CID/RID/AMD) if one is flagged as valid.
Attempts to transmit the pending login frame (CID, RID, or AMD).
Clears login_outgoing_can_msg_valid only after successful transmission. Returns true if a login frame was pending (sent or retried), false if none.
| bool CanMainStatemachine_handle_try_enumerate_first_node | ( | void | ) |
Starts node enumeration by fetching and processing the first node.
Gets the first node and processes it through its appropriate state machine.
Returns false if enumeration is already active (node pointer non-NULL). Otherwise fetches the first node, runs its login state machine if still logging in, and returns true.
| bool CanMainStatemachine_handle_try_enumerate_next_node | ( | void | ) |
Advances node enumeration to the next node.
Continues enumeration and processes the next node.
Fetches the next node and runs its login state machine if still logging in. Returns true when there are no more nodes (enumeration complete), false otherwise.
| bool CanMainStatemachine_handle_listener_verification | ( | void | ) |
Probes one listener alias for staleness and queues an AME if due.
Algorithm:
| void CanMainStateMachine_run | ( | void | ) |
Executes one cooperative iteration of the main CAN state machine.
Executes one iteration of the main CAN state machine.
Calls each handler in priority order, returning after the first one that does work. Listener verification runs unconditionally before the priority chain. Priority: duplicate aliases -> outgoing CAN frame -> login frame -> enumerate first node -> enumerate next node.
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License