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

State machine for decoding a DCC packet flow. More...

#include <Receiver.hxx>

Classes

struct  Timing
 Represents the timing of a half-wave of the digital track signal. More...
 

Public Types

enum  State : uint8_t {
  UNKNOWN , DCC_PREAMBLE , DCC_END_OF_PREAMBLE , DCC_DATA ,
  DCC_DATA_ONE , DCC_DATA_ZERO , DCC_MAYBE_CUTOUT , DCC_CUTOUT ,
  DCC_PACKET_FINISHED , MM_DATA , MM_ZERO , MM_ONE ,
  MM_PACKET_FINISHED
}
 Internal states of the decoding state machine. More...
 

Public Member Functions

 DccDecoder (unsigned tick_per_usec)
 
State state ()
 
void set_packet (DCCPacket *pkt)
 Sets where to write the decoded DCC data to.
 
DCCPacketpkt ()
 Retrieves the last applied DCC packet pointer.
 
void process_data (uint32_t value)
 Call this function for each time the polarity of the signal changes.
 
bool before_dcc_cutout ()
 Returns true if we are close to the DCC cutout.
 

Private Types

enum  TimingInfo {
  DCC_ONE = 0 , DCC_ZERO , MM_PREAMBLE , MM_SHORT ,
  MM_LONG , MAX_TIMINGS
}
 Indexes the timing array. More...
 

Private Member Functions

void clear_packet ()
 Sets the input DCC packet to empty.
 

Private Attributes

uint8_t parseCount_ = 0
 Counter that works through bit patterns.
 
uint8_t havePacket_: 1
 True if we have storage in the right time for the current packet.
 
uint8_t checkCRC_: 1
 True if we need to check CRC.
 
uint8_t xorState_
 Checksum state for XOR checksum.
 
Crc8DallasMaxim crcState_
 Checksum state for CRC8 checksum.
 
State parseState_ = UNKNOWN
 State machine for parsing.
 
DCCPacketpkt_ = nullptr
 Storage for the current packet.
 
Timing timings_ [MAX_TIMINGS]
 The various timings by the standards.
 

Detailed Description

State machine for decoding a DCC packet flow.

Supports both DCC and Marklin-Motorola packets.

Definition at line 60 of file Receiver.hxx.

Member Enumeration Documentation

◆ State

enum dcc::DccDecoder::State : uint8_t

Internal states of the decoding state machine.

Definition at line 75 of file Receiver.hxx.

◆ TimingInfo

Indexes the timing array.

Definition at line 432 of file Receiver.hxx.

Constructor & Destructor Documentation

◆ DccDecoder()

dcc::DccDecoder::DccDecoder ( unsigned  tick_per_usec)
inline
Parameters
tick_per_usecspecifies how many timer capture ticks happen per usec. The default value assumes the timer does not have a prescaler.

Definition at line 65 of file Receiver.hxx.

Member Function Documentation

◆ before_dcc_cutout()

bool dcc::DccDecoder::before_dcc_cutout ( )
inline

Returns true if we are close to the DCC cutout.

This situation is recognized by having seen the first half of the end-of-packet one bit.

Definition at line 366 of file Receiver.hxx.

◆ clear_packet()

void dcc::DccDecoder::clear_packet ( )
inlineprivate

Sets the input DCC packet to empty.

Definition at line 388 of file Receiver.hxx.

◆ pkt()

DCCPacket * dcc::DccDecoder::pkt ( )
inline

Retrieves the last applied DCC packet pointer.

Returns
DCC packet, or nullptr if there was no DCC packet pointer assigned yet.

Definition at line 114 of file Receiver.hxx.

◆ process_data()

void dcc::DccDecoder::process_data ( uint32_t  value)
inline

Call this function for each time the polarity of the signal changes.

Parameters
valueis the number of clock cycles since the last polarity change.

Definition at line 122 of file Receiver.hxx.

◆ set_packet()

void dcc::DccDecoder::set_packet ( DCCPacket pkt)
inline

Sets where to write the decoded DCC data to.

If this function is not called before a packet preamble starts, the packet will be discarded.

Parameters
pktwhere to store the incoming payload bytes. This packet will be reset to an empty packet.

Definition at line 102 of file Receiver.hxx.

◆ state()

State dcc::DccDecoder::state ( )
inline
Returns
the current decoding state.

Definition at line 93 of file Receiver.hxx.

Member Data Documentation

◆ checkCRC_

uint8_t dcc::DccDecoder::checkCRC_
private

True if we need to check CRC.

Definition at line 377 of file Receiver.hxx.

◆ crcState_

Crc8DallasMaxim dcc::DccDecoder::crcState_
private

Checksum state for CRC8 checksum.

Definition at line 381 of file Receiver.hxx.

◆ havePacket_

uint8_t dcc::DccDecoder::havePacket_
private

True if we have storage in the right time for the current packet.

Definition at line 375 of file Receiver.hxx.

◆ parseCount_

uint8_t dcc::DccDecoder::parseCount_ = 0
private

Counter that works through bit patterns.

Definition at line 373 of file Receiver.hxx.

◆ parseState_

State dcc::DccDecoder::parseState_ = UNKNOWN
private

State machine for parsing.

Definition at line 383 of file Receiver.hxx.

◆ pkt_

DCCPacket* dcc::DccDecoder::pkt_ = nullptr
private

Storage for the current packet.

Definition at line 385 of file Receiver.hxx.

◆ timings_

Timing dcc::DccDecoder::timings_[MAX_TIMINGS]
private

The various timings by the standards.

Definition at line 442 of file Receiver.hxx.

◆ xorState_

uint8_t dcc::DccDecoder::xorState_
private

Checksum state for XOR checksum.

Definition at line 379 of file Receiver.hxx.


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