Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Device / Driver / Condor.cpp
blob03d816e0e5495fd60ee1b4bc34a46d39fdc59757
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Device/Driver/Condor.hpp"
25 #include "Device/Driver.hpp"
26 #include "Units/System.hpp"
27 #include "Device/Parser.hpp"
28 #include "NMEA/Checksum.hpp"
29 #include "NMEA/Info.hpp"
30 #include "NMEA/InputLine.hpp"
31 #include "Compiler.h"
33 #include <stdlib.h>
35 class CondorDevice : public AbstractDevice {
36 public:
37 virtual bool ParseNMEA(const char *line, struct NMEAInfo &info) override;
40 static bool
41 ReadSpeedVector(NMEAInputLine &line, SpeedVector &value_r)
43 fixed bearing, norm;
45 bool bearing_valid = line.ReadChecked(bearing);
46 bool norm_valid = line.ReadChecked(norm);
48 if (bearing_valid && norm_valid) {
49 // Condor 1.1.4 outputs the direction that the wind is going to,
50 // _not_ the direction it is coming from !!
52 // This seems to differ from the output that the LX devices are giving !!
53 value_r.bearing = Angle::Degrees(bearing).Reciprocal();
54 value_r.norm = Units::ToSysUnit(norm, Unit::KILOMETER_PER_HOUR);
55 return true;
56 } else
57 return false;
60 static bool
61 cLXWP0(NMEAInputLine &line, NMEAInfo &info)
64 $LXWP0,Y,222.3,1665.5,1.71,,,,,,239,174,10.1
66 0 logger_stored (Y/N)
67 1 IAS (kph) ----> Condor uses TAS!
68 2 baroaltitude (m)
69 3 vario (m/s)
70 4-8 unknown
71 9 heading of plane
72 10 windcourse (deg)
73 11 windspeed (kph)
77 line.Skip();
79 fixed airspeed;
80 bool tas_available = line.ReadChecked(airspeed);
82 fixed value;
83 if (line.ReadChecked(value))
84 info.ProvideBaroAltitudeTrue(value);
86 if (tas_available)
87 info.ProvideTrueAirspeed(Units::ToSysUnit(airspeed, Unit::KILOMETER_PER_HOUR));
89 if (line.ReadChecked(value))
90 info.ProvideTotalEnergyVario(value);
92 line.Skip(6);
94 SpeedVector wind;
95 if (ReadSpeedVector(line, wind))
96 info.ProvideExternalWind(wind);
98 return true;
101 bool
102 CondorDevice::ParseNMEA(const char *String, NMEAInfo &info)
104 if (!VerifyNMEAChecksum(String))
105 return false;
107 NMEAInputLine line(String);
108 char type[16];
109 line.Read(type, 16);
111 if (StringIsEqual(type, "$LXWP0"))
112 return cLXWP0(line, info);
114 return false;
117 static Device *
118 CondorCreateOnPort(const DeviceConfig &config, gcc_unused Port &com_port)
120 return new CondorDevice();
123 const struct DeviceRegister condor_driver = {
124 _T("Condor"),
125 _T("Condor Soaring Simulator"),
127 CondorCreateOnPort,