Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] align with v2 course api #91

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ module.exports = function (app) {

function mapToNmea (encoder, throttle) {
const selfStreams = encoder.keys.map((key, index) => {
app.debug(`key= ${key}, index= ${index}`)
let stream = app.streambundle.getSelfStream(key)
app.debug(`stream => ${stream}`)
if (encoder.defaults && typeof encoder.defaults[index] != 'undefined') {
stream = stream.merge(Bacon.once(encoder.defaults[index]))
}
return stream
}, app.streambundle)
const sentenceEvent = encoder.sentence ? `g${encoder.sentence}` : undefined


let stream = Bacon.combineWith(function () {
try {
return encoder.f.apply(this, arguments)
Expand Down Expand Up @@ -70,6 +73,7 @@ module.exports = function (app) {

Object.keys(plugin.sentences).forEach(name => {
if (options[name]) {
app.debug(`${name}= enabled`)
mapToNmea(plugin.sentences[name], options[getThrottlePropname(name)])
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@signalk/signalk-to-nmea0183",
"version": "1.9.0",
"version": "2.0.0-beta.1",
"description": "Signal K server plugin to convert Signal K to NMEA0183",
"main": "index.js",
"scripts": {
Expand Down
28 changes: 20 additions & 8 deletions sentences/APB.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@
// to verify
const nmea = require('../nmea.js')
module.exports = function (app) {

const apiVersion = app.config.version ? parseInt(app.config.version.split('.')[0]) : 1
const keys = apiVersion > 1
? [
'navigation.course.calcValues.crossTrackError',
'navigation.course.calcValues.bearingTrackTrue',
'navigation.course.calcValues.bearingTrue',
'navigation.course.calcValues.bearingMagnetic'
]
: [
'navigation.courseGreatCircle.crossTrackError',
'navigation.courseGreatCircle.bearingTrackTrue',
'navigation.courseGreatCircle.nextPoint.bearingTrue',
'navigation.courseGreatCircle.nextPoint.bearingMagnetic'
]

return {
sentence: 'APB',
title: 'APB - Autopilot info',
keys: [
'navigation.courseGreatCircle.crossTrackError',
'navigation.courseGreatCircle.bearingTrackTrue',
'navigation.courseGreatCircle.nextPoint'
],
f: function (xte, originToDest, nextPoint) {
keys: keys,
f: function (xte, originToDest, bearingTrue, bearingMagnetic) {
return nmea.toSentence([
'$IIAPB',
'A',
Expand All @@ -57,9 +69,9 @@ module.exports = function (app) {
nmea.radsToDeg(originToDest).toFixed(0),
'T',
'00',
nmea.radsToDeg(nextPoint.bearingTrue).toFixed(0),
nmea.radsToDeg(bearingTrue).toFixed(0),
'T',
nmea.radsToDeg(nextPoint.bearingMagnetic).toFixed(0),
nmea.radsToDeg(bearingMagnetic).toFixed(0),
'M'
])
}
Expand Down
38 changes: 25 additions & 13 deletions sentences/RMB.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,54 @@ $IIRMB,A,x.x,a,,,IIII.II,a,yyyyy.yy,a,x.x,x.x,x.x,A,a*hh
I I I I I I I I I_Speed to WP in knots
I I I I I I I I_True heading to destination in degrees
I I I I I I I_Distance to destination in miles
I I I I I_ ___ I_Longitude of the WP to destination, E/W
I I I__ I_Latidude of the WP to destination, N/S
I I I I I_ ___ I_Longitude of the WP destination, E/W
I I I__ I_Latitude of the WP destination, N/S
I I_Direction of cross-track error, L/R
I_Distance of cross-track error in miles
*/
// to verify
const nmea = require('../nmea.js')
module.exports = function (app) {

const apiVersion = app.config.version ? parseInt(app.config.version.split('.')[0]) : 1
const waypointPath = apiVersion > 1
? 'navigation.course.nextPoint.position'
: 'navigation.courseGreatCircle.nextPoint.position'
const keys = apiVersion > 1
? [
'navigation.course.calcValues.crossTrackError',
'navigation.course.calcValues.distance',
'navigation.course.calcValues.bearingTrue'
]
: [
'navigation.courseGreatCircle.crossTrackError',
'navigation.courseGreatCircle.nextPoint.distance',
'navigation.courseGreatCircle.nextPoint.bearingTrue'
]

return {
sentence: 'RMB',
title: 'RMB - Heading and distance to waypoint',
keys: [
'navigation.courseRhumbline.crossTrackError',
'resources.waypoints.next.position.latitude',
'resources.waypoints.next.position.longitude',
'navigation.courseRhumbline.nextPoint.distance',
'navigation.courseRhumbline.bearingTrue'
],
keys: keys,
f: function (
crossTrackError,
wpLatitude,
wpLongitude,
wpDistance,
bearingTrue
) {
const wp = app.getSelfPath(waypointPath)
if (!wp) return
return nmea.toSentence([
'$IIRMB',
crossTrackError.toFixed(2),
crossTrackError < 0 ? 'R' : 'L',
nmea.toNmeaDegreesLatitude(wpLatitude),
nmea.toNmeaDegreesLongitude(wpLongitude),
nmea.toNmeaDegreesLatitude(wp.value.latitude),
nmea.toNmeaDegreesLongitude(wp.value.longitude),
wpDistance.toFixed(2),
nmea.radsToDeg(bearingTrue).toFixed(2),
'V', // dont set the arrival flag as it will set of alarms.
''
])
}
}

}
8 changes: 7 additions & 1 deletion sentences/XTE.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ $IIXTE,A,A,x.x,a,N,A*hh
// to verify
const nmea = require('../nmea.js')
module.exports = function (app) {

const apiVersion = app.config.version ? parseInt(app.config.version.split('.')[0]) : 1
const keys = apiVersion > 1
? ['navigation.course.calcValues.crossTrackError']
: ['navigation.courseGreatCircle.crossTrackError']

return {
title: 'XTE - Cross-track error',
keys: ['navigation.courseRhumbline.crossTrackError'],
keys: keys,
f: function (crossTrackError) {
return nmea.toSentence([
'$IIXTE',
Expand Down