diff --git a/pgns/127507.js b/pgns/127507.js new file mode 100644 index 0000000..790d947 --- /dev/null +++ b/pgns/127507.js @@ -0,0 +1,43 @@ + +function prefix(n2k) { + return `electrical.charger.${n2k.fields['Instance']}.battery.${n2k.fields['Battery Instance']}` +} + +module.exports = [ + { + node: n2k => prefix(n2k) + '.operatingState', + value: n2k => n2k.fields['Operating State'].toLowerCase(), + filter: n2k => typeof n2k.fields['Operating State'] === 'string' + }, + { + node: n2k => prefix(n2k) + '.chargeMode', + value: n2k => n2k.fields['Charge Mode'].toLowerCase(), + filter: n2k => typeof n2k.fields['Charge Mode'] === 'string' + }, + { + node: n2k => prefix(n2k) + '.chargerEnabled', + value: n2k => n2k.fields['Charger Enabled'].toLowerCase(), + filter: n2k => typeof n2k.fields['Charger Enabled'] === 'string' + }, + { + node: n2k => prefix(n2k) + '.equalizationPending', + value: n2k => n2k.fields['Equalization Pending'].toLowerCase(), + filter: n2k => typeof n2k.fields['Equalization Pending'] === 'string' + }, + { + allowNull: true, + value: function (n2k) { + var val = n2k.fields['Equalization Time Remaining'] + var res + if (typeof val !== 'undefined') { + res = val * 60 // convert to seconds + } else { + res = null + } + return res + }, + node: function (n2k) { + return prefix(n2k) + '.equalizationTimeRemaining' + } + } +] diff --git a/pgns/index.js b/pgns/index.js index b468ed9..13db9a0 100644 --- a/pgns/index.js +++ b/pgns/index.js @@ -11,6 +11,7 @@ module.exports = { 127489: require('./127489.js'), 127505: require('./127505.js'), 127506: require('./127506.js'), + 127507: require('./127507.js'), 127508: require('./127508.js'), 128259: require('./128259.js'), 128267: require('./128267.js'), diff --git a/test/127507_charger_status.js b/test/127507_charger_status.js new file mode 100644 index 0000000..20fc21a --- /dev/null +++ b/test/127507_charger_status.js @@ -0,0 +1,43 @@ +var chai = require('chai') +chai.Should() +const { expect } = chai +chai.use(require('chai-things')) +chai.use(require('@signalk/signalk-schema').chaiModule) + +describe('127507 charger status', function () { + it('complete sentence converts', function () { + const pgn = + '{"canId":435295105,"prio":6,"src":129,"dst":255,"pgn":127507,"timestamp":"2021-07-30T16:48:59.722Z","input":[],"fields":{"Instance":113,"Battery Instance":0,"Operating State":"Disabled","Charge Mode":"Standalone mode","Charger Enabled":"Off"},"description":"Charger Status"}' + + const delta = require('./testMapper').toDelta(JSON.parse(pgn)) + + findPathValue( + delta, + 'electrical.charger.113.battery.0.operatingState' + ).value.should.equal('disabled') + findPathValue( + delta, + 'electrical.charger.113.battery.0.chargeMode' + ).value.should.equal('standalone mode') + findPathValue( + delta, + 'electrical.charger.113.battery.0.chargerEnabled' + ).value.should.equal('off') + expect(findPathValue( + delta, + 'electrical.charger.113.battery.0.equalizationTimeRemaining' + ).value).to.be.null + }) +}) + +function findPathValue(delta, path) { + const found = delta.updates[0].values.find( + (pathValue) => pathValue.path === path + ) + if (!found) { + throw new Error( + `No pathValue with path ${path} in ${JSON.stringify(delta, null, 2)}` + ) + } + return found +}