Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Crc8DallasMaxim Class Reference

Helper class for computing CRC-8 according to Dallas/Maxim specification for 1-wire protocol. More...

#include <Crc.hxx>

Public Member Functions

void init ()
 Re-sets the state machine for checksumming a new message.
 
uint8_t get ()
 
bool check_ok ()
 Checks that the message has a correct CRC.
 
bool check_ok (uint8_t checksum_byte)
 Checks that the message has a correct CRC.
 
void update0 (uint8_t message_byte)
 Processes one byte of the incoming message.
 
void update16 (uint8_t message_byte)
 Processes one byte of the incoming message.
 
void update256 (uint8_t message_byte)
 Processes one byte of the incoming message.
 
void update (uint8_t message_byte)
 Processes one byte of the incoming message.
 

Private Attributes

uint8_t state_
 Current value of the state register for the CRC computation.
 

Static Private Attributes

static const uint8_t table256 [256]
 256-entry lookup table for the update256 function.
 
static const uint8_t tableHi16 [16]
 16-entry lookup table for the update16 function.
 
static const uint8_t tableLo16 [16]
 16-entry lookup table for the update16 function.
 

Detailed Description

Helper class for computing CRC-8 according to Dallas/Maxim specification for 1-wire protocol.

This specification is used for BiDiB, RCN-218 and S-9.2.1.1.

This class can incrementally compute CRC byte by byte. There are three implementations available, with different code space requirements.

Definition at line 82 of file Crc.hxx.

Constructor & Destructor Documentation

◆ Crc8DallasMaxim()

Crc8DallasMaxim::Crc8DallasMaxim ( )
inline

Definition at line 85 of file Crc.hxx.

Member Function Documentation

◆ check_ok() [1/2]

bool Crc8DallasMaxim::check_ok ( )
inline

Checks that the message has a correct CRC.

This function assumes that the CRC byte has already been consumed.

Returns
true if the message checksum is correct.

Definition at line 105 of file Crc.hxx.

◆ check_ok() [2/2]

bool Crc8DallasMaxim::check_ok ( uint8_t  checksum_byte)
inline

Checks that the message has a correct CRC.

This function assumes that the CRC byte was not part of the message.

Parameters
checksum_bytethe CRC8 byte of the received message.
Returns
true if the message checksum is correct.

Definition at line 114 of file Crc.hxx.

◆ get()

uint8_t Crc8DallasMaxim::get ( )
inline
Returns
the checksum of the currently consumed message.

Definition at line 97 of file Crc.hxx.

◆ init()

void Crc8DallasMaxim::init ( )
inline

Re-sets the state machine for checksumming a new message.

Definition at line 91 of file Crc.hxx.

◆ update()

void Crc8DallasMaxim::update ( uint8_t  message_byte)
inline

Processes one byte of the incoming message.

Parameters
message_bytenext byte in the message.

Definition at line 180 of file Crc.hxx.

◆ update0()

void Crc8DallasMaxim::update0 ( uint8_t  message_byte)
inline

Processes one byte of the incoming message.

No lookup table will be used.

Parameters
message_bytenext byte in the message.

Definition at line 122 of file Crc.hxx.

◆ update16()

void Crc8DallasMaxim::update16 ( uint8_t  message_byte)
inline

Processes one byte of the incoming message.

A small lookup table will be used.

Parameters
message_bytenext byte in the message.

Definition at line 164 of file Crc.hxx.

◆ update256()

void Crc8DallasMaxim::update256 ( uint8_t  message_byte)
inline

Processes one byte of the incoming message.

A 256-byte lookup table will be used.

Parameters
message_bytenext byte in the message.

Definition at line 173 of file Crc.hxx.

Member Data Documentation

◆ state_

uint8_t Crc8DallasMaxim::state_
private

Current value of the state register for the CRC computation.

Definition at line 207 of file Crc.hxx.

◆ table256

const uint8_t Crc8DallasMaxim::table256
staticprivate

256-entry lookup table for the update256 function.

Definition at line 225 of file Crc.hxx.

◆ tableHi16

const uint8_t Crc8DallasMaxim::tableHi16
staticprivate
Initial value:
=
{
0x00, 0x9d, 0x23, 0xbe, 0x46, 0xdb, 0x65, 0xf8,
0x8c, 0x11, 0xaf, 0x32, 0xca, 0x57, 0xe9, 0x74
}

16-entry lookup table for the update16 function.

Definition at line 269 of file Crc.hxx.

◆ tableLo16

const uint8_t Crc8DallasMaxim::tableLo16
staticprivate
Initial value:
=
{
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83,
0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
}

16-entry lookup table for the update16 function.

Definition at line 262 of file Crc.hxx.


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