Skip to content

Commit

Permalink
Add Types to handle download failed message from Meadow. (#277)
Browse files Browse the repository at this point in the history
* Add Types to handle download failed message from Meadow.

* Added Redownload logic
  • Loading branch information
CartBlanche committed Jul 17, 2023
1 parent 92bcd04 commit c03ff6e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Meadow.CLI.Core/Devices/MeadowLocalDevice.Comms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public partial class MeadowLocalDevice
private const int PROGESS_INCREMENTS = 5;
uint _packetCrc32;
private readonly SemaphoreSlim _comPortSemaphore = new SemaphoreSlim(1, 1);
bool reUploadSkippedFiles = false;
byte reUploadCounter = 0;

public async Task SendTheEntireFile(FileCommand command,
bool lastInSeries,
Expand Down Expand Up @@ -364,6 +366,10 @@ void ResponseHandler(object s, MeadowMessageEventArgs e)
Logger?.LogError(msg);
}
break;
case MeadowMessageType.DownloadFailed:
// Set Re-download flag, increment download count.
reUploadSkippedFiles = true;
break;
default:
break;
}
Expand Down
27 changes: 26 additions & 1 deletion Meadow.CLI.Core/Devices/MeadowLocalDevice.FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,32 @@ await WriteFile(
cancellationToken);
}

Logger.LogInformation($"{Environment.NewLine}{fi.Name} deploy complete!{Environment.NewLine}");
if (reUploadSkippedFiles)
{
reUploadCounter++;
if (reUploadCounter < 3)
{
await DeployApp(applicationFilePath,
osVersion,
includePdbs,
verbose,
noLink,
cancellationToken);
}
else
{
// Clean up the reload variables.
reUploadSkippedFiles = false;
reUploadCounter = 0;

// Let's bail out of here
throw new Exception("Tried to send files to Meadow at least 3 times and failed. Something it seriously wrong! Check you are running the latest OS etc.");
}
}
else
{
Logger.LogInformation($"{Environment.NewLine}{fi.Name} deploy complete!{Environment.NewLine}");
}
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum MeadowMessageType
Concluded,
DownloadStartOkay,
DownloadStartFail,
DownloadFailed,
DevicePublicKey
}

Expand Down Expand Up @@ -364,6 +365,11 @@ private void ParseAndProcessReceivedPacket(byte[] receivedMsg, CancellationToken

break;
}

case HcomHostRequestType.HCOM_HOST_REQUEST_DNLD_FAIL_RESEND:
OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.DownloadFailed, responseString));
break;

case HcomHostRequestType.HCOM_HOST_REQUEST_DEVICE_PUBLIC_KEY:
OnReceiveData?.Invoke(this, new MeadowMessageEventArgs(MeadowMessageType.DevicePublicKey, responseString));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public ReceiveMessageFactoryManager(ILogger logger)
{HcomHostRequestType.HCOM_HOST_REQUEST_TEXT_MONO_STDERR, new ReceiveSimpleTextFactory() },
{HcomHostRequestType.HCOM_HOST_REQUEST_FILE_START_OKAY, new ReceiveSimpleTextFactory() },
{HcomHostRequestType.HCOM_HOST_REQUEST_FILE_START_FAIL, new ReceiveSimpleTextFactory() },
{HcomHostRequestType.HCOM_HOST_REQUEST_DNLD_FAIL_RESEND, new ReceiveSimpleTextFactory()},
{HcomHostRequestType.HCOM_HOST_REQUEST_DEVICE_PUBLIC_KEY, new ReceiveSimpleTextFactory()},
};
}
Expand Down
4 changes: 4 additions & 0 deletions Meadow.Hcom/HcomHostRequestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public enum HcomHostRequestType : ushort
HCOM_HOST_REQUEST_TEXT_MONO_STDERR = 0x0d | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE_TEXT,
HCOM_HOST_REQUEST_FILE_START_OKAY = 0x0e | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE_TEXT,
HCOM_HOST_REQUEST_FILE_START_FAIL = 0x0f | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE_TEXT,

// The Meadow file name is enclosed in single quotes 'filename' and CLI will
// need to workout what file was being downloaded and start the download over
HCOM_HOST_REQUEST_DNLD_FAIL_RESEND = 0x12 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE_TEXT,
HCOM_HOST_REQUEST_DEVICE_PUBLIC_KEY = 0x13 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE_TEXT,

// Simple with debugger message from Meadow
Expand Down

0 comments on commit c03ff6e

Please sign in to comment.