Skip to content

Commit

Permalink
feature: add pgns for raymarine and simrad display info (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Jun 7, 2024
1 parent 33726df commit 7dad284
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 2 deletions.
1 change: 1 addition & 0 deletions n2kMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 42 additions & 2 deletions raymarine/126720.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
57 changes: 57 additions & 0 deletions simrad/130845.js
Original file line number Diff line number Diff line change
@@ -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'
}
3 changes: 3 additions & 0 deletions simrad/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
130845: require('./130845.js')
}
30 changes: 30 additions & 0 deletions test/126720_seatalk_displays.js
Original file line number Diff line number Diff line change
@@ -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'
)
})
})
42 changes: 42 additions & 0 deletions test/130845_simrad_displays.js
Original file line number Diff line number Diff line change
@@ -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'
)
})
})

0 comments on commit 7dad284

Please sign in to comment.