@canboat/canboatjs 1.27.0 → 1.27.2

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/serial.js CHANGED
@@ -108,6 +108,10 @@ SerialStream.prototype.start = function () {
108
108
  this.isFile = false
109
109
  this.state = MSG_START
110
110
 
111
+ if ( typeof this.reconnectDelay === 'undefined' ) {
112
+ this.reconnectDelay = 1000
113
+ }
114
+
111
115
  if ( !this.options.fromFile ) {
112
116
  this.serial = new SerialPort(this.options.device, {
113
117
  baudRate: this.options.baudrate || 115200
@@ -122,7 +126,9 @@ SerialStream.prototype.start = function () {
122
126
  ? (msg) => {
123
127
  this.options.app.setProviderError(this.options.providerId, msg)
124
128
  }
125
- : () => {}
129
+ : () => {}
130
+ this.setProviderStatus = setProviderStatus
131
+
126
132
  var that = this
127
133
 
128
134
  this.serial.on('data', (data) => {
@@ -175,15 +181,18 @@ SerialStream.prototype.start = function () {
175
181
  this.serial.on('error', function (x) {
176
182
  setProviderError(x.message)
177
183
  console.log(x)
184
+ that.scheduleReconnect()
178
185
  })
179
186
  this.serial.on('close', () => {
180
187
  setProviderError('Closed, reconnecting...')
181
- this.start.bind(this)
188
+ //this.start.bind(this)
189
+ that.scheduleReconnect()
182
190
  })
183
191
  this.serial.on(
184
192
  'open',
185
193
  function () {
186
194
  try {
195
+ this.reconnectDelay = 1000
187
196
  setProviderStatus(`Connected to ${that.options.device}`)
188
197
  var buf = composeMessage(NGT_MSG_SEND, Buffer.from(NGT_STARTUP_MSG), NGT_STARTUP_MSG.length)
189
198
  debugOut(buf)
@@ -211,6 +220,16 @@ SerialStream.prototype.start = function () {
211
220
  }
212
221
  }
213
222
 
223
+ SerialStream.prototype.scheduleReconnect = function () {
224
+ this.reconnectDelay *= this.reconnectDelay < 60 * 1000 ? 1.5 : 1
225
+ const msg = `Not connected (retry delay ${(
226
+ this.reconnectDelay / 1000
227
+ ).toFixed(0)} s)`
228
+ debug(msg)
229
+ this.setProviderStatus(msg)
230
+ setTimeout(this.start.bind(this), this.reconnectDelay)
231
+ }
232
+
214
233
  function readData(that, data) {
215
234
  for ( var i = 0; i < data.length; i++ ) {
216
235
  //console.log(data[i])
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "1.27.0",
3
+ "version": "1.27.2",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {