forked from SignalK/nmea0183-signalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRMC.js
More file actions
106 lines (89 loc) · 2.84 KB
/
RMC.js
File metadata and controls
106 lines (89 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright 2016 Signal K <info@signalk.org> and contributors.
*
* 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.
*/
'use strict'
const utils = require('@signalk/nmea0183-utilities')
const moment = require('moment-timezone')
/*
RMC Sentence
http://www.gpsinformation.org/dale/nmea.htm#RMC
$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
values:
- RMC Recommended Minimum sentence C
[0] 123519 Fix taken at 12:35:19 UTC
[1] A Status A=active or V=Void.
[2][3] 4807.038,N Latitude 48 deg 07.038' N
[4][5] 01131.000,E Longitude 11 deg 31.000' E
[6] 022.4 Speed over the ground in knots
[7] 084.4 Track angle in degrees True
[8] 230394 Date - 23rd of March 1994
[9][10] 003.1,W Magnetic Variation
- *6A The checksum data, always begins with *
*/
module.exports = function (input) {
const { id, sentence, parts, tags } = input
let latitude = -1
let longitude = -1
let speed = 0.0
let track = 0.0
let variation = 0.0
const timestamp = utils.timestamp(parts[0], parts[8])
const age = moment.tz(timestamp, 'UTC').unix()
latitude = utils.coordinate(parts[2], parts[3])
longitude = utils.coordinate(parts[4], parts[5])
speed = utils.float(parts[6])
speed = (!isNaN(speed) && speed > 0) ? speed : 0.0
track = utils.float(parts[7])
track = (!isNaN(track)) ? track : 0.0
variation = utils.magneticVariaton(parts[9], parts[10])
const delta = {
updates: [
{
source: tags.source,
timestamp: timestamp,
values: [
{
path: 'navigation.position',
value: {
longitude,
latitude
}
},
{
path: 'navigation.courseOverGroundTrue',
value: utils.transform(track, 'deg', 'rad')
},
{
path: 'navigation.speedOverGround',
value: utils.transform(speed, 'knots', 'ms')
},
{
path: 'navigation.magneticVariation',
value: utils.transform(variation, 'deg', 'rad')
},
{
path: 'navigation.magneticVariationAgeOfService',
value: age
},
{
path: 'navigation.datetime',
value: timestamp,
},
]
}
],
}
return delta
}