@canboat/canboatjs 3.3.2 → 3.3.4
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/dist/bin/actisense-file.js +2 -0
- package/dist/bin/actisense-file.js.map +1 -1
- package/dist/bin/actisense-n2k-tcp.js +2 -0
- package/dist/bin/actisense-n2k-tcp.js.map +1 -1
- package/dist/bin/actisense-serialjs.js +2 -0
- package/dist/bin/actisense-serialjs.js.map +1 -1
- package/dist/bin/analyzerjs.js +35 -8
- package/dist/bin/analyzerjs.js.map +1 -1
- package/dist/bin/candumpjs.js +7 -4
- package/dist/bin/candumpjs.js.map +1 -1
- package/dist/bin/cansend.js +2 -0
- package/dist/bin/cansend.js.map +1 -1
- package/dist/bin/to-pgn.js +2 -0
- package/dist/bin/to-pgn.js.map +1 -1
- package/dist/bin/utils.d.ts +4 -0
- package/dist/bin/utils.d.ts.map +1 -0
- package/dist/bin/utils.js +15 -0
- package/dist/bin/utils.js.map +1 -0
- package/dist/bin/ydvr-file.d.ts +3 -0
- package/dist/bin/ydvr-file.d.ts.map +1 -0
- package/dist/bin/ydvr-file.js +31 -0
- package/dist/bin/ydvr-file.js.map +1 -0
- package/dist/fromPgn.d.ts.map +1 -1
- package/dist/fromPgn.js +1 -0
- package/dist/fromPgn.js.map +1 -1
- package/dist/stringMsg.d.ts +2 -0
- package/dist/stringMsg.d.ts.map +1 -1
- package/dist/stringMsg.js +18 -1
- package/dist/stringMsg.js.map +1 -1
- package/dist/stringMsg.test.js +15 -1
- package/dist/stringMsg.test.js.map +1 -1
- package/package.json +3 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/.github/workflows/publish.yml +0 -32
- package/.github/workflows/release_on_tag.yml +0 -27
- package/.github/workflows/require_pr_label.yml +0 -13
- package/.github/workflows/test.yml +0 -28
- package/.github/workflows/test_canboat_changes.yml +0 -92
- package/examples/signalk-device-emulator/index.js +0 -1
- package/examples/signalk-device-emulator/package.json +0 -24
- package/examples/simpleCan.js +0 -42
- package/ios.js +0 -67
- package/lib/actisense-serial.ts +0 -644
- package/lib/bin/actisense-file.ts +0 -53
- package/lib/bin/actisense-n2k-tcp.ts +0 -50
- package/lib/bin/actisense-serialjs.ts +0 -55
- package/lib/bin/analyzerjs.ts +0 -66
- package/lib/bin/candumpjs.ts +0 -100
- package/lib/bin/cansend.ts +0 -131
- package/lib/bin/ikonvert-serial.ts +0 -44
- package/lib/bin/to-pgn.ts +0 -65
- package/lib/bin/ydvr-file +0 -33
- package/lib/canId.test.js +0 -61
- package/lib/canId.ts +0 -84
- package/lib/canbus.ts +0 -293
- package/lib/candevice.ts +0 -41
- package/lib/codes.ts +0 -21
- package/lib/discovery.ts +0 -118
- package/lib/fromPgn.ts +0 -1217
- package/lib/fromPgnStream.ts +0 -54
- package/lib/ikonvert.ts +0 -250
- package/lib/index.ts +0 -48
- package/lib/n2k-actisense.test.js +0 -58
- package/lib/n2k-actisense.ts +0 -152
- package/lib/n2kDevice.ts +0 -509
- package/lib/pgns.test.ts +0 -12
- package/lib/pgns.ts +0 -191
- package/lib/simpleCan.ts +0 -140
- package/lib/stringMsg.test.js +0 -273
- package/lib/stringMsg.ts +0 -464
- package/lib/toPgn.ts +0 -601
- package/lib/utilities.test.js +0 -8
- package/lib/utilities.ts +0 -169
- package/lib/venus-mqtt.js +0 -118
- package/lib/venus.js +0 -88
- package/lib/w2k01.ts +0 -142
- package/lib/yddevice.ts +0 -48
- package/lib/ydgw02.ts +0 -197
- package/lib/ydvr.js +0 -138
package/lib/fromPgnStream.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2018 Scott Bender (scott@scottbender.net)
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { PGN } from '@canboat/ts-pgns'
|
|
18
|
-
import { createDebug } from './utilities'
|
|
19
|
-
import { Transform } from 'stream'
|
|
20
|
-
import { Parser as FromPgn } from './fromPgn'
|
|
21
|
-
import util from 'util'
|
|
22
|
-
|
|
23
|
-
const debug = createDebug('canboatjs:FromPgnStream')
|
|
24
|
-
|
|
25
|
-
export function fromPgnStream(this: any, options: any = {}) {
|
|
26
|
-
Transform.call(this, {
|
|
27
|
-
objectMode: true
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
this.fromPgn = new FromPgn(options)
|
|
31
|
-
|
|
32
|
-
this.fromPgn.on('pgn', (pgn: PGN) => {
|
|
33
|
-
this.push(pgn)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
this.fromPgn.on('warning', (pgn: PGN, warning: string) => {
|
|
37
|
-
debug(`[warning] ${pgn.pgn} ${warning}`)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
this.fromPgn.on('error', (pgn: PGN, error: any) => {
|
|
41
|
-
debug(`[error] ${pgn.pgn} ${error}`)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
util.inherits(fromPgnStream, Transform)
|
|
46
|
-
|
|
47
|
-
fromPgnStream.prototype._transform = function (
|
|
48
|
-
chunk: any,
|
|
49
|
-
encoding: string,
|
|
50
|
-
done: any
|
|
51
|
-
) {
|
|
52
|
-
this.fromPgn.parse(chunk)
|
|
53
|
-
done()
|
|
54
|
-
}
|
package/lib/ikonvert.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2018 Scott Bender (scott@scottbender.net)
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { PGN } from '@canboat/ts-pgns'
|
|
18
|
-
import { createDebug } from './utilities'
|
|
19
|
-
import { Transform } from 'stream'
|
|
20
|
-
import { toPgn, pgnToiKonvertSerialFormat } from './toPgn'
|
|
21
|
-
import { Parser } from './fromPgn'
|
|
22
|
-
import _ from 'lodash'
|
|
23
|
-
import { defaultTransmitPGNs } from './codes'
|
|
24
|
-
import util from 'util'
|
|
25
|
-
|
|
26
|
-
//const pgnsSent = {}
|
|
27
|
-
|
|
28
|
-
export function iKonvertStream(this: any, options: any) {
|
|
29
|
-
if (this == undefined) {
|
|
30
|
-
return new (iKonvertStream as any)(options)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
this.debug = createDebug('canboatjs:ikonvert', options)
|
|
34
|
-
|
|
35
|
-
Transform.call(this, {
|
|
36
|
-
objectMode: true
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
this.isTcp = options.tcp === true
|
|
40
|
-
|
|
41
|
-
this.outEvent = this.isTcp ? 'navlink2-out' : 'ikonvertOut'
|
|
42
|
-
|
|
43
|
-
this.plainText = false
|
|
44
|
-
this.reconnect = options.reconnect || true
|
|
45
|
-
this.options = options
|
|
46
|
-
this.cansend = false
|
|
47
|
-
this.buffer = Buffer.alloc(500)
|
|
48
|
-
this.bufferOffset = 0
|
|
49
|
-
this.start()
|
|
50
|
-
|
|
51
|
-
this.setProviderStatus =
|
|
52
|
-
options.app && options.app.setProviderStatus
|
|
53
|
-
? (msg: string) => {
|
|
54
|
-
options.app.setProviderStatus(options.providerId, msg)
|
|
55
|
-
}
|
|
56
|
-
: () => {}
|
|
57
|
-
this.setProviderError =
|
|
58
|
-
options.app && options.app.setProviderError
|
|
59
|
-
? (msg: string) => {
|
|
60
|
-
options.app.setProviderError(options.providerId, msg)
|
|
61
|
-
}
|
|
62
|
-
: () => {}
|
|
63
|
-
|
|
64
|
-
this.transmitPGNs = defaultTransmitPGNs
|
|
65
|
-
if (this.options.transmitPGNs) {
|
|
66
|
-
this.transmitPGNs = _.union(this.transmitPGNs, this.options.transmitPGNs)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
70
|
-
const that = this
|
|
71
|
-
|
|
72
|
-
if (this.options.app) {
|
|
73
|
-
options.app.on(this.options.outEevent || 'nmea2000out', (msg: string) => {
|
|
74
|
-
if (typeof msg === 'string') {
|
|
75
|
-
that.sendActisensePGN(msg)
|
|
76
|
-
} else {
|
|
77
|
-
that.sendPGN(msg)
|
|
78
|
-
}
|
|
79
|
-
options.app.emit('connectionwrite', { providerId: options.providerId })
|
|
80
|
-
})
|
|
81
|
-
options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
|
|
82
|
-
that.sendPGN(msg)
|
|
83
|
-
options.app.emit('connectionwrite', { providerId: options.providerId })
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
this.isSetup = false
|
|
87
|
-
//this.cansend = true
|
|
88
|
-
this.state = 0
|
|
89
|
-
this.setupCommands = this.getSetupCommands()
|
|
90
|
-
this.expecting = false
|
|
91
|
-
|
|
92
|
-
this.debug('started')
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
util.inherits(iKonvertStream, Transform)
|
|
97
|
-
|
|
98
|
-
iKonvertStream.prototype.start = function () {}
|
|
99
|
-
|
|
100
|
-
iKonvertStream.prototype.sendString = function (msg: string) {
|
|
101
|
-
this.debug('sending %s', msg)
|
|
102
|
-
if (this.isTcp) {
|
|
103
|
-
msg = msg + '\n\r'
|
|
104
|
-
}
|
|
105
|
-
this.options.app.emit(this.outEvent, msg)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
iKonvertStream.prototype.sendPGN = function (pgn: PGN) {
|
|
109
|
-
if (this.cansend) {
|
|
110
|
-
//let now = Date.now()
|
|
111
|
-
//let lastSent = pgnsSent[pgn.pgn]
|
|
112
|
-
const msg = pgnToiKonvertSerialFormat(pgn)
|
|
113
|
-
this.sendString(msg)
|
|
114
|
-
//pgnsSent[pgn.pgn] = now
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
iKonvertStream.prototype.sendActisensePGN = function (msg: string) {
|
|
119
|
-
if (this.cansend) {
|
|
120
|
-
if (!this.parser) {
|
|
121
|
-
this.parser = new Parser(this.options)
|
|
122
|
-
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
124
|
-
const that = this
|
|
125
|
-
this.parser.on('error', (pgn: PGN, error: any) => {
|
|
126
|
-
console.error(`Error parsing ${pgn.pgn} ${error}`)
|
|
127
|
-
console.error(error.stack)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
this.parser.on('pgn', (pgn: PGN) => {
|
|
131
|
-
//let now = Date.now()
|
|
132
|
-
//let lastSent = pgnsSent[pgn.pgn]
|
|
133
|
-
const msg = pgnToiKonvertSerialFormat(pgn)
|
|
134
|
-
that.sendString(msg)
|
|
135
|
-
//pgnsSent[pgn.pgn] = now
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
this.parser.parseString(msg)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
iKonvertStream.prototype.setup = function () {
|
|
143
|
-
let txPgns = '$PDGY,TX_LIST'
|
|
144
|
-
this.transmitPGNs.forEach((pgn: number) => {
|
|
145
|
-
txPgns = txPgns + `,${pgn}`
|
|
146
|
-
})
|
|
147
|
-
this.debug('sending pgn tx list')
|
|
148
|
-
this.sendString(txPgns)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
iKonvertStream.prototype.getSetupCommands = function () {
|
|
152
|
-
let txPgns = '$PDGY,TX_LIST'
|
|
153
|
-
this.transmitPGNs.forEach((pgn: number) => {
|
|
154
|
-
txPgns = txPgns + `,${pgn}`
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
const setupCommands = []
|
|
158
|
-
|
|
159
|
-
setupCommands.push('$PDGY,N2NET_OFFLINE:$PDGY,TEXT,Digital_Yacht_')
|
|
160
|
-
if (this.isTcp) {
|
|
161
|
-
setupCommands.push('$PDGY,N2NET_MODE,15:$PDGY,ACK,N2NET_MODE')
|
|
162
|
-
}
|
|
163
|
-
setupCommands.push('$PDGY,TX_LIMIT,OFF:$PDGY,') // NACK is ok with old firmware
|
|
164
|
-
setupCommands.push(`${txPgns}:$PDGY,ACK,TX_LIST`)
|
|
165
|
-
setupCommands.push('$PDGY,N2NET_INIT,ALL:$PDGY,ACK,N2NET_INIT,ALL')
|
|
166
|
-
|
|
167
|
-
return setupCommands
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
iKonvertStream.prototype._transform = function (
|
|
171
|
-
chunk: any,
|
|
172
|
-
encoding: string,
|
|
173
|
-
done: any
|
|
174
|
-
) {
|
|
175
|
-
let line = chunk.toString().trim()
|
|
176
|
-
line = line.substring(0, line.length) // take off the \r
|
|
177
|
-
|
|
178
|
-
if (line.startsWith('$PDGY,TEXT')) {
|
|
179
|
-
this.debug(line)
|
|
180
|
-
} else if (line.startsWith('$PDGY,000000,')) {
|
|
181
|
-
const parts = line.split(',')
|
|
182
|
-
|
|
183
|
-
//FIXME, camelCase?
|
|
184
|
-
if (this.options.sendNetworkStats && parts[2] && parts[2].length > 0) {
|
|
185
|
-
const pgn = {
|
|
186
|
-
pgn: 0x40100,
|
|
187
|
-
prio: 7,
|
|
188
|
-
dst: 255,
|
|
189
|
-
src: 0,
|
|
190
|
-
'CAN network load': Number(parts[2]),
|
|
191
|
-
Errors: Number(parts[3]),
|
|
192
|
-
'Device count': Number(parts[4]),
|
|
193
|
-
Uptime: Number(parts[5]),
|
|
194
|
-
'Gateway address': Number(parts[6]),
|
|
195
|
-
'Rejected TX requests': Number(parts[7])
|
|
196
|
-
}
|
|
197
|
-
const buf = toPgn(pgn)
|
|
198
|
-
if (buf) {
|
|
199
|
-
this.push(
|
|
200
|
-
`!PDGY,${pgn.pgn},${pgn.prio},${pgn.src},${pgn.dst},0,${buf.toString('base64')}`
|
|
201
|
-
)
|
|
202
|
-
}
|
|
203
|
-
done()
|
|
204
|
-
return
|
|
205
|
-
}
|
|
206
|
-
} else if (line.startsWith('$PDGY,NAK')) {
|
|
207
|
-
const parts = line.split(',')
|
|
208
|
-
const msg = `NavLink2 error ${parts[2]}: ${parts[3]}`
|
|
209
|
-
console.error(msg)
|
|
210
|
-
//this.setProviderError(msg)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (!this.isSetup) {
|
|
214
|
-
this.debug(line)
|
|
215
|
-
let command = this.setupCommands[this.state].split(':')
|
|
216
|
-
if (!this.expecting) {
|
|
217
|
-
this.sendString(command[0])
|
|
218
|
-
this.expecting = true
|
|
219
|
-
this.sentTime = Date.now()
|
|
220
|
-
this.debug(`Waiting for ${command[1]}`)
|
|
221
|
-
} else {
|
|
222
|
-
if (line.startsWith(command[1])) {
|
|
223
|
-
this.state = this.state + 1
|
|
224
|
-
|
|
225
|
-
if (this.state == this.setupCommands.length) {
|
|
226
|
-
this.isSetup = true
|
|
227
|
-
this.cansend = true
|
|
228
|
-
this.options.app.emit('nmea2000OutAvailable')
|
|
229
|
-
this.debug('Setup completed')
|
|
230
|
-
} else {
|
|
231
|
-
command = this.setupCommands[this.state].split(':')
|
|
232
|
-
this.sendString(command[0])
|
|
233
|
-
this.expecting = true
|
|
234
|
-
this.sentTime = Date.now()
|
|
235
|
-
this.debug(`Waiting for ${command[1]}`)
|
|
236
|
-
}
|
|
237
|
-
} else if (Date.now() - this.sentTime > 5000) {
|
|
238
|
-
this.debug(`Did not receive expected: ${command[1]}, retrying...`)
|
|
239
|
-
this.sendString(command[0])
|
|
240
|
-
this.sentTime = Date.now()
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
} else {
|
|
244
|
-
this.push(line)
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
done()
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
iKonvertStream.prototype.end = function () {}
|
package/lib/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2019 Scott Bender <scott@scottbender.net>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export { Parser as FromPgn } from './fromPgn'
|
|
18
|
-
export { CanbusStream as canbus } from './canbus'
|
|
19
|
-
export {
|
|
20
|
-
addCustomPgns,
|
|
21
|
-
lookupEnumerationValue,
|
|
22
|
-
lookupEnumerationName
|
|
23
|
-
} from './pgns'
|
|
24
|
-
export {
|
|
25
|
-
parseN2kString,
|
|
26
|
-
isN2KString,
|
|
27
|
-
toActisenseSerialFormat
|
|
28
|
-
} from './stringMsg'
|
|
29
|
-
export {
|
|
30
|
-
toPgn,
|
|
31
|
-
pgnToActisenseSerialFormat,
|
|
32
|
-
pgnToActisenseN2KAsciiFormat,
|
|
33
|
-
pgnToiKonvertSerialFormat,
|
|
34
|
-
pgnToYdgwRawFormat,
|
|
35
|
-
pgnToYdgwFullRawFormat,
|
|
36
|
-
pgnToPCDIN,
|
|
37
|
-
pgnToMXPGN
|
|
38
|
-
} from './toPgn'
|
|
39
|
-
export { Ydgw02Stream as Ydwg02 } from './ydgw02'
|
|
40
|
-
export { Ydgw02Stream as Ydgw02 } from './ydgw02'
|
|
41
|
-
export { W2K01Stream as W2k01 } from './w2k01'
|
|
42
|
-
export { iKonvertStream as iKonvert } from './ikonvert'
|
|
43
|
-
export { VenusStream as Venus } from './venus'
|
|
44
|
-
export { VenusMQTT } from './venus-mqtt'
|
|
45
|
-
export { discover } from './discovery'
|
|
46
|
-
export { SimpleCan } from './simpleCan'
|
|
47
|
-
export { YdDevice } from './yddevice'
|
|
48
|
-
export { ActisenseStream as serial } from './actisense-serial'
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const { readN2KActisense, encodeN2KActisense } = require('./n2k-actisense')
|
|
2
|
-
|
|
3
|
-
describe('readN2KActisense', () => {
|
|
4
|
-
test('basic msg', () => {
|
|
5
|
-
const buffer = Buffer.from(
|
|
6
|
-
'1002d01500ff0502f809004c86fe00fffccba56800ffff7310031002d01500ff0501f809004c86fe000d474717e2da69d29c1003',
|
|
7
|
-
'hex'
|
|
8
|
-
)
|
|
9
|
-
const res = readN2KActisense(buffer, false, {})
|
|
10
|
-
delete res.pgn.timestamp
|
|
11
|
-
expect(res).toEqual({
|
|
12
|
-
coalesced: true,
|
|
13
|
-
data: Buffer.from('0d474717e2da69d2', 'hex'),
|
|
14
|
-
length: 8,
|
|
15
|
-
pgn: {
|
|
16
|
-
canId: 167248133,
|
|
17
|
-
dst: 255,
|
|
18
|
-
pgn: 129025,
|
|
19
|
-
prio: 2,
|
|
20
|
-
src: 5
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('encodeN2KActisense', () => {
|
|
27
|
-
test('basic msg', () => {
|
|
28
|
-
const expected = '1002d01500ff0501f80900000000000d474717e2da69d2001003'
|
|
29
|
-
const pgn = {
|
|
30
|
-
dst: 255,
|
|
31
|
-
pgn: 129025,
|
|
32
|
-
prio: 2,
|
|
33
|
-
src: 5
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const encoded = encodeN2KActisense(
|
|
37
|
-
pgn,
|
|
38
|
-
Buffer.from('0d474717e2da69d2', 'hex')
|
|
39
|
-
)
|
|
40
|
-
expect(encoded).toEqual(Buffer.from(expected, 'hex'))
|
|
41
|
-
|
|
42
|
-
const read = readN2KActisense(encoded, false, {})
|
|
43
|
-
delete read.pgn.timestamp
|
|
44
|
-
|
|
45
|
-
expect(read).toEqual({
|
|
46
|
-
coalesced: true,
|
|
47
|
-
data: Buffer.from('0d474717e2da69d2', 'hex'),
|
|
48
|
-
length: 8,
|
|
49
|
-
pgn: {
|
|
50
|
-
canId: 167248133,
|
|
51
|
-
dst: 255,
|
|
52
|
-
pgn: 129025,
|
|
53
|
-
prio: 2,
|
|
54
|
-
src: 5
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
})
|
package/lib/n2k-actisense.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 Scott Bender <scott@scottbender.net>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { PGN } from '@canboat/ts-pgns'
|
|
18
|
-
import { createDebug } from './utilities'
|
|
19
|
-
import { parseCanId, encodeCanId } from './canId'
|
|
20
|
-
import { BitStream } from 'bit-buffer'
|
|
21
|
-
import { binToActisense } from './utilities'
|
|
22
|
-
|
|
23
|
-
const debug = createDebug('canboatjs:w2k01')
|
|
24
|
-
const debugData = createDebug('canboatjs:w2k01-data')
|
|
25
|
-
|
|
26
|
-
export const readN2KActisense = (
|
|
27
|
-
data: Buffer,
|
|
28
|
-
plainText: boolean,
|
|
29
|
-
context: any,
|
|
30
|
-
cb: (data: any) => void
|
|
31
|
-
) => {
|
|
32
|
-
const inBuf = Buffer.from(data)
|
|
33
|
-
let inOffset = 0
|
|
34
|
-
let last
|
|
35
|
-
|
|
36
|
-
if (debugData.enabled) {
|
|
37
|
-
debugData(
|
|
38
|
-
'Received: (' + data.length + ') ' + Buffer.from(data).toString('hex')
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
while (true) {
|
|
44
|
-
const len = inBuf.readUInt16LE(inOffset + 3)
|
|
45
|
-
|
|
46
|
-
if (inBuf.length < inOffset + 5 + len) {
|
|
47
|
-
/*
|
|
48
|
-
I've never seen this happen
|
|
49
|
-
context.lastChunk = Buffer.alloc(inBuf.length - inOffset)
|
|
50
|
-
inBuf.copy(context.lastChunk, 0, inOffset, inBuf.length-1)
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
if (debug.enabled) {
|
|
54
|
-
debug(
|
|
55
|
-
'incomplete packet: (' +
|
|
56
|
-
len +
|
|
57
|
-
') ' +
|
|
58
|
-
inBuf.toString('hex', inOffset)
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
} else if (
|
|
64
|
-
inBuf[inOffset + 5 + len - 1] != 0x03 ||
|
|
65
|
-
inBuf[inOffset + 5 + len - 2] != 0x10
|
|
66
|
-
) {
|
|
67
|
-
if (debug.enabled) {
|
|
68
|
-
debug('bad packet: (' + len + ') ' + inBuf.toString('hex', inOffset))
|
|
69
|
-
}
|
|
70
|
-
//context.lastChunk = null
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const buf = Buffer.alloc(len)
|
|
75
|
-
inBuf.copy(buf, 0, inOffset + 5, inOffset + len + 5)
|
|
76
|
-
|
|
77
|
-
//console.log('NextBuf: (' + buf.length + ') ' + buf.toString('hex'))
|
|
78
|
-
|
|
79
|
-
let offset = 0
|
|
80
|
-
const _dst = buf.readUInt8(offset)
|
|
81
|
-
offset += 1
|
|
82
|
-
const canid = buf.readUInt32LE(offset)
|
|
83
|
-
offset += 4
|
|
84
|
-
const _timestamp = buf.readUInt32LE(offset)
|
|
85
|
-
offset += 4
|
|
86
|
-
const _mhs = buf.readUInt8(offset)
|
|
87
|
-
offset += 1
|
|
88
|
-
|
|
89
|
-
const info = parseCanId(canid)
|
|
90
|
-
|
|
91
|
-
//console.log(`${len} ${mhs} ${dst} (${info.src}, ${info.dst}) ${info.pgn} ${timestamp}`)
|
|
92
|
-
|
|
93
|
-
const pgnData = Buffer.alloc(len - offset - 3)
|
|
94
|
-
buf.copy(pgnData, 0, offset, len - 3)
|
|
95
|
-
const timestamp = new Date().toISOString()
|
|
96
|
-
|
|
97
|
-
if (plainText) {
|
|
98
|
-
last = binToActisense(info, timestamp, pgnData, pgnData.length)
|
|
99
|
-
cb && cb(last)
|
|
100
|
-
} else {
|
|
101
|
-
last = {
|
|
102
|
-
pgn: info,
|
|
103
|
-
length: pgnData.length,
|
|
104
|
-
data: pgnData,
|
|
105
|
-
coalesced: true
|
|
106
|
-
}
|
|
107
|
-
cb && cb(last)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
inOffset += len + 5
|
|
111
|
-
if (inOffset == inBuf.length) {
|
|
112
|
-
return last
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} catch (error) {
|
|
116
|
-
debug(`[error] ${error}`)
|
|
117
|
-
//context.lastChunk = null
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export const encodeN2KActisense = (pgn: PGN, data: Buffer) => {
|
|
123
|
-
const bs = new BitStream(Buffer.alloc(18 + data.length))
|
|
124
|
-
|
|
125
|
-
bs.writeUint8(0x10) //BST Message ID
|
|
126
|
-
bs.writeUint8(0x02)
|
|
127
|
-
bs.writeUint8(0xd0)
|
|
128
|
-
|
|
129
|
-
bs.writeUint16(13 + data.length) //len
|
|
130
|
-
bs.writeUint8(pgn.dst)
|
|
131
|
-
bs.writeUint32(
|
|
132
|
-
encodeCanId({
|
|
133
|
-
pgn: pgn.pgn,
|
|
134
|
-
src: pgn.src || 0,
|
|
135
|
-
prio: pgn.prio || 2,
|
|
136
|
-
dst: pgn.dst
|
|
137
|
-
})
|
|
138
|
-
)
|
|
139
|
-
bs.writeUint32(0) //timestamp
|
|
140
|
-
bs.writeUint8(0) //mhs
|
|
141
|
-
data.copy(bs.view.buffer, bs.byteIndex, 0)
|
|
142
|
-
bs.byteIndex += data.length
|
|
143
|
-
bs.writeUint8(0) // ??
|
|
144
|
-
bs.writeUint8(0x10)
|
|
145
|
-
bs.writeUint8(0x03)
|
|
146
|
-
|
|
147
|
-
if (debugData.enabled) {
|
|
148
|
-
debugData('encoded: ' + bs.view.buffer.toString('hex'))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return bs.view.buffer
|
|
152
|
-
}
|