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

State handlers for the 10-state CAN alias allocation login sequence. More...

Go to the source code of this file.

Data Structures

struct  interface_can_login_message_handler_t
 Dependency-injection interface for the CAN login message handler. More...
 

Functions

void CanLoginMessageHandler_initialize (const interface_can_login_message_handler_t *interface)
 Registers the dependency-injection interface for this module.
 
void CanLoginMessageHandler_state_init (can_statemachine_info_t *can_statemachine_info)
 State 1: Sets node seed to its Node ID, then jumps to GENERATE_ALIAS.
 
void CanLoginMessageHandler_state_generate_seed (can_statemachine_info_t *can_statemachine_info)
 State 2: Generates a new seed via LFSR, then transitions to GENERATE_ALIAS.
 
void CanLoginMessageHandler_state_generate_alias (can_statemachine_info_t *can_statemachine_info)
 State 3: Derives a 12-bit alias from the seed, registers it, then transitions to LOAD_CID07.
 
void CanLoginMessageHandler_state_load_cid07 (can_statemachine_info_t *can_statemachine_info)
 State 4: Loads a CID7 frame (Node ID bits 47-36) into the outgoing buffer.
 
void CanLoginMessageHandler_state_load_cid06 (can_statemachine_info_t *can_statemachine_info)
 State 5: Loads a CID6 frame (Node ID bits 35-24) into the outgoing buffer.
 
void CanLoginMessageHandler_state_load_cid05 (can_statemachine_info_t *can_statemachine_info)
 State 6: Loads a CID5 frame (Node ID bits 23-12) into the outgoing buffer.
 
void CanLoginMessageHandler_state_load_cid04 (can_statemachine_info_t *can_statemachine_info)
 State 7: Loads a CID4 frame (Node ID bits 11-0) and resets the 200 ms timer.
 
void CanLoginMessageHandler_state_wait_200ms (can_statemachine_info_t *can_statemachine_info)
 State 8: Waits until timerticks > 2, then transitions to LOAD_RESERVE_ID.
 
void CanLoginMessageHandler_state_load_rid (can_statemachine_info_t *can_statemachine_info)
 State 9: Loads an RID frame to claim the alias, then transitions to LOAD_AMD.
 
void CanLoginMessageHandler_state_load_amd (can_statemachine_info_t *can_statemachine_info)
 State 10: Loads an AMD frame with the full Node ID, marks the node permitted, and updates the alias mapping to permitted status.
 

Detailed Description

State handlers for the 10-state CAN alias allocation login sequence.

Each handler builds the appropriate CAN control frame (CID, RID, AMD) per the OpenLCB CAN Frame Transfer Standard.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ CanLoginMessageHandler_initialize()

void CanLoginMessageHandler_initialize ( const interface_can_login_message_handler_t * interface)
extern

Registers the dependency-injection interface for this module.

Parameters
interfacePointer to a populated interface_can_login_message_handler_t. Must remain valid for the lifetime of the application.
Warning
NOT thread-safe - call during single-threaded initialization only.
See also
CanLoginStateMachine_initialize

Registers the dependency-injection interface for this module.

* @param interface Pointer to the populated dependency-injection interface.
* 

◆ CanLoginMessageHandler_state_init()

void CanLoginMessageHandler_state_init ( can_statemachine_info_t * can_statemachine_info)
extern

State 1: Sets node seed to its Node ID, then jumps to GENERATE_ALIAS.

Parameters
can_statemachine_infoState machine context (node + outgoing message buffer).

State 1: Sets node seed to its Node ID, then jumps to GENERATE_ALIAS.

On first login the Node ID itself is the initial seed, so GENERATE_SEED (which advances the PRNG one step) is skipped. GENERATE_SEED is only entered on alias conflict retry, when _reset_node() sets run_state back to RUNSTATE_GENERATE_SEED.

* @param can_statemachine_info State machine context.
* 

◆ CanLoginMessageHandler_state_generate_seed()

void CanLoginMessageHandler_state_generate_seed ( can_statemachine_info_t * can_statemachine_info)
extern

State 2: Generates a new seed via LFSR, then transitions to GENERATE_ALIAS.

Only entered when an alias conflict forces a new alias attempt.

Parameters
can_statemachine_infoState machine context.

State 2: Generates a new seed via LFSR, then transitions to GENERATE_ALIAS.

◆ CanLoginMessageHandler_state_generate_alias()

void CanLoginMessageHandler_state_generate_alias ( can_statemachine_info_t * can_statemachine_info)
extern

State 3: Derives a 12-bit alias from the seed, registers it, then transitions to LOAD_CID07.

Parameters
can_statemachine_infoState machine context.

State 3: Derives a 12-bit alias from the seed, registers it, then transitions to LOAD_CID07.

◆ CanLoginMessageHandler_state_load_cid07()

void CanLoginMessageHandler_state_load_cid07 ( can_statemachine_info_t * can_statemachine_info)
extern

State 4: Loads a CID7 frame (Node ID bits 47-36) into the outgoing buffer.

Parameters
can_statemachine_infoState machine context.

◆ CanLoginMessageHandler_state_load_cid06()

void CanLoginMessageHandler_state_load_cid06 ( can_statemachine_info_t * can_statemachine_info)
extern

State 5: Loads a CID6 frame (Node ID bits 35-24) into the outgoing buffer.

Parameters
can_statemachine_infoState machine context.

◆ CanLoginMessageHandler_state_load_cid05()

void CanLoginMessageHandler_state_load_cid05 ( can_statemachine_info_t * can_statemachine_info)
extern

State 6: Loads a CID5 frame (Node ID bits 23-12) into the outgoing buffer.

Parameters
can_statemachine_infoState machine context.

◆ CanLoginMessageHandler_state_load_cid04()

void CanLoginMessageHandler_state_load_cid04 ( can_statemachine_info_t * can_statemachine_info)
extern

State 7: Loads a CID4 frame (Node ID bits 11-0) and resets the 200 ms timer.

Parameters
can_statemachine_infoState machine context.

State 7: Loads a CID4 frame (Node ID bits 11-0) and resets the 200 ms timer.

◆ CanLoginMessageHandler_state_wait_200ms()

void CanLoginMessageHandler_state_wait_200ms ( can_statemachine_info_t * can_statemachine_info)
extern

State 8: Waits until timerticks > 2, then transitions to LOAD_RESERVE_ID.

Non-blocking — returns immediately each call until the timer expires. timerticks is reset to 0 at the end of State 7 (CID4) and incremented every 100 ms, so this waits at least 300 ms — satisfying the spec minimum of 200 ms (§6.2.1). Requires the 100 ms timer tick to be running (OpenLcbNode_100ms_timer_tick).

Parameters
can_statemachine_infoState machine context.

State 8: Waits until timerticks > 2, then transitions to LOAD_RESERVE_ID.

◆ CanLoginMessageHandler_state_load_rid()

void CanLoginMessageHandler_state_load_rid ( can_statemachine_info_t * can_statemachine_info)
extern

State 9: Loads an RID frame to claim the alias, then transitions to LOAD_AMD.

Parameters
can_statemachine_infoState machine context.

◆ CanLoginMessageHandler_state_load_amd()

void CanLoginMessageHandler_state_load_amd ( can_statemachine_info_t * can_statemachine_info)
extern

State 10: Loads an AMD frame with the full Node ID, marks the node permitted, and updates the alias mapping to permitted status.

This is the final state. After transmission the node may send OpenLCB messages.

Parameters
can_statemachine_infoState machine context.
See also
CanUtilities_copy_node_id_to_payload

State 10: Loads an AMD frame with the full Node ID, marks the node permitted, and updates the alias mapping to permitted status.


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