TrainRBCSim
ADR-029 Train (EVC) simulator — dual-homed TCP client speaking the RBC wire protocol
Loading...
Searching...
No Matches
train.ertms_adapters Namespace Reference

Functions

 _position_report_from_fields (fields)
 _position_report_packet1_from_fields (fields)
 _flatten_msg3 (decoded)
 _flatten_msg24 (decoded)

Variables

dict ENCODERS
dict FLATTENERS

Detailed Description

Train sim's own adapters between message_catalog.json's flat
{field: int} fields dict (the same shape every JSON sendMessage command
already uses for the flat scheme) and rbc_ertms_wire.py's real, per-
message-shaped encode_msg_*()/decode() functions - injected into
SimCore's MessageCatalog at construction time (see that module's own
header doc for why this lives here, not there: Subset-026 is the
Train<->RBC air-gap protocol specifically, not something IL/CTC ever
speak in this codebase, so it's this sim's own application-layer
concern, same as message_catalog.json itself already is per-sim).

Function Documentation

◆ _flatten_msg24()

_flatten_msg24 ( decoded)
protected
Msg 24 (General Message) -> one flat dict, same shape/rationale as
_flatten_msg3() above. NOTE a real, currently-latent collision: P65
(tsr) and P66 (tsr_revoke) both have their own "nid_tsr" field - not
prefixed below since this project's own SoM/Running/EoM flow never
carries both in the same Msg 24, but a future scenario that does
(dynamic TSR work) would need to prefix these the same way
gradient/ssp are above.

Definition at line 106 of file ertms_adapters.py.

◆ _flatten_msg3()

_flatten_msg3 ( decoded)
protected
Msg 3 (Movement Authority) -> one flat {field: value} dict, same
shape decode_to_message() already returns for the flat scheme, plus
"packetsPresent" (this message's own optional-packet list) so a
Robot test can assert presence, not just field values. Packet-
specific fields are prefixed by packet (gradient_*/ssp_*/linking_*)
since e.g. gradient and ssp both have their own "segment_count" -
Msg 3 in this flow ALWAYS carries both at once (Packet 15+21+27),
so this collision is real, not theoretical.

Definition at line 83 of file ertms_adapters.py.

◆ _position_report_from_fields()

_position_report_from_fields ( fields)
protected

Definition at line 15 of file ertms_adapters.py.

◆ _position_report_packet1_from_fields()

_position_report_packet1_from_fields ( fields)
protected
Same shape as _position_report_from_fields() plus Packet 1's own
extra NID_PRVLRBG pair (prv_nid_c/prv_nid_bg) - defaults to mirroring
nid_c/nid_bg when not explicitly given, since a stationary heartbeat's
"previous" LRBG is typically its own last-reported one.

Definition at line 39 of file ertms_adapters.py.

Variable Documentation

◆ ENCODERS

dict train.ertms_adapters.ENCODERS
Initial value:
= {
"M155": lambda nid_engine, fields, t_train: ertms.encode_msg_155(nid_engine, t_train),
"M156": lambda nid_engine, fields, t_train: ertms.encode_msg_156(nid_engine, t_train),
"M159": lambda nid_engine, fields, t_train: ertms.encode_msg_159(
nid_engine, fields.get("m_version", 0), t_train),
"M146": lambda nid_engine, fields, t_train: ertms.encode_msg_146(
nid_engine, fields.get("t_train_ack", 0), t_train),
"M136": lambda nid_engine, fields, t_train: ertms.encode_msg_136(
nid_engine, _position_report_from_fields(fields), t_train),
"M136_P1": lambda nid_engine, fields, t_train: ertms.encode_msg_136_packet1(
nid_engine, _position_report_packet1_from_fields(fields), t_train),
"M132": lambda nid_engine, fields, t_train: ertms.encode_msg_132(
nid_engine, fields.get("q_marqstreason", 0), _position_report_from_fields(fields), t_train),
"M129": lambda nid_engine, fields, t_train: ertms.encode_msg_129(
nid_engine, _position_report_from_fields(fields), fields.get("l_train", 0),
fields.get("v_maxtrain", 0), fields.get("m_loadinggauge", 0), fields.get("m_axleload", 0),
bool(fields.get("m_airtight", 0)), t_train),
"M130": lambda nid_engine, fields, t_train: ertms.encode_msg_130(
nid_engine, _position_report_from_fields(fields), t_train),
"M147": lambda nid_engine, fields, t_train: ertms.encode_msg_147(
nid_engine, fields.get("nid_em", 0), fields.get("q_emergency_stop", 0),
_position_report_from_fields(fields), t_train),
"M150": lambda nid_engine, fields, t_train: ertms.encode_msg_150(
nid_engine, _position_report_from_fields(fields), t_train),
"M154": lambda nid_engine, fields, t_train: ertms.encode_msg_154(nid_engine, t_train),
"M157": lambda nid_engine, fields, t_train: ertms.encode_msg_157(
nid_engine, fields.get("q_status", 0), _position_report_from_fields(fields), t_train),
"M158": lambda nid_engine, fields, t_train: ertms.encode_msg_158(
nid_engine, fields.get("nid_textmessage", 0), _position_report_from_fields(fields), t_train),
}

Definition at line 51 of file ertms_adapters.py.

◆ FLATTENERS

dict train.ertms_adapters.FLATTENERS
Initial value:
= {
ertms.MSG_MOVEMENT_AUTHORITY: _flatten_msg3,
ertms.MSG_GENERAL_MESSAGE: _flatten_msg24,
}

Definition at line 132 of file ertms_adapters.py.