-
Notifications
You must be signed in to change notification settings - Fork 0
/
NMEA.hpp
48 lines (39 loc) · 994 Bytes
/
NMEA.hpp
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
#define MAXLEN 255
/*
* Format of HDM Message
* $--HDM,x.x,M*hh
*
*
*/
const char* sourceID = "HC"; //Heading Compass
//Virtual base class. Completely useless until derived.
//It just provides the method to calculate and add
//The NMEA checkSum which is common to all NMEA messages
class NMEAmessage {
public:
char msgString[MAXLEN];
protected:
void addCheckSum() {
int checkSum = 0;
char temp[MAXLEN];
for(int i = 1; i < strlen(msgString); i++)
{
checkSum ^= msgString[i];
}
// Add the "*" and check sum
sprintf(msgString,"%s*%02x", msgString, checkSum);
}
};
/*
* "HDM" message - Magnetic Heading
*
* All the work is done in the constructor.
* Once created, this object is read-only
*/
class HDMmessage : public NMEAmessage {
public:
HDMmessage(float heading) {
sprintf(msgString,"$%sHDM,%03d,M",sourceID, static_cast<int>(std::round(heading)));
addCheckSum();
}
};