Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
dcc::RailcomBroadcastDecoder Class Reference

Simple state machine to decode DCC address from railcom broadcast packets. More...

#include <RailcomBroadcastDecoder.hxx>

Public Member Functions

uint16_t current_address ()
 
bool process_packet (const dcc::Feedback &packet)
 Decodes a packet.
 
void set_occupancy (bool value)
 Notifies the state machine about observed occupancy.
 

Public Attributes

uint16_t lastAddress_
 usable by clients for storage.
 

Private Member Functions

bool process_data (const uint8_t *data, unsigned size)
 Helper function to process a sequence of bytes (whichever window they are coming from).
 
void notify_empty ()
 Notifies the state machine that there is no occupancy detected.
 

Private Attributes

uint8_t currentH_
 last received high address bits
 
uint8_t currentL_
 last received low address bits
 
uint8_t countH_
 observed repeat count of high address bits
 
uint8_t countL_
 observed repeat count of low address bits
 
uint16_t currentAddress_
 last valid address (0 if no valid address)
 

Static Private Attributes

static const uint8_t MIN_REPEAT_COUNT = 3
 How many times we shall get the same data out of railcom before we believe it and report to the bus.
 
static const uint8_t MIN_EMPTY_COUNT = 8
 This is how many empty packets we need to forget the current address when we're getting empty packets.
 

Detailed Description

Simple state machine to decode DCC address from railcom broadcast packets.

Usage:

For each incoming Railcom packet call the process_packet() function. call the current_address() function to retrieve the currently known address that came with the global broadcast.

Definition at line 51 of file RailcomBroadcastDecoder.hxx.

Constructor & Destructor Documentation

◆ RailcomBroadcastDecoder()

dcc::RailcomBroadcastDecoder::RailcomBroadcastDecoder ( )
inline

Definition at line 54 of file RailcomBroadcastDecoder.hxx.

Member Function Documentation

◆ current_address()

uint16_t dcc::RailcomBroadcastDecoder::current_address ( )
inline
Returns
the currently valid DCC address, or zero if no valid address right now.

Definition at line 66 of file RailcomBroadcastDecoder.hxx.

◆ notify_empty()

void dcc::RailcomBroadcastDecoder::notify_empty ( )
private

Notifies the state machine that there is no occupancy detected.

Definition at line 143 of file RailcomBroadcastDecoder.cxx.

◆ process_data()

bool dcc::RailcomBroadcastDecoder::process_data ( const uint8_t *  data,
unsigned  size 
)
private

Helper function to process a sequence of bytes (whichever window they are coming from).

Parameters
datapointer to bytes
sizehow many bytes arethere to decode.
Returns
dunno.

TODO(balazs.racz) if we have only one byte in ch1 but we have a second byte in ch2, we should still process those because it might be a misaligned window.

Definition at line 66 of file RailcomBroadcastDecoder.cxx.

◆ process_packet()

bool dcc::RailcomBroadcastDecoder::process_packet ( const dcc::Feedback packet)

Decodes a packet.

Parameters
packetis what to decode.
Returns
true if the packet is garbage or matches a global address broadcast, false if it is a valid packet that is not an address broadcast.
true if the packet is garbage or matches a global address broadcast, false if it is a valid packet that is not an address broadcast.

Definition at line 47 of file RailcomBroadcastDecoder.cxx.

◆ set_occupancy()

void dcc::RailcomBroadcastDecoder::set_occupancy ( bool  value)

Notifies the state machine about observed occupancy.

Parameters
valueis true if the track is sensed as occupied.

Definition at line 134 of file RailcomBroadcastDecoder.cxx.

Member Data Documentation

◆ countH_

uint8_t dcc::RailcomBroadcastDecoder::countH_
private

observed repeat count of high address bits

Definition at line 101 of file RailcomBroadcastDecoder.hxx.

◆ countL_

uint8_t dcc::RailcomBroadcastDecoder::countL_
private

observed repeat count of low address bits

Definition at line 102 of file RailcomBroadcastDecoder.hxx.

◆ currentAddress_

uint16_t dcc::RailcomBroadcastDecoder::currentAddress_
private

last valid address (0 if no valid address)

Definition at line 104 of file RailcomBroadcastDecoder.hxx.

◆ currentH_

uint8_t dcc::RailcomBroadcastDecoder::currentH_
private

last received high address bits

Definition at line 99 of file RailcomBroadcastDecoder.hxx.

◆ currentL_

uint8_t dcc::RailcomBroadcastDecoder::currentL_
private

last received low address bits

Definition at line 100 of file RailcomBroadcastDecoder.hxx.

◆ lastAddress_

uint16_t dcc::RailcomBroadcastDecoder::lastAddress_

usable by clients for storage.

Definition at line 108 of file RailcomBroadcastDecoder.hxx.

◆ MIN_EMPTY_COUNT

const uint8_t dcc::RailcomBroadcastDecoder::MIN_EMPTY_COUNT = 8
staticprivate

This is how many empty packets we need to forget the current address when we're getting empty packets.

Definition at line 97 of file RailcomBroadcastDecoder.hxx.

◆ MIN_REPEAT_COUNT

const uint8_t dcc::RailcomBroadcastDecoder::MIN_REPEAT_COUNT = 3
staticprivate

How many times we shall get the same data out of railcom before we believe it and report to the bus.

Definition at line 94 of file RailcomBroadcastDecoder.hxx.


The documentation for this class was generated from the following files: