UNPKG

@signalk/nmea0183-signalk

Version:

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

59 lines (50 loc) 1.79 kB
/** * 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') /* 99 00 XX Compass variation sent by ST40 compass instrument or ST1000, ST2000, ST4000+, E-80 every 10 seconds but only if the variation is set on the instrument Positive XX values: Variation West, Negative XX values: Variation East Examples (XX => variation): 00 => 0, 01 => -1 west, 02 => -2 west ... FF => +1 east, FE => +2 east ... Corresponding NMEA sentences: RMC, HDG */ module.exports = function (input) { const { id, sentence, parts, tags } = input var XX = parseInt(parts[2], 16) var value = 128 - (XX & 0x7f) var s = -1 if (XX & (0x80 != 0)) { s = 1 } var magneticVariation = s * value var pathValues = [] pathValues.push({ path: 'navigation.magneticVariation', value: utils.transform(utils.float(magneticVariation), 'deg', 'rad'), }) return { updates: [ { source: tags.source, timestamp: tags.timestamp, values: pathValues, }, ], } }