Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Defs.hxx File Reference
#include <stdint.h>

Go to the source code of this file.

Enumerations

enum class  dcc::TrainAddressType : uint8_t {
  DCC_SHORT_ADDRESS = 1 , DCC_LONG_ADDRESS , MM , DCC_ACCY_BASIC_OUTPUT ,
  DCC_ACCY_EXT , UNSUPPORTED = 255 , UNSPECIFIED = 254
}
 Which address type this legacy train node uses. More...
 
enum  {
  MARKLIN_DEFAULT_CMD = 0b00100110 , MARKLIN_CHANGE_DIR_B2 = 0b11000000 , DCC_DEFAULT_CMD = 0 , DCC_LONG_PREAMBLE_CMD = 0b00001100 ,
  DCC_SERVICE_MODE_5X_WITH_ACK_CMD = 0b00111000 , DCC_SERVICE_MODE_5X_CMD = 0b00101000 , DCC_SERVICE_MODE_1X_CMD = 0b00001000 , dcc::Defs::DCC_LONG_ADDRESS_FIRST = 0b11000000 ,
  DCC_BASELINE_SPEED = 0b01000000 , DCC_BASELINE_SPEED_FORWARD = 0b00100000 , DCC_BASELINE_SPEED_LIGHT = 0b00010000 , DCC_FUNCTION1 = 0b10000000 ,
  DCC_FUNCTION1_F0 = 0b00010000 , DCC_FUNCTION2_F5 = 0b10110000 , DCC_FUNCTION2_F9 = 0b10100000 , DCC_FEATURE_EXP_F13 = 0b11011110 ,
  DCC_FEATURE_EXP_F21 = 0b11011111 , DCC_FEATURE_EXP_FNHI = 0b11011000 , DCC_BINARY_SHORT = 0b11011101 , DCC_BINARY_LONG = 0b11000000 ,
  DCC_ANALOG_FN = 0b00111101 , DCC_PROG_READ1 = 0b11100100 , DCC_PROG_WRITE1 = 0b11101100 , DCC_PROG_READ4 = 0b11100000 ,
  DCC_SVC_BIT_MANIPULATE = 0b01111000 , DCC_SVC_WRITE = 0b01111100 , DCC_SVC_VERIFY = 0b01110100 , DCC_SVC_MASK = 0b11111100 ,
  DCC_SVC_BITVAL_WRITE = 0b11110000 , DCC_SVC_BITVAL_VERIFY = 0b11100000 , DCC_SVC_BITVAL_VALUE = 0b00001000 , DCC_SVC_BITVAL_MASK = 0b11110000 ,
  DCC_SVC_PAGED_WRITE = 0b01111000 , DCC_SVC_PAGED_VERIFY = 0b01110000 , DCC_SVC_PAGED_MASK = 0b11111000 , DCC_BASIC_ACCESSORY_B1 = 0b10000000 ,
  DCC_BASIC_ACCESSORY_MASK1 = 0b11000000 , DCC_BASIC_ACCESSORY_B2 = 0b10000000 , DCC_BASIC_ACCESSORY_MASK2 = 0b10000000 , DCC_EXT_ACCESSORY_B2 = 0b00000001 ,
  DCC_EXT_ACCESSORY_MASK2 = 0b10001001 , DCC_BASIC_ACCESSORY_B2_ACTIVATE = 0b00001000 , DCC_BASIC_ACCESSORY_B2_DEACTIVATE = 0b00000000 , DCC_BASIC_ACCESSORY_B2_ACTIVATE_MASK = DCC_BASIC_ACCESSORY_B2_ACTIVATE ,
  DCC_BASIC_ACCESSORY_B2_THROWN = 0b00000000 , DCC_BASIC_ACCESSORY_B2_CLOSED = 0b00000001 , DCC_BASIC_ACCESSORY_B2_DIR_MASK = DCC_BASIC_ACCESSORY_B2_CLOSED , DCC_EXT_SPEED = 0b00111111 ,
  DCC_EXT_SPEED_FORWARD = 0x80 , dcc::Defs::ADDRESS_LOGON = 254 , dcc::Defs::ADDRESS_EXT = 253 , dcc::Defs::DCC_LOGON_ENABLE = 0b11111100 ,
  DCC_LOGON_ENABLE_MASK = 0b11111100 , dcc::Defs::DCC_SELECT = 0b11010000 , DCC_SELECT_MASK = 0b11110000 , dcc::Defs::DCC_GET_DATA_START = 0 ,
  dcc::Defs::DCC_GET_DATA_CONT = 1 , dcc::Defs::DCC_LOGON_ASSIGN = 0b11100000 , DCC_LOGON_ASSIGN_MASK = 0b11110000 , dcc::Defs::DCC_DID_MIN = DCC_SELECT ,
  dcc::Defs::DCC_DID_MAX = DCC_LOGON_ASSIGN + 0xF , dcc::Defs::DCC_DID_MASK = 0xF0 , CMD_READ_SHORT_INFO = 0b11111111 , CMD_READ_BLOCK = 0b11111110 ,
  CMD_READ_BACKGROUND = 0b11111101 , CMD_WRITE_BLOCK = 0b11111100 , dcc::Defs::ADR_MASK = 0b111111 , dcc::Defs::ADR_MOBILE_SHORT = 0b00111000 ,
  dcc::Defs::ADR_MOBILE_SHORT_MASK = 0xFF , dcc::Defs::ADR_MOBILE_LONG = 0 , dcc::Defs::MAX_MOBILE_LONG = 0b00100111 , dcc::Defs::ADR_ACC_EXT = 0b00101000 ,
  dcc::Defs::MASK_ACC_EXT = 0b00111000 , dcc::Defs::ADR_ACC_BASIC = 0b00110000 , dcc::Defs::MASK_ACC_BASIC = 0b00111000 , dcc::Defs::ADR_INVALID = (ADR_MOBILE_SHORT << 8)
}
 
enum class  dcc::Defs::LogonEnableParam { NOW = 0b11 , LOCO = 0b01 , ACC = 0b10 , ALL = 0b00 }
 Parameters for the Logon Enable command. More...
 

Functions

bool dcc::Defs::decode_address_partition (uint16_t addr14, uint16_t *addr, uint8_t *partition, dcc::TrainAddressType *atype)
 Decodes a 14-bit address (according to S-9.2.1.1) into an address type and a raw address.
 
static unsigned dcc::Defs::accy_address_user_to_binary (unsigned user)
 Convers a DCC basic or extended accessory decoder address from user address (1-2048) to binary address (0..2047).
 
static unsigned dcc::Defs::accy_address_binary_to_user (unsigned binary)
 Convers a DCC basic or extended accessory decoder address from a binary address (0 - 2047) to user address (1 - 2048).
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definitions for DCC concepts.

Author
Balazs Racz
Date
27 Feb 2016

Definition in file dcc/Defs.hxx.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DCC_LONG_ADDRESS_FIRST 

Prefix for DCC long addresses (first byte).

ADDRESS_LOGON 

Address partition used for logon features per S-9.2.1.1 and RCN-218.

ADDRESS_EXT 

Address partition used for advanced extended packets per S-9.2.1.1.

DCC_LOGON_ENABLE 

Logon enable in the 254 address partition.

DCC_SELECT 

Select command in the 254 address partition.

DCC_GET_DATA_START 

Get Data Start command in the 254 address partition.

DCC_GET_DATA_CONT 

Get Data Continue command in the 254 address partition.

DCC_LOGON_ASSIGN 

Logon Assign command the 254 address partition.

DCC_DID_MIN 

Minimum value of second byte for DID assigned packets.

DCC_DID_MAX 

Maximum value of second byte for DID assigned packets.

DCC_DID_MASK 

Mask used for the DCC_DID packets primary command byte.

ADR_MASK 

Mask for the address partition bits.

ADR_MOBILE_SHORT 

7-bit mobile decoders

ADR_MOBILE_SHORT_MASK 

Mask for 7-bit mobile decoders.

ADR_MOBILE_LONG 

14-bit mobile decoders

MAX_MOBILE_LONG 

Maximum value of the first byte for a 14-bit mobile decoder.

ADR_ACC_EXT 

11-bit extended accessory decoder

MASK_ACC_EXT 

Mask for 11-bit extended accessory decoder.

ADR_ACC_BASIC 

9-bit basic accessory decoder

MASK_ACC_BASIC 

Mask for 9-bit basic accessory decoder.

ADR_INVALID 

This value, when given to a decoder, represents an invalid (unassignable) address.

This is a 2-byte value that can go to the wire – above we only have the constants for address partitions, which is the first byte.

Definition at line 69 of file dcc/Defs.hxx.

◆ LogonEnableParam

enum class dcc::Defs::LogonEnableParam
strong

Parameters for the Logon Enable command.

Enumerator
NOW 

All decoders respond and ignore backoff.

LOCO 

Locomotive decoders only.

ACC 

Accessory decoders only.

ALL 

All decoders respond.

Definition at line 264 of file dcc/Defs.hxx.

◆ TrainAddressType

enum class dcc::TrainAddressType : uint8_t
strong

Which address type this legacy train node uses.

These address types translate to mutually independent packets on the track.

Enumerator
DCC_SHORT_ADDRESS 

DCC packets with short address (1..127)

DCC_LONG_ADDRESS 

DCC packets with long address (128..~10000)

MM 

Marklin-motorola packets. Addresses 1..80 are supported.

DCC_ACCY_BASIC_OUTPUT 

Per-output addressing of DCC basic accessories (user facing is 1 to 2048, internal is 0 to 2047)

DCC_ACCY_EXT 

DCC 11-bit extended accessory decoder address (user facing is 1 to 2048, internal is 0 to 2047).

UNSUPPORTED 

Unsupported address type (e.g.

a protocol we don't have an implementation for).

UNSPECIFIED 

Unspecified address type (default / match any).

Definition at line 45 of file dcc/Defs.hxx.

Function Documentation

◆ accy_address_binary_to_user()

static unsigned dcc::Defs::accy_address_binary_to_user ( unsigned  binary)
inlinestatic

Convers a DCC basic or extended accessory decoder address from a binary address (0 - 2047) to user address (1 - 2048).

This takes into account the 2023 draft of the DCC standard for address mapping. It uses per-output addressing for basic accessory decoders. It uses 2044 user address for the binary address that previously was the broadcast for basic accessory decoders.

Parameters
binarythe address in the DCC packet. The one's complement for the highest bits should be undone already.
Returns
user user address for accy decoders. 1..2040 uses the legacy addressing. 2041 .. 2048 uses the 2023 RCN-213 and DCC S-9.2.1 encoding.

Definition at line 251 of file dcc/Defs.hxx.

◆ accy_address_user_to_binary()

static unsigned dcc::Defs::accy_address_user_to_binary ( unsigned  user)
inlinestatic

Convers a DCC basic or extended accessory decoder address from user address (1-2048) to binary address (0..2047).

This takes into account the 2023 draft of the DCC standard for address mapping. It uses per-output addressing for basic accessory decoders. It uses 2044 for the address that previously was the broadcast address for basic accessory decoders.

Parameters
useruser address for accy decoders. 1..2040 uses the legacy addressing. 2041 .. 2048 uses the 2023 RCN-213 and DCC S-9.2.1 encoding.
Returns
binary address to be used in the DCC packet. The one's complement of the highest address bits is not yet applied.

Definition at line 229 of file dcc/Defs.hxx.

◆ decode_address_partition()

bool dcc::Defs::decode_address_partition ( uint16_t  addr14,
uint16_t *  addr,
uint8_t *  partition,
dcc::TrainAddressType atype 
)

Decodes a 14-bit address (according to S-9.2.1.1) into an address type and a raw address.

Parameters
addr14a 14-bit address according to S-9.2.1.1
addrthe decoded address value (8 to 14 bits)
partitionthe partition of the address type (the top byte, max 6 bits, e.g. ADR_MOBILE_SHORT)
atypeaddress type enum
Returns
true if the decoding is successful, false if the value is not representable.

Definition at line 42 of file dcc/Defs.cxx.