@canboat/canboatjs 1.26.3 → 1.27.1

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/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/stringMsg.js CHANGED
@@ -59,7 +59,7 @@ exports.encodeActisense = ({
59
59
  byteString(data)
60
60
  ].join(','))
61
61
 
62
- exports.toActisenseSerialFormat = (pgn, data, dst=255, src=0) => exports.encodeActisense({
62
+ exports.toActisenseSerialFormat = (pgn, data, dst=255, src=0, prio=2) => exports.encodeActisense({
63
63
  pgn, data, dst, src, prio
64
64
  })
65
65
 
package/lib/toPgn.js CHANGED
@@ -154,7 +154,7 @@ function writeField(bs, pgn_number, field, data, value, bitLength) {
154
154
  }
155
155
 
156
156
  // console.log(`${field.Name}:${value}(${bitLength}-${field.Resolution})`)
157
- if ( _.isUndefined(value) ) {
157
+ if ( _.isUndefined(value) || value === null) {
158
158
  if ( field.Type && fieldTypeWriters[field.Type] ) {
159
159
  fieldTypeWriters[field.Type](pgn_number, field, value, bs)
160
160
  } else if ( bitLength % 8 == 0 ) {
@@ -223,7 +223,7 @@ function writeField(bs, pgn_number, field, data, value, bitLength) {
223
223
  if (field.Signed) {
224
224
  bs.writeInt32(value)
225
225
  } else {
226
- bs.writeUint32(value)
226
+ bs.writeUint32(value)
227
227
  }
228
228
  } else if (bitLength === 48 || bitLength == 24) {
229
229
  var count = bitLength/8;
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.3",
3
+ "version": "1.27.1",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {