@canboat/canboatjs 3.1.0 → 3.2.3

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.
Files changed (62) hide show
  1. package/.github/workflows/publish.yml +18 -9
  2. package/README.md +3 -7
  3. package/dist/actisense-serial.d.ts.map +1 -1
  4. package/dist/actisense-serial.js +39 -39
  5. package/dist/actisense-serial.js.map +1 -1
  6. package/dist/bin/actisense-file.js +0 -0
  7. package/dist/bin/actisense-n2k-tcp.js +0 -0
  8. package/dist/bin/actisense-serialjs.js +0 -0
  9. package/dist/bin/analyzerjs.js +0 -0
  10. package/dist/bin/candumpjs.js +0 -0
  11. package/dist/bin/cansend.js +0 -0
  12. package/dist/bin/ikonvert-serial.js +0 -0
  13. package/dist/bin/to-pgn.js +0 -0
  14. package/dist/canbus.d.ts.map +1 -1
  15. package/dist/canbus.js +5 -5
  16. package/dist/canbus.js.map +1 -1
  17. package/dist/candevice.d.ts.map +1 -1
  18. package/dist/candevice.js +2 -4
  19. package/dist/candevice.js.map +1 -1
  20. package/dist/ikonvert.d.ts.map +1 -1
  21. package/dist/ikonvert.js +10 -10
  22. package/dist/ikonvert.js.map +1 -1
  23. package/dist/n2kDevice.d.ts +5 -1
  24. package/dist/n2kDevice.d.ts.map +1 -1
  25. package/dist/n2kDevice.js +88 -36
  26. package/dist/n2kDevice.js.map +1 -1
  27. package/dist/utilities.d.ts +3 -1
  28. package/dist/utilities.d.ts.map +1 -1
  29. package/dist/utilities.js +50 -3
  30. package/dist/utilities.js.map +1 -1
  31. package/dist/w2k01.d.ts.map +1 -1
  32. package/dist/w2k01.js +7 -7
  33. package/dist/w2k01.js.map +1 -1
  34. package/dist/yddevice.d.ts.map +1 -1
  35. package/dist/yddevice.js +2 -4
  36. package/dist/yddevice.js.map +1 -1
  37. package/dist/ydgw02.d.ts.map +1 -1
  38. package/dist/ydgw02.js +5 -5
  39. package/dist/ydgw02.js.map +1 -1
  40. package/lib/actisense-serial.ts +40 -40
  41. package/lib/canbus.ts +6 -6
  42. package/lib/candevice.ts +2 -5
  43. package/lib/ikonvert.ts +11 -11
  44. package/lib/n2kDevice.ts +102 -37
  45. package/lib/utilities.ts +50 -3
  46. package/lib/w2k01.ts +8 -8
  47. package/lib/yddevice.ts +2 -5
  48. package/lib/ydgw02.ts +5 -6
  49. package/package.json +1 -1
  50. package/tsconfig.tsbuildinfo +1 -1
  51. package/CHANGELOG.md +0 -101
  52. package/dist/bin/candumpanalyzerjs.d.ts +0 -3
  53. package/dist/bin/candumpanalyzerjs.d.ts.map +0 -1
  54. package/dist/bin/candumpanalyzerjs.js +0 -31
  55. package/dist/bin/candumpanalyzerjs.js.map +0 -1
  56. package/dist/ncanbus.d.ts +0 -17
  57. package/dist/ncanbus.d.ts.map +0 -1
  58. package/dist/ncanbus.js +0 -92
  59. package/dist/ncanbus.js.map +0 -1
  60. package/ios_canboat.js/main.js +0 -2
  61. package/ios_canboat.js/main.js.LICENSE.txt +0 -17
  62. package/ios_canboat.js/main.js.map +0 -1
package/lib/n2kDevice.ts CHANGED
@@ -18,13 +18,17 @@ import {
18
18
  PGN,
19
19
  PGN_60928,
20
20
  PGN_59904,
21
+ PGN_59904Defaults,
21
22
  PGN_126208,
22
23
  PGN_126208_Acknowledge,
24
+ PGN_126208_AcknowledgeDefaults,
23
25
  PGN_126208_Command,
24
26
  PGN_126996,
25
27
  PGN_126993,
26
28
  PGN_59392,
29
+ PGN_59392Defaults,
27
30
  PGN_126464,
31
+ PGN_126464Defaults,
28
32
  PgnListFunction,
29
33
  GroupFunction,
30
34
  PgnErrorCode,
@@ -32,15 +36,14 @@ import {
32
36
  ControllerState,
33
37
  IsoControl
34
38
  } from '@canboat/ts-pgns'
35
- import { createDebug } from './utilities'
36
39
  import { EventEmitter } from 'node:events'
37
40
  import _ from 'lodash'
38
41
  import { Uint64LE } from 'int64-buffer'
39
42
  import { defaultTransmitPGNs } from './codes'
40
43
  import { toPgn } from './toPgn'
41
44
  import packageJson from '../package.json'
42
-
43
- const debug = createDebug('canboatjs:n2kdevice')
45
+ import { getPersistedData, savePersistedData } from './utilities'
46
+ import { createDebug } from './utilities'
44
47
 
45
48
  const deviceTransmitPGNs = [60928, 59904, 126996, 126464]
46
49
 
@@ -60,10 +63,25 @@ export class N2kDevice extends EventEmitter {
60
63
  addressClaimSentAt?: number
61
64
  addressClaimChecker?: any
62
65
  heartbeatInterval?: any
66
+ debug: any
63
67
 
64
- constructor(options: any) {
68
+ constructor(options: any, debugName: string) {
65
69
  super()
66
70
 
71
+ this.options = options === undefined ? {} : options
72
+ this.debug = createDebug(debugName, options)
73
+
74
+ let uniqueNumber: number
75
+ if (options.uniqueNumber !== undefined) {
76
+ uniqueNumber = options.uniqueNumber
77
+ } else {
78
+ uniqueNumber = this.getPersistedData('uniqueNumber')
79
+ if (uniqueNumber === undefined) {
80
+ uniqueNumber = Math.floor(Math.random() * Math.floor(2097151))
81
+ this.savePersistedData('uniqueNumber', uniqueNumber)
82
+ }
83
+ }
84
+
67
85
  if (options.addressClaim) {
68
86
  this.addressClaim = options.addressClaim
69
87
  this.addressClaim.pgn = 60928
@@ -74,7 +92,6 @@ export class N2kDevice extends EventEmitter {
74
92
  pgn: 60928,
75
93
  dst: 255,
76
94
  prio: 6,
77
- 'Unique Number': 1263,
78
95
  'Manufacturer Code': 999,
79
96
  'Device Function': 130, // PC gateway
80
97
  'Device Class': 25, // Inter/Intranetwork Device
@@ -85,8 +102,8 @@ export class N2kDevice extends EventEmitter {
85
102
  Reserved1: 1,
86
103
  Reserved2: 2
87
104
  }
88
- this.addressClaim['Unique Number'] =
89
- options.uniqueNumber || Math.floor(Math.random() * Math.floor(2097151))
105
+
106
+ this.addressClaim['Unique Number'] = uniqueNumber
90
107
  }
91
108
 
92
109
  const version = packageJson ? packageJson.version : '1.0'
@@ -102,10 +119,8 @@ export class N2kDevice extends EventEmitter {
102
119
  'NMEA 2000 Version': 1300,
103
120
  'Product Code': 667, // Just made up..
104
121
  'Model ID': 'Signal K',
105
- 'Model Version': 'canboatjs',
106
- 'Model Serial Code': options.uniqueNumber
107
- ? options.uniqueNumber.toString()
108
- : '000001',
122
+ 'Model Version': getModelVersion(options),
123
+ 'Model Serial Code': uniqueNumber.toString(),
109
124
  'Certification Level': 0,
110
125
  'Load Equivalency': 1
111
126
  }
@@ -123,11 +138,16 @@ export class N2kDevice extends EventEmitter {
123
138
  }
124
139
  }
125
140
 
126
- this.options = _.isUndefined(options) ? {} : options
141
+ let address: number | undefined = undefined
142
+
143
+ address = this.getPersistedData('lastAddress')
127
144
 
128
- this.address = _.isUndefined(options.preferredAddress)
129
- ? 100
130
- : options.preferredAddress
145
+ if (address === undefined) {
146
+ address = _.isUndefined(options.preferredAddress)
147
+ ? 100
148
+ : options.preferredAddress
149
+ }
150
+ this.address = address!
131
151
  this.cansend = false
132
152
  this.foundConflict = false
133
153
  this.heartbeatCounter = 0
@@ -156,12 +176,39 @@ export class N2kDevice extends EventEmitter {
156
176
  }, 1000)
157
177
  }
158
178
 
179
+ getPersistedData(key: string) {
180
+ try {
181
+ return getPersistedData(this.options, this.options.providerId, key)
182
+ } catch (err: any) {
183
+ this.debug('reading persisted data %o', err)
184
+ if (err.code !== 'ENOENT') {
185
+ console.error(err)
186
+ this.setError(err.message)
187
+ }
188
+ }
189
+ }
190
+
191
+ savePersistedData(key: string, value: any) {
192
+ try {
193
+ savePersistedData(this.options, this.options.providerId, key, value)
194
+ } catch (err: any) {
195
+ console.error(err)
196
+ this.setError(err.message)
197
+ }
198
+ }
199
+
159
200
  setStatus(msg: string) {
160
201
  if (this.options.app && this.options.app.setPluginStatus) {
161
202
  this.options.app.setProviderStatus(this.options.providerId, msg)
162
203
  }
163
204
  }
164
205
 
206
+ setError(msg: string) {
207
+ if (this.options.app && this.options.app.setPluginStatus) {
208
+ this.options.app.setProviderError(this.options.providerId, msg)
209
+ }
210
+ }
211
+
165
212
  n2kMessage(pgn: PGN) {
166
213
  if (pgn.dst == 255 || pgn.dst == this.address) {
167
214
  try {
@@ -193,8 +240,16 @@ export class N2kDevice extends EventEmitter {
193
240
  sendPGN(_pgn: PGN, _src: number | undefined = undefined) {}
194
241
  }
195
242
 
243
+ function getModelVersion(options: any) {
244
+ if (options.app?.config?.getExternalHostname !== undefined) {
245
+ return `${options.app.config.ssl ? 'https' : 'http'}://${options.app.config.getExternalHostname()}:${options.app.config.getExternalPort()}`
246
+ } else {
247
+ return 'canboatjs'
248
+ }
249
+ }
250
+
196
251
  function handleISORequest(device: N2kDevice, n2kMsg: PGN_59904) {
197
- debug('handleISORequest %j', n2kMsg)
252
+ device.debug('handleISORequest %j', n2kMsg)
198
253
 
199
254
  const PGN = Number(n2kMsg.fields.pgn)
200
255
 
@@ -206,7 +261,7 @@ function handleISORequest(device: N2kDevice, n2kMsg: PGN_59904) {
206
261
  sendConfigInformation(device)
207
262
  break
208
263
  case 60928: // ISO address claim request
209
- debug('sending address claim %j', device.addressClaim)
264
+ device.debug('sending address claim %j', device.addressClaim)
210
265
  device.sendPGN(device.addressClaim as PGN)
211
266
  break
212
267
  case 126464:
@@ -214,21 +269,21 @@ function handleISORequest(device: N2kDevice, n2kMsg: PGN_59904) {
214
269
  break
215
270
  default:
216
271
  if (!device.options.disableNAKs) {
217
- debug(`Got unsupported ISO request for PGN ${PGN}. Sending NAK.`)
272
+ device.debug(`Got unsupported ISO request for PGN ${PGN}. Sending NAK.`)
218
273
  sendNAKAcknowledgement(device, n2kMsg.src!, PGN)
219
274
  }
220
275
  }
221
276
  }
222
277
 
223
278
  function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
224
- debug('handleGroupFunction %j', n2kMsg)
279
+ device.debug('handleGroupFunction %j', n2kMsg)
225
280
  const functionCode = n2kMsg.fields.functionCode
226
281
  if (functionCode === 'Request') {
227
282
  handleRequestGroupFunction(device, n2kMsg)
228
283
  } else if (functionCode === 'Command') {
229
284
  handleCommandGroupFunction(device, n2kMsg)
230
285
  } else {
231
- debug('Got unsupported Group Function PGN: %j', n2kMsg)
286
+ device.debug('Got unsupported Group Function PGN: %j', n2kMsg)
232
287
  }
233
288
 
234
289
  function handleRequestGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
@@ -237,13 +292,13 @@ function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
237
292
 
238
293
  const PGN = n2kMsg.fields.pgn
239
294
 
240
- debug(
295
+ device.debug(
241
296
  "Sending 'PGN Not Supported' Group Function response for requested PGN",
242
297
  PGN
243
298
  )
244
299
 
245
300
  const acknowledgement: PGN_126208_Acknowledge = {
246
- pgn: 126208,
301
+ ...PGN_126208_AcknowledgeDefaults,
247
302
  dst: n2kMsg.src!,
248
303
  fields: {
249
304
  functionCode: GroupFunction.Acknowledge,
@@ -268,13 +323,13 @@ function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
268
323
 
269
324
  const PGN = n2kMsg.fields.pgn
270
325
 
271
- debug(
326
+ device.debug(
272
327
  "Sending 'PGN Not Supported' Group Function response for commanded PGN",
273
328
  PGN
274
329
  )
275
330
 
276
331
  const acknowledgement: PGN_126208_Acknowledge = {
277
- pgn: 126208,
332
+ ...PGN_126208_AcknowledgeDefaults,
278
333
  dst: n2kMsg.src!,
279
334
  fields: {
280
335
  functionCode: GroupFunction.Acknowledge,
@@ -294,7 +349,7 @@ function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
294
349
  function handleISOAddressClaim(device: N2kDevice, n2kMsg: PGN_60928) {
295
350
  if (n2kMsg.src != device.address) {
296
351
  if (!device.devices[n2kMsg.src!]) {
297
- debug(`registering device ${n2kMsg.src}`)
352
+ device.debug(`registering device ${n2kMsg.src}`)
298
353
  device.devices[n2kMsg.src!] = { addressClaim: n2kMsg }
299
354
  if (device.cansend) {
300
355
  //sendISORequest(device, 126996, undefined, n2kMsg.src)
@@ -303,7 +358,7 @@ function handleISOAddressClaim(device: N2kDevice, n2kMsg: PGN_60928) {
303
358
  return
304
359
  }
305
360
 
306
- debug('Checking ISO address claim. %j', n2kMsg)
361
+ device.debug('Checking ISO address claim. %j', n2kMsg)
307
362
 
308
363
  const uint64ValueFromReceivedClaim = getISOAddressClaimAsUint64(n2kMsg)
309
364
  const uint64ValueFromOurOwnClaim = getISOAddressClaimAsUint64(
@@ -311,12 +366,16 @@ function handleISOAddressClaim(device: N2kDevice, n2kMsg: PGN_60928) {
311
366
  )
312
367
 
313
368
  if (uint64ValueFromOurOwnClaim < uint64ValueFromReceivedClaim) {
314
- debug(`Address conflict detected! Kept our address as ${device.address}.`)
369
+ device.debug(
370
+ `Address conflict detected! Kept our address as ${device.address}.`
371
+ )
315
372
  sendAddressClaim(device) // We have smaller address claim data -> we can keep our address -> re-claim it
316
373
  } else if (uint64ValueFromOurOwnClaim > uint64ValueFromReceivedClaim) {
317
374
  device.foundConflict = true
318
375
  increaseOwnAddress(device) // We have bigger address claim data -> we have to change our address
319
- debug(`Address conflict detected! trying address ${device.address}.`)
376
+ device.debug(
377
+ `Address conflict detected! trying address ${device.address}.`
378
+ )
320
379
  sendAddressClaim(device)
321
380
  }
322
381
  }
@@ -332,7 +391,7 @@ function handleProductInformation(device: N2kDevice, n2kMsg: PGN_126996) {
332
391
  if (!device.devices[n2kMsg.src!]) {
333
392
  device.devices[n2kMsg.src!] = {}
334
393
  }
335
- debug('got product information %j', n2kMsg)
394
+ device.debug('got product information %j', n2kMsg)
336
395
  device.devices[n2kMsg.src!].productInformation = n2kMsg
337
396
  }
338
397
 
@@ -361,7 +420,7 @@ function sendAddressClaim(device: N2kDevice) {
361
420
  //someone already has this address, so find a free one
362
421
  increaseOwnAddress(device)
363
422
  }
364
- debug(`Sending address claim ${device.address}`)
423
+ device.debug(`Sending address claim ${device.address}`)
365
424
  device.sendPGN(device.addressClaim)
366
425
  device.setStatus(`Claimed address ${device.address}`)
367
426
  device.addressClaimSentAt = Date.now()
@@ -372,7 +431,10 @@ function sendAddressClaim(device: N2kDevice) {
372
431
  device.addressClaimChecker = setTimeout(() => {
373
432
  //if ( Date.now() - device.addressClaimSentAt > 1000 ) {
374
433
  //device.addressClaimChecker = null
375
- debug('claimed address %d', device.address)
434
+ device.debug('claimed address %d', device.address)
435
+
436
+ device.savePersistedData('lastAddress', device.address)
437
+
376
438
  device.cansend = true
377
439
  if (!device.sentAvailable) {
378
440
  if (device.options.app) {
@@ -397,9 +459,10 @@ function sendISORequest(
397
459
  src: number | undefined = undefined,
398
460
  dst = 255
399
461
  ) {
400
- debug(`Sending iso request for ${pgn} to ${dst}`)
462
+ device.debug(`Sending iso request for ${pgn} to ${dst}`)
401
463
 
402
464
  const isoRequest: PGN_59904 = {
465
+ ...PGN_59904Defaults,
403
466
  pgn: 59904,
404
467
  dst: dst,
405
468
  fields: {
@@ -410,14 +473,14 @@ function sendISORequest(
410
473
  }
411
474
 
412
475
  function sendProductInformation(device: N2kDevice) {
413
- debug('Sending product info %j', device.productInfo)
476
+ device.debug('Sending product info %j', device.productInfo)
414
477
 
415
478
  device.sendPGN(device.productInfo)
416
479
  }
417
480
 
418
481
  function sendConfigInformation(device: N2kDevice) {
419
482
  if (device.configurationInfo) {
420
- debug('Sending config info..')
483
+ device.debug('Sending config info..')
421
484
  device.sendPGN(device.configurationInfo)
422
485
  }
423
486
  }
@@ -428,7 +491,7 @@ function sendNAKAcknowledgement(
428
491
  requestedPGN: number
429
492
  ) {
430
493
  const acknowledgement: PGN_59392 = {
431
- pgn: 59392,
494
+ ...PGN_59392Defaults,
432
495
  dst: src,
433
496
  fields: {
434
497
  control: IsoControl.Ack,
@@ -443,11 +506,13 @@ function sendPGNList(device: N2kDevice, dst: number) {
443
506
  //FIXME: for now, adding everything that signalk-to-nmea2000 supports
444
507
  //need a way for plugins, etc. to register the pgns they provide
445
508
  const pgnList: PGN_126464 = {
446
- pgn: 126464,
509
+ ...PGN_126464Defaults,
447
510
  dst,
448
511
  fields: {
449
512
  functionCode: PgnListFunction.TransmitPgnList,
450
- list: device.transmitPGNs
513
+ list: device.transmitPGNs.map((num: number) => {
514
+ return { pgn: num }
515
+ })
451
516
  }
452
517
  }
453
518
  device.sendPGN(pgnList)
package/lib/utilities.ts CHANGED
@@ -15,12 +15,59 @@
15
15
  */
16
16
 
17
17
  import { debug } from 'debug'
18
-
19
18
  import { CanID } from './canId'
20
19
  import { map, padCharsStart, trimChars } from 'lodash/fp'
20
+ import fs from 'fs'
21
+
22
+ const getDataPath = (options: any) => {
23
+ if (options.app?.config?.configPath !== undefined) {
24
+ return `${options.app.config.configPath}/canboatjs-data.json`
25
+ }
26
+ }
27
+
28
+ export const getPersistedData = (options: any, id: string, key: string) => {
29
+ const path = getDataPath(options)
30
+ if (path !== undefined) {
31
+ const content = fs.readFileSync(path)
32
+ const data = JSON.parse(content.toString())
33
+ return data[id] !== undefined && data[id][key]
34
+ }
35
+ }
36
+
37
+ export const savePersistedData = (
38
+ options: any,
39
+ id: string,
40
+ key: string,
41
+ value: any
42
+ ) => {
43
+ const path = getDataPath(options)
44
+ if (path !== undefined) {
45
+ let content: string
21
46
 
22
- export const createDebug = (name: string) => {
23
- return debug(name)
47
+ try {
48
+ content = fs.readFileSync(path).toString()
49
+ } catch (err: any) {
50
+ if (err.code === 'ENOENT') {
51
+ content = '{}'
52
+ } else {
53
+ throw err
54
+ }
55
+ }
56
+ const data = JSON.parse(content.toString())
57
+ if (data[id] === undefined) {
58
+ data[id] = {}
59
+ }
60
+ data[id][key] = value
61
+ fs.writeFileSync(path, JSON.stringify(data, null, 2))
62
+ }
63
+ }
64
+
65
+ export const createDebug = (name: string, appOptions: any = undefined) => {
66
+ if (appOptions !== undefined && appOptions.createDebug !== undefined) {
67
+ return appOptions.createDebug(name)
68
+ } else {
69
+ return debug(name)
70
+ }
24
71
  }
25
72
 
26
73
  export function getPlainPGNs(buffer: Buffer) {
package/lib/w2k01.ts CHANGED
@@ -26,9 +26,6 @@ import {
26
26
  import { readN2KActisense } from './n2k-actisense'
27
27
  import util from 'util'
28
28
 
29
- const debug = createDebug('canboatjs:w2k01')
30
- const debugData = createDebug('canboatjs:w2k01-data')
31
-
32
29
  //const pgnsSent = {}
33
30
 
34
31
  const N2K_ASCII = 0
@@ -48,6 +45,9 @@ export function W2K01Stream(
48
45
  objectMode: true
49
46
  })
50
47
 
48
+ this.debug = createDebug('canboatjs:w2k01', options)
49
+ this.debugData = createDebug('canboatjs:w2k01-data', options)
50
+
51
51
  this.sentAvailable = false
52
52
  this.options = options
53
53
  this.outEvent = outEvent || 'w2k-1-out'
@@ -72,11 +72,11 @@ export function W2K01Stream(
72
72
  }
73
73
  }
74
74
 
75
- debug('started')
75
+ this.debug('started')
76
76
  }
77
77
 
78
78
  W2K01Stream.prototype.send = function (msg: string | Buffer) {
79
- debug('sending %s', msg)
79
+ this.debug('sending %s', msg)
80
80
  this.options.app.emit(this.outEvent, msg)
81
81
  }
82
82
 
@@ -111,14 +111,14 @@ W2K01Stream.prototype._transform = function (
111
111
  done: any
112
112
  ) {
113
113
  if (!this.sentAvailable && this.format === N2K_ASCII) {
114
- debug('emit nmea2000OutAvailable')
114
+ this.debug('emit nmea2000OutAvailable')
115
115
  this.options.app.emit('nmea2000OutAvailable')
116
116
  this.sentAvailable = true
117
117
  }
118
118
 
119
119
  if (this.format === N2K_ASCII) {
120
- if (debugData.enabled) {
121
- debugData('Received: ' + chunk)
120
+ if (this.debugData.enabled) {
121
+ this.debugData('Received: ' + chunk)
122
122
  }
123
123
  this.push(chunk)
124
124
  } else {
package/lib/yddevice.ts CHANGED
@@ -17,16 +17,13 @@
17
17
  import { PGN } from '@canboat/ts-pgns'
18
18
  import { N2kDevice } from './n2kDevice'
19
19
  import { actisenseToYdgwFullRawFormat } from './toPgn'
20
- import { createDebug } from './utilities'
21
-
22
- const debug = createDebug('canboatjs:n2kdevice')
23
20
 
24
21
  export class YdDevice extends N2kDevice {
25
22
  app: any
26
23
  n2kOutEvent: string
27
24
 
28
25
  constructor(options: any) {
29
- super(options)
26
+ super(options, 'canboatjs:yddevice')
30
27
  this.app = options.app
31
28
  this.n2kOutEvent = options.jsonOutEvent || 'nmea2000JsonOut'
32
29
 
@@ -41,7 +38,7 @@ export class YdDevice extends N2kDevice {
41
38
  const ppgn = pgn as any //FIXME??
42
39
  ppgn.ydFullFormat = true
43
40
 
44
- debug('Sending PGN %j', pgn)
41
+ this.debug('Sending PGN %j', pgn)
45
42
  this.app.emit(this.n2kOutEvent, pgn)
46
43
  }
47
44
 
package/lib/ydgw02.ts CHANGED
@@ -27,8 +27,6 @@ import {
27
27
  } from './toPgn'
28
28
  import util from 'util'
29
29
 
30
- const debug = createDebug('canboatjs:ydgw02')
31
-
32
30
  //const pgnsSent = {}
33
31
 
34
32
  export function Ydgw02Stream(this: any, options: any, type: string) {
@@ -40,6 +38,7 @@ export function Ydgw02Stream(this: any, options: any, type: string) {
40
38
  objectMode: true
41
39
  })
42
40
 
41
+ this.debug = createDebug('canboatjs:ydgw02', options)
43
42
  this.sentAvailable = false
44
43
  this.options = options
45
44
  this.outEvent = options.ydgwOutEvent || 'ydwg02-out'
@@ -52,7 +51,7 @@ export function Ydgw02Stream(this: any, options: any, type: string) {
52
51
  })
53
52
 
54
53
  this.fromPgn.on('error', (pgn: PGN, error: any) => {
55
- debug(`[error] ${pgn.pgn} ${error}`)
54
+ this.debug(`[error] ${pgn.pgn} ${error}`)
56
55
  })
57
56
 
58
57
  if (options.app) {
@@ -87,7 +86,7 @@ export function Ydgw02Stream(this: any, options: any, type: string) {
87
86
  this.device.start()
88
87
  }
89
88
 
90
- debug('started')
89
+ this.debug('started')
91
90
  }
92
91
  }
93
92
 
@@ -97,7 +96,7 @@ Ydgw02Stream.prototype.cansend = function (_msg: any) {
97
96
 
98
97
  Ydgw02Stream.prototype.sendString = function (msg: string, forceSend: boolean) {
99
98
  if (this.cansend() || forceSend === true) {
100
- debug('sending %s', msg)
99
+ this.debug('sending %s', msg)
101
100
  this.options.app.emit(this.outEvent, msg)
102
101
  }
103
102
  }
@@ -176,7 +175,7 @@ Ydgw02Stream.prototype._transform = function (
176
175
  //line = line.substring(0, line.length) // take off the \r
177
176
 
178
177
  if (this.device === undefined && !this.sentAvailable) {
179
- debug('emit nmea2000OutAvailable')
178
+ this.debug('emit nmea2000OutAvailable')
180
179
  this.options.app.emit('nmea2000OutAvailable')
181
180
  this.sentAvailable = true
182
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "3.1.0",
3
+ "version": "3.2.3",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",