diff --git a/pgns/127501.js b/pgns/127501.js index 3cab6e3..4cf5f47 100644 --- a/pgns/127501.js +++ b/pgns/127501.js @@ -1,7 +1,7 @@ module.exports = [ function (n2k) { var res = [] - for (var i = 0; i < 28; i++) { + for (var i = 1; i <= 28; i++) { const field = 'Indicator' + i if (typeof n2k.fields[field] !== 'undefined') { const basePath = diff --git a/pgns/127503.js b/pgns/127503.js index f81d27c..864f4a3 100644 --- a/pgns/127503.js +++ b/pgns/127503.js @@ -1,66 +1,42 @@ -const { acPhase } = require('../utils.js') - function instance (n2k) { return n2k.fields['Instance'] } -function prefix (n2k) { - return `electrical.ac.${instance(n2k)}.${acPhase(n2k)}` +function acPhase (lineData) { + const phaseMap = { 0: 'A', 1: 'B', 2: 'C' } + return phaseMap[lineData.Line] ?? 'A' +} + +function prefix (n2k, lineData) { + return `electrical.ac.${instance(n2k)}.${acPhase(lineData)}` } module.exports = [ - { - source: 'Acceptability', - node: function (n2k) { - return `${prefix(n2k)}.acceptability` - } - }, - { - source: 'Voltage', - node: function (n2k) { - return `${prefix(n2k)}.voltage` - } - }, - { - source: 'Current', - node: function (n2k) { - return `${prefix(n2k)}.current` - } - }, - { - source: 'Frequency', - node: function (n2k) { - return `${prefix(n2k)}.frequency` - } - }, - { - source: 'Frequency', - node: function (n2k) { - return `${prefix(n2k)}.frequency` - } - }, - { - source: 'Breaker Size', - node: function (n2k) { - return `${prefix(n2k)}.breakerSize` - } - }, - { - source: 'Real Power', - node: function (n2k) { - return `${prefix(n2k)}.realPower` - } - }, - { - source: 'Reactive Power', - node: function (n2k) { - return `${prefix(n2k)}.reactivePower` - } - }, - { - source: 'Power Factor', - node: function (n2k) { - return `${prefix(n2k)}.powerFactor` - } + function (n2k, stage) { + const fields = { + Acceptability: 'acceptability', + Voltage: 'voltage', + Current: 'current', + Frequency: 'frequency', + 'Breaker Size': 'breakerSize', + 'Real Power': 'realPower', + 'Reactive Power': 'reactivePower', + 'Power Factor': 'powerFactor' + } + return n2k.fields.list + ? n2k.fields.list.reduce((updates, lineData) => { + const pathPrefix = prefix(n2k, lineData) + Object.keys(fields).reduce((fieldUpdates, fieldName) => { + if (typeof lineData[fieldName] !== 'undefined') { + updates.push({ + path: `${pathPrefix}.${fields[fieldName]}`, + value: lineData[fieldName] + }) + } + return updates + }, updates) + return updates + }, []) + : [] } ] diff --git a/pgns/127504.js b/pgns/127504.js index 85b9e4b..9155dc7 100644 --- a/pgns/127504.js +++ b/pgns/127504.js @@ -1,66 +1,42 @@ -const { acPhase } = require('../utils.js') - function instance (n2k) { return n2k.fields['Instance'] } -function prefix (n2k) { - return `electrical.inverters.${instance(n2k)}.${acPhase(n2k)}` +function acPhase (lineData) { + const phaseMap = { 0: 'A', 1: 'B', 2: 'C' } + return phaseMap[lineData.Line] ?? 'A' +} + +function prefix (n2k, lineData) { + return `electrical.inverters.${instance(n2k)}.${acPhase(lineData)}` } module.exports = [ - { - source: 'Waveform', - node: function (n2k) { - return `${prefix(n2k)}.waveform` - } - }, - { - source: 'Voltage', - node: function (n2k) { - return `${prefix(n2k)}.voltage` - } - }, - { - source: 'Current', - node: function (n2k) { - return `${prefix(n2k)}.current` - } - }, - { - source: 'Frequency', - node: function (n2k) { - return `${prefix(n2k)}.frequency` - } - }, - { - source: 'Frequency', - node: function (n2k) { - return `${prefix(n2k)}.frequency` - } - }, - { - source: 'Breaker Size', - node: function (n2k) { - return `${prefix(n2k)}.breakerSize` - } - }, - { - source: 'Real Power', - node: function (n2k) { - return `${prefix(n2k)}.realPower` - } - }, - { - source: 'Reactive Power', - node: function (n2k) { - return `${prefix(n2k)}.reactivePower` - } - }, - { - source: 'Power Factor', - node: function (n2k) { - return `${prefix(n2k)}.powerFactor` - } + function (n2k, stage) { + const fields = { + Waveform: 'waveform', + Voltage: 'voltage', + Current: 'current', + Frequency: 'frequency', + 'Breaker Size': 'breakerSize', + 'Real Power': 'realPower', + 'Reactive Power': 'reactivePower', + 'Power Factor': 'powerFactor' + } + return n2k.fields.list + ? n2k.fields.list.reduce((updates, lineData) => { + const pathPrefix = prefix(n2k, lineData) + Object.keys(fields).reduce((fieldUpdates, fieldName) => { + if (typeof lineData[fieldName] !== 'undefined') { + updates.push({ + path: `${pathPrefix}.${fields[fieldName]}`, + value: lineData[fieldName] + }) + } + return updates + }, updates) + return updates + }, []) + : [] } ]