-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathKMessageNMEAVisitor.cpp
executable file
·114 lines (96 loc) · 3.9 KB
/
KMessageNMEAVisitor.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
The MIT License
Copyright (c) 2016 Thomas Sarlandie [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "KMessageNMEAVisitor.h"
#include "KBoxDebug.h"
#include "util/NMEASentenceBuilder.h"
#include "util/nmea2000.h"
void KMessageNMEAVisitor::visit(const NMEASentence& s) {
nmeaContent += s.getSentence() + "\r\n";
}
void KMessageNMEAVisitor::visit(const VoltageMeasurement &vm) {
NMEASentenceBuilder sb("II", "XDR", 4);
sb.setField(1, "V");
sb.setField(2, vm.getVoltage(), 2);
sb.setField(3, "V");
sb.setField(4, vm.getLabel());
nmeaContent += sb.toNMEA() + "\r\n";
}
void KMessageNMEAVisitor::visit(const NMEA2000Message &n2km) {
// $PCDIN,<PGN 6>,<Timestamp 8>,<src 2>,<data>*20
const tN2kMsg& msg = n2km.getN2kMsg();
char *s = nmea_pcdin_sentence_for_n2kmsg(msg, n2km.getReceivedMillis() / 1000);
nmeaContent += String(s) + "\r\n";
free(s);
}
void KMessageNMEAVisitor::visit(const BarometerMeasurement &bm) {
// XDR is not a very well defined sentence. Can be used for lots of things
// apparently but that is better than nothing.
double respressure = bm.getPressure();
//RES_MOD_7_29_17 convert pressure to Bar not hBar - 5 decimal places
respressure = respressure/100000;
NMEASentenceBuilder sb("II", "XDR", 8);
sb.setField(1, "P");
sb.setField(2, respressure, 5);
sb.setField(3, "B");
sb.setField(4, "Barometer");
sb.setField(5, "C");
sb.setField(6, bm.getTemperature());
sb.setField(7, "C");
sb.setField(8, "TempAir");
nmeaContent += sb.toNMEA() + "\r\n";
}
//RES_MOD_7_29_17 for OpenCPN drop yaw data now only 12 instead of 16 data
// part of message, switch pitch and roll to match my mount
void KMessageNMEAVisitor::visit(const IMUMessage &imu) {
NMEASentenceBuilder sb("II", "XDR", 12);
//sb.setField(1, "A");
//sb.setField(2, imu.getYaw(), 1);
//sb.setField(3, "D");
//sb.setField(4, "Yaw");
//RES_MOD_7_29_17 DEFINE NEW VARIABLEs TO ADD OFFSET to pitch and roll
// and switch pitch and roll for my mounting, adjust SetField
double resrolloffset = imu.getPitch();
double resptchoffset = imu.getRoll();
resrolloffset = - resrolloffset;
resptchoffset = - resptchoffset;
sb.setField(1, "A");
//RES_MOD_7_29_17 use new variable
//sb.setField(6, imu.getPitch(), 1);
sb.setField(2, resrolloffset, 1);
sb.setField(3, "D");
//make pitch to be roll
sb.setField(4, "ROLL");
sb.setField(5, "A");
//sb.setField(10, imu.getRoll(), 1);
sb.setField(6, resptchoffset, 1);
sb.setField(7, "D");
// make roll to be pitch; PTCH in OpenCPN
sb.setField(8, "PTCH");
sb.setField(9, "");
sb.setField(10, imu.getCalibration());
sb.setField(11, "");
sb.setField(12, "Calibration");
nmeaContent += sb.toNMEA() + "\r\n";
//RES_MOD_10_28_17 remove HDM output, as repeated from GPS
//NMEASentenceBuilder sb2("II", "HDM", 2);
//sb2.setField(1, imu.getCourse());
//sb2.setField(2, "M");
//nmeaContent += sb2.toNMEA() + "\r\n";
}