srecord  1.65.0
srecord::crc16 Class Reference

The crc16 class is used to represent the running value of a 16-bit cyclic redundancy check of series of bytes. More...

#include <crc16.h>

Public Types

enum  {
  polynomial_ccitt = 0x1021 , polynomial_ansi = 0x8005 , polynomial_dnp = 0x3D65 , polynomial_dect = 0x0589 ,
  polynomial_t10_dif = 0x8BB7
}
 
enum  seed_mode_t { seed_mode_ccitt , seed_mode_xmodem , seed_mode_broken }
 
enum  bit_direction_t { bit_direction_most_to_least , bit_direction_least_to_most }
 

Public Member Functions

virtual ~crc16 ()
 The destructor. More...
 
 crc16 (seed_mode_t seed_mode=seed_mode_ccitt, bool augment=true, unsigned short polynomial=polynomial_ccitt, bit_direction_t bitdir=bit_direction_most_to_least)
 The default constructor. More...
 
 crc16 (const crc16 &)
 The copy constructor. More...
 
crc16operator= (const crc16 &)
 The assignment operator. More...
 
unsigned short get () const
 The get method is used to obtain the running value of the cyclic redundancy check. More...
 
void next (unsigned char)
 The next method is used to advance the state by one byte. More...
 
void nextbuf (const void *, size_t)
 The nextbuf method is used to advance the state by a series of bytes. More...
 
void print_table (void) const
 The print_table method may be used to print the table being used. More...
 

Static Public Member Functions

static int polynomial_by_name (const char *name)
 The polynomial_by_name class method is used to take the name of a CRC-16 polynamlial, and return the value of the CRC-16 polynomial corresponding to that name. More...
 

Detailed Description

The crc16 class is used to represent the running value of a 16-bit cyclic redundancy check of series of bytes.

Note: this CRC16 works for systems that process the leaast significant bit of each byte first, and working to wards the most significant bit.

If you were expecting MSB first (you may not even know it) this code will give you "wrong" answers. Try using the bitrev filter.

Definition at line 42 of file crc16.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
polynomial_ccitt 

X.25, V.41, HDLC, XMODEM, Bluetooth, SD, CRC-CCITT.

polynomial_ansi 

CRC-16-IBM, Bisync, Modbus, USB, ANSI X3.28, CRC-16-ANSI.

polynomial_dnp 

CRC-16-DNP, DNP, IEC 870, M-Bus.

polynomial_dect 

CRC-16-DECT.

polynomial_t10_dif 

CRC-16-T10-DIF, SCSI DIF.

Definition at line 47 of file crc16.h.

◆ seed_mode_t

Enumerator
seed_mode_ccitt 
seed_mode_xmodem 
seed_mode_broken 

Definition at line 82 of file crc16.h.

◆ bit_direction_t

Enumerator
bit_direction_most_to_least 
bit_direction_least_to_most 

Definition at line 94 of file crc16.h.

Constructor & Destructor Documentation

◆ ~crc16()

virtual srecord::crc16::~crc16 ( )
virtual

The destructor.

◆ crc16() [1/2]

srecord::crc16::crc16 ( seed_mode_t  seed_mode = seed_mode_ccitt,
bool  augment = true,
unsigned short  polynomial = polynomial_ccitt,
bit_direction_t  bitdir = bit_direction_most_to_least 
)

The default constructor.

Parameters
seed_modeThis selects which CRC16 calculation seed is to be used.
augmentThis is true if the 16-zero-bit augmentation is desired. This is the default. False if no augmentation is desired.
polynomialThe checksum polynomial.
bitdirThe direction of bits in a characters as they pass through the algorithm.

◆ crc16() [2/2]

srecord::crc16::crc16 ( const crc16 )

The copy constructor.

Member Function Documentation

◆ polynomial_by_name()

static int srecord::crc16::polynomial_by_name ( const char *  name)
static

The polynomial_by_name class method is used to take the name of a CRC-16 polynamlial, and return the value of the CRC-16 polynomial corresponding to that name.

◆ operator=()

crc16& srecord::crc16::operator= ( const crc16 )

The assignment operator.

◆ get()

unsigned short srecord::crc16::get ( ) const

The get method is used to obtain the running value of the cyclic redundancy check.

◆ next()

void srecord::crc16::next ( unsigned char  )

The next method is used to advance the state by one byte.

◆ nextbuf()

void srecord::crc16::nextbuf ( const void *  ,
size_t   
)

The nextbuf method is used to advance the state by a series of bytes.

◆ print_table()

void srecord::crc16::print_table ( void  ) const

The print_table method may be used to print the table being used.

This is principally for debugging the table generation process.


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