Skip to content

Commit

Permalink
MAVFtp: rerequest where duplicating data.
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Aug 13, 2024
1 parent 2c5d900 commit ea5567a
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions ExtLibs/ArduPilot/Mavlink/MAVFtp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public MemoryStream kCmdBurstReadFile(string file, int size, CancellationTokenSo
// we have lost data
if (answer.Position != ftphead.offset)
{
log.Info($"lost data {file} at rx {ftphead.offset} vs ms {answer.Position}");
}
// got a valid segment, so reset retrys
Expand All @@ -792,17 +792,19 @@ public MemoryStream kCmdBurstReadFile(string file, int size, CancellationTokenSo
chunkSortedList[ftphead.offset] = ftphead.offset + ftphead.size;
SimplifyChunkList(chunkSortedList);
var currentsize = chunkSortedList.Sum(a => a.Value - a.Key);
log.Info($"got data {file} at {ftphead.offset} got {currentsize} of {size}");
//log.Info($"got data {file} at {ftphead.offset} got {currentsize} of {size}");
answer.Seek(ftphead.offset, SeekOrigin.Begin);
answer.Write(ftphead.data, 0, ftphead.size);
timeout.ResetTimeout();
//log.Debug(ftphead);
seq_no = (ushort)(ftphead.seq_number + 1);
// if rerequest needed
payload.offset = ftphead.offset + ftphead.size;
// dont move backwards
payload.offset = Math.Max(ftphead.offset + ftphead.size, payload.offset);
payload.seq_number = seq_no;
fileTransferProtocol.payload = payload;
// ignore the burst read first response
Expand Down Expand Up @@ -860,6 +862,29 @@ public MemoryStream kCmdBurstReadFile(string file, int size, CancellationTokenSo
return answer;
}

private void SimplifyChunkList(SortedList<uint, uint> chunkSortedList)
{
// join any overlapping chunks
for (int i = 0; i < chunkSortedList.Count - 1; i++)
{
var chunk = chunkSortedList.ElementAt(i);
var nextchunk = chunkSortedList.ElementAt(i + 1);
// next chunk is after this one
if (chunk.Value >= nextchunk.Key)
{
chunkSortedList[chunk.Key] = nextchunk.Value;
chunkSortedList.RemoveAt(i + 1);
i--;
}
// next chunk is inside this one
else if (nextchunk.Key >= chunk.Key && nextchunk.Value <= chunk.Value)
{
chunkSortedList.RemoveAt(i + 1);
i--;
}
}
}

private uint FindMissing(SortedList<uint, uint> chunkSortedList)
{
var currentpoint = 0u;
Expand Down

0 comments on commit ea5567a

Please sign in to comment.