Debian Codegraph @

src/Network/garmin.cxx

raw symbols SCIP
1 // garmin.cxx -- Garmin protocol class
2 //
3 // Written by Curtis Olson, started November 1999.
4 //
5 // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <simgear/debug/logstream.hxx>
28 #include <FDM/flightProperties.hxx>
29 #include <simgear/constants.h>
30 #include "garmin.hxx"
31
32 using namespace NMEA;
33
34 FGGarmin::FGGarmin() :
35 FGNMEA(),
36 mGarminMessages(GARMIN::PGRMZ),
37 mMetric(true) // use metric altitude reports
38 // In fact Garmin devices normally seem report barometric altitude in feet (not meters), but
39 // the FG implementation has always used metric reports for years (and we keep it this way,
40 // to avoid complaints about changed implementation). The unit is also part of the NMEA message,
41 // so smart devices are probably ok with both anyway.
42 {
43 // only enable the GPRMC standard NMEA message
44 mNmeaMessages = NMEA::GPRMC;
45 // Garmin uses CR-LF line feeds.
46 mLineFeed = "\r\n";
47 }
48
49
50 FGGarmin::~FGGarmin()
51 {
52 }
53
54
55 // generate Garmin NMEA messages
56 bool FGGarmin::gen_message()
57 {
58 (void) FGNMEA::gen_message();
59
60 char nmea[256];
61
62 // RMZ sentence (Garmin proprietary)
63 if (mGarminMessages & GARMIN::PGRMZ)
64 {
65 double altitude_ft = mFdm.get_Altitude();
66
67 // $PGRMZ,AAAA.A,F,T*XX
68 if (mMetric)
69 snprintf(nmea, 256, "$PGRMZ,%.1f,M,3", altitude_ft * SG_FEET_TO_METER);
70 else
71 snprintf(nmea, 256, "$PGRMZ,%.1f,F,3", altitude_ft);
72 add_with_checksum(nmea, 256);
73 }
74
75 return true;
76 }
77
78 // process a Garmin sentence
79 void FGGarmin::parse_message(const std::vector<std::string>& tokens)
80 {
81 if (tokens[0] == "PGRMZ")
82 {
83 if (tokens.size()<3)
84 return;
85
86 // #1: altitude
87 double altitude = atof( tokens[1].c_str() );
88
89 // #2: altitude units
90 const std::string& alt_units = tokens[2];
91 if ( alt_units != "F" && alt_units != "f" )
92 altitude *= SG_METER_TO_FEET;
93
94 mFdm.set_Altitude( altitude );
95
96 SG_LOG( SG_IO, SG_DEBUG, " altitude = " << altitude );
97 }
98 else
99 {
100 // not a Garmin message. Maybe standard NMEA message.
101 FGNMEA::parse_message(tokens);
102 }
103 }