@canboat/canboatjs 1.22.0 → 1.22.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/lib/fromPgn.js CHANGED
@@ -39,7 +39,7 @@ const maxUint64 = new Int64LE(0xffffffff, 0xffffffff)
39
39
  const maxInt64 = new Int64LE(0x7fffffff, 0xffffffff)
40
40
 
41
41
  const FORMAT_PLAIN = 0
42
- const FORMAT_FAST = 1
42
+ const FORMAT_COALESCED = 1
43
43
 
44
44
  const FASTPACKET_INDEX = 0
45
45
  const FASTPACKET_SIZE = 1
@@ -111,8 +111,8 @@ class Parser extends EventEmitter {
111
111
  }
112
112
 
113
113
  trace(`${pgn.pgn} ${len} ${pgnData.Length} ${pgnData.RepeatingFields} ${couldBeMulti}`)
114
- if ( coalesced || len > 0x8 || (this.format == FORMAT_FAST && !this.mixedFormat) ) {
115
- this.format = FORMAT_FAST
114
+ if ( coalesced || len > 0x8 || (this.format == FORMAT_COALESCED && !this.mixedFormat) ) {
115
+ this.format = FORMAT_COALESCED
116
116
  if ( sourceString ) {
117
117
  pgn.input = [ sourceString ]
118
118
  }
@@ -137,7 +137,6 @@ class Parser extends EventEmitter {
137
137
  var start = bs.byteIndex
138
138
  var packetIndex = bs.view.buffer.readUInt8(FASTPACKET_INDEX)
139
139
  var bucket = packetIndex & FASTPACKET_MAX_INDEX;
140
- var maybeBad = false
141
140
 
142
141
  trace(`${pgn.pgn} partial ${packetIndex} ${bucket} ${packet.size}`)
143
142
 
@@ -159,7 +158,8 @@ class Parser extends EventEmitter {
159
158
  debug(`PGN ${pgn.pgn} malformed packet for ${pgn.src} received; expected ${packet.lastPacket+1} but got ${packetIndex}`)
160
159
  cb && cb(`Could not parse ${JSON.stringify(pgn)}`)
161
160
  bs.byteIndex = start
162
- maybeBad = true
161
+ delete this.devices[pgn.src][pgn.pgn]
162
+ return
163
163
  } else {
164
164
  trace(`${pgn.pgn} targetStart: ${FASTPACKET_BUCKET_0_SIZE + FASTPACKET_BUCKET_N_SIZE * (bucket-1)} sourceStart: ${FASTPACKET_BUCKET_N_OFFSET} sourceEned: ${FASTPACKET_BUCKET_N_SIZE}`)
165
165
  bs.view.buffer.copy(
@@ -169,20 +169,18 @@ class Parser extends EventEmitter {
169
169
  )
170
170
  }
171
171
  }
172
- if ( !maybeBad ) {
173
- packet.lastPacket = packetIndex;
174
- if (FASTPACKET_BUCKET_0_SIZE + FASTPACKET_BUCKET_N_SIZE * bucket < packet.size)
175
- {
176
- // Packet is not complete yet
177
- trace(`${pgn.pgn} not complete`)
178
- return;
179
- }
180
- var view = new BitView(packet.buffer)
181
- bs = new BitStream(view)
182
- trace(`${pgn.pgn} done`)
183
- pgn.input = packet.src
184
- delete this.devices[pgn.src][pgn.pgn]
172
+ packet.lastPacket = packetIndex;
173
+ if (FASTPACKET_BUCKET_0_SIZE + FASTPACKET_BUCKET_N_SIZE * bucket < packet.size)
174
+ {
175
+ // Packet is not complete yet
176
+ trace(`${pgn.pgn} not complete`)
177
+ return;
185
178
  }
179
+ var view = new BitView(packet.buffer)
180
+ bs = new BitStream(view)
181
+ trace(`${pgn.pgn} done`)
182
+ pgn.input = packet.src
183
+ delete this.devices[pgn.src][pgn.pgn]
186
184
  } else if ( sourceString ) {
187
185
  pgn.input = [ sourceString ]
188
186
  }
@@ -667,7 +665,13 @@ function readVariableLengthField(options, pgn, field, bs) {
667
665
 
668
666
  if ( refField ) {
669
667
  var bits = (refField.BitLength + 7) & ~7; // Round # of bits in field refField up to complete bytes: 1->8, 7->8, 8->8 etc.
670
- return readField(options, false, pgn, refField, bs, bits)
668
+ let res = readField(options, false, pgn, refField, bs)
669
+
670
+ if ( bits > field.BitLength ) {
671
+ bs.readBits(bits - refField.BitLength, false)
672
+ }
673
+
674
+ return res
671
675
  }
672
676
  }
673
677
 
package/lib/ydgw02.js CHANGED
@@ -89,7 +89,7 @@ Ydgw02Stream.prototype.sendPGN = function (pgn) {
89
89
  Ydgw02Stream.prototype.sendYdgwPGN = function (msg) {
90
90
 
91
91
  actisenseToYdgwRawFormat(msg).forEach(raw => {
92
- this.sendString(raw)
92
+ this.sendString(raw + '\r\n')
93
93
  })
94
94
 
95
95
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "1.22.0",
3
+ "version": "1.22.1",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {