JavaScript utility that parses Isoblue raw data
The library can be installed with npm
using
$ npm install isobus-parser
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)
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
var data = [0x01, 0x01, 0x01, 0x01, 0x0, 0x0, 0xFF, 0xFF];
function test_parse () {
parse(data, 1, 3, 3, 2);
Output:
197381.0
Parses raw input array from IsoBlue
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: ##
}
...
...
}
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}]}
Parses a 16 character hex string into an array of 8 bytes, assuming the first charcter in the string is the least significant byte.
payload
{String} 16 character hex string (padded with 0 bytes if necessary)
payload= 'FFFFFFFFFFFFFF22';
getBytes(payload);
Output:
[255.0, 255.0, 255.0, 255.0, 255.0, 255.0, 255.0, 34.0]
converts Isobus formatted string hex value from speadsheet into decimal PGN number
canString
{String} Isobus formatted string hex value
canString= '0ff46x';
getPgn(canString);
Output:
65350.0
Converts hex string into decimal number
h
{String} hex string to be converted to decimal
hval= "FFFF";
h2d(hval);
Output:
65535.0