Skip to content

Commit

Permalink
feature:parse PBVE (oil pressure only) (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybentley authored and tkurki committed Feb 15, 2019
1 parent 5ff2899 commit 66147be
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- [ALK - Seatalk](https://en.wikipedia.org/wiki/Seatalk)
- [APB - Autopilot Sentence "B"](http://www.catb.org/gpsd/NMEA.html#_apb_autopilot_sentence_b)
- [BVE - CruzPro Proprietary Sentence (currently only OP30/60 supported)](http://www.cruzpro.com/op60.html)
- [DBT - Depth Below Transducer](http://www.catb.org/gpsd/NMEA.html#_dbt_depth_below_transducer)
- [DPT - Depth of Water](http://www.catb.org/gpsd/NMEA.html#_dpt_depth_of_water)
- [DSC - Digital Selective Calling Class-D Radios](http://continuouswave.com/whaler/reference/DSC_Datagrams.html)
Expand Down
1 change: 1 addition & 0 deletions hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'HDG': require('./HDG.js'),
'HDM': require('./HDM.js'),
'HDT': require('./HDT.js'),
'PBVE': require('./proprietary/PBVE.js'),
'PNKEP': require('./proprietary/PNKEP.js'),
'MTW': require('./MTW.js'),
'MWV': require('./MWV.js'),
Expand Down
120 changes: 120 additions & 0 deletions hooks/proprietary/PBVE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
'use strict'

/**
* Copyright 2019 Signal K <info@signalk.org>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/



const debug = require('debug')('signalk-parser-nmea0183/PBVE')
const utils = require('@signalk/nmea0183-utilities')

/*
OP30 digital oil pressure gauge sample NMEA sentence:
Sentence: $PBVE,DGOIADNNACAEACAAABBLAAEBAACMCFAAEPAIKI*37
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| | | | | | | | | | | | | | |
$PBVE,x,x,xxxx,xxxx,xx,xx,xx,xx,xxxx,xxxx,xx,xxxx,xxxx,xx*xx
D G OIAD NNAC AE AC AA AB BLAA EBAA CM CFAA EPAI KI*37
0: Product code: D = OP 30/60
1: Software version: G = ???
2: Oil pressure calibration number: OIAD = 14 8 0 3 = ???
3: A2D gain: NNAC = ???
4: Sender Type: AE = 4
5: Backlight level: AC = 2
6: Units of measure: AA = psi
7: Built in alarms armed: AB = 1 = true
8: Low pressure alarm value: BLAA = 1 11 0 0 = ???
9: High pressure alarm value: EBAA = 4 1 0 0 = ???
10: Checksum for Non-Volatile Memory: CM = 2 12 = ???
11: Oil Pressure: CFAA = 37
12: Sensor Volts: EPAI = 4 15 0 8 = ???
13: Checksum: KI = 10 8
14: Checksum: 37
Where A=0, B=1, C=2, ... , O=14, P=15
Decode Oil Pressure as:
CFAA = 16*M + L + 4096*A + 256*A
CFAA = 16*2 + 5 + 4096*0 + 256*0
CFAA = 37 psi
//ALPHA is an array map for converting sentence codes from letters to numbers
//A=0, B=1, etc
*/
const ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')

/*
@function convertAlphasToInts
@param alphas String
@return Array
*/
function convertAlphasToInts(alphas){
alphas = alphas.split('')
var replacement = [];
for(var i = 0; i < alphas.length;i++){
const indexValue = ALPHA.indexOf(alphas[i]);
replacement.push(indexValue)
}
return replacement;
}


/*
@function convertToOilPressure
@param values Array
@return Int
*/
function convertToOilPressure(values){
return (16 * values[0]) + values[1] + (4096 * values[2]) + (256 * values[3])
}

module.exports = function(input) {
const { id, sentence, parts, tags } = input

let values = []
let delta = {}

const data = parts[0]
const productCode = data.substr(0,1)

if(productCode !== 'D'){
debug('Unsupported CruzPro instrument type')
return;
}

const convertedValue = convertAlphasToInts(data.substr(28,4))
const oilPressure = convertToOilPressure(convertedValue)

const oilPressureValue = {
path: 'propulsion.0.oilPressure',
value: oilPressure
}

delta = {
updates: [{
source: tags.source,
timestamp: tags.timestamp,
values: [oilPressureValue]
}]
}

return delta
}
32 changes: 32 additions & 0 deletions test/PBVE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2019 Signal K <info@signalk.org> and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const Parser = require('../lib')
const should = require('chai').Should()
const toFull = require('./toFull')

describe('PBVE', () => {
it('Converts OK using individual parser', () => {
const delta = new Parser().parse('$PBVE,DGOIADNNACAEACAAABBLAAEBAACMCFAAEPAIKI*37')
delta.updates[0].values.should.contain.an.item.with.property('path', 'propulsion.0.oilPressure')
delta.updates[0].values[0].value.should.equal(37)
toFull(delta).should.be.validSignalK
})
//currently only produce code D is supported so test that all others do not process
it('Will not convert if productCode not D', () => {
should.equal(new Parser().parse('$PBVE,FGLABCGJAAAHADEE*21'),undefined)
})
})

0 comments on commit 66147be

Please sign in to comment.