UNPKG

@canboat/canboatjs

Version:

Native javascript version of canboat

130 lines (129 loc) 4.67 kB
"use strict"; /* * Copyright 2025 Scott Bender <scott@scottbender.net> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); var canboatjs = require('@canboat/canboatjs'); var util = require('util'); var keepAlivePGN = '%s,7,65305,%s,255,8,41,9f,01,17,1c,01,00,00'; function default_1(app) { var error = app.error; var debug = app.debug; var props; var onStop = []; var device; var plugin = { start: function (properties) { var _this = this; props = properties; var n2kOptions = { app: app, canDevice: props.candevice, preferredAddress: props.sourceAddress, disableDefaultTransmitPGNs: true, transmitPGNs: [126996], addressClaim: { 'Unique Number': 1731561, 'Manufacturer Code': 'Navico', 'Device Function': 190, 'Device Class': 'Internal Environment', 'Device Instance Lower': 0, 'Device Instance Upper': 0, 'System Instance': 0, 'Industry Group': 'Marine' }, productInfo: { 'NMEA 2000 Version': 2100, 'Product Code': 246, 'Model ID': 'H5000 CPU', 'Software Version Code': '2.0.45.0.29', 'Model Version': '', 'Model Serial Code': '005469', 'Certification Level': 2, 'Load Equivalency': 1 } }; if (props.emulationType === 'socketcan') { device = new canboatjs.SimpleCan(n2kOptions); device.start(); } else { app.on('nmea2000OutAvailable', function () { device = new canboatjs.YdDevice(n2kOptions); device.start(); }); } var timer = setInterval(function () { _this.sendKeepAlive(); }, 1000); onStop.push(function () { clearInterval(timer); }); }, sendKeepAlive: function () { var msg = util.format(keepAlivePGN, (new Date()).toISOString(), device.address); device.sendActisenseFormat(msg); /* device.sendPGN({ "prio":2, "dst":255, "pgn":127245, "fields":{ "Instance":252, "Direction Order":4, "Angle Order":-0.0021, "Position":-0.0029, "Reserved1":null, "Reserved2":null } }) */ }, stop: function () { onStop.forEach(function (f) { return f(); }); onStop = []; }, id: 'signalk-device-emulator', name: 'signalk-device-emulator', description: 'signalk-device-emulator', schema: function () { var schema = { type: 'object', properties: { emulationType: { type: 'string', title: 'Emulation Device', enum: ['socketcan', 'yd'], enumNames: [ 'SocketCan', 'Yacht Devices' ], default: 'yd' }, candevice: { type: "string", title: "Candevice to use for device emulation)", default: "can0" }, sourceAddress: { type: "number", title: "Source device id for device emulation to use.", default: 199 }, } }; return schema; } }; return plugin; } exports.default = default_1;