Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::TractionDefs Struct Reference

Static constants and helper functions for the Traciton protocol family. More...

#include <TractionDefs.hxx>

Public Types

enum  {
  REQ_SET_SPEED = 0x00 , REQ_SET_FN = 0x01 , REQ_EMERGENCY_STOP = 0x02 , REQ_QUERY_SPEED = 0x10 ,
  REQ_QUERY_FN = 0x11 , REQ_CONTROLLER_CONFIG = 0x20 , REQ_CONSIST_CONFIG = 0x30 , REQ_TRACTION_MGMT = 0x40 ,
  REQ_MASK = 0x7F , REQ_LISTENER = 0x80 , CTRLREQ_ASSIGN_CONTROLLER = 0x01 , CTRLREQ_RELEASE_CONTROLLER = 0x02 ,
  CTRLREQ_QUERY_CONTROLLER = 0x03 , CTRLREQ_NOTIFY_CONTROLLER_CHANGED = 0x04 , CNSTREQ_ATTACH_NODE = 0x01 , CNSTREQ_DETACH_NODE = 0x02 ,
  CNSTREQ_QUERY_NODES = 0x03 , MGMTREQ_RESERVE = 0x01 , MGMTREQ_RELEASE = 0x02 , MGMTREQ_NOOP = 0x03 ,
  RESP_QUERY_SPEED = REQ_QUERY_SPEED , RESP_QUERY_FN = REQ_QUERY_FN , RESP_CONTROLLER_CONFIG = REQ_CONTROLLER_CONFIG , RESP_CONSIST_CONFIG = REQ_CONSIST_CONFIG ,
  RESP_TRACTION_MGMT = REQ_TRACTION_MGMT , SPEEDRESP_STATUS_IS_ESTOP = 1 , CTRLRESP_ASSIGN_CONTROLLER = CTRLREQ_ASSIGN_CONTROLLER , CTRLRESP_QUERY_CONTROLLER = CTRLREQ_QUERY_CONTROLLER ,
  CTRLRESP_NOTIFY_CONTROLLER_CHANGED = CTRLREQ_NOTIFY_CONTROLLER_CHANGED , CTRLRESP_ASSIGN_ERROR_TRAIN = 0x02 , CTRLRESP_ASSIGN_ERROR_CONTROLLER = 0x01 , CNSTRESP_ATTACH_NODE = CNSTREQ_ATTACH_NODE ,
  CNSTRESP_DETACH_NODE = CNSTREQ_DETACH_NODE , CNSTRESP_QUERY_NODES = CNSTREQ_QUERY_NODES , CNSTFLAGS_ALIASVALID = 0x01 , CNSTFLAGS_REVERSE = 0x02 ,
  CNSTFLAGS_LINKF0 = 0x04 , CNSTFLAGS_LINKFN = 0x08 , CNSTFLAGS_HIDE = 0x80 , MGMTRESP_RESERVE = MGMTREQ_RESERVE ,
  MGMTRESP_HEARTBEAT = 0x03 , PROXYREQ_ALLOCATE = 0x01 , PROXYREQ_ATTACH = 0x02 , PROXYREQ_DETACH = 0x03 ,
  PROXYREQ_MANAGE = 0x80 , PROXYRESP_ALLOCATE = PROXYREQ_ALLOCATE , PROXYRESP_ATTACH = PROXYREQ_ATTACH , PROXYRESP_MANAGE = PROXYREQ_MANAGE ,
  PROXYREQ_MANAGE_RESERVE = 0x01 , PROXYREQ_MANAGE_RELEASE = 0x02 , PROXYRESP_MANAGE_RESERVE_REPLY = 0x01 , PROXYTYPE_DCC = 1 ,
  PROXYTYPE_DC = 2 , PROXYTYPE_MARKLIN_DIGITAL = 3 , PROXYTYPE_MARKLIN_DELTA = 4 , PROXYTYPE_MARKLIN_MFX = 5 ,
  PROXYTYPE_SELECTRIX = 6 , PROXYTYPE_MTH_DCS = 7 , PROXYTYPE_LIONEL_TMCC = 8 , FUNCTION_CONFIG_MEMORY_SPACE = 0xF9 ,
  FNCONFIG_FN = 0x0 , FNCONFIG_BINARYSTATE_LONG = 0x1 , FNCONFIG_BINARYSTATE_SHORT = 0x2 , FNCONFIG_ANALOG_OUTPUT = 0x3
}
 

Static Public Member Functions

static NodeID train_node_id_from_legacy (dcc::TrainAddressType type, uint32_t addr)
 Converts a legacy address to an NMRAnet node ID.
 
static bool legacy_address_from_train_node_id (NodeID id, dcc::TrainAddressType *type, uint32_t *addr)
 Converts a node ID to a legacy address if possible.
 
static string train_node_name_from_legacy (dcc::TrainAddressType type, uint32_t addr)
 Converts a legacy address to a user-visible name.
 
static string guess_train_node_name (NodeID node_id)
 Renders a guess at the traction node name.
 
static Payload estop_set_payload ()
 
static Payload speed_set_payload (Velocity v)
 
static Payload speed_get_payload ()
 
static bool speed_get_parse_last (const Payload &p, Velocity *v, bool *is_estop=nullptr)
 Parses the response payload of a GET_SPEED packet.
 
static Payload fn_set_payload (unsigned address, uint16_t value)
 
static Payload fn_get_payload (unsigned address)
 
static bool fn_get_parse (const Payload &p, uint16_t *value, unsigned *address)
 Parses the response payload of a GET_FN packet.
 
static Payload assign_controller_payload (Node *ctrl)
 
static Payload release_controller_payload (Node *ctrl)
 
static Payload consist_add_payload (NodeID slave, uint8_t flags)
 
static Payload consist_add_response (NodeID slave, uint16_t error_code)
 
static Payload consist_del_payload (NodeID slave)
 
static Payload consist_del_response (NodeID slave, uint16_t error_code)
 
static Payload consist_qry_payload ()
 
static Payload consist_qry_payload (uint8_t arg)
 
static Payload consist_qry_response_short (uint8_t num_entries)
 
static Payload consist_qry_response_long (uint8_t num_entries, uint8_t index, uint8_t flags, NodeID slave)
 
static Payload heartbeat_request_payload (uint8_t deadline_sec=3)
 Generates a Heartbeat Request, to be sent from the train node to the controller.
 
static Payload noop_payload ()
 Generates a Noop message, to be sent from the throttle to the train node.
 

Static Public Attributes

static const uint64_t IS_TRAIN_EVENT = 0x0101000000000303ULL
 This event should be produced by train nodes.
 
static const uint64_t IS_PROXY_EVENT = 0x0101000000000304ULL
 This event should be produced by traction proxy nodes.
 
static constexpr uint64_t ACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE = 0x0101020000FF0000ULL
 Base address of DCC accessory decoder well-known event range (active)
 
static constexpr uint64_t INACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE = 0x0101020000FE0000ULL
 Base address of DCC accessory decoder well-known event range (inactive)
 
static constexpr uint64_t EXT_DCC_ACCESSORY_EVENT_BASE = 0x0101020001000000ULL
 Base address of DCC extended accessory decoder well-known event range.
 
static const uint64_t NODE_ID_DC_BLOCK = 0x060000000000ULL
 Node ID space allocated for DC blocks.
 
static const uint64_t NODE_ID_DCC = 0x060100000000ULL
 Node ID space allocated for DCC locomotives.
 
static const uint16_t DCC_LONG_SELECTOR = 0xC000
 Long addresses should OR this selector to {}.
 
static const uint64_t NODE_ID_TMCC = 0x060200000000ULL
 Node ID space allocated for TMCC protocol.
 
static const uint64_t NODE_ID_MARKLIN_MOTOROLA = 0x060300000000ULL
 Node ID space allocated for the Marklin-Motorola protocol.
 
static const uint64_t NODE_ID_MTH_DCS = 0x060400000000ULL
 Node ID space allocated for the MTH DCS protocol.
 
static const uint64_t NODE_ID_MASK = 0xFFFF00000000ULL
 Node ID space mask.
 

Detailed Description

Static constants and helper functions for the Traciton protocol family.

Definition at line 67 of file TractionDefs.hxx.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
REQ_MASK 

Mask to apply to the command byte of the requests.

REQ_LISTENER 

Flag bit in the command byte set when a listener command is forwarded.

FUNCTION_CONFIG_MEMORY_SPACE 

This is the memory space number for accessing an NMRA DCC locomotive's functions via the memory config protocol.

FNCONFIG_FN 

F0-F28 are at offset 0 to 28 here.

FNCONFIG_BINARYSTATE_LONG 

Binary State Control Instruction long form.

Offset 0 to 32767

FNCONFIG_BINARYSTATE_SHORT 

Binary State Control Instruction short form.

Offset 0 to 127

FNCONFIG_ANALOG_OUTPUT 

Analog outputs, defined by NMRA DCC WG Topic 9910241.

Offset 0-255, values 0-255 each.

Definition at line 93 of file TractionDefs.hxx.

Member Function Documentation

◆ assign_controller_payload()

static Payload openlcb::TractionDefs::assign_controller_payload ( Node ctrl)
inlinestatic

Definition at line 424 of file TractionDefs.hxx.

◆ consist_add_payload()

static Payload openlcb::TractionDefs::consist_add_payload ( NodeID  slave,
uint8_t  flags 
)
inlinestatic

Definition at line 444 of file TractionDefs.hxx.

◆ consist_add_response()

static Payload openlcb::TractionDefs::consist_add_response ( NodeID  slave,
uint16_t  error_code 
)
inlinestatic

Definition at line 454 of file TractionDefs.hxx.

◆ consist_del_payload()

static Payload openlcb::TractionDefs::consist_del_payload ( NodeID  slave)
inlinestatic

Definition at line 464 of file TractionDefs.hxx.

◆ consist_del_response()

static Payload openlcb::TractionDefs::consist_del_response ( NodeID  slave,
uint16_t  error_code 
)
inlinestatic

Definition at line 473 of file TractionDefs.hxx.

◆ consist_qry_payload() [1/2]

static Payload openlcb::TractionDefs::consist_qry_payload ( )
inlinestatic

Definition at line 480 of file TractionDefs.hxx.

◆ consist_qry_payload() [2/2]

static Payload openlcb::TractionDefs::consist_qry_payload ( uint8_t  arg)
inlinestatic

Definition at line 488 of file TractionDefs.hxx.

◆ consist_qry_response_long()

static Payload openlcb::TractionDefs::consist_qry_response_long ( uint8_t  num_entries,
uint8_t  index,
uint8_t  flags,
NodeID  slave 
)
inlinestatic

Definition at line 506 of file TractionDefs.hxx.

◆ consist_qry_response_short()

static Payload openlcb::TractionDefs::consist_qry_response_short ( uint8_t  num_entries)
inlinestatic

Definition at line 497 of file TractionDefs.hxx.

◆ estop_set_payload()

static Payload openlcb::TractionDefs::estop_set_payload ( )
inlinestatic

Definition at line 333 of file TractionDefs.hxx.

◆ fn_get_parse()

static bool openlcb::TractionDefs::fn_get_parse ( const Payload p,
uint16_t *  value,
unsigned *  address 
)
inlinestatic

Parses the response payload of a GET_FN packet.

Returns
true if there is a valid function value.
Parameters
pis the response payload.
valuewill be set to the output value.
addresswill be set to the function address.

Definition at line 407 of file TractionDefs.hxx.

◆ fn_get_payload()

static Payload openlcb::TractionDefs::fn_get_payload ( unsigned  address)
inlinestatic

Definition at line 393 of file TractionDefs.hxx.

◆ fn_set_payload()

static Payload openlcb::TractionDefs::fn_set_payload ( unsigned  address,
uint16_t  value 
)
inlinestatic

Definition at line 382 of file TractionDefs.hxx.

◆ guess_train_node_name()

static string openlcb::TractionDefs::guess_train_node_name ( NodeID  node_id)
inlinestatic

Renders a guess at the traction node name.

If it is a recognized train node range, renders te default name for that protocol, otherwise a mac address format.

Parameters
node_idis the train node OpenLCB node ID
Returns
a user-visible node name

Definition at line 313 of file TractionDefs.hxx.

◆ heartbeat_request_payload()

static Payload openlcb::TractionDefs::heartbeat_request_payload ( uint8_t  deadline_sec = 3)
inlinestatic

Generates a Heartbeat Request, to be sent from the train node to the controller.

Definition at line 521 of file TractionDefs.hxx.

◆ legacy_address_from_train_node_id()

static bool openlcb::TractionDefs::legacy_address_from_train_node_id ( NodeID  id,
dcc::TrainAddressType type,
uint32_t *  addr 
)
inlinestatic

Converts a node ID to a legacy address if possible.

Parameters
idis an openLCB NodeID
type(must be not null) will be filled with the legacy train address type
addr(must be not null) will be filled with the legacy train address.
Returns
true if the address was recognized and type, addr was filled with values. Returns false if the address was not recognized as a legacy train node's address.

Definition at line 241 of file TractionDefs.hxx.

◆ noop_payload()

static Payload openlcb::TractionDefs::noop_payload ( )
inlinestatic

Generates a Noop message, to be sent from the throttle to the train node.

Definition at line 531 of file TractionDefs.hxx.

◆ release_controller_payload()

static Payload openlcb::TractionDefs::release_controller_payload ( Node ctrl)
inlinestatic

Definition at line 434 of file TractionDefs.hxx.

◆ speed_get_parse_last()

static bool openlcb::TractionDefs::speed_get_parse_last ( const Payload p,
Velocity v,
bool is_estop = nullptr 
)
inlinestatic

Parses the response payload of a GET_SPEED packet.

Returns
true if the last_set_speed value was present and non-NaN.
Parameters
pis the response payload.
vis the velocity that will be set to the speed value.
is_estopif non-null, will be set to true if the train was last set to estop instead of a speed.

Definition at line 359 of file TractionDefs.hxx.

◆ speed_get_payload()

static Payload openlcb::TractionDefs::speed_get_payload ( )
inlinestatic

Definition at line 346 of file TractionDefs.hxx.

◆ speed_set_payload()

static Payload openlcb::TractionDefs::speed_set_payload ( Velocity  v)
inlinestatic

Definition at line 339 of file TractionDefs.hxx.

◆ train_node_id_from_legacy()

static NodeID openlcb::TractionDefs::train_node_id_from_legacy ( dcc::TrainAddressType  type,
uint32_t  addr 
)
inlinestatic

Converts a legacy address to an NMRAnet node ID.

The conversion algorithm chosen here is rather arbitrary, as it is not specified in the standard how the individual reserved blocks are laid out internally to addresses. The only important thing is that for different track bit patterns a different node ID be generated.

Parameters
typedefines what address type it is (dcc-short, dcc-long or MM)
addris the legacy address, the valid values are defined by the specific protocols.

Definition at line 215 of file TractionDefs.hxx.

◆ train_node_name_from_legacy()

static string openlcb::TractionDefs::train_node_name_from_legacy ( dcc::TrainAddressType  type,
uint32_t  addr 
)
inlinestatic

Converts a legacy address to a user-visible name.

Parameters
typedefines what address type it is (dcc-short, dcc-long or MM)
addris the legacy address, the valid values are defined by the specific protocols.
Returns
user-readable address.

Definition at line 277 of file TractionDefs.hxx.

Member Data Documentation

◆ ACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE

constexpr uint64_t openlcb::TractionDefs::ACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE = 0x0101020000FF0000ULL
staticconstexpr

Base address of DCC accessory decoder well-known event range (active)

Definition at line 73 of file TractionDefs.hxx.

◆ DCC_LONG_SELECTOR

const uint16_t openlcb::TractionDefs::DCC_LONG_SELECTOR = 0xC000
static

Long addresses should OR this selector to {}.

Definition at line 83 of file TractionDefs.hxx.

◆ EXT_DCC_ACCESSORY_EVENT_BASE

constexpr uint64_t openlcb::TractionDefs::EXT_DCC_ACCESSORY_EVENT_BASE = 0x0101020001000000ULL
staticconstexpr

Base address of DCC extended accessory decoder well-known event range.

Definition at line 77 of file TractionDefs.hxx.

◆ INACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE

constexpr uint64_t openlcb::TractionDefs::INACTIVATE_BASIC_DCC_ACCESSORY_EVENT_BASE = 0x0101020000FE0000ULL
staticconstexpr

Base address of DCC accessory decoder well-known event range (inactive)

Definition at line 75 of file TractionDefs.hxx.

◆ IS_PROXY_EVENT

const uint64_t openlcb::TractionDefs::IS_PROXY_EVENT = 0x0101000000000304ULL
static

This event should be produced by traction proxy nodes.

Definition at line 71 of file TractionDefs.hxx.

◆ IS_TRAIN_EVENT

const uint64_t openlcb::TractionDefs::IS_TRAIN_EVENT = 0x0101000000000303ULL
static

This event should be produced by train nodes.

Definition at line 69 of file TractionDefs.hxx.

◆ NODE_ID_DC_BLOCK

const uint64_t openlcb::TractionDefs::NODE_ID_DC_BLOCK = 0x060000000000ULL
static

Node ID space allocated for DC blocks.

Definition at line 79 of file TractionDefs.hxx.

◆ NODE_ID_DCC

const uint64_t openlcb::TractionDefs::NODE_ID_DCC = 0x060100000000ULL
static

Node ID space allocated for DCC locomotives.

Definition at line 81 of file TractionDefs.hxx.

◆ NODE_ID_MARKLIN_MOTOROLA

const uint64_t openlcb::TractionDefs::NODE_ID_MARKLIN_MOTOROLA = 0x060300000000ULL
static

Node ID space allocated for the Marklin-Motorola protocol.

Definition at line 87 of file TractionDefs.hxx.

◆ NODE_ID_MASK

const uint64_t openlcb::TractionDefs::NODE_ID_MASK = 0xFFFF00000000ULL
static

Node ID space mask.

Definition at line 91 of file TractionDefs.hxx.

◆ NODE_ID_MTH_DCS

const uint64_t openlcb::TractionDefs::NODE_ID_MTH_DCS = 0x060400000000ULL
static

Node ID space allocated for the MTH DCS protocol.

Definition at line 89 of file TractionDefs.hxx.

◆ NODE_ID_TMCC

const uint64_t openlcb::TractionDefs::NODE_ID_TMCC = 0x060200000000ULL
static

Node ID space allocated for TMCC protocol.

Definition at line 85 of file TractionDefs.hxx.


The documentation for this struct was generated from the following files: