@canboat/canboatjs 3.3.3 → 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.
Files changed (73) hide show
  1. package/dist/bin/actisense-file.js +2 -0
  2. package/dist/bin/actisense-file.js.map +1 -1
  3. package/dist/bin/actisense-n2k-tcp.js +2 -0
  4. package/dist/bin/actisense-n2k-tcp.js.map +1 -1
  5. package/dist/bin/actisense-serialjs.js +2 -0
  6. package/dist/bin/actisense-serialjs.js.map +1 -1
  7. package/dist/bin/analyzerjs.js +2 -0
  8. package/dist/bin/analyzerjs.js.map +1 -1
  9. package/dist/bin/candumpjs.js +7 -4
  10. package/dist/bin/candumpjs.js.map +1 -1
  11. package/dist/bin/cansend.js +2 -0
  12. package/dist/bin/cansend.js.map +1 -1
  13. package/dist/bin/to-pgn.js +2 -0
  14. package/dist/bin/to-pgn.js.map +1 -1
  15. package/dist/bin/utils.d.ts +4 -0
  16. package/dist/bin/utils.d.ts.map +1 -0
  17. package/dist/bin/utils.js +15 -0
  18. package/dist/bin/utils.js.map +1 -0
  19. package/dist/bin/ydvr-file.d.ts +3 -0
  20. package/dist/bin/ydvr-file.d.ts.map +1 -0
  21. package/dist/bin/ydvr-file.js +31 -0
  22. package/dist/bin/ydvr-file.js.map +1 -0
  23. package/dist/fromPgn.d.ts.map +1 -1
  24. package/dist/fromPgn.js +1 -0
  25. package/dist/fromPgn.js.map +1 -1
  26. package/package.json +3 -2
  27. package/tsconfig.tsbuildinfo +1 -1
  28. package/.github/workflows/publish.yml +0 -32
  29. package/.github/workflows/release_on_tag.yml +0 -27
  30. package/.github/workflows/require_pr_label.yml +0 -13
  31. package/.github/workflows/test.yml +0 -28
  32. package/.github/workflows/test_canboat_changes.yml +0 -92
  33. package/examples/signalk-device-emulator/index.js +0 -1
  34. package/examples/signalk-device-emulator/package.json +0 -24
  35. package/examples/simpleCan.js +0 -42
  36. package/ios.js +0 -67
  37. package/lib/actisense-serial.ts +0 -644
  38. package/lib/bin/actisense-file.ts +0 -53
  39. package/lib/bin/actisense-n2k-tcp.ts +0 -50
  40. package/lib/bin/actisense-serialjs.ts +0 -55
  41. package/lib/bin/analyzerjs.ts +0 -91
  42. package/lib/bin/candumpjs.ts +0 -100
  43. package/lib/bin/cansend.ts +0 -131
  44. package/lib/bin/ikonvert-serial.ts +0 -44
  45. package/lib/bin/to-pgn.ts +0 -65
  46. package/lib/bin/ydvr-file +0 -33
  47. package/lib/canId.test.js +0 -61
  48. package/lib/canId.ts +0 -84
  49. package/lib/canbus.ts +0 -293
  50. package/lib/candevice.ts +0 -41
  51. package/lib/codes.ts +0 -21
  52. package/lib/discovery.ts +0 -118
  53. package/lib/fromPgn.ts +0 -1217
  54. package/lib/fromPgnStream.ts +0 -54
  55. package/lib/ikonvert.ts +0 -250
  56. package/lib/index.ts +0 -48
  57. package/lib/n2k-actisense.test.js +0 -58
  58. package/lib/n2k-actisense.ts +0 -152
  59. package/lib/n2kDevice.ts +0 -509
  60. package/lib/pgns.test.ts +0 -12
  61. package/lib/pgns.ts +0 -191
  62. package/lib/simpleCan.ts +0 -140
  63. package/lib/stringMsg.test.js +0 -288
  64. package/lib/stringMsg.ts +0 -478
  65. package/lib/toPgn.ts +0 -601
  66. package/lib/utilities.test.js +0 -8
  67. package/lib/utilities.ts +0 -169
  68. package/lib/venus-mqtt.js +0 -118
  69. package/lib/venus.js +0 -88
  70. package/lib/w2k01.ts +0 -142
  71. package/lib/yddevice.ts +0 -48
  72. package/lib/ydgw02.ts +0 -197
  73. package/lib/ydvr.js +0 -138
package/lib/canId.ts DELETED
@@ -1,84 +0,0 @@
1
- import { flow } from 'lodash/fp'
2
-
3
- export type ParsedCanID = {
4
- canId: number
5
- prio: number
6
- src: number
7
- pgn: number
8
- dst: number
9
- }
10
-
11
- export type CanID = {
12
- prio: number
13
- src: number
14
- pgn: number
15
- dst: number
16
- }
17
-
18
- // Decode CAN Identifier (canId). ISO 11783 (CAN 2.0 B Extended Frame Format)
19
- export const parseCanId = (id: number): ParsedCanID => {
20
- const PF = (id >> 16) & 0xff // PDU Format
21
- const PS = (id >> 8) & 0xff // PDU Specific
22
- const DP = (id >> 24) & 1 // Data Page
23
-
24
- let dst: number, pgn: number
25
-
26
- if (PF < 240) {
27
- /* PDU1 format, the PS contains the destination address */
28
- dst = PS
29
- pgn = (DP << 16) + (PF << 8)
30
- } else {
31
- /* PDU2 format, the destination is implied global and the PGN is extended */
32
- dst = 0xff
33
- pgn = (DP << 16) + (PF << 8) + PS
34
- }
35
- return {
36
- canId: id, // Include original canId in return object.
37
- prio: (id >> 26) & 0x7, // Priority
38
- src: id & 0xff, // Source Address (SA),
39
- pgn,
40
- dst
41
- }
42
- }
43
- // canId should be a hex encoded string without spaces or commas.
44
- export const parseCanIdStr = (canId: string) => parseCanId(parseInt(canId, 16))
45
-
46
- export const buildCanId = (
47
- prio: string | number,
48
- pgn: string | number,
49
- dst: string | number,
50
- src: string | number
51
- ): CanID => ({
52
- prio: Number(prio),
53
- pgn: Number(pgn),
54
- dst: Number(dst),
55
- src: Number(src)
56
- })
57
-
58
- // Encode CAN Identifier (canId)
59
- export const encodeCanId = (id: CanID) => {
60
- let canId = id.src & 0xff
61
-
62
- //I can't get this to work, but things seem ok??
63
- //let canId = ((src & 0xff) | 0x80000000)) // src bits are the lowest ones of the CAN ID. Also set the highest bit to 1 as n2k uses
64
- // only extended frames (EFF bit).
65
-
66
- const PF = (id.pgn >> 8) & 0xff
67
-
68
- if (PF < 240) {
69
- // PDU 1
70
- canId = canId | ((id.dst & 0xff) << 8)
71
- canId = canId | (id.pgn << 8)
72
- } else {
73
- // PDU 2
74
- canId = canId | (id.pgn << 8)
75
- }
76
- canId = canId | (id.prio << 26)
77
-
78
- return canId
79
- }
80
- export const canIdString = (canId: number) =>
81
- canId.toString(16).padStart(8, '0')
82
- export const encodeCanIdString = flow(encodeCanId, canIdString)
83
- // Utility function that parses and re-encodes. Compare result to original.
84
- export const parseEncode = (x: number) => encodeCanId(parseCanId(x))
package/lib/canbus.ts DELETED
@@ -1,293 +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 } from './toPgn'
21
- import _ from 'lodash'
22
- import { CanDevice } from './candevice'
23
- import { getPlainPGNs, binToActisense } from './utilities'
24
- import { CanID, encodeCanId, parseCanId } from './canId'
25
- import { toActisenseSerialFormat, parseActisense } from './stringMsg'
26
- import util from 'util'
27
-
28
- export function CanbusStream(this: any, options: any) {
29
- if (this === undefined) {
30
- return new (CanbusStream as any)(options)
31
- }
32
-
33
- this.debug = createDebug('canboatjs:canbus', options)
34
-
35
- Transform.call(this, {
36
- objectMode: true
37
- })
38
-
39
- this.plainText = false
40
- this.options = options
41
- this.start()
42
-
43
- this.setProviderStatus =
44
- options.app && options.app.setProviderStatus
45
- ? (msg: string) => {
46
- options.app.setProviderStatus(options.providerId, msg)
47
- }
48
- : () => {}
49
- this.setProviderError =
50
- options.app && options.app.setProviderError
51
- ? (msg: string) => {
52
- options.app.setProviderError(options.providerId, msg)
53
- }
54
- : () => {}
55
-
56
- if (options.fromStdIn) {
57
- return
58
- }
59
-
60
- try {
61
- // eslint-disable-next-line @typescript-eslint/no-require-imports
62
- this.socketcan = require('socketcan')
63
- } catch (err) {
64
- console.error(err)
65
- const msg = 'unable to load native socketcan interface'
66
- console.error(msg)
67
- }
68
-
69
- // eslint-disable-next-line @typescript-eslint/no-this-alias
70
- const that = this
71
-
72
- if (options.app) {
73
- options.app.on(options.outEvent || 'nmea2000out', (msg: string) => {
74
- that.sendPGN(msg)
75
- })
76
- options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
77
- that.sendPGN(msg)
78
- })
79
- }
80
-
81
- if (this.connect() == false) {
82
- return
83
- }
84
-
85
- const noDataReceivedTimeout =
86
- typeof options.noDataReceivedTimeout !== 'undefined'
87
- ? options.noDataReceivedTimeout
88
- : -1
89
- if (noDataReceivedTimeout > 0) {
90
- this.noDataInterval = setInterval(() => {
91
- if (
92
- this.channel &&
93
- this.lastDataReceived &&
94
- Date.now() - this.lastDataReceived > noDataReceivedTimeout * 1000
95
- ) {
96
- const channel = this.channel
97
- delete this.channel
98
- try {
99
- channel.stop()
100
- } catch (_error) {}
101
- this.setProviderError('No data received, retrying...')
102
- if (this.options.app) {
103
- console.error('No data received, retrying...')
104
- }
105
- this.connect()
106
- }
107
- }, noDataReceivedTimeout * 1000)
108
- }
109
- }
110
-
111
- CanbusStream.prototype.connect = function () {
112
- const canDevice = this.options.canDevice || 'can0'
113
-
114
- try {
115
- if (this.socketcan === undefined) {
116
- this.setProviderError('unable to load native socketcan interface')
117
- return false
118
- }
119
-
120
- // eslint-disable-next-line @typescript-eslint/no-this-alias
121
- const that = this
122
- this.channel = this.socketcan.createRawChannelWithOptions(canDevice, {
123
- non_block_send: true
124
- })
125
- this.channel.addListener('onStopped', () => {
126
- if (this.channel) {
127
- // stoped by us?
128
- delete this.channel
129
- this.setProviderError('Stopped, Retrying...')
130
- if (this.options.app) {
131
- console.error('socketcan stopped, retrying...')
132
- }
133
- setTimeout(() => {
134
- this.setProviderError('Reconnecting...')
135
- this.connect()
136
- }, 2000)
137
- }
138
- })
139
- this.channel.addListener('onMessage', (msg: any) => {
140
- const pgn = parseCanId(msg.id)
141
-
142
- if (this.noDataInterval) {
143
- this.lastDataReceived = Date.now()
144
- }
145
-
146
- //always send address claims through
147
- if (
148
- pgn.pgn != 60928 &&
149
- that.candevice &&
150
- that.candevice.cansend &&
151
- pgn.src == that.candevice.address
152
- ) {
153
- return
154
- }
155
-
156
- const timestamp = new Date().toISOString()
157
- if (that.plainText) {
158
- this.push(binToActisense(pgn, timestamp, msg.data, msg.data.length))
159
- } else {
160
- that.push({ pgn, length: msg.data.length, data: msg.data })
161
- }
162
- })
163
- this.channel.start()
164
- this.setProviderStatus('Connected to socketcan')
165
- this.candevice = new CanDevice(this, this.options)
166
- this.candevice.start()
167
- return true
168
- } catch (e: any) {
169
- console.error(`unable to open canbus ${canDevice}: ${e}`)
170
- console.error(e.stack)
171
- this.setProviderError(e.message)
172
- return false
173
- }
174
- }
175
-
176
- util.inherits(CanbusStream, Transform)
177
-
178
- CanbusStream.prototype.start = function () {}
179
-
180
- CanbusStream.prototype.sendPGN = function (msg: any, force: boolean) {
181
- if (this.candevice) {
182
- //if ( !this.candevice.cansend && (_.isString(msg) || msg.pgn !== 59904) ) {
183
- if (!this.candevice.cansend && force !== true) {
184
- //we have not completed address claim yet
185
- return
186
- }
187
-
188
- this.debug('sending %j', msg)
189
-
190
- if (this.options.app) {
191
- this.options.app.emit('connectionwrite', {
192
- providerId: this.options.providerId
193
- })
194
- }
195
-
196
- const src =
197
- msg.pgn === 59904 || msg.forceSrc ? msg.src : this.candevice.address
198
- if (_.isString(msg)) {
199
- const split = msg.split(',')
200
- split[3] = src
201
- msg = split.join(',')
202
- } else {
203
- msg.src = src
204
- if (_.isUndefined(msg.prio)) {
205
- msg.prio = 3
206
- }
207
- if (_.isUndefined(msg.dst)) {
208
- msg.dst = 255
209
- }
210
- }
211
-
212
- if (this.socketCanWriter) {
213
- if (_.isString(msg)) {
214
- this.socketCanWriter.stdin.write(msg + '\n')
215
- } else {
216
- const str = toActisenseSerialFormat(
217
- msg.pgn,
218
- toPgn(msg),
219
- msg.dst,
220
- msg.src
221
- )
222
- this.socketCanWriter.stdin.write(str + '\n')
223
- }
224
- } else if (this.channel) {
225
- let canid: number
226
- let buffer: Buffer | undefined
227
- let pgn: any
228
-
229
- if (_.isObject(msg)) {
230
- canid = encodeCanId(msg as CanID)
231
- buffer = toPgn(msg)
232
- pgn = msg
233
- } else {
234
- pgn = parseActisense(msg)
235
- canid = encodeCanId(pgn)
236
- buffer = pgn.data
237
- }
238
-
239
- if (this.debug.enabled) {
240
- const str = toActisenseSerialFormat(pgn.pgn, buffer, pgn.dst, pgn.src)
241
- this.debug(str)
242
- }
243
-
244
- if (buffer === undefined) {
245
- this.debug("can't convert %j", msg)
246
- return
247
- }
248
-
249
- //seems as though 126720 should always be encoded this way
250
- if (buffer.length > 8 || pgn.pgn == 126720) {
251
- const pgns = getPlainPGNs(buffer)
252
- pgns.forEach((pbuffer) => {
253
- this.channel.send({ id: canid, ext: true, data: pbuffer })
254
- })
255
- } else {
256
- this.channel.send({ id: canid, ext: true, data: buffer })
257
- }
258
- }
259
- }
260
- }
261
-
262
- CanbusStream.prototype._transform = function (
263
- chunk: any,
264
- encoding: any,
265
- done: any
266
- ) {
267
- done()
268
- }
269
-
270
- CanbusStream.prototype.end = function () {
271
- if (this.channel) {
272
- const channel = this.channel
273
- delete this.channel
274
- channel.stop()
275
- }
276
- if (this.noDataInterval) {
277
- clearInterval(this.noDataInterval)
278
- }
279
- }
280
-
281
- CanbusStream.prototype.pipe = function (pipeTo: any) {
282
- if (!pipeTo.fromPgn) {
283
- this.plainText = true
284
- }
285
- /*
286
- pipeTo.fromPgn.on('pgn', (pgn) => {
287
- if ( this.candevice ) {
288
- this.candevice.n2kMessage(pgn)
289
- }
290
- })
291
- */
292
- return (CanbusStream as any).super_.prototype.pipe.call(this, pipeTo)
293
- }
package/lib/candevice.ts DELETED
@@ -1,41 +0,0 @@
1
- /**
2
- * Copyright 2018 Scott Bender (scott@scottbender.net) and Jouni Hartikainen (jouni.hartikainen@iki.fi)
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 { N2kDevice } from './n2kDevice'
19
- import _ from 'lodash'
20
-
21
- export class CanDevice extends N2kDevice {
22
- canbus: any
23
-
24
- constructor(canbus: any, options: any) {
25
- super(options, 'canboatjs:candevice')
26
- this.canbus = canbus
27
-
28
- if (options.app) {
29
- options.app.on(
30
- options.analyzerOutEvent || 'N2KAnalyzerOut',
31
- this.n2kMessage.bind(this)
32
- )
33
- }
34
- }
35
-
36
- sendPGN(pgn: PGN, src: number | undefined = undefined) {
37
- pgn.src = src || this.address
38
- this.debug('Sending PGN %j', pgn)
39
- this.canbus.sendPGN(pgn, true)
40
- }
41
- }
package/lib/codes.ts DELETED
@@ -1,21 +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
- export const defaultTransmitPGNs = [
18
- 126992, 128267, 129794, 129038, 129041, 127505, 127506, 127508, 129026,
19
- 129025, 129029, 127250, 130306, 126720, 127489, 127488, 130311, 130312,
20
- 127257, 128259, 127502
21
- ]
package/lib/discovery.ts DELETED
@@ -1,118 +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
- import { createDebug } from './utilities'
18
- import { isYDRAW } from './stringMsg'
19
- import dgram from 'dgram'
20
-
21
- const debug = createDebug('canboatjs:discovery')
22
-
23
- export function discover(app: any) {
24
- if (app.config.settings.pipedProviders) {
25
- const exists = app.config.settings.pipedProviders.find((provider: any) => {
26
- return (
27
- provider.pipeElements &&
28
- provider.pipeElements.length === 1 &&
29
- provider.pipeElements[0].type == 'providers/simple' &&
30
- provider.pipeElements[0].options &&
31
- provider.pipeElements[0].options.type === 'NMEA2000' &&
32
- provider.pipeElements[0].options.subOptions.type ===
33
- 'ydwg02-udp-canboatjs' &&
34
- provider.pipeElements[0].options.subOptions.port === '2002'
35
- )
36
- })
37
-
38
- if (!exists) {
39
- const socket = dgram.createSocket('udp4')
40
- socket.on('message', (buffer: Buffer, _remote: any) => {
41
- const msg = buffer.toString('utf8')
42
- if (isYDRAW(msg)) {
43
- socket.close()
44
- app.emit('discovered', {
45
- id: 'YDGW-02-UDP',
46
- pipeElements: [
47
- {
48
- type: 'providers/simple',
49
- options: {
50
- logging: false,
51
- type: 'NMEA2000',
52
- subOptions: {
53
- type: 'ydwg02-udp-canboatjs',
54
- port: '2002'
55
- }
56
- }
57
- }
58
- ]
59
- })
60
- }
61
- })
62
- socket.on('error', (error: any) => {
63
- debug(error)
64
- })
65
- socket.on('close', () => {
66
- debug('close')
67
- })
68
- debug('looking for YDGW over UDP')
69
- try {
70
- socket.bind(2002)
71
- } catch (ex) {
72
- debug(ex)
73
- }
74
- setTimeout(() => {
75
- if (socket) {
76
- socket.close()
77
- }
78
- }, 5000)
79
- }
80
- }
81
-
82
- /*
83
- if ( app.config.settings.pipedProviders ) {
84
- const exists = app.config.settings.pipedProviders.find(provider => {
85
- return provider.pipeElements
86
- && provider.pipeElements.length === 1
87
- && provider.pipeElements[0].type == 'providers/simple'
88
- && provider.pipeElements[0].options
89
- && provider.pipeElements[0].options.type === 'NMEA2000'
90
- && provider.pipeElements[0].options.subOptions.host === '192.168.88.99'
91
- && provider.pipeElements[0].options.subOptions.port === '1457'
92
- })
93
-
94
- if ( !exists )
95
- {
96
- setTimeout(() =>
97
- app.emit('discovered', {
98
- id: 'TestDiscovered',
99
- pipeElements: [
100
- {
101
- "type": "providers/simple",
102
- "options": {
103
- "logging": false,
104
- "type": "NMEA2000",
105
- "subOptions": {
106
- "type": "ydwg02-canboatjs",
107
- "host": "192.168.88.99",
108
- "port": "1457"
109
- }
110
- }
111
- }
112
- ]
113
- }), 5000)
114
-
115
- }
116
- }
117
- */
118
- }