All Projects → imnemo → crc16

imnemo / crc16

Licence: MIT license
A native node addon to calcalate and verify CRC16 values, adopted by MODBUS agreement

Programming Languages

C++
36643 projects - #6 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to crc16

modbus-esp8266
Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.
Stars: ✭ 332 (+1283.33%)
Mutual labels:  modbus, modbus-rtu, modbus-protocol, modbus-serial
ModbusMechanic
Cross platform GUI MODBUS TCP/RTU simulator & gateway. Interprets data types including ascii float and int.
Stars: ✭ 63 (+162.5%)
Mutual labels:  modbus, modbus-rtu
rodbus
Rust implementation of Modbus with idiomatic bindings for C, C++, .NET, and Java
Stars: ✭ 34 (+41.67%)
Mutual labels:  modbus, modbus-protocol
go-modbus
modbus write in pure go, support rtu,ascii,tcp master library,also support tcp slave.(WIP new implement<old: https://github.com/thinkgos/gomodbus >)
Stars: ✭ 124 (+416.67%)
Mutual labels:  modbus, modbus-rtu
Home Assistant EDP Box
Integração das EDP Box com Home Assistant Core
Stars: ✭ 91 (+279.17%)
Mutual labels:  modbus, modbus-serial
ioBroker.modbus
Modbus adapter for ioBroker
Stars: ✭ 31 (+29.17%)
Mutual labels:  modbus, modbus-rtu
crc
A Pure Rust Implementation of Generic CRC Algorithm
Stars: ✭ 24 (+0%)
Mutual labels:  crc, crc16
solaredge modbus
SolarEdge Modbus data collection library
Stars: ✭ 49 (+104.17%)
Mutual labels:  modbus, modbus-rtu
EasyModbusTCP.Java
EasyModbusTCP library for Java implementation
Stars: ✭ 76 (+216.67%)
Mutual labels:  modbus, modbus-rtu
huawei solar
Home Assistant integration for Huawei Solar inverters via Modbus
Stars: ✭ 126 (+425%)
Mutual labels:  modbus, modbus-rtu
Dominos
A main actionbar replacement
Stars: ✭ 72 (+200%)
Mutual labels:  addon
interactive-physics-editor
Simplifies the process of positioning multiple objects in 3D space with collision handling
Stars: ✭ 20 (-16.67%)
Mutual labels:  addon
recastCLI.js
CLI tool & Node.js addon to generate navigation mesh
Stars: ✭ 36 (+50%)
Mutual labels:  node-module
hexen-dll-injector
HEX-EN DLL Injector
Stars: ✭ 20 (-16.67%)
Mutual labels:  addon
node-mysql
Node with mysql boilerplate
Stars: ✭ 72 (+200%)
Mutual labels:  node-module
wfc 2D B3D
2D Wave Function Collapse as Blender Plugin
Stars: ✭ 29 (+20.83%)
Mutual labels:  addon
addon-sqlite-web
SQLite Web - Home Assistant Community Add-ons
Stars: ✭ 29 (+20.83%)
Mutual labels:  addon
HistoryCleaner
Firefox addon that deletes history older than a specified amount of days.
Stars: ✭ 51 (+112.5%)
Mutual labels:  addon
openmuc
OpenMUC is a software framework based on Java and OSGi that simplifies the development of customized monitoring, logging and controlling systems.
Stars: ✭ 12 (-50%)
Mutual labels:  modbus
ofxPS3EyeGrabber
A Sony PS3 Eye Camera grabber for openFrameworks.
Stars: ✭ 83 (+245.83%)
Mutual labels:  addon

Build Status Coverage Status Try node-crc16 on RunKit DeepScan Grade

Node CRC16 - (中文版README)

MODBUS is an application-layer messaging protocol, positioned at level 7 of the OSI model. It provides client/server communication between devices connected on different types of buses or networks.The CRC(Cyclic Redundancy Check) part in protocol, such as MODBUS over serial line(Page 42), and Modbus-RTU(Page 75), adopt the same one algorithm.

node-crc16 implement the c++ version of this algorithm by table look-up, and also provide a node native addon and a nodejs version wrapper.

This module has been well unit tested and documented.

Versions

If your version of node.js is lower than v8.x.x, please use the latest v1.x.x of this module, or you should select v2.x.x, which uses NAPI to implement native addon gracefully and compatibly.

Usage

Tips: the most intuitive decription about this module is the comment in src and the code in unit test :).

Install

npm install node-crc16

generate a sum by crc16.checkSum

checkSumaccept three params, the first two params (input, [encoding]) construct a Buffer

crc16.checkSum('utf8 string', 'utf8')

default encoding is hex

var sum = crc16.checkSum('a031ffb7');
sum.should.equal('726d');

the third param is option,which type is Object

  • option.retType set the format of the returned sum
    • default is hex,two bytes BigEndian hex string, 726d
    • array, two unsigned char number of the returned sum,[114, 109]
    • int,one unsigned short number of the returned sum,29293
    • buffer,Buffer type of the returned sum,<Buffer 72 6d>
var sum = crc16.checkSum('a031ffb7', {retType: 'array'});
sum.should.eql([114, 109]);

verify a sum by crc16.verifySum

Params of verifySum is same as checkSum, the first two params are used to constructe a Buffer which contains the sum to be verified.

var stream = 'a031ffb7',
    sum = '726d';
var isValid = crc16.verifySum(stream + sum);
isValid.should.equal(true);

Contribution

get source code

# fork and clone the code to your local env
git clone [email protected]:imnemo/crc16.git
cd crc16

code structure

├── lib         //CRC16 algorithm implemention in c++
├── util        //Util functions
├── src         //Node Native Addon
├── test        //JS unit testing
├── test_cpp    //C++ unit testing
├── index.js    //Main entry of NodeJS module

install dependencies

npm install

C++ unit testing

The implemention of CRC16 checking and verifing algorithm in c++ is standalone in ./lib/crc16.cc. If you want to modify it, please write suitable unittest cases. You can reference Catch, and then run:

make test

Make sure all the unit testing case is passed after you modify.

JS unit testing

npm test or ./node_modules/.bin/mocha --reporter spec

Benchmark

use benchmark.js

 >>> npm run benchmark

> [email protected] benchmark /Users/nemo/code/imnemo/crc16
> node benchmark/benchmark.js

CEC16#checkSum x 905,071 ops/sec ±2.00% (83 runs sampled)
CRC16#verifySum x 1,540,940 ops/sec ±19.92% (65 runs sampled)
Fastest is CRC16#verifySum

use nanobench

 >>> npm run nanobench

> [email protected] nanobench /Users/nemo/code/imnemo/crc16
> node benchmark/nanobench.js

NANOBENCH version 2
> /Users/nemo/.nvm/versions/node/v8.1.2/bin/node benchmark/nanobench.js

# CRC16#checkSum 2,000,000 times
ok ~3.17 s (3 s + 166422442 ns)

# CRC16#verifySum 2,000,000 times
ok ~2.85 s (2 s + 848059820 ns)

all benchmarks completed
ok ~6.01 s (6 s + 14482262 ns)

pull request

You can pull a request when you complete all steps above.

TODO

  • Add JS code lint
  • Add changelog
  • Add JS unit test
  • Add JS unit test code covarage
  • Add C++ unit test
  • Add CI
  • Add performance test
  • Refactor node native addon part with NAPI
  • Add index.js.d
  • Add global module supported to provide a cli tool
  • Add donate entry

twitter: @imoncoding

qrcode_mp_oncoding

Welcome to subscribe my wechat!

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].