Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update lib/crc.js

added modbus hex
  • Loading branch information...
commit d6a3f3d9565750216ab4ed675bc6ef47b5788aab 1 parent 76ca5d9
@thebadger412 thebadger412 authored
Showing with 20 additions and 45 deletions.
  1. +20 −45 lib/crc.js
View
65 lib/crc.js
@@ -43,8 +43,8 @@
// is taken from an article by David Schwaderer in the April 1985
// issue of PC Tech Journal.
var CRC_ARC_TAB = new Array(
+ // THIS TABLE IS THE RIGHT ONE FOR MODBUS CALCULATIONS
// C/C++ language:
- //
// unsigned short CRC_ARC_TAB[] = {...};
0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,0xC601,0x06C0,0x0780,0xC741,0x0500,
0xC5C1,0xC481,0x0440,0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40,0x0A00,0xCAC1,
@@ -294,6 +294,7 @@
function crcModbusHex(buf)
{
+ //SAME AS ABOVE EXCEPT THIS HAS THE MODBUS CRC AT 0XFFFF
var crc = 65535
for (var i = 0, len = buf.length; i < len; ++i)
@@ -317,6 +318,7 @@
return crc;
};
+
function crc16Buffer(buf)
{
var crc = 0;
@@ -329,31 +331,6 @@
return crc;
}
- function crc16CCITT(str)
- {
@bminer
bminer added a note

Hey! Why is crc16CCITT function being removed here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- var i,
- len = str.length,
- crc = 0xFFFF
- ;
-
- for(i = 0; i < len; i++)
- crc = crc16Add(crc, str.charCodeAt(i));
-
- return crc^0x0000;
- };
-
- function crc16CCITTBuffer(buf)
- {
- var crc = 0xFFFF;
-
- for (var i = 0, len = buf.length; i < len; ++i)
- {
- crc = crc16Add(crc, buf[i]);
- }
-
- return crc^0x0000;
- }
-
function fcs16(str)
{
var i,
@@ -377,7 +354,7 @@
for(i = 0; i < len; i++)
crc = crc32Add(crc, str.charCodeAt(i));
- return (crc^0xFFFFFFFF) >>> 0;
+ return crc^0xFFFFFFFF;
};
function crc32Buffer(buf)
@@ -389,7 +366,7 @@
crc = crc32Add(crc, buf[i]);
}
- return (crc ^ 0xFFFFFFFF) >>> 0;
+ return crc ^ 0xFFFFFFFF;
}
/**
@@ -425,7 +402,7 @@
var target, property;
- if(typeof(module) !== 'undefined' && module.exports)
+ if(typeof(window) == 'undefined')
{
target = module;
property = 'exports';
@@ -437,22 +414,20 @@
}
target[property] = {
- 'crc8' : crc8,
- 'crcArc' : crcArc,
- 'crcModbusString' : crcModbusString,
- 'crcModbusHex' : crcModbusHex,
- 'crc16' : crc16,
- 'crc16CCITT' : crc16CCITT,
- 'fcs16' : fcs16,
- 'crc32' : crc32,
- 'hex8' : hex8,
- 'hex16' : hex16,
- 'hex32' : hex32,
- 'buffer' : {
- crc8 : crc8Buffer,
- crc16 : crc16Buffer,
- crc16CCITT : crc16CCITTBuffer,
- crc32 : crc32Buffer
+ 'crc8' : crc8,
+ 'crcArc' : crcArc,
+ 'crcModbusString' : crcModbusString,
+ 'crcModbusHex' : crcModbusHex,
+ 'crc16' : crc16,
+ 'fcs16' : fcs16,
+ 'crc32' : crc32,
+ 'hex8' : hex8,
+ 'hex16' : hex16,
+ 'hex32' : hex32,
+ 'buffer' : {
+ crc8 : crc8Buffer,
+ crc16 : crc16Buffer,
+ crc32 : crc32Buffer
}
};
})();
Please sign in to comment.
Something went wrong with that request. Please try again.