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 "NMEA/Info.hpp"
25 #include "Device/Port/NullPort.hpp"
26 #include "Device/Driver.hpp"
27 #include "Device/Register.hpp"
28 #include "Device/Parser.hpp"
29 #include "Device/device.hpp"
30 #include "Engine/Waypoint/Waypoints.hpp"
31 #include "Input/InputEvents.hpp"
32 #include "OS/Args.hpp"
33 #include "Profile/DeviceConfig.hpp"
34 #include "Util/ConvertString.hpp"
38 const struct DeviceRegister
*driver
;
41 Dump(GeoPoint location
)
43 int latitude
= (int)(location
.latitude
.Degrees() * 3600);
44 char north_or_south
= latitude
< 0 ? 'S' : 'N';
45 latitude
= abs(latitude
);
47 int longitude
= (int)(location
.longitude
.Degrees() * 3600);
48 char east_or_west
= latitude
< 0 ? 'W' : 'E';
49 longitude
= abs(longitude
);
51 printf("%d.%02u.%02u%c;%d.%02u.%02u%c",
52 latitude
/ 3600, (latitude
/ 60) % 60, latitude
% 60, north_or_south
,
53 longitude
/ 3600, (longitude
/ 60) % 60, longitude
% 60, east_or_west
);
57 Dump(const ExternalSettings
&settings
)
59 if (settings
.mac_cready_available
)
60 printf("MacCready=%.1f\n", (double)settings
.mac_cready
);
62 if (settings
.ballast_fraction_available
)
63 printf("Ballast=%.1f\n", (double)settings
.ballast_fraction
);
65 if (settings
.bugs_available
)
66 printf("Bugs=%.1f\n", (double)settings
.bugs
);
68 if (settings
.qnh_available
)
69 printf("QNH=%f\n", (double)settings
.qnh
.GetHectoPascal());
73 Dump(const NMEAInfo
&basic
)
75 if (basic
.date_available
)
76 printf("Date=%02u.%02u.%04u\n",
77 basic
.date_time_utc
.day
, basic
.date_time_utc
.month
, basic
.date_time_utc
.year
);
79 if (basic
.time_available
)
80 printf("Time=%02u:%02u:%02u\n",
81 basic
.date_time_utc
.hour
, basic
.date_time_utc
.minute
, basic
.date_time_utc
.second
);
84 printf("GPS not connected\n");
85 else if (!basic
.gps
.satellites_used_available
)
86 printf("GPS connected\n");
88 printf("GPS connected, %d satellites\n", basic
.gps
.satellites_used
);
90 if (basic
.location_available
) {
96 if (basic
.track_available
)
97 printf("TrackBearing=%d\n", (int)basic
.track
.Degrees());
99 if (basic
.ground_speed_available
)
100 printf("GroundSpeed=%d\n", (int)basic
.ground_speed
);
102 if (basic
.airspeed_available
) {
103 printf("TrueAirspeed=%d\n", (int)basic
.true_airspeed
);
104 printf("IndicatedAirspeed=%d\n",
105 (int)basic
.indicated_airspeed
);
108 if (basic
.gps_altitude_available
)
109 printf("GPSAltitude=%d\n", (int)basic
.gps_altitude
);
111 if (basic
.static_pressure_available
)
112 printf("StaticPressure=%f hPa\n",
113 (double)basic
.static_pressure
.GetHectoPascal());
115 if (basic
.pressure_altitude_available
)
116 printf("PressureAltitude=%d\n", (int)basic
.pressure_altitude
);
118 if (basic
.baro_altitude_available
)
119 printf("BaroAltitude=%d\n", (int)basic
.baro_altitude
);
121 if (basic
.total_energy_vario_available
)
122 printf("TotalEnergyVario=%.1f\n", (double)basic
.total_energy_vario
);
124 if (basic
.netto_vario_available
)
125 printf("NettoVario=%.1f\n", (double)basic
.netto_vario
);
127 if (basic
.external_wind_available
)
128 printf("Wind=%d/%d\n",
129 (int)basic
.external_wind
.bearing
.Degrees(),
130 (int)basic
.external_wind
.norm
);
132 if (basic
.temperature_available
)
133 printf("OutsideAirTemperature=%d\n", (int)basic
.temperature
);
135 if (basic
.humidity_available
)
136 printf("RelativeHumidity=%d\n", (int)basic
.humidity
);
138 const DeviceInfo
&device
= basic
.device
;
139 if (!device
.product
.empty())
140 printf("Device.Product=%s\n", device
.product
.c_str());
141 if (!device
.serial
.empty())
142 printf("Device.Serial=%s\n", device
.serial
.c_str());
143 if (!device
.hardware_version
.empty())
144 printf("Device.HardwareVersion=%s\n", device
.hardware_version
.c_str());
145 if (!device
.software_version
.empty())
146 printf("Device.SoftwareVersion=%s\n", device
.software_version
.c_str());
148 const DeviceInfo
&device2
= basic
.secondary_device
;
149 if (!device2
.product
.empty())
150 printf("SecondaryDevice.Product=%s\n", device2
.product
.c_str());
151 if (!device2
.serial
.empty())
152 printf("SecondaryDevice.Serial=%s\n", device2
.serial
.c_str());
153 if (!device2
.hardware_version
.empty())
154 printf("SecondaryDevice.HardwareVersion=%s\n",
155 device2
.hardware_version
.c_str());
156 if (!device2
.software_version
.empty())
157 printf("SecondaryDevice.SoftwareVersion=%s\n",
158 device2
.software_version
.c_str());
160 const FlarmData
&flarm
= basic
.flarm
;
161 if (flarm
.status
.available
) {
162 printf("FLARM rx=%u tx=%u\n", flarm
.status
.rx
, flarm
.status
.tx
);
163 printf("FLARM gps=%u\n", (unsigned)flarm
.status
.gps
);
164 printf("FLARM alarm=%u\n", (unsigned)flarm
.status
.alarm_level
);
165 printf("FLARM traffic=%u\n", flarm
.traffic
.list
.size());
168 if (basic
.engine_noise_level_available
)
169 printf("ENL=%u\n", basic
.engine_noise_level
);
171 if (basic
.voltage_available
)
172 printf("Battery=%fV\n", (double)basic
.voltage
);
174 if (basic
.battery_level_available
)
175 printf("Battery=%f%%\n", (double)basic
.battery_level
);
177 Dump(basic
.settings
);
180 int main(int argc
, char **argv
)
182 NarrowString
<1024> usage
;
184 "Where DRIVER is one of:";
186 const DeviceRegister
*driver
;
187 for (unsigned i
= 0; (driver
= GetDriverByIndex(i
)) != NULL
; ++i
) {
188 WideToUTF8Converter
driver_name(driver
->name
);
189 usage
.AppendFormat("\n\t%s", (const char *)driver_name
);
193 Args
args(argc
, argv
, usage
);
194 tstring driver_name
= args
.ExpectNextT();
197 driver
= FindDriverByName(driver_name
.c_str());
198 if (driver
== NULL
) {
199 _ftprintf(stderr
, _T("No such driver: %s\n"), driver_name
.c_str());
207 Device
*device
= driver
->CreateOnPort
!= NULL
208 ? driver
->CreateOnPort(config
, port
)
217 while (fgets(buffer
, sizeof(buffer
), stdin
) != NULL
) {
220 if (device
== NULL
|| !device
->ParseNMEA(buffer
, data
))
221 parser
.ParseLine(buffer
, data
);