Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
dcc/Defs.cxx
Go to the documentation of this file.
1
35#include "dcc/Defs.hxx"
36
37namespace dcc
38{
39namespace Defs
40{
41
42bool decode_address_partition(uint16_t addr14, uint16_t *addr,
43 uint8_t *partition, dcc::TrainAddressType *atype)
44{
45 TrainAddressType _atype = TrainAddressType::UNSUPPORTED;
46 uint8_t _partition = 0xff;
47 uint16_t _addr = 0xffffu;
48
49 addr14 &= (1u << 14) - 1;
50 uint8_t hibyte = addr14 >> 8;
51 if (hibyte <= MAX_MOBILE_LONG)
52 {
53 _atype = TrainAddressType::DCC_LONG_ADDRESS;
54 _partition = 0;
55 _addr = addr14;
56 }
57 else if ((hibyte & MASK_ACC_EXT) == ADR_ACC_EXT)
58 {
59 _atype = TrainAddressType::DCC_ACCY_EXT;
60 _partition = ADR_ACC_EXT;
61 _addr = addr14 & ~(MASK_ACC_EXT << 8);
62 }
63 else if ((hibyte & MASK_ACC_BASIC) == ADR_ACC_BASIC)
64 {
65 _atype = TrainAddressType::DCC_ACCY_BASIC_OUTPUT;
66 _partition = ADR_ACC_BASIC;
67 _addr = addr14 & ~(MASK_ACC_BASIC << 8);
68 }
69 else if (hibyte == ADR_MOBILE_SHORT)
70 {
71 _atype = TrainAddressType::DCC_SHORT_ADDRESS;
72 _partition = hibyte;
73 _addr = addr14 & 0x7f;
74 }
75 else
76 {
77 return false;
78 }
79
80 if (addr)
81 {
82 *addr = _addr;
83 }
84 if (partition)
85 {
86 *partition = _partition;
87 }
88 if (atype)
89 {
90 *atype = _atype;
91 }
92 return true;
93}
94
95} // namespace dcc::Defs
96
97} // namespace dcc
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
TrainAddressType
Which address type this legacy train node uses.
Definition dcc/Defs.hxx:46
@ 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
@ MAX_MOBILE_LONG
Maximum value of the first byte for a 14-bit mobile decoder.
Definition dcc/Defs.hxx:193
@ ADR_MOBILE_SHORT
7-bit mobile decoders
Definition dcc/Defs.hxx:187
@ ADR_ACC_BASIC
9-bit basic accessory decoder
Definition dcc/Defs.hxx:199
@ MASK_ACC_EXT
Mask for 11-bit extended accessory decoder.
Definition dcc/Defs.hxx:197