Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
RailCom.cxx File Reference
#include <string.h>
#include "dcc/RailCom.hxx"
#include "utils/Crc.hxx"

Go to the source code of this file.

Functions

void dcc::parse_internal (uint8_t fb_channel, uint8_t railcom_channel, const uint8_t *ptr, unsigned size, std::vector< struct RailcomPacket > *output)
 Helper function to parse a part of a railcom packet.
 
void dcc::parse_railcom_data (const dcc::Feedback &fb, std::vector< struct RailcomPacket > *output)
 Interprets the data from a railcom feedback.
 

Variables

static constexpr uint8_t dcc::INV = RailcomDefs::INV
 
static constexpr uint8_t dcc::ACK = RailcomDefs::ACK
 
static constexpr uint8_t dcc::NACK = RailcomDefs::NACK
 
static constexpr uint8_t dcc::BUSY = RailcomDefs::BUSY
 
static constexpr uint8_t dcc::RESVD1 = RailcomDefs::RESVD1
 
static constexpr uint8_t dcc::RESVD2 = RailcomDefs::RESVD2
 
const uint8_t dcc::railcom_decode [256]
 Table for 8-to-6 decoding of railcom data.
 
const uint8_t dcc::railcom_encode [64]
 Table for 6-to-8 encoding of railcom data.
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Implementation of RailCom helper functions and tables.

Author
Balazs Racz
Date
12 Nov 2014

Definition in file RailCom.cxx.

Function Documentation

◆ parse_internal()

void dcc::parse_internal ( uint8_t  fb_channel,
uint8_t  railcom_channel,
const uint8_t *  ptr,
unsigned  size,
std::vector< struct RailcomPacket > *  output 
)

Helper function to parse a part of a railcom packet.

Parameters
fb_channelWhich hardware channel did the railcom message arrive at. typically from 0.. num channels - 1: for a command station always 0, for a multi-channel railcom decoder it's as many as the number of ports.
railcom_channel1 or 2 depending on which part of the cutout window the data is from.
ptrraw railcom data read from the UART.
sizehow many bytes were read from the UART
outputwhere to put the decoded packets (or GARBAGE packets if decoding fails).

Definition at line 162 of file RailCom.cxx.

◆ parse_railcom_data()

void dcc::parse_railcom_data ( const dcc::Feedback fb,
std::vector< struct RailcomPacket > *  output 
)

Interprets the data from a railcom feedback.

If the railcom data contains error, will add a packet of type "GARBAGE" into the output list. Clears the output list before fillign with the railcom data.

Definition at line 267 of file RailCom.cxx.

Variable Documentation

◆ ACK

constexpr uint8_t dcc::ACK = RailcomDefs::ACK
staticconstexpr

Definition at line 42 of file RailCom.cxx.

◆ BUSY

constexpr uint8_t dcc::BUSY = RailcomDefs::BUSY
staticconstexpr

Definition at line 44 of file RailCom.cxx.

◆ INV

constexpr uint8_t dcc::INV = RailcomDefs::INV
staticconstexpr

Definition at line 41 of file RailCom.cxx.

◆ NACK

constexpr uint8_t dcc::NACK = RailcomDefs::NACK
staticconstexpr

Definition at line 43 of file RailCom.cxx.

◆ railcom_decode

const uint8_t dcc::railcom_decode

Table for 8-to-6 decoding of railcom data.

This table can be indexed by the 8-bit value read from the railcom channel, and the return value will be either a 6-bit number, or one of the constants in RailcomDefs. If the value is invalid, the INV constant is returned.

Definition at line 47 of file RailCom.cxx.

◆ railcom_encode

const uint8_t dcc::railcom_encode

Table for 6-to-8 encoding of railcom data.

The table can be indexed by a 6-bit value that is the semantic content of a railcom byte, and returns the matching 8-bit value to put out on the UART. This table only contains the standard codes, for the special codes like ACK use RailcomDefs::ACK.

Definition at line 83 of file RailCom.cxx.

◆ RESVD1

constexpr uint8_t dcc::RESVD1 = RailcomDefs::RESVD1
staticconstexpr

Definition at line 45 of file RailCom.cxx.

◆ RESVD2

constexpr uint8_t dcc::RESVD2 = RailcomDefs::RESVD2
staticconstexpr

Definition at line 46 of file RailCom.cxx.