OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
interface_protocol_train_handler_t Struct Reference

Callback interface for train protocol events. More...

Data Fields

void(* on_speed_changed )(openlcb_node_t *openlcb_node, uint16_t speed_float16)
 Speed was set. State already updated.
 
void(* on_function_changed )(openlcb_node_t *openlcb_node, uint32_t fn_address, uint16_t fn_value)
 Function was set. Standard functions stored in train_state.functions[].
 
void(* on_emergency_entered )(openlcb_node_t *openlcb_node, train_emergency_type_enum emergency_type)
 Emergency state entered. State flags already updated.
 
void(* on_emergency_exited )(openlcb_node_t *openlcb_node, train_emergency_type_enum emergency_type)
 Emergency state exited. State flags already updated.
 
void(* on_controller_assigned )(openlcb_node_t *openlcb_node, node_id_t controller_node_id)
 Controller assigned or changed. State already updated.
 
void(* on_controller_released )(openlcb_node_t *openlcb_node)
 Controller released. State already cleared.
 
void(* on_listener_changed )(openlcb_node_t *openlcb_node)
 Listener list modified (attach or detach).
 
void(* on_heartbeat_timeout )(openlcb_node_t *openlcb_node)
 Heartbeat timed out. State already updated.
 
bool(* on_controller_assign_request )(openlcb_node_t *openlcb_node, node_id_t current_controller, node_id_t requesting_controller)
 Another controller wants to take over. Return true to accept. NULL = accept.
 
bool(* on_controller_changed_request )(openlcb_node_t *openlcb_node, node_id_t new_controller)
 Controller Changed Notify received. Return true to accept handoff. NULL = accept.
 
void(* on_query_speeds_reply )(openlcb_node_t *openlcb_node, uint16_t set_speed, uint8_t status, uint16_t commanded_speed, uint16_t actual_speed)
 Query Speeds reply received.
 
void(* on_query_function_reply )(openlcb_node_t *openlcb_node, uint32_t fn_address, uint16_t fn_value)
 Query Function reply received.
 
void(* on_controller_assign_reply )(openlcb_node_t *openlcb_node, uint8_t result, node_id_t current_controller)
 Controller Assign reply received. On reject (result != 0), current_controller is the Node ID of the controller that currently owns the train. On accept, it is 0.
 
void(* on_controller_query_reply )(openlcb_node_t *openlcb_node, uint8_t flags, node_id_t controller_node_id)
 Controller Query reply received.
 
void(* on_controller_changed_notify_reply )(openlcb_node_t *openlcb_node, uint8_t result)
 Controller Changed Notify reply received.
 
void(* on_listener_attach_reply )(openlcb_node_t *openlcb_node, node_id_t node_id, uint8_t result)
 Listener Attach reply received.
 
void(* on_listener_detach_reply )(openlcb_node_t *openlcb_node, node_id_t node_id, uint8_t result)
 Listener Detach reply received.
 
void(* on_listener_query_reply )(openlcb_node_t *openlcb_node, uint8_t count, uint8_t index, uint8_t flags, node_id_t node_id)
 Listener Query reply received.
 
void(* on_reserve_reply )(openlcb_node_t *openlcb_node, uint8_t result)
 Reserve reply received.
 
void(* on_heartbeat_request )(openlcb_node_t *openlcb_node, uint32_t timeout_seconds)
 Heartbeat request from train node.
 

Detailed Description

Callback interface for train protocol events.

All callbacks are optional (can be NULL).

Train-node side:

  • Notifiers fire AFTER the handler has updated train_state and built any reply. The application can use these to drive hardware (DCC output, motor controller, etc).
  • Decision callbacks return a value the handler uses. If NULL the handler uses a default policy.

Throttle side:

  • Notifiers fire when a reply is received from the train node.

Field Documentation

◆ on_speed_changed

void(* on_speed_changed) (openlcb_node_t *openlcb_node, uint16_t speed_float16)

Speed was set. State already updated.

◆ on_function_changed

void(* on_function_changed) (openlcb_node_t *openlcb_node, uint32_t fn_address, uint16_t fn_value)

Function was set. Standard functions stored in train_state.functions[].

◆ on_emergency_entered

void(* on_emergency_entered) (openlcb_node_t *openlcb_node, train_emergency_type_enum emergency_type)

Emergency state entered. State flags already updated.

◆ on_emergency_exited

void(* on_emergency_exited) (openlcb_node_t *openlcb_node, train_emergency_type_enum emergency_type)

Emergency state exited. State flags already updated.

◆ on_controller_assigned

void(* on_controller_assigned) (openlcb_node_t *openlcb_node, node_id_t controller_node_id)

Controller assigned or changed. State already updated.

◆ on_controller_released

void(* on_controller_released) (openlcb_node_t *openlcb_node)

Controller released. State already cleared.

◆ on_listener_changed

void(* on_listener_changed) (openlcb_node_t *openlcb_node)

Listener list modified (attach or detach).

◆ on_heartbeat_timeout

void(* on_heartbeat_timeout) (openlcb_node_t *openlcb_node)

Heartbeat timed out. State already updated.

◆ on_controller_assign_request

bool(* on_controller_assign_request) (openlcb_node_t *openlcb_node, node_id_t current_controller, node_id_t requesting_controller)

Another controller wants to take over. Return true to accept. NULL = accept.

◆ on_controller_changed_request

bool(* on_controller_changed_request) (openlcb_node_t *openlcb_node, node_id_t new_controller)

Controller Changed Notify received. Return true to accept handoff. NULL = accept.

◆ on_query_speeds_reply

void(* on_query_speeds_reply) (openlcb_node_t *openlcb_node, uint16_t set_speed, uint8_t status, uint16_t commanded_speed, uint16_t actual_speed)

Query Speeds reply received.

◆ on_query_function_reply

void(* on_query_function_reply) (openlcb_node_t *openlcb_node, uint32_t fn_address, uint16_t fn_value)

Query Function reply received.

◆ on_controller_assign_reply

void(* on_controller_assign_reply) (openlcb_node_t *openlcb_node, uint8_t result, node_id_t current_controller)

Controller Assign reply received. On reject (result != 0), current_controller is the Node ID of the controller that currently owns the train. On accept, it is 0.

◆ on_controller_query_reply

void(* on_controller_query_reply) (openlcb_node_t *openlcb_node, uint8_t flags, node_id_t controller_node_id)

Controller Query reply received.

◆ on_controller_changed_notify_reply

void(* on_controller_changed_notify_reply) (openlcb_node_t *openlcb_node, uint8_t result)

Controller Changed Notify reply received.

◆ on_listener_attach_reply

void(* on_listener_attach_reply) (openlcb_node_t *openlcb_node, node_id_t node_id, uint8_t result)

Listener Attach reply received.

◆ on_listener_detach_reply

void(* on_listener_detach_reply) (openlcb_node_t *openlcb_node, node_id_t node_id, uint8_t result)

Listener Detach reply received.

◆ on_listener_query_reply

void(* on_listener_query_reply) (openlcb_node_t *openlcb_node, uint8_t count, uint8_t index, uint8_t flags, node_id_t node_id)

Listener Query reply received.

◆ on_reserve_reply

void(* on_reserve_reply) (openlcb_node_t *openlcb_node, uint8_t result)

Reserve reply received.

◆ on_heartbeat_request

void(* on_heartbeat_request) (openlcb_node_t *openlcb_node, uint32_t timeout_seconds)

Heartbeat request from train node.


The documentation for this struct was generated from the following file:

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