@canboat/canboatjs 2.2.0 → 2.4.0
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/bin/analyzerjs +18 -2
- package/lib/fromPgn.js +27 -10
- package/package.json +2 -2
package/bin/analyzerjs
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const argv = require('minimist')(process.argv.slice(2)
|
|
3
|
+
const argv = require('minimist')(process.argv.slice(2), {
|
|
4
|
+
alias: { h: 'help' },
|
|
5
|
+
boolean: ['n']
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
if ( argv['help'] ) {
|
|
9
|
+
console.error(`Usage: ${process.argv[1]} [options]
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
-c don't check for invalid values
|
|
13
|
+
-n output null values
|
|
14
|
+
-h, --help output usage information`)
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
const Parser = require('../index').FromPgn
|
|
6
|
-
var parser = new Parser(
|
|
19
|
+
var parser = new Parser( {
|
|
20
|
+
returnNulls: argv['n'] === true,
|
|
21
|
+
checkForInvalidFields: argv['n']
|
|
22
|
+
})
|
|
7
23
|
|
|
8
24
|
parser.on('error', (pgn, error) => {
|
|
9
25
|
console.error(`Error parsing ${pgn.pgn} ${error}`)
|
package/lib/fromPgn.js
CHANGED
|
@@ -60,6 +60,10 @@ class Parser extends EventEmitter {
|
|
|
60
60
|
super()
|
|
61
61
|
this.options = _.isUndefined(opts) ? {} : opts
|
|
62
62
|
|
|
63
|
+
if ( this.options.returnNulls === undefined ) {
|
|
64
|
+
this.options.returnNulls = false
|
|
65
|
+
}
|
|
66
|
+
|
|
63
67
|
this.name = pkg.name
|
|
64
68
|
this.version = pkg.version
|
|
65
69
|
this.author = pkg.author
|
|
@@ -235,7 +239,8 @@ class Parser extends EventEmitter {
|
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
241
|
|
|
238
|
-
if ( !_.isUndefined(value) && value != null
|
|
242
|
+
if ( !_.isUndefined(value) && (value != null ||
|
|
243
|
+
this.options.returnNulls) ) {
|
|
239
244
|
pgn.fields[field.Name] = value
|
|
240
245
|
}
|
|
241
246
|
}
|
|
@@ -243,7 +248,15 @@ class Parser extends EventEmitter {
|
|
|
243
248
|
var repeating = fields.slice(fields.length-RepeatingFields)
|
|
244
249
|
pgn.fields.list = []
|
|
245
250
|
|
|
246
|
-
|
|
251
|
+
let count
|
|
252
|
+
|
|
253
|
+
if ( pgnData.RepeatingFieldSet1CountField !== undefined ) {
|
|
254
|
+
count = pgn.fields[pgnData.Fields[pgnData.RepeatingFieldSet1CountField-1].Name]
|
|
255
|
+
} else {
|
|
256
|
+
count = 2048
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
while ( bs.bitsLeft > 0 && --count >= 0 ) {
|
|
247
260
|
var group = {}
|
|
248
261
|
repeating.forEach(field => {
|
|
249
262
|
if ( bs.bitsLeft > 0 ) {
|
|
@@ -570,7 +583,18 @@ function readField(options, runPostProcessor, pgn, field, bs) {
|
|
|
570
583
|
if ( field.Offset ) {
|
|
571
584
|
value += field.Offset
|
|
572
585
|
}
|
|
573
|
-
|
|
586
|
+
let max
|
|
587
|
+
if ( typeof field.RangeMax !== 'undefined'
|
|
588
|
+
&& field.Resolution ) {
|
|
589
|
+
max = field.RangeMax / field.Resolution
|
|
590
|
+
}
|
|
591
|
+
if ( options.checkForInvalidFields !== false && max !== 'undefined' &&
|
|
592
|
+
field.FieldType !== 'LOOKUP' &&
|
|
593
|
+
field.BitLength > 1 &&
|
|
594
|
+
max - value <= 0 ) {
|
|
595
|
+
//console.log(`Bad field ${field.Name} ${max - value}`)
|
|
596
|
+
value = null
|
|
597
|
+
} if ( field.Resolution && typeof value === 'number' ) {
|
|
574
598
|
var resolution = field.Resolution
|
|
575
599
|
|
|
576
600
|
if ( _.isString(resolution) ) {
|
|
@@ -586,13 +610,6 @@ function readField(options, runPostProcessor, pgn, field, bs) {
|
|
|
586
610
|
}
|
|
587
611
|
|
|
588
612
|
value = Number.parseFloat(value.toFixed(precision))
|
|
589
|
-
|
|
590
|
-
if ( typeof field.RangeMin !== 'undefined' && value < field.RangeMin ) {
|
|
591
|
-
value = null
|
|
592
|
-
}
|
|
593
|
-
if ( typeof field.RangeMax !== 'undefined' && value > field.RangeMax ) {
|
|
594
|
-
value = null
|
|
595
|
-
}
|
|
596
613
|
}
|
|
597
614
|
|
|
598
615
|
if (field.FieldType === 'LOOKUP' &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canboat/canboatjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Native javascript version of canboat",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"webpack-cli": "^3.3.10"
|
|
80
80
|
},
|
|
81
81
|
"optionalDependencies": {
|
|
82
|
-
"serialport": "
|
|
82
|
+
"serialport": "11.x.x",
|
|
83
83
|
"socketcan": "^4.0.3"
|
|
84
84
|
},
|
|
85
85
|
"repository": {
|