isobus-parser v1.0.0
isobus-parser-js
JavaScript utility that parses Isoblue raw data
Getting Started
Installation
The library can be installed with npm
using
$ npm install isobus-parser
parse(data, smallbyte,bigbyte,mul,add)
Taking data array and extracts a message from data array according to input parameters: smallbyte, bigbyte, mul and add Function makes no assumption about endianness of data. Considers the first element of data to be less significant than the second Function will fail if caller tries to retrieve too many bytes (js uses only 53 bits in numbers)
Parameters
data
{Arrray} of 8 bytes
smallbyte
{Number} specify the region of bytes to parse; represents the lowest byte to use
bigbyte
{Number} specify the region of bytes to parse; respresents the end byte
respresents the range for the consecutive bytes that comprise the message
i.e.: smallbyte=0, bigbyte=2 would parse the first 3 bytes in the data word
mult
{Number} Represent factor to multipy the parsed byte sequence
add
{Function} Represent factor to add to the parsed byte sequence
Usage Example
var data = [0x01, 0x01, 0x01, 0x01, 0x0, 0x0, 0xFF, 0xFF];
function test_parse () {
parse(data, 1, 3, 3, 2);
Output:
197381.0
parseArray(input, config)
Parses raw input array from IsoBlue
Parameters
input
{Array} of objects comprised of PGNS, a 8 byte data array, and a time stamp. Requires a JSON configuration file Ine the following format:
input=[
{pgn:XXXXX,
data: 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
timestamp=XX
},
{pgn:XXXXX,
data:0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
timstamp=XX
},
...
...
]
config
{File} Required file that contains extraction information for a given message in the following format:
config = {
'parameter': {
pgn: ##,
low: ##,
high: ##,
mul: ##,
add: ##
}
...
...
}
Usage Example
config = {
'enginespeed': {
signed: false,
pgn: 61444,
low: 3,
high: 4,
mul: 0.125,
add: 0
}
};
input=[
{pgn:61444,
data: [0xFF, 0xFF, 0xFF, 0x95, 0x47, 0xFF, 0xFF, 0xFF],
timestamp:.94
},
{pgn:61444,
data: [0xFF, 0xFF, 0xFF, 0x01, 0x1C, 0xFF, 0xFF, 0xFF],
timestamp:.94
},
{pgn:61444,
data: [0xFF, 0xFF, 0xFF, 0x0E, 0x1C, 0xFF, 0xFF, 0xFF],
timestamp:.94
},
{pgn:61444,
data: [0xFF, 0xFF, 0xFF, 0xF8, 0x1B, 0xFF, 0xFF, 0xFF],
timestamp:.94
}
];
parseArray(input,config);
Output:
{enginespeed=[{timestamp=0.94, measurement=2290.625}, {timestamp=0.94, measurement=896.125}, {timestamp=0.94, measurement=897.75}, {timestamp=0.94, measurement=895.0}]}
getBytes(payload)
Parses a 16 character hex string into an array of 8 bytes, assuming the first charcter in the string is the least significant byte.
Parameters
payload
{String} 16 character hex string (padded with 0 bytes if necessary)
Usage Example
payload= 'FFFFFFFFFFFFFF22';
getBytes(payload);
Output:
[255.0, 255.0, 255.0, 255.0, 255.0, 255.0, 255.0, 34.0]
getPgn(canString)
converts Isobus formatted string hex value from speadsheet into decimal PGN number
Parameters
canString
{String} Isobus formatted string hex value
Usage Example
canString= '0ff46x';
getPgn(canString);
Output:
65350.0
h2d(h)
Converts hex string into decimal number
Parameters
h
{String} hex string to be converted to decimal
Usage Example
hval= "FFFF";
h2d(hval);
Output:
65535.0
10 years ago