@canboat/canboatjs 3.0.2 → 3.1.0
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/test.yml +2 -2
- package/.github/workflows/test_canboat_changes.yml +91 -0
- package/.husky/pre-commit +4 -0
- package/.mocharc.js +7 -0
- package/.prettierrc.json +5 -0
- package/README.md +2 -7
- package/dist/actisense-serial.d.ts +17 -0
- package/dist/actisense-serial.d.ts.map +1 -0
- package/dist/actisense-serial.js +569 -0
- package/dist/actisense-serial.js.map +1 -0
- package/dist/bin/actisense-file.d.ts +3 -0
- package/dist/bin/actisense-file.d.ts.map +1 -0
- package/dist/bin/actisense-file.js +49 -0
- package/dist/bin/actisense-file.js.map +1 -0
- package/dist/bin/actisense-n2k-tcp.d.ts +3 -0
- package/dist/bin/actisense-n2k-tcp.d.ts.map +1 -0
- package/dist/bin/actisense-n2k-tcp.js +46 -0
- package/dist/bin/actisense-n2k-tcp.js.map +1 -0
- package/dist/bin/actisense-serialjs.d.ts +3 -0
- package/dist/bin/actisense-serialjs.d.ts.map +1 -0
- package/dist/bin/actisense-serialjs.js +51 -0
- package/dist/bin/actisense-serialjs.js.map +1 -0
- package/dist/bin/analyzerjs.d.ts +3 -0
- package/dist/bin/analyzerjs.d.ts.map +1 -0
- package/dist/bin/analyzerjs.js +61 -0
- package/dist/bin/analyzerjs.js.map +1 -0
- package/dist/bin/candumpanalyzerjs.d.ts +3 -0
- package/dist/bin/candumpanalyzerjs.d.ts.map +1 -0
- package/dist/bin/candumpanalyzerjs.js +31 -0
- package/dist/bin/candumpanalyzerjs.js.map +1 -0
- package/dist/bin/candumpjs.d.ts +3 -0
- package/dist/bin/candumpjs.d.ts.map +1 -0
- package/dist/bin/candumpjs.js +73 -0
- package/dist/bin/candumpjs.js.map +1 -0
- package/dist/bin/cansend.d.ts +3 -0
- package/dist/bin/cansend.d.ts.map +1 -0
- package/dist/bin/cansend.js +123 -0
- package/dist/bin/cansend.js.map +1 -0
- package/dist/bin/ikonvert-serial.d.ts +3 -0
- package/dist/bin/ikonvert-serial.d.ts.map +1 -0
- package/dist/bin/ikonvert-serial.js +36 -0
- package/dist/bin/ikonvert-serial.js.map +1 -0
- package/dist/bin/to-pgn.d.ts +3 -0
- package/dist/bin/to-pgn.d.ts.map +1 -0
- package/dist/bin/to-pgn.js +57 -0
- package/dist/bin/to-pgn.js.map +1 -0
- package/dist/canId.d.ts +21 -0
- package/dist/canId.d.ts.map +1 -0
- package/dist/canId.js +66 -0
- package/dist/canId.js.map +1 -0
- package/dist/canId.test.d.ts +2 -0
- package/dist/canId.test.d.ts.map +1 -0
- package/dist/canId.test.js +58 -0
- package/dist/canId.test.js.map +1 -0
- package/dist/canbus.d.ts +17 -0
- package/dist/canbus.d.ts.map +1 -0
- package/dist/canbus.js +261 -0
- package/dist/canbus.js.map +1 -0
- package/dist/candevice.d.ts +23 -0
- package/dist/candevice.d.ts.map +1 -0
- package/dist/candevice.js +38 -0
- package/dist/candevice.js.map +1 -0
- package/dist/codes.d.ts +2 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/codes.js +24 -0
- package/dist/codes.js.map +1 -0
- package/dist/discovery.d.ts +17 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +119 -0
- package/dist/discovery.js.map +1 -0
- package/dist/fromPgn.d.ts +51 -0
- package/dist/fromPgn.d.ts.map +1 -0
- package/dist/fromPgn.js +989 -0
- package/dist/fromPgn.js.map +1 -0
- package/dist/fromPgnStream.d.ts +17 -0
- package/dist/fromPgnStream.d.ts.map +1 -0
- package/dist/fromPgnStream.js +47 -0
- package/dist/fromPgnStream.js.map +1 -0
- package/dist/ikonvert.d.ts +17 -0
- package/dist/ikonvert.d.ts.map +1 -0
- package/dist/ikonvert.js +224 -0
- package/dist/ikonvert.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/n2k-actisense.d.ts +24 -0
- package/dist/n2k-actisense.d.ts.map +1 -0
- package/dist/n2k-actisense.js +126 -0
- package/dist/n2k-actisense.js.map +1 -0
- package/dist/n2k-actisense.test.d.ts +2 -0
- package/dist/n2k-actisense.test.d.ts.map +1 -0
- package/dist/n2k-actisense.test.js +49 -0
- package/dist/n2k-actisense.test.js.map +1 -0
- package/dist/n2kDevice.d.ts +40 -0
- package/dist/n2kDevice.d.ts.map +1 -0
- package/dist/n2kDevice.js +387 -0
- package/dist/n2kDevice.js.map +1 -0
- package/dist/ncanbus.d.ts +17 -0
- package/dist/ncanbus.d.ts.map +1 -0
- package/dist/ncanbus.js +92 -0
- package/dist/ncanbus.js.map +1 -0
- package/dist/pgns.d.ts +22 -0
- package/dist/pgns.d.ts.map +1 -0
- package/dist/pgns.js +157 -0
- package/dist/pgns.js.map +1 -0
- package/dist/pgns.test.d.ts +2 -0
- package/dist/pgns.test.d.ts.map +1 -0
- package/dist/pgns.test.js +14 -0
- package/dist/pgns.test.js.map +1 -0
- package/dist/simpleCan.d.ts +17 -0
- package/dist/simpleCan.d.ts.map +1 -0
- package/dist/simpleCan.js +125 -0
- package/dist/simpleCan.js.map +1 -0
- package/dist/stringMsg.d.ts +33 -0
- package/dist/stringMsg.d.ts.map +1 -0
- package/dist/stringMsg.js +359 -0
- package/dist/stringMsg.js.map +1 -0
- package/dist/stringMsg.test.d.ts +2 -0
- package/dist/stringMsg.test.d.ts.map +1 -0
- package/dist/stringMsg.test.js +244 -0
- package/dist/stringMsg.test.js.map +1 -0
- package/dist/toPgn.d.ts +34 -0
- package/dist/toPgn.d.ts.map +1 -0
- package/dist/toPgn.js +500 -0
- package/dist/toPgn.js.map +1 -0
- package/dist/utilities.d.ts +26 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +112 -0
- package/dist/utilities.js.map +1 -0
- package/dist/utilities.test.d.ts +2 -0
- package/dist/utilities.test.d.ts.map +1 -0
- package/dist/utilities.test.js +9 -0
- package/dist/utilities.test.js.map +1 -0
- package/dist/venus-mqtt.d.ts +11 -0
- package/dist/venus-mqtt.d.ts.map +1 -0
- package/dist/venus-mqtt.js +100 -0
- package/dist/venus-mqtt.js.map +1 -0
- package/dist/venus.d.ts +11 -0
- package/dist/venus.d.ts.map +1 -0
- package/dist/venus.js +71 -0
- package/dist/venus.js.map +1 -0
- package/dist/w2k01.d.ts +17 -0
- package/dist/w2k01.d.ts.map +1 -0
- package/dist/w2k01.js +119 -0
- package/dist/w2k01.js.map +1 -0
- package/dist/yddevice.d.ts +25 -0
- package/dist/yddevice.d.ts.map +1 -0
- package/dist/yddevice.js +45 -0
- package/dist/yddevice.js.map +1 -0
- package/dist/ydgw02.d.ts +17 -0
- package/dist/ydgw02.d.ts.map +1 -0
- package/dist/ydgw02.js +163 -0
- package/dist/ydgw02.js.map +1 -0
- package/dist/ydvr.d.ts +17 -0
- package/dist/ydvr.d.ts.map +1 -0
- package/dist/ydvr.js +120 -0
- package/dist/ydvr.js.map +1 -0
- package/eslint.config.js +58 -0
- package/jest.config.js +5 -0
- package/lib/actisense-serial.ts +644 -0
- package/lib/bin/actisense-file.ts +53 -0
- package/lib/bin/actisense-n2k-tcp.ts +50 -0
- package/lib/bin/actisense-serialjs.ts +55 -0
- package/{bin/analyzerjs → lib/bin/analyzerjs.ts} +16 -15
- package/{bin/candumpjs → lib/bin/candumpjs.ts} +19 -20
- package/lib/bin/cansend.ts +131 -0
- package/lib/bin/ikonvert-serial.ts +44 -0
- package/{bin/to-pgn → lib/bin/to-pgn.ts} +23 -17
- package/lib/bin/ydvr-file +33 -0
- package/lib/canId.test.js +35 -15
- package/lib/canId.ts +84 -0
- package/lib/canbus.ts +293 -0
- package/lib/{candevice.js → candevice.ts} +14 -21
- package/lib/codes.ts +21 -0
- package/lib/{discovery.js → discovery.ts} +32 -30
- package/lib/fromPgn.ts +1207 -0
- package/lib/{fromPgnStream.js → fromPgnStream.ts} +17 -12
- package/lib/{ikonvert.js → ikonvert.ts} +90 -85
- package/lib/index.ts +48 -0
- package/lib/n2k-actisense.test.js +31 -32
- package/lib/n2k-actisense.ts +152 -0
- package/lib/n2kDevice.ts +458 -0
- package/lib/pgns.test.ts +12 -0
- package/lib/pgns.ts +191 -0
- package/lib/simpleCan.ts +140 -0
- package/lib/stringMsg.test.js +58 -41
- package/lib/stringMsg.ts +464 -0
- package/lib/toPgn.ts +597 -0
- package/lib/{utilities.js → utilities.ts} +48 -37
- package/lib/venus-mqtt.js +69 -73
- package/lib/venus.js +8 -8
- package/lib/{w2k01.js → w2k01.ts} +57 -44
- package/lib/{yddevice.js → yddevice.ts} +18 -13
- package/lib/{ydgw02.js → ydgw02.ts} +55 -47
- package/lib/ydvr.js +65 -147
- package/package.json +54 -18
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/bin/actisense-file +0 -47
- package/bin/actisense-n2k-tcp +0 -45
- package/bin/actisense-serialjs +0 -52
- package/bin/candumpanalyzerjs +0 -29
- package/bin/cansend +0 -130
- package/bin/ikonvert-serial +0 -50
- package/bin/ydgw-analyzerjs +0 -36
- package/bin/ydvr-file +0 -33
- package/index.js +0 -53
- package/lib/canId.js +0 -64
- package/lib/canbus.js +0 -278
- package/lib/codes.js +0 -69
- package/lib/codes.test.js +0 -17
- package/lib/codesMfgs.json +0 -166
- package/lib/fromPgn.js +0 -1027
- package/lib/n2k-actisense.js +0 -108
- package/lib/n2kDevice.js +0 -390
- package/lib/pgns.js +0 -196
- package/lib/pgns.test.js +0 -13
- package/lib/serial.js +0 -647
- package/lib/simpleCan.js +0 -105
- package/lib/stringMsg.js +0 -339
- package/lib/toPgn.js +0 -518
|
@@ -14,30 +14,37 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
import { debug } from 'debug'
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var bucket = 0x40 // 64
|
|
19
|
+
import { CanID } from './canId'
|
|
20
|
+
import { map, padCharsStart, trimChars } from 'lodash/fp'
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
export const createDebug = (name: string) => {
|
|
23
|
+
return debug(name)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getPlainPGNs(buffer: Buffer) {
|
|
27
|
+
const res = []
|
|
28
|
+
let bucket = 0x40 // 64
|
|
29
|
+
|
|
30
|
+
const first = Buffer.alloc(8)
|
|
24
31
|
first.writeUInt8(bucket++, 0)
|
|
25
32
|
first.writeUInt8(buffer.length, 1)
|
|
26
33
|
buffer.copy(first, 2, 0, 6)
|
|
27
34
|
res.push(first)
|
|
28
35
|
|
|
29
|
-
for (
|
|
30
|
-
|
|
36
|
+
for (let index = 6; index < buffer.length; index += 7) {
|
|
37
|
+
const next = Buffer.alloc(8)
|
|
31
38
|
next.writeUInt8(bucket++, 0)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
39
|
+
let end = index + 7
|
|
40
|
+
let fill = 0
|
|
41
|
+
if (end > buffer.length) {
|
|
35
42
|
fill = end - buffer.length
|
|
36
43
|
end = buffer.length
|
|
37
44
|
}
|
|
38
45
|
buffer.copy(next, 1, index, end)
|
|
39
|
-
if (
|
|
40
|
-
for (
|
|
46
|
+
if (fill > 0) {
|
|
47
|
+
for (let i = end - index + 1; i < 8; i++) {
|
|
41
48
|
next.writeUInt8(0xff, i)
|
|
42
49
|
}
|
|
43
50
|
}
|
|
@@ -45,8 +52,6 @@ function getPlainPGNs(buffer) {
|
|
|
45
52
|
}
|
|
46
53
|
return res
|
|
47
54
|
}
|
|
48
|
-
exports.getPlainPGNs = getPlainPGNs
|
|
49
|
-
|
|
50
55
|
|
|
51
56
|
const m_hex = [
|
|
52
57
|
'0',
|
|
@@ -67,13 +72,13 @@ const m_hex = [
|
|
|
67
72
|
'F'
|
|
68
73
|
]
|
|
69
74
|
|
|
70
|
-
function toHexString
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
function toHexString(v: number) {
|
|
76
|
+
const msn = (v >> 4) & 0x0f
|
|
77
|
+
const lsn = (v >> 0) & 0x0f
|
|
73
78
|
return m_hex[msn] + m_hex[lsn]
|
|
74
79
|
}
|
|
75
80
|
|
|
76
|
-
function compute0183Checksum
|
|
81
|
+
export function compute0183Checksum(sentence: string) {
|
|
77
82
|
// skip the $
|
|
78
83
|
let i = 1
|
|
79
84
|
// init to first character
|
|
@@ -85,27 +90,33 @@ function compute0183Checksum (sentence) {
|
|
|
85
90
|
return '*' + toHexString(c1)
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
function binToActisense(
|
|
93
|
+
export function binToActisense(
|
|
94
|
+
pgn: CanID,
|
|
95
|
+
timestamp: string,
|
|
96
|
+
data: Buffer,
|
|
97
|
+
length: number
|
|
98
|
+
) {
|
|
99
|
+
const arr: string[] = []
|
|
89
100
|
return (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.reduce(function(acc, i) {
|
|
94
|
-
acc.push(i.toString(16))
|
|
95
|
-
return acc
|
|
96
|
-
},
|
|
97
|
-
.map(x => (x.length === 1 ?
|
|
98
|
-
.join(
|
|
99
|
-
)
|
|
101
|
+
timestamp +
|
|
102
|
+
`,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
|
|
103
|
+
new Uint32Array(data)
|
|
104
|
+
.reduce(function (acc, i) {
|
|
105
|
+
acc.push(i.toString(16))
|
|
106
|
+
return acc
|
|
107
|
+
}, arr)
|
|
108
|
+
.map((x) => (x.length === 1 ? '0' + x : x))
|
|
109
|
+
.join(',')
|
|
110
|
+
)
|
|
100
111
|
}
|
|
101
112
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
export const trimWrap = trimChars('()<>[]')
|
|
114
|
+
export const rmChecksum = (str: string) =>
|
|
115
|
+
str.includes('*') ? str.split('*', 1)[0] : str
|
|
116
|
+
export const arrBuff = (arr: string[], encoding: BufferEncoding = 'hex') =>
|
|
117
|
+
Buffer.from(arr.join(''), encoding)
|
|
118
|
+
export const hexByte = (x: number) =>
|
|
119
|
+
padCharsStart('0', 2, Number(x).toString(16))
|
|
120
|
+
export const byteString = (data: Buffer, separator = ',') =>
|
|
109
121
|
// Uint32Array map method doesn't work as expect. _.map does.
|
|
110
122
|
map(exports.hexByte, new Uint32Array(data)).join(separator)
|
|
111
|
-
)
|
package/lib/venus-mqtt.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
1
|
const Transform = require('stream').Transform
|
|
3
|
-
const mqtt = require('mqtt')
|
|
2
|
+
const mqtt = require('mqtt')
|
|
4
3
|
const debug = require('debug')('venus-mqtt')
|
|
5
4
|
//const pgns = require('./fromPgn').pgns
|
|
6
5
|
const _ = require('lodash')
|
|
7
6
|
|
|
8
|
-
function MQTTStream
|
|
7
|
+
function MQTTStream(options) {
|
|
9
8
|
Transform.call(this, {
|
|
10
9
|
objectMode: true
|
|
11
10
|
})
|
|
@@ -14,109 +13,106 @@ function MQTTStream (options) {
|
|
|
14
13
|
|
|
15
14
|
require('util').inherits(MQTTStream, Transform)
|
|
16
15
|
|
|
17
|
-
MQTTStream.prototype.discoveryAvailable = function() {
|
|
18
|
-
return moduleAvailable('md' + 'ns')
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function mysleep(millis) {
|
|
22
|
-
return new Promise(resolve => setTimeout(resolve, millis));
|
|
16
|
+
MQTTStream.prototype.discoveryAvailable = function () {
|
|
17
|
+
return moduleAvailable('md' + 'ns')
|
|
23
18
|
}
|
|
24
19
|
|
|
25
20
|
MQTTStream.prototype.pipe = function (pipeTo) {
|
|
26
21
|
const that = this
|
|
27
|
-
this.startDiscovery()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
/*
|
|
42
38
|
pgns.forEach(key => {
|
|
43
39
|
debug(`adding pgn ${key}`)
|
|
44
40
|
client.publish('n2k/mqtt_n2k/addpgn', key)
|
|
45
41
|
//require('sleep').msleep(100)
|
|
46
42
|
})
|
|
47
43
|
*/
|
|
48
|
-
|
|
49
|
-
})
|
|
44
|
+
})
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
client.on('error', (error) => {
|
|
47
|
+
this.options.app.setProviderError(`error connecting to mqtt ${error}`)
|
|
48
|
+
})
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
client.on('close', () => {
|
|
51
|
+
this.options.app.setProviderError(`mqtt close`)
|
|
52
|
+
})
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
client.on('reconnect', () => {
|
|
55
|
+
//this.(`mqtt reconnect`)
|
|
56
|
+
})
|
|
62
57
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
})
|
|
69
65
|
})
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
.catch((error) => {
|
|
67
|
+
debug(error)
|
|
68
|
+
this.options.app.setProviderStatus(error.msg)
|
|
69
|
+
})
|
|
70
|
+
|
|
75
71
|
Transform.prototype.pipe.call(this, pipeTo)
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
MQTTStream.prototype.startDiscovery = function() {
|
|
79
|
-
var that = this
|
|
80
|
-
return new Promise(function(resolve, reject) {
|
|
74
|
+
MQTTStream.prototype.startDiscovery = function () {
|
|
75
|
+
var that = this
|
|
76
|
+
return new Promise(function (resolve, reject) {
|
|
81
77
|
if (!that.discoveryAvailable()) {
|
|
82
|
-
console.log(
|
|
83
|
-
|
|
84
|
-
);
|
|
85
|
-
reject('Discovery requires mdns');
|
|
78
|
+
console.log('Discovery requires mdns or specify hostname and port')
|
|
79
|
+
reject('Discovery requires mdns')
|
|
86
80
|
}
|
|
87
|
-
|
|
88
|
-
var mdns = require('md' + 'ns')
|
|
89
|
-
|
|
81
|
+
|
|
82
|
+
var mdns = require('md' + 'ns')
|
|
83
|
+
|
|
90
84
|
function doStart(serviceName) {
|
|
91
85
|
let browser = mdns.createBrowser(mdns.tcp(serviceName), {
|
|
92
|
-
resolverSequence: [mdns.rst.DNSServiceResolve()]
|
|
93
|
-
})
|
|
94
|
-
browser.on('serviceUp', function(service) {
|
|
95
|
-
debug(`Discovered ${serviceName}:` + JSON.stringify(service, null, 2))
|
|
86
|
+
resolverSequence: [mdns.rst.DNSServiceResolve()]
|
|
87
|
+
})
|
|
88
|
+
browser.on('serviceUp', function (service) {
|
|
89
|
+
debug(`Discovered ${serviceName}:` + JSON.stringify(service, null, 2))
|
|
96
90
|
//that.get('/signalk', service.host, service.port, isHttps ? 'https' : 'http').then(function(response) {
|
|
97
|
-
debug(
|
|
91
|
+
debug(
|
|
92
|
+
`Service at ${service.host}:${service.port} ${service.txtRecord.base_topic}`
|
|
93
|
+
)
|
|
98
94
|
resolve(service)
|
|
99
|
-
})
|
|
100
|
-
debug(`Starting ${serviceName} discovery`)
|
|
101
|
-
browser.start()
|
|
95
|
+
})
|
|
96
|
+
debug(`Starting ${serviceName} discovery`)
|
|
97
|
+
browser.start()
|
|
102
98
|
return browser
|
|
103
99
|
}
|
|
104
|
-
|
|
100
|
+
|
|
105
101
|
this.browser = doStart('mqtt-n2k')
|
|
106
102
|
})
|
|
107
103
|
}
|
|
108
|
-
|
|
109
104
|
|
|
110
|
-
MQTTStream.prototype._transform = function (
|
|
105
|
+
MQTTStream.prototype._transform = function (_data, _encoding, _callback) {}
|
|
111
106
|
|
|
112
107
|
function moduleAvailable(name) {
|
|
113
108
|
try {
|
|
114
|
-
require.resolve(name)
|
|
115
|
-
return true
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
require.resolve(name)
|
|
110
|
+
return true
|
|
111
|
+
// eslint-disable-next-line no-empty
|
|
112
|
+
} catch (_e) {}
|
|
113
|
+
return false
|
|
118
114
|
}
|
|
119
115
|
|
|
120
|
-
module.exports = MQTTStream
|
|
116
|
+
module.exports.VenusMQTT = MQTTStream
|
|
121
117
|
|
|
122
|
-
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']
|
|
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
CHANGED
|
@@ -19,7 +19,7 @@ const Transform = require('stream').Transform
|
|
|
19
19
|
const FromPgn = require('./fromPgn').Parser
|
|
20
20
|
const _ = require('lodash')
|
|
21
21
|
|
|
22
|
-
function VenusStream
|
|
22
|
+
function VenusStream(options) {
|
|
23
23
|
if (!(this instanceof VenusStream)) {
|
|
24
24
|
return new VenusStream(options)
|
|
25
25
|
}
|
|
@@ -47,7 +47,6 @@ function VenusStream (options) {
|
|
|
47
47
|
debug(`[error] ${pgn.pgn} ${error}`)
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
/*
|
|
52
51
|
if ( this.options.app ) {
|
|
53
52
|
options.app.on('nmea2000out', (msg) => {
|
|
@@ -67,22 +66,23 @@ function VenusStream (options) {
|
|
|
67
66
|
|
|
68
67
|
require('util').inherits(VenusStream, Transform)
|
|
69
68
|
|
|
70
|
-
|
|
71
69
|
VenusStream.prototype._transform = function (pgn, encoding, done) {
|
|
72
70
|
//let line = chunk.toString().trim()
|
|
73
71
|
//line = line.substring(0, line.length) // take off the \r
|
|
74
72
|
|
|
75
73
|
this.fromPgn.parseVenusMQTT(pgn, (error, pgn) => {
|
|
76
|
-
if (
|
|
74
|
+
if (!error) {
|
|
77
75
|
this.push(pgn)
|
|
78
|
-
this.options.app.emit(
|
|
76
|
+
this.options.app.emit(
|
|
77
|
+
this.options.analyzerOutEvent || 'N2KAnalyzerOut',
|
|
78
|
+
pgn
|
|
79
|
+
)
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
done()
|
|
82
83
|
})
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
VenusStream.prototype.end = function () {
|
|
86
|
-
}
|
|
86
|
+
VenusStream.prototype.end = function () {}
|
|
87
87
|
|
|
88
|
-
module.exports = VenusStream
|
|
88
|
+
module.exports.VenusStream = VenusStream
|
|
@@ -14,21 +14,34 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 debug = createDebug('canboatjs:w2k01')
|
|
30
|
+
const debugData = createDebug('canboatjs:w2k01-data')
|
|
31
|
+
|
|
32
|
+
//const pgnsSent = {}
|
|
25
33
|
|
|
26
34
|
const N2K_ASCII = 0
|
|
27
35
|
const N2K_ACTISENSE = 1
|
|
28
36
|
|
|
29
|
-
function W2K01Stream
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
export function W2K01Stream(
|
|
38
|
+
this: any,
|
|
39
|
+
options: any,
|
|
40
|
+
type: string,
|
|
41
|
+
outEvent: string
|
|
42
|
+
) {
|
|
43
|
+
if (this === undefined) {
|
|
44
|
+
return new (W2K01Stream as any)(options, type, outEvent)
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
Transform.call(this, {
|
|
@@ -41,18 +54,18 @@ function W2K01Stream (options, type, outEvent) {
|
|
|
41
54
|
|
|
42
55
|
this.format = type === 'ascii' ? N2K_ASCII : N2K_ACTISENSE
|
|
43
56
|
|
|
44
|
-
if (
|
|
45
|
-
if (
|
|
46
|
-
options.app.on(this.options.outEevent || 'nmea2000out', (msg) => {
|
|
47
|
-
if (
|
|
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') {
|
|
48
61
|
this.sendW2KPGN(msg)
|
|
49
62
|
} else {
|
|
50
63
|
this.sendPGN(msg)
|
|
51
64
|
}
|
|
52
65
|
options.app.emit('connectionwrite', { providerId: options.providerId })
|
|
53
66
|
})
|
|
54
|
-
|
|
55
|
-
options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
|
|
67
|
+
|
|
68
|
+
options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg: PGN) => {
|
|
56
69
|
this.sendPGN(msg)
|
|
57
70
|
options.app.emit('connectionwrite', { providerId: options.providerId })
|
|
58
71
|
})
|
|
@@ -62,68 +75,68 @@ function W2K01Stream (options, type, outEvent) {
|
|
|
62
75
|
debug('started')
|
|
63
76
|
}
|
|
64
77
|
|
|
65
|
-
W2K01Stream.prototype.send = function (msg) {
|
|
78
|
+
W2K01Stream.prototype.send = function (msg: string | Buffer) {
|
|
66
79
|
debug('sending %s', msg)
|
|
67
80
|
this.options.app.emit(this.outEvent, msg)
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
W2K01Stream.prototype.sendPGN = function (pgn) {
|
|
71
|
-
|
|
72
|
-
let lastSent = pgnsSent[pgn.pgn]
|
|
73
|
-
if (
|
|
74
|
-
|
|
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)
|
|
75
88
|
this.send(ascii + '\r\n')
|
|
76
89
|
} else {
|
|
77
|
-
|
|
90
|
+
const buf = pgnToN2KActisenseFormat(pgn)
|
|
78
91
|
this.send(buf)
|
|
79
92
|
}
|
|
80
|
-
pgnsSent[pgn.pgn] = now
|
|
93
|
+
//pgnsSent[pgn.pgn] = now
|
|
81
94
|
}
|
|
82
95
|
|
|
83
|
-
W2K01Stream.prototype.sendW2KPGN = function (msg) {
|
|
84
|
-
if (
|
|
85
|
-
|
|
96
|
+
W2K01Stream.prototype.sendW2KPGN = function (msg: string) {
|
|
97
|
+
if (this.format === N2K_ASCII) {
|
|
98
|
+
const ascii = actisenseToN2KAsciiFormat(msg)
|
|
86
99
|
this.send(ascii + '\r\n')
|
|
87
100
|
} else {
|
|
88
|
-
|
|
101
|
+
const buf = actisenseToN2KActisenseFormat
|
|
89
102
|
this.send(buf)
|
|
90
103
|
}
|
|
91
104
|
}
|
|
92
105
|
|
|
93
|
-
|
|
106
|
+
util.inherits(W2K01Stream, Transform)
|
|
94
107
|
|
|
95
|
-
W2K01Stream.prototype._transform = function (
|
|
96
|
-
|
|
108
|
+
W2K01Stream.prototype._transform = function (
|
|
109
|
+
chunk: any,
|
|
110
|
+
encoding: string,
|
|
111
|
+
done: any
|
|
112
|
+
) {
|
|
113
|
+
if (!this.sentAvailable && this.format === N2K_ASCII) {
|
|
97
114
|
debug('emit nmea2000OutAvailable')
|
|
98
115
|
this.options.app.emit('nmea2000OutAvailable')
|
|
99
116
|
this.sentAvailable = true
|
|
100
117
|
}
|
|
101
118
|
|
|
102
|
-
if (
|
|
103
|
-
if (
|
|
119
|
+
if (this.format === N2K_ASCII) {
|
|
120
|
+
if (debugData.enabled) {
|
|
104
121
|
debugData('Received: ' + chunk)
|
|
105
122
|
}
|
|
106
123
|
this.push(chunk)
|
|
107
124
|
} else {
|
|
108
|
-
readN2KActisense(chunk, this.plainText, this, (data) => {
|
|
125
|
+
readN2KActisense(chunk, this.plainText, this, (data: any) => {
|
|
109
126
|
this.push(data)
|
|
110
127
|
})
|
|
111
128
|
}
|
|
112
|
-
|
|
129
|
+
|
|
113
130
|
done()
|
|
114
131
|
}
|
|
115
132
|
|
|
116
|
-
W2K01Stream.prototype.pipe = function (pipeTo) {
|
|
117
|
-
if (
|
|
133
|
+
W2K01Stream.prototype.pipe = function (pipeTo: any) {
|
|
134
|
+
if (!pipeTo.fromPgn) {
|
|
118
135
|
this.plainText = true
|
|
119
136
|
} else {
|
|
120
137
|
this.plainText = false
|
|
121
138
|
}
|
|
122
|
-
return W2K01Stream.super_.prototype.pipe.call(this, pipeTo)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
W2K01Stream.prototype.end = function () {
|
|
139
|
+
return (W2K01Stream as any).super_.prototype.pipe.call(this, pipeTo)
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
|
|
142
|
+
W2K01Stream.prototype.end = function () {}
|
|
@@ -14,33 +14,38 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { PGN } from '@canboat/ts-pgns'
|
|
18
|
+
import { N2kDevice } from './n2kDevice'
|
|
19
|
+
import { actisenseToYdgwFullRawFormat } from './toPgn'
|
|
20
|
+
import { createDebug } from './utilities'
|
|
17
21
|
|
|
18
|
-
const debug =
|
|
19
|
-
const N2kDevice = require('./n2kDevice')
|
|
22
|
+
const debug = createDebug('canboatjs:n2kdevice')
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
export class YdDevice extends N2kDevice {
|
|
25
|
+
app: any
|
|
26
|
+
n2kOutEvent: string
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
constructor (options) {
|
|
28
|
+
constructor(options: any) {
|
|
25
29
|
super(options)
|
|
26
30
|
this.app = options.app
|
|
27
31
|
this.n2kOutEvent = options.jsonOutEvent || 'nmea2000JsonOut'
|
|
28
|
-
|
|
32
|
+
|
|
29
33
|
const analyzerOutEvent = options.analyzerOutEvent || 'N2KAnalyzerOut'
|
|
30
|
-
|
|
31
|
-
this.app.on(
|
|
34
|
+
|
|
35
|
+
this.app.on(analyzerOutEvent, this.n2kMessage.bind(this))
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
sendPGN(pgn, src) {
|
|
38
|
+
sendPGN(pgn: PGN, src: number | undefined = undefined) {
|
|
35
39
|
pgn.src = src || this.address
|
|
36
|
-
|
|
40
|
+
|
|
41
|
+
const ppgn = pgn as any //FIXME??
|
|
42
|
+
ppgn.ydFullFormat = true
|
|
43
|
+
|
|
37
44
|
debug('Sending PGN %j', pgn)
|
|
38
45
|
this.app.emit(this.n2kOutEvent, pgn)
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
sendActisenseFormat(msg) {
|
|
48
|
+
sendActisenseFormat(msg: string) {
|
|
42
49
|
this.app.emit('ydFullRawOut', actisenseToYdgwFullRawFormat(msg))
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
|
-
|
|
46
|
-
module.exports = YdDevice
|