forked from SignalK/nmea0183-signalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGGA.js
More file actions
163 lines (143 loc) · 4.62 KB
/
GGA.js
File metadata and controls
163 lines (143 loc) · 4.62 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
'use strict'
/**
* 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/GGA')
const utils = require('@signalk/nmea0183-utilities')
const moment = require('moment-timezone')
/*
=== GGA - Global Positioning System Fix Data ===
Time, Position and fix related data for a GPS receiver.
------------------------------------------------------------------------------
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| | | | | | | | | | | | | | |
$--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
0. Universal Time Coordinated (UTC)
1. Latitude
2. N or S (North or South)
3. Longitude
4. E or W (East or West)
5. GPS Quality Indicator,
- 0 - fix not available,
- 1 - GPS fix,
- 2 - Differential GPS fix
(values above 2 are 2.3 features)
- 3 = PPS fix
- 4 = Real Time Kinematic
- 5 = Float RTK
- 6 = estimated (dead reckoning)
- 7 = Manual input mode
- 8 = Simulation mode
6. Number of satellites in view, 00 - 12
7. Horizontal Dilution of precision (meters)
8. Antenna Altitude above/below mean-sea-level (geoid) (in meters)
9. Units of antenna altitude, meters
10. Geoidal separation, the difference between the WGS-84 earth
ellipsoid and mean-sea-level (geoid), '-' means mean-sea-level
below ellipsoid
11. Units of geoidal separation, meters
12. Age of differential GPS data, time in seconds since last SC104
type 1 or 9 update, null field when DGPS is not used
13. Differential reference station ID, 0000-1023
14. Checksum
*/
function isEmpty(mixed) {
return ((typeof mixed !== 'string' && typeof mixed !== 'number') || (typeof mixed === 'string' && mixed.trim() === ''))
}
module.exports = function (input) {
const { id, sentence, parts, tags } = input
const empty = parts.reduce((e, val) => {
if (isEmpty(val)) {
++e
}
return e
}, 0)
if (empty > 3) {
return null
}
const time = parts[0].indexOf('.') === -1 ? parts[0] : parts[0].split('.')[0]
const timestamp = utils.timestamp(time, moment.tz('UTC').format('DDMMYY'))
const quality = [
'no GPS',
'GNSS Fix',
'DGNSS fix',
'Precise GNSS',
'RTK fixed integer',
'RTK float',
'Estimated (DR) mode',
'Manual input',
'Simulator mode',
'Error'
]
const delta = {
updates: [
{
source: tags.source,
timestamp: timestamp,
values: [
{
path: 'navigation.position',
value: {
longitude: utils.coordinate(parts[3], parts[4]),
latitude: utils.coordinate(parts[1], parts[2])
}
},
{
path: 'navigation.gnss.methodQuality',
value: quality[utils.int(parts[5])]
},
{
path: 'navigation.gnss.satellites',
value: utils.int(parts[6])
},
{
path: 'navigation.gnss.antennaAltitude',
value: utils.int(parts[8])
},
{
path: 'navigation.gnss.horizontalDilution',
value: utils.int(parts[7])
},
{
path: 'navigation.gnss.geoidalSeparation',
value: utils.int(parts[11])
},
{
path: 'navigation.gnss.differentialAge',
value: utils.int(parts[12])
},
{
path: 'navigation.gnss.differentialReference',
value: Number(parts[13])
}
]
}
],
}
const toRemove = []
delta.updates[0].values.forEach((update, index) => {
if (typeof update.value === 'undefined' || update.value === null || (typeof update.value === 'string' && update.value.trim() === '') || (typeof update.value === 'number' && isNaN(update.value))) {
toRemove.push(index)
}
})
if (toRemove.length > 0) {
toRemove.forEach(index => {
delta.updates[0].values.splice(index, 1)
})
}
return delta
}