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 "Internal.hpp"
25 #include "Protocol.hpp"
26 #include "Device/Port/Port.hpp"
27 #include "Operation/Operation.hpp"
34 * Sizes of VL memory regions
36 static constexpr size_t VLAPI_LOG_MEMSIZE
= 81920L;
39 ParseDate(const tm
&time
,BrokenDate
&date
)
41 date
.year
= time
.tm_year
+ 1900;
42 date
.month
= time
.tm_mon
+ 1;
43 date
.day
= time
.tm_mday
;
45 return date
.Plausible();
49 ParseTime(const tm
&time
,BrokenTime
&btime
)
51 btime
.hour
= time
.tm_hour
;
52 btime
.minute
= time
.tm_min
;
53 btime
.second
= time
.tm_sec
;
55 return btime
.Plausible();
59 ConvertDirectoryToRecordedFlightList(const std::vector
<DIRENTRY
> &dir
,
60 RecordedFlightList
&flight_list
)
62 RecordedFlightInfo flight_info
;
63 for (unsigned i
=0; (i
< dir
.size()) && !flight_list
.full(); i
++) {
64 const DIRENTRY
&flight
= dir
[i
];
66 * Only show logs with a takeoff detected
68 if (flight
.takeoff
== 1) {
69 if (!ParseDate(flight
.firsttime
, flight_info
.date
) ||
70 !ParseTime(flight
.firsttime
, flight_info
.start_time
) ||
71 !ParseTime(flight
.lasttime
, flight_info
.end_time
) )
73 flight_info
.internal
.volkslogger
= i
;
74 flight_list
.append(flight_info
);
81 ReadFlightListInner(Port
&port
,
82 RecordedFlightList
&flight_list
,
83 OperationEnvironment
&env
)
85 env
.SetProgressRange(10);
86 if (!Volkslogger::ConnectAndFlush(port
, env
, 20000))
88 env
.SetProgressPosition(3);
90 uint8_t dirbuffer
[VLAPI_LOG_MEMSIZE
];
91 int data_length
= Volkslogger::ReadFlightList(port
, env
,
92 dirbuffer
, sizeof(dirbuffer
));
94 return data_length
== 0;
96 std::vector
<DIRENTRY
> directory
;
97 if (!conv_dir(directory
, dirbuffer
, data_length
))
100 if (directory
.empty())
103 env
.SetProgressPosition(8);
104 if (!ConvertDirectoryToRecordedFlightList(directory
, flight_list
))
106 env
.SetProgressPosition(10);
112 DownloadFlightInner(Port
&port
, unsigned bulkrate
,
113 const RecordedFlightInfo
&flight
,
115 OperationEnvironment
&env
)
117 if (!Volkslogger::ConnectAndFlush(port
, env
, 20000))
120 uint8_t logbuffer
[VLAPI_LOG_MEMSIZE
];
121 const size_t length
= Volkslogger::ReadFlight(port
, bulkrate
, env
,
122 flight
.internal
.volkslogger
,
124 logbuffer
, sizeof(logbuffer
));
128 FILE *outfile
= _tfopen(path
, _T("wt"));
129 if (outfile
== nullptr)
132 size_t r
= convert_gcs(0, outfile
, logbuffer
, length
, true);
138 print_g_record(outfile
, // output to stdout
139 logbuffer
, // binary file is in buffer
140 r
// length of binary file to include
146 VolksloggerDevice::ReadFlightList(RecordedFlightList
&flight_list
,
147 OperationEnvironment
&env
)
151 // change to IO mode baud rate
152 unsigned old_baud_rate
= port
.GetBaudrate();
153 if (old_baud_rate
== 9600)
155 else if (old_baud_rate
!= 0 && !port
.SetBaudrate(9600))
158 bool success
= ReadFlightListInner(port
, flight_list
, env
);
161 if (old_baud_rate
!= 0)
162 port
.SetBaudrate(old_baud_rate
);
168 VolksloggerDevice::DownloadFlight(const RecordedFlightInfo
&flight
,
170 OperationEnvironment
&env
)
174 // change to IO mode baud rate
175 unsigned old_baud_rate
= port
.GetBaudrate();
176 if (old_baud_rate
== 9600)
178 else if (old_baud_rate
!= 0 && !port
.SetBaudrate(9600))
181 bool success
= DownloadFlightInner(port
, bulkrate
,
184 if (old_baud_rate
!= 0)
185 port
.SetBaudrate(old_baud_rate
);