This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcassiopeia.js
96 lines (87 loc) · 2.6 KB
/
cassiopeia.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
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
var Bacon = require("baconjs").Bacon;
var n2kMessages = require("../../webapp/lib/messages.js").messages;
var navi = require('../naviutils.js');
/**
var sources = {
n2k: new StreamBundle(function(msg){return msg.pgn;}),
nmea: {
raw: new Bacon.Bus(),
json: new Bacon.Bus()
},
gaugeData: new StreamBundle()
}
**/
exports.boat = {
configureStreams: function (streams) {
streams.gaugeData.plug(streams.n2k.getTypeStream(n2kMessages.WATERDEPTH).map(function (msg) {
return {
type: 'depth',
depth: msg.fields.Depth
}
}), 'depth');
/* { type: 'nav-info',
timestamp: '065335.00',
status: 'valid',
lat: '6008.634',
latPole: 'N',
lon: '02453.922',
lonPole: 'E',
speedKnots: 5.9,
trackTrue: 163.4,
date: '220913',
variation: 8.1,
variationPole: 'E',
talker_id: 'II' }*/
streams.gaugeData.plug(streams.nmea.json.filter(function (msg) {
return msg.type === 'nav-info'
}).flatMap(function (msg) {
return Bacon.fromArray([
{
type: 'course',
heading: msg.trackTrue},
{
type: 'speed',
knots: msg.speedKnots
},
{
type: 'position',
lat: Number(msg.lat.substring(0, 2)) + Number(msg.lat.substring(2, msg.lat.length)) / 60,
lon: Number(msg.lon.substring(0, 3)) + Number(msg.lon.substring(3, msg.lon.length) / 60)
}
]);
}));
streams.gaugeData.plug(streams.nmea.json.filter(
function (msg) {
return msg.type === '2waypoint'
}).map(function (msg) {
return {
type: '2waypoint',
bearing: Number(msg.bearingtrue),
distance: Number(msg.distance),
vmg: Number(0)
};
})
);
var apparentWind = streams.n2k.getTypeStream(n2kMessages.WIND).map(
function (n2k) {
return {
type: 'wind',
reference: 'apparent',
angle: n2k.fields['Wind Angle'],
speed: n2k.fields['Wind Speed']
}
});
streams.gaugeData.plug(apparentWind);
var sogKnots = streams.nmea.json.filter(function (n) {
return n.type == 'nav-info'
}).map('.speedKnots');
streams.gaugeData.plug(sogKnots.combine(apparentWind, function (sogInKnots, awInfo) {
return {
type: 'wind',
reference: 'true boat',
speed: navi.getTrueWindSpeed(navi.knots2MetersPerSecond(sogInKnots), awInfo.speed, awInfo.angle),
angle: navi.getTrueWindAngle(navi.knots2MetersPerSecond(sogInKnots), awInfo.speed, awInfo.angle)
};
}));
}
}