Skip to main content

Module reference

Module reference 

Source
Expand description

§Protocol reference

Quick-reference tables for the parts of OpenLCB this crate implements. Values are hexadecimal. The authoritative source is the set of OpenLCB Standards and Technical Notes published at https://openlcb.org.

§Message Type Indicators

From the Message Network Standard, Event Transport Standard, Traction Control Standard, Simple Node Information Standard and Datagram Transport Standard. “A” = addressed (bit 3), “E” = carries an Event ID (bit 2). Constants are on Mti; variants on Message.

MTICAN-MTIFlagsNameMti constantPayload
0100100Initialization CompleteINITIALIZATION_COMPLETENode ID (6)
0101101Initialization Complete (simple)INITIALIZATION_COMPLETE_SIMPLENode ID (6)
0488488AVerify Node ID (addressed)VERIFY_NODE_ID_ADDRESSEDoptional Node ID
0490490Verify Node ID (global)VERIFY_NODE_ID_GLOBALoptional Node ID
0170170Verified Node IDVERIFIED_NODE_IDNode ID (6)
0171171Verified Node ID (simple)VERIFIED_NODE_ID_SIMPLENode ID (6)
0068068AOptional Interaction RejectedOPTIONAL_INTERACTION_REJECTEDerror code (2), MTI (2)
00A80A8ATerminate Due To ErrorTERMINATE_DUE_TO_ERRORerror code (2), MTI (2)
0828828AProtocol Support InquiryPROTOCOL_SUPPORT_INQUIRY—
0668668AProtocol Support ReplyPROTOCOL_SUPPORT_REPLYflags (6)
08F48F4EIdentify ConsumerIDENTIFY_CONSUMEREvent ID (8)
04A44A4EConsumer Range IdentifiedCONSUMER_RANGE_IDENTIFIEDEvent ID (8)
04C44C4EConsumer Identified, validCONSUMER_IDENTIFIED_VALIDEvent ID (8)
04C54C5EConsumer Identified, invalidCONSUMER_IDENTIFIED_INVALIDEvent ID (8)
04C74C7EConsumer Identified, unknownCONSUMER_IDENTIFIED_UNKNOWNEvent ID (8)
0914914EIdentify ProducerIDENTIFY_PRODUCEREvent ID (8)
0524524EProducer Range IdentifiedPRODUCER_RANGE_IDENTIFIEDEvent ID (8)
0544544EProducer Identified, validPRODUCER_IDENTIFIED_VALIDEvent ID (8)
0545545EProducer Identified, invalidPRODUCER_IDENTIFIED_INVALIDEvent ID (8)
0547547EProducer Identified, unknownPRODUCER_IDENTIFIED_UNKNOWNEvent ID (8)
0968968AIdentify Events (addressed)IDENTIFY_EVENTS_ADDRESSED—
0970970Identify Events (global)IDENTIFY_EVENTS_GLOBAL—
0594594ELearn EventLEARN_EVENTEvent ID (8)
05B45B4EProducer/Consumer Event Report (PCER)PCEREvent ID (8)
05EB5EBATraction Control CommandTRACTION_CONTROL_COMMANDsee traction commands
01E91E9ATraction Control ReplyTRACTION_CONTROL_REPLYsee traction replies
0DE8DE8ASimple Node Information RequestSNIP_REQUEST—
0A08A08ASimple Node Information ReplySNIP_REPLYsee SNIP
1C48(frame types 2-5)ADatagramDATAGRAMup to 72 bytes
0A28A28ADatagram Received OKDATAGRAM_RECEIVED_OKoptional flags (1)
0A48A48ADatagram RejectedDATAGRAM_REJECTEDerror code (2)

§CAN identifier layout

From the CAN Frame Transfer Standard. All frames are CAN 2.0B extended (29-bit identifier), 125 kbit/s.

  28  27  26 25 24  23 ................ 12  11 ................. 0
 ┌───┬───┬─────────┬─────────────────────────┬───────────────────────┐
 │ 1 │ F │  type   │     variable field      │     source alias      │
 └───┴───┴─────────┴─────────────────────────┴───────────────────────┘
   │   │      │                │
   │   │      │                └ CAN-MTI (type 1), destination alias (types 2-5, 7),
   │   │      │                  Node ID slice (CID) or control code (RID/AMD/AME/AMR)
   │   │      └ message frame type (F=1) or control sequence (F=0)
   │   └ F: 1 = OpenLCB message frame, 0 = CAN control frame
   └ reserved, always 1 (send) / ignored (receive)

See CanHeader.

§Control frames (bit 27 = 0)

Bits 26-24Bits 23-12FrameDataPurpose
7Node ID bits 47-36CID7—Check ID, 1st of 4
6Node ID bits 35-24CID6—Check ID, 2nd
5Node ID bits 23-12CID5—Check ID, 3rd
4Node ID bits 11-0CID4—Check ID, 4th
0700RID—Reserve ID: claim alias after 200 ms / defend against CID
0701AMDNode IDAlias Map Definition: alias ↔ Node ID; node is now permitted
0702AMEoptional Node IDAlias Mapping Enquiry: request AMDs
0703AMRNode IDAlias Map Reset: alias released

Example identifiers for alias 285 and Node ID 05.01.01.01.22.00:

 CID7 :X17050285N;   CID6 :X16101285N;   CID5 :X15012285N;   CID4 :X14200285N;
 RID  :X10700285N;   AMD  :X10701285N050101012200;
 Init Complete :X19100285N050101012200;

§Message frame types (bit 27 = 1)

Bits 26-24FrameVariable fieldData
0reserved
1Global / addressed messageCAN-MTIaddressed: 2-byte flags+dest, then ≤ 6 bytes; global: ≤ 8 bytes
2Datagram, only framedestination alias≤ 8 bytes
3Datagram, first framedestination alias8 bytes
4Datagram, middle framedestination alias8 bytes
5Datagram, final framedestination alias≤ 8 bytes
6reserved
7Stream datadestination alias

See MessageFrameType.

§Addressed message framing

The first two data bytes of every frame of an addressed message:

 byte 0: F F F F D D D D     FFFF framing (bits 5-4 used), DDDD = dest alias bits 11-8
 byte 1: D D D D D D D D     dest alias bits 7-0
Byte 0 high nibbleMeaning
0only frame
1first frame of several
3middle frame
2last frame

For example a 9-byte Assign Controller from alias 285 to alias 6A1:

:X195EB285N16A1200100050101   first: flag 1, dest 6A1, 6 payload bytes
:X195EB285N26A1012299         last:  flag 2, dest 6A1, 3 payload bytes

§Protocol Support (PIP) bits

Reply payload bytes 0-2 as used by message::protocol (byte 0 = bits 23-16 of the u32).

ByteBitMask (u32)ProtocolConstant
0780_0000Simple Protocol subsetSIMPLE
0640_0000DatagramDATAGRAM
0520_0000StreamSTREAM
0410_0000Memory ConfigurationMEMORY_CONFIGURATION
0308_0000ReservationRESERVATION
0204_0000Event ExchangeEVENT_EXCHANGE
0102_0000IdentificationIDENTIFICATION
0001_0000Teaching / LearningTEACHING
1700_8000Remote ButtonREMOTE_BUTTON
1600_4000Abbreviated Default CDIACDI
1500_2000DisplayDISPLAY
1400_1000Simple Node InformationSNIP
1300_0800Configuration Description InformationCDI
1200_0400Traction ControlTRACTION_CONTROL
1100_0200Function Description InformationFDI
2700_0080Simple Train Node InformationSIMPLE_TRAIN_NODE_INFO
2600_0040Function ConfigurationFUNCTION_CONFIGURATION

A default Node advertises EVENT_EXCHANGE | SNIP (04_1000).

§Traction Control commands

Payload of MTI 05EB; see traction::Command and traction::cmd. Multi-byte fields are big-endian.

BytesCommandVariant
00 SS SSSet Speed (half-float m/s, sign = reverse)SetSpeed
01 AA AA AA VV VVSet Function (24-bit address, 16-bit value)SetFunction
02Emergency StopEmergencyStop
10Query SpeedQuerySpeed
11 AA AA AAQuery FunctionQueryFunction
20 01 FF NN NN NN NN NN NNAssign Controller (flags, Node ID)AssignController
20 02 FF NN NN NN NN NN NNRelease ControllerReleaseController
20 03Query ControllerQueryController
20 04 FF NN NN NN NN NN NNController Changing Notify (flags, new controller’s Node ID); sent by the train to its current controllerControllerChangingNotify
30 …Consist (listener) configurationUnknown
40 01Management: ReserveReserve
40 02Management: ReleaseRelease
40 03Management: No-op / heartbeat answerNoop

Bit 7 of byte 0 (80, LISTENER_FLAG) marks a command forwarded to a consist member; decoding ignores it. A Node without the TRACTION_CONTROL protocol bit rejects incoming commands with Optional Interaction Rejected 1043, except Controller Changing Notify (20 04), which throttles must receive.

§Traction Control replies

Payload of MTI 01E9; see traction::Reply.

BytesReplyVariant
10 SS SS ST CC CC AA AAQuery Speed: set speed, status (bit 0 = e-stop), commanded, actualQuerySpeed
11 AA AA AA VV VVQuery FunctionQueryFunction
20 01 RRAssign Controller result (0 = OK)AssignController
20 03 FF NN NN NN NN NN NNQuery Controller (flags, controller Node ID)QueryController
20 04 RRController Changing reply, sent by the current controller to the train (0 = handover accepted)ControllerChanged
40 01 RRReserve resultReserve
40 03 TTHeartbeat request, timeout TT secondsHeartbeat

§Half-float speeds

SpeedBitsNotes
stop, forward0000Speed::STOP_FORWARD
stop, reverse8000Speed::STOP_REVERSE (-0.0)
1.0 m/s forward3C00
1.0 m/s reverseBC00sign bit set
0.5 m/s3800
126 mph ≈ 56.33 m/s530ADCC “full speed” by convention
not availableFFFFSpeed::NAN, in Query Speed replies

§Train search events

From the Train Search Standard; see traction::search.

 09.00.99.FF . D5 D4 . D3 D2 . D1 D0 . FLAGS
             └──── 6 BCD nibbles ───┘  F = unused (leading)
FlagMaskMeaning
ALLOCATE80Create the train if none matches
EXACT40Only exact matches
ADDRESS_ONLY20Match address only, not name
DCC08DCC protocol
DCC_LONG_ADDRESS04Long (extended) DCC address
SPEED_STEPS_MASK030 default, 1 = 14, 2 = 28, 3 = 128 steps
SearchEvent ID
DCC 3, short09.00.99.FF.FF.FF.F3.68
DCC 3, short, allocate09.00.99.FF.FF.FF.F3.E8
DCC 1234 (long)09.00.99.FF.FF.12.34.6C

§Simple Node Information

Payload of the SNIP reply; see NodeInfo.

FieldMax bytes incl. NUL
version (04)1
manufacturer41
model41
hardware version21
software version21
user version (02)1
user name63
user description64

§Error codes

Used by Optional Interaction Rejected, Terminate Due To Error and Datagram Rejected; see mti::error_code.

CodeClassMeaningConstant
1000permanentpermanent errorPERMANENT
1020permanentsource not permittedSOURCE_NOT_PERMITTED
1040permanentnot implementedNOT_IMPLEMENTED
1041permanentnot implemented: unknown sub-commandNOT_IMPLEMENTED_SUBCOMMAND
1042permanentnot implemented: unknown commandNOT_IMPLEMENTED_COMMAND
1043permanentnot implemented: unknown MTI or transport protocol. Sent by Node for unknown addressed MTIs, traction commands to a non-train, and datagramsNOT_IMPLEMENTED_UNKNOWN_MTI
2000temporarytemporary error, retry laterTEMPORARY
2010temporarytimeoutTIMEOUT
2020temporarybuffer unavailableBUFFER_UNAVAILABLE
2040temporaryout of orderOUT_OF_ORDER
2041temporaryout of order: middle or final frame without a first frameOUT_OF_ORDER_NO_START
2042temporaryout of order: first frame before the previous message endedOUT_OF_ORDER_START_BEFORE_END

§Well-known events

Event IDMeaningConstant
01.00.00.00.00.00.FF.FFEmergency Off (de-energize)EventId::EMERGENCY_OFF
01.00.00.00.00.00.FF.FEClear Emergency OffEventId::CLEAR_EMERGENCY_OFF
01.00.00.00.00.00.FF.FDEmergency Stop of all operationsEventId::EMERGENCY_STOP
01.00.00.00.00.00.FF.FCClear Emergency StopEventId::CLEAR_EMERGENCY_STOP
01.01.00.00.00.00.02.01Duplicate Node ID detected (produced once by Node)EventId::DUPLICATE_NODE_ID
01.01.00.00.00.00.03.03Is Train (produced by train nodes)EventId::IS_TRAIN

§Timing and limits

ItemValue
CID → RID wait200 ms (ALIAS_RESERVE_MS)
Messages held before login512 (MAX_PENDING)
Partial multi-frame messages tracked32 (oldest evicted first)
Partial message expiry (accept_at, used by Node)3 s without a new frame (PARTIAL_TIMEOUT_MS)
Maximum reassembled payload256 bytes
Datagram maximum (standard)72 bytes
GridConnect decoder token limit32 characters
Hub broadcast ring (shared by all ports)4096 frames
Hub write batch64 frames
Hub reconnect delay2 s