Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
dcc/Defs.hxx
Go to the documentation of this file.
1
35#ifndef _DCC_DEFS_HXX_
36#define _DCC_DEFS_HXX_
37
38#include <stdint.h>
39
40namespace dcc
41{
42
45enum class TrainAddressType : uint8_t
46{
52 MM,
61 UNSUPPORTED = 255,
63 UNSPECIFIED = 254,
64};
65
66namespace Defs
67{
68
69enum
70{
71 MARKLIN_DEFAULT_CMD = 0b00100110,
72 // Direction change bits for marklin-old format.
73 MARKLIN_CHANGE_DIR_B2 = 0b11000000,
74
75 DCC_DEFAULT_CMD = 0,
76 DCC_LONG_PREAMBLE_CMD = 0b00001100,
77 DCC_SERVICE_MODE_5X_WITH_ACK_CMD = 0b00111000,
78 // standard dcc packet with 5x repeat.
79 DCC_SERVICE_MODE_5X_CMD = 0b00101000,
80 DCC_SERVICE_MODE_1X_CMD = 0b00001000,
83
84 // Baseline packet: speed and direction.
85 DCC_BASELINE_SPEED = 0b01000000,
86 DCC_BASELINE_SPEED_FORWARD = 0b00100000,
87 DCC_BASELINE_SPEED_LIGHT = 0b00010000,
88 DCC_FUNCTION1 = 0b10000000,
89 DCC_FUNCTION1_F0 = 0b00010000,
90 DCC_FUNCTION2_F5 = 0b10110000,
91 DCC_FUNCTION2_F9 = 0b10100000,
92 DCC_FEATURE_EXP_F13 = 0b11011110,
93 DCC_FEATURE_EXP_F21 = 0b11011111,
94 DCC_FEATURE_EXP_FNHI = 0b11011000,
95 DCC_BINARY_SHORT = 0b11011101,
96 DCC_BINARY_LONG = 0b11000000,
97 DCC_ANALOG_FN = 0b00111101,
98
99 DCC_PROG_READ1 = 0b11100100,
100 DCC_PROG_WRITE1 = 0b11101100,
101 DCC_PROG_READ4 = 0b11100000,
102
103 DCC_SVC_BIT_MANIPULATE = 0b01111000,
104 DCC_SVC_WRITE = 0b01111100,
105 DCC_SVC_VERIFY = 0b01110100,
106 DCC_SVC_MASK = 0b11111100,
107
108 DCC_SVC_BITVAL_WRITE = 0b11110000,
109 DCC_SVC_BITVAL_VERIFY = 0b11100000,
110 DCC_SVC_BITVAL_VALUE = 0b00001000,
111 DCC_SVC_BITVAL_MASK = 0b11110000,
112
113 DCC_SVC_PAGED_WRITE = 0b01111000,
114 DCC_SVC_PAGED_VERIFY = 0b01110000,
115 DCC_SVC_PAGED_MASK = 0b11111000,
116
117 // Byte 1 of dcc accessory control packet
118 DCC_BASIC_ACCESSORY_B1 = 0b10000000,
119 // Mask to check on DCC_BASIC_ACCESSORY_B1
120 DCC_BASIC_ACCESSORY_MASK1 = 0b11000000,
121 // Byte 2 of dcc basic accessory control packet
122 DCC_BASIC_ACCESSORY_B2 = 0b10000000,
123 // Mask for dcc basic accessory control packet
124 DCC_BASIC_ACCESSORY_MASK2 = 0b10000000,
125 // Byte 2 of DCC extended accessory control packet
126 DCC_EXT_ACCESSORY_B2 = 0b00000001,
127 // Mask for DCC_EXT_ACCESSORY_B2
128 DCC_EXT_ACCESSORY_MASK2 = 0b10001001,
129
130 // Basic accy activate command (in byte 2)
131 DCC_BASIC_ACCESSORY_B2_ACTIVATE = 0b00001000,
132 // Basic accy deactivate command (in byte 2)
133 DCC_BASIC_ACCESSORY_B2_DEACTIVATE = 0b00000000,
134 // Mask for activate/deactivate
135 DCC_BASIC_ACCESSORY_B2_ACTIVATE_MASK = DCC_BASIC_ACCESSORY_B2_ACTIVATE,
136 // Basic accy thrown / reverse / red / off command (in byte 2)
137 DCC_BASIC_ACCESSORY_B2_THROWN = 0b00000000,
138 // Basic accy closed / normal / green / on command (in byte 2)
139 DCC_BASIC_ACCESSORY_B2_CLOSED = 0b00000001,
140 // Mask for thrown / closed
141 DCC_BASIC_ACCESSORY_B2_DIR_MASK = DCC_BASIC_ACCESSORY_B2_CLOSED,
142
143 // Extended packet: 128-step speed.
144 DCC_EXT_SPEED = 0b00111111,
145 DCC_EXT_SPEED_FORWARD = 0x80,
146
151
152 // Logon commands
154 DCC_LOGON_ENABLE = 0b11111100,
155 DCC_LOGON_ENABLE_MASK = 0b11111100,
157 DCC_SELECT = 0b11010000,
158 DCC_SELECT_MASK = 0b11110000,
164 DCC_LOGON_ASSIGN = 0b11100000,
165 DCC_LOGON_ASSIGN_MASK = 0b11110000,
166
173
174 // Commands in 254 Select and 253 addressed.
175 CMD_READ_SHORT_INFO = 0b11111111,
176 CMD_READ_BLOCK = 0b11111110,
177 CMD_READ_BACKGROUND = 0b11111101,
178 CMD_WRITE_BLOCK = 0b11111100,
179
180 // Address partitions as defined by S-9.2.1.1. These are 6-bit values for
181 // the first byte of the reported and assigned address.
182
184 ADR_MASK = 0b111111,
185
187 ADR_MOBILE_SHORT = 0b00111000,
193 MAX_MOBILE_LONG = 0b00100111,
195 ADR_ACC_EXT = 0b00101000,
197 MASK_ACC_EXT = 0b00111000,
199 ADR_ACC_BASIC = 0b00110000,
201 MASK_ACC_BASIC = 0b00111000,
202
208};
209
218bool decode_address_partition(uint16_t addr14, uint16_t* addr, uint8_t* partition, dcc::TrainAddressType* atype);
219
229static inline unsigned accy_address_user_to_binary(unsigned user)
230{
231 if (user >= 2045)
232 {
233 return user - 2045;
234 }
235 else
236 {
237 return user + 3;
238 }
239}
240
251static inline unsigned accy_address_binary_to_user(unsigned binary)
252{
253 if (binary < 4)
254 {
255 return binary + 2045;
256 }
257 else
258 {
259 return binary - 3;
260 }
261}
262
265{
267 NOW = 0b11,
269 LOCO = 0b01,
271 ACC = 0b10,
273 ALL = 0b00,
274};
275
276} // namespace dcc::Defs
277
278} // namespace dcc
279
280#endif
bool 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.
Definition dcc/Defs.cxx:42
LogonEnableParam
Parameters for the Logon Enable command.
Definition dcc/Defs.hxx:265
@ NOW
All decoders respond and ignore backoff.
@ LOCO
Locomotive decoders only.
@ ALL
All decoders respond.
@ ACC
Accessory decoders only.
static unsigned accy_address_user_to_binary(unsigned user)
Convers a DCC basic or extended accessory decoder address from user address (1-2048) to binary addres...
Definition dcc/Defs.hxx:229
TrainAddressType
Which address type this legacy train node uses.
Definition dcc/Defs.hxx:46
@ UNSPECIFIED
Unspecified address type (default / match any).
@ UNSUPPORTED
Unsupported address type (e.g.
@ DCC_ACCY_EXT
DCC 11-bit extended accessory decoder address (user facing is 1 to 2048, internal is 0 to 2047).
@ DCC_SHORT_ADDRESS
DCC packets with short address (1..127)
@ DCC_ACCY_BASIC_OUTPUT
Per-output addressing of DCC basic accessories (user facing is 1 to 2048, internal is 0 to 2047)
@ MM
Marklin-motorola packets. Addresses 1..80 are supported.
@ DCC_LONG_ADDRESS
DCC packets with long address (128..~10000)
@ ADR_MASK
Mask for the address partition bits.
Definition dcc/Defs.hxx:184
@ MASK_ACC_BASIC
Mask for 9-bit basic accessory decoder.
Definition dcc/Defs.hxx:201
@ ADR_ACC_EXT
11-bit extended accessory decoder
Definition dcc/Defs.hxx:195
@ ADR_MOBILE_LONG
14-bit mobile decoders
Definition dcc/Defs.hxx:191
@ ADR_INVALID
This value, when given to a decoder, represents an invalid (unassignable) address.
Definition dcc/Defs.hxx:207
@ DCC_GET_DATA_CONT
Get Data Continue command in the 254 address partition.
Definition dcc/Defs.hxx:162
@ MAX_MOBILE_LONG
Maximum value of the first byte for a 14-bit mobile decoder.
Definition dcc/Defs.hxx:193
@ DCC_LOGON_ENABLE
Logon enable in the 254 address partition.
Definition dcc/Defs.hxx:154
@ ADDRESS_LOGON
Address partition used for logon features per S-9.2.1.1 and RCN-218.
Definition dcc/Defs.hxx:148
@ ADR_MOBILE_SHORT
7-bit mobile decoders
Definition dcc/Defs.hxx:187
@ ADR_MOBILE_SHORT_MASK
Mask for 7-bit mobile decoders.
Definition dcc/Defs.hxx:189
@ DCC_DID_MAX
Maximum value of second byte for DID assigned packets.
Definition dcc/Defs.hxx:170
@ DCC_LONG_ADDRESS_FIRST
Prefix for DCC long addresses (first byte).
Definition dcc/Defs.hxx:82
@ ADR_ACC_BASIC
9-bit basic accessory decoder
Definition dcc/Defs.hxx:199
@ DCC_SELECT
Select command in the 254 address partition.
Definition dcc/Defs.hxx:157
@ MASK_ACC_EXT
Mask for 11-bit extended accessory decoder.
Definition dcc/Defs.hxx:197
@ DCC_DID_MASK
Mask used for the DCC_DID packets primary command byte.
Definition dcc/Defs.hxx:172
@ DCC_LOGON_ASSIGN
Logon Assign command the 254 address partition.
Definition dcc/Defs.hxx:164
@ DCC_DID_MIN
Minimum value of second byte for DID assigned packets.
Definition dcc/Defs.hxx:168
@ DCC_GET_DATA_START
Get Data Start command in the 254 address partition.
Definition dcc/Defs.hxx:160
@ ADDRESS_EXT
Address partition used for advanced extended packets per S-9.2.1.1.
Definition dcc/Defs.hxx:150
static unsigned accy_address_binary_to_user(unsigned binary)
Convers a DCC basic or extended accessory decoder address from a binary address (0 - 2047) to user ad...
Definition dcc/Defs.hxx:251