1.1.0 • Published 6 years ago

crc-full v1.1.0

Weekly downloads
576
License
MIT
Repository
github
Last release
6 years ago

crc-full

Support Node of LTS npm version Build passing dependencies typescript License mit


Description

The crc-full module is used to calculate any kind of CRC setting parameters such as length, polynomial and others. It's completely written in typescript for node js.

How to use

Use is very simple. Just add the module to project.

Install dependencies:
The only one dependency is typescript compiler

npm install -g typescript

Import in node js

After typescript is installed, simple run:

npm install crc-full

Use in your project

First of all import the module in your project files, then create an instance of the class whith all parameters of the CRC algorithm you need. After the instance is create you can compute the CRC of your data passing an array of byte or simply a buffer object.

For typescript use:

import {CRC} from 'crc-full'
...
let crc =  new CRC("CRC16", 16, 0x8005, 0x0000, 0x0000, false, false);
crc.compute([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]);
let computed_crc = crc.compute(Buffer.from("Hello world!","ascii"))

For javascript use:

const CRC = require('crc-full').CRC;
var crc = new CRC("CRC16", 16, 0x8005, 0x0000, 0x0000, false, false);
crc.compute([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]);
var computed_crc = crc.compute(Buffer.from("Hello world!", "ascii"))

Where the parameters in the constructor are:

  • Length: the Length of CRC in bit (8,16,32)
  • Name: friendly name for the configuration
  • Polinomial: the polinomial used to compute CRC
  • InitialValue: initial value of CRC
  • FinalXorValue: final value of CRC
  • InputReflected: boolen that indicate if need to reflect input
  • OutputReflected: boolen that indicate if need to reflect input

Presets

Invoking the static getter defaults is possible to use the internal preconfigurated CRC algorithms. An array of instantiated object is returned back

The algorithms are:

LengthNamePolinomialInitial valueFinal valueInput reflectedOutput reflected
8CRC80x070x000x00falsefalse)
8CRC8_SAE_J18500x1D0xFF0xFFfalsefalse)
8CRC8_SAE_J1850_ZERO0x1D0x000x00falsefalse)
8CRC8_8H2F0x2F0xFF0xFFfalsefalse)
8CRC8_CDMA20000x9B0xFF0x00falsefalse)
8CRC8_DARC0x390x000x00truetrue)
8CRC8_DVB_S20xD50x000x00falsefalse)
8CRC8_EBU0x1D0xFF0x00truetrue)
8CRC8_ICODE0x1D0xFD0x00falsefalse)
8CRC8_ITU0x070x000x55falsefalse
8CRC8_MAXIM0x310x000x00truetrue
8CRC8_ROHC0x070xFF0x00truetrue
8CRC8_WCDMA0x9B0x000x00truetrue
16CRC16_CCIT_ZERO0x10210x00000x0000falsefalse
16CRC16_ARC0x80050x00000x0000truetrue
16CRC16_AUG_CCITT0x10210x1D0F0x0000falsefalse
16CRC16_BUYPASS0x80050x00000x0000falsefalse
16CRC16_CCITT_FALSE0x10210xFFFF0x0000falsefalse
16CRC16_CDMA20000xC8670xFFFF0x0000falsefalse
16CRC16_DDS_1100x80050x800D0x0000falsefalse
16CRC16_DECT_R0x05890x00000x0001falsefalse
16CRC16_DECT_X0x05890x00000x0000falsefalse
16CRC16_DNP0x3D650x00000xFFFFtruetrue
16CRC16_EN_137570x3D650x00000xFFFFfalsefalse
16CRC16_GENIBUS0x10210xFFFF0xFFFFfalsefalse
16CRC16_MAXIM0x80050x00000xFFFFtruetrue
16CRC16_MCRF4XX0x10210xFFFF0x0000truetrue
16CRC16_RIELLO0x10210xB2AA0x0000truetrue
16CRC16_T10_DIF0x8BB70x00000x0000falsefalse
16CRC16_TELEDISK0xA0970x00000x0000falsefalse
16CRC16_TMS371570x10210x89EC0x0000truetrue
16CRC16_USB0x80050xFFFF0xFFFFtruetrue
16CRC16_A0x10210xC6C60x0000truetrue
16CRC16_KERMIT0x10210x00000x0000truetrue
16CRC16_MODBUS0x80050xFFFF0x0000truetrue
16CRC16_X_250x10210xFFFF0xFFFFtruetrue
16CRC16_XMODEM0x10210x00000x0000falsefalse
32CRC320x04C11DB70xFFFFFFFF0xFFFFFFFFtruetrue
32CRC32_BZIP20x04C11DB70xFFFFFFFF0xFFFFFFFFfalsefalse
32CRC32_C0x1EDC6F410xFFFFFFFF0xFFFFFFFFtruetrue
32CRC32_D0xA833982B0xFFFFFFFF0xFFFFFFFFtruetrue
32CRC32_MPEG20x04C11DB70xFFFFFFFF0x00000000falsefalse
32CRC32_POSIX0x04C11DB70x000000000xFFFFFFFFfalsefalse
32CRC32_Q0x814141AB0x000000000x00000000falsefalse
32CRC32_JAMCRC0x04C11DB70xFFFFFFFF0x00000000truetrue
32CRC32_XFER0x000000AF0x000000000x00000000falsefalse

Is possible to use one of above CRC preset using the method default(name) where parameter name is the name of chosen preset.

Typescript users can use:

import {CRC} from 'crc-full'
let crc = CRC.default("CRC16_CCIT_ZERO");
let computed_crc = crc.compute(Buffer.from("Hello world!","ascii"))

Typescript users can use:

const CRC = require('crc-full').CRC;
var crc = CRC.default("CRC16_CCIT_ZERO");
var computed_crc = crc.compute(Buffer.from("Hello world!","ascii"))

Advanced

The module also support advanced methods to calculate CRC tables and export them as byte arrays:

...
crc.makeCrcTable();
crc.makeCrcTableReversed();
var table = crc.table;
...

Notes

The method compute take a byte array (or Buffer) as input and returns a number.
If you need to convert a string you have to pass it as a byte array.
If you need to read the CRC result in hex format string use .toString(16)