@canboat/canboatjs 1.26.2 → 1.27.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/ydvr-file CHANGED
File without changes
package/lib/canbus.js CHANGED
@@ -84,7 +84,7 @@ function CanbusStream (options) {
84
84
  options.app.on(options.outEvent || 'nmea2000out', (msg) => {
85
85
  that.sendPGN(msg)
86
86
  })
87
- options.app.on('nmea2000JsonOut', (msg) => {
87
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
88
88
  that.sendPGN(msg)
89
89
  })
90
90
  }
package/lib/candevice.js CHANGED
@@ -88,7 +88,7 @@ class CanDevice extends EventEmitter {
88
88
  }
89
89
 
90
90
  if ( options.app ) {
91
- options.app.on('N2KAnalyzerOut', this.n2kMessage.bind(this))
91
+ options.app.on(options.analyzerOutEvent || 'N2KAnalyzerOut', this.n2kMessage.bind(this))
92
92
  }
93
93
  }
94
94
 
package/lib/fromPgn.js CHANGED
@@ -738,17 +738,21 @@ function readVariableLengthField(options, pgn, field, bs) {
738
738
  * length and thus that the field number is exactly one byte earlier.
739
739
  */
740
740
 
741
- var refField = getField(pgn.fields.PGN, bs.view.buffer[bs.byteIndex-1]-1, pgn)
742
-
743
- if ( refField ) {
744
- var bits = (refField.BitLength + 7) & ~7; // Round # of bits in field refField up to complete bytes: 1->8, 7->8, 8->8 etc.
745
- let res = readField(options, false, pgn, refField, bs)
746
-
747
- if ( bits > refField.BitLength ) {
748
- bs.readBits(bits - refField.BitLength, false)
741
+ try {
742
+ var refField = getField(pgn.fields.PGN, bs.view.buffer[bs.byteIndex-1]-1, pgn)
743
+
744
+ if ( refField ) {
745
+ var bits = (refField.BitLength + 7) & ~7; // Round # of bits in field refField up to complete bytes: 1->8, 7->8, 8->8 etc.
746
+ let res = readField(options, false, pgn, refField, bs)
747
+
748
+ if ( bits > refField.BitLength ) {
749
+ bs.readBits(bits - refField.BitLength, false)
750
+ }
751
+
752
+ return res
749
753
  }
750
-
751
- return res
754
+ } catch ( error ) {
755
+ debug(error)
752
756
  }
753
757
  }
754
758
 
package/lib/ikonvert.js CHANGED
@@ -77,7 +77,7 @@ function iKonvertStream (options) {
77
77
  that.sendPGN(msg)
78
78
  }
79
79
  })
80
- options.app.on('nmea2000JsonOut', (msg) => {
80
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
81
81
  that.sendPGN(msg)
82
82
  })
83
83
 
package/lib/serial.js CHANGED
@@ -163,7 +163,7 @@ SerialStream.prototype.start = function () {
163
163
  }
164
164
  })
165
165
 
166
- this.options.app.on('nmea2000JsonOut', msg => {
166
+ this.options.app.on(this.options.jsonOutEvent || 'nmea2000JsonOut', msg => {
167
167
  if ( this.outAvailable ) {
168
168
  writeObject(msg)
169
169
  }
package/lib/venus.js CHANGED
@@ -75,7 +75,7 @@ VenusStream.prototype._transform = function (pgn, encoding, done) {
75
75
  this.fromPgn.parseVenusMQTT(pgn, (error, pgn) => {
76
76
  if ( !error ) {
77
77
  this.push(pgn)
78
- this.options.app.emit('N2KAnalyzerOut', pgn)
78
+ this.options.app.emit(this.options.analyzerOutEvent || 'N2KAnalyzerOut', pgn)
79
79
  }
80
80
 
81
81
  done()
package/lib/w2k01.js CHANGED
@@ -51,7 +51,7 @@ function W2K01Stream (options, type, outEvent) {
51
51
  }
52
52
  })
53
53
 
54
- options.app.on('nmea2000JsonOut', (msg) => {
54
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
55
55
  this.sendPGN(msg)
56
56
  })
57
57
  }
package/lib/ydgw02.js CHANGED
@@ -57,7 +57,7 @@ function Ydgw02Stream (options, type) {
57
57
  }
58
58
  })
59
59
 
60
- options.app.on('nmea2000JsonOut', (msg) => {
60
+ options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
61
61
  this.sendPGN(msg)
62
62
  })
63
63
 
@@ -133,7 +133,7 @@ Ydgw02Stream.prototype._transform = function (chunk, encoding, done) {
133
133
  const pgn = this.fromPgn.parseYDGW02(line)
134
134
  if ( !_.isUndefined(pgn) ) {
135
135
  this.push(pgn)
136
- this.options.app.emit('N2KAnalyzerOut', pgn)
136
+ this.options.app.emit(this.options.analyzerOutEvent || 'N2KAnalyzerOut', pgn)
137
137
  }
138
138
 
139
139
  done()
package/lib/ydvr.js CHANGED
@@ -108,6 +108,10 @@ function YdvrStream() {
108
108
 
109
109
  this.parser = new FromPgn();
110
110
 
111
+ this.messageCount = 0;
112
+ this.errorCount = 0;
113
+ this.timerResetCount = 0;
114
+
111
115
  this.parser.on('error', (pgn, error) => {
112
116
  console.error(`Error parsing ${pgn.pgn} ${error}`);
113
117
  console.error(error.stack);
@@ -141,7 +145,8 @@ YdvrStream.prototype.parseNextRecord = function () {
141
145
  let timeAbsolute;
142
146
  if (this.lastTime != null && time < this.lastTime) {
143
147
  this.timeOffset = (this.timeOffset || 0) + 60000;
144
- timeAbsolute = time + timeOffset;
148
+ timeAbsolute = time + this.timeOffset;
149
+ this.timerResetCount += 1;
145
150
  } else {
146
151
  timeAbsolute = time;
147
152
  }
@@ -150,6 +155,9 @@ YdvrStream.prototype.parseNextRecord = function () {
150
155
  var identifier = this.bs.readUint32();
151
156
  if (identifier === 0xffffffff) {
152
157
  // service record
158
+ if (this.bs.bitsLeft < 8 * 8) {
159
+ return false;
160
+ }
153
161
  var srData = this.bs.readArrayBuffer(8);
154
162
  } else {
155
163
  const pgn = parseCanId(identifier);
@@ -163,6 +171,9 @@ YdvrStream.prototype.parseNextRecord = function () {
163
171
  } else {
164
172
  bodyLen = 8;
165
173
  }
174
+ if (this.bs.bitsLeft < bodyLen * 8) {
175
+ return false;
176
+ }
166
177
  var body = this.bs.readArrayBuffer(bodyLen);
167
178
 
168
179
  const parsed = this.parser.parsePgnData(
@@ -177,6 +188,7 @@ YdvrStream.prototype.parseNextRecord = function () {
177
188
  }
178
189
  }
179
190
 
191
+ this.messageCount += 1;
180
192
  return true;
181
193
  }
182
194
 
@@ -192,7 +204,10 @@ YdvrStream.prototype._transform = function (chunk, encoding, done) {
192
204
  let parsed = false;
193
205
  try {
194
206
  parsed = this.parseNextRecord();
195
- } catch (ex) { }
207
+ } catch (ex) {
208
+ console.error(ex);
209
+ this.errorCount += 1;
210
+ }
196
211
  if (!parsed) {
197
212
  this.bs.byteIndex = startIndex;
198
213
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "1.26.2",
3
+ "version": "1.27.0",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {