-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: PGN 127503/127504 -> use new canboatjs2 / canboat4 data, PGN 127…
…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
Showing
3 changed files
with
67 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, []) | ||
: [] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, []) | ||
: [] | ||
} | ||
] |