Skip to content

Commit

Permalink
feature: add DBS and DBK sentences (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored and tkurki committed Apr 22, 2019
1 parent 3f52e47 commit e0f0399
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- [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)
- [DBS - Depth Below Surface](http://www.catb.org/gpsd/NMEA.html#_dbs_depth_below_surface)
- [DBK - Depth Below Keel](http://www.catb.org/gpsd/NMEA.html#_dbk_depth_below_keel)
- [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)
- [GGA - Global Positioning System Fix Data](http://www.catb.org/gpsd/NMEA.html#_gga_global_positioning_system_fix_data)
Expand Down
62 changes: 62 additions & 0 deletions hooks/DBK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

/**
* Copyright 2016 Signal K and Fabian Tollenaar <fabian@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/DBT')
const utils = require('@signalk/nmea0183-utilities')

/*
=== DBK - Depth below keel ===
------------------------------------------------------------------------------
*******0 1 2 3 4 5 6
*******| | | | | | |
$--DBK,x.x,f,x.x,M,x.x,F*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
0. Depth, feet
1. f = feet
2. Depth, meters
3. M = meters
4. Depth, Fathoms
5. F = Fathoms
6. Checksum
*/

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

if ((typeof parts[2] !== 'string' && typeof parts[2] !== 'number') || (typeof parts[2] === 'string' && parts[2].trim() === '')) {
return null
}

const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: [
{
path: 'environment.depth.belowKeel',
value: utils.float(parts[2])
}
]
}
],
}

return delta
}
62 changes: 62 additions & 0 deletions hooks/DBS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

/**
* Copyright 2016 Signal K and Fabian Tollenaar <fabian@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/DBT')
const utils = require('@signalk/nmea0183-utilities')

/*
=== DBS - Depth below surface ===
------------------------------------------------------------------------------
*******0 1 2 3 4 5 6
*******| | | | | | |
$--DBS,x.x,f,x.x,M,x.x,F*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
0. Depth, feet
1. f = feet
2. Depth, meters
3. M = meters
4. Depth, Fathoms
5. F = Fathoms
6. Checksum
*/

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

if ((typeof parts[2] !== 'string' && typeof parts[2] !== 'number') || (typeof parts[2] === 'string' && parts[2].trim() === '')) {
return null
}

const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: [
{
path: 'environment.depth.belowSurface',
value: utils.float(parts[2])
}
]
}
],
}

return delta
}
2 changes: 2 additions & 0 deletions hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module.exports = {
'ALK': require('./ALK.js'),
'APB': require('./APB.js'),
'DBT': require('./DBT.js'),
'DBK': require('./DBK.js'),
'DBS': require('./DBS.js'),
'DPT': require('./DPT.js'),
'DSC': require('./DSC.js'),
'GGA': require('./GGA.js'),
Expand Down
36 changes: 36 additions & 0 deletions test/DBK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

/**
* Copyright 2016 Signal K and Fabian Tollenaar <fabian@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 Parser = require('../lib')
const chai = require('chai')
const should = chai.Should()

chai.use(require('chai-things'))

describe('DBK', () => {
it('Converts OK using individual parser', () => {
const delta = new Parser().parse('$IIDBK,035.53,f,010.83,M,005.85,F*3C')
delta.updates[0].values.should.contain.an.item.with.property('path', 'environment.depth.belowKeel')
delta.updates[0].values.should.contain.an.item.with.property('value', 10.83)
})

it('Doesn\'t choke on empty sentences', () => {
const delta = new Parser().parse('$IIDBK,,,,,,*4D')
should.equal(delta, null)
})
})
36 changes: 36 additions & 0 deletions test/DBS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

/**
* Copyright 2016 Signal K and Fabian Tollenaar <fabian@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 Parser = require('../lib')
const chai = require('chai')
const should = chai.Should()

chai.use(require('chai-things'))

describe('DBS', () => {
it('Converts OK using individual parser', () => {
const delta = new Parser().parse('$IIDBS,035.53,f,010.83,M,005.85,F*24')
delta.updates[0].values.should.contain.an.item.with.property('path', 'environment.depth.belowSurface')
delta.updates[0].values.should.contain.an.item.with.property('value', 10.83)
})

it('Doesn\'t choke on empty sentences', () => {
const delta = new Parser().parse('$IIDBS,,,,,,*55')
should.equal(delta, null)
})
})

0 comments on commit e0f0399

Please sign in to comment.