@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.
Files changed (79) 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 +35 -8
  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/dist/stringMsg.d.ts +2 -0
  27. package/dist/stringMsg.d.ts.map +1 -1
  28. package/dist/stringMsg.js +18 -1
  29. package/dist/stringMsg.js.map +1 -1
  30. package/dist/stringMsg.test.js +15 -1
  31. package/dist/stringMsg.test.js.map +1 -1
  32. package/package.json +3 -2
  33. package/tsconfig.tsbuildinfo +1 -1
  34. package/.github/workflows/publish.yml +0 -32
  35. package/.github/workflows/release_on_tag.yml +0 -27
  36. package/.github/workflows/require_pr_label.yml +0 -13
  37. package/.github/workflows/test.yml +0 -28
  38. package/.github/workflows/test_canboat_changes.yml +0 -92
  39. package/examples/signalk-device-emulator/index.js +0 -1
  40. package/examples/signalk-device-emulator/package.json +0 -24
  41. package/examples/simpleCan.js +0 -42
  42. package/ios.js +0 -67
  43. package/lib/actisense-serial.ts +0 -644
  44. package/lib/bin/actisense-file.ts +0 -53
  45. package/lib/bin/actisense-n2k-tcp.ts +0 -50
  46. package/lib/bin/actisense-serialjs.ts +0 -55
  47. package/lib/bin/analyzerjs.ts +0 -66
  48. package/lib/bin/candumpjs.ts +0 -100
  49. package/lib/bin/cansend.ts +0 -131
  50. package/lib/bin/ikonvert-serial.ts +0 -44
  51. package/lib/bin/to-pgn.ts +0 -65
  52. package/lib/bin/ydvr-file +0 -33
  53. package/lib/canId.test.js +0 -61
  54. package/lib/canId.ts +0 -84
  55. package/lib/canbus.ts +0 -293
  56. package/lib/candevice.ts +0 -41
  57. package/lib/codes.ts +0 -21
  58. package/lib/discovery.ts +0 -118
  59. package/lib/fromPgn.ts +0 -1217
  60. package/lib/fromPgnStream.ts +0 -54
  61. package/lib/ikonvert.ts +0 -250
  62. package/lib/index.ts +0 -48
  63. package/lib/n2k-actisense.test.js +0 -58
  64. package/lib/n2k-actisense.ts +0 -152
  65. package/lib/n2kDevice.ts +0 -509
  66. package/lib/pgns.test.ts +0 -12
  67. package/lib/pgns.ts +0 -191
  68. package/lib/simpleCan.ts +0 -140
  69. package/lib/stringMsg.test.js +0 -273
  70. package/lib/stringMsg.ts +0 -464
  71. package/lib/toPgn.ts +0 -601
  72. package/lib/utilities.test.js +0 -8
  73. package/lib/utilities.ts +0 -169
  74. package/lib/venus-mqtt.js +0 -118
  75. package/lib/venus.js +0 -88
  76. package/lib/w2k01.ts +0 -142
  77. package/lib/yddevice.ts +0 -48
  78. package/lib/ydgw02.ts +0 -197
  79. package/lib/ydvr.js +0 -138
package/lib/utilities.ts DELETED
@@ -1,169 +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 { debug } from 'debug'
18
- import { CanID } from './canId'
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
46
-
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
- }
71
- }
72
-
73
- export function getPlainPGNs(buffer: Buffer) {
74
- const res = []
75
- let bucket = 0x40 // 64
76
-
77
- const first = Buffer.alloc(8)
78
- first.writeUInt8(bucket++, 0)
79
- first.writeUInt8(buffer.length, 1)
80
- buffer.copy(first, 2, 0, 6)
81
- res.push(first)
82
-
83
- for (let index = 6; index < buffer.length; index += 7) {
84
- const next = Buffer.alloc(8)
85
- next.writeUInt8(bucket++, 0)
86
- let end = index + 7
87
- let fill = 0
88
- if (end > buffer.length) {
89
- fill = end - buffer.length
90
- end = buffer.length
91
- }
92
- buffer.copy(next, 1, index, end)
93
- if (fill > 0) {
94
- for (let i = end - index + 1; i < 8; i++) {
95
- next.writeUInt8(0xff, i)
96
- }
97
- }
98
- res.push(next)
99
- }
100
- return res
101
- }
102
-
103
- const m_hex = [
104
- '0',
105
- '1',
106
- '2',
107
- '3',
108
- '4',
109
- '5',
110
- '6',
111
- '7',
112
- '8',
113
- '9',
114
- 'A',
115
- 'B',
116
- 'C',
117
- 'D',
118
- 'E',
119
- 'F'
120
- ]
121
-
122
- function toHexString(v: number) {
123
- const msn = (v >> 4) & 0x0f
124
- const lsn = (v >> 0) & 0x0f
125
- return m_hex[msn] + m_hex[lsn]
126
- }
127
-
128
- export function compute0183Checksum(sentence: string) {
129
- // skip the $
130
- let i = 1
131
- // init to first character
132
- let c1 = sentence.charCodeAt(i)
133
- // process rest of characters, zero delimited
134
- for (i = 2; i < sentence.length; ++i) {
135
- c1 = c1 ^ sentence.charCodeAt(i)
136
- }
137
- return '*' + toHexString(c1)
138
- }
139
-
140
- export function binToActisense(
141
- pgn: CanID,
142
- timestamp: string,
143
- data: Buffer,
144
- length: number
145
- ) {
146
- const arr: string[] = []
147
- return (
148
- timestamp +
149
- `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
150
- new Uint32Array(data)
151
- .reduce(function (acc, i) {
152
- acc.push(i.toString(16))
153
- return acc
154
- }, arr)
155
- .map((x) => (x.length === 1 ? '0' + x : x))
156
- .join(',')
157
- )
158
- }
159
-
160
- export const trimWrap = trimChars('()<>[]')
161
- export const rmChecksum = (str: string) =>
162
- str.includes('*') ? str.split('*', 1)[0] : str
163
- export const arrBuff = (arr: string[], encoding: BufferEncoding = 'hex') =>
164
- Buffer.from(arr.join(''), encoding)
165
- export const hexByte = (x: number) =>
166
- padCharsStart('0', 2, Number(x).toString(16))
167
- export const byteString = (data: Buffer, separator = ',') =>
168
- // Uint32Array map method doesn't work as expect. _.map does.
169
- map(exports.hexByte, new Uint32Array(data)).join(separator)
package/lib/venus-mqtt.js DELETED
@@ -1,118 +0,0 @@
1
- const Transform = require('stream').Transform
2
- const mqtt = require('mqtt')
3
- const debug = require('debug')('venus-mqtt')
4
- //const pgns = require('./fromPgn').pgns
5
- const _ = require('lodash')
6
-
7
- function MQTTStream(options) {
8
- Transform.call(this, {
9
- objectMode: true
10
- })
11
- this.options = options
12
- }
13
-
14
- require('util').inherits(MQTTStream, Transform)
15
-
16
- MQTTStream.prototype.discoveryAvailable = function () {
17
- return moduleAvailable('md' + 'ns')
18
- }
19
-
20
- MQTTStream.prototype.pipe = function (pipeTo) {
21
- const that = this
22
- this.startDiscovery()
23
- .then((service) => {
24
- let url = service.txtRecord.mqtt_broker
25
- var client = mqtt.connect(url)
26
- client.on('connect', function () {
27
- debug(`connected to ${url}`)
28
-
29
- client.subscribe('n2k/mqtt_n2k/self')
30
- //client.subscribe('n2k/mqtt_n2k/listenpgns')
31
- client.publish('n2k/mqtt_n2k/getself')
32
- client.publish('n2k/mqtt_n2k/addpgn', '129026')
33
- client.publish('n2k/mqtt_n2k/addpgn', '129025')
34
- //client.publish('n2k/mqtt_n2k/getlistenpgns')
35
- client.subscribe('n2k/mqtt_n2k/bus/#')
36
-
37
- /*
38
- pgns.forEach(key => {
39
- debug(`adding pgn ${key}`)
40
- client.publish('n2k/mqtt_n2k/addpgn', key)
41
- //require('sleep').msleep(100)
42
- })
43
- */
44
- })
45
-
46
- client.on('error', (error) => {
47
- this.options.app.setProviderError(`error connecting to mqtt ${error}`)
48
- })
49
-
50
- client.on('close', () => {
51
- this.options.app.setProviderError(`mqtt close`)
52
- })
53
-
54
- client.on('reconnect', () => {
55
- //this.(`mqtt reconnect`)
56
- })
57
-
58
- client.on('message', (topic, json) => {
59
- debug(`${topic}: '${json}'`)
60
- const pgn = JSON.parse(json)
61
- if (topic.startsWith('n2k/mqtt_n2k/bus/')) {
62
- that.push(pgn)
63
- }
64
- })
65
- })
66
- .catch((error) => {
67
- debug(error)
68
- this.options.app.setProviderStatus(error.msg)
69
- })
70
-
71
- Transform.prototype.pipe.call(this, pipeTo)
72
- }
73
-
74
- MQTTStream.prototype.startDiscovery = function () {
75
- var that = this
76
- return new Promise(function (resolve, reject) {
77
- if (!that.discoveryAvailable()) {
78
- console.log('Discovery requires mdns or specify hostname and port')
79
- reject('Discovery requires mdns')
80
- }
81
-
82
- var mdns = require('md' + 'ns')
83
-
84
- function doStart(serviceName) {
85
- let browser = mdns.createBrowser(mdns.tcp(serviceName), {
86
- resolverSequence: [mdns.rst.DNSServiceResolve()]
87
- })
88
- browser.on('serviceUp', function (service) {
89
- debug(`Discovered ${serviceName}:` + JSON.stringify(service, null, 2))
90
- //that.get('/signalk', service.host, service.port, isHttps ? 'https' : 'http').then(function(response) {
91
- debug(
92
- `Service at ${service.host}:${service.port} ${service.txtRecord.base_topic}`
93
- )
94
- resolve(service)
95
- })
96
- debug(`Starting ${serviceName} discovery`)
97
- browser.start()
98
- return browser
99
- }
100
-
101
- this.browser = doStart('mqtt-n2k')
102
- })
103
- }
104
-
105
- MQTTStream.prototype._transform = function (_data, _encoding, _callback) {}
106
-
107
- function moduleAvailable(name) {
108
- try {
109
- require.resolve(name)
110
- return true
111
- // eslint-disable-next-line no-empty
112
- } catch (_e) {}
113
- return false
114
- }
115
-
116
- module.exports.VenusMQTT = MQTTStream
117
-
118
- //const pgns = [ '126992','127505','129029','129291','130312','127245','127506','129038','129793','130314','127250','127508','129039','129794','130577','127251','128259','129040','129809','130842','127257','128267','129041','129810','127258','128275','129283','130306','127488','129025','129284','130310','127489','129026','129285','130311']
package/lib/venus.js DELETED
@@ -1,88 +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
- const debug = require('debug')('canboatjs:venus')
18
- const Transform = require('stream').Transform
19
- const FromPgn = require('./fromPgn').Parser
20
- const _ = require('lodash')
21
-
22
- function VenusStream(options) {
23
- if (!(this instanceof VenusStream)) {
24
- return new VenusStream(options)
25
- }
26
-
27
- Transform.call(this, {
28
- objectMode: true
29
- })
30
-
31
- this.options = options
32
-
33
- this.fromPgn = new FromPgn(options)
34
-
35
- debug('created FromPgn')
36
-
37
- /*
38
- this.fromPgn.on('pgn', pgn => {
39
- })
40
- */
41
-
42
- this.fromPgn.on('warning', (pgn, warning) => {
43
- debug(`[warning] ${pgn.pgn} ${warning}`)
44
- })
45
-
46
- this.fromPgn.on('error', (pgn, error) => {
47
- debug(`[error] ${pgn.pgn} ${error}`)
48
- })
49
-
50
- /*
51
- if ( this.options.app ) {
52
- options.app.on('nmea2000out', (msg) => {
53
- that.sendActisensePGN(msg)
54
- })
55
- options.app.on('nmea2000JsonOut', (msg) => {
56
- that.sendPGN(msg)
57
- })
58
-
59
- this.sendString('$PDGY,N2NET_OFFLINE')
60
-
61
- debug('started')
62
- //this.options.app.emit('nmea2000OutAvailable')
63
- }
64
- */
65
- }
66
-
67
- require('util').inherits(VenusStream, Transform)
68
-
69
- VenusStream.prototype._transform = function (pgn, encoding, done) {
70
- //let line = chunk.toString().trim()
71
- //line = line.substring(0, line.length) // take off the \r
72
-
73
- this.fromPgn.parseVenusMQTT(pgn, (error, pgn) => {
74
- if (!error) {
75
- this.push(pgn)
76
- this.options.app.emit(
77
- this.options.analyzerOutEvent || 'N2KAnalyzerOut',
78
- pgn
79
- )
80
- }
81
-
82
- done()
83
- })
84
- }
85
-
86
- VenusStream.prototype.end = function () {}
87
-
88
- module.exports.VenusStream = VenusStream
package/lib/w2k01.ts DELETED
@@ -1,142 +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 {
21
- pgnToActisenseN2KAsciiFormat,
22
- actisenseToN2KAsciiFormat,
23
- pgnToN2KActisenseFormat,
24
- actisenseToN2KActisenseFormat
25
- } from './toPgn'
26
- import { readN2KActisense } from './n2k-actisense'
27
- import util from 'util'
28
-
29
- //const pgnsSent = {}
30
-
31
- const N2K_ASCII = 0
32
- const N2K_ACTISENSE = 1
33
-
34
- export function W2K01Stream(
35
- this: any,
36
- options: any,
37
- type: string,
38
- outEvent: string
39
- ) {
40
- if (this === undefined) {
41
- return new (W2K01Stream as any)(options, type, outEvent)
42
- }
43
-
44
- Transform.call(this, {
45
- objectMode: true
46
- })
47
-
48
- this.debug = createDebug('canboatjs:w2k01', options)
49
- this.debugData = createDebug('canboatjs:w2k01-data', options)
50
-
51
- this.sentAvailable = false
52
- this.options = options
53
- this.outEvent = outEvent || 'w2k-1-out'
54
-
55
- this.format = type === 'ascii' ? N2K_ASCII : N2K_ACTISENSE
56
-
57
- if (this.format === N2K_ASCII) {
58
- if (options.app) {
59
- options.app.on(this.options.outEevent || 'nmea2000out', (msg: string) => {
60
- if (typeof msg === 'string') {
61
- this.sendW2KPGN(msg)
62
- } else {
63
- this.sendPGN(msg)
64
- }
65
- options.app.emit('connectionwrite', { providerId: options.providerId })
66
- })
67
-
68
- options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
69
- this.sendPGN(msg)
70
- options.app.emit('connectionwrite', { providerId: options.providerId })
71
- })
72
- }
73
- }
74
-
75
- this.debug('started')
76
- }
77
-
78
- W2K01Stream.prototype.send = function (msg: string | Buffer) {
79
- this.debug('sending %s', msg)
80
- this.options.app.emit(this.outEvent, msg)
81
- }
82
-
83
- W2K01Stream.prototype.sendPGN = function (pgn: PGN) {
84
- //const now = Date.now()
85
- //let lastSent = pgnsSent[pgn.pgn]
86
- if (this.format === N2K_ASCII) {
87
- const ascii = pgnToActisenseN2KAsciiFormat(pgn)
88
- this.send(ascii + '\r\n')
89
- } else {
90
- const buf = pgnToN2KActisenseFormat(pgn)
91
- this.send(buf)
92
- }
93
- //pgnsSent[pgn.pgn] = now
94
- }
95
-
96
- W2K01Stream.prototype.sendW2KPGN = function (msg: string) {
97
- if (this.format === N2K_ASCII) {
98
- const ascii = actisenseToN2KAsciiFormat(msg)
99
- this.send(ascii + '\r\n')
100
- } else {
101
- const buf = actisenseToN2KActisenseFormat
102
- this.send(buf)
103
- }
104
- }
105
-
106
- util.inherits(W2K01Stream, Transform)
107
-
108
- W2K01Stream.prototype._transform = function (
109
- chunk: any,
110
- encoding: string,
111
- done: any
112
- ) {
113
- if (!this.sentAvailable && this.format === N2K_ASCII) {
114
- this.debug('emit nmea2000OutAvailable')
115
- this.options.app.emit('nmea2000OutAvailable')
116
- this.sentAvailable = true
117
- }
118
-
119
- if (this.format === N2K_ASCII) {
120
- if (this.debugData.enabled) {
121
- this.debugData('Received: ' + chunk)
122
- }
123
- this.push(chunk)
124
- } else {
125
- readN2KActisense(chunk, this.plainText, this, (data: any) => {
126
- this.push(data)
127
- })
128
- }
129
-
130
- done()
131
- }
132
-
133
- W2K01Stream.prototype.pipe = function (pipeTo: any) {
134
- if (!pipeTo.fromPgn) {
135
- this.plainText = true
136
- } else {
137
- this.plainText = false
138
- }
139
- return (W2K01Stream as any).super_.prototype.pipe.call(this, pipeTo)
140
- }
141
-
142
- W2K01Stream.prototype.end = function () {}
package/lib/yddevice.ts DELETED
@@ -1,48 +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 { N2kDevice } from './n2kDevice'
19
- import { actisenseToYdgwFullRawFormat } from './toPgn'
20
-
21
- export class YdDevice extends N2kDevice {
22
- app: any
23
- n2kOutEvent: string
24
-
25
- constructor(options: any) {
26
- super(options, 'canboatjs:yddevice')
27
- this.app = options.app
28
- this.n2kOutEvent = options.jsonOutEvent || 'nmea2000JsonOut'
29
-
30
- const analyzerOutEvent = options.analyzerOutEvent || 'N2KAnalyzerOut'
31
-
32
- this.app.on(analyzerOutEvent, this.n2kMessage.bind(this))
33
- }
34
-
35
- sendPGN(pgn: PGN, src: number | undefined = undefined) {
36
- pgn.src = src || this.address
37
-
38
- const ppgn = pgn as any //FIXME??
39
- ppgn.ydFullFormat = true
40
-
41
- this.debug('Sending PGN %j', pgn)
42
- this.app.emit(this.n2kOutEvent, pgn)
43
- }
44
-
45
- sendActisenseFormat(msg: string) {
46
- this.app.emit('ydFullRawOut', actisenseToYdgwFullRawFormat(msg))
47
- }
48
- }