Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
RailCom.hxx
Go to the documentation of this file.
1
35#ifndef _DCC_RAILCOM_HXX_
36#define _DCC_RAILCOM_HXX_
37
38#include <cstdint>
39#include <string>
40#include <vector>
41
42#include "dcc/railcom.h"
43
44namespace dcc
45{
46
49struct Feedback : public DCCFeedback
50{
52 void reset(uint32_t feedback_key)
53 {
54 this->feedbackKey = feedback_key;
55 ch1Size = 0;
56 ch2Size = 0;
57 channel = 0;
58 }
59
61 void add_ch1_data(uint8_t data)
62 {
63 if (ch1Size < sizeof(ch1Data))
64 {
65 ch1Data[ch1Size++] = data;
66 }
67 }
68
70 void add_ch2_data(uint8_t data)
71 {
72 if (ch2Size < sizeof(ch2Data))
73 {
74 ch2Data[ch2Size++] = data;
75 }
76 }
77};
78
80std::string railcom_debug(const Feedback& fb);
81
86extern const uint8_t railcom_decode[256];
91extern const uint8_t railcom_encode[64];
92
95{
96 // These values appear in the railcom_decode table to mean special symbols.
97 enum
98 {
100 INV = 0xff,
103 ACK = 0xfe,
105 NACK = 0xfd,
109 BUSY = 0xfc,
110
112 RESVD1 = 0xfb,
114 RESVD2 = 0xfa,
115 };
116
117 // These values need to be sent on the UART
118 enum
119 {
121 CODE_ACK = 0xf0,
123 CODE_ACK2 = 0x0f,
125 CODE_NACK = 0x3c,
127 CODE_BUSY = 0xE1,
128 };
129
135 static uint16_t encode12(uint8_t nibble, uint8_t data)
136 {
137 return (railcom_encode[((nibble << 2) | (data >> 6)) & 0x3F] << 8) |
138 railcom_encode[data & 0x3f];
139 }
140
145 static void append12(uint8_t nibble, uint8_t data, uint8_t* dst)
146 {
147 *dst++ = railcom_encode[((nibble << 2) | (data >> 6)) & 0x3F];
148 *dst++ = railcom_encode[data & 0x3f];
149 }
150
155 static void append36(uint8_t nibble, uint32_t data, uint8_t* dst)
156 {
157 *dst++ = railcom_encode[((nibble << 2) | (data >> 30)) & 0x3F];
158 *dst++ = railcom_encode[(data >> 24) & 0x3F];
159 *dst++ = railcom_encode[(data >> 18) & 0x3F];
160 *dst++ = railcom_encode[(data >> 12) & 0x3F];
161 *dst++ = railcom_encode[(data >> 6) & 0x3F];
162 *dst++ = railcom_encode[data & 0x3F];
163 }
164
168 static void add_did_feedback(uint64_t decoder_id, Feedback *fb);
169
176 static void add_shortinfo_feedback(uint16_t requested_address,
177 uint8_t max_fn, uint8_t psupp, uint8_t ssupp, Feedback *fb);
178
185 static void add_assign_feedback(uint8_t changeflags, uint16_t changecount,
186 uint8_t supp2, uint8_t supp3, Feedback *fb);
187
188private:
191};
192
193
196{
197 RMOB_POM = 0,
198 RMOB_ADRHIGH = 1,
199 RMOB_ADRLOW = 2,
200 RMOB_EXT = 3,
201 RMOB_DYN = 7,
202 RMOB_XPOM0 = 8,
203 RMOB_XPOM1 = 9,
204 RMOB_XPOM2 = 10,
205 RMOB_XPOM3 = 11,
206 RMOB_SUBID = 12,
207 RMOB_LOGON_ASSIGN_FEEDBACK = 13,
208 RMOB_LOGON_ENABLE_FEEDBACK = 15,
209};
210
215{
216 enum
217 {
218 GARBAGE,
219 ACK,
220 NACK,
221 BUSY,
222 MOB_POM,
223 MOB_ADRHIGH,
224 MOB_ADRLOW,
225 MOB_EXT,
226 MOB_DYN,
227 MOB_XPOM0,
228 MOB_XPOM1,
229 MOB_XPOM2,
230 MOB_XPOM3,
231 MOB_SUBID
232 };
234 uint8_t hw_channel;
238 uint8_t type;
240 uint32_t argument;
247 RailcomPacket(uint8_t _hw_channel, uint8_t _railcom_channel, uint8_t _type,
248 uint32_t _argument)
249 : hw_channel(_hw_channel)
250 , railcom_channel(_railcom_channel)
251 , type(_type)
252 , argument(_argument)
253 {
254 }
255};
256
260void parse_railcom_data(
261 const dcc::Feedback &fb, std::vector<struct RailcomPacket> *output);
262
263} // namespace dcc
264
265#endif // _DCC_RAILCOM_HXX_
const uint8_t railcom_encode[64]
Table for 6-to-8 encoding of railcom data.
Definition RailCom.cxx:83
RailcomMobilePacketId
Packet identifiers from Mobile Decoders.
Definition RailCom.hxx:196
uint8_t ch2Size
Number of bytes in channel two.
Definition railcom.h:49
uint8_t ch1Size
Number of bytes in channel one.
Definition railcom.h:45
uint8_t channel
Used by multi-channel railcom receiver drivers.
Definition railcom.h:54
uint8_t ch1Data[2]
Payload of channel 1.
Definition railcom.h:47
uintptr_t feedbackKey
Opaque identifier that allows linking outgoing dcc::Packet sent to the DCC waveform generator to the ...
Definition railcom.h:58
uint8_t ch2Data[6]
Payload of channel 2.
Definition railcom.h:51
Structure used for reading (railcom) feedback data from DCC / Railcom device drivers.
Definition RailCom.hxx:50
void reset(uint32_t feedback_key)
Clears the structure and sets the feedback key to a specific value.
Definition RailCom.hxx:52
void add_ch1_data(uint8_t data)
Appends a byte to the channel 1 payload.
Definition RailCom.hxx:61
void add_ch2_data(uint8_t data)
Appends a byte to the channel 2 payload.
Definition RailCom.hxx:70
Special constant values returned by the railcom_decode[] array.
Definition RailCom.hxx:95
static void add_shortinfo_feedback(uint16_t requested_address, uint8_t max_fn, uint8_t psupp, uint8_t ssupp, Feedback *fb)
Creates a ShortInfo feedback.
Definition RailCom.cxx:315
@ CODE_NACK
Code point for NACK (according to RCN-217)
Definition RailCom.hxx:125
@ CODE_ACK
Code point for ACK (according to RCN-217)
Definition RailCom.hxx:121
@ CODE_ACK2
Another accepted code point for ACK (according to RCN-217)
Definition RailCom.hxx:123
@ CODE_BUSY
Code point for BUSY (according to NMRA S-9.3.2)
Definition RailCom.hxx:127
static void add_did_feedback(uint64_t decoder_id, Feedback *fb)
Creates a Logon Enable feedback with the decoder unique ID.
Definition RailCom.cxx:305
@ ACK
Railcom ACK; the decoder received the message ok.
Definition RailCom.hxx:103
@ INV
invalid value (not conforming to the 4bit weighting requirement)
Definition RailCom.hxx:100
@ RESVD2
Reserved for future expansion.
Definition RailCom.hxx:114
@ RESVD1
Reserved for future expansion.
Definition RailCom.hxx:112
@ BUSY
The decoder is busy; send the packet again.
Definition RailCom.hxx:109
@ NACK
The decoder rejected the packet.
Definition RailCom.hxx:105
static uint16_t encode12(uint8_t nibble, uint8_t data)
Encodes 12 bits of useful payload into 16 bits of UART data to transmit.
Definition RailCom.hxx:135
static void append12(uint8_t nibble, uint8_t data, uint8_t *dst)
Encodes 12 bits of useful payload into 16 bits of UART data to transmit.
Definition RailCom.hxx:145
static void append36(uint8_t nibble, uint32_t data, uint8_t *dst)
Encodes a 36-bit railcom datagram into UART bytes.
Definition RailCom.hxx:155
RailcomDefs()
This struct cannot be instantiated.
static void add_assign_feedback(uint8_t changeflags, uint16_t changecount, uint8_t supp2, uint8_t supp3, Feedback *fb)
Creates a Logon Assign feedback.
Definition RailCom.cxx:336
Represents a single Railcom datagram.
Definition RailCom.hxx:215
uint8_t type
packet type, see enum above
Definition RailCom.hxx:238
uint8_t hw_channel
which detector supplied this data
Definition RailCom.hxx:234
uint8_t railcom_channel
which part of the railcom cutout (1 or 2)
Definition RailCom.hxx:236
uint32_t argument
payload of the railcom packet, justified to LSB.
Definition RailCom.hxx:240
RailcomPacket(uint8_t _hw_channel, uint8_t _railcom_channel, uint8_t _type, uint32_t _argument)
Constructor.
Definition RailCom.hxx:247