diff --git a/Meadow.CLI.Core/Devices/MeadowLocalDevice.Comms.cs b/Meadow.CLI.Core/Devices/MeadowLocalDevice.Comms.cs index 98eedeb0..34a79bd2 100644 --- a/Meadow.CLI.Core/Devices/MeadowLocalDevice.Comms.cs +++ b/Meadow.CLI.Core/Devices/MeadowLocalDevice.Comms.cs @@ -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, @@ -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; } diff --git a/Meadow.CLI.Core/Devices/MeadowLocalDevice.FileManager.cs b/Meadow.CLI.Core/Devices/MeadowLocalDevice.FileManager.cs index effa7455..7debc9b2 100644 --- a/Meadow.CLI.Core/Devices/MeadowLocalDevice.FileManager.cs +++ b/Meadow.CLI.Core/Devices/MeadowLocalDevice.FileManager.cs @@ -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) { diff --git a/Meadow.CLI.Core/Internals/MeadowCommunication/MeadowSerialDataProcessor.cs b/Meadow.CLI.Core/Internals/MeadowCommunication/MeadowSerialDataProcessor.cs index 40db55a9..38075904 100644 --- a/Meadow.CLI.Core/Internals/MeadowCommunication/MeadowSerialDataProcessor.cs +++ b/Meadow.CLI.Core/Internals/MeadowCommunication/MeadowSerialDataProcessor.cs @@ -33,6 +33,7 @@ public enum MeadowMessageType Concluded, DownloadStartOkay, DownloadStartFail, + DownloadFailed, DevicePublicKey } @@ -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; diff --git a/Meadow.CLI.Core/Internals/MeadowCommunication/ReceiveClasses/ReceiveMessageFactoryManager.cs b/Meadow.CLI.Core/Internals/MeadowCommunication/ReceiveClasses/ReceiveMessageFactoryManager.cs index 38b3ca29..86dd1ec4 100644 --- a/Meadow.CLI.Core/Internals/MeadowCommunication/ReceiveClasses/ReceiveMessageFactoryManager.cs +++ b/Meadow.CLI.Core/Internals/MeadowCommunication/ReceiveClasses/ReceiveMessageFactoryManager.cs @@ -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()}, }; } diff --git a/Meadow.Hcom/HcomHostRequestType.cs b/Meadow.Hcom/HcomHostRequestType.cs index 906e5b4b..fec2a5bd 100644 --- a/Meadow.Hcom/HcomHostRequestType.cs +++ b/Meadow.Hcom/HcomHostRequestType.cs @@ -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