Commit 3565bfe3 authored by Nate Weibley's avatar Nate Weibley Committed by Nate Weibley

Switch to hash table for gaps and reposition the file when starting to fill a new segment

parent 8e97b8f5
...@@ -282,16 +282,7 @@ LogDownloadController::_logData(UASInterface* uas, uint32_t ofs, uint16_t id, ui ...@@ -282,16 +282,7 @@ LogDownloadController::_logData(UASInterface* uas, uint32_t ofs, uint16_t id, ui
// Check for a gap // Check for a gap
qint64 pos = _downloadData->file.pos(); qint64 pos = _downloadData->file.pos();
if (pos != ofs) { if (pos != ofs) {
// Check for a gap collision if (pos < ofs) {
if (_downloadData->gaps.contains(ofs)) {
// The gap is being filled. Shrink it
const int32_t gap = _downloadData->gaps.take(ofs) - count;
if (gap > 0) {
_downloadData->gaps[ofs+count] = qMax(static_cast<uint32_t>(gap), _downloadData->gaps.value(ofs+count, 0));
} else {
timeout_time = 20;
}
} else if (pos < ofs) {
// Mind the gap // Mind the gap
uint32_t gap = ofs - pos; uint32_t gap = ofs - pos;
_downloadData->gaps[pos] = gap; _downloadData->gaps[pos] = gap;
...@@ -304,6 +295,17 @@ LogDownloadController::_logData(UASInterface* uas, uint32_t ofs, uint16_t id, ui ...@@ -304,6 +295,17 @@ LogDownloadController::_logData(UASInterface* uas, uint32_t ofs, uint16_t id, ui
} }
} }
// Check for a gap collision
if (_downloadData->gaps.contains(ofs)) {
// The gap is being filled. Shrink it
const int32_t gap = _downloadData->gaps.take(ofs) - count;
if (gap > 0) {
_downloadData->gaps[ofs+count] = qMax(static_cast<uint32_t>(gap), _downloadData->gaps.value(ofs+count, 0));
} else {
timeout_time = 20;
}
}
//-- Write chunk to file //-- Write chunk to file
if(_downloadData->file.write((const char*)data, count)) { if(_downloadData->file.write((const char*)data, count)) {
_downloadData->written += count; _downloadData->written += count;
...@@ -378,9 +380,12 @@ LogDownloadController::_findMissingData() ...@@ -378,9 +380,12 @@ LogDownloadController::_findMissingData()
const qint64 pos = _downloadData->file.pos(), const qint64 pos = _downloadData->file.pos(),
size = _downloadData->entry->size(); size = _downloadData->entry->size();
if (!_downloadData->gaps.isEmpty()) { if (!_downloadData->gaps.isEmpty()) {
const uint32_t start = _downloadData->gaps.firstKey(); auto keys = _downloadData->gaps.keys();
qSort(keys);
const uint32_t start = keys.first();
const uint32_t count = _downloadData->gaps.value(start); const uint32_t count = _downloadData->gaps.value(start);
_downloadData->file.seek(start);
//-- Request these log chunks again //-- Request these log chunks again
_requestLogData(_downloadData->ID, start, count); _requestLogData(_downloadData->ID, start, count);
} else if (pos != size) { } else if (pos != size) {
......
...@@ -125,13 +125,13 @@ private: ...@@ -125,13 +125,13 @@ private:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
struct LogDownloadData { struct LogDownloadData {
LogDownloadData(QGCLogEntry* entry); LogDownloadData(QGCLogEntry* entry);
QMap<uint32_t, uint32_t> gaps; QHash<uint32_t, uint32_t> gaps;
QFile file; QFile file;
QString filename; QString filename;
uint ID; uint ID;
QGCLogEntry* entry; QGCLogEntry* entry;
uint written; uint written;
QElapsedTimer elapsed; QElapsedTimer elapsed;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment