Skip to content

Commit

Permalink
fix: PGN 127503/127504 -> use new canboatjs2 / canboat4 data, PGN 127…
Browse files Browse the repository at this point in the history
…501 -> off by one error fixed (#266)

* fix: use canboatjs2 / canboat4 data

repeatable fields are passed in an array (fields.list) by canboatjs2
  • Loading branch information
patg authored Jun 4, 2024
1 parent a0b8515 commit b98b3bb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 115 deletions.
2 changes: 1 addition & 1 deletion pgns/127501.js
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
90 changes: 33 additions & 57 deletions pgns/127503.js
Original file line number Diff line number Diff line change
@@ -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
}, [])
: []
}
]
90 changes: 33 additions & 57 deletions pgns/127504.js
Original file line number Diff line number Diff line change
@@ -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
}, [])
: []
}
]

0 comments on commit b98b3bb

Please sign in to comment.