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 "Tracking/SkyLines/Client.hpp"
25 #include "NMEA/Info.hpp"
26 #include "OS/Args.hpp"
27 #include "Util/NumberParser.hpp"
28 #include "Util/StringUtil.hpp"
29 #include "DebugReplay.hpp"
31 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
32 #include "IO/Async/GlobalIOThread.hpp"
34 class Handler
: public SkyLinesTracking::Handler
{
41 Handler():done(false) {}
43 bool Wait(unsigned timeout_ms
=5000) {
44 const ScopeLock
protect(mutex
);
45 return done
|| (cond
.Wait(mutex
, timeout_ms
) && done
);
50 const ScopeLock
protect(mutex
);
56 virtual void OnAck(unsigned id
) override
{
57 printf("received ack %u\n", id
);
61 virtual void OnTraffic(unsigned pilot_id
, unsigned time_of_day_ms
,
62 const GeoPoint
&location
, int altitude
) override
{
63 BrokenTime time
= BrokenTime::FromSecondOfDay(time_of_day_ms
/ 1000);
65 printf("received traffic pilot=%u time=%02u:%02u:%02u location=%f/%f altitude=%d\n",
66 pilot_id
, time
.hour
, time
.minute
, time
.second
,
67 (double)location
.longitude
.Degrees(),
68 (double)location
.latitude
.Degrees(),
77 main(int argc
, char *argv
[])
79 Args
args(argc
, argv
, "HOST KEY");
80 const char *host
= args
.ExpectNext();
81 const char *key
= args
.ExpectNext();
83 SocketAddress address
;
84 if (!address
.Lookup(host
, "5597", SOCK_DGRAM
)) {
85 fprintf(stderr
, "Failed to look up: %s\n", host
);
89 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
93 SkyLinesTracking::Client client
;
95 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
96 client
.SetIOThread(io_thread
);
99 client
.SetHandler(&handler
);
102 client
.SetKey(ParseUint64(key
, NULL
, 16));
103 if (!client
.Open(address
)) {
104 fprintf(stderr
, "Failed to create client\n");
108 if (args
.IsEmpty() || StringIsEqual(args
.PeekNext(), "fix")) {
112 basic
.time
= fixed(1);
113 basic
.time_available
.Update(basic
.clock
);
115 return client
.SendFix(basic
) ? EXIT_SUCCESS
: EXIT_FAILURE
;
116 } else if (StringIsEqual(args
.PeekNext(), "ping")) {
119 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
122 } else if (StringIsEqual(args
.PeekNext(), "traffic")) {
123 client
.SendTrafficRequest(true, true);
125 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
129 DebugReplay
*replay
= CreateDebugReplay(args
);
133 while (replay
->Next()) {
134 client
.SendFix(replay
->Basic());
139 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
141 DeinitialiseIOThread();