UNPKG

@signalk/nmea0183-signalk

Version:

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

179 lines (174 loc) 6.44 kB
"use strict"; /** * Copyright 2021 Signal K 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. */ 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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const utils = __importStar(require("@signalk/nmea0183-utilities")); const debug_1 = __importDefault(require("debug")); const debug = (0, debug_1.default)('signalk-parser-nmea0183/GSV'); /** NMEA0183 GSV $GPGSV,3,1,09,07,16,321,37,08,29,281,33,10,29,143,35,16,75,216,35,0*6E $GPGSV,3,2,09,18,38,057,35,20,44,105,40,21,81,117,33,26,43,164,25,0*63 $GPGSV,3,3,09,27,62,289,41,0*5B $GLGSV,3,1,10,65,14,112,18,71,15,018,11,72,25,069,31,77,10,181,30,0*79 $GLGSV,3,2,10,78,52,221,38,79,44,310,28,80,00,342,,81,35,261,40,0*7E $GLGSV,3,3,10,87,41,052,31,88,75,350,33,0*73 $GAGSV,2,1,07,01,37,308,33,03,09,074,35,05,07,025,,13,85,237,31,0*7F $GAGSV,2,2,07,15,39,060,33,21,63,228,39,26,30,239,40,0*44 GSV - GNSS Satellites In View ** 0 1 2 3 4 5 6 n | | | | | | | | $--GSV,x,x,x,x,x,x,x.........*hh<CR><LF> ** Field Number: 0) Number of sentences for full data 1) sentence number 2) Number of satellites in view 3) Satellite PRN number 4) Elevation, degrees 5) Azimuth, degrees 6) SNR - higher is better 7) Satellite PRN number 8) Elevation, degrees 9) Azimuth, degrees 10) SNR - higher is better 11) Satellite PRN number 12) Elevation, degrees 13) Azimuth, degrees 14) SNR - higher is better 15) Satellite PRN number 16) Elevation, degrees 17) Azimuth, degrees 18) SNR - higher is better n) Checksum note: NMEA 0183 4.11 has an , not used, extra field 19. */ const NUMBER_OF_SENTENCES = 0; const SENTENCE_NUMBER = 1; const SATS_IN_VIEW = 2; const SAT_DATA_BLOCK_START = 3; const SAT_DATA_LENGTH = 4; const OFFSET_ELEVATION = 1; const OFFSET_AZIMUTH = 2; const OFFSET_SNR = 3; const TALKER_TO_GNSS = { GP: 'GPS', GL: 'GLONASS', GA: 'GALILEO', GB: 'BEIDOU', GQ: 'QZSS' }; const GSV = function (input, session) { const { id, parts, tags, talker } = input; let gsvData = session['gsvData']; if (!gsvData) { gsvData = { nextSentenceNumber: 1, numberOfSentences: Number(parts[NUMBER_OF_SENTENCES]), count: Number(parts[SATS_IN_VIEW]), satellites: [], gnss: TALKER_TO_GNSS[talker] }; session['gsvData'] = gsvData; } if (Number(parts[SENTENCE_NUMBER]) !== gsvData.nextSentenceNumber) { debug(`Expected sentence number to be ${gsvData.nextSentenceNumber} but got ${parts}`); delete session['gsvData']; return null; } gsvData.nextSentenceNumber = (gsvData.nextSentenceNumber ?? 0) + 1; for (let i = 0; i < 4; i++) { const thisSatDataStart = SAT_DATA_BLOCK_START + i * SAT_DATA_LENGTH; const _satPRN = parts[thisSatDataStart]; if (_satPRN !== undefined && !isNaN(Number(_satPRN))) { const satPRN = Number(_satPRN); gsvData.satellites.push({ id: satPRN >= 64 ? satPRN - 64 : satPRN, elevation: utils.transform(parts[thisSatDataStart + OFFSET_ELEVATION] ?? '0', 'deg', 'rad'), azimuth: utils.transform(parts[thisSatDataStart + OFFSET_AZIMUTH] ?? '0', 'deg', 'rad'), SNR: Number(parts[thisSatDataStart + OFFSET_SNR]) }); } } if (Number(parts[SENTENCE_NUMBER]) === gsvData.numberOfSentences) { delete session['gsvData']; delete gsvData.nextSentenceNumber; delete gsvData.numberOfSentences; gsvData.satellites = gsvData.satellites.slice(0, gsvData.count); let source = tags.source; if (id === 'GSVH') { // Unicore UM98x slave antenna gsvData.antennaType = 'SLAVE'; //no source from tag, append H to create separate source from regular talker if (source === ':') { source = `${talker}-H`; } } return { updates: [ { source, timestamp: tags.timestamp, values: [ { path: 'navigation.gnss.satellitesInView', value: gsvData } ] } ] }; } return null; }; exports.default = GSV; //# sourceMappingURL=GSV.js.map