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

Add real lat/lon to RMC sentence #3

Merged
merged 4 commits into from
Apr 24, 2017
Merged
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
37 changes: 29 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
}
Expand Down Expand Up @@ -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',
toNmeaDegrees(position.latitude),
position.latitude < 0 ? 'S' : 'N',
toNmeaDegrees(position.longitude),
position.longitude < 0 ? 'W' : 'E',
(sog * 1.94384).toFixed(1),
cog.toFixed(1),
radsToDeg(cog).toFixed(1),
'0000',
'7.0',
'E'
Expand Down Expand Up @@ -321,3 +322,23 @@ 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 toNmeaDegrees(val)
{
val = Math.abs(val)
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)
}