UNPKG

@signalk/nmea0183-signalk

Version:

A node.js/javascript parser for NMEA0183 sentences. Sentences are parsed to Signal K format.

175 lines 6.36 kB
"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. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const utils = __importStar(require("@signalk/nmea0183-utilities")); const nmea_casts_1 = require("../lib/nmea-casts"); /* === 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' || mixed.trim() === ''; } const GGA = function (input, _session) { const { parts, tags } = input; const empty = parts.reduce((e, val) => { if (isEmpty(val)) { ++e; } return e; }, 0); if (empty > 4) { return null; } const time = parts[0].indexOf('.') === -1 ? parts[0] : parts[0].split('.')[0]; const timestamp = utils.timestamp(time); const quality = [ 'no GPS', 'GNSS Fix', 'DGNSS fix', 'Precise GNSS', 'RTK fixed integer', 'RTK float', 'Estimated (DR) mode', 'Manual input', 'Simulator mode', 'Error' ]; const latitude = (0, nmea_casts_1.coord)(parts[1], parts[2]); const longitude = (0, nmea_casts_1.coord)(parts[3], parts[4]); let position = null; if (latitude !== null && longitude !== null && utils.isValidPosition(latitude, longitude)) { position = { latitude: latitude, longitude: longitude }; } const delta = { updates: [ { source: tags.source, timestamp: timestamp, values: [ { path: 'navigation.position', value: position }, { 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.float(parts[8]) }, { path: 'navigation.gnss.horizontalDilution', value: utils.float(parts[7]) }, { path: 'navigation.gnss.geoidalSeparation', value: utils.float(parts[10]) }, { path: 'navigation.gnss.differentialAge', value: utils.float(parts[12]) }, { path: 'navigation.gnss.differentialReference', value: Number(parts[13]) } ] } ] }; return delta; }; exports.default = GGA; //# sourceMappingURL=GGA.js.map