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 "DebugReplay.hpp"
25 #include "IO/TextWriter.hpp"
26 #include "NMEA/Checksum.hpp"
27 #include "Units/System.hpp"
28 #include "OS/Args.hpp"
33 GenerateNMEA(TextWriter
&writer
,
34 const GeoPoint
&loc
, const fixed speed
,
35 const Angle bearing
, const fixed alt
,
36 const fixed baroalt
, const fixed t
)
38 unsigned time
= (unsigned)t
;
39 unsigned hour
= time
/ 3600;
41 unsigned minute
= time
/ 60;
43 unsigned second
= time
;
45 unsigned lat_d
, lat_m
, lat_s
;
47 loc
.latitude
.ToDMS(lat_d
, lat_m
, lat_s
, lat_sign
);
48 double lat_ms
= lat_m
+ lat_s
/ 60.;
50 unsigned lon_d
, lon_m
, lon_s
;
52 loc
.longitude
.ToDMS(lon_d
, lon_m
, lon_s
, lon_sign
);
53 double lon_ms
= lon_m
+ lon_s
/ 60.;
55 NarrowString
<256> gprmc("$GPRMC");
56 gprmc
.AppendFormat(",%02d%02d%02d", hour
, minute
, second
);
58 gprmc
.AppendFormat(",%02d%06.3f", lat_d
, lat_ms
);
59 gprmc
.append(lat_sign
? ",N" : ",S");
60 gprmc
.AppendFormat(",%03d%06.3f", lon_d
, lon_ms
);
61 gprmc
.append(lon_sign
? ",E" : ",W");
62 gprmc
.AppendFormat(",%.0f", (double)Units::ToUserUnit(speed
, Unit::KNOTS
));
63 gprmc
.AppendFormat(",%.0f", (double)bearing
.Degrees());
64 AppendNMEAChecksum(gprmc
.buffer());
66 writer
.WriteLine(gprmc
);
67 printf("%s\n", gprmc
.c_str());
69 NarrowString
<256> gpgga("$GPGGA");
70 gpgga
.AppendFormat(",%02d%02d%02d", hour
, minute
, second
);
71 gpgga
.AppendFormat(",%02d%06.3f", lat_d
, lat_ms
);
72 gpgga
.append(lat_sign
? ",N" : ",S");
73 gpgga
.AppendFormat(",%03d%06.3f", lon_d
, lon_ms
);
74 gpgga
.append(lon_sign
? ",E" : ",W");
76 gpgga
.AppendFormat(",%.0f,m", (double)alt
);
77 AppendNMEAChecksum(gpgga
.buffer());
79 writer
.WriteLine(gpgga
);
80 printf("%s\n", gpgga
.c_str());
82 NarrowString
<256> pgrmz("$PGRMZ");
83 pgrmz
.AppendFormat(",%.0f,m", (double)baroalt
);
84 AppendNMEAChecksum(pgrmz
.buffer());
86 writer
.WriteLine(pgrmz
);
87 printf("%s\n", pgrmz
.c_str());
91 main(int argc
, char **argv
)
93 Args
args(argc
, argv
, "INFILE.igc OUTFILE.nmea");
94 DebugReplay
*replay
= CreateDebugReplay(args
);
98 const char *output_file
= args
.ExpectNext();
101 TextWriter
writer(output_file
);
102 if (!writer
.IsOpen()) {
103 fprintf(stderr
, "Failed to create output file\n");
107 while (replay
->Next()) {
108 const NMEAInfo
&basic
= replay
->Basic();
109 GenerateNMEA(writer
, basic
.location
,
110 basic
.ground_speed
, basic
.track
, basic
.gps_altitude
,
111 basic
.baro_altitude
, basic
.time
);