Skip to content

Commit 309a77b

Browse files
e-sailingtkurki
authored andcommitted
fix percent to ratio (0-100 -> 0-1) (#82)
1 parent da9f201 commit 309a77b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

pgns/127505.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ module.exports = [
99
'.currentLevel'
1010
)
1111
},
12-
source: 'Level'
12+
value: function (n2k) {
13+
var ratio100 = Number(n2k.fields['Level'])
14+
return ratio100 / 100
15+
}
1316
},
1417
{
1518
node: function (n2k) {

pgns/130311.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ module.exports = [
1919
'.humidity'
2020
)
2121
},
22-
source: 'Humidity'
22+
filter: function (n2k) {
23+
return typeof n2k.fields['Humidity'] !== 'undefined'
24+
},
25+
value: function (n2k) {
26+
var ratio100 = Number(n2k.fields['Humidity'])
27+
return ratio100 / 100
28+
}
2329
},
2430
{
2531
node: 'environment.outside.pressure',

test/127505_fluid_level.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('127505 fuel', function () {
1010
'{"timestamp":"2015-01-15-16:15:30.984Z","prio":"6","src":"17","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Fuel","Level":"131.068"}}'
1111
)
1212
)
13-
tree.should.have.nested.property('tanks.fuel.0.currentLevel.value', 131.068)
13+
tree.should.have.nested.property('tanks.fuel.0.currentLevel.value', 1.31068)
1414
tree.should.be.validSignalKVesselIgnoringIdentity
1515
})
1616
it('level and capacity', function () {
@@ -19,7 +19,7 @@ describe('127505 fuel', function () {
1919
'{"timestamp":"2015-01-15-16:15:33.341Z","prio":"6","src":"112","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"1","Type":"Fuel","Level":"64.284","Capacity":"41.6"}}'
2020
)
2121
)
22-
tree.should.have.nested.property('tanks.fuel.1.currentLevel.value', 64.284)
22+
tree.tanks.fuel['1'].currentLevel.value.should.be.closeTo(0.64284, 0.000005)
2323
tree.should.have.nested.property('tanks.fuel.1.capacity.value', 41.6)
2424
tree.should.be.validSignalKVesselIgnoringIdentity
2525
})
@@ -32,9 +32,9 @@ describe('127505 water', function () {
3232
'{"timestamp":"2015-01-15-16:15:33.366Z","prio":"6","src":"114","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Water","Level":"88.596","Capacity":"71.9"}}'
3333
)
3434
)
35-
tree.should.have.nested.property(
36-
'tanks.freshWater.0.currentLevel.value',
37-
88.596
35+
tree.tanks.freshWater['0'].currentLevel.value.should.be.closeTo(
36+
0.88596,
37+
0.000005
3838
)
3939
tree.should.have.nested.property('tanks.freshWater.0.capacity.value', 71.9)
4040
tree.should.be.validSignalKVesselIgnoringIdentity
@@ -50,7 +50,7 @@ describe('127505 grayWater', function () {
5050
)
5151
tree.should.have.nested.property(
5252
'tanks.wasteWater.0.currentLevel.value',
53-
90.24
53+
0.9024
5454
)
5555
tree.should.have.nested.property('tanks.wasteWater.0.capacity.value', 37.9)
5656
tree.should.be.validSignalKVesselIgnoringIdentity

0 commit comments

Comments
 (0)