Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Device / Driver / FlymasterF1.cpp
blobb8f0d283b800ce6d806c323414ef52edd1d58fad
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/FlymasterF1.hpp"
25 #include "Device/Driver.hpp"
26 #include "Device/Parser.hpp"
27 #include "Device/Internal.hpp"
28 #include "NMEA/Checksum.hpp"
29 #include "NMEA/Info.hpp"
30 #include "NMEA/InputLine.hpp"
31 #include "Atmosphere/Temperature.hpp"
33 #include <stdlib.h>
34 #include <math.h>
36 class FlymasterF1Device : public AbstractDevice {
37 Port &port;
39 public:
40 FlymasterF1Device(Port &_port):port(_port) {}
42 virtual bool EnableNMEA(OperationEnvironment &env) override;
43 virtual bool ParseNMEA(const char *line, struct NMEAInfo &info) override;
46 bool
47 FlymasterF1Device::EnableNMEA(OperationEnvironment &env)
49 /* this command initiates NMEA mode according to the "Flymaster F1
50 Commands" document */
51 return PortWriteNMEA(port, "$PFMNAV,", env);
54 static bool
55 VARIO(NMEAInputLine &line, NMEAInfo &info)
57 // $VARIO,fPressure,fVario,Bat1Volts,Bat2Volts,BatBank,TempSensor1,TempSensor2*CS
59 // fVario = the variometer in decimeters per second
60 // Bat1Volts = the voltage of the battery in bank 1
61 // Bat2Volts = the voltage of the battery in bank 2
62 // BatBank = the battery bank in use.
63 // TempSensor1 = temperature in ºC of external wireless sensor 1
64 // TempSensor2 = temperature in ºC of external wireless sensor 2
66 fixed value;
67 if (line.ReadChecked(value))
68 info.ProvideStaticPressure(AtmosphericPressure::HectoPascal(value));
70 if (line.ReadChecked(value))
71 info.ProvideTotalEnergyVario(value / 10);
73 unsigned battery_bank;
74 fixed voltage[2];
75 if (line.ReadChecked(voltage[0]) &&
76 line.ReadChecked(voltage[1]) &&
77 line.ReadChecked(battery_bank) &&
78 battery_bank != 0 &&
79 battery_bank <= 2) {
80 info.voltage = voltage[battery_bank - 1];
81 info.voltage_available.Update(info.clock);
84 if (line.ReadChecked(value)) {
85 info.temperature = CelsiusToKelvin(value);
86 info.temperature_available = true;
89 return true;
92 bool
93 FlymasterF1Device::ParseNMEA(const char *String, NMEAInfo &info)
95 if (!VerifyNMEAChecksum(String))
96 return false;
98 NMEAInputLine line(String);
99 char type[16];
100 line.Read(type, 16);
102 if (StringIsEqual(type, "$VARIO"))
103 return VARIO(line, info);
104 else
105 return false;
108 static Device *
109 FlymasterF1CreateOnPort(const DeviceConfig &config, Port &port)
111 return new FlymasterF1Device(port);
114 const struct DeviceRegister flymaster_f1_driver = {
115 _T("FlymasterF1"),
116 _T("Flymaster F1"),
118 FlymasterF1CreateOnPort,