srecord: srecord::crc16 Class Reference

srecord 1.65.0

Loading...
Searching...
No Matches
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.
| 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.
| crc16 (const crc16 &)
| The copy constructor.
crc16 & | operator= (const crc16 &)
| The assignment operator.
unsigned short | get () const
| The get method is used to obtain the running value of the cyclic redundancy check.
void | next (unsigned char)
| The next method is used to advance the state by one byte.
void | nextbuf (const void *, size_t)
| The nextbuf method is used to advance the state by a series of bytes.
void | print_table (void) const
| The print_table method may be used to print the table being used.

## 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.

## 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

enum srecord::crc16::seed_mode_t

Enumerator
seed_mode_ccitt |
seed_mode_xmodem |
seed_mode_broken |

Definition at line 82 of file crc16.h.

## ◆ bit_direction_t

enum srecord::crc16::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_mode | This selects which CRC16 calculation seed is to be used.
  augment | This is true if the 16-zero-bit augmentation is desired. This is the default. False if no augmentation is desired.
  polynomial | The checksum polynomial.
  bitdir | The direction of bits in a characters as they pass through the algorithm.

References bit_direction_most_to_least, polynomial_ccitt, and seed_mode_ccitt.

Referenced by crc16(), and operator=().

## ◆ crc16() [2/2]

srecord::crc16::crc16 | ( | const crc16 & |  | ) |

The copy constructor.

References crc16().

## Member Function Documentation

## ◆ polynomial_by_name()

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.

References crc16().

## ◆ 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:

- crc16.h