|
TrainRBCSim
ADR-029 Train (EVC) simulator — dual-homed TCP client speaking the RBC wire protocol
|
Classes | |
| class | ErtmsDecodeError |
Functions | |
| _pack_position_report (pos) | |
| _unpack_position_report (buf, offset) | |
| _finalize (nid_message, body_after_header, nid_engine, t_train) | |
| encode_msg_155 (nid_engine, t_train=0) | |
| encode_msg_156 (nid_engine, t_train=0) | |
| encode_msg_159 (nid_engine, m_version, t_train=0) | |
| encode_msg_146 (nid_engine, t_train_ack, t_train=0) | |
| encode_msg_136 (nid_engine, position_report, t_train=0) | |
| encode_msg_136_packet1 (nid_engine, packet1_report, t_train=0) | |
| encode_msg_132 (nid_engine, q_marqstreason, position_report, t_train=0) | |
| encode_msg_129 (nid_engine, position_report, l_train, v_maxtrain, m_loadinggauge, m_axleload, m_airtight, t_train=0) | |
| encode_msg_130 (nid_engine, position_report, t_train=0) | |
| encode_msg_147 (nid_engine, nid_em, q_emergency_stop, position_report, t_train=0) | |
| encode_msg_150 (nid_engine, position_report, t_train=0) | |
| encode_msg_154 (nid_engine, t_train=0) | |
| encode_msg_157 (nid_engine, q_status, position_report, t_train=0) | |
| encode_msg_158 (nid_engine, nid_textmessage, position_report, t_train=0) | |
| _decode_header_c2t (buf) | |
| decode_msg_3 (buf) | |
| decode_msg_24 (buf) | |
| decode (buf) | |
Real Subset-026 ERTMS message codec - Python mirror of
safeAPIRBC2oo2GP/src/application/AB/GP/ertms/train/ab_gp_ertms_train_codec.c
(byte shape and order only). Keep this file in exact sync with that C
file by hand; there is no shared schema between the two languages, same
"by-hand port, not a generated binding" precedent rbc_wire.py's own
module doc already states for the flat ADR-029 scheme.
**Deliberately a DIFFERENT wire shape from rbc_wire.py, not a variant of
it** - this is not an oversight, don't "fix" the two into consistency:
- rbc_wire.py: one fixed 96-byte struct, little-endian, every field at
a fixed offset regardless of kind - mirrors rbc_wire_types.h/
rbc_wire.c's own flat ADR-029 envelope.
- This module: real Subset-026 message-specific shapes, BIG-endian,
genuinely variable length (optional packets each self-identify with
their own leading NID_PACKET byte) - mirrors ab_gp_ertms_train_codec.c,
a byte-aligned TLV codec (not literally the real spec's own sub-byte
bit-packing - see that C file's own header doc for why: a deliberate,
already-made MISRA-friendly simplification this module also follows).
Both scheme's bytes are wrapped identically at the TRANSPORT level by one
new envelope kind, RBC_MSG_ERTMS_ENVELOPE (rbc_wire_types.h) - see that
kind's own doc: byte 0 = the kind (22 - moved from 21 after a real
collision with this project's own flat TRAIN_CONNECT=21, see
rbc_wire_types.h's/rbc_messages.py's own comments), byte 1 = train_id, bytes 2..
= this module's own encode()/decode() output verbatim. rbc_messages.py's
MessageCatalog is what actually builds/parses that 2-byte prefix (its own
"ertms" wireFormat branch) - this module only ever sees/produces the
bytes AFTER that prefix, same "SimCore doesn't know kind numbers"
boundary rbc_wire.py's own module doc draws for the flat scheme.
Real NID_MESSAGE/NID_PACKET numbers only, never this project's own flat-
scheme project-specific numbering (rbc_wire.py's `kind` byte) - see
ab_gp_ertms_train_interface.h/ab_gp_ertms_train_packets.h for the C-side
`#define`s these mirror.
|
protected |
Definition at line 249 of file rbc_ertms_wire.py.
|
protected |
Builds the full Train-to-Track frame and patches l_message with the real total length, exactly matching rbc_train_codec_encode_track_to_train()'s own "l_message computed here, not caller-supplied" fix on the C side - never trust a placeholder length, always the real encoded size.
Definition at line 130 of file rbc_ertms_wire.py.
|
protected |
@param pos: dict with the full Packet 0 field set - q_scale, nid_c, nid_bg, d_lrbg, q_dirlrbg, q_dlrbg, l_doubtover, l_doubtunder, v_train, m_mode, m_level - matching rbc_packet_read_0_position_report()'s own field order exactly (ab_gp_ertms_train_packet_codec.c).
Definition at line 108 of file rbc_ertms_wire.py.
|
protected |
Unused today (this sim only ENCODES Packet 0, as the message originator - see _pack_position_report()'s own doc) - kept for encode/decode symmetry with the rest of this module.
Definition at line 118 of file rbc_ertms_wire.py.
| decode | ( | buf | ) |
@return (nid_message, decoded_dict) by peeking buf[0], dispatching to the matching decode_msg_*() above. Raises ErtmsDecodeError for an empty buffer or an nid_message this module doesn't yet decode (Msg 16/18 - Emergency Stop - have real C-side encoders already but no Python decoder yet, out of scope for the SoM/Running/EoM flow).
Definition at line 399 of file rbc_ertms_wire.py.
| decode_msg_24 | ( | buf | ) |
Msg 24: General Message. @return dict with header and whichever of Packet 3/57/58/65/66/72 were present - same has_X/X pairing ab_gp_ertms_train_interface.h's own rbc_msg_24_general_message_t struct uses.
Definition at line 324 of file rbc_ertms_wire.py.
| decode_msg_3 | ( | buf | ) |
Msg 3: Movement Authority. @return dict with header, ma (Packet 15, always present), and optional gradient/ssp/linking (Packets 21/27/5) - same has_X/X pairing ab_gp_ertms_train_interface.h's own rbc_msg_3_movement_authority_t struct uses.
Definition at line 260 of file rbc_ertms_wire.py.
| encode_msg_129 | ( | nid_engine, | |
| position_report, | |||
| l_train, | |||
| v_maxtrain, | |||
| m_loadinggauge, | |||
| m_axleload, | |||
| m_airtight, | |||
| t_train = 0 ) |
Msg 129: Validated Train Data - Packet 0 then the flat train-data fields (same field subset ab_gp_ertms_train_codec.c's own decode reads).
Definition at line 197 of file rbc_ertms_wire.py.
| encode_msg_130 | ( | nid_engine, | |
| position_report, | |||
| t_train = 0 ) |
Msg 130: Request for Shunting - Packet 0.
Definition at line 208 of file rbc_ertms_wire.py.
| encode_msg_132 | ( | nid_engine, | |
| q_marqstreason, | |||
| position_report, | |||
| t_train = 0 ) |
Msg 132: MA Request - Q_MARQSTREASON then Packet 0.
Definition at line 191 of file rbc_ertms_wire.py.
| encode_msg_136 | ( | nid_engine, | |
| position_report, | |||
| t_train = 0 ) |
Msg 136: Train Position Report, Packet 0 - the normal active-mission cadence. Real Subset-026 Msg 136 self-identifies which packet variant it carries with a leading NID_PACKET byte (see rbc_train_codec_decode_train_to_track()'s own Msg 136 case) - this encoder writes PACKET_0_POSITION_REPORT then the Packet 0 body.
Definition at line 167 of file rbc_ertms_wire.py.
| encode_msg_136_packet1 | ( | nid_engine, | |
| packet1_report, | |||
| t_train = 0 ) |
Msg 136: Train Position Report, Packet 1 (2-balise-group variant) - the post-EoM idle heartbeat cadence (see train_sim.py's own post-EoM phase tracking). @param packet1_report: dict with nid_c, nid_bg, prv_nid_c, prv_nid_bg, d_lrbg, v_train, m_mode, m_level - same field set read_position_report_packet1() reads on the C side.
Definition at line 177 of file rbc_ertms_wire.py.
| encode_msg_146 | ( | nid_engine, | |
| t_train_ack, | |||
| t_train = 0 ) |
Msg 146: Acknowledgement - real Subset-026 146 acks by TIMESTAMP of the acked message, not a sequence number (see message_catalog.json's own _subset026Reference comment on this).
Definition at line 160 of file rbc_ertms_wire.py.
| encode_msg_147 | ( | nid_engine, | |
| nid_em, | |||
| q_emergency_stop, | |||
| position_report, | |||
| t_train = 0 ) |
Msg 147: Ack Emergency Stop - NID_EM, Q_EMERGENCY_STOP then Packet 0.
Definition at line 213 of file rbc_ertms_wire.py.
| encode_msg_150 | ( | nid_engine, | |
| position_report, | |||
| t_train = 0 ) |
Msg 150: End of Mission - Packet 0.
Definition at line 219 of file rbc_ertms_wire.py.
| encode_msg_154 | ( | nid_engine, | |
| t_train = 0 ) |
Msg 154: No compatible version supported - header only.
Definition at line 224 of file rbc_ertms_wire.py.
| encode_msg_155 | ( | nid_engine, | |
| t_train = 0 ) |
Msg 155: Initiation of a Communication Session - header only.
Definition at line 145 of file rbc_ertms_wire.py.
| encode_msg_156 | ( | nid_engine, | |
| t_train = 0 ) |
Msg 156: Termination of a Communication Session - header only.
Definition at line 150 of file rbc_ertms_wire.py.
| encode_msg_157 | ( | nid_engine, | |
| q_status, | |||
| position_report, | |||
| t_train = 0 ) |
Msg 157: SoM Position Report - Q_STATUS then Packet 0.
Definition at line 229 of file rbc_ertms_wire.py.
| encode_msg_158 | ( | nid_engine, | |
| nid_textmessage, | |||
| position_report, | |||
| t_train = 0 ) |
Msg 158: Text Message Ack - NID_TEXTMESSAGE then Packet 0.
Definition at line 235 of file rbc_ertms_wire.py.
| encode_msg_159 | ( | nid_engine, | |
| m_version, | |||
| t_train = 0 ) |
Msg 159: Session Established.
Definition at line 155 of file rbc_ertms_wire.py.
|
protected |
Definition at line 393 of file rbc_ertms_wire.py.
|
protected |
Definition at line 69 of file rbc_ertms_wire.py.
|
protected |
Definition at line 68 of file rbc_ertms_wire.py.
|
protected |
Definition at line 78 of file rbc_ertms_wire.py.
|
protected |
Definition at line 79 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_ACK_EMERGENCY_STOP = 147 |
Definition at line 46 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_ACKNOWLEDGEMENT = 146 |
Definition at line 45 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_GENERAL_MESSAGE = 24 |
Definition at line 54 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_INIT_SESSION = 155 |
Definition at line 47 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_MA_REQUEST = 132 |
Definition at line 43 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_MOVEMENT_AUTHORITY = 3 |
Definition at line 51 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_POSITION_REPORT = 136 |
Definition at line 44 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_REQUEST_FOR_SHUNTING = 130 |
Definition at line 42 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_REVOCATION_EMERGENCY_STOP = 18 |
Definition at line 53 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_SESSION_ESTABLISHED = 159 |
Definition at line 49 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_TERMINATE_SESSION = 156 |
Definition at line 48 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_UNCONDITIONAL_EMERGENCY_STOP = 16 |
Definition at line 52 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.MSG_VALIDATED_TRAIN_DATA = 129 |
Definition at line 41 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_0_POSITION_REPORT = 0 |
Definition at line 104 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_1_POSITION_REPORT_2BG = 1 |
Definition at line 105 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_GRADIENT_PROFILE = 21 |
Definition at line 60 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_LEVEL_2_3_MA = 15 |
Definition at line 59 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_LINKING_INFO = 5 |
Definition at line 58 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_MA_REQUEST_PARAMS = 57 |
Definition at line 62 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_NATIONAL_VALUES = 3 |
Definition at line 57 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_POSITION_REPORT_PARAMS = 58 |
Definition at line 63 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_STATIC_SPEED_PROFILE = 27 |
Definition at line 61 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_TEMPORARY_SPEED_RESTRICT = 65 |
Definition at line 64 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_TEXT_MESSAGE = 72 |
Definition at line 66 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.PACKET_TSR_REVOCATION = 66 |
Definition at line 65 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_DIRLRBG_NOMINAL = 1 |
Definition at line 92 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_DIRLRBG_REVERSE = 0 |
Definition at line 91 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_DIRLRBG_UNKNOWN = 2 |
Definition at line 93 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_DLRBG_NOMINAL = 1 |
Definition at line 95 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_DLRBG_REVERSE = 0 |
Definition at line 94 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_DLRBG_UNKNOWN = 2 |
Definition at line 96 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_SCALE_10CM = 0 |
Definition at line 88 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_SCALE_10M = 2 |
Definition at line 90 of file rbc_ertms_wire.py.
| int train.rbc_ertms_wire.Q_SCALE_1M = 1 |
Definition at line 89 of file rbc_ertms_wire.py.