-
Notifications
You must be signed in to change notification settings - Fork 28
/
VHW.js
42 lines (40 loc) · 1.14 KB
/
VHW.js
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
/**
$IIVHW,x .x,T,x.x,M,x.x,N,x.x,K*hh
I I I I I I I__I_Surface speed in kph
I I I I I__I_Surface speed in knots
I I I__I_Magnetic compass heading
I__I_True compass heading
*/
// NMEA0183 Encoder VHW $IIVHW,201.1,T,209.2,M,6.5,N,12.0,K*6E
const nmea = require('../nmea.js')
module.exports = function (app) {
return {
sentence: 'VHW',
title: 'VHW - Speed and direction',
keys: [
'navigation.headingTrue',
'navigation.magneticVariation',
'navigation.speedThroughWater'
],
f: function vhw (headingTrue, magneticVariation, speedThroughWater) {
var headingMagnetic = headingTrue + magneticVariation
if (headingMagnetic > Math.PI * 2) {
headingMagnetic -= Math.PI * 2
}
if (headingMagnetic < 0) {
headingMagnetic += Math.PI * 2
}
return nmea.toSentence([
'$IIVHW',
nmea.radsToDeg(headingTrue).toFixed(1),
'T',
nmea.radsToDeg(headingMagnetic).toFixed(1),
'M',
nmea.msToKnots(speedThroughWater).toFixed(2),
'N',
nmea.msToKM(speedThroughWater).toFixed(2),
'K'
])
}
}
}