|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Train Control Protocol message handler (Layer 1) More...
Go to the source code of this file.
Data Structures | |
| struct | interface_protocol_train_handler_t |
| Callback interface for train protocol events. More... | |
Functions | |
| void | ProtocolTrainHandler_initialize (const interface_protocol_train_handler_t *interface) |
| Initializes the Train Control Protocol handler. | |
| void | ProtocolTrainHandler_handle_train_command (openlcb_statemachine_info_t *statemachine_info) |
| Handles an incoming Train Control Protocol command (MTI_TRAIN_PROTOCOL). | |
| void | ProtocolTrainHandler_handle_train_reply (openlcb_statemachine_info_t *statemachine_info) |
| Handles an incoming Train Control Protocol reply (MTI_TRAIN_REPLY). | |
| 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. | |
Train Control Protocol message handler (Layer 1)
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.
Handles incoming MTI_TRAIN_PROTOCOL (0x05EB) commands and MTI_TRAIN_REPLY (0x01E9) replies. Automatically updates train state, builds protocol replies, and forwards consist commands to listeners. Fires optional notifier callbacks after state is updated.
Train-node side callbacks are split into:
Throttle-side callbacks are all notifiers that fire when a reply is received.
Called from the main statemachine when a train protocol message is received.
|
extern |
Initializes the Train Control Protocol handler.
| interface | Pointer to interface_protocol_train_handler_t callbacks (may be NULL). |
Initializes the Train Control Protocol handler.
* @param interface Populated callback table (may be NULL). *
|
extern |
Handles an incoming Train Control Protocol command (MTI_TRAIN_PROTOCOL).
Decodes the sub-command byte, updates train_state, builds the appropriate reply, and fires notifier or decision callbacks.
| statemachine_info | Pointer to openlcb_statemachine_info_t context. |
Handles an incoming Train Control Protocol command (MTI_TRAIN_PROTOCOL).
Masks the P bit (bit 7) from the instruction byte before dispatch so that forwarded commands (P=1) are processed identically to direct commands (P=0). After local processing of speed, function, or emergency stop commands, initiates listener forwarding enumeration if listeners are attached and the command is not itself a forwarded command (P=0).
* @param statemachine_info Pointer to openlcb_statemachine_info_t context. *
|
extern |
Handles an incoming Train Control Protocol reply (MTI_TRAIN_REPLY).
Decodes the reply sub-command and fires the matching throttle-side notifier callback.
| statemachine_info | Pointer to openlcb_statemachine_info_t context. |
Handles an incoming Train Control Protocol reply (MTI_TRAIN_REPLY).
* @param statemachine_info Pointer to openlcb_statemachine_info_t context. *
|
extern |
Handles a global or addressed emergency event for a train node.
Activates or clears the emergency state based on the well-known Event ID and fires the appropriate notifier callback.
| statemachine_info | Pointer to openlcb_statemachine_info_t context. |
| event_id | Well-known event_id_t for the emergency condition. |
Sets or clears emergency flags based on the well-known Event ID and fires the appropriate notifier callback.
* @param statemachine_info Pointer to openlcb_statemachine_info_t context. * @param event_id Well-known event_id_t for the emergency condition. *
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License