-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNmeaSerial.cpp
113 lines (99 loc) · 3.46 KB
/
NmeaSerial.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
/*
* Copyright 2010,2011,2012,2013 Robert Huitema robert@42.co.nz
*
* This file is part of FreeBoard. (http://www.42.co.nz/freeboard)
*
* FreeBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* FreeBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with FreeBoard. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* NmeaSerial.cpp
*
* Created on: 23/12/2010
* Author: robert
*/
#include "NmeaSerial.h"
NmeaSerial::~NmeaSerial() {
}
void NmeaSerial::begin(long speed) {
//initialise the nmea output, always pind 46/48 for AltSoftSerial
AltSoftSerial::begin(speed);
}
void NmeaSerial::printNmea(char* sentence) {
//sentence can be up to 80 chars
//make it as perfect as possible, as the Raymarine C70 is very touchy
// noInterrupts();
AltSoftSerial::println(sentence);
// interrupts();
//if(DEBUG)Serial.println(sentence);
}
/*=== MWV - Wind Speed and Angle ===
*
* ------------------------------------------------------------------------------
* 1 2 3 4 5
* | | | | |
* $--MWV,x.x,a,x.x,a*hh<CR><LF>
* ------------------------------------------------------------------------------
*
* Field Number:
*
* 1. Wind Angle, 0 to 360 degrees
* 2. Reference, R = Relative, T = True
* 3. Wind Speed
* 4. Wind Speed Units, K/M/N
* 5. Status, A = Data Valid
* 6. Checksum
*
*/
void NmeaSerial::printWindNmea() {
//Assemble a sentence of the various parts so that we can calculate the proper checksum
PString str(windSentence, sizeof(windSentence));
str.print(F("$WIMWV,"));
str.print(model->getWindApparentDir());
str.print(F(".0,R,"));
str.print(model->getWindAverage());
str.print(F(",N,A*"));
//calculate the checksum
cs = getChecksum(windSentence); //clear any old checksum
//bug - arduino prints 0x007 as 7, 0x02B as 2B, so we add it now
if (cs < 0x10) str.print('0');
str.print(cs, HEX); // Assemble the final message and send it out the serial port
Serial.println(windSentence);
printNmea(windSentence);
}
/*
* Heading, True.
*
*Actual vessel heading in degrees Ture produced by any device or system producing true heading.
*
*$--HDT,x.x,T
*x.x = Heading, degrees True
*/
void NmeaSerial::printTrueHeading() {
//Assemble a sentence of the various parts so that we can calculate the proper checksum
// declination is positive when true N is west of MagN, eg subtract the declination
if(model->getDeclination()==0.0)return;
PString str(trueHeadingSentence, sizeof(trueHeadingSentence));
str.print(F("$HCHDT,"));
float trueHeading = model->getMagneticHeading()-model->getDeclination();
str.print(trueHeading);
str.print(F(",T*"));
//calculate the checksum
cs = 0; //clear any old checksum
for (unsigned int n = 1; n < strlen(trueHeadingSentence) - 1; n++) {
cs ^= trueHeadingSentence[n]; //calculates the checksum
}
//bug - arduino prints 0x007 as 7, 0x02B as 2B, so we add it now
if (cs < 0x10) str.print('0');
str.print(cs, HEX); // Assemble the final message and send it out the serial port
Serial.println(trueHeadingSentence);
printNmea(trueHeadingSentence);
}