Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions hooks/ALK.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

'use strict'

const utils = require('@signalk/nmea0183-utilities')
const loadSubHooks = require('../lib/loadSubhooks')
const path = require('path').join(__dirname, './seatalk')
const folderName = 'seatalk'
/*
0 1 2 3
| | | |
Expand All @@ -32,19 +28,14 @@ STALK Raymarine Seatalk1 datagram sentence
3 hex Checksum
*/

const subHooks = loadSubHooks(folderName)
const seatalkHooks = require('./seatalk')

module.exports = function(parser, input) {
const { id, sentence, parts, tags } = input
const key = '0x' + parseInt(parts[0],16).toString(16).toUpperCase()
if (key in subHooks){
try {
return require(`${path}/${key}`)(parser, input)
} catch (e) {
return Promise.reject(e)
}

if (typeof seatalkHooks[key] === 'function'){
return seatalkHooks[key](parser, input)
} else {
return Promise.resolve(null)
return null
}
}
81 changes: 38 additions & 43 deletions hooks/APB.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,71 @@

/**
* 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/APB')
const utils = require('@signalk/nmea0183-utilities')

/*

0 1 2 3 4 5 6 7 8 9 10 11 12
| | | | | | | | | | | | |
$GPAPB,A,A,0.10,R,N,V,V,011,M,DEST,011,M,011,M*3C
$GPAPB,A,A,0.10,R,N,V,V,011,M,DEST,011,M,011,M*3C
where:
APB Autopilot format B
0 A Loran-C blink/SNR warning, general warning
1 A Loran-C cycle warning
2 0.10 cross-track error distance
3 R steer Right to correct (or L for Left)
4 N cross-track error units - nautical miles (K for kilometers)
5 V arrival alarm - circle
6 V arrival alarm - perpendicular
7,8 011,M magnetic bearing, origin to destination
9 DEST destination waypoint ID
10,11 011,M magnetic bearing, present position to destination
12,13 011,M magnetic heading to steer (bearings could True as 033,T)
0 A Loran-C blink/SNR warning, general warning
1 A Loran-C cycle warning
2 0.10 cross-track error distance
3 R steer Right to correct (or L for Left)
4 N cross-track error units - nautical miles (K for kilometers)
5 V arrival alarm - circle
6 V arrival alarm - perpendicular
7,8 011,M magnetic bearing, origin to destination
9 DEST destination waypoint ID
10,11 011,M magnetic bearing, present position to destination
12,13 011,M magnetic heading to steer (bearings could True as 033,T)
*3C Checksum

*/

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

if(parts[0].toUpperCase() == 'V') {
// Don't parse this sentence as it's void.
return Promise.reject(new Error('Not parsing sentence for it\'s void (LORAN-C blink/SNR warning)'))
}
const { id, sentence, parts } = input

if(parts[1].toUpperCase() == 'V') {
return Promise.reject(new Error('Not parsing sentence for it\'s void (LORAN-C cycle warning)'))
}
if(parts[0].toUpperCase() == 'V') {
// Don't parse this sentence as it's void.
throw new Error('Not parsing sentence for it\'s void (LORAN-C blink/SNR warning)')
}

const xte = utils.transform(parts[2], (parts[4].toUpperCase() === 'N' ? 'nm' : 'km'), 'm')
if(parts[1].toUpperCase() == 'V') {
throw new Error('Not parsing sentence for it\'s void (LORAN-C cycle warning)')
}

const xte = utils.transform(parts[2], (parts[4].toUpperCase() === 'N' ? 'nm' : 'km'), 'm')

const currentRoute = {
source: utils.source(id),
timestamp: utils.timestamp(),
steer: (parts[3].toUpperCase() == 'R' ? 'right' : 'left'),
bearingActual: utils.transform(utils.float(parts[10]), 'deg', 'rad'),
bearingDirect: utils.transform(utils.float(parts[7]), 'deg', 'rad'),
courseRequired: utils.transform(utils.float(parts[12]), 'deg', 'rad'),
waypoint: {
next: parts[9],
xte: xte
}
const currentRoute = {
source: utils.source(id),
timestamp: utils.timestamp(),
steer: (parts[3].toUpperCase() == 'R' ? 'right' : 'left'),
bearingActual: utils.transform(utils.float(parts[10]), 'deg', 'rad'),
bearingDirect: utils.transform(utils.float(parts[7]), 'deg', 'rad'),
courseRequired: utils.transform(utils.float(parts[12]), 'deg', 'rad'),
waypoint: {
next: parts[9],
xte: xte
}

return Promise.reject(new Error('@FIXME: APB hook needs to be rewritten to fit latest version of SK'))
} catch (e) {
debug(`Try/catch failed: ${e.message}`)
return Promise.reject(e)
}

throw new Error('@FIXME: APB hook needs to be rewritten to fit latest version of SK')
}
51 changes: 23 additions & 28 deletions hooks/DBT.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

/**
* 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')

Expand All @@ -37,31 +37,26 @@ Field Number:
*/

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

if ((typeof parts[2] !== 'string' && typeof parts[2] !== 'number') || (typeof parts[2] === 'string' && parts[2].trim() === '')) {
return Promise.resolve(null)
}
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.belowTransducer',
value: utils.float(parts[2])
}
]
}
],
}

return Promise.resolve({ delta })
} catch (e) {
debug(`Try/catch failed: ${e.message}`)
return Promise.reject(e)
const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: [
{
path: 'environment.depth.belowTransducer',
value: utils.float(parts[2])
}
]
}
],
}

return delta
}
97 changes: 46 additions & 51 deletions hooks/DPT.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

/**
* 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')

/*
=== DPT - Depth of water ===
------------------------------------------------------------------------------
*******0 1 2
*******| | |
*******| | |
$--DPT,x.x,x.x*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
Expand All @@ -33,55 +33,50 @@ Field Number:
*/

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

if (((typeof parts[0] !== 'string' || parts[0].trim() == '') && typeof parts[0] !== 'number') ||
(typeof parts[1] !== 'string' && typeof parts[1] !== 'number')) {
return Promise.resolve(null)
}
var depth = utils.float(parts[0])
const { id, sentence, parts, tags } = input

const delta = {
updates: [
{
source: tags.source,
timestamp: tags.timestamp,
values: [
{
path: 'environment.depth.belowTransducer',
value: depth
}
]
}
],
}
if (((typeof parts[0] !== 'string' || parts[0].trim() == '') && typeof parts[0] !== 'number') ||
(typeof parts[1] !== 'string' && typeof parts[1] !== 'number')) {
return null
}
var depth = utils.float(parts[0])

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

if ( offset > 0 ) {
delta.updates[0].values.push({
path: 'environment.depth.surfaceToTransducer',
value: offset
})
delta.updates[0].values.push({
path: 'environment.depth.belowSurface',
value: depth + offset
})
} else if ( offset < 0 ) {
delta.updates[0].values.push({
path: 'environment.depth.transducerToKeel',
value: offset * -1
})
delta.updates[0].values.push({
path: 'environment.depth.belowKeel',
value: depth + offset
})
}
var offset = utils.float(parts[1])

return Promise.resolve({ delta })
} catch (e) {
debug(`Try/catch failed: ${e.message}`)
return Promise.reject(e)
if ( offset > 0 ) {
delta.updates[0].values.push({
path: 'environment.depth.surfaceToTransducer',
value: offset
})
delta.updates[0].values.push({
path: 'environment.depth.belowSurface',
value: depth + offset
})
} else if ( offset < 0 ) {
delta.updates[0].values.push({
path: 'environment.depth.transducerToKeel',
value: offset * -1
})
delta.updates[0].values.push({
path: 'environment.depth.belowKeel',
value: depth + offset
})
}

return delta
}
Loading