4. Messages (from the train)
The intelino train sends a lot of valuable information which is accessible through typed data classes (read only). Some of this information comes as events and some are delivered as responses to single requests or stream requests.
4.1. Base classes
Base classes are not intended for use, but it is good to know what have all messages in common.
- class trainlib_async.messages.TrainMsgBase
Base train message.
- command_id: ClassVar[int]
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventBase
Bases:
TrainMsgBase
Base event message.
- command_id: ClassVar[int] = 224
- event_id: ClassVar[EventId]
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventSensorColorChangedBase
Bases:
TrainMsgEventBase
Triggered after the color is accepted by the train.
- sensor: ClassVar[ColorSensor]
- color: SnapColorValue
- command_id: ClassVar[int] = 224
- event_id: ClassVar[EventId]
- timestamp_ms: int
- raw_packet: TrainBlePacket
4.2. Response messages
- class trainlib_async.messages.TrainMsgMacAddress
Bases:
TrainMsgBase
TrainMsgMacAddress(raw_packet: ‘TrainBlePacket’, mac_address: str)
- command_id: ClassVar[int] = 66
- mac_address: str
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgTrainUuid
Bases:
TrainMsgBase
TrainMsgTrainUuid(raw_packet: ‘TrainBlePacket’, uuid: str)
- command_id: ClassVar[int] = 67
- uuid: str
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgVersionDetail
Bases:
TrainMsgBase
Train version information.
- class Version(major: int, minor: int, patch: int | None = None)
Bases:
object
Version number tuple.
- major: int
- minor: int
- patch: int | None = None
- command_id: ClassVar[int] = 7
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgStatsLifetimeOdometer
Bases:
TrainMsgBase
TrainMsgStatsLifetimeOdometer(raw_packet: ‘TrainBlePacket’, lifetime_odometer_meters: float)
- command_id: ClassVar[int] = 62
- lifetime_odometer_meters: float
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgMovement
Bases:
TrainMsgBase
Movement stream message.
- command_id: ClassVar[int] = 183
- direction: MovementDirection
- speed_cmps: float
- pwm: int
- speed_control: bool
- desired_speed_cmps: float
- pause_time_ms: int
- next_split_decision: SteeringDecision
- lifetime_odometer_meters: float
- raw_packet: TrainBlePacket
4.3. Event messages
- class trainlib_async.messages.TrainMsgEventMovementDirectionChanged
Bases:
TrainMsgEventBase
Triggered whenever the direction changes or the train stops.
- event_id: ClassVar[EventId] = 1
- direction: MovementDirection
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventLowBattery
Bases:
TrainMsgEventBase
Triggered when the battery voltage is low.
- event_id: ClassVar[EventId] = 2
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventChargingStateChanged
Bases:
TrainMsgEventBase
Triggered when the charger is connected or disconnected.
- event_id: ClassVar[EventId] = 4
- is_charging: bool
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventButtonPressDetected
Bases:
TrainMsgEventBase
Triggered when the train’s button is pressed. The detection does not affect the button’s functionality (start/stop driving on a short press, turn off on a long press).
- event_id: ClassVar[EventId] = 5
- button_press_type: ButtonPress
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventSnapCommandDetected
Bases:
TrainMsgEventBase
Triggered when a snap sequence (command) is detected, regardless of the execution status.
- event_id: ClassVar[EventId] = 9
- snap_counter: int
- colors: SnapCommand
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventSnapCommandExecuted
Bases:
TrainMsgEventBase
Triggered after the snap sequence (command) execution started.
If snap execution is turned off, this event will not be sent.
- event_id: ClassVar[EventId] = 6
- snap_counter: int
- colors: SnapCommand
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventFrontColorChanged
Bases:
TrainMsgEventSensorColorChangedBase
Train’s front color sensor.
- event_id: ClassVar[EventId] = 7
- sensor: ClassVar[ColorSensor] = 1
- command_id: ClassVar[int] = 224
- color: SnapColorValue
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventBackColorChanged
Bases:
TrainMsgEventSensorColorChangedBase
Train’s back color sensor.
- event_id: ClassVar[EventId] = 8
- sensor: ClassVar[ColorSensor] = 2
- command_id: ClassVar[int] = 224
- color: SnapColorValue
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventSplitDecision
Bases:
TrainMsgEventBase
Triggered after the split track is detected and the steering decision is made.
- event_id: ClassVar[EventId] = 10
- decision: SteeringDecision
- command_id: ClassVar[int] = 224
- timestamp_ms: int
- raw_packet: TrainBlePacket
4.4. Error messages
- class trainlib_async.messages.TrainMsgUnknown
Bases:
TrainMsgBase
TrainMsgUnknown(raw_packet: ‘TrainBlePacket’)
- command_id: ClassVar[int] = 0
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgEventUnknown
Bases:
TrainMsgEventBase
TrainMsgEventUnknown(raw_packet: ‘TrainBlePacket’, timestamp_ms: int)
- command_id: ClassVar[int] = 0
- event_id: ClassVar[EventId] = 0
- timestamp_ms: int
- raw_packet: TrainBlePacket
- class trainlib_async.messages.TrainMsgMalformed
Bases:
TrainMsgBase
TrainMsgMalformed(raw_packet: ‘TrainBlePacket’)
- command_id: ClassVar[int] = 256
- raw_packet: TrainBlePacket
4.5. Union classes
The library defines aliased union classes for messages. These should be used instead of the base classes e.g. when a function expects various message types as arguments.
- trainlib_async.messages.TrainMsg
alias of
Union
[TrainMsgUnknown
,TrainMsgMalformed
,TrainMsgMacAddress
,TrainMsgTrainUuid
,TrainMsgVersionDetail
,TrainMsgStatsLifetimeOdometer
,TrainMsgMovement
,TrainMsgEventUnknown
,TrainMsgEventMovementDirectionChanged
,TrainMsgEventLowBattery
,TrainMsgEventLowBatteryCutOff
,TrainMsgEventChargingStateChanged
,TrainMsgEventButtonPressDetected
,TrainMsgEventSnapCommandExecuted
,TrainMsgEventFrontColorChanged
,TrainMsgEventBackColorChanged
,TrainMsgEventSnapCommandDetected
,TrainMsgEventSplitDecision
]
- trainlib_async.messages.TrainMsgEvent
alias of
Union
[TrainMsgEventUnknown
,TrainMsgEventMovementDirectionChanged
,TrainMsgEventLowBattery
,TrainMsgEventLowBatteryCutOff
,TrainMsgEventChargingStateChanged
,TrainMsgEventButtonPressDetected
,TrainMsgEventSnapCommandExecuted
,TrainMsgEventFrontColorChanged
,TrainMsgEventBackColorChanged
,TrainMsgEventSnapCommandDetected
,TrainMsgEventSplitDecision
]
- trainlib_async.messages.TrainMsgEventSensorColorChanged
alias of
Union
[TrainMsgEventFrontColorChanged
,TrainMsgEventBackColorChanged
]