OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
protocol_train_handler.h
Go to the documentation of this file.
1
50#ifndef __OPENLCB_PROTOCOL_TRAIN_HANDLER__
51#define __OPENLCB_PROTOCOL_TRAIN_HANDLER__
52
53#include <stdbool.h>
54#include <stdint.h>
55
56#include "openlcb_types.h"
57
74 typedef struct {
75
76 // ---- Train-node side: notifiers (fire after state updated) ----
77
79 void (*on_speed_changed)(openlcb_node_t *openlcb_node, uint16_t speed_float16);
80
82 void (*on_function_changed)(openlcb_node_t *openlcb_node, uint32_t fn_address, uint16_t fn_value);
83
85 void (*on_emergency_entered)(openlcb_node_t *openlcb_node, train_emergency_type_enum emergency_type);
86
88 void (*on_emergency_exited)(openlcb_node_t *openlcb_node, train_emergency_type_enum emergency_type);
89
91 void (*on_controller_assigned)(openlcb_node_t *openlcb_node, node_id_t controller_node_id);
92
94 void (*on_controller_released)(openlcb_node_t *openlcb_node);
95
97 void (*on_listener_changed)(openlcb_node_t *openlcb_node);
98
100 void (*on_heartbeat_timeout)(openlcb_node_t *openlcb_node);
101
102 // ---- Train-node side: decision callbacks ----
103
105 bool (*on_controller_assign_request)(openlcb_node_t *openlcb_node, node_id_t current_controller, node_id_t requesting_controller);
106
108 bool (*on_controller_changed_request)(openlcb_node_t *openlcb_node, node_id_t new_controller);
109
110 // ---- Throttle side: notifiers (receiving replies from train) ----
111
113 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);
114
116 void (*on_query_function_reply)(openlcb_node_t *openlcb_node, uint32_t fn_address, uint16_t fn_value);
117
121 void (*on_controller_assign_reply)(openlcb_node_t *openlcb_node, uint8_t result, node_id_t current_controller);
122
124 void (*on_controller_query_reply)(openlcb_node_t *openlcb_node, uint8_t flags, node_id_t controller_node_id);
125
127 void (*on_controller_changed_notify_reply)(openlcb_node_t *openlcb_node, uint8_t result);
128
130 void (*on_listener_attach_reply)(openlcb_node_t *openlcb_node, node_id_t node_id, uint8_t result);
131
133 void (*on_listener_detach_reply)(openlcb_node_t *openlcb_node, node_id_t node_id, uint8_t result);
134
136 void (*on_listener_query_reply)(openlcb_node_t *openlcb_node, uint8_t count, uint8_t index, uint8_t flags, node_id_t node_id);
137
139 void (*on_reserve_reply)(openlcb_node_t *openlcb_node, uint8_t result);
140
142 void (*on_heartbeat_request)(openlcb_node_t *openlcb_node, uint32_t timeout_seconds);
143
145
146#ifdef __cplusplus
147extern "C" {
148#endif
149
156
166
176
187 openlcb_statemachine_info_t *statemachine_info, event_id_t event_id);
188
189
190#ifdef __cplusplus
191}
192#endif
193
194#endif /* __OPENLCB_PROTOCOL_TRAIN_HANDLER__ */
Core type definitions, structures, and configuration constants for the OpenLCB library.
uint64_t event_id_t
64-bit Event ID.
Definition openlcb_types.h:340
train_emergency_type_enum
Emergency state type for train protocol callbacks.
Definition openlcb_types.h:288
uint64_t node_id_t
48-bit Node ID stored in a 64-bit type (upper 16 bits unused).
Definition openlcb_types.h:359
void ProtocolTrainHandler_handle_train_reply(openlcb_statemachine_info_t *statemachine_info)
Handles an incoming Train Control Protocol reply (MTI_TRAIN_REPLY).
Definition protocol_train_handler.c:1321
void ProtocolTrainHandler_initialize(const interface_protocol_train_handler_t *interface)
Initializes the Train Control Protocol handler.
Definition protocol_train_handler.c:60
void ProtocolTrainHandler_handle_emergency_event(openlcb_statemachine_info_t *statemachine_info, event_id_t event_id)
Handles a global or addressed emergency event for a train node.
Definition protocol_train_handler.c:1383
void ProtocolTrainHandler_handle_train_command(openlcb_statemachine_info_t *statemachine_info)
Handles an incoming Train Control Protocol command (MTI_TRAIN_PROTOCOL).
Definition protocol_train_handler.c:1203
Callback interface for train protocol events.
Definition protocol_train_handler.h:74
OpenLCB virtual node.
Definition openlcb_types.h:679
Complete context passed to protocol handler functions.
Definition openlcb_types.h:743

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