From 66147be12aef6b612afb6465fe80e54da0863eda Mon Sep 17 00:00:00 2001 From: Tony Bentley Date: Fri, 15 Feb 2019 11:56:26 -0800 Subject: [PATCH] feature:parse PBVE (oil pressure only) (#142) --- .DS_Store | Bin 6148 -> 6148 bytes README.md | 1 + hooks/index.js | 1 + hooks/proprietary/PBVE.js | 120 ++++++++++++++++++++++++++++++++++++++ test/PBVE.js | 32 ++++++++++ 5 files changed, 154 insertions(+) create mode 100644 hooks/proprietary/PBVE.js create mode 100644 test/PBVE.js diff --git a/.DS_Store b/.DS_Store index 3c56884df5aa29171f0bcb8ba0942efe839ec166..9689bc9ba028564e786a54f54d7c627db3336c66 100644 GIT binary patch delta 32 ocmZoMXfc@J&nUJrU^g?P*k&G<-He;d*(NYfEZDG_o#QV*0In+v^Z)<= delta 203 zcmZoMXfc@J&nUGqU^g?P)Mg%*-Hi1-40#Os3@Hq$4Dk%PU{)zZ4v<%zlWrKCoS$33 z00fM7ybpjBPPMuDE-ophCCLm7S3XD12I;`3HU&woE`G%Y8Ay(}dtvio)+vme**X65 F0|2-FGZz2= diff --git a/README.md b/README.md index ab1d7258..65a2dc68 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/hooks/index.js b/hooks/index.js index 3b66dc15..23470bb5 100644 --- a/hooks/index.js +++ b/hooks/index.js @@ -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'), diff --git a/hooks/proprietary/PBVE.js b/hooks/proprietary/PBVE.js new file mode 100644 index 00000000..e7a3350d --- /dev/null +++ b/hooks/proprietary/PBVE.js @@ -0,0 +1,120 @@ +'use strict' + +/** + * Copyright 2019 Signal K . + * + * 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 +} diff --git a/test/PBVE.js b/test/PBVE.js new file mode 100644 index 00000000..0e60d7b4 --- /dev/null +++ b/test/PBVE.js @@ -0,0 +1,32 @@ +/** + * Copyright 2019 Signal K 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) + }) +})