From 3693d83cd722e595256f890d548710ed9d138b7c Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Sat, 22 Apr 2017 21:36:42 -0400 Subject: [PATCH 1/4] Add real lat/lon to RMC sentence --- index.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 757ae50..8e74fd5 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ module.exports = function(app) { function mapToNmea(encoder) { const selfStreams = encoder.keys.map(app.streambundle.getSelfStream, app.streambundle) - plugin.unsubscribes.push(Bacon.combineWith(encoder.f, selfStreams).changes().debounceImmediate(20).log().onValue(nmeaString => { + plugin.unsubscribes.push(Bacon.combineWith(encoder.f, selfStreams).changes().debounceImmediate(20).onValue(nmeaString => { app.emit('nmea0183out', nmeaString) })) } @@ -195,22 +195,23 @@ Field Number: var RMC = { keys: [ - 'navigation.datetime', 'navigation.speedOverGround', 'navigation.courseOverGroundTrue' + 'navigation.datetime', 'navigation.speedOverGround', 'navigation.courseOverGroundTrue', 'navigation.position' ], - f: function(datetime8601, sog, cog) { + f: function(datetime8601, sog, cog, position) { var datetime = new Date(datetime8601); var hours = ('00' + datetime.getHours()).slice(-2); var minutes = ('00' + datetime.getMinutes()).slice(-2); var seconds = ('00' + datetime.getSeconds()).slice(-2); + return toSentence([ '$SKRMC', hours + minutes + seconds + '.020', 'A', - '0000.00', - 'N', - '0000.00', - 'E', + conv_latlon(position.latitude), + position.latitude < 0 ? 'S' : 'N', + conv_latlon(position.longitude), + position.longitude < 0 ? 'W' : 'E', (sog * 1.94384).toFixed(1), - cog.toFixed(1), + radsToDeg(cog).toFixed(1), '0000', '7.0', 'E' @@ -321,3 +322,27 @@ function toHexString(v) { lsn = (v >> 0) & 0x0f; return m_hex[msn] + m_hex[lsn]; }; + +function radsToDeg(radians) { + return radians * 180 / Math.PI +} + +function padd(n, p, c) +{ + var pad_char = typeof c !== 'undefined' ? c : '0'; + var pad = new Array(1 + p).join(pad_char); + return (pad + n).slice(-pad.length); +} + +function conv_latlon(val) +{ + if ( val < 0 ) + { + val *= -1; + } + + var lati = Math.floor(val) + var latm = val - lati + latm *= 60.0; + return padd(lati.toFixed(0),2) + padd(latm.toFixed(4), 7) +} From 2538053a70bd1d788935b328629db296ea76c35c Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Sun, 23 Apr 2017 17:46:28 -0400 Subject: [PATCH 2/4] Update to use Math.abs --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.js b/index.js index 8e74fd5..2ee0222 100644 --- a/index.js +++ b/index.js @@ -336,11 +336,7 @@ function padd(n, p, c) function conv_latlon(val) { - if ( val < 0 ) - { - val *= -1; - } - + val = Math.abs(val) var lati = Math.floor(val) var latm = val - lati latm *= 60.0; From 002aa811a1d25adef5e0093ab1745f575dafab1b Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Sun, 23 Apr 2017 17:57:23 -0400 Subject: [PATCH 3/4] Update more descriptice variable names in lat/lon conversion --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2ee0222..67a31fa 100644 --- a/index.js +++ b/index.js @@ -337,8 +337,8 @@ function padd(n, p, c) function conv_latlon(val) { val = Math.abs(val) - var lati = Math.floor(val) - var latm = val - lati - latm *= 60.0; - return padd(lati.toFixed(0),2) + padd(latm.toFixed(4), 7) + var minutes = Math.floor(val) + var minutes_decimal = val % 1 + minutes_decimal *= 60.0; + return padd(minutes.toFixed(0),2) + padd(minutes_decimal.toFixed(4), 7) } From 251652fd955e58d009a9f9bc290605a0b6398f2f Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Sun, 23 Apr 2017 17:58:41 -0400 Subject: [PATCH 4/4] Rename lat/long conversion function to toNmeaDegrees --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 67a31fa..045ed0a 100644 --- a/index.js +++ b/index.js @@ -206,9 +206,9 @@ var RMC = { return toSentence([ '$SKRMC', hours + minutes + seconds + '.020', 'A', - conv_latlon(position.latitude), + toNmeaDegrees(position.latitude), position.latitude < 0 ? 'S' : 'N', - conv_latlon(position.longitude), + toNmeaDegrees(position.longitude), position.longitude < 0 ? 'W' : 'E', (sog * 1.94384).toFixed(1), radsToDeg(cog).toFixed(1), @@ -334,7 +334,7 @@ function padd(n, p, c) return (pad + n).slice(-pad.length); } -function conv_latlon(val) +function toNmeaDegrees(val) { val = Math.abs(val) var minutes = Math.floor(val)