@canboat/canboatjs 2.11.0 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +3 -3
- package/bin/analyzerjs +8 -2
- package/bin/to-pgn +3 -4
- package/index.js +0 -3
- package/ios_canboat.js/main.js +2 -0
- package/ios_canboat.js/main.js.LICENSE.txt +17 -0
- package/ios_canboat.js/main.js.map +1 -0
- package/lib/candevice.js +330 -8
- package/lib/fromPgn.js +32 -9
- package/lib/pgns.js +3 -2
- package/lib/simpleCan.js +1 -5
- package/lib/stringMsg.js +0 -12
- package/lib/toPgn.js +14 -13
- package/lib/ydgw02.js +2 -19
- package/package.json +2 -2
- package/examples/signalk-device-emulator/dist/index.d.ts +0 -11
- package/examples/signalk-device-emulator/dist/index.js +0 -129
- package/examples/signalk-device-emulator/index.js +0 -1
- package/examples/signalk-device-emulator/package.json +0 -24
- package/examples/signalk-device-emulator/signalk-device-emulator-1.0.0.tgz +0 -0
- package/lib/n2kDevice.js +0 -365
- package/lib/yddevice.js +0 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canboat/canboatjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "Native javascript version of canboat",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
],
|
|
54
54
|
"license": "Apache-2.0",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@canboat/pgns": "5.
|
|
56
|
+
"@canboat/pgns": "5.2.x",
|
|
57
57
|
"bit-buffer": "0.2.3",
|
|
58
58
|
"debug": "^4.3.4",
|
|
59
59
|
"dnssd": "^0.4.1",
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2025 Scott Bender <scott@scottbender.net>
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var canboatjs = require('@canboat/canboatjs');
|
|
18
|
-
var util = require('util');
|
|
19
|
-
var keepAlivePGN = '%s,7,65305,%s,255,8,41,9f,01,17,1c,01,00,00';
|
|
20
|
-
function default_1(app) {
|
|
21
|
-
var error = app.error;
|
|
22
|
-
var debug = app.debug;
|
|
23
|
-
var props;
|
|
24
|
-
var onStop = [];
|
|
25
|
-
var device;
|
|
26
|
-
var plugin = {
|
|
27
|
-
start: function (properties) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
props = properties;
|
|
30
|
-
var n2kOptions = {
|
|
31
|
-
app: app,
|
|
32
|
-
canDevice: props.candevice,
|
|
33
|
-
preferredAddress: props.sourceAddress,
|
|
34
|
-
disableDefaultTransmitPGNs: true,
|
|
35
|
-
transmitPGNs: [126996],
|
|
36
|
-
addressClaim: {
|
|
37
|
-
'Unique Number': 1731561,
|
|
38
|
-
'Manufacturer Code': 'Navico',
|
|
39
|
-
'Device Function': 190,
|
|
40
|
-
'Device Class': 'Internal Environment',
|
|
41
|
-
'Device Instance Lower': 0,
|
|
42
|
-
'Device Instance Upper': 0,
|
|
43
|
-
'System Instance': 0,
|
|
44
|
-
'Industry Group': 'Marine'
|
|
45
|
-
},
|
|
46
|
-
productInfo: {
|
|
47
|
-
'NMEA 2000 Version': 2100,
|
|
48
|
-
'Product Code': 246,
|
|
49
|
-
'Model ID': 'H5000 CPU',
|
|
50
|
-
'Software Version Code': '2.0.45.0.29',
|
|
51
|
-
'Model Version': '',
|
|
52
|
-
'Model Serial Code': '005469',
|
|
53
|
-
'Certification Level': 2,
|
|
54
|
-
'Load Equivalency': 1
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
if (props.emulationType === 'socketcan') {
|
|
58
|
-
device = new canboatjs.SimpleCan(n2kOptions);
|
|
59
|
-
device.start();
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
app.on('nmea2000OutAvailable', function () {
|
|
63
|
-
device = new canboatjs.YdDevice(n2kOptions);
|
|
64
|
-
device.start();
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
var timer = setInterval(function () {
|
|
68
|
-
_this.sendKeepAlive();
|
|
69
|
-
}, 1000);
|
|
70
|
-
onStop.push(function () { clearInterval(timer); });
|
|
71
|
-
},
|
|
72
|
-
sendKeepAlive: function () {
|
|
73
|
-
var msg = util.format(keepAlivePGN, (new Date()).toISOString(), device.address);
|
|
74
|
-
device.sendActisenseFormat(msg);
|
|
75
|
-
/*
|
|
76
|
-
device.sendPGN({
|
|
77
|
-
"prio":2,
|
|
78
|
-
"dst":255,
|
|
79
|
-
"pgn":127245,
|
|
80
|
-
"fields":{
|
|
81
|
-
"Instance":252,
|
|
82
|
-
"Direction Order":4,
|
|
83
|
-
"Angle Order":-0.0021,
|
|
84
|
-
"Position":-0.0029,
|
|
85
|
-
"Reserved1":null,
|
|
86
|
-
"Reserved2":null
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
*/
|
|
90
|
-
},
|
|
91
|
-
stop: function () {
|
|
92
|
-
onStop.forEach(function (f) { return f(); });
|
|
93
|
-
onStop = [];
|
|
94
|
-
},
|
|
95
|
-
id: 'signalk-device-emulator',
|
|
96
|
-
name: 'signalk-device-emulator',
|
|
97
|
-
description: 'signalk-device-emulator',
|
|
98
|
-
schema: function () {
|
|
99
|
-
var schema = {
|
|
100
|
-
type: 'object',
|
|
101
|
-
properties: {
|
|
102
|
-
emulationType: {
|
|
103
|
-
type: 'string',
|
|
104
|
-
title: 'Emulation Device',
|
|
105
|
-
enum: ['socketcan', 'yd'],
|
|
106
|
-
enumNames: [
|
|
107
|
-
'SocketCan',
|
|
108
|
-
'Yacht Devices'
|
|
109
|
-
],
|
|
110
|
-
default: 'yd'
|
|
111
|
-
},
|
|
112
|
-
candevice: {
|
|
113
|
-
type: "string",
|
|
114
|
-
title: "Candevice to use for device emulation)",
|
|
115
|
-
default: "can0"
|
|
116
|
-
},
|
|
117
|
-
sourceAddress: {
|
|
118
|
-
type: "number",
|
|
119
|
-
title: "Source device id for device emulation to use.",
|
|
120
|
-
default: 199
|
|
121
|
-
},
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
return schema;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
return plugin;
|
|
128
|
-
}
|
|
129
|
-
exports.default = default_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/').default
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "signalk-device-emulator",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Signal K Plugin which emulates a device",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"format": "prettier-standard 'src/*.ts'",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"watch": "npm run build -- -w"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"signalk-node-server-plugin"
|
|
13
|
-
],
|
|
14
|
-
"author": "scott@scottbender.net",
|
|
15
|
-
"license": "Apache-2.0",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@canboat/canboatjs": "^2.10.0"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@types/node": "^14.14.10",
|
|
21
|
-
"prettier-standard": "^16.4.1",
|
|
22
|
-
"typescript": "^4.1.2"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
Binary file
|
package/lib/n2kDevice.js
DELETED
|
@@ -1,365 +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
|
-
const debug = require('debug')('canboatjs:n2kdevice')
|
|
18
|
-
const EventEmitter = require('events')
|
|
19
|
-
const _ = require('lodash')
|
|
20
|
-
const Uint64LE = require('int64-buffer').Uint64LE
|
|
21
|
-
const { defaultTransmitPGNs, getIndustryCode, getManufacturerCode, getDeviceClassCode } = require('./codes')
|
|
22
|
-
const { toPgn } = require('./toPgn')
|
|
23
|
-
let packageJson
|
|
24
|
-
|
|
25
|
-
try
|
|
26
|
-
{
|
|
27
|
-
packageJson = require('../' + 'package.json')
|
|
28
|
-
} catch (ex) {
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const deviceTransmitPGNs = [ 60928, 59904, 126996, 126464 ]
|
|
32
|
-
|
|
33
|
-
class N2kDevice extends EventEmitter {
|
|
34
|
-
constructor (options) {
|
|
35
|
-
super()
|
|
36
|
-
|
|
37
|
-
if ( options.addressClaim ) {
|
|
38
|
-
this.addressClaim = options.addressClaim
|
|
39
|
-
this.addressClaim.pgn = 60928
|
|
40
|
-
this.addressClaim.dst = 255
|
|
41
|
-
this.addressClaim.prio = 6
|
|
42
|
-
} else {
|
|
43
|
-
this.addressClaim = {
|
|
44
|
-
pgn: 60928,
|
|
45
|
-
dst: 255,
|
|
46
|
-
prio:6,
|
|
47
|
-
"Unique Number": 1263,
|
|
48
|
-
"Manufacturer Code": 999,
|
|
49
|
-
"Device Function": 130, // PC gateway
|
|
50
|
-
"Device Class": 25, // Inter/Intranetwork Device
|
|
51
|
-
"Device Instance Lower": 0,
|
|
52
|
-
"Device Instance Upper": 0,
|
|
53
|
-
"System Instance": 0,
|
|
54
|
-
"Industry Group": 4, // Marine
|
|
55
|
-
"Reserved1": 1,
|
|
56
|
-
"Reserved2": 2
|
|
57
|
-
}
|
|
58
|
-
this.addressClaim["Unique Number"] = options.uniqueNumber || Math.floor(Math.random() * Math.floor(2097151))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let version = packageJson ? packageJson.version : "1.0"
|
|
62
|
-
|
|
63
|
-
if ( options.productInfo ) {
|
|
64
|
-
this.productInfo = options.productInfo
|
|
65
|
-
this.productInfo.pgn = 126996
|
|
66
|
-
this.productInfo.dst = 255
|
|
67
|
-
} else {
|
|
68
|
-
this.productInfo = {
|
|
69
|
-
pgn: 126996,
|
|
70
|
-
dst: 255,
|
|
71
|
-
"NMEA 2000 Version": 1300,
|
|
72
|
-
"Product Code": 667, // Just made up..
|
|
73
|
-
"Model ID": "Signal K",
|
|
74
|
-
"Model Version": "canboatjs",
|
|
75
|
-
"Model Serial Code": options.uniqueNumber ? options.uniqueNumber.toString() : "000001",
|
|
76
|
-
"Certification Level": 0,
|
|
77
|
-
"Load Equivalency": 1
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.productInfo["Software Version Code"] = version
|
|
82
|
-
|
|
83
|
-
if ( options.serverVersion && options.serverUrl ) {
|
|
84
|
-
this.configurationInfo = {
|
|
85
|
-
pgn: 126998,
|
|
86
|
-
dst: 255,
|
|
87
|
-
"Installation Description #1": options.serverUrl,
|
|
88
|
-
"Installation Description #2": options.serverDescription,
|
|
89
|
-
"Manufacturer Information": options.serverVersion
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
this.options = _.isUndefined(options) ? {} : options
|
|
94
|
-
|
|
95
|
-
this.address = _.isUndefined(options.preferredAddress) ? 100 : options.preferredAddress
|
|
96
|
-
this.cansend = false
|
|
97
|
-
this.foundConflict = false
|
|
98
|
-
this.heartbeatCounter = 0
|
|
99
|
-
this.devices = {}
|
|
100
|
-
|
|
101
|
-
if ( !options.disableDefaultTransmitPGNs ) {
|
|
102
|
-
this.transmitPGNs = _.union(deviceTransmitPGNs, defaultTransmitPGNs)
|
|
103
|
-
} else {
|
|
104
|
-
this.transmitPGNs = [...deviceTransmitPGNs]
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if ( this.options.transmitPGNs ) {
|
|
108
|
-
this.transmitPGNs = _.union(this.transmitPGNs,
|
|
109
|
-
this.options.transmitPGNs)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
start() {
|
|
114
|
-
sendISORequest(this, 60928, 254)
|
|
115
|
-
setTimeout(() => {
|
|
116
|
-
sendAddressClaim(this)
|
|
117
|
-
}, 1000)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
n2kMessage(pgn) {
|
|
121
|
-
if ( pgn.dst == 255 || pgn.dst == this.address ) {
|
|
122
|
-
try {
|
|
123
|
-
if ( pgn.pgn == 59904 ) {
|
|
124
|
-
handleISORequest(this, pgn)
|
|
125
|
-
} else if ( pgn.pgn == 126208 ) {
|
|
126
|
-
handleGroupFunction(this, pgn)
|
|
127
|
-
} else if ( pgn.pgn == 60928 ) {
|
|
128
|
-
handleISOAddressClaim(this, pgn)
|
|
129
|
-
} else if ( pgn.pgn == 126996 ) {
|
|
130
|
-
handleProductInformation(this, pgn)
|
|
131
|
-
}
|
|
132
|
-
} catch ( err ) {
|
|
133
|
-
console.error(err)
|
|
134
|
-
console.error(err.stack)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/*
|
|
138
|
-
var handler = this.handlers[pgn.pgn.toString()]
|
|
139
|
-
if ( pgn.dst == this.address )
|
|
140
|
-
debug(`handler ${handler}`)
|
|
141
|
-
if ( _.isFunction(handler) ) {
|
|
142
|
-
debug(`got handled PGN %j ${handled}`, pgn)
|
|
143
|
-
handler(pgn)
|
|
144
|
-
}
|
|
145
|
-
*/
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
sendPGN(pgn, src) {
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function handleISORequest(device, n2kMsg) {
|
|
154
|
-
debug('handleISORequest %j', n2kMsg)
|
|
155
|
-
|
|
156
|
-
switch (n2kMsg.fields.PGN) {
|
|
157
|
-
case 126996: // Product Information request
|
|
158
|
-
sendProductInformation(device)
|
|
159
|
-
break;
|
|
160
|
-
case 126998: // Config Information request
|
|
161
|
-
sendConfigInformation(device)
|
|
162
|
-
break;
|
|
163
|
-
case 60928: // ISO address claim request
|
|
164
|
-
device.sendPGN(device.addressClaim)
|
|
165
|
-
break;
|
|
166
|
-
case 126464:
|
|
167
|
-
sendPGNList(device)
|
|
168
|
-
break;
|
|
169
|
-
default:
|
|
170
|
-
if ( !device.options.disableNAKs ) {
|
|
171
|
-
debug(`Got unsupported ISO request for PGN ${n2kMsg.fields.PGN}. Sending NAK.`)
|
|
172
|
-
sendNAKAcknowledgement(device, n2kMsg.src, n2kMsg.fields.PGN)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function handleGroupFunction(device, n2kMsg) {
|
|
178
|
-
debug('handleGroupFunction %j', n2kMsg)
|
|
179
|
-
if(n2kMsg.fields["Function Code"] === 'Request') {
|
|
180
|
-
handleRequestGroupFunction(device, n2kMsg)
|
|
181
|
-
} else if(n2kMsg.fields["Function Code"] === 'Command') {
|
|
182
|
-
handleCommandGroupFunction(device, n2kMsg)
|
|
183
|
-
} else {
|
|
184
|
-
debug('Got unsupported Group Function PGN: %j', n2kMsg)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function handleRequestGroupFunction(device, n2kMsg) {
|
|
188
|
-
if ( !device.options.disableNAKs ) {
|
|
189
|
-
// We really don't support group function requests for any PGNs yet -> always respond with pgnErrorCode 1 = "PGN not supported"
|
|
190
|
-
debug("Sending 'PGN Not Supported' Group Function response for requested PGN", n2kMsg.fields.PGN)
|
|
191
|
-
|
|
192
|
-
const acknowledgement = {
|
|
193
|
-
pgn: 126208,
|
|
194
|
-
dst: n2kMsg.src,
|
|
195
|
-
"Function Code": 2,
|
|
196
|
-
"PGN": n2kMsg.fields.PGN,
|
|
197
|
-
"PGN error code": 4,
|
|
198
|
-
"Transmission interval/Priority error code": 0,
|
|
199
|
-
"# of Parameters": 0
|
|
200
|
-
}
|
|
201
|
-
device.sendPGN(acknowledgement)
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function handleCommandGroupFunction(device, n2kMsg) {
|
|
206
|
-
if ( !device.options.disableNAKs ) {
|
|
207
|
-
// We really don't support group function commands for any PGNs yet -> always respond with pgnErrorCode 1 = "PGN not supported"
|
|
208
|
-
debug("Sending 'PGN Not Supported' Group Function response for commanded PGN", n2kMsg.fields.PGN)
|
|
209
|
-
|
|
210
|
-
const acknowledgement = {
|
|
211
|
-
pgn: 126208,
|
|
212
|
-
dst: n2kMsg.src,
|
|
213
|
-
"Function Code": 2,
|
|
214
|
-
"PGN": n2kMsg.fields.PGN,
|
|
215
|
-
"PGN error code": 4,
|
|
216
|
-
"Transmission interval/Priority error code": 0,
|
|
217
|
-
"# of Parameters": 0
|
|
218
|
-
}
|
|
219
|
-
device.sendPGN(acknowledgement)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function handleISOAddressClaim(device, n2kMsg) {
|
|
225
|
-
if ( n2kMsg.src != device.address ) {
|
|
226
|
-
if ( !device.devices[n2kMsg.src] ) {
|
|
227
|
-
debug(`registering device ${n2kMsg.src}`)
|
|
228
|
-
device.devices[n2kMsg.src] = { addressClaim: n2kMsg }
|
|
229
|
-
if ( device.cansend ) {
|
|
230
|
-
//sendISORequest(device, 126996, undefined, n2kMsg.src)
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
debug('Checking ISO address claim. %j', n2kMsg)
|
|
237
|
-
|
|
238
|
-
const uint64ValueFromReceivedClaim = getISOAddressClaimAsUint64(n2kMsg)
|
|
239
|
-
const uint64ValueFromOurOwnClaim = getISOAddressClaimAsUint64(device.addressClaim)
|
|
240
|
-
|
|
241
|
-
if(uint64ValueFromOurOwnClaim < uint64ValueFromReceivedClaim) {
|
|
242
|
-
debug(`Address conflict detected! Kept our address as ${device.address}.`)
|
|
243
|
-
sendAddressClaim(device) // We have smaller address claim data -> we can keep our address -> re-claim it
|
|
244
|
-
} else if(uint64ValueFromOurOwnClaim > uint64ValueFromReceivedClaim) {
|
|
245
|
-
this.foundConflict = true
|
|
246
|
-
increaseOwnAddress(device) // We have bigger address claim data -> we have to change our address
|
|
247
|
-
sendAddressClaim(device)
|
|
248
|
-
debug(`Address conflict detected! Changed our address to ${device.address}.`)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function increaseOwnAddress(device) {
|
|
253
|
-
var start = device.address
|
|
254
|
-
do {
|
|
255
|
-
device.address = (device.address + 1) % 253
|
|
256
|
-
} while ( device.address != start && device.devices[device.address] )
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function handleProductInformation(device, n2kMsg) {
|
|
260
|
-
if ( !device.devices[n2kMsg.src] ) {
|
|
261
|
-
device.devices[n2kMsg.src] = {}
|
|
262
|
-
}
|
|
263
|
-
debug('got production information %j', n2kMsg)
|
|
264
|
-
device.devices[n2kMsg.src].productInformation = n2kMsg
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function sendHeartbeat(device)
|
|
268
|
-
{
|
|
269
|
-
device.heartbeatCounter = device.heartbeatCounter + 1
|
|
270
|
-
if ( device.heartbeatCounter > 252 )
|
|
271
|
-
{
|
|
272
|
-
device.heartbeatCounter = 0
|
|
273
|
-
}
|
|
274
|
-
device.sendPGN({
|
|
275
|
-
pgn: 126993,
|
|
276
|
-
dst: 255,
|
|
277
|
-
prio:7,
|
|
278
|
-
"Data transmit offset": "00:01:00",
|
|
279
|
-
"Sequence Counter": device.heartbeatCounter,
|
|
280
|
-
"Controller 1 State":"Error Active"
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
function sendAddressClaim(device) {
|
|
286
|
-
if ( device.devices[device.address] ) {
|
|
287
|
-
//someone already has this address, so find a free one
|
|
288
|
-
increaseOwnAddress(device)
|
|
289
|
-
}
|
|
290
|
-
debug(`Sending address claim ${device.address}`)
|
|
291
|
-
device.sendPGN(device.addressClaim)
|
|
292
|
-
setTimeout(() => {
|
|
293
|
-
if ( !device.foundConflict ) {
|
|
294
|
-
debug('no address conflics, enabling send')
|
|
295
|
-
device.cansend = true
|
|
296
|
-
if ( device.options.app ) {
|
|
297
|
-
device.options.app.emit('nmea2000OutAvailable')
|
|
298
|
-
}
|
|
299
|
-
sendISORequest(device, 126996)
|
|
300
|
-
device.heartbeatInterval = setInterval(() => {
|
|
301
|
-
sendHeartbeat(device)
|
|
302
|
-
}, 60*1000)
|
|
303
|
-
/*
|
|
304
|
-
_.keys(device.devices).forEach((address) => {
|
|
305
|
-
sendISORequest(device, 126996, undefined, address)
|
|
306
|
-
})
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
}, 250)
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function sendISORequest(device, pgn, src, dst=255) {
|
|
314
|
-
debug(`Sending iso request for ${pgn} to ${dst}`)
|
|
315
|
-
|
|
316
|
-
const isoRequest = {
|
|
317
|
-
pgn: 59904,
|
|
318
|
-
dst: dst,
|
|
319
|
-
"PGN": pgn
|
|
320
|
-
}
|
|
321
|
-
device.sendPGN(isoRequest, src)
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
function sendProductInformation(device) {
|
|
326
|
-
debug("Sending product info..")
|
|
327
|
-
|
|
328
|
-
device.sendPGN(device.productInfo)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function sendConfigInformation(device) {
|
|
332
|
-
if ( device.configurationInfo ) {
|
|
333
|
-
debug("Sending config info..")
|
|
334
|
-
device.sendPGN(device.configurationInfo)
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function sendNAKAcknowledgement(device, src, requestedPGN) {
|
|
339
|
-
const acknowledgement = {
|
|
340
|
-
pgn: 59392,
|
|
341
|
-
dst: src,
|
|
342
|
-
Control: 1,
|
|
343
|
-
"Group Function": 255,
|
|
344
|
-
PGN: requestedPGN
|
|
345
|
-
}
|
|
346
|
-
device.sendPGN(device, acknowledgement)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function sendPGNList(device, src) {
|
|
350
|
-
//FIXME: for now, adding everything that signalk-to-nmea2000 supports
|
|
351
|
-
//need a way for plugins, etc. to register the pgns they provide
|
|
352
|
-
const pgnList = {
|
|
353
|
-
pgn: 126464,
|
|
354
|
-
dst: src,
|
|
355
|
-
"Function Code": 0,
|
|
356
|
-
list: device.transmitPGNs
|
|
357
|
-
}
|
|
358
|
-
device.sendPGN(pgnList)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function getISOAddressClaimAsUint64(pgn) {
|
|
362
|
-
return new Uint64LE(toPgn(pgn))
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
module.exports = N2kDevice
|
package/lib/yddevice.js
DELETED
|
@@ -1,47 +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
|
-
|
|
18
|
-
const debug = require('debug')('canboatjs:n2kdevice')
|
|
19
|
-
const N2kDevice = require('./n2kDevice')
|
|
20
|
-
|
|
21
|
-
const { actisenseToYdgwFullRawFormat } = require('./toPgn')
|
|
22
|
-
|
|
23
|
-
class YdDevice extends N2kDevice {
|
|
24
|
-
constructor (options) {
|
|
25
|
-
super(options)
|
|
26
|
-
this.app = options.app
|
|
27
|
-
this.n2kOutEvent = options.jsonOutEvent || 'nmea2000JsonOut'
|
|
28
|
-
|
|
29
|
-
const analyzerOutEvent = options.analyzerOutEvent || 'N2KAnalyzerOut'
|
|
30
|
-
|
|
31
|
-
this.app.on(options.analyzerOutEvent || 'N2KAnalyzerOut', this.n2kMessage.bind(this))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
sendPGN(pgn, src) {
|
|
35
|
-
pgn.src = src || this.address
|
|
36
|
-
pgn.
|
|
37
|
-
pgn.ydFullFormat = true
|
|
38
|
-
debug('Sending PGN %j', pgn)
|
|
39
|
-
this.app.emit(this.n2kOutEvent, pgn)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
sendActisenseFormat(msg) {
|
|
43
|
-
this.app.emit('ydFullRawOut', actisenseToYdgwFullRawFormat(msg))
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = YdDevice
|