@canboat/canboatjs 2.5.3 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yml +28 -0
- package/lib/fromPgn.js +7 -5
- package/lib/stringMsg.js +24 -5
- package/lib/toPgn.js +2 -1
- package/package.json +1 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
+
|
|
4
|
+
name: Node.js CI & Test
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "master" ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ "master" ]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
node-version: [16.x, 18.x, 20.x]
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v3
|
|
23
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
24
|
+
uses: actions/setup-node@v3
|
|
25
|
+
with:
|
|
26
|
+
node-version: ${{ matrix.node-version }}
|
|
27
|
+
- run: npm install
|
|
28
|
+
- run: npm test
|
package/lib/fromPgn.js
CHANGED
|
@@ -24,7 +24,6 @@ const BitStream = require('bit-buffer').BitStream
|
|
|
24
24
|
const BitView = require('bit-buffer').BitView
|
|
25
25
|
const Int64LE = require('int64-buffer').Int64LE
|
|
26
26
|
const Uint64LE = require('int64-buffer').Uint64LE
|
|
27
|
-
const { parse: parseDate } = require('date-fns')
|
|
28
27
|
|
|
29
28
|
const { getPGNFromCanId } = require('./utilities')
|
|
30
29
|
const { getIndustryName, getManufacturerName } = require('./codes')
|
|
@@ -120,9 +119,7 @@ class Parser extends EventEmitter {
|
|
|
120
119
|
})
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
trace(`${pgn.pgn} ${len} ${pgnData.Length} ${RepeatingFields} ${couldBeMulti}`)
|
|
122
|
+
trace(`${pgn.pgn} ${len} ${pgnData.Length} ${couldBeMulti}`)
|
|
126
123
|
if ( coalesced || len > 0x8 || (this.format == FORMAT_COALESCED && !this.mixedFormat) ) {
|
|
127
124
|
this.format = FORMAT_COALESCED
|
|
128
125
|
if ( sourceString ) {
|
|
@@ -204,6 +201,8 @@ class Parser extends EventEmitter {
|
|
|
204
201
|
pgn.input = [ sourceString ]
|
|
205
202
|
}
|
|
206
203
|
|
|
204
|
+
let RepeatingFields = pgnData.RepeatingFieldSet1Size ? pgnData.RepeatingFieldSet1Size : 0
|
|
205
|
+
|
|
207
206
|
pgn.fields = {}
|
|
208
207
|
try {
|
|
209
208
|
var fields = pgnData.Fields
|
|
@@ -246,6 +245,7 @@ class Parser extends EventEmitter {
|
|
|
246
245
|
if ( value == null ) {
|
|
247
246
|
value = pgnData.Fields[i].Match
|
|
248
247
|
}
|
|
248
|
+
RepeatingFields = pgnData.RepeatingFieldSet1Size ? pgnData.RepeatingFieldSet1Size : 0
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -611,6 +611,7 @@ function readField(options, runPostProcessor, pgn, field, bs, fields) {
|
|
|
611
611
|
}
|
|
612
612
|
if ( options.checkForInvalidFields !== false && max !== 'undefined' &&
|
|
613
613
|
field.FieldType !== 'LOOKUP' &&
|
|
614
|
+
field.FieldType !== 'FIELDTYPE_LOOKUP' &&
|
|
614
615
|
field.BitLength > 1 &&
|
|
615
616
|
max - value <= 0 ) {
|
|
616
617
|
//console.log(`Bad field ${field.Name} ${max - value}`)
|
|
@@ -633,7 +634,8 @@ function readField(options, runPostProcessor, pgn, field, bs, fields) {
|
|
|
633
634
|
value = Number.parseFloat(value.toFixed(precision))
|
|
634
635
|
}
|
|
635
636
|
|
|
636
|
-
if (field.FieldType === 'LOOKUP'
|
|
637
|
+
if ((field.FieldType === 'LOOKUP' ||
|
|
638
|
+
field.FieldType === 'FIELDTYPE_LOOKUP') &&
|
|
637
639
|
runPostProcessor &&
|
|
638
640
|
(_.isUndefined(options.resolveEnums) ||
|
|
639
641
|
options.resolveEnums)) {
|
package/lib/stringMsg.js
CHANGED
|
@@ -8,7 +8,6 @@ const {
|
|
|
8
8
|
const {
|
|
9
9
|
buildCanId, encodeCanIdString, parseCanId, parseCanIdStr,
|
|
10
10
|
} = require('./canId')
|
|
11
|
-
const { parse: parseDate } = require('date-fns')
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Helper function that helps merge canId fields with format, data, and others.
|
|
@@ -113,10 +112,26 @@ exports.encodeYDRAW = ({ data, ...canIdInfo }) => {
|
|
|
113
112
|
return pgns.map(buffer => canId + ' ' + byteString(buffer, ' '))
|
|
114
113
|
}
|
|
115
114
|
|
|
115
|
+
const get0183Sentence = (msg) => {
|
|
116
|
+
let sentence = msg
|
|
117
|
+
if (sentence.charAt(0) === '\\') {
|
|
118
|
+
split = sentence.split('\\')
|
|
119
|
+
if ( split.length < 3 ) {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
sentence = split[2]
|
|
123
|
+
}
|
|
124
|
+
return sentence
|
|
125
|
+
}
|
|
126
|
+
|
|
116
127
|
// $PCDIN,01F119,00000000,0F,2AAF00D1067414FF*59
|
|
117
|
-
exports.isPCDIN =
|
|
128
|
+
exports.isPCDIN = (msg) => {
|
|
129
|
+
const sentence = get0183Sentence(msg)
|
|
130
|
+
return sentence.startsWith('$PCDIN,')
|
|
131
|
+
}
|
|
118
132
|
exports.parsePCDIN = (input) => {
|
|
119
|
-
const
|
|
133
|
+
const sentence = get0183Sentence(input)
|
|
134
|
+
const [ prefix, pgn, timeHex, src, data ] = sentence.split(',')
|
|
120
135
|
let timer = parseInt(timeHex, 32)
|
|
121
136
|
|
|
122
137
|
timer = timer / 1024
|
|
@@ -137,9 +152,13 @@ exports.encodePCDIN = ({ prefix = '$PCDIN', pgn, data, dst = 255}) => {
|
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
// $MXPGN,01F801,2801,C1308AC40C5DE343*19
|
|
140
|
-
exports.isMXPGN =
|
|
155
|
+
exports.isMXPGN = (msg) => {
|
|
156
|
+
const sentence = get0183Sentence(msg)
|
|
157
|
+
return sentence.startsWith('$MXPGN,')
|
|
158
|
+
}
|
|
141
159
|
exports.parseMXPGN = (input) => {
|
|
142
|
-
const
|
|
160
|
+
const sentence = get0183Sentence(input)
|
|
161
|
+
const [ prefix, pgn, attr_word, data ] = sentence.split(',')
|
|
143
162
|
|
|
144
163
|
const send_prio_len = (parseInt(attr_word.substr(0,2), 16).toString(2)).padStart(8, '0');
|
|
145
164
|
const addr = (parseInt(attr_word.substr(2,2), 16));
|
package/lib/toPgn.js
CHANGED
|
@@ -190,7 +190,8 @@ function writeField(bs, pgn_number, field, data, value, fields, bitLength) {
|
|
|
190
190
|
}
|
|
191
191
|
} else if ( type && fieldTypeMappers[type] ) {
|
|
192
192
|
value = fieldTypeMappers[type](field, value)
|
|
193
|
-
} else if (field.FieldType === 'LOOKUP'
|
|
193
|
+
} else if ((field.FieldType === 'LOOKUP' ||
|
|
194
|
+
field.FieldType === 'FIELDTYPE_LOOKUP') && _.isString(value)) {
|
|
194
195
|
if (!(field.Id === "timeStamp" && value < 60)) {
|
|
195
196
|
value = lookup(field, value)
|
|
196
197
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canboat/canboatjs",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "Native javascript version of canboat",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@canboat/pgns": "3.x.x",
|
|
59
59
|
"bit-buffer": "0.2.3",
|
|
60
|
-
"date-fns": "2.0.0-alpha.27",
|
|
61
60
|
"debug": "^4.3.4",
|
|
62
61
|
"dnssd": "^0.4.1",
|
|
63
62
|
"int64-buffer": "^0.1.10",
|