@canboat/canboatjs 3.1.0 → 3.2.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/.github/workflows/publish.yml +18 -9
- package/README.md +3 -7
- package/dist/actisense-serial.d.ts.map +1 -1
- package/dist/actisense-serial.js +39 -39
- package/dist/actisense-serial.js.map +1 -1
- package/dist/bin/actisense-file.js +0 -0
- package/dist/bin/actisense-n2k-tcp.js +0 -0
- package/dist/bin/actisense-serialjs.js +0 -0
- package/dist/bin/analyzerjs.js +0 -0
- package/dist/bin/candumpjs.js +0 -0
- package/dist/bin/cansend.js +0 -0
- package/dist/bin/ikonvert-serial.js +0 -0
- package/dist/bin/to-pgn.js +0 -0
- package/dist/canbus.d.ts.map +1 -1
- package/dist/canbus.js +5 -5
- package/dist/canbus.js.map +1 -1
- package/dist/candevice.d.ts.map +1 -1
- package/dist/candevice.js +2 -4
- package/dist/candevice.js.map +1 -1
- package/dist/ikonvert.d.ts.map +1 -1
- package/dist/ikonvert.js +10 -10
- package/dist/ikonvert.js.map +1 -1
- package/dist/n2kDevice.d.ts +5 -1
- package/dist/n2kDevice.d.ts.map +1 -1
- package/dist/n2kDevice.js +80 -31
- package/dist/n2kDevice.js.map +1 -1
- package/dist/utilities.d.ts +3 -1
- package/dist/utilities.d.ts.map +1 -1
- package/dist/utilities.js +50 -3
- package/dist/utilities.js.map +1 -1
- package/dist/w2k01.d.ts.map +1 -1
- package/dist/w2k01.js +7 -7
- package/dist/w2k01.js.map +1 -1
- package/dist/yddevice.d.ts.map +1 -1
- package/dist/yddevice.js +2 -4
- package/dist/yddevice.js.map +1 -1
- package/dist/ydgw02.d.ts.map +1 -1
- package/dist/ydgw02.js +5 -5
- package/dist/ydgw02.js.map +1 -1
- package/lib/actisense-serial.ts +40 -40
- package/lib/canbus.ts +6 -6
- package/lib/candevice.ts +2 -5
- package/lib/ikonvert.ts +11 -11
- package/lib/n2kDevice.ts +90 -32
- package/lib/utilities.ts +50 -3
- package/lib/w2k01.ts +8 -8
- package/lib/yddevice.ts +2 -5
- package/lib/ydgw02.ts +5 -6
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +0 -101
- package/dist/bin/candumpanalyzerjs.d.ts +0 -3
- package/dist/bin/candumpanalyzerjs.d.ts.map +0 -1
- package/dist/bin/candumpanalyzerjs.js +0 -31
- package/dist/bin/candumpanalyzerjs.js.map +0 -1
- package/dist/ncanbus.d.ts +0 -17
- package/dist/ncanbus.d.ts.map +0 -1
- package/dist/ncanbus.js +0 -92
- package/dist/ncanbus.js.map +0 -1
- package/ios_canboat.js/main.js +0 -2
- package/ios_canboat.js/main.js.LICENSE.txt +0 -17
- package/ios_canboat.js/main.js.map +0 -1
package/lib/n2kDevice.ts
CHANGED
|
@@ -32,15 +32,14 @@ import {
|
|
|
32
32
|
ControllerState,
|
|
33
33
|
IsoControl
|
|
34
34
|
} from '@canboat/ts-pgns'
|
|
35
|
-
import { createDebug } from './utilities'
|
|
36
35
|
import { EventEmitter } from 'node:events'
|
|
37
36
|
import _ from 'lodash'
|
|
38
37
|
import { Uint64LE } from 'int64-buffer'
|
|
39
38
|
import { defaultTransmitPGNs } from './codes'
|
|
40
39
|
import { toPgn } from './toPgn'
|
|
41
40
|
import packageJson from '../package.json'
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
import { getPersistedData, savePersistedData } from './utilities'
|
|
42
|
+
import { createDebug } from './utilities'
|
|
44
43
|
|
|
45
44
|
const deviceTransmitPGNs = [60928, 59904, 126996, 126464]
|
|
46
45
|
|
|
@@ -60,10 +59,25 @@ export class N2kDevice extends EventEmitter {
|
|
|
60
59
|
addressClaimSentAt?: number
|
|
61
60
|
addressClaimChecker?: any
|
|
62
61
|
heartbeatInterval?: any
|
|
62
|
+
debug: any
|
|
63
63
|
|
|
64
|
-
constructor(options: any) {
|
|
64
|
+
constructor(options: any, debugName: string) {
|
|
65
65
|
super()
|
|
66
66
|
|
|
67
|
+
this.options = options === undefined ? {} : options
|
|
68
|
+
this.debug = createDebug(debugName, options)
|
|
69
|
+
|
|
70
|
+
let uniqueNumber: number
|
|
71
|
+
if (options.uniqueNumber !== undefined) {
|
|
72
|
+
uniqueNumber = options.uniqueNumber
|
|
73
|
+
} else {
|
|
74
|
+
uniqueNumber = this.getPersistedData('uniqueNumber')
|
|
75
|
+
if (uniqueNumber === undefined) {
|
|
76
|
+
uniqueNumber = Math.floor(Math.random() * Math.floor(2097151))
|
|
77
|
+
this.savePersistedData('uniqueNumber', uniqueNumber)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
if (options.addressClaim) {
|
|
68
82
|
this.addressClaim = options.addressClaim
|
|
69
83
|
this.addressClaim.pgn = 60928
|
|
@@ -74,7 +88,6 @@ export class N2kDevice extends EventEmitter {
|
|
|
74
88
|
pgn: 60928,
|
|
75
89
|
dst: 255,
|
|
76
90
|
prio: 6,
|
|
77
|
-
'Unique Number': 1263,
|
|
78
91
|
'Manufacturer Code': 999,
|
|
79
92
|
'Device Function': 130, // PC gateway
|
|
80
93
|
'Device Class': 25, // Inter/Intranetwork Device
|
|
@@ -85,8 +98,8 @@ export class N2kDevice extends EventEmitter {
|
|
|
85
98
|
Reserved1: 1,
|
|
86
99
|
Reserved2: 2
|
|
87
100
|
}
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
|
|
102
|
+
this.addressClaim['Unique Number'] = uniqueNumber
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
const version = packageJson ? packageJson.version : '1.0'
|
|
@@ -102,10 +115,8 @@ export class N2kDevice extends EventEmitter {
|
|
|
102
115
|
'NMEA 2000 Version': 1300,
|
|
103
116
|
'Product Code': 667, // Just made up..
|
|
104
117
|
'Model ID': 'Signal K',
|
|
105
|
-
'Model Version':
|
|
106
|
-
'Model Serial Code':
|
|
107
|
-
? options.uniqueNumber.toString()
|
|
108
|
-
: '000001',
|
|
118
|
+
'Model Version': getModelVersion(options),
|
|
119
|
+
'Model Serial Code': uniqueNumber.toString(),
|
|
109
120
|
'Certification Level': 0,
|
|
110
121
|
'Load Equivalency': 1
|
|
111
122
|
}
|
|
@@ -123,11 +134,16 @@ export class N2kDevice extends EventEmitter {
|
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
|
|
126
|
-
|
|
137
|
+
let address: number | undefined = undefined
|
|
138
|
+
|
|
139
|
+
address = this.getPersistedData('lastAddress')
|
|
127
140
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
if (address === undefined) {
|
|
142
|
+
address = _.isUndefined(options.preferredAddress)
|
|
143
|
+
? 100
|
|
144
|
+
: options.preferredAddress
|
|
145
|
+
}
|
|
146
|
+
this.address = address!
|
|
131
147
|
this.cansend = false
|
|
132
148
|
this.foundConflict = false
|
|
133
149
|
this.heartbeatCounter = 0
|
|
@@ -156,12 +172,39 @@ export class N2kDevice extends EventEmitter {
|
|
|
156
172
|
}, 1000)
|
|
157
173
|
}
|
|
158
174
|
|
|
175
|
+
getPersistedData(key: string) {
|
|
176
|
+
try {
|
|
177
|
+
return getPersistedData(this.options, this.options.providerId, key)
|
|
178
|
+
} catch (err: any) {
|
|
179
|
+
this.debug('reading persisted data %o', err)
|
|
180
|
+
if (err.code !== 'ENOENT') {
|
|
181
|
+
console.error(err)
|
|
182
|
+
this.setError(err.message)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
savePersistedData(key: string, value: any) {
|
|
188
|
+
try {
|
|
189
|
+
savePersistedData(this.options, this.options.providerId, key, value)
|
|
190
|
+
} catch (err: any) {
|
|
191
|
+
console.error(err)
|
|
192
|
+
this.setError(err.message)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
159
196
|
setStatus(msg: string) {
|
|
160
197
|
if (this.options.app && this.options.app.setPluginStatus) {
|
|
161
198
|
this.options.app.setProviderStatus(this.options.providerId, msg)
|
|
162
199
|
}
|
|
163
200
|
}
|
|
164
201
|
|
|
202
|
+
setError(msg: string) {
|
|
203
|
+
if (this.options.app && this.options.app.setPluginStatus) {
|
|
204
|
+
this.options.app.setProviderError(this.options.providerId, msg)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
165
208
|
n2kMessage(pgn: PGN) {
|
|
166
209
|
if (pgn.dst == 255 || pgn.dst == this.address) {
|
|
167
210
|
try {
|
|
@@ -193,8 +236,16 @@ export class N2kDevice extends EventEmitter {
|
|
|
193
236
|
sendPGN(_pgn: PGN, _src: number | undefined = undefined) {}
|
|
194
237
|
}
|
|
195
238
|
|
|
239
|
+
function getModelVersion(options: any) {
|
|
240
|
+
if (options.app?.config?.getExternalHostname !== undefined) {
|
|
241
|
+
return `${options.app.config.ssl ? 'https' : 'http'}://${options.app.config.getExternalHostname()}:${options.app.config.getExternalPort()}`
|
|
242
|
+
} else {
|
|
243
|
+
return 'canboatjs'
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
196
247
|
function handleISORequest(device: N2kDevice, n2kMsg: PGN_59904) {
|
|
197
|
-
debug('handleISORequest %j', n2kMsg)
|
|
248
|
+
device.debug('handleISORequest %j', n2kMsg)
|
|
198
249
|
|
|
199
250
|
const PGN = Number(n2kMsg.fields.pgn)
|
|
200
251
|
|
|
@@ -206,7 +257,7 @@ function handleISORequest(device: N2kDevice, n2kMsg: PGN_59904) {
|
|
|
206
257
|
sendConfigInformation(device)
|
|
207
258
|
break
|
|
208
259
|
case 60928: // ISO address claim request
|
|
209
|
-
debug('sending address claim %j', device.addressClaim)
|
|
260
|
+
device.debug('sending address claim %j', device.addressClaim)
|
|
210
261
|
device.sendPGN(device.addressClaim as PGN)
|
|
211
262
|
break
|
|
212
263
|
case 126464:
|
|
@@ -214,21 +265,21 @@ function handleISORequest(device: N2kDevice, n2kMsg: PGN_59904) {
|
|
|
214
265
|
break
|
|
215
266
|
default:
|
|
216
267
|
if (!device.options.disableNAKs) {
|
|
217
|
-
debug(`Got unsupported ISO request for PGN ${PGN}. Sending NAK.`)
|
|
268
|
+
device.debug(`Got unsupported ISO request for PGN ${PGN}. Sending NAK.`)
|
|
218
269
|
sendNAKAcknowledgement(device, n2kMsg.src!, PGN)
|
|
219
270
|
}
|
|
220
271
|
}
|
|
221
272
|
}
|
|
222
273
|
|
|
223
274
|
function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
|
|
224
|
-
debug('handleGroupFunction %j', n2kMsg)
|
|
275
|
+
device.debug('handleGroupFunction %j', n2kMsg)
|
|
225
276
|
const functionCode = n2kMsg.fields.functionCode
|
|
226
277
|
if (functionCode === 'Request') {
|
|
227
278
|
handleRequestGroupFunction(device, n2kMsg)
|
|
228
279
|
} else if (functionCode === 'Command') {
|
|
229
280
|
handleCommandGroupFunction(device, n2kMsg)
|
|
230
281
|
} else {
|
|
231
|
-
debug('Got unsupported Group Function PGN: %j', n2kMsg)
|
|
282
|
+
device.debug('Got unsupported Group Function PGN: %j', n2kMsg)
|
|
232
283
|
}
|
|
233
284
|
|
|
234
285
|
function handleRequestGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
|
|
@@ -237,7 +288,7 @@ function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
|
|
|
237
288
|
|
|
238
289
|
const PGN = n2kMsg.fields.pgn
|
|
239
290
|
|
|
240
|
-
debug(
|
|
291
|
+
device.debug(
|
|
241
292
|
"Sending 'PGN Not Supported' Group Function response for requested PGN",
|
|
242
293
|
PGN
|
|
243
294
|
)
|
|
@@ -268,7 +319,7 @@ function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
|
|
|
268
319
|
|
|
269
320
|
const PGN = n2kMsg.fields.pgn
|
|
270
321
|
|
|
271
|
-
debug(
|
|
322
|
+
device.debug(
|
|
272
323
|
"Sending 'PGN Not Supported' Group Function response for commanded PGN",
|
|
273
324
|
PGN
|
|
274
325
|
)
|
|
@@ -294,7 +345,7 @@ function handleGroupFunction(device: N2kDevice, n2kMsg: PGN_126208) {
|
|
|
294
345
|
function handleISOAddressClaim(device: N2kDevice, n2kMsg: PGN_60928) {
|
|
295
346
|
if (n2kMsg.src != device.address) {
|
|
296
347
|
if (!device.devices[n2kMsg.src!]) {
|
|
297
|
-
debug(`registering device ${n2kMsg.src}`)
|
|
348
|
+
device.debug(`registering device ${n2kMsg.src}`)
|
|
298
349
|
device.devices[n2kMsg.src!] = { addressClaim: n2kMsg }
|
|
299
350
|
if (device.cansend) {
|
|
300
351
|
//sendISORequest(device, 126996, undefined, n2kMsg.src)
|
|
@@ -303,7 +354,7 @@ function handleISOAddressClaim(device: N2kDevice, n2kMsg: PGN_60928) {
|
|
|
303
354
|
return
|
|
304
355
|
}
|
|
305
356
|
|
|
306
|
-
debug('Checking ISO address claim. %j', n2kMsg)
|
|
357
|
+
device.debug('Checking ISO address claim. %j', n2kMsg)
|
|
307
358
|
|
|
308
359
|
const uint64ValueFromReceivedClaim = getISOAddressClaimAsUint64(n2kMsg)
|
|
309
360
|
const uint64ValueFromOurOwnClaim = getISOAddressClaimAsUint64(
|
|
@@ -311,12 +362,16 @@ function handleISOAddressClaim(device: N2kDevice, n2kMsg: PGN_60928) {
|
|
|
311
362
|
)
|
|
312
363
|
|
|
313
364
|
if (uint64ValueFromOurOwnClaim < uint64ValueFromReceivedClaim) {
|
|
314
|
-
debug(
|
|
365
|
+
device.debug(
|
|
366
|
+
`Address conflict detected! Kept our address as ${device.address}.`
|
|
367
|
+
)
|
|
315
368
|
sendAddressClaim(device) // We have smaller address claim data -> we can keep our address -> re-claim it
|
|
316
369
|
} else if (uint64ValueFromOurOwnClaim > uint64ValueFromReceivedClaim) {
|
|
317
370
|
device.foundConflict = true
|
|
318
371
|
increaseOwnAddress(device) // We have bigger address claim data -> we have to change our address
|
|
319
|
-
debug(
|
|
372
|
+
device.debug(
|
|
373
|
+
`Address conflict detected! trying address ${device.address}.`
|
|
374
|
+
)
|
|
320
375
|
sendAddressClaim(device)
|
|
321
376
|
}
|
|
322
377
|
}
|
|
@@ -332,7 +387,7 @@ function handleProductInformation(device: N2kDevice, n2kMsg: PGN_126996) {
|
|
|
332
387
|
if (!device.devices[n2kMsg.src!]) {
|
|
333
388
|
device.devices[n2kMsg.src!] = {}
|
|
334
389
|
}
|
|
335
|
-
debug('got product information %j', n2kMsg)
|
|
390
|
+
device.debug('got product information %j', n2kMsg)
|
|
336
391
|
device.devices[n2kMsg.src!].productInformation = n2kMsg
|
|
337
392
|
}
|
|
338
393
|
|
|
@@ -361,7 +416,7 @@ function sendAddressClaim(device: N2kDevice) {
|
|
|
361
416
|
//someone already has this address, so find a free one
|
|
362
417
|
increaseOwnAddress(device)
|
|
363
418
|
}
|
|
364
|
-
debug(`Sending address claim ${device.address}`)
|
|
419
|
+
device.debug(`Sending address claim ${device.address}`)
|
|
365
420
|
device.sendPGN(device.addressClaim)
|
|
366
421
|
device.setStatus(`Claimed address ${device.address}`)
|
|
367
422
|
device.addressClaimSentAt = Date.now()
|
|
@@ -372,7 +427,10 @@ function sendAddressClaim(device: N2kDevice) {
|
|
|
372
427
|
device.addressClaimChecker = setTimeout(() => {
|
|
373
428
|
//if ( Date.now() - device.addressClaimSentAt > 1000 ) {
|
|
374
429
|
//device.addressClaimChecker = null
|
|
375
|
-
debug('claimed address %d', device.address)
|
|
430
|
+
device.debug('claimed address %d', device.address)
|
|
431
|
+
|
|
432
|
+
device.savePersistedData('lastAddress', device.address)
|
|
433
|
+
|
|
376
434
|
device.cansend = true
|
|
377
435
|
if (!device.sentAvailable) {
|
|
378
436
|
if (device.options.app) {
|
|
@@ -397,7 +455,7 @@ function sendISORequest(
|
|
|
397
455
|
src: number | undefined = undefined,
|
|
398
456
|
dst = 255
|
|
399
457
|
) {
|
|
400
|
-
debug(`Sending iso request for ${pgn} to ${dst}`)
|
|
458
|
+
device.debug(`Sending iso request for ${pgn} to ${dst}`)
|
|
401
459
|
|
|
402
460
|
const isoRequest: PGN_59904 = {
|
|
403
461
|
pgn: 59904,
|
|
@@ -410,14 +468,14 @@ function sendISORequest(
|
|
|
410
468
|
}
|
|
411
469
|
|
|
412
470
|
function sendProductInformation(device: N2kDevice) {
|
|
413
|
-
debug('Sending product info %j', device.productInfo)
|
|
471
|
+
device.debug('Sending product info %j', device.productInfo)
|
|
414
472
|
|
|
415
473
|
device.sendPGN(device.productInfo)
|
|
416
474
|
}
|
|
417
475
|
|
|
418
476
|
function sendConfigInformation(device: N2kDevice) {
|
|
419
477
|
if (device.configurationInfo) {
|
|
420
|
-
debug('Sending config info..')
|
|
478
|
+
device.debug('Sending config info..')
|
|
421
479
|
device.sendPGN(device.configurationInfo)
|
|
422
480
|
}
|
|
423
481
|
}
|
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
|
-
|
|
23
|
-
|
|
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
|
}
|