4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2012 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 "TrackingGlue.hpp"
25 #include "NMEA/Info.hpp"
26 #include "NMEA/Derived.hpp"
27 #include "Units/System.hpp"
29 TrackingGlue::TrackingGlue()
31 settings
.SetDefaults();
32 LiveTrack24::SetServer(settings
.livetrack24
.server
);
36 TrackingGlue::StopAsync()
38 ScopeLock
protect(mutex
);
39 StandbyThread::StopAsync();
43 TrackingGlue::WaitStopped()
45 ScopeLock
protect(mutex
);
46 StandbyThread::WaitStopped();
50 TrackingGlue::SetSettings(const TrackingSettings
&_settings
)
52 ScopeLock
protect(mutex
);
54 if (_settings
.livetrack24
.server
!= settings
.livetrack24
.server
) {
56 LiveTrack24::SetServer(_settings
.livetrack24
.server
);
59 if (_settings
.livetrack24
.username
!= settings
.livetrack24
.username
||
60 _settings
.livetrack24
.password
!= settings
.livetrack24
.password
)
67 TrackingGlue::OnTimer(const NMEAInfo
&basic
, const DerivedInfo
&calculated
)
69 if (!settings
.livetrack24
.enabled
)
70 /* disabled by configuration */
71 /* note that we are allowed to read "settings" without locking the
72 mutex, because the background thread never writes to this
76 if (!basic
.time_available
|| !basic
.location_available
)
77 /* can't track without a valid GPS fix */
80 if (!clock
.CheckUpdate(settings
.interval
* 1000))
84 ScopeLock
protect(mutex
);
86 /* still running, skip this submission */
89 date_time
= basic
.date_time_utc
;
90 if (!basic
.date_available
)
91 /* use "today" if the GPS didn't provide a date */
92 (BrokenDate
&)date_time
= (BrokenDate
)BrokenDateTime::NowUTC();
94 location
= basic
.location
;
95 /* XXX use nav_altitude? */
96 altitude
= basic
.gps_altitude_available
&& positive(basic
.gps_altitude
)
97 ? (unsigned)basic
.gps_altitude
99 ground_speed
= basic
.ground_speed_available
100 ? (unsigned)Units::ToUserUnit(basic
.ground_speed
, Unit::KILOMETER_PER_HOUR
)
102 track
= basic
.track_available
106 flying
= calculated
.flight
.flying
;
114 if (!settings
.livetrack24
.enabled
)
115 /* settings have been cleared meanwhile, bail out */
118 unsigned tracking_interval
= settings
.interval
;
119 LiveTrack24Settings copy
= this->settings
.livetrack24
;
123 if (!state
.HasSession()) {
124 LiveTrack24::UserID user_id
= 0;
125 if (!copy
.username
.empty() && !copy
.password
.empty())
126 user_id
= LiveTrack24::GetUserID(copy
.username
, copy
.password
);
129 copy
.username
.clear();
130 copy
.password
.clear();
131 state
.session_id
= LiveTrack24::GenerateSessionID();
133 state
.session_id
= LiveTrack24::GenerateSessionID(user_id
);
136 if (!LiveTrack24::StartTracking(state
.session_id
, copy
.username
,
137 copy
.password
, tracking_interval
,
138 LiveTrack24::VehicleType::GLIDER
)) {
139 state
.ResetSession();
147 LiveTrack24::SendPosition(state
.session_id
, state
.packet_id
++,
148 location
, altitude
, ground_speed
, track
,
149 date_time
.ToUnixTimeUTC());