Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Device / Driver / ILEC.cpp
blob816b405a391ce75e7c347f7bee2cbbf61d04078b
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/ILEC.hpp"
25 #include "Device/Parser.hpp"
26 #include "Device/Driver.hpp"
27 #include "NMEA/Checksum.hpp"
28 #include "NMEA/Info.hpp"
29 #include "NMEA/InputLine.hpp"
30 #include "Units/System.hpp"
32 #include <stdlib.h>
33 #include <math.h>
35 class ILECDevice : 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 norm, bearing;
45 bool bearing_valid = line.ReadChecked(bearing);
46 bool norm_valid = line.ReadChecked(norm);
48 if (bearing_valid && norm_valid) {
49 value_r.norm = Units::ToSysUnit(norm, Unit::KILOMETER_PER_HOUR);
50 value_r.bearing = Angle::Degrees(bearing);
51 return true;
52 } else
53 return false;
56 /**
57 * Parse a "$PILC,PDA1" sentence.
59 * Example: "$PILC,PDA1,1489,-3.21,274,15,58*7D"
61 static bool
62 ParsePDA1(NMEAInputLine &line, NMEAInfo &info)
64 fixed value;
66 // altitude [m]
67 int altitude;
68 if (line.ReadChecked(altitude))
69 info.ProvideBaroAltitudeTrue(fixed(altitude));
71 // total energy vario [m/s]
72 if (line.ReadChecked(value))
73 info.ProvideTotalEnergyVario(value);
75 // wind direction [degrees, kph]
76 SpeedVector wind;
77 if (ReadSpeedVector(line, wind))
78 info.ProvideExternalWind(wind);
80 // confidence [0..100]
81 // not used
83 return true;
86 bool
87 ILECDevice::ParseNMEA(const char *_line, NMEAInfo &info)
89 if (!VerifyNMEAChecksum(_line))
90 return false;
92 NMEAInputLine line(_line);
93 char type[16];
94 line.Read(type, sizeof(type));
96 if (StringIsEqual(type, "$PILC")) {
97 line.Read(type, sizeof(type));
98 if (StringIsEqual(type, "PDA1"))
99 return ParsePDA1(line, info);
100 else
101 return false;
102 } else
103 return false;
106 static Device *
107 ILECCreateOnPort(const DeviceConfig &config, Port &com_port)
109 return new ILECDevice();
112 const struct DeviceRegister ilec_driver = {
113 _T("ILEC SN10"),
114 _T("ILEC SN10"),
116 ILECCreateOnPort,