OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
openlcb_login_statemachine_handler.c File Reference

Implementation of the login state machine message handler. More...

Functions

void OpenLcbLoginMessageHandler_initialize (const interface_openlcb_login_message_handler_t *interface)
 Stores the callback interface. Call once at startup.
 
void OpenLcbLoginMessageHandler_load_initialization_complete (openlcb_login_statemachine_info_t *statemachine_info)
 Builds the Initialization Complete message and transitions to producer event enumeration.
 
void OpenLcbLoginMessageHandler_load_producer_event (openlcb_login_statemachine_info_t *statemachine_info)
 Builds one Producer Identified message; sets enumerate flag if more remain.
 
void OpenLcbLoginMessageHandler_load_consumer_event (openlcb_login_statemachine_info_t *statemachine_info)
 Builds one Consumer Identified message; sets enumerate flag if more remain.
 

Detailed Description

Implementation of the login state machine message handler.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

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 module implements the message construction handlers for the OpenLCB login sequence. It builds properly formatted OpenLCB messages for:

  • Initialization Complete (Simple and Full protocol variants)
  • Producer Event Identified (with Valid, Invalid, Unknown states)
  • Consumer Event Identified (with Valid, Invalid, Unknown states)

The implementation follows the OpenLCB Message Network Standard and Event Transport specifications. Each handler function:

  1. Determines the appropriate MTI based on node configuration or event state
  2. Loads the message structure with source alias, destination, and MTI
  3. Copies the payload data (Node ID or Event ID) into the message
  4. Sets the payload count
  5. Updates the node's state machine state
  6. Sets flags to control message transmission and enumeration

Message Construction Pattern: All messages use OpenLcbUtilities_load_openlcb_message() to set the header fields, then use specific copy functions for payload data (Node ID or Event ID), and finally set the payload_count to indicate message size.

State Transitions:

  • load_initialization_complete: RUNSTATE_LOAD_INITIALIZATION_COMPLETE -> RUNSTATE_LOAD_PRODUCER_EVENTS
  • load_producer_event: RUNSTATE_LOAD_PRODUCER_EVENTS -> (enumerate) -> RUNSTATE_LOAD_CONSUMER_EVENTS
  • load_consumer_event: RUNSTATE_LOAD_CONSUMER_EVENTS -> (enumerate) -> RUNSTATE_LOGIN_COMPLETE
Author
Jim Kueneman
Date
28 Feb 2026
See also
openlcb_login_statemachine.c - State machine dispatcher that calls these handlers
OpenLCB Message Network Standard S-9.7.3.1 - Initialization Complete
OpenLCB Event Transport Standard S-9.7.4 - Event Transport Protocol

Function Documentation

◆ OpenLcbLoginMessageHandler_initialize()

void OpenLcbLoginMessageHandler_initialize ( const interface_openlcb_login_message_handler_t * interface)

Stores the callback interface. Call once at startup.

Stores the callback interface. Call once at startup before login processing.

* @param interface Pointer to interface structure containing callback functions
* 

◆ OpenLcbLoginMessageHandler_load_initialization_complete()

void OpenLcbLoginMessageHandler_load_initialization_complete ( openlcb_login_statemachine_info_t * statemachine_info)

Builds the Initialization Complete message and transitions to producer event enumeration.

Algorithm:

  1. Pick MTI_INITIALIZATION_COMPLETE or _SIMPLE based on PSI_SIMPLE flag
  2. Load message header and copy 6-byte Node ID into payload
  3. Mark node initialized, set up producer enumerator, set valid flag
  4. Transition to RUNSTATE_LOAD_PRODUCER_EVENTS
* @param statemachine_info Pointer to state machine info containing node and message buffer
* 

◆ OpenLcbLoginMessageHandler_load_producer_event()

void OpenLcbLoginMessageHandler_load_producer_event ( openlcb_login_statemachine_info_t * statemachine_info)

Builds one Producer Identified message; sets enumerate flag if more remain.

Algorithm:

  1. If no producers, skip to RUNSTATE_LOAD_CONSUMER_EVENTS
  2. Emit range events first, then normal events
  3. For each event: get MTI from callback, copy Event ID to payload
  4. Set enumerate=true and valid=true for each message
  5. When all done, reset enumerator and transition to consumer events
* @param statemachine_info Pointer to state machine info containing node and message buffer
* 

◆ OpenLcbLoginMessageHandler_load_consumer_event()

void OpenLcbLoginMessageHandler_load_consumer_event ( openlcb_login_statemachine_info_t * statemachine_info)

Builds one Consumer Identified message; sets enumerate flag if more remain.

Algorithm:

  1. If no consumers, skip to RUNSTATE_LOGIN_COMPLETE
  2. Emit range events first, then normal events
  3. For each event: get MTI from callback, copy Event ID to payload
  4. Set enumerate=true and valid=true for each message
  5. When all done, reset enumerator and transition to RUNSTATE_LOGIN_COMPLETE
* @param statemachine_info Pointer to state machine info containing node and message buffer
* 

Copyright (c) 2026 Jim Kueneman all rights reserved. See the License