From dc29d00f40ea0e82ce2da7541810e6d0e3a73b9e Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Fri, 21 Jul 2023 08:37:28 +0300 Subject: [PATCH] style: autoformat --- lowrance/65285.js | 11 +- lowrance/index.js | 2 +- mmsi-context.js | 9 +- n2kMapper.js | 150 ++++++++++++++----------- pgns/126983.js | 143 ++++++++++++----------- pgns/126985.js | 43 +++---- pgns/127237.js | 7 +- pgns/127493.js | 8 +- pgns/127497.js | 6 +- pgns/127503.js | 4 +- pgns/127504.js | 4 +- pgns/127505.js | 2 +- pgns/127750.js | 3 +- pgns/127751.js | 5 +- pgns/129038.js | 4 +- pgns/129039.js | 2 +- pgns/129040.js | 2 +- pgns/129041.js | 10 +- pgns/129540.js | 10 +- pgns/129793.js | 4 +- pgns/129798.js | 10 +- pgns/130306.js | 10 +- pgns/130311.js | 13 +-- pgns/130312.js | 4 +- pgns/130313.js | 5 +- pgns/acPower.js | 6 +- pressureMappings.js | 16 +-- raymarine/126720.js | 53 +++++---- raymarine/65288.js | 48 ++++---- raymarine/65345.js | 10 +- raymarine/65359.js | 36 +++--- raymarine/65360.js | 8 +- raymarine/65379.js | 24 ++-- raymarine/index.js | 2 +- test/126983_alert.js | 93 ++++++++------- test/126985_alert_text.js | 14 ++- test/127237_heading_track_control.js | 5 +- test/127488_engine_boost.js | 5 +- test/127493_transmission.js | 4 +- test/127497_trip_params.js | 9 +- test/127505_fluid_level.js | 10 +- test/127744_ac_power.js | 28 +++-- test/127745_ac_power.js | 28 +++-- test/127746_ac_power.js | 28 +++-- test/127750_converter_status.js | 64 +++++------ test/127751_dv_voltage_current.js | 36 +++--- test/129038_ais_class_a.js | 55 ++++----- test/129040_class_b_extended.js | 2 +- test/129540_sats_in_view.js | 2 +- test/129794_ais_class_a_static_data.js | 102 +++++++++-------- test/129809_ais_class_b_static_data.js | 8 +- test/130310-2.json | 2 +- test/130314-data.json | 40 +++---- test/130314_pressure_new.js | 10 +- test/13031_temperature.js | 25 ++--- test/65359_seatalk_pilot_heading.js | 10 +- test/ais_utils.js | 2 +- test/customPgns.js | 35 +++--- test/maretron.js | 85 ++++++++++++-- test/meta.js | 62 ++++++++-- utils.js | 22 ++-- 61 files changed, 822 insertions(+), 638 deletions(-) diff --git a/lowrance/65285.js b/lowrance/65285.js index e829d2f7..53ea5c9c 100644 --- a/lowrance/65285.js +++ b/lowrance/65285.js @@ -5,14 +5,11 @@ module.exports = [ source: 'Actual Temperature', node: function (n2k) { var temperatureMapping = - temperatureMappings[n2k.fields['Temperature Source']] - - if ( temperatureMappings ) { + temperatureMappings[n2k.fields['Temperature Source']] + + if (temperatureMappings) { if (temperatureMapping.pathWithIndex) { - return temperatureMapping.pathWithIndex.replace( - '', - 'default' - ) + return temperatureMapping.pathWithIndex.replace('', 'default') } else if (temperatureMapping.path) { return temperatureMapping.path } diff --git a/lowrance/index.js b/lowrance/index.js index a5e75c65..2deb800b 100644 --- a/lowrance/index.js +++ b/lowrance/index.js @@ -1,3 +1,3 @@ module.exports = { 65285: require('./65285.js') -} \ No newline at end of file +} diff --git a/mmsi-context.js b/mmsi-context.js index 5de86580..6bebf599 100644 --- a/mmsi-context.js +++ b/mmsi-context.js @@ -1,11 +1,12 @@ - module.exports.getMmsiContext = function (n2k) { - return typeof n2k.fields['User ID'] !== 'undefined' ? 'vessels.urn:mrn:imo:mmsi:' + n2k.fields['User ID'] : undefined + return typeof n2k.fields['User ID'] !== 'undefined' + ? 'vessels.urn:mrn:imo:mmsi:' + n2k.fields['User ID'] + : undefined } -function padUserID(n2k) { +function padUserID (n2k) { let id = n2k.fields['User ID'] - if ( typeof id !== 'undefined' ) { + if (typeof id !== 'undefined') { id = id.toString() return id != '0' ? id.padStart(9, '0') : id } diff --git a/n2kMapper.js b/n2kMapper.js index e82f027d..5cf24073 100644 --- a/n2kMapper.js +++ b/n2kMapper.js @@ -4,7 +4,7 @@ var debug = require('debug')('signalk:n2k-signalk') const toPgn = require('@canboat/canboatjs').toPgn const Uint64LE = require('int64-buffer').Uint64LE -require('util').inherits(N2kMapper, EventEmitter); +require('util').inherits(N2kMapper, EventEmitter) var n2kMappings = {} Object.assign(n2kMappings, require('./pgns')) @@ -16,39 +16,43 @@ Object.assign(n2kMappings, require('./actisense')) Object.assign(n2kMappings, require('./digitalyacht')) function N2kMapper (options) { - this.state = { } + this.state = {} this.unknownPGNs = {} this.customPgns = {} this.options = options || {} - - if ( this.options.onPropertyValues ) { + + if (this.options.onPropertyValues) { this.options.onPropertyValues('pgn-to-signalk', values => { - values.filter(v => v !== undefined).forEach(pv => { - Object.entries(pv.value).forEach(([pgnNumber, mappings]) => { - if ( n2kMappings[pgnNumber] && - !this.options.allowCustomPGNOverride ) { - console.error(`pgn ${pgnNumber} can't be overwritten`) - } else { - this.customPgns[pgnNumber] = mappings - debug('registered custom pgn %d by %s', pgnNumber, pv.setter) - } + values + .filter(v => v !== undefined) + .forEach(pv => { + Object.entries(pv.value).forEach(([pgnNumber, mappings]) => { + if ( + n2kMappings[pgnNumber] && + !this.options.allowCustomPGNOverride + ) { + console.error(`pgn ${pgnNumber} can't be overwritten`) + } else { + this.customPgns[pgnNumber] = mappings + debug('registered custom pgn %d by %s', pgnNumber, pv.setter) + } + }) }) - }) }) } } -N2kMapper.prototype.n2kOutIsAvailable = function(listener, event) { +N2kMapper.prototype.n2kOutIsAvailable = function (listener, event) { this.n2kOutEvent = event this.n2kListener = listener this.requestAllMeta() } -N2kMapper.prototype.requestMetaData = function(dst, pgn) { +N2kMapper.prototype.requestMetaData = function (dst, pgn) { const reqPgn = { - "pgn": 59904, - "dst": dst, - "PGN": pgn + pgn: 59904, + dst: dst, + PGN: pgn } debug(`requesting pgn ${pgn} from src ${dst}`) return new Promise((resolve, reject) => { @@ -59,64 +63,73 @@ N2kMapper.prototype.requestMetaData = function(dst, pgn) { }) } -N2kMapper.prototype.requestMetaPGNs = async function(dst, pgns) { - for ( let i = 0; i < pgns.length; i++ ) { +N2kMapper.prototype.requestMetaPGNs = async function (dst, pgns) { + for (let i = 0; i < pgns.length; i++) { await this.requestMetaData(dst, pgns[i]) } } -N2kMapper.prototype.checkSrcMetasAndRetry = function(src) { - if ( src !== "255" ) { +N2kMapper.prototype.checkSrcMetasAndRetry = function (src) { + if (src !== '255') { const neededPGNs = Object.keys(metaPGNs).filter(pgn => { - return !this.state[src].metaPGNsReceived || + return ( + !this.state[src].metaPGNsReceived || !this.state[src].metaPGNsReceived[pgn] + ) }) - if ( neededPGNs.length > 0 ) { + if (neededPGNs.length > 0) { debug('did not get meta pgns %j for src %d', neededPGNs, src) - this.requestMetaPGNs(src, neededPGNs) - .then(() => { - neededPGNs.forEach(pgn => { - if (!this.state[src].metaPGNsReceived || - !this.state[src].metaPGNsReceived[pgn]) { - debug(`did not get meta pgn ${pgn} for src ${src}`) - this.emit('n2kSourceMetadataTimeout', pgn, src) - } - }) + this.requestMetaPGNs(src, neededPGNs).then(() => { + neededPGNs.forEach(pgn => { + if ( + !this.state[src].metaPGNsReceived || + !this.state[src].metaPGNsReceived[pgn] + ) { + debug(`did not get meta pgn ${pgn} for src ${src}`) + this.emit('n2kSourceMetadataTimeout', pgn, src) + } }) + }) } } } -N2kMapper.prototype.requestAllMeta = function() { - this.requestMetaPGNs(255, Object.keys(metaPGNs)) - .then(() => { - Object.keys(this.state).forEach(src => this.checkSrcMetasAndRetry(src)) - }) +N2kMapper.prototype.requestAllMeta = function () { + this.requestMetaPGNs(255, Object.keys(metaPGNs)).then(() => { + Object.keys(this.state).forEach(src => this.checkSrcMetasAndRetry(src)) + }) } -N2kMapper.prototype.toDelta = function(n2k) { - if ( metaPGNs[n2k.pgn] ) { +N2kMapper.prototype.toDelta = function (n2k) { + if (metaPGNs[n2k.pgn]) { const meta = metaPGNs[n2k.pgn](n2k) - if ( ! this.state[n2k.src] ) { + if (!this.state[n2k.src]) { this.state[n2k.src] = {} } - if ( !this.state[n2k.src].metaPGNsReceived ) { + if (!this.state[n2k.src].metaPGNsReceived) { this.state[n2k.src].metaPGNsReceived = {} } - if ( n2k.pgn === 60928 ) { + if (n2k.pgn === 60928) { const canName = new Uint64LE(toPgn(n2k)).toString(16) - if ( ! this.state[n2k.src] ) { + if (!this.state[n2k.src]) { this.state[n2k.src] = {} - } else if ( this.state[n2k.src].canName && this.state[n2k.src].canName != canName ) { + } else if ( + this.state[n2k.src].canName && + this.state[n2k.src].canName != canName + ) { // clear out any existing state since the src addresses have changed - this.emit('n2kSourceChanged', n2k.src, this.state[n2k.src].canName, canName) + this.emit( + 'n2kSourceChanged', + n2k.src, + this.state[n2k.src].canName, + canName + ) this.state[n2k.src] = {} - this.requestMetaData(n2k.src, 126996) - .then(() => { - return this.requestMetaData(n2k.src, 126998) - }) + this.requestMetaData(n2k.src, 126996).then(() => { + return this.requestMetaData(n2k.src, 126998) + }) } this.state[n2k.src].deviceInstance = meta.deviceInstance meta.canName = canName @@ -124,16 +137,18 @@ N2kMapper.prototype.toDelta = function(n2k) { } this.state[n2k.src].metaPGNsReceived[n2k.pgn] = Date.now() - + this.emit('n2kSourceMetadata', n2k, meta) } else { - if ( !n2kMappings[n2k.pgn] ) { - if ( !this.unknownPGNs[n2k.src] ) { + if (!n2kMappings[n2k.pgn]) { + if (!this.unknownPGNs[n2k.src]) { this.unknownPGNs[n2k.src] = {} } - if ( !this.unknownPGNs[n2k.src][n2k.pgn] ) { + if (!this.unknownPGNs[n2k.src][n2k.pgn]) { this.unknownPGNs[n2k.src][n2k.pgn] = n2k - this.emit('n2kSourceMetadata', n2k, { unknownPGNs: this.unknownPGNs[n2k.src] }) + this.emit('n2kSourceMetadata', n2k, { + unknownPGNs: this.unknownPGNs[n2k.src] + }) } } return toDelta(n2k, this.state, this.customPgns) @@ -144,7 +159,10 @@ var toDelta = function (n2k, state, customPgns = {}) { try { var theMappings, customMappings - theMappings = [ ...customPgns[n2k.pgn] || [], ...n2kMappings[n2k.pgn] || []] + theMappings = [ + ...(customPgns[n2k.pgn] || []), + ...(n2kMappings[n2k.pgn] || []) + ] var src_state if (state) { @@ -171,10 +189,10 @@ var toDelta = function (n2k, state, customPgns = {}) { } ] } - if ( src_state && src_state.canName ) { + if (src_state && src_state.canName) { result.updates[0].source.canName = src_state.canName } - if ( src_state && typeof src_state.deviceInstance !== 'undefined' ) { + if (src_state && typeof src_state.deviceInstance !== 'undefined') { result.updates[0].source.deviceInstance = src_state.deviceInstance } if ( @@ -186,10 +204,10 @@ var toDelta = function (n2k, state, customPgns = {}) { result.context = mapping.context(n2k, src_state) } }) - if ( result.context ) { + if (result.context) { //filter out invalid mmsi let last = result.context.lastIndexOf(':') - if ( last != -1 && result.context.slice(last+1).length < 9 ) { + if (last != -1 && result.context.slice(last + 1).length < 9) { console.error('bad MMSI: ' + result.context) return } @@ -338,7 +356,7 @@ function addAsNested (pathValue, source, timestamp, result) { } const metaPGNs = { - 60928: (n2k) => { + 60928: n2k => { return { uniqueId: n2k.fields['Unique Number'], manufacturerName: n2k.fields['Manufacturer Code'], @@ -347,10 +365,12 @@ const metaPGNs = { deviceInstanceLower: n2k.fields['Device Instance Lower'], deviceInstanceUpper: n2k.fields['Device Instance Upper'], systemInstance: n2k.fields['System Instance'], - deviceInstance: (n2k.fields['Device Instance Upper'] << 3) | n2k.fields['Device Instance Lower'] + deviceInstance: + (n2k.fields['Device Instance Upper'] << 3) | + n2k.fields['Device Instance Lower'] } }, - 126998: (n2k) => { + 126998: n2k => { return { installationNote1: n2k.fields['Installation Description #1'], installationNote2: n2k.fields['Installation Description #2'], @@ -358,7 +378,7 @@ const metaPGNs = { manufacturerInfo: n2k.fields['Manufacturer Information'] } }, - 126996: (n2k) => { + 126996: n2k => { return { productName: n2k.fields['Model ID'], hardwareVersion: n2k.fields['Model Version'], diff --git a/pgns/126983.js b/pgns/126983.js index a293e4fd..3071c0de 100644 --- a/pgns/126983.js +++ b/pgns/126983.js @@ -1,86 +1,99 @@ // ALERT const debug = require('debug')('n2k-signalk-126983') -const alertTypes = [{ - "nmea": "Emergency Alarm", - "sk": "emergency" +const alertTypes = [ + { + nmea: 'Emergency Alarm', + sk: 'emergency' }, { - "nmea": "Alarm", - "sk": "alarm" + nmea: 'Alarm', + sk: 'alarm' }, { - "nmea": "Warning", - "sk": "warn" + nmea: 'Warning', + sk: 'warn' }, { - "nmea": "Caution", - "sk": "alert" + nmea: 'Caution', + sk: 'alert' } ] -module.exports = [{ - node: function(n2k, state) { - var alertType = n2k.fields['Alert Type'].replace(/ /g, '').toLowerCase() +module.exports = [ + { + node: function (n2k, state) { + var alertType = n2k.fields['Alert Type'].replace(/ /g, '').toLowerCase() - var alertCategory = n2k.fields['Alert Category'].toLowerCase() + var alertCategory = n2k.fields['Alert Category'].toLowerCase() - var path = 'notifications.nmea.' + alertType + '.' + alertCategory + '.' + n2k.fields['Alert System'] + '.' + n2k.fields['Alert ID'] - debug('126983 path: ' + path) + var path = + 'notifications.nmea.' + + alertType + + '.' + + alertCategory + + '.' + + n2k.fields['Alert System'] + + '.' + + n2k.fields['Alert ID'] + debug('126983 path: ' + path) - return path - }, - value: function(n2k, state) { - debug('126983 value') + return path + }, + value: function (n2k, state) { + debug('126983 value') - var skstate = alertTypes.filter(alertType => alertType.nmea === n2k.fields['Alert Type']) - debug('126983 skstate: ' + skstate[0].sk) + var skstate = alertTypes.filter( + alertType => alertType.nmea === n2k.fields['Alert Type'] + ) + debug('126983 skstate: ' + skstate[0].sk) - var alertId = n2k.fields['Alert ID'] + var alertId = n2k.fields['Alert ID'] - var value = { - "state": skstate[0].sk, - "method": [ - "visual", - "sound" - ], - "message": state.alerts[alertId].textDescription, - "alertType": n2k.fields['Alert Type'], - "alertCategory": n2k.fields['Alert Category'], - "alertSystem": n2k.fields['Alert System'], - "alertId": n2k.fields['Alert ID'], - "dataSourceNetworkIDNAME": n2k.fields['Data Source Network ID NAME'], - "dataSourceInstance": n2k.fields['Data Source Instance'], - "dataSourceIndex-Source": n2k.fields['Data Source Index-Source'], - "occurrence": n2k.fields['Alert Occurrence Number'], - "temporarySilenceStatus": n2k.fields['Temporary Silence Status'], - "acknowledgeStatus": n2k.fields['Acknowledge Status'], - "escalationStatus": n2k.fields['Escalation Status'], - "temporarySilenceSupport": n2k.fields['Temporary Silence Support'], - "acknowledgeSupport": n2k.fields['Acknowledge Support'], - "escalationSupport": n2k.fields['Escalation Support'], - "acknowledgeSourceNetworkIDNAME": n2k.fields['Acknowledge Source Network ID NAME'], - "triggerCondition": n2k.fields['Trigger Condition'], - "thresholdStatus": n2k.fields['Threshold Status'], - "alertPriority": n2k.fields['Alert Priority'], - "alertState": n2k.fields['Alert State'] - } + var value = { + state: skstate[0].sk, + method: ['visual', 'sound'], + message: state.alerts[alertId].textDescription, + alertType: n2k.fields['Alert Type'], + alertCategory: n2k.fields['Alert Category'], + alertSystem: n2k.fields['Alert System'], + alertId: n2k.fields['Alert ID'], + dataSourceNetworkIDNAME: n2k.fields['Data Source Network ID NAME'], + dataSourceInstance: n2k.fields['Data Source Instance'], + 'dataSourceIndex-Source': n2k.fields['Data Source Index-Source'], + occurrence: n2k.fields['Alert Occurrence Number'], + temporarySilenceStatus: n2k.fields['Temporary Silence Status'], + acknowledgeStatus: n2k.fields['Acknowledge Status'], + escalationStatus: n2k.fields['Escalation Status'], + temporarySilenceSupport: n2k.fields['Temporary Silence Support'], + acknowledgeSupport: n2k.fields['Acknowledge Support'], + escalationSupport: n2k.fields['Escalation Support'], + acknowledgeSourceNetworkIDNAME: + n2k.fields['Acknowledge Source Network ID NAME'], + triggerCondition: n2k.fields['Trigger Condition'], + thresholdStatus: n2k.fields['Threshold Status'], + alertPriority: n2k.fields['Alert Priority'], + alertState: n2k.fields['Alert State'] + } - //if the alert is silenced or acknowledged then dont alert in SK - if (n2k.fields['Temporary Silence Status'] == 'Temporary Silence' || - n2k.fields['Acknowledge Status'] == 'Acknowledged') { - value.method = [] - } - debug('126983 value: ' + JSON.stringify(value)) + //if the alert is silenced or acknowledged then dont alert in SK + if ( + n2k.fields['Temporary Silence Status'] == 'Temporary Silence' || + n2k.fields['Acknowledge Status'] == 'Acknowledged' + ) { + value.method = [] + } + debug('126983 value: ' + JSON.stringify(value)) - return value - }, - filter: function(n2k, state) { - return ( - n2k.fields['Alert Type'] && - typeof state === 'object' && - state.alerts && - state.alerts[n2k.fields['Alert ID']] - ) + return value + }, + filter: function (n2k, state) { + return ( + n2k.fields['Alert Type'] && + typeof state === 'object' && + state.alerts && + state.alerts[n2k.fields['Alert ID']] + ) + } } -}] +] diff --git a/pgns/126985.js b/pgns/126985.js index a7d4a61b..466dbf30 100644 --- a/pgns/126985.js +++ b/pgns/126985.js @@ -1,24 +1,27 @@ //ALERT TEXT const debug = require('debug')('n2k-signalk-126985') -module.exports = [{ - filter: function(n2k, state) { - if (typeof state !== 'undefined') { - var alertId = n2k.fields['Alert ID'] - var text = { - languageId: n2k.fields['Language ID'], - textDescription: n2k.fields['Alert Text Description'], - locationTextDescription: n2k.fields['Alert Location Text Description'] || '' - } - //store the alert text in state for use with PGN 126983 - if (!state.alerts) { - state.alerts = {} - } - state.alerts[alertId] = text +module.exports = [ + { + filter: function (n2k, state) { + if (typeof state !== 'undefined') { + var alertId = n2k.fields['Alert ID'] + var text = { + languageId: n2k.fields['Language ID'], + textDescription: n2k.fields['Alert Text Description'], + locationTextDescription: + n2k.fields['Alert Location Text Description'] || '' + } + //store the alert text in state for use with PGN 126983 + if (!state.alerts) { + state.alerts = {} + } + state.alerts[alertId] = text - debug('set alert state text: ' + JSON.stringify(text)) - } - return false - }, - source: 'Alert Text' -}] + debug('set alert state text: ' + JSON.stringify(text)) + } + return false + }, + source: 'Alert Text' + } +] diff --git a/pgns/127237.js b/pgns/127237.js index ccfbc8d7..278cc2a8 100644 --- a/pgns/127237.js +++ b/pgns/127237.js @@ -2,11 +2,12 @@ module.exports = [ { source: 'Heading-To-Steer (Course)', node: function (n2k) { - const reference = n2k.fields['Heading Reference'] === 'Magnetic' ? 'Magnetic' : 'True' + const reference = + n2k.fields['Heading Reference'] === 'Magnetic' ? 'Magnetic' : 'True' return `steering.autopilot.target.heading${reference}` }, filter: function (n2k) { return typeof n2k.fields['Heading-To-Steer (Course)'] !== 'undefined' - }, - }, + } + } ] diff --git a/pgns/127493.js b/pgns/127493.js index 4bddec74..cb1c9887 100644 --- a/pgns/127493.js +++ b/pgns/127493.js @@ -63,15 +63,15 @@ function generateMappingsForStatus (field, notifications) { return typeof n2k.fields[field] !== 'undefined' }, value: function (n2k, state) { - const val = n2k.fields[field] + const val = n2k.fields[field] let on = false - if ( typeof val === 'number' ) { - on = val & (1< { + filter: n2k => { return typeof n2k.fields['Capacity'] !== 'undefined' } } diff --git a/pgns/127750.js b/pgns/127750.js index 42ac0e1a..6a73a997 100644 --- a/pgns/127750.js +++ b/pgns/127750.js @@ -1,5 +1,4 @@ - -function prefix(n2k) { +function prefix (n2k) { return `electrical.converter.${n2k.src}.${n2k.fields['Connection Number']}` } diff --git a/pgns/127751.js b/pgns/127751.js index e2ab8590..60fa5fb8 100644 --- a/pgns/127751.js +++ b/pgns/127751.js @@ -1,5 +1,4 @@ - -function prefix(n2k) { +function prefix (n2k) { return `electrical.dc.${n2k.src}.${n2k.fields['Connection Number']}` } @@ -11,5 +10,5 @@ module.exports = [ { source: 'DC Current', node: n2k => prefix(n2k) + '.current' - }, + } ] diff --git a/pgns/129038.js b/pgns/129038.js index 67f0e1a1..07f1bcd9 100644 --- a/pgns/129038.js +++ b/pgns/129038.js @@ -10,7 +10,7 @@ module.exports = [ node: 'navigation.courseOverGroundTrue' }, { - filter: (n2k) => n2k.fields.Longitude && n2k.fields.Latitude, + filter: n2k => n2k.fields.Longitude && n2k.fields.Latitude, value: function (n2k) { return { longitude: Number(n2k.fields.Longitude), @@ -84,5 +84,5 @@ const specialManeuverMapping = { 'Not available': 'not available', 'Not engaged in special maneuver': 'not engaged', 'Engaged in special maneuver': 'engaged', - 'Reserverd': 'reserved' + Reserverd: 'reserved' } diff --git a/pgns/129039.js b/pgns/129039.js index 08007836..3e25e505 100644 --- a/pgns/129039.js +++ b/pgns/129039.js @@ -10,7 +10,7 @@ module.exports = [ node: 'navigation.courseOverGroundTrue' }, { - filter: (n2k) => n2k.fields.Longitude && n2k.fields.Latitude, + filter: n2k => n2k.fields.Longitude && n2k.fields.Latitude, value: function (n2k) { return { longitude: Number(n2k.fields.Longitude), diff --git a/pgns/129040.js b/pgns/129040.js index 63a69984..8094c928 100644 --- a/pgns/129040.js +++ b/pgns/129040.js @@ -17,7 +17,7 @@ module.exports = [ node: 'navigation.destination.commonName' }, { - filter: (n2k) => n2k.fields.Longitude && n2k.fields.Latitude, + filter: n2k => n2k.fields.Longitude && n2k.fields.Latitude, value: function (n2k) { return { longitude: Number(n2k.fields.Longitude), diff --git a/pgns/129041.js b/pgns/129041.js index c7cfee63..2868a6e8 100644 --- a/pgns/129041.js +++ b/pgns/129041.js @@ -13,7 +13,7 @@ module.exports = [ } }, { - filter: (n2k) => n2k.fields.Longitude && n2k.fields.Latitude, + filter: n2k => n2k.fields.Longitude && n2k.fields.Latitude, value: function (n2k) { return { longitude: Number(n2k.fields.Longitude), @@ -66,14 +66,14 @@ module.exports = [ { node: 'virtual', value: function (n2k) { - const flag = n2k.fields['Virtual AtoN Flag'] + const flag = n2k.fields['Virtual AtoN Flag'] return typeof flag != 'undefined' ? flag === 'Yes' : undefined } }, { node: 'offPosition', value: function (n2k) { - const flag = n2k.fields['Off Position Indicator'] + const flag = n2k.fields['Off Position Indicator'] return typeof flag != 'undefined' ? flag === 'Yes' : undefined } }, @@ -88,7 +88,9 @@ module.exports = [ }, { context: function (n2k) { - return n2k.fields['User ID'] ? 'atons.urn:mrn:imo:mmsi:' + n2k.fields['User ID'] : undefined + return n2k.fields['User ID'] + ? 'atons.urn:mrn:imo:mmsi:' + n2k.fields['User ID'] + : undefined } }, { diff --git a/pgns/129540.js b/pgns/129540.js index 45ab9631..1b354226 100644 --- a/pgns/129540.js +++ b/pgns/129540.js @@ -8,21 +8,21 @@ module.exports = [ PRN: id, Elevation: elevation, Azimuth: azimuth, - SNR, + SNR } = satInfo acc.push({ id, elevation, azimuth, - SNR, + SNR }) } return acc }, []) return { count: satellites.length, - satellites, + satellites } - }, - }, + } + } ] diff --git a/pgns/129793.js b/pgns/129793.js index 2b554dec..688cc4a4 100644 --- a/pgns/129793.js +++ b/pgns/129793.js @@ -29,7 +29,9 @@ module.exports = [ }, { context: function (n2k) { - return typeof n2k.fields['User ID'] !== 'undefined' ? 'shore.basestations.urn:mrn:imo:mmsi:' + padUserID(n2k) : undefined + return typeof n2k.fields['User ID'] !== 'undefined' + ? 'shore.basestations.urn:mrn:imo:mmsi:' + padUserID(n2k) + : undefined } }, { diff --git a/pgns/129798.js b/pgns/129798.js index 1b86b822..0e43cf2e 100644 --- a/pgns/129798.js +++ b/pgns/129798.js @@ -10,14 +10,14 @@ module.exports = [ node: 'navigation.courseOverGroundTrue' }, { - filter: (n2k) => n2k.fields.Longitude && n2k.fields.Latitude, + filter: n2k => n2k.fields.Longitude && n2k.fields.Latitude, value: function (n2k) { var res = { longitude: Number(n2k.fields.Longitude), latitude: Number(n2k.fields.Latitude) } - if ( typeof n2k.fields.Altitude !== 'undefined' ) { - res.altitude = Number(n2k.fields.Altitude) + if (typeof n2k.fields.Altitude !== 'undefined') { + res.altitude = Number(n2k.fields.Altitude) } return res }, @@ -34,7 +34,9 @@ module.exports = [ }, { context: function (n2k) { - return typeof n2k.fields['User ID'] !== 'undefined' ? 'sar.urn:mrn:imo:mmsi:' + padUserID(n2k) : undefined + return typeof n2k.fields['User ID'] !== 'undefined' + ? 'sar.urn:mrn:imo:mmsi:' + padUserID(n2k) + : undefined } }, { diff --git a/pgns/130306.js b/pgns/130306.js index f266ee40..b09db53b 100644 --- a/pgns/130306.js +++ b/pgns/130306.js @@ -3,7 +3,10 @@ module.exports = [ source: 'Wind Speed', node: 'environment.wind.speedApparent', filter: function (n2k) { - return n2k.fields['Reference'] === 'Apparent' || n2k.fields['Reference'] === undefined + return ( + n2k.fields['Reference'] === 'Apparent' || + n2k.fields['Reference'] === undefined + ) } }, { @@ -23,7 +26,10 @@ module.exports = [ { node: 'environment.wind.angleApparent', filter: function (n2k) { - return n2k.fields['Reference'] === 'Apparent' || n2k.fields['Reference'] === undefined + return ( + n2k.fields['Reference'] === 'Apparent' || + n2k.fields['Reference'] === undefined + ) }, value: function (n2k) { var angle = Number(n2k.fields['Wind Angle']) diff --git a/pgns/130311.js b/pgns/130311.js index ed9d98eb..a20696c5 100644 --- a/pgns/130311.js +++ b/pgns/130311.js @@ -4,14 +4,11 @@ module.exports = [ { node: function (n2k) { var temperatureMapping = - temperatureMappings[n2k.fields['Temperature Source']] - + temperatureMappings[n2k.fields['Temperature Source']] + if (temperatureMapping) { if (temperatureMapping.pathWithIndex) { - return temperatureMapping.pathWithIndex.replace( - '', - 'default' - ) + return temperatureMapping.pathWithIndex.replace('', 'default') } else if (temperatureMapping.path) { return temperatureMapping.path } @@ -23,7 +20,9 @@ module.exports = [ node: function (n2k) { return ( 'environment.' + - (n2k.fields['Humidity Source'] === 'Inside' ? 'inside.relativeHumidity' : 'outside.humidity') + (n2k.fields['Humidity Source'] === 'Inside' + ? 'inside.relativeHumidity' + : 'outside.humidity') ) }, filter: function (n2k) { diff --git a/pgns/130312.js b/pgns/130312.js index 20fd0cf9..7bf07797 100644 --- a/pgns/130312.js +++ b/pgns/130312.js @@ -16,7 +16,9 @@ module.exports = [ return temperatureMapping.path } } else { - return `generic.temperatures.userDefined${n2k.fields['Source'].toString().replace(/\ /g, '_')}.${n2k.fields['Instance']}.temperature` + return `generic.temperatures.userDefined${n2k.fields['Source'] + .toString() + .replace(/\ /g, '_')}.${n2k.fields['Instance']}.temperature` } }, instance: function (n2k) { diff --git a/pgns/130313.js b/pgns/130313.js index c83968cd..bad0115d 100644 --- a/pgns/130313.js +++ b/pgns/130313.js @@ -3,7 +3,9 @@ module.exports = [ node: function (n2k) { return ( 'environment.' + - (n2k.fields['Source'] === 'Inside' ? 'inside.relativeHumidity' : 'outside.humidity') + (n2k.fields['Source'] === 'Inside' + ? 'inside.relativeHumidity' + : 'outside.humidity') ) }, filter: function (n2k) { @@ -15,4 +17,3 @@ module.exports = [ } } ] - diff --git a/pgns/acPower.js b/pgns/acPower.js index 370b2d45..5a1855fb 100644 --- a/pgns/acPower.js +++ b/pgns/acPower.js @@ -1,7 +1,5 @@ - -module.exports = (phase) => { - - function prefix(n2k) { +module.exports = phase => { + function prefix (n2k) { return `electrical.ac.${n2k.src}.${n2k.fields['Connection Number']}.${phase}` } diff --git a/pressureMappings.js b/pressureMappings.js index ed141a21..e4c68203 100644 --- a/pressureMappings.js +++ b/pressureMappings.js @@ -10,14 +10,14 @@ {"8": "Fuel"} */ module.exports = { - 'Atmospheric': { + Atmospheric: { path: 'environment.outside.pressure' }, - 'Water': { + Water: { path: 'water.default.pressure', pathWithIndex: 'water..pressure' }, - 'Steam': { + Steam: { path: 'steam.default.pressure', pathWithIndex: 'steam..pressure' }, @@ -25,23 +25,23 @@ module.exports = { path: 'compressedAir.default.pressure', pathWithIndex: 'compressedAir..pressure' }, - 'Hydraulic': { + Hydraulic: { path: 'hydraulic.default.pressure', pathWithIndex: 'hydraulic..pressure' }, - 'Filter': { + Filter: { path: 'filter.default.pressure', pathWithIndex: 'filter..pressure' }, - 'AltimeterSetting': { + AltimeterSetting: { path: 'altimetersetting.default.pressure', pathWithIndex: 'altimetersetting..pressure' }, - 'Oil': { + Oil: { path: 'oil.default.pressure', pathWithIndex: 'oil..pressure' }, - 'Fuel': { + Fuel: { path: 'fuel.default.pressure', pathWithIndex: 'fuel..pressure' } diff --git a/raymarine/126720.js b/raymarine/126720.js index c8893a94..efae8c63 100644 --- a/raymarine/126720.js +++ b/raymarine/126720.js @@ -1,9 +1,9 @@ const debug = require('debug')('n2k-signalk-126720') -module.exports = [ +module.exports = [ { // filters for SmartPilot behind Seatalk-STNG-Converter - filter: function(n2k) { + filter: function (n2k) { return ( n2k.description === 'Seatalk1: Pilot Mode' && n2k.fields['Manufacturer Code'] === 'Raymarine' && @@ -12,25 +12,34 @@ module.exports = [ ) }, node: 'steering.autopilot.state', - value: function(n2k) { - var mode = Number(n2k.fields['Pilot Mode']); - var subMode = Number(n2k.fields['Sub Mode']); - if ( (mode == 0 || mode == 64 || mode == 68 || mode == 72) && subMode == 0 ) { - return 'standby'; - } - else if ( mode == 70 && ( subMode == 0 || subMode == 4 || subMode == 8 || subMode ==12 ) ) { // submodes: 0=on course, 4=off course pt/stb, 8=wind shift, submode 12 tbd - return 'wind'; - } - else if (mode == 74 && subMode == 0 ) { - return 'route'; - } - else if ( mode == 66 && ( subMode == 0 || subMode == 4 ) ) { //subMode 4 means offcourse - return 'auto'; - } - else { - debug('Unknown PGN 126720 AP state found - Mode: ' + mode + ', SubMode: ' + subMode) - return; + value: function (n2k) { + var mode = Number(n2k.fields['Pilot Mode']) + var subMode = Number(n2k.fields['Sub Mode']) + if ( + (mode == 0 || mode == 64 || mode == 68 || mode == 72) && + subMode == 0 + ) { + return 'standby' + } else if ( + mode == 70 && + (subMode == 0 || subMode == 4 || subMode == 8 || subMode == 12) + ) { + // submodes: 0=on course, 4=off course pt/stb, 8=wind shift, submode 12 tbd + return 'wind' + } else if (mode == 74 && subMode == 0) { + return 'route' + } else if (mode == 66 && (subMode == 0 || subMode == 4)) { + //subMode 4 means offcourse + return 'auto' + } else { + debug( + 'Unknown PGN 126720 AP state found - Mode: ' + + mode + + ', SubMode: ' + + subMode + ) + return } } - }, -] \ No newline at end of file + } +] diff --git a/raymarine/65288.js b/raymarine/65288.js index 40be94a8..1feccbb0 100644 --- a/raymarine/65288.js +++ b/raymarine/65288.js @@ -1,33 +1,37 @@ - module.exports = [ { - filter: function(n2k) { - return n2k.fields['Manufacturer Code'] === 'Raymarine' - && typeof n2k.fields['Alarm Group'] !== 'undefined' - && typeof n2k.fields['Alarm Status'] !== 'undefined' + filter: function (n2k) { + return ( + n2k.fields['Manufacturer Code'] === 'Raymarine' && + typeof n2k.fields['Alarm Group'] !== 'undefined' && + typeof n2k.fields['Alarm Status'] !== 'undefined' + ) }, - node: function(n2k) { + node: function (n2k) { var alarmName = n2k.fields['Alarm ID'] - if ( typeof alarmName === 'string' ) { + if (typeof alarmName === 'string') { alarmName = alarmName.replace(/ /g, '') } else { alarmName = `unknown${alarmName}` } - - var path = n2k.fields['Alarm Group'].toLowerCase().replace(/ /g, '') + '.' + alarmName; - return 'notifications.' + path; + + var path = + n2k.fields['Alarm Group'].toLowerCase().replace(/ /g, '') + + '.' + + alarmName + return 'notifications.' + path }, - value: function(n2k) { - var state = n2k.fields['Alarm Status']; + value: function (n2k) { + var state = n2k.fields['Alarm Status'] - var method = [ 'visual' ]; + var method = ['visual'] - if ( state == 'Alarm condition met and not silenced' ) { - method.push('sound'); + if (state == 'Alarm condition met and not silenced') { + method.push('sound') } - if ( state == 'Alarm condition not met' ) { + if (state == 'Alarm condition not met') { state = 'normal' } else { state = 'alarm' @@ -35,12 +39,14 @@ module.exports = [ var alarmName = n2k.fields['Alarm ID'] - if ( typeof alarmName !== 'string' ) { + if (typeof alarmName !== 'string') { alarmName = `Unknown Seatalk Alarm ${alarmName}` - } else if ( state == 'alarm' - && (alarmName === 'WP Arrival' - || alarmName === 'Pilot Way Point Advance' - || alarmName === 'Pilot Route Complete') ) { + } else if ( + state == 'alarm' && + (alarmName === 'WP Arrival' || + alarmName === 'Pilot Way Point Advance' || + alarmName === 'Pilot Route Complete') + ) { state = 'alert' } diff --git a/raymarine/65345.js b/raymarine/65345.js index 9d4af768..2c42d48f 100644 --- a/raymarine/65345.js +++ b/raymarine/65345.js @@ -1,12 +1,10 @@ - module.exports = [ { node: 'steering.autopilot.target.windAngleApparent', - value: function(n2k) { + value: function (n2k) { var angle = Number(n2k.fields['Wind Datum']) - if ( angle > Math.PI ) - angle = angle-(Math.PI*2); - return angle; - } + if (angle > Math.PI) angle = angle - Math.PI * 2 + return angle + } } ] diff --git a/raymarine/65359.js b/raymarine/65359.js index 3ebe16aa..e8fbdad0 100644 --- a/raymarine/65359.js +++ b/raymarine/65359.js @@ -1,21 +1,23 @@ // PGN 65359 Seatalk: Pilot Heading module.exports = [ - { - node: 'navigation.headingTrue', - filter: function(n2k) { - return ( - n2k.description === 'Seatalk: Pilot Heading' && - typeof n2k.fields['Heading True'] !== 'undefined' - ) - }, - source: 'Heading True' + { + node: 'navigation.headingTrue', + filter: function (n2k) { + return ( + n2k.description === 'Seatalk: Pilot Heading' && + typeof n2k.fields['Heading True'] !== 'undefined' + ) }, - { - node: 'navigation.headingMagnetic', - filter: function(n2k) { - return n2k.description === 'Seatalk: Pilot Heading' && + source: 'Heading True' + }, + { + node: 'navigation.headingMagnetic', + filter: function (n2k) { + return ( + n2k.description === 'Seatalk: Pilot Heading' && typeof n2k.fields['Heading Magnetic'] !== 'undefined' - }, - source: 'Heading Magnetic' - } - ] \ No newline at end of file + ) + }, + source: 'Heading Magnetic' + } +] diff --git a/raymarine/65360.js b/raymarine/65360.js index 0821948c..6d4ce020 100644 --- a/raymarine/65360.js +++ b/raymarine/65360.js @@ -1,14 +1,14 @@ - module.exports = [ { node: 'steering.autopilot.target.headingTrue', - filter: function(n2k) { + filter: function (n2k) { return n2k.fields['Target Heading True'] }, source: 'Target Heading True' - },{ + }, + { node: 'steering.autopilot.target.headingMagnetic', - filter: function(n2k) { + filter: function (n2k) { return n2k.fields['Target Heading Magnetic'] }, source: 'Target Heading Magnetic' diff --git a/raymarine/65379.js b/raymarine/65379.js index c0a182bc..a2cdbe29 100644 --- a/raymarine/65379.js +++ b/raymarine/65379.js @@ -1,20 +1,14 @@ - -module.exports = [ +module.exports = [ { node: 'steering.autopilot.state', - value: function(n2k) { - var mode = Number(n2k.fields['Pilot Mode']); - var subMode = Number(n2k.fields['Sub Mode']); - if ( mode == 0 && subMode == 0 ) - return 'standby'; - else if ( mode == 0 && subMode == 1 ) - return 'wind'; - else if ( (mode == 128 || mode == 129) && subMode == 1 ) - return 'route'; - else if ( mode == 64 && subMode == 0 ) - return 'auto'; - else - return 'standby'; + value: function (n2k) { + var mode = Number(n2k.fields['Pilot Mode']) + var subMode = Number(n2k.fields['Sub Mode']) + if (mode == 0 && subMode == 0) return 'standby' + else if (mode == 0 && subMode == 1) return 'wind' + else if ((mode == 128 || mode == 129) && subMode == 1) return 'route' + else if (mode == 64 && subMode == 0) return 'auto' + else return 'standby' } } ] diff --git a/raymarine/index.js b/raymarine/index.js index dbe35b4f..16fece4c 100644 --- a/raymarine/index.js +++ b/raymarine/index.js @@ -5,4 +5,4 @@ module.exports = { 65360: require('./65360.js'), 65379: require('./65379.js'), 126720: require('./126720.js') -} \ No newline at end of file +} diff --git a/test/126983_alert.js b/test/126983_alert.js index 608a1576..8ff51425 100644 --- a/test/126983_alert.js +++ b/test/126983_alert.js @@ -2,66 +2,67 @@ var chai = require('chai') chai.Should() chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) -var expect = chai.expect; +var expect = chai.expect var mapper = require('./testMapper') //provided by PGN 126985 Alert Text var state = { - "40": { - "alerts": { - "23480": { - "languageId": "English (US)", - "locationTextDescription": "", - "textDescription": "TEST: Temperature over 0" + '40': { + alerts: { + '23480': { + languageId: 'English (US)', + locationTextDescription: '', + textDescription: 'TEST: Temperature over 0' } } } } var value = { - "state": "warn", - "method": [ - "visual", - "sound" - ], - "message": "TEST: Temperature over 0", - "alertType": "Warning", - "alertCategory": "Navigational", - "alertSystem": 20, - "alertId": 23480, - "dataSourceNetworkIDNAME": 6458553273545042000, - "dataSourceInstance": 0, - "dataSourceIndex-Source": 0, - "occurrence": 1, - "temporarySilenceStatus": "Not Temporary Silence", - "acknowledgeStatus": "Not Acknowledged", - "escalationStatus": "Not Escalated", - "temporarySilenceSupport": "Supported", - "acknowledgeSupport": "Supported", - "escalationSupport": "Not Supported", - "acknowledgeSourceNetworkIDNAME": 1233993542451364400, - "triggerCondition": "Auto", - "thresholdStatus": "Threshold Exceeded", - "alertPriority": 187, - "alertState": "Active" + state: 'warn', + method: ['visual', 'sound'], + message: 'TEST: Temperature over 0', + alertType: 'Warning', + alertCategory: 'Navigational', + alertSystem: 20, + alertId: 23480, + dataSourceNetworkIDNAME: 6458553273545042000, + dataSourceInstance: 0, + 'dataSourceIndex-Source': 0, + occurrence: 1, + temporarySilenceStatus: 'Not Temporary Silence', + acknowledgeStatus: 'Not Acknowledged', + escalationStatus: 'Not Escalated', + temporarySilenceSupport: 'Supported', + acknowledgeSupport: 'Supported', + escalationSupport: 'Not Supported', + acknowledgeSourceNetworkIDNAME: 1233993542451364400, + triggerCondition: 'Auto', + thresholdStatus: 'Threshold Exceeded', + alertPriority: 187, + alertState: 'Active' } -describe('126983 Alert', function() { - it('alert without silence or ackknowledgement', function() { +describe('126983 Alert', function () { + it('alert without silence or ackknowledgement', function () { var msg = JSON.parse( '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Not Temporary Silence","Acknowledge Status":"Not Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Supported","Acknowledge Support":"Supported","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' ) var tree = mapper.toNested(msg, state) - tree.should.have.nested.property('notifications.nmea.warning.navigational.20.23480.value') + tree.should.have.nested.property( + 'notifications.nmea.warning.navigational.20.23480.value' + ) - expect(tree.notifications.nmea.warning.navigational[20][23480].value).to.deep.include(value) + expect( + tree.notifications.nmea.warning.navigational[20][23480].value + ).to.deep.include(value) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) }) - it('alert with temporary silence', function() { + it('alert with temporary silence', function () { //method should be empty for this test value.method = [] value.temporarySilenceStatus = 'Temporary Silence' @@ -70,15 +71,19 @@ describe('126983 Alert', function() { '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Temporary Silence","Acknowledge Status":"Not Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Supported","Acknowledge Support":"Supported","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' ) var tree = mapper.toNested(msg, state) - tree.should.have.nested.property('notifications.nmea.warning.navigational.20.23480.value') + tree.should.have.nested.property( + 'notifications.nmea.warning.navigational.20.23480.value' + ) - expect(tree.notifications.nmea.warning.navigational[20][23480].value).to.deep.include(value) + expect( + tree.notifications.nmea.warning.navigational[20][23480].value + ).to.deep.include(value) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) }) - it('alert with acknowledgement', function() { + it('alert with acknowledgement', function () { value.temporarySilenceStatus = 'Not Temporary Silence' value.acknowledgeStatus = 'Acknowledged' @@ -86,9 +91,13 @@ describe('126983 Alert', function() { '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Not Temporary Silence","Acknowledge Status":"Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Supported","Acknowledge Support":"Supported","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' ) var tree = mapper.toNested(msg, state) - tree.should.have.nested.property('notifications.nmea.warning.navigational.20.23480.value') + tree.should.have.nested.property( + 'notifications.nmea.warning.navigational.20.23480.value' + ) - expect(tree.notifications.nmea.warning.navigational[20][23480].value).to.deep.include(value) + expect( + tree.notifications.nmea.warning.navigational[20][23480].value + ).to.deep.include(value) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) diff --git a/test/126985_alert_text.js b/test/126985_alert_text.js index 7201779a..4d4825c1 100644 --- a/test/126985_alert_text.js +++ b/test/126985_alert_text.js @@ -2,7 +2,7 @@ var chai = require('chai') chai.Should() chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) -var expect = chai.expect; +var expect = chai.expect const mapper = require('./testMapper') @@ -17,7 +17,17 @@ describe('126985 alert text', function () { state ) - var text = {"40":{"alerts":{"23480":{"languageId":"English (US)","locationTextDescription": "","textDescription":"TEST: Temperature over 0"}}}} + var text = { + '40': { + alerts: { + '23480': { + languageId: 'English (US)', + locationTextDescription: '', + textDescription: 'TEST: Temperature over 0' + } + } + } + } expect(state).to.deep.include(text) }) }) diff --git a/test/127237_heading_track_control.js b/test/127237_heading_track_control.js index b6d6dcaf..614cd981 100644 --- a/test/127237_heading_track_control.js +++ b/test/127237_heading_track_control.js @@ -13,7 +13,10 @@ describe('127237 Heading/Track Control ', function () { 'timestamp', '2021-07-13T07:00:01.412Z' ) - tree.steering.autopilot.target.headingMagnetic.should.have.property('value', 3.2115) + tree.steering.autopilot.target.headingMagnetic.should.have.property( + 'value', + 3.2115 + ) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127488_engine_boost.js b/test/127488_engine_boost.js index 8fa5c50e..84cdda6e 100644 --- a/test/127488_engine_boost.js +++ b/test/127488_engine_boost.js @@ -49,10 +49,7 @@ describe('127488 engine boost 2', function () { ).forEach(pgn => { var tree = require('./testMapper').toNested(JSON.parse(pgn)) tree.should.have.nested.property('propulsion.2.boostPressure') - tree.should.have.nested.property( - 'propulsion.2.boostPressure.value', - 129 - ) + tree.should.have.nested.property('propulsion.2.boostPressure.value', 129) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127493_transmission.js b/test/127493_transmission.js index f5e7c19a..df2cafe8 100644 --- a/test/127493_transmission.js +++ b/test/127493_transmission.js @@ -49,7 +49,7 @@ describe('127493 transmission parameters Port', function () { //temporarily until the specification is fixed delete tree.propulsion.port.transmission.gear - + tree.should.be.validSignalKVesselIgnoringIdentity }) }) @@ -95,7 +95,7 @@ describe('127493 transmission parameters Port', function () { //temporarily until the specification is fixed delete tree.propulsion.port.transmission.gear - + tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127497_trip_params.js b/test/127497_trip_params.js index 77f6218b..e74caeea 100644 --- a/test/127497_trip_params.js +++ b/test/127497_trip_params.js @@ -4,9 +4,11 @@ chai.use(require('chai-things')) describe('127497 Trip Parameters, Engine', function () { it('complete engine boost sentence converts', function () { - var tree = require('./testMapper').toNested(JSON.parse( - '{"prio":5,"pgn":127497,"dst":255,"src":56,"timestamp":"2017-10-06T07:52:53.225Z","fields":{"Instance":"Dual Engine Starboard","Trip Fuel Used":4271, "Fuel Rate, Average": 100,"Fuel Rate, Economy": 90,"Instantaneous Fuel Economy":210},"description":"Trip Parameters, Engine"}' - )) + var tree = require('./testMapper').toNested( + JSON.parse( + '{"prio":5,"pgn":127497,"dst":255,"src":56,"timestamp":"2017-10-06T07:52:53.225Z","fields":{"Instance":"Dual Engine Starboard","Trip Fuel Used":4271, "Fuel Rate, Average": 100,"Fuel Rate, Economy": 90,"Instantaneous Fuel Economy":210},"description":"Trip Parameters, Engine"}' + ) + ) tree.should.have.nested.property( 'propulsion.starboard.trip.fuelUsed.value', 4.271 @@ -25,4 +27,3 @@ describe('127497 Trip Parameters, Engine', function () { ) }) }) - diff --git a/test/127505_fluid_level.js b/test/127505_fluid_level.js index 06b01f88..94675702 100644 --- a/test/127505_fluid_level.js +++ b/test/127505_fluid_level.js @@ -36,7 +36,10 @@ describe('127505 water', function () { 0.88596, 0.000005 ) - tree.should.have.nested.property('tanks.freshWater.0.capacity.value', 0.0719) + tree.should.have.nested.property( + 'tanks.freshWater.0.capacity.value', + 0.0719 + ) tree.should.be.validSignalKVesselIgnoringIdentity }) }) @@ -52,7 +55,10 @@ describe('127505 grayWater', function () { 'tanks.wasteWater.0.currentLevel.value', 0.9024 ) - tree.should.have.nested.property('tanks.wasteWater.0.capacity.value', 0.037899999999999996) + tree.should.have.nested.property( + 'tanks.wasteWater.0.capacity.value', + 0.037899999999999996 + ) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127744_ac_power.js b/test/127744_ac_power.js index de3e3e73..cae0e5fb 100644 --- a/test/127744_ac_power.js +++ b/test/127744_ac_power.js @@ -4,22 +4,20 @@ chai.use(require('chai-things')) describe('127744 ac power/currrent', function () { it('complete sentence converts', function () { - var tree = require('./testMapper').toNested( - { - timestamp:"2020-07-28T01:46:48.714Z", - prio:6, - src:33, - dst:255, - pgn:127744, - description: "AC Power / Current- Phase A", - fields: { - SID:133, - "Connection Number":0, - "AC RMS Current":11, - Power: 120 - } + var tree = require('./testMapper').toNested({ + timestamp: '2020-07-28T01:46:48.714Z', + prio: 6, + src: 33, + dst: 255, + pgn: 127744, + description: 'AC Power / Current- Phase A', + fields: { + SID: 133, + 'Connection Number': 0, + 'AC RMS Current': 11, + Power: 120 } - ) + }) tree.should.have.nested.property( 'electrical.ac.33.0.phase.A.power.value', 120 diff --git a/test/127745_ac_power.js b/test/127745_ac_power.js index 86c151bc..e3f84d71 100644 --- a/test/127745_ac_power.js +++ b/test/127745_ac_power.js @@ -4,22 +4,20 @@ chai.use(require('chai-things')) describe('127745 ac power/currrent', function () { it('complete sentence converts', function () { - var tree = require('./testMapper').toNested( - { - timestamp:"2020-07-28T01:46:48.714Z", - prio:6, - src:33, - dst:255, - pgn:127745, - description: "AC Power / Current- Phase B", - fields: { - SID:133, - "Connection Number":0, - "AC RMS Current":11, - Power: 120 - } + var tree = require('./testMapper').toNested({ + timestamp: '2020-07-28T01:46:48.714Z', + prio: 6, + src: 33, + dst: 255, + pgn: 127745, + description: 'AC Power / Current- Phase B', + fields: { + SID: 133, + 'Connection Number': 0, + 'AC RMS Current': 11, + Power: 120 } - ) + }) tree.should.have.nested.property( 'electrical.ac.33.0.phase.B.power.value', 120 diff --git a/test/127746_ac_power.js b/test/127746_ac_power.js index 67e0ba18..53393962 100644 --- a/test/127746_ac_power.js +++ b/test/127746_ac_power.js @@ -4,22 +4,20 @@ chai.use(require('chai-things')) describe('127746 ac power/currrent', function () { it('complete sentence converts', function () { - var tree = require('./testMapper').toNested( - { - timestamp:"2020-07-28T01:46:48.714Z", - prio:6, - src:33, - dst:255, - pgn:127746, - description: "AC Power / Current- Phase C", - fields: { - SID:133, - "Connection Number":0, - "AC RMS Current":11, - Power: 120 - } + var tree = require('./testMapper').toNested({ + timestamp: '2020-07-28T01:46:48.714Z', + prio: 6, + src: 33, + dst: 255, + pgn: 127746, + description: 'AC Power / Current- Phase C', + fields: { + SID: 133, + 'Connection Number': 0, + 'AC RMS Current': 11, + Power: 120 } - ) + }) tree.should.have.nested.property( 'electrical.ac.33.0.phase.C..power.value', 120 diff --git a/test/127750_converter_status.js b/test/127750_converter_status.js index 4aa5ed23..a8c65610 100644 --- a/test/127750_converter_status.js +++ b/test/127750_converter_status.js @@ -4,24 +4,22 @@ chai.use(require('chai-things')) describe('127750 converter status', function () { it('complete sentence converts', function () { - var tree = require('./testMapper').toNested( - { - timestamp:'2016-11-26T20:40:00.895Z', - prio:7, - src:10, - dst:255, - pgn:127750, - description:'Converter Status', - fields: { - 'Connection Number': 1, - 'Operating State': 'Absorption', - 'Temperature State': 'Warning', - 'Overload State': 'Overload', - 'Low DC Voltage State': 'DC voltage too low', - 'Ripple State': 'Ripple Too High' - } + var tree = require('./testMapper').toNested({ + timestamp: '2016-11-26T20:40:00.895Z', + prio: 7, + src: 10, + dst: 255, + pgn: 127750, + description: 'Converter Status', + fields: { + 'Connection Number': 1, + 'Operating State': 'Absorption', + 'Temperature State': 'Warning', + 'Overload State': 'Overload', + 'Low DC Voltage State': 'DC voltage too low', + 'Ripple State': 'Ripple Too High' } - ) + }) tree.should.have.nested.property( 'electrical.converter.10.1.operatingState.value', 'absorption' @@ -45,24 +43,22 @@ describe('127750 converter status', function () { }) it('unknown states convert', function () { - var tree = require('./testMapper').toNested( - { - timestamp:'2016-11-26T20:40:00.895Z', - prio:7, - src:10, - dst:255, - pgn:127750, - description:'Converter Status', - fields: { - 'Connection Number': 100, - 'Operating State': 100, - 'Temperature State': 100, - 'Overload State': 100, - 'Low DC Voltage State': 'DC voltage too low', - 'Ripple State': 'Ripple Too High' - } + var tree = require('./testMapper').toNested({ + timestamp: '2016-11-26T20:40:00.895Z', + prio: 7, + src: 10, + dst: 255, + pgn: 127750, + description: 'Converter Status', + fields: { + 'Connection Number': 100, + 'Operating State': 100, + 'Temperature State': 100, + 'Overload State': 100, + 'Low DC Voltage State': 'DC voltage too low', + 'Ripple State': 'Ripple Too High' } - ) + }) tree.should.not.have.nested.property( 'electrical.converter.10.1.operatingState.value' ) diff --git a/test/127751_dv_voltage_current.js b/test/127751_dv_voltage_current.js index 6708ec4a..7dd56d7c 100644 --- a/test/127751_dv_voltage_current.js +++ b/test/127751_dv_voltage_current.js @@ -4,28 +4,20 @@ chai.use(require('chai-things')) describe('127750 converter status', function () { it('complete sentence converts', function () { - var tree = require('./testMapper').toNested( - { - timestamp:'2016-11-26T20:40:00.895Z', - prio:7, - src:15, - dst:255, - pgn:127751, - description:'DC Voltage/Current', - fields: { - 'Connection Number': 2, - 'DC Voltage': 12.5, - 'DC Current': 6 - } + var tree = require('./testMapper').toNested({ + timestamp: '2016-11-26T20:40:00.895Z', + prio: 7, + src: 15, + dst: 255, + pgn: 127751, + description: 'DC Voltage/Current', + fields: { + 'Connection Number': 2, + 'DC Voltage': 12.5, + 'DC Current': 6 } - ) - tree.should.have.nested.property( - 'electrical.dc.15.2.voltage.value', - 12.5 - ) - tree.should.have.nested.property( - 'electrical.dc.15.2.current.value', - 6 - ) + }) + tree.should.have.nested.property('electrical.dc.15.2.voltage.value', 12.5) + tree.should.have.nested.property('electrical.dc.15.2.current.value', 6) }) }) diff --git a/test/129038_ais_class_a.js b/test/129038_ais_class_a.js index 19dfbe43..df419be5 100644 --- a/test/129038_ais_class_a.js +++ b/test/129038_ais_class_a.js @@ -44,7 +44,10 @@ describe('129038 Class A Update', function () { ) var tree = mapper.toNested(msg) tree.should.have.nested.property('navigation.state') - tree.should.have.nested.property('navigation.specialManeuver.value', 'engaged') + tree.should.have.nested.property( + 'navigation.specialManeuver.value', + 'engaged' + ) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) delta.context.should.equal('vessels.urn:mrn:imo:mmsi:230982000') @@ -52,33 +55,33 @@ describe('129038 Class A Update', function () { it('no User Id produces no output', function () { const msg = { - "prio": 4, - "pgn": 129038, - "dst": 255, - "src": 3, - "timer": 9256.214, - "input": [ - "!PDGY,129038,4,3,255,9256.214,wwAAAAAp1QwGt4hmIMjsXAAAAAAAoHYAAPX+" + prio: 4, + pgn: 129038, + dst: 255, + src: 3, + timer: 9256.214, + input: [ + '!PDGY,129038,4,3,255,9256.214,wwAAAAAp1QwGt4hmIMjsXAAAAAAAoHYAAPX+' ], - "fields": { - "Message ID": 3, - "User ID": 0, - "Longitude": 10.1504297, - "Latitude": 54.3590583, - "Position Accuracy": "Low", - "RAIM": "not in use", - "Time Stamp": "50", - "COG": 2.3788, - "SOG": 0, - "Communication State": "0", - "AIS Transceiver information": "Channel A VDL reception", - "Heading": 3.0368, - "Rate of Turn": 0, - "Nav Status": "Moored", - "AIS Spare": "6" + fields: { + 'Message ID': 3, + 'User ID': 0, + Longitude: 10.1504297, + Latitude: 54.3590583, + 'Position Accuracy': 'Low', + RAIM: 'not in use', + 'Time Stamp': '50', + COG: 2.3788, + SOG: 0, + 'Communication State': '0', + 'AIS Transceiver information': 'Channel A VDL reception', + Heading: 3.0368, + 'Rate of Turn': 0, + 'Nav Status': 'Moored', + 'AIS Spare': '6' }, - "description": "AIS Class A Position Report", - "timestamp": "2022-05-09T13:38:38.917Z" + description: 'AIS Class A Position Report', + timestamp: '2022-05-09T13:38:38.917Z' } const deltaType = typeof mapper.toDelta(msg, {}) deltaType.should.equal('undefined') diff --git a/test/129040_class_b_extended.js b/test/129040_class_b_extended.js index 18a095d5..efa12bd8 100644 --- a/test/129040_class_b_extended.js +++ b/test/129040_class_b_extended.js @@ -17,7 +17,7 @@ describe('129040 AIS Class B Extended Position Repeat', function () { delta.updates[0].values[0].path.should.equal('') delta.updates[0].values[0].value.name.should.equal('RESCUE RAUTAUOMA') assertSensorClass(delta, 'B') - + var tree = mapper.toNested(msg) tree.should.have.nested.property('design.length.value.overall', 16.0) tree.should.have.nested.property('design.aisShipType.value.id', 51) diff --git a/test/129540_sats_in_view.js b/test/129540_sats_in_view.js index eff221c7..7016aa39 100644 --- a/test/129540_sats_in_view.js +++ b/test/129540_sats_in_view.js @@ -18,7 +18,7 @@ describe('129540 satellites in view', function () { id: 2, SNR: 43, azimuth: 1.5358, - elevation: 0.9424, + elevation: 0.9424 }) }) }) diff --git a/test/129794_ais_class_a_static_data.js b/test/129794_ais_class_a_static_data.js index 09815351..80b94985 100644 --- a/test/129794_ais_class_a_static_data.js +++ b/test/129794_ais_class_a_static_data.js @@ -50,26 +50,32 @@ describe('129794 AIS Class A Static and Voyage Related Data', function () { delta.context.should.equal('vessels.urn:mrn:imo:mmsi:356307000') assertSensorClass(delta, 'A') - const valuesWithEmptyPath = delta.updates[0].values.filter(pathValue => pathValue.path === '') + const valuesWithEmptyPath = delta.updates[0].values.filter( + pathValue => pathValue.path === '' + ) valuesWithEmptyPath.length.should.equal(3) - expect(valuesWithEmptyPath).to.have.deep.members([{ - path: '', - value: { - name: 'SILVER GWEN' - } - }, { - path: '', - value: { - 'mmsi': '356307000' - } - }, { - path: '', - value: { - registrations: { - imo: 'IMO 9683362' + expect(valuesWithEmptyPath).to.have.deep.members([ + { + path: '', + value: { + name: 'SILVER GWEN' + } + }, + { + path: '', + value: { + mmsi: '356307000' + } + }, + { + path: '', + value: { + registrations: { + imo: 'IMO 9683362' + } } } - }]) + ]) var tree = mapper.toNested(msg) tree.should.have.nested.property('design.draft.value.maximum', 10.6) tree.should.have.nested.property('design.length.value.overall', 183.0) @@ -92,39 +98,41 @@ describe('129794 AIS Class A Static and Voyage Related Data', function () { it('Empty destination converts to empty string', () => { const msg = { - "prio": 6, - "pgn": 129794, - "dst": 255, - "src": 43, - "timestamp": "2014-08-15T19:05:41.030Z", - "input": [ - "2014-08-15T19:05:41.030Z,6,129794,43,255,75,05,b0,7f,79,10,00,00,00,00,45,53,59,32,31,31,31,50,56,4c,2d,31,31,31,20,56,41,50,50,45,52,20,20,20,20,20,20,37,7c,01,3c,00,14,00,b4,00,14,40,00,00,00,00,00,00,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,00,e1" + prio: 6, + pgn: 129794, + dst: 255, + src: 43, + timestamp: '2014-08-15T19:05:41.030Z', + input: [ + '2014-08-15T19:05:41.030Z,6,129794,43,255,75,05,b0,7f,79,10,00,00,00,00,45,53,59,32,31,31,31,50,56,4c,2d,31,31,31,20,56,41,50,50,45,52,20,20,20,20,20,20,37,7c,01,3c,00,14,00,b4,00,14,40,00,00,00,00,00,00,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,00,e1' ], - "fields": { - "Message ID": 5, - "Repeat indicator": "Initial", - "User ID": 276398000, - "IMO number": 0, - "Callsign": "ESY2111", - "Name": "PVL-111 VAPPER", - "Type of ship": "Law enforcement", - "Length": 38, - "Beam": 6, - "Position reference from Starboard": 2, - "Position reference from Bow": 18, - "ETA Date": "2014.11.30", - "ETA Time": "00:00:00", - "Draft": 0, - "Destination": "", - "AIS version indicator": "ITU-R M.1371-1", - "GNSS type": "undefined", - "DTE": "available", - "Reserved1": "0", - "AIS Transceiver information": "Channel B VDL reception" + fields: { + 'Message ID': 5, + 'Repeat indicator': 'Initial', + 'User ID': 276398000, + 'IMO number': 0, + Callsign: 'ESY2111', + Name: 'PVL-111 VAPPER', + 'Type of ship': 'Law enforcement', + Length: 38, + Beam: 6, + 'Position reference from Starboard': 2, + 'Position reference from Bow': 18, + 'ETA Date': '2014.11.30', + 'ETA Time': '00:00:00', + Draft: 0, + Destination: '', + 'AIS version indicator': 'ITU-R M.1371-1', + 'GNSS type': 'undefined', + DTE: 'available', + Reserved1: '0', + 'AIS Transceiver information': 'Channel B VDL reception' }, - "description": "AIS Class A Static and Voyage Related Data" + description: 'AIS Class A Static and Voyage Related Data' } const delta = mapper.toDelta(msg) - delta.updates[0].values.find((pv) => pv.path === 'navigation.destination.commonName').value.should.equal('') + delta.updates[0].values + .find(pv => pv.path === 'navigation.destination.commonName') + .value.should.equal('') }) }) diff --git a/test/129809_ais_class_b_static_data.js b/test/129809_ais_class_b_static_data.js index b1be3370..a73de9f0 100644 --- a/test/129809_ais_class_b_static_data.js +++ b/test/129809_ais_class_b_static_data.js @@ -13,8 +13,12 @@ describe('129809 Class B static data', function () { var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) delta.context.should.equal('vessels.urn:mrn:imo:mmsi:230044160') - delta.updates[0].values.find(pathValue => pathValue.path === '').value.name.should.equal('LAGUNA') - delta.updates[0].values.find(pathValue => pathValue.path === 'sensors.ais.class').value.should.equal('B') + delta.updates[0].values + .find(pathValue => pathValue.path === '') + .value.name.should.equal('LAGUNA') + delta.updates[0].values + .find(pathValue => pathValue.path === 'sensors.ais.class') + .value.should.equal('B') var tree = mapper.toNested(msg) //TODO enable when sensors.ais.class is in the schema //tree.should.be.validSignalKVesselIgnoringIdentity diff --git a/test/130310-2.json b/test/130310-2.json index a6033113..a8f1dd5f 100644 --- a/test/130310-2.json +++ b/test/130310-2.json @@ -476,7 +476,7 @@ "timestamp": "2015-01-15-16:15:19.628Z", "prio": "5", "src": "36", - "dst": "255", + "dst": "255", "pgn": "130312", "description": "Temperature", "fields": { diff --git a/test/130314-data.json b/test/130314-data.json index f4b63d83..d52f0fe7 100644 --- a/test/130314-data.json +++ b/test/130314-data.json @@ -19,10 +19,10 @@ "pgn": "130314", "description": "Actual Pressure", "fields": { - "SID":0, - "Instance":0, - "Source":"Atmospheric", - "Pressure":100578 + "SID": 0, + "Instance": 0, + "Source": "Atmospheric", + "Pressure": 100578 }, "testExpectConvertedValues": { "environment.outside.pressure": 100578 @@ -36,10 +36,10 @@ "pgn": "130314", "description": "Actual Pressure", "fields": { - "SID":0, - "Instance":2, - "Source":"Water", - "Pressure":180911.6 + "SID": 0, + "Instance": 2, + "Source": "Water", + "Pressure": 180911.6 }, "testExpectConvertedValues": { "water.2.pressure": 180911.6 @@ -53,10 +53,10 @@ "pgn": "130314", "description": "Actual Pressure", "fields": { - "SID":0, - "Instance":2, - "Source":"Steam", - "Pressure":180911.6 + "SID": 0, + "Instance": 2, + "Source": "Steam", + "Pressure": 180911.6 }, "testExpectConvertedValues": { "steam.2.pressure": 180911.6 @@ -70,10 +70,10 @@ "pgn": "130314", "description": "Actual Pressure", "fields": { - "SID":0, - "Instance":2, - "Source":"Compressed Air", - "Pressure":180911.6 + "SID": 0, + "Instance": 2, + "Source": "Compressed Air", + "Pressure": 180911.6 }, "testExpectConvertedValues": { "compressedAir.2.pressure": 180911.6 @@ -87,10 +87,10 @@ "pgn": "130314", "description": "Actual Pressure", "fields": { - "SID":0, - "Instance":2, - "Source":"Hydraulic", - "Pressure":180911.6 + "SID": 0, + "Instance": 2, + "Source": "Hydraulic", + "Pressure": 180911.6 }, "testExpectConvertedValues": { "hydraulic.2.pressure": 180911.6 diff --git a/test/130314_pressure_new.js b/test/130314_pressure_new.js index 1ae1a6e2..008fee53 100644 --- a/test/130314_pressure_new.js +++ b/test/130314_pressure_new.js @@ -7,7 +7,7 @@ var _ = require('lodash') describe('Pressure: ', function () { var n2kMapper = require('./testMapper') - var full = new (require('@signalk/signalk-schema')).FullSignalK( + var full = new (require('@signalk/signalk-schema').FullSignalK)( 'urn:mrn:imo:mmsi:230099999' ) @@ -33,11 +33,7 @@ describe('Pressure: ', function () { ) expectedValueFound[0].value.should.equal( testCase['testExpectConvertedValues'][expectedValuePath], - `Value ${expectedValuePath} incorrectly converted to ${ - expectedValueFound[0].value - } - expected ${ - testCase['testExpectConvertedValues'][expectedValuePath] - }` + `Value ${expectedValuePath} incorrectly converted to ${expectedValueFound[0].value} - expected ${testCase['testExpectConvertedValues'][expectedValuePath]}` ) } ) @@ -50,7 +46,7 @@ describe('Pressure: ', function () { it('all 130314 mappings are valid', function () { var pressureMappings = require('../pressureMappings') - var full = new (require('@signalk/signalk-schema')).FullSignalK( + var full = new (require('@signalk/signalk-schema').FullSignalK)( 'urn:mrn:imo:mmsi:230099999' ) _.forOwn(pressureMappings, function (mapping, key) { diff --git a/test/13031_temperature.js b/test/13031_temperature.js index 17f98fc8..1febb42b 100644 --- a/test/13031_temperature.js +++ b/test/13031_temperature.js @@ -7,7 +7,7 @@ var _ = require('lodash') describe('Temperature: ', function () { var n2kMapper = require('./testMapper') - var full = new (require('@signalk/signalk-schema')).FullSignalK( + var full = new (require('@signalk/signalk-schema').FullSignalK)( 'urn:mrn:imo:mmsi:230099999' ) @@ -29,20 +29,20 @@ describe('Temperature: ', function () { ) expectedValueFound.length.should.equal( 1, - `Expected value ${expectedValuePath} not found in ${JSON.stringify(delta, null, 2)}` + `Expected value ${expectedValuePath} not found in ${JSON.stringify( + delta, + null, + 2 + )}` ) expectedValueFound[0].value.should.equal( testCase['testExpectConvertedValues'][expectedValuePath], - `Value ${expectedValuePath} incorrectly converted to ${ - expectedValueFound[0].value - } - expected ${ - testCase['testExpectConvertedValues'][expectedValuePath] - }` + `Value ${expectedValuePath} incorrectly converted to ${expectedValueFound[0].value} - expected ${testCase['testExpectConvertedValues'][expectedValuePath]}` ) } ) - if(!testCase.notInSpec || testCase.notInSpec == false){ + if (!testCase.notInSpec || testCase.notInSpec == false) { var fullDoc = full.retrieve() fullDoc.vessels['urn:mrn:imo:mmsi:230099999'].mmsi = '230099999' fullDoc.should.be.validSignalK @@ -52,15 +52,14 @@ describe('Temperature: ', function () { it('all 130312 mappings are valid', function () { var temperatureMappings = require('../temperatureMappings') - var full = new (require('@signalk/signalk-schema')).FullSignalK( + var full = new (require('@signalk/signalk-schema').FullSignalK)( 'urn:mrn:imo:mmsi:230099999' ) _.forOwn(temperatureMappings, function (mapping, key) { + let path = mapping.pathWithIndex + ? mapping.pathWithIndex.replace('', '0') + : mapping.path - let path = mapping.pathWithIndex ? - mapping.pathWithIndex.replace('','0') - : mapping.path - var delta = { context: 'vessels.urn:mrn:imo:mmsi:230099999', updates: [ diff --git a/test/65359_seatalk_pilot_heading.js b/test/65359_seatalk_pilot_heading.js index 4ca32c52..d6e9bbea 100644 --- a/test/65359_seatalk_pilot_heading.js +++ b/test/65359_seatalk_pilot_heading.js @@ -10,10 +10,7 @@ describe('65359 Seatalk Pilot Heading', function () { '{"timestamp":"2016-10-18T15:52:49.041Z","prio":7,"src":115,"dst":255,"pgn":65359,"description":"Seatalk: Pilot Heading","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Heading Magnetic":3.0422}}' ) ) - tree.should.have.nested.property( - 'navigation.headingMagnetic.value', - 3.0422 - ) + tree.should.have.nested.property('navigation.headingMagnetic.value', 3.0422) tree.should.be.validSignalKVesselIgnoringIdentity }) it('complet true sentence converts', function () { @@ -22,10 +19,7 @@ describe('65359 Seatalk Pilot Heading', function () { '{"timestamp":"2016-10-18T15:52:49.041Z","prio":7,"src":115,"dst":255,"pgn":65359,"description":"Seatalk: Pilot Heading","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Heading True":3.0422}}' ) ) - tree.should.have.nested.property( - 'navigation.headingTrue.value', - 3.0422 - ) + tree.should.have.nested.property('navigation.headingTrue.value', 3.0422) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/ais_utils.js b/test/ais_utils.js index 00b3b8a4..4d058c86 100644 --- a/test/ais_utils.js +++ b/test/ais_utils.js @@ -1,6 +1,6 @@ module.exports = { assertSensorClass: (delta, theClass) => delta.updates[0].values - .find((pathValue) => pathValue.path === "sensors.ais.class") + .find(pathValue => pathValue.path === 'sensors.ais.class') .value.should.equal(theClass) } diff --git a/test/customPgns.js b/test/customPgns.js index 1578e48e..e02f38c2 100644 --- a/test/customPgns.js +++ b/test/customPgns.js @@ -1,7 +1,7 @@ const N2kMapper = require('../n2kMapper').N2kMapper const EventEmitter = require('events') const signalkSchema = require('@signalk/signalk-schema') -const PropertyValues = require('@signalk/server-api').PropertyValues +const PropertyValues = require('@signalk/server-api').PropertyValues var chai = require('chai') chai.Should() @@ -12,11 +12,7 @@ const mappings = { 127999: [ { node: function (n2k) { - return ( - 'tanks.fuel.' + - n2k.fields['Instance'] + - '.customCurrentLevel' - ) + return 'tanks.fuel.' + n2k.fields['Instance'] + '.customCurrentLevel' }, value: function (n2k) { var ratio100 = Number(n2k.fields['Level']) @@ -28,7 +24,7 @@ const mappings = { describe('custom pgns', function () { it('custom fulid pgn works', function () { - const propertyValues = new PropertyValues(); + const propertyValues = new PropertyValues() propertyValues.emitPropertyValue({ timestamp: Date.now(), @@ -36,16 +32,25 @@ describe('custom pgns', function () { name: 'pgn-to-signalk', value: mappings }) - - const n2kMapper = new N2kMapper({ onPropertyValues: propertyValues.onPropertyValues.bind(propertyValues) }) - - var delta = n2kMapper.toDelta(JSON.parse( - '{"timestamp":"2015-01-15-16:15:30.984Z","prio":"6","src":"17","dst":"255","pgn":"127999","description":"Fluid Level","fields":{"Instance":"0","Type":"Fuel","Level":"131.068"}}' - )) + + const n2kMapper = new N2kMapper({ + onPropertyValues: propertyValues.onPropertyValues.bind(propertyValues) + }) + + var delta = n2kMapper.toDelta( + JSON.parse( + '{"timestamp":"2015-01-15-16:15:30.984Z","prio":"6","src":"17","dst":"255","pgn":"127999","description":"Fluid Level","fields":{"Instance":"0","Type":"Fuel","Level":"131.068"}}' + ) + ) delta.context = 'vessels.' + signalkSchema.fakeMmsiId var contextParts = delta.context.split('.') - var tree = signalkSchema.deltaToFull(delta)[contextParts[0]][contextParts[1]] + var tree = signalkSchema.deltaToFull(delta)[contextParts[0]][ + contextParts[1] + ] - tree.should.have.nested.property('tanks.fuel.0.customCurrentLevel.value', 1.31068) + tree.should.have.nested.property( + 'tanks.fuel.0.customCurrentLevel.value', + 1.31068 + ) }) }) diff --git a/test/maretron.js b/test/maretron.js index 105a1bac..677dbe95 100644 --- a/test/maretron.js +++ b/test/maretron.js @@ -9,16 +9,67 @@ const toNested = require('./testMapper').toNested describe('Maretron AC PGNs work', function () { const n2kMapper = new N2kMapper() - n2kMapper.toDelta({"prio":6,"pgn":60928,"dst":255,"src":192,"timestamp":"2019-05-31T11:46:58.594Z","fields":{"Unique Number":"76223","Device Instance Lower":0,"Device Instance Upper":1,"Device Function":130,"Reserved1":"0","System Instance":0,"Industry Group":"Marine","Reserved2":"1"},"description":"ISO Address Claim"}) + n2kMapper.toDelta({ + prio: 6, + pgn: 60928, + dst: 255, + src: 192, + timestamp: '2019-05-31T11:46:58.594Z', + fields: { + 'Unique Number': '76223', + 'Device Instance Lower': 0, + 'Device Instance Upper': 1, + 'Device Function': 130, + Reserved1: '0', + 'System Instance': 0, + 'Industry Group': 'Marine', + Reserved2: '1' + }, + description: 'ISO Address Claim' + }) - n2kMapper.toDelta({"prio":6,"pgn":60928,"dst":255,"src":193,"timestamp":"2019-05-31T11:46:58.594Z","fields":{"Unique Number":"76223","Device Instance Lower":0,"Device Instance Upper":2,"Device Function":130,"Reserved1":"0","System Instance":0,"Industry Group":"Marine","Reserved2":"1"},"description":"ISO Address Claim"}) + n2kMapper.toDelta({ + prio: 6, + pgn: 60928, + dst: 255, + src: 193, + timestamp: '2019-05-31T11:46:58.594Z', + fields: { + 'Unique Number': '76223', + 'Device Instance Lower': 0, + 'Device Instance Upper': 2, + 'Device Function': 130, + Reserved1: '0', + 'System Instance': 0, + 'Industry Group': 'Marine', + Reserved2: '1' + }, + description: 'ISO Address Claim' + }) - n2kMapper.toDelta({"prio":6,"pgn":60928,"dst":255,"src":194,"timestamp":"2019-05-31T11:46:58.594Z","fields":{"Unique Number":"76223","Device Instance Lower":0,"Device Instance Upper":3,"Device Function":130,"Reserved1":"0","System Instance":0,"Industry Group":"Marine","Reserved2":"1"},"description":"ISO Address Claim"}) + n2kMapper.toDelta({ + prio: 6, + pgn: 60928, + dst: 255, + src: 194, + timestamp: '2019-05-31T11:46:58.594Z', + fields: { + 'Unique Number': '76223', + 'Device Instance Lower': 0, + 'Device Instance Upper': 3, + 'Device Function': 130, + Reserved1: '0', + 'System Instance': 0, + 'Industry Group': 'Marine', + Reserved2: '1' + }, + description: 'ISO Address Claim' + }) it('65005 Utility Total AC Energy', function () { var tree = toNested( JSON.parse( - '{"canId":217968066,"prio":3,"src":194,"dst":255,"pgn":65005,"direction":"R","time":"18:58:12.730","fields":{"Total Energy Export":0,"Total Energy Import":0},"description":"Utility Total AC Energy","timestamp":"2020-03-28T18:58:13.092Z"}', + '{"canId":217968066,"prio":3,"src":194,"dst":255,"pgn":65005,"direction":"R","time":"18:58:12.730","fields":{"Total Energy Export":0,"Total Energy Import":0},"description":"Utility Total AC Energy","timestamp":"2020-03-28T18:58:13.092Z"}' ), n2kMapper.state ) @@ -40,7 +91,7 @@ describe('Maretron AC PGNs work', function () { ), n2kMapper.state ) - + tree.should.have.nested.property( 'electrical.ac.8.phase.A.reactivePower.value', 859 @@ -53,13 +104,27 @@ describe('Maretron AC PGNs work', function () { 'electrical.ac.8.phase.A.powerFactorLagging.value', 'lagging' ) - + //tree.should.be.validSignalKVesselIgnoringIdentity }) //needed for the next test - n2kMapper.toDelta({"canId":217969088,"prio":3,"src":192,"dst":255,"pgn":65009,"direction":"R","time":"18:58:11.940","fields":{"Reactive Power":37888,"Power Factor":30517,"Power Factor Lagging":"Leading"},"description":"Utility Phase B AC Reactive Power","timestamp":"2020-03-28T18:58:12.480Z"}) - + n2kMapper.toDelta({ + canId: 217969088, + prio: 3, + src: 192, + dst: 255, + pgn: 65009, + direction: 'R', + time: '18:58:11.940', + fields: { + 'Reactive Power': 37888, + 'Power Factor': 30517, + 'Power Factor Lagging': 'Leading' + }, + description: 'Utility Phase B AC Reactive Power', + timestamp: '2020-03-28T18:58:12.480Z' + }) it('65010 Utility Phase B AC Power', function () { var tree = toNested( @@ -78,7 +143,7 @@ describe('Maretron AC PGNs work', function () { ) tree.should.be.validSignalKVesselIgnoringIdentity }) - + it('65030 Generator Average Basic AC Quantities', function () { var tree = toNested( JSON.parse( @@ -102,7 +167,7 @@ describe('Maretron AC PGNs work', function () { 'electrical.generators.16.average.current.value', 0 ) - + //tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/meta.js b/test/meta.js index 197ae555..d282d382 100644 --- a/test/meta.js +++ b/test/meta.js @@ -5,8 +5,7 @@ chai.use(require('chai-things')) const N2kMapper = require('../n2kMapper').N2kMapper describe('Meta data works', function () { - - it('Address Claim', (done) => { + it('Address Claim', done => { const n2kMapper = new N2kMapper() n2kMapper.on('n2kSourceMetadata', (n2k, meta) => { meta.should.have.property('uniqueId', '76223') @@ -20,10 +19,29 @@ describe('Meta data works', function () { meta.should.have.property('deviceInstance', 0) done() }) - n2kMapper.toDelta({"prio":6,"pgn":60928,"dst":255,"src":12,"timestamp":"2019-05-31T11:46:58.594Z","fields":{"Unique Number":"76223","Manufacturer Code":"Fusion Electronics","Device Instance Lower":0,"Device Instance Upper":0,"Device Function":130,"Reserved1":"0","Device Class":"Entertainment","System Instance":0,"Industry Group":"Marine","Reserved2":"1"},"description":"ISO Address Claim"}) + n2kMapper.toDelta({ + prio: 6, + pgn: 60928, + dst: 255, + src: 12, + timestamp: '2019-05-31T11:46:58.594Z', + fields: { + 'Unique Number': '76223', + 'Manufacturer Code': 'Fusion Electronics', + 'Device Instance Lower': 0, + 'Device Instance Upper': 0, + 'Device Function': 130, + Reserved1: '0', + 'Device Class': 'Entertainment', + 'System Instance': 0, + 'Industry Group': 'Marine', + Reserved2: '1' + }, + description: 'ISO Address Claim' + }) }) - it('Configuration Information', (done) => { + it('Configuration Information', done => { const n2kMapper = new N2kMapper() n2kMapper.on('n2kSourceMetadata', (n2k, meta) => { meta.should.have.property('installationNote1', 'UD-650') @@ -31,10 +49,22 @@ describe('Meta data works', function () { meta.should.have.property('installationNote3', 'Fusion Electronics Ltd') done() }) - n2kMapper.toDelta({"prio":6,"pgn":126998,"dst":255,"src":12,"timestamp":"2019-05-31T11:56:11.266Z","fields":{"Installation Description #1":"UD-650","Installation Description #2":"FUSION","Installation Description #3":"Fusion Electronics Ltd"},"description":"Configuration Information"}) + n2kMapper.toDelta({ + prio: 6, + pgn: 126998, + dst: 255, + src: 12, + timestamp: '2019-05-31T11:56:11.266Z', + fields: { + 'Installation Description #1': 'UD-650', + 'Installation Description #2': 'FUSION', + 'Installation Description #3': 'Fusion Electronics Ltd' + }, + description: 'Configuration Information' + }) }) - it('Product Information', (done) => { + it('Product Information', done => { const n2kMapper = new N2kMapper() n2kMapper.on('n2kSourceMetadata', (n2k, meta) => { meta.should.have.property('productName', 'UD-650') @@ -47,7 +77,23 @@ describe('Meta data works', function () { meta.should.have.property('loadEquivalency', 1) done() }) - n2kMapper.toDelta({"prio":6,"pgn":126996,"dst":255,"src":12,"timestamp":"2019-05-31T11:53:13.922Z","fields":{"NMEA 2000 Version":1301,"Product Code":3115,"Model ID":"UD-650","Software Version Code":"2.0.265","Model Version":"FUSION-LINK-1.0","Model Serial Code":"76223","Certification Level":1,"Load Equivalency":1},"description":"Product Information"}) + n2kMapper.toDelta({ + prio: 6, + pgn: 126996, + dst: 255, + src: 12, + timestamp: '2019-05-31T11:53:13.922Z', + fields: { + 'NMEA 2000 Version': 1301, + 'Product Code': 3115, + 'Model ID': 'UD-650', + 'Software Version Code': '2.0.265', + 'Model Version': 'FUSION-LINK-1.0', + 'Model Serial Code': '76223', + 'Certification Level': 1, + 'Load Equivalency': 1 + }, + description: 'Product Information' + }) }) - }) diff --git a/utils.js b/utils.js index e7017e98..e0e8eb4c 100644 --- a/utils.js +++ b/utils.js @@ -25,20 +25,20 @@ function skEngineTitle (n2k) { } } -function acPhase(n2k) { +function acPhase (n2k) { const line = n2k.fields['Line'] - if ( !line ) { + if (!line) { return 'A' } else { - switch ( line ) { - case 'Line 1': - return 'A' - case 'Line 2': - return 'B' - case 'Line 3': - return 'C' - default: - return 'A' + switch (line) { + case 'Line 1': + return 'A' + case 'Line 2': + return 'B' + case 'Line 3': + return 'C' + default: + return 'A' } } }