35#ifndef _DCC_RECEIVER_HXX_
36#define _DCC_RECEIVER_HXX_
67 timings_[DCC_ONE].set(tick_per_usec, 52, 64);
68 timings_[DCC_ZERO].set(tick_per_usec, 95, 9900);
69 timings_[MM_PREAMBLE].set(tick_per_usec, 1000, -1);
70 timings_[MM_SHORT].set(tick_per_usec, 20, 32);
71 timings_[MM_LONG].set(tick_per_usec, 200, 216);
124#ifdef DCC_DECODER_DEBUG
125 debugLog_.add(value);
130 case DCC_PACKET_FINISHED:
131 case MM_PACKET_FINISHED:
164 case DCC_END_OF_PREAMBLE:
166 if (
timings_[DCC_ZERO].match(value))
193 if (
timings_[DCC_ZERO].match(value))
240 if (
timings_[DCC_ZERO].match(value))
280 case DCC_MAYBE_CUTOUT:
282 if (value <
timings_[DCC_ZERO].min_value)
302 if (
timings_[MM_SHORT].match(value))
311 if (
timings_[MM_SHORT].match(value))
390 pkt_->header_raw_data = 0;
402 void set(uint32_t tick_per_usec,
int min_usec,
int max_usec)
410 min_value = tick_per_usec * min_usec;
418 max_value = tick_per_usec * max_usec;
422 bool match(uint32_t value_clocks)
const
424 return min_value <= value_clocks && value_clocks <= max_value;
443#ifdef DCC_DECODER_DEBUG
462 fd_ = ::open(dev, O_RDONLY | O_NONBLOCK);
468 Action register_and_sleep()
479 int ret = ::read(fd_, &value,
sizeof(value));
495 static uint8_t x = 0;
501 virtual void dcc_packet_finished(
const uint8_t* payload,
size_t len) = 0;
502 virtual void mm_packet_finished(
const uint8_t* payload,
size_t len) = 0;
503 virtual void debug_data(uint32_t value)
508 uint32_t lastValue_ = 0;
int ioctl(int fd, unsigned long int key,...)
Request and ioctl transaction.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Helper class for computing CRC-8 according to Dallas/Maxim specification for 1-wire protocol.
bool check_ok()
Checks that the message has a correct CRC.
void update16(uint8_t message_byte)
Processes one byte of the incoming message.
void init()
Re-sets the state machine for checksumming a new message.
Alternative for hundreds of entries.
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
Base class for state machines.
StateFlowBase()
Default constructor.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
User-space DCC decoding flow.
DCCPacket pkt_
Packet buffer.
DccDecoder decoder_
State machine that does the DCC decoding.
State machine for decoding a DCC packet flow.
void clear_packet()
Sets the input DCC packet to empty.
DCCPacket * pkt_
Storage for the current packet.
uint8_t checkCRC_
True if we need to check CRC.
Timing timings_[MAX_TIMINGS]
The various timings by the standards.
State parseState_
State machine for parsing.
void set_packet(DCCPacket *pkt)
Sets where to write the decoded DCC data to.
DccDecoder(unsigned tick_per_usec)
Crc8DallasMaxim crcState_
Checksum state for CRC8 checksum.
DCCPacket * pkt()
Retrieves the last applied DCC packet pointer.
TimingInfo
Indexes the timing array.
uint8_t xorState_
Checksum state for XOR checksum.
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.
State
Internal states of the decoding state machine.
uint8_t havePacket_
True if we have storage in the right time for the current packet.
uint8_t parseCount_
Counter that works through bit patterns.
#define CAN_IOC_READ_ACTIVE
read active ioctl.
#define DCC_PACKET_MAX_PAYLOAD
Maximum number of payload bytes.
uint8_t skip_ec
typically for DCC packets: 1: do NOT append an EC byte to the end of the packet.
uint8_t is_marklin
0: DCC packet, 1: motorola packet.
uint8_t csum_error
1 if there was a checksum error in this packet.
Stores a DCC packet in memory.
uintptr_t feedback_key
An opaque key used by the hardware driver to attribute feedback information to the source of the pack...
uint8_t payload[DCC_PACKET_MAX_PAYLOAD]
Packet payload bytes.
uint8_t dlc
Specifies the number of used payload bytes.
Represents the timing of a half-wave of the digital track signal.