diff --git a/n2kMapper.js b/n2kMapper.js index 5cf2407..849c561 100644 --- a/n2kMapper.js +++ b/n2kMapper.js @@ -14,6 +14,7 @@ Object.assign(n2kMappings, require('./raymarine')) Object.assign(n2kMappings, require('./maretron')) Object.assign(n2kMappings, require('./actisense')) Object.assign(n2kMappings, require('./digitalyacht')) +Object.assign(n2kMappings, require('./simrad')) function N2kMapper (options) { this.state = {} diff --git a/package.json b/package.json index 756175d..51cbe31 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "repository": "https://github.com/SignalK/n2k-signalk", "dependencies": { "@canboat/canboatjs": "^2.1.0", + "camelcase": "^6.2.0", "debug": "^4.0.0", "int64-buffer": "^0.99.1007", "JSONStream": "~1.3.0", diff --git a/raymarine/126720.js b/raymarine/126720.js index c42859d..8c27996 100644 --- a/raymarine/126720.js +++ b/raymarine/126720.js @@ -1,14 +1,54 @@ const debug = require('debug')('n2k-signalk-126720') +const camelCase = require('camelcase') module.exports = [ + { + // Display Brightness + filter: function (n2k) { + return ( + n2k.description === 'Seatalk1: Display Brightness' && + n2k.fields['Manufacturer Code'] === 'Raymarine' && + n2k.fields['Group'] !== undefined + ) + }, + node: n2k => { + return `electrical.displays.raymarine.${camelCase( + n2k.fields['Group'] + )}.brightness` + }, + allowNull: true, + value: n2k => { + let val = n2k.fields['Brightness'] + return val !== undefined ? val / 100.0 : null + } + }, + { + // Display Color + filter: function (n2k) { + return ( + n2k.description === 'Seatalk1: Display Color' && + n2k.fields['Manufacturer Code'] === 'Raymarine' && + n2k.fields['Group'] !== undefined + ) + }, + node: n2k => { + return `electrical.displays.raymarine.${camelCase( + n2k.fields['Group'] + )}.color` + }, + allowNull: true, + value: n2k => { + return camelCase(n2k.fields['Color']) + } + }, { // filters for SmartPilot behind Seatalk-STNG-Converter filter: function (n2k) { return ( n2k.description === 'Seatalk1: Pilot Mode' && n2k.fields['Manufacturer Code'] === 'Raymarine' && - typeof n2k.fields['Pilot Mode'] !== 'undefined' && - typeof n2k.fields['Sub Mode'] !== 'undefined' + typeof n2k.fields['Pilot Mode'] !== undefined && + typeof n2k.fields['Sub Mode'] !== undefined ) }, node: 'steering.autopilot.state', diff --git a/simrad/130845.js b/simrad/130845.js new file mode 100644 index 0000000..ed2891a --- /dev/null +++ b/simrad/130845.js @@ -0,0 +1,57 @@ +const debug = require('debug')('n2k-signalk-130845') +const camelCase = require('camelcase') + +module.exports = [ + { + filter: function (n2k) { + return ( + n2k.fields['Manufacturer Code'] === 'Simrad' && + n2k.fields['Display Group'] !== 'undefined' && + n2k.fields['Key'] === 'Backlight level' + ) + }, + node: (n2k) => { return `electrical.displays.navico.${camelCase(n2k.fields['Display Group'])}.brightness` }, + allowNull: true, + value: (n2k) => { + let val = n2k.fields['Value'] + return val !== 'undefined' ? val / 100.0 : null + } + }, + { + filter: function (n2k) { + return ( + n2k.fields['Manufacturer Code'] === 'Simrad' && + n2k.fields['Display Group'] !== 'undefined' && + n2k.fields['Key'] === 'Night mode' + ) + }, + node: (n2k) => { return `electrical.displays.navico.${camelCase(n2k.fields['Display Group'])}.nightMode.state` }, + allowNull: true, + value: (n2k) => { + return n2k.fields['Value'] === 4 ? 1 : 0 + } + }, + { + filter: function (n2k) { + return ( + n2k.fields['Manufacturer Code'] === 'Simrad' && + n2k.fields['Display Group'] !== 'undefined' && + n2k.fields['Key'] === 'Night mode color' + ) + }, + node: (n2k) => { return `electrical.displays.navico.${camelCase(n2k.fields['Display Group'])}.nightModeColor` }, + allowNull: true, + value: (n2k) => { + let val = nightModeColorMapping[n2k.fields['Value']] + return val ? val : 'unknown' + } + }, +] + +const nightModeColorMapping = { + 0: 'red', + 1: 'green', + 2: 'blue', + 3: 'white', + 4: 'magenta' +} diff --git a/simrad/index.js b/simrad/index.js new file mode 100644 index 0000000..c8bc7ee --- /dev/null +++ b/simrad/index.js @@ -0,0 +1,3 @@ +module.exports = { + 130845: require('./130845.js') +} diff --git a/test/126720_seatalk_displays.js b/test/126720_seatalk_displays.js new file mode 100644 index 0000000..12bfd92 --- /dev/null +++ b/test/126720_seatalk_displays.js @@ -0,0 +1,30 @@ +var chai = require('chai') +chai.Should() +chai.use(require('chai-things')) +chai.use(require('@signalk/signalk-schema').chaiModule) + +describe('126720 Seatalk Displays', function () { + it('birghtness converts', function () { + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":126720, "description": "Seatalk1: Display Brightness", "fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry", "Proprietary ID": 3212, "Command": "Brightness", "Group": "Helm 1", "Brightness":50}}' + ) + ) + tree.should.have.nested.property( + 'electrical.displays.raymarine.helm1.brightness.value', + 0.5 + ) + }) + + it('display color converts', function () { + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":126720, "description": "Seatalk1: Display Color", "fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry", "Proprietary ID": 3212, "Command": "Color", "Group": "Helm 1", "Color":"Red/Black"}}' + ) + ) + tree.should.have.nested.property( + 'electrical.displays.raymarine.helm1.color.value', + 'red/black' + ) + }) +}) diff --git a/test/130845_simrad_displays.js b/test/130845_simrad_displays.js new file mode 100644 index 0000000..dd0bced --- /dev/null +++ b/test/130845_simrad_displays.js @@ -0,0 +1,42 @@ +var chai = require('chai') +chai.Should() +chai.use(require('chai-things')) +chai.use(require('@signalk/signalk-schema').chaiModule) + +describe('130845 Simrad Displays', function () { + it('birghtness converts', function () { + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":130845,"fields":{"Manufacturer Code":"Simrad","Industry Code":"Marine Industry","Display Group": "Group 1", "Key":"Backlight level","Value":50}}' + ) + ) + tree.should.have.nested.property( + 'electrical.displays.navico.group1.brightness.value', + 0.5 + ) + }) + + it('night mode converts', function () { + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":130845,"fields":{"Manufacturer Code":"Simrad","Industry Code":"Marine Industry","Display Group": "Group 1", "Key":"Night mode","Value":4}}' + ) + ) + tree.should.have.nested.property( + 'electrical.displays.navico.group1.nightMode.state.value', + 1 + ) + }) + + it('night mode color converts', function () { + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":130845,"fields":{"Manufacturer Code":"Simrad","Industry Code":"Marine Industry","Display Group": "Group 1", "Key":"Night mode color","Value":1}}' + ) + ) + tree.should.have.nested.property( + 'electrical.displays.navico.group1.nightModeColor.value', + 'green' + ) + }) +})