Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
RailcomBroadcastDecoder.hxx
Go to the documentation of this file.
1
35#include <stdint.h>
36
37#ifndef _DCC_RAILCOMBROADCASTDECODER_HXX_
38#define _DCC_RAILCOMBROADCASTDECODER_HXX_
39
40namespace dcc
41{
42
43struct Feedback;
44
52{
53public:
55 : currentH_(0)
56 , currentL_(0)
57 , countH_(0)
58 , countL_(0)
60 , lastAddress_(0)
61 {
62 }
63
66 uint16_t current_address()
67 {
68 return currentAddress_;
69 }
70
76 bool process_packet(const dcc::Feedback &packet);
77
81 void set_occupancy(bool value);
82
83private:
87 bool process_data(const uint8_t *data, unsigned size);
88
90 void notify_empty();
91
94 static const uint8_t MIN_REPEAT_COUNT = 3;
97 static const uint8_t MIN_EMPTY_COUNT = 8;
98
99 uint8_t currentH_;
100 uint8_t currentL_;
101 uint8_t countH_;
102 uint8_t countL_;
103
105
106public:
108 uint16_t lastAddress_;
109};
110
111} // namespace dcc
112
113#endif // _DCC_RAILCOMBROADCASTDECODER_HXX_
Simple state machine to decode DCC address from railcom broadcast packets.
static const uint8_t MIN_EMPTY_COUNT
This is how many empty packets we need to forget the current address when we're getting empty packets...
uint16_t currentAddress_
last valid address (0 if no valid address)
bool process_data(const uint8_t *data, unsigned size)
Helper function to process a sequence of bytes (whichever window they are coming from).
bool process_packet(const dcc::Feedback &packet)
Decodes a packet.
void set_occupancy(bool value)
Notifies the state machine about observed occupancy.
uint16_t lastAddress_
usable by clients for storage.
uint8_t countH_
observed repeat count of high address bits
uint8_t currentL_
last received low address bits
static const uint8_t MIN_REPEAT_COUNT
How many times we shall get the same data out of railcom before we believe it and report to the bus.
uint8_t countL_
observed repeat count of low address bits
void notify_empty()
Notifies the state machine that there is no occupancy detected.
uint8_t currentH_
last received high address bits
Structure used for reading (railcom) feedback data from DCC / Railcom device drivers.
Definition RailCom.hxx:50