From dd724f118f584eea84a11af90292a88c62ecd022 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 29 Nov 2018 18:59:41 +0200 Subject: Working on Firmware upgrade ! --- .../ViewModels/FirmwareUpgradeViewVM.cs | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs new file mode 100644 index 000000000..ce8b09aa4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -0,0 +1,100 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Integration.Operation; +using Tango.SharedUI; + +namespace Tango.MachineStudio.UI.ViewModels +{ + public class FirmwareUpgradeViewVM : DialogViewVM + { + private IMachineOperator _operator; + private FileStream _stream; + + private FirmwareUpgradeHandler _handler; + public FirmwareUpgradeHandler Handler + { + get { return _handler; } + set { _handler = value; RaisePropertyChangedAuto(); } + } + + private String _selectedFile; + public String SelectedFile + { + get { return _selectedFile; } + set { _selectedFile = value; RaisePropertyChangedAuto(); } + } + + private int _currentPage; + public int CurrentPage + { + get { return _currentPage; } + set { _currentPage = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand SelectCommand { get; set; } + + public RelayCommand UpgradeCommand { get; set; } + + public RelayCommand AbortCommand { get; set; } + + public FirmwareUpgradeViewVM(IMachineOperator machineOperator) : base() + { + _operator = machineOperator; + SelectCommand = new RelayCommand(BrowseForFile); + UpgradeCommand = new RelayCommand(StartUpgrade, () => SelectedFile != null); + AbortCommand = new RelayCommand(AbortUpgrade, () => Handler != null && Handler.Status != FirmwareUpgradeStatus.Validating && Handler.Status != FirmwareUpgradeStatus.Activating); + } + + private void BrowseForFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select tango firmware package file"; + dlg.Filter = "Tango Firmware Package|*.tfp"; + if (dlg.ShowDialog().Value) + { + SelectedFile = dlg.FileName; + InvalidateRelayCommands(); + } + } + + private async void StartUpgrade() + { + CurrentPage = 1; + + _stream = new FileStream(SelectedFile, FileMode.Open); + Handler = await _operator.UpgradeFirmware(_stream); + Handler.Progress += (_, e) => + { + InvokeUI(() => + { + AbortCommand.RaiseCanExecuteChanged(); + }); + }; + Handler.Completed += (_, __) => + { + _stream.Dispose(); + CurrentPage = 2; + }; + Handler.Canceled += (_, __) => + { + _stream.Dispose(); + }; + Handler.Failed += (_, __) => + { + _stream.Dispose(); + }; + + } + + private async void AbortUpgrade() + { + await Handler.Cancel(); + } + } +} -- cgit v1.3.1 From a2d959a7777bf2387d0f50dbc1ecf69f53e2253d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 2 Dec 2018 16:37:25 +0200 Subject: Implemented machine studio storage module. firmware upgrade version/validate/activate. Implemented firmware package generator utility. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 20578304 -> 20578304 bytes .../PMR/Messages/IO/ActivateVersionRequest.proto | 4 +- .../PMR/Messages/IO/ValidateVersionRequest.proto | 4 +- .../PMR/Messages/IO/VersionPackageDescriptor.proto | 11 + .../ViewModels/MainViewVM.cs | 38 +++ .../Views/MainView.xaml | 4 +- .../FirmwareUpgrade/IFirmwareUpgrader.cs | 1 + .../FirmwareUpgrade/DefaultFirmwareUpgrader.cs | 5 +- .../Tango.MachineStudio.UI.csproj | 2 +- .../ViewModels/FirmwareUpgradeViewVM.cs | 87 +++++-- .../Views/FirmwareUpgradeView.xaml | 15 +- .../ExtensionMethods/ExceptionExtensions.cs | 21 ++ .../ExtensionMethods/ObjectExtensions.cs | 1 + .../Tango.Core/Json/ProtobufContractResolver.cs | 24 ++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 3 +- .../Tango.Emulations/Emulators/MachineEmulator.cs | 45 +++- .../Operation/FirmwareUpgradeHandler.cs | 94 ------- .../Operation/FirmwareUpgradeProgressEventArgs.cs | 15 -- .../Operation/FirmwareUpgradeStatus.cs | 37 --- .../Operation/IMachineOperator.cs | 21 ++ .../Tango.Integration/Operation/MachineOperator.cs | 276 ++++++++++----------- .../Tango.Integration/Storage/StorageManager.cs | 1 + .../Tango.Integration/Tango.Integration.csproj | 6 +- .../Upgrade/FirmwareUpgradeHandler.cs | 108 ++++++++ .../Upgrade/FirmwareUpgradeProgressEventArgs.cs | 16 ++ .../Upgrade/FirmwareUpgradeStatus.cs | 31 +++ .../Tango.PMR/IO/ActivateVersionRequest.cs | 48 ++-- .../Tango.PMR/IO/ValidateVersionRequest.cs | 48 ++-- .../Tango.PMR/IO/VersionPackageDescriptor.cs | 153 ++++++++++++ Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj | 3 +- .../Tango.Transport/TransporterBase.cs | 29 ++- Software/Visual_Studio/Tango.sln | 55 +++- .../Tango.FirmwarePackageGenerator/App.config | 50 ++++ .../Tango.FirmwarePackageGenerator/App.xaml | 25 ++ .../Tango.FirmwarePackageGenerator/App.xaml.cs | 17 ++ .../Images/firmware_upgrade.png | Bin 0 -> 52803 bytes .../Tango.FirmwarePackageGenerator/MainWindow.xaml | 41 +++ .../MainWindow.xaml.cs | 43 ++++ .../Tango.FirmwarePackageGenerator/MainWindowVM.cs | 103 ++++++++ .../Properties/AssemblyInfo.cs | 7 + .../Properties/Resources.Designer.cs | 71 ++++++ .../Properties/Resources.resx | 117 +++++++++ .../Properties/Settings.Designer.cs | 30 +++ .../Properties/Settings.settings | 7 + .../Tango.FirmwarePackageGenerator.csproj | 134 ++++++++++ .../VersionFileModel.cs | 44 ++++ .../Tango.FirmwarePackageGenerator/packages.config | 6 + 48 files changed, 1508 insertions(+), 393 deletions(-) create mode 100644 Software/PMR/Messages/IO/VersionPackageDescriptor.proto create mode 100644 Software/Visual_Studio/Tango.Core/Json/ProtobufContractResolver.cs delete mode 100644 Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeHandler.cs delete mode 100644 Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeProgressEventArgs.cs delete mode 100644 Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeStatus.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeHandler.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeProgressEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs create mode 100644 Software/Visual_Studio/Tango.PMR/IO/VersionPackageDescriptor.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.config create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Images/firmware_upgrade.png create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindowVM.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.resx create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.settings create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Tango.FirmwarePackageGenerator.csproj create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/VersionFileModel.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/packages.config (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 355832ca0..ff9e90053 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index e4f508570..07da3d430 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/PMR/Messages/IO/ActivateVersionRequest.proto b/Software/PMR/Messages/IO/ActivateVersionRequest.proto index cc82e673c..6b6579197 100644 --- a/Software/PMR/Messages/IO/ActivateVersionRequest.proto +++ b/Software/PMR/Messages/IO/ActivateVersionRequest.proto @@ -1,11 +1,9 @@ syntax = "proto3"; -import "VersionFileDescriptor.proto"; - package Tango.PMR.IO; option java_package = "com.twine.tango.pmr.io"; message ActivateVersionRequest { - repeated VersionFileDescriptor FileDescriptors = 1; + string Path = 1; } \ No newline at end of file diff --git a/Software/PMR/Messages/IO/ValidateVersionRequest.proto b/Software/PMR/Messages/IO/ValidateVersionRequest.proto index 7a0c080ec..9bc2ff0d5 100644 --- a/Software/PMR/Messages/IO/ValidateVersionRequest.proto +++ b/Software/PMR/Messages/IO/ValidateVersionRequest.proto @@ -1,11 +1,9 @@ syntax = "proto3"; -import "VersionFileDescriptor.proto"; - package Tango.PMR.IO; option java_package = "com.twine.tango.pmr.io"; message ValidateVersionRequest { - repeated VersionFileDescriptor FileDescriptors = 1; + string Path = 1; } \ No newline at end of file diff --git a/Software/PMR/Messages/IO/VersionPackageDescriptor.proto b/Software/PMR/Messages/IO/VersionPackageDescriptor.proto new file mode 100644 index 000000000..1b67b8062 --- /dev/null +++ b/Software/PMR/Messages/IO/VersionPackageDescriptor.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +import "VersionFileDescriptor.proto"; + +package Tango.PMR.IO; +option java_package = "com.twine.tango.pmr.io"; + +message VersionPackageDescriptor +{ + repeated VersionFileDescriptor FileDescriptors = 1; +} \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs index a9cfed937..4db48c636 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs @@ -75,6 +75,10 @@ namespace Tango.MachineStudio.Storage.ViewModels public RelayCommand UploadVersionCommand { get; set; } + public RelayCommand ValidateVersionCommand { get; set; } + + public RelayCommand ActivateVersionCommand { get; set; } + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IFirmwareUpgrader firmwareUpgrader) { _applicationManager = applicationManager; @@ -96,6 +100,8 @@ namespace Tango.MachineStudio.Storage.ViewModels DeleteFolderCommand = new RelayCommand(DeleteFolder, () => StorageManager != null && SelectedStorageItem != null && SelectedStorageItem is StorageFolder); UploadFileCommand = new RelayCommand(UploadFile, () => StorageManager != null && StorageManager.CurrentFolder != null); UploadVersionCommand = new RelayCommand(UploadVersion, () => StorageManager != null && StorageManager.CurrentFolder != null); + ValidateVersionCommand = new RelayCommand(ValidateVersion, () => StorageManager != null && StorageManager.CurrentFolder != null); + ActivateVersionCommand = new RelayCommand(ActivateVersion, () => StorageManager != null && StorageManager.CurrentFolder != null); } private void UploadFile() @@ -362,5 +368,37 @@ namespace Tango.MachineStudio.Storage.ViewModels { _firmwareUpgrader.InvokeUpgradeUI(); } + + private async void ValidateVersion() + { + using (_notification.PushTaskItem("Validating firmware version...")) + { + try + { + await _applicationManager.ConnectedMachine.ValidateFirmwareVersion(StorageManager.CurrentPath); + _notification.ShowInfo($"Version validated successfully!"); + } + catch (Exception ex) + { + _notification.ShowError($"Error validating firmware version.\n{ex.FlattenMessage()}"); + } + } + } + + private async void ActivateVersion() + { + using (_notification.PushTaskItem("Activating firmware version...")) + { + try + { + await _applicationManager.ConnectedMachine.ActivateFirmwareVersion(StorageManager.CurrentPath); + _notification.ShowInfo($"Version activated successfully!"); + } + catch (Exception ex) + { + _notification.ShowError($"Error activating firmware version.\n{ex.FlattenMessage()}"); + } + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml index 1f435b696..e59837d49 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml @@ -68,13 +68,13 @@ UPGRADE VERSION - - @@ -67,7 +67,7 @@ Upgrading Machine Firmware - + @@ -80,6 +80,15 @@ + + + + Firmware Upgrade Failed + + + + + diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ExceptionExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ExceptionExtensions.cs index fdb041ea9..86434cdc4 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ExceptionExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ExceptionExtensions.cs @@ -29,5 +29,26 @@ public static class ExceptionExtensions return stringBuilder.ToString(); } + + /// + /// Flattens the exception message in case it is an aggregated exception. + /// + /// The exception. + /// + public static String FlattenMessage(this Exception exception) + { + String message = exception.Message; + + if (exception is AggregateException) + { + try + { + message += Environment.NewLine + String.Join(Environment.NewLine, (exception as AggregateException).InnerExceptions.Select(x => x.Message)); + } + catch { } + } + + return message; + } } diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs index cff4e6a3a..0ce3e8369 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs @@ -132,6 +132,7 @@ public static class ObjectExtensions { var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); + settings.ContractResolver = new ProtobufContractResolver(); return settings; }); diff --git a/Software/Visual_Studio/Tango.Core/Json/ProtobufContractResolver.cs b/Software/Visual_Studio/Tango.Core/Json/ProtobufContractResolver.cs new file mode 100644 index 000000000..4921114af --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Json/ProtobufContractResolver.cs @@ -0,0 +1,24 @@ +using Google.Protobuf; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.Json +{ + public class ProtobufContractResolver : DefaultContractResolver + { + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + JsonProperty property = base.CreateProperty(member, memberSerialization); + + property.ShouldSerialize = (x) => property.PropertyType != typeof(ByteString); + + return property; + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 16451aa4e..469a17cd9 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -86,6 +86,7 @@ GlobalVersionInfo.cs + @@ -191,7 +192,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 4a0758a4c..91868d85c 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -27,6 +27,7 @@ using Tango.PMR.Hardware; using System.Runtime.InteropServices; using Tango.PMR.IO; using System.IO; +using Tango.Integration.Operation; namespace Tango.Emulations.Emulators { @@ -44,6 +45,7 @@ namespace Tango.Emulations.Emulators public bool Canceled { get; set; } } + private const int MAX_CHUNK_LENGTH = 1024 * 10; private StartDiagnosticsRequest _diagnosticsRequest; private bool _cancelJob; private List _motorJoggingRequestTypes; @@ -193,7 +195,10 @@ namespace Tango.Emulations.Emulators /// The container. protected override void OnTransporterRequestReceived(object sender, MessageContainer container) { - LogManager.Log(container.Type.ToString().ToWords() + " received." + Environment.NewLine + MessageFactory.ExtractMessageFromContainer(container).ToJsonString()); + if (container.Type != MessageType.FileChunkUploadRequest && container.Type != MessageType.FileChunkDownloadRequest) + { + LogManager.Log(container.Type.ToString().ToWords() + " received." + Environment.NewLine + MessageFactory.ExtractMessageFromContainer(container).ToJsonString()); + } if (PerformNativeRoundTrip) { @@ -1057,7 +1062,7 @@ namespace Tango.Emulations.Emulators Transporter.SendResponse(new FileDownloadResponse() { DownloadID = Guid.NewGuid().ToString(), - MaxChunkLength = Math.Min(1024, length), + MaxChunkLength = Math.Min(MAX_CHUNK_LENGTH, length), }, request.Container.Token, null, File.Exists(request.Message.FileName) ? ErrorCode.None : ErrorCode.FileNotFound); } @@ -1070,7 +1075,7 @@ namespace Tango.Emulations.Emulators using (FileStream fs = new FileStream(message.FileName, FileMode.Open)) { fs.Position = message.Position; - byte[] buffer = new byte[Math.Min(1024, fs.Length - fs.Position)]; + byte[] buffer = new byte[Math.Min(MAX_CHUNK_LENGTH, fs.Length - fs.Position)]; fs.Read(buffer, 0, buffer.Length); Transporter.SendResponse(new FileChunkDownloadResponse() { @@ -1126,7 +1131,7 @@ namespace Tango.Emulations.Emulators var message = request.Message; Transporter.SendResponse(new FileUploadResponse() { - MaxChunkLength = 1024, + MaxChunkLength = MAX_CHUNK_LENGTH, UploadID = Guid.NewGuid().ToString(), }, request.Container.Token); } @@ -1153,10 +1158,23 @@ namespace Tango.Emulations.Emulators private void HandleValidateVersionRequest(TangoMessage request) { - Task.Factory.StartNew(() => + Task.Factory.StartNew(() => { Thread.Sleep(3000); - Transporter.SendResponse(new ValidateVersionResponse(), request.Container.Token); + + try + { + using (FileStream fs = new FileStream(Path.Combine(request.Message.Path, MachineOperator.FIRMWARE_UPGRADE_CONFIG_FILE_NAME), FileMode.Open)) + { + VersionPackageDescriptor package = VersionPackageDescriptor.Parser.ParseFrom(fs); + } + + Transporter.SendResponse(new ValidateVersionResponse(), request.Container.Token); + } + catch (Exception ex) + { + Transporter.SendResponse(new ValidateVersionResponse(), request.Container.Token, null, ErrorCode.GeneralError, ex.Message); + } }); } @@ -1165,7 +1183,20 @@ namespace Tango.Emulations.Emulators Task.Factory.StartNew(() => { Thread.Sleep(3000); - Transporter.SendResponse(new ActivateVersionResponse(), request.Container.Token); + + try + { + using (FileStream fs = new FileStream(Path.Combine(request.Message.Path, MachineOperator.FIRMWARE_UPGRADE_CONFIG_FILE_NAME), FileMode.Open)) + { + VersionPackageDescriptor package = VersionPackageDescriptor.Parser.ParseFrom(fs); + } + + Transporter.SendResponse(new ActivateVersionResponse(), request.Container.Token); + } + catch (Exception ex) + { + Transporter.SendResponse(new ActivateVersionResponse(), request.Container.Token, null, ErrorCode.GeneralError, ex.Message); + } }); } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeHandler.cs b/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeHandler.cs deleted file mode 100644 index f944a2587..000000000 --- a/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeHandler.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; -using Tango.Integration.Storage; - -namespace Tango.Integration.Operation -{ - public class FirmwareUpgradeHandler : ExtendedObject - { - private Action _cancelAction; - - public event EventHandler Progress; - public event EventHandler Completed; - public event EventHandler Canceled; - public event EventHandler Failed; - - internal FirmwareUpgradeHandler() - { - - } - - internal FirmwareUpgradeHandler(Action cancelAction) - { - _cancelAction = cancelAction; - } - - private FirmwareUpgradeStatus _status; - public FirmwareUpgradeStatus Status - { - get { return _status; } - private set { _status = value; RaisePropertyChangedAuto(); } - } - - private long _current; - public long Current - { - get { return _current; } - internal set - { - _current = value; RaisePropertyChangedAuto(); - } - } - - private long _total; - public long Total - { - get { return _total; } - internal set { _total = value; RaisePropertyChangedAuto(); } - } - - public Task Cancel() - { - return Task.Factory.StartNew(() => - { - _cancelAction.Invoke(); - Status = FirmwareUpgradeStatus.Canceled; - }); - } - - internal void RaiseCompleted() - { - Status = FirmwareUpgradeStatus.Completed; - Completed?.Invoke(this, new EventArgs()); - } - - internal void RaiseCanceled() - { - Status = FirmwareUpgradeStatus.Canceled; - Canceled?.Invoke(this, new EventArgs()); - } - - internal void RaiseFailed(Exception ex) - { - Status = FirmwareUpgradeStatus.Failed; - Failed?.Invoke(this, ex); - } - - internal void RaiseProgress(long current, FirmwareUpgradeStatus status) - { - Current = current; - Status = status; - - Progress?.Invoke(this, new FirmwareUpgradeProgressEventArgs() - { - Current = Current, - Status = Status, - Total = Total - }); - } - } -} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeProgressEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeProgressEventArgs.cs deleted file mode 100644 index 4e1c86fe6..000000000 --- a/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeProgressEventArgs.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Integration.Operation -{ - public class FirmwareUpgradeProgressEventArgs : EventArgs - { - public long Current { get; set; } - public long Total { get; set; } - public FirmwareUpgradeStatus Status { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeStatus.cs b/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeStatus.cs deleted file mode 100644 index e2c956807..000000000 --- a/Software/Visual_Studio/Tango.Integration/Operation/FirmwareUpgradeStatus.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Integration.Operation -{ - public enum FirmwareUpgradeStatus - { - [Description("Initializing...")] - Initializing, - [Description("Uploading MCU file...")] - UploadingMCU, - [Description("Uploading FPGA 1 file...")] - UploadingFPGA1, - [Description("Uploading FPGA 2 file...")] - UploadingFPGA2, - [Description("Uploading FPGA 3 file...")] - UploadingFPGA3, - [Description("Validating version integrity...")] - Validating, - [Description("Activating version...")] - Activating, - [Description("Waiting for device reboot...")] - WaitingForReboot, - [Description("Connecting...")] - Connecting, - [Description("Completed")] - Completed, - [Description("Aborted")] - Canceled, - [Description("Failed")] - Failed, - } -} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index 1495808cd..831b601be 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -17,6 +17,8 @@ using Tango.PMR.Connection; using Tango.PMR.Stubs; using Tango.Integration.Storage; using System.IO; +using Tango.Integration.Upgrade; +using Tango.PMR.IO; namespace Tango.Integration.Operation { @@ -331,6 +333,25 @@ namespace Tango.Integration.Operation /// Task UpgradeFirmware(Stream tfpStream); + /// + /// Directs the embedded device to validate the last uploaded firmware package. + /// + /// + Task ValidateFirmwareVersion(String path); + + /// + /// Directs the embedded device to validate the last uploaded firmware package. + /// + /// + Task ActivateFirmwareVersion(String path); + + /// + /// Gets the firmware update package info. + /// + /// The TFP (Tango Firmware Package File) stream. + /// + Task GetFirmwarePackageInfo(Stream tfpStream); + /// /// Creates a storage manager for managing the machine file system. /// diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index b3d8741b6..50bce46c2 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -29,6 +29,7 @@ using Tango.Integration.Storage; using Ionic.Zip; using Tango.Core.Threading; using Tango.PMR.IO; +using Tango.Integration.Upgrade; namespace Tango.Integration.Operation { @@ -39,11 +40,8 @@ namespace Tango.Integration.Operation /// public class MachineOperator : BasicTransporter, IMachineOperator { - private const String FIRMWARE_UPGRADE_FOLDER_NAME = "UpgradePackage"; - private const String FIRMWARE_MCU_FILE_NAME = "mcu"; - private const String FIRMWARE_FPGA1_FILE_NAME = "fpga1"; - private const String FIRMWARE_FPGA2_FILE_NAME = "fpga2"; - private const String FIRMWARE_FPGA3_FILE_NAME = "fpga3"; + public const String FIRMWARE_UPGRADE_FOLDER_NAME = "UpgradePackage"; + public const String FIRMWARE_UPGRADE_CONFIG_FILE_NAME = "package.cfg"; private bool _diagnosticsSent; private bool _eventsSent; @@ -1775,178 +1773,176 @@ namespace Tango.Integration.Operation public async Task UpgradeFirmware(Stream tfpStream) { bool cancel = false; + ZipFile zip = null; - var upgradeHandler = new FirmwareUpgradeHandler(() => + var upgradeHandler = new FirmwareUpgradeHandler(() => { cancel = true; }); - ZipFile zip = ZipFile.Read(tfpStream); - - //Perform zip validation... - if (!zip.Entries.ToList().Exists(x => x.FileName == FIRMWARE_MCU_FILE_NAME)) + try { - throw new IOException($"Invalid firmware upgrade package. file {FIRMWARE_MCU_FILE_NAME} could not be found."); - } + zip = ZipFile.Read(tfpStream); - if (!zip.Entries.ToList().Exists(x => x.FileName == FIRMWARE_FPGA1_FILE_NAME)) - { - throw new IOException($"Invalid firmware upgrade package. file {FIRMWARE_FPGA1_FILE_NAME} could not be found."); - } + upgradeHandler.Total = zip.Entries.Sum(x => x.UncompressedSize); - if (!zip.Entries.ToList().Exists(x => x.FileName == FIRMWARE_FPGA2_FILE_NAME)) - { - throw new IOException($"Invalid firmware upgrade package. file {FIRMWARE_FPGA2_FILE_NAME} could not be found."); - } - - if (!zip.Entries.ToList().Exists(x => x.FileName == FIRMWARE_FPGA3_FILE_NAME)) - { - throw new IOException($"Invalid firmware upgrade package. file {FIRMWARE_FPGA3_FILE_NAME} could not be found."); - } + var storage = CreateStorageManager(); + var drive = await storage.GetStorageDrive(); + var root = await storage.GetRootFolder(); + var existing_folder = root.Items.SingleOrDefault(x => x.Name == FIRMWARE_UPGRADE_FOLDER_NAME); + if (existing_folder != null) + { + await storage.DeleteItem(existing_folder); + } - upgradeHandler.Total = zip.Entries.Sum(x => x.UncompressedSize); + String package_folder = Path.Combine(drive.Root, FIRMWARE_UPGRADE_FOLDER_NAME); - var storage = CreateStorageManager(); - var drive = await storage.GetStorageDrive(); - var root = await storage.GetRootFolder(); - var existing_folder = root.Items.SingleOrDefault(x => x.Name == FIRMWARE_UPGRADE_FOLDER_NAME); - if (existing_folder != null) - { - await storage.DeleteItem(existing_folder); - } + await storage.CreateFolder(package_folder); - String package_folder = Path.Combine(drive.Root, FIRMWARE_UPGRADE_FOLDER_NAME); + List handlers = new List(); + List entries = zip.Entries.ToList(); + List streams = new List(); - await storage.CreateFolder(package_folder); + Action uploadNext = null; + Action validate = null; + Action activate = null; + Action postActivation = null; - List handlers = new List(); - List entries = zip.Entries.ToList(); - List streams = new List(); + uploadNext = new Action(() => + { + if (entries.Count > 0) + { + try + { + var entry = entries.First(); + entries.Remove(entry); + + var reader = entry.OpenReader(); + streams.Add(reader); + + var handler = storage.UploadFile(Path.Combine(package_folder, entry.FileName), reader).Result; + handlers.Add(handler); + handler.Canceled += (_, __) => { upgradeHandler.RaiseCanceled(); cancel = true; }; + handler.Completed += (_, __) => uploadNext(); + handler.Failed += (_, failedEx) => { upgradeHandler.RaiseFailed(failedEx); cancel = true; }; + handler.Progress += (_, e) => + { + if (cancel) + { + handler.Cancel(); + return; + } - Action uploadNext = null; - Action validate = null; - Action activate = null; - Action postActivation = null; + upgradeHandler.RaiseProgress(upgradeHandler.Current + e.Delta, FirmwareUpgradeStatus.Uploading, $"Uploading '{entry.FileName}'..."); + }; + } + catch (Exception ex) + { + upgradeHandler.RaiseFailed(ex); + } + } + else + { + validate(); + } + }); - uploadNext = new Action(() => - { - if (entries.Count > 0) + validate = new Action(() => { try { - var entry = entries.First(); - entries.Remove(entry); - - var reader = entry.OpenReader(); - streams.Add(reader); - - var handler = storage.UploadFile(Path.Combine(package_folder, entry.FileName), reader).Result; - handlers.Add(handler); - handler.Canceled += (_, __) => { upgradeHandler.RaiseCanceled(); cancel = true; }; - handler.Completed += (_, __) => uploadNext(); - handler.Failed += (_, failedEx) => { upgradeHandler.RaiseFailed(failedEx); cancel = true; }; - handler.Progress += (_, e) => - { - if (cancel) - { - handler.Cancel(); - return; - } + streams.ForEach(x => x.Dispose()); + upgradeHandler.RaiseProgress(upgradeHandler.Total, FirmwareUpgradeStatus.Validating, "Validating version..."); + var validateRequest = new ValidateVersionRequest(); + validateRequest.Path = package_folder; + var validateResponse = SendRequest(validateRequest, TimeSpan.FromSeconds(10)).Result; + activate(); + } + catch (Exception ex) + { + upgradeHandler.RaiseFailed(ex); + } + }); - switch (entry.FileName) - { - case FIRMWARE_MCU_FILE_NAME: - upgradeHandler.RaiseProgress(upgradeHandler.Current + e.Delta, FirmwareUpgradeStatus.UploadingMCU); - break; - case FIRMWARE_FPGA1_FILE_NAME: - upgradeHandler.RaiseProgress(upgradeHandler.Current + e.Delta, FirmwareUpgradeStatus.UploadingFPGA1); - break; - case FIRMWARE_FPGA2_FILE_NAME: - upgradeHandler.RaiseProgress(upgradeHandler.Current + e.Delta, FirmwareUpgradeStatus.UploadingFPGA2); - break; - case FIRMWARE_FPGA3_FILE_NAME: - upgradeHandler.RaiseProgress(upgradeHandler.Current + e.Delta, FirmwareUpgradeStatus.UploadingFPGA3); - break; - } - }; + activate = new Action(() => + { + try + { + upgradeHandler.RaiseProgress(upgradeHandler.Total, FirmwareUpgradeStatus.Activating, "Activating version..."); + var activateRequest = new ActivateVersionRequest(); + activateRequest.Path = package_folder; + var activateResponse = SendRequest(activateRequest, TimeSpan.FromSeconds(10)).Result; + postActivation(); } catch (Exception ex) { upgradeHandler.RaiseFailed(ex); } - } - else + }); + + postActivation = new Action(() => { - validate(); - } - }); + upgradeHandler.RaiseCompleted(); + }); - List descriptors = new List(); - descriptors.Add(new VersionFileDescriptor() - { - FileName = Path.Combine(package_folder, FIRMWARE_MCU_FILE_NAME), - Destination = VersionFileDestination.Mcu, - }); - descriptors.Add(new VersionFileDescriptor() - { - FileName = Path.Combine(package_folder, FIRMWARE_FPGA1_FILE_NAME), - Destination = VersionFileDestination.Fpga1, - }); - descriptors.Add(new VersionFileDescriptor() - { - FileName = Path.Combine(package_folder, FIRMWARE_FPGA2_FILE_NAME), - Destination = VersionFileDestination.Fpga2, - }); - descriptors.Add(new VersionFileDescriptor() - { - FileName = Path.Combine(package_folder, FIRMWARE_FPGA3_FILE_NAME), - Destination = VersionFileDestination.Fpga3, - }); + ThreadFactory.StartNew(() => + { + uploadNext(); + }); - validate = new Action(() => + return upgradeHandler; + } + catch (Exception) { - try - { - streams.ForEach(x => x.Dispose()); - upgradeHandler.RaiseProgress(upgradeHandler.Total, FirmwareUpgradeStatus.Validating); - var validateRequest = new ValidateVersionRequest(); - validateRequest.FileDescriptors.AddRange(descriptors); - var validateResponse = SendRequest(validateRequest, TimeSpan.FromSeconds(10)).Result; - activate(); - } - catch (Exception ex) + if (zip != null) { - upgradeHandler.RaiseFailed(ex); + zip.Dispose(); } - }); - activate = new Action(() => + throw; + } + } + + /// + /// Validates the firmware package integrity. + /// + /// The TFP (Tango Firmware Package File) stream. + /// + public Task GetFirmwarePackageInfo(Stream tfpStream) + { + return Task.Factory.StartNew(() => { - try - { - upgradeHandler.RaiseProgress(upgradeHandler.Total, FirmwareUpgradeStatus.Activating); - var activateRequest = new ActivateVersionRequest(); - activateRequest.FileDescriptors.AddRange(descriptors); - var activateResponse = SendRequest(activateRequest, TimeSpan.FromSeconds(10)).Result; - postActivation(); - } - catch (Exception ex) + using (ZipFile zip = ZipFile.Read(tfpStream)) { - upgradeHandler.RaiseFailed(ex); + var reader = zip.Entries.SingleOrDefault(x => x.FileName == FIRMWARE_UPGRADE_CONFIG_FILE_NAME).OpenReader(); + var info = VersionPackageDescriptor.Parser.ParseFrom(reader); + reader.Close(); + reader.Dispose(); + return info; } }); + } - postActivation = new Action(() => - { - upgradeHandler.RaiseCompleted(); - }); - - ThreadFactory.StartNew(() => - { - uploadNext(); - }); + /// + /// Directs the embedded device to validate the last uploaded firmware package. + /// + /// + public async Task ValidateFirmwareVersion(String path) + { + var validateRequest = new ValidateVersionRequest(); + validateRequest.Path = path; + await SendRequest(validateRequest, TimeSpan.FromSeconds(10)); + } - return upgradeHandler; + /// + /// Directs the embedded device to validate the last uploaded firmware package. + /// + /// + public async Task ActivateFirmwareVersion(String path) + { + var activateRequest = new ActivateVersionRequest(); + activateRequest.Path = path; + await SendRequest(activateRequest, TimeSpan.FromSeconds(10)); } #endregion diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs index 0743fe54d..1a82d0ff4 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs @@ -312,6 +312,7 @@ namespace Tango.Integration.Storage return; } + byte[] buffer = chunk_response.Message.Buffer.ToByteArray(); stream.Write(buffer, 0, buffer.Length); diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 14cdc03c5..b4e104f4d 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -89,9 +89,9 @@ - - - + + + diff --git a/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeHandler.cs b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeHandler.cs new file mode 100644 index 000000000..774824b49 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeHandler.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Integration.Storage; + +namespace Tango.Integration.Upgrade +{ + public class FirmwareUpgradeHandler : ExtendedObject + { + private Action _cancelAction; + + public event EventHandler Progress; + public event EventHandler Completed; + public event EventHandler Canceled; + public event EventHandler Failed; + + internal FirmwareUpgradeHandler() + { + Message = "Initializing..."; + } + + internal FirmwareUpgradeHandler(Action cancelAction) : this() + { + _cancelAction = cancelAction; + } + + private String _message; + public String Message + { + get { return _message; } + set { _message = value; RaisePropertyChangedAuto(); } + } + + private FirmwareUpgradeStatus _status; + public FirmwareUpgradeStatus Status + { + get { return _status; } + private set { _status = value; RaisePropertyChangedAuto(); } + } + + private long _current; + public long Current + { + get { return _current; } + internal set + { + _current = value; RaisePropertyChangedAuto(); + } + } + + private long _total; + public long Total + { + get { return _total; } + internal set { _total = value; RaisePropertyChangedAuto(); } + } + + public Task Cancel() + { + return Task.Factory.StartNew(() => + { + _cancelAction.Invoke(); + Message = "Canceled."; + Status = FirmwareUpgradeStatus.Canceled; + Canceled?.Invoke(this, new EventArgs()); + }); + } + + internal void RaiseCompleted() + { + Status = FirmwareUpgradeStatus.Completed; + Message = "Completed."; + Completed?.Invoke(this, new EventArgs()); + } + + internal void RaiseCanceled() + { + Status = FirmwareUpgradeStatus.Canceled; + Message = "Canceled."; + Canceled?.Invoke(this, new EventArgs()); + } + + internal void RaiseFailed(Exception ex) + { + Status = FirmwareUpgradeStatus.Failed; + Message = "Failed."; + Failed?.Invoke(this, ex); + } + + internal void RaiseProgress(long current, FirmwareUpgradeStatus status, String message) + { + Current = current; + Status = status; + Message = message; + + Progress?.Invoke(this, new FirmwareUpgradeProgressEventArgs() + { + Current = Current, + Status = Status, + Total = Total, + Message = Message, + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeProgressEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeProgressEventArgs.cs new file mode 100644 index 000000000..fa4f4cc96 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeProgressEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Upgrade +{ + public class FirmwareUpgradeProgressEventArgs : EventArgs + { + public long Current { get; set; } + public long Total { get; set; } + public FirmwareUpgradeStatus Status { get; set; } + public String Message { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs new file mode 100644 index 000000000..0d8449ee9 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Upgrade +{ + public enum FirmwareUpgradeStatus + { + [Description("Initializing...")] + Initializing, + [Description("Uploading files...")] + Uploading, + [Description("Validating version...")] + Validating, + [Description("Activating version...")] + Activating, + [Description("Waiting for device reboot...")] + WaitingForReboot, + [Description("Connecting...")] + Connecting, + [Description("Completed")] + Completed, + [Description("Aborted")] + Canceled, + [Description("Failed")] + Failed, + } +} diff --git a/Software/Visual_Studio/Tango.PMR/IO/ActivateVersionRequest.cs b/Software/Visual_Studio/Tango.PMR/IO/ActivateVersionRequest.cs index b20f28d63..0901521e8 100644 --- a/Software/Visual_Studio/Tango.PMR/IO/ActivateVersionRequest.cs +++ b/Software/Visual_Studio/Tango.PMR/IO/ActivateVersionRequest.cs @@ -22,15 +22,13 @@ namespace Tango.PMR.IO { static ActivateVersionRequestReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "ChxBY3RpdmF0ZVZlcnNpb25SZXF1ZXN0LnByb3RvEgxUYW5nby5QTVIuSU8a", - "G1ZlcnNpb25GaWxlRGVzY3JpcHRvci5wcm90byJWChZBY3RpdmF0ZVZlcnNp", - "b25SZXF1ZXN0EjwKD0ZpbGVEZXNjcmlwdG9ycxgBIAMoCzIjLlRhbmdvLlBN", - "Ui5JTy5WZXJzaW9uRmlsZURlc2NyaXB0b3JCGAoWY29tLnR3aW5lLnRhbmdv", - "LnBtci5pb2IGcHJvdG8z")); + "ChxBY3RpdmF0ZVZlcnNpb25SZXF1ZXN0LnByb3RvEgxUYW5nby5QTVIuSU8i", + "JgoWQWN0aXZhdGVWZXJzaW9uUmVxdWVzdBIMCgRQYXRoGAEgASgJQhgKFmNv", + "bS50d2luZS50YW5nby5wbXIuaW9iBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Tango.PMR.IO.VersionFileDescriptorReflection.Descriptor, }, + new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.ActivateVersionRequest), global::Tango.PMR.IO.ActivateVersionRequest.Parser, new[]{ "FileDescriptors" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.ActivateVersionRequest), global::Tango.PMR.IO.ActivateVersionRequest.Parser, new[]{ "Path" }, null, null, null) })); } #endregion @@ -61,7 +59,7 @@ namespace Tango.PMR.IO { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public ActivateVersionRequest(ActivateVersionRequest other) : this() { - fileDescriptors_ = other.fileDescriptors_.Clone(); + path_ = other.path_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -69,14 +67,15 @@ namespace Tango.PMR.IO { return new ActivateVersionRequest(this); } - /// Field number for the "FileDescriptors" field. - public const int FileDescriptorsFieldNumber = 1; - private static readonly pb::FieldCodec _repeated_fileDescriptors_codec - = pb::FieldCodec.ForMessage(10, global::Tango.PMR.IO.VersionFileDescriptor.Parser); - private readonly pbc::RepeatedField fileDescriptors_ = new pbc::RepeatedField(); + /// Field number for the "Path" field. + public const int PathFieldNumber = 1; + private string path_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public pbc::RepeatedField FileDescriptors { - get { return fileDescriptors_; } + public string Path { + get { return path_; } + set { + path_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -92,14 +91,14 @@ namespace Tango.PMR.IO { if (ReferenceEquals(other, this)) { return true; } - if(!fileDescriptors_.Equals(other.fileDescriptors_)) return false; + if (Path != other.Path) return false; return true; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - hash ^= fileDescriptors_.GetHashCode(); + if (Path.Length != 0) hash ^= Path.GetHashCode(); return hash; } @@ -110,13 +109,18 @@ namespace Tango.PMR.IO { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - fileDescriptors_.WriteTo(output, _repeated_fileDescriptors_codec); + if (Path.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Path); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - size += fileDescriptors_.CalculateSize(_repeated_fileDescriptors_codec); + if (Path.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Path); + } return size; } @@ -125,7 +129,9 @@ namespace Tango.PMR.IO { if (other == null) { return; } - fileDescriptors_.Add(other.fileDescriptors_); + if (other.Path.Length != 0) { + Path = other.Path; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -137,7 +143,7 @@ namespace Tango.PMR.IO { input.SkipLastField(); break; case 10: { - fileDescriptors_.AddEntriesFrom(input, _repeated_fileDescriptors_codec); + Path = input.ReadString(); break; } } diff --git a/Software/Visual_Studio/Tango.PMR/IO/ValidateVersionRequest.cs b/Software/Visual_Studio/Tango.PMR/IO/ValidateVersionRequest.cs index 0dda007d2..d5d032969 100644 --- a/Software/Visual_Studio/Tango.PMR/IO/ValidateVersionRequest.cs +++ b/Software/Visual_Studio/Tango.PMR/IO/ValidateVersionRequest.cs @@ -22,15 +22,13 @@ namespace Tango.PMR.IO { static ValidateVersionRequestReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "ChxWYWxpZGF0ZVZlcnNpb25SZXF1ZXN0LnByb3RvEgxUYW5nby5QTVIuSU8a", - "G1ZlcnNpb25GaWxlRGVzY3JpcHRvci5wcm90byJWChZWYWxpZGF0ZVZlcnNp", - "b25SZXF1ZXN0EjwKD0ZpbGVEZXNjcmlwdG9ycxgBIAMoCzIjLlRhbmdvLlBN", - "Ui5JTy5WZXJzaW9uRmlsZURlc2NyaXB0b3JCGAoWY29tLnR3aW5lLnRhbmdv", - "LnBtci5pb2IGcHJvdG8z")); + "ChxWYWxpZGF0ZVZlcnNpb25SZXF1ZXN0LnByb3RvEgxUYW5nby5QTVIuSU8i", + "JgoWVmFsaWRhdGVWZXJzaW9uUmVxdWVzdBIMCgRQYXRoGAEgASgJQhgKFmNv", + "bS50d2luZS50YW5nby5wbXIuaW9iBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Tango.PMR.IO.VersionFileDescriptorReflection.Descriptor, }, + new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.ValidateVersionRequest), global::Tango.PMR.IO.ValidateVersionRequest.Parser, new[]{ "FileDescriptors" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.ValidateVersionRequest), global::Tango.PMR.IO.ValidateVersionRequest.Parser, new[]{ "Path" }, null, null, null) })); } #endregion @@ -61,7 +59,7 @@ namespace Tango.PMR.IO { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public ValidateVersionRequest(ValidateVersionRequest other) : this() { - fileDescriptors_ = other.fileDescriptors_.Clone(); + path_ = other.path_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -69,14 +67,15 @@ namespace Tango.PMR.IO { return new ValidateVersionRequest(this); } - /// Field number for the "FileDescriptors" field. - public const int FileDescriptorsFieldNumber = 1; - private static readonly pb::FieldCodec _repeated_fileDescriptors_codec - = pb::FieldCodec.ForMessage(10, global::Tango.PMR.IO.VersionFileDescriptor.Parser); - private readonly pbc::RepeatedField fileDescriptors_ = new pbc::RepeatedField(); + /// Field number for the "Path" field. + public const int PathFieldNumber = 1; + private string path_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public pbc::RepeatedField FileDescriptors { - get { return fileDescriptors_; } + public string Path { + get { return path_; } + set { + path_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -92,14 +91,14 @@ namespace Tango.PMR.IO { if (ReferenceEquals(other, this)) { return true; } - if(!fileDescriptors_.Equals(other.fileDescriptors_)) return false; + if (Path != other.Path) return false; return true; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - hash ^= fileDescriptors_.GetHashCode(); + if (Path.Length != 0) hash ^= Path.GetHashCode(); return hash; } @@ -110,13 +109,18 @@ namespace Tango.PMR.IO { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - fileDescriptors_.WriteTo(output, _repeated_fileDescriptors_codec); + if (Path.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Path); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - size += fileDescriptors_.CalculateSize(_repeated_fileDescriptors_codec); + if (Path.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Path); + } return size; } @@ -125,7 +129,9 @@ namespace Tango.PMR.IO { if (other == null) { return; } - fileDescriptors_.Add(other.fileDescriptors_); + if (other.Path.Length != 0) { + Path = other.Path; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -137,7 +143,7 @@ namespace Tango.PMR.IO { input.SkipLastField(); break; case 10: { - fileDescriptors_.AddEntriesFrom(input, _repeated_fileDescriptors_codec); + Path = input.ReadString(); break; } } diff --git a/Software/Visual_Studio/Tango.PMR/IO/VersionPackageDescriptor.cs b/Software/Visual_Studio/Tango.PMR/IO/VersionPackageDescriptor.cs new file mode 100644 index 000000000..54c9e0e9d --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/IO/VersionPackageDescriptor.cs @@ -0,0 +1,153 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: VersionPackageDescriptor.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.IO { + + /// Holder for reflection information generated from VersionPackageDescriptor.proto + public static partial class VersionPackageDescriptorReflection { + + #region Descriptor + /// File descriptor for VersionPackageDescriptor.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static VersionPackageDescriptorReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ch5WZXJzaW9uUGFja2FnZURlc2NyaXB0b3IucHJvdG8SDFRhbmdvLlBNUi5J", + "TxobVmVyc2lvbkZpbGVEZXNjcmlwdG9yLnByb3RvIlgKGFZlcnNpb25QYWNr", + "YWdlRGVzY3JpcHRvchI8Cg9GaWxlRGVzY3JpcHRvcnMYASADKAsyIy5UYW5n", + "by5QTVIuSU8uVmVyc2lvbkZpbGVEZXNjcmlwdG9yQhgKFmNvbS50d2luZS50", + "YW5nby5wbXIuaW9iBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Tango.PMR.IO.VersionFileDescriptorReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.VersionPackageDescriptor), global::Tango.PMR.IO.VersionPackageDescriptor.Parser, new[]{ "FileDescriptors" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class VersionPackageDescriptor : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new VersionPackageDescriptor()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.IO.VersionPackageDescriptorReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public VersionPackageDescriptor() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public VersionPackageDescriptor(VersionPackageDescriptor other) : this() { + fileDescriptors_ = other.fileDescriptors_.Clone(); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public VersionPackageDescriptor Clone() { + return new VersionPackageDescriptor(this); + } + + /// Field number for the "FileDescriptors" field. + public const int FileDescriptorsFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_fileDescriptors_codec + = pb::FieldCodec.ForMessage(10, global::Tango.PMR.IO.VersionFileDescriptor.Parser); + private readonly pbc::RepeatedField fileDescriptors_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField FileDescriptors { + get { return fileDescriptors_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as VersionPackageDescriptor); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(VersionPackageDescriptor other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!fileDescriptors_.Equals(other.fileDescriptors_)) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= fileDescriptors_.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + fileDescriptors_.WriteTo(output, _repeated_fileDescriptors_codec); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += fileDescriptors_.CalculateSize(_repeated_fileDescriptors_codec); + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(VersionPackageDescriptor other) { + if (other == null) { + return; + } + fileDescriptors_.Add(other.fileDescriptors_); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + fileDescriptors_.AddEntriesFrom(input, _repeated_fileDescriptors_codec); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj index bbea736e5..2fc510b58 100644 --- a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj +++ b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj @@ -199,6 +199,7 @@ + @@ -258,7 +259,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs index 195ff845f..ed57e5014 100644 --- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs @@ -28,7 +28,7 @@ namespace Tango.Transport { private const int MESSAGE_TOKEN_LENGTH = 36; private ProducerConsumerQueue _sendingQueue; - private List _pendingRequests; + private ConcurrentList _pendingRequests; private ProducerConsumerQueue _arrivedResponses; private Thread _pushThread; private Thread _pullThread; @@ -260,7 +260,7 @@ namespace Tango.Transport Encoder = new ProtoEncoder(); _pendingResponses = new Dictionary(); _sendingQueue = new ProducerConsumerQueue(); - _pendingRequests = new List(); + _pendingRequests = new ConcurrentList(); _arrivedResponses = new ProducerConsumerQueue(); RequestTimeout = TimeSpan.FromSeconds(5); } @@ -284,7 +284,7 @@ namespace Tango.Transport public void ClearQueues() { _sendingQueue = new ProducerConsumerQueue(); - _pendingRequests = new List(); + _pendingRequests = new ConcurrentList(); _arrivedResponses = new ProducerConsumerQueue(); } @@ -343,7 +343,7 @@ namespace Tango.Transport TransportMessage message = new TransportMessage(container.Token, request, TransportMessageDirection.Request, () => container.ToByteArray(), source); EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + TimeoutTask.StartNew(() => { if (!source.Task.IsCompleted) @@ -413,7 +413,7 @@ namespace Tango.Transport TransportMessage message = new TransportMessage(container.Token, container, TransportMessageDirection.Request, () => container.ToByteArray(), source); EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + TimeoutTask.StartNew(() => { if (!source.Task.IsCompleted) @@ -503,7 +503,7 @@ namespace Tango.Transport }; EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + TimeoutTask.StartNew(() => { if (!message.AtLeastOneResponseReceived) @@ -538,7 +538,7 @@ namespace Tango.Transport TransportMessage> message = new TransportMessage>(request.Container.Token, request, TransportMessageDirection.Request, () => Encoder.Encode(request), source); EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + TimeoutTask.StartNew(() => { if (!source.Task.IsCompleted) @@ -583,7 +583,7 @@ namespace Tango.Transport }; EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + TimeoutTask.StartNew(() => { if (!message.AtLeastOneResponseReceived) @@ -649,7 +649,7 @@ namespace Tango.Transport }; EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + TimeoutTask.StartNew(() => { if (!message.AtLeastOneResponseReceived) @@ -878,7 +878,10 @@ namespace Tango.Transport if (message.Direction == TransportMessageDirection.Request) { - _pendingRequests.Add(message); + lock (_pendingRequests) + { + _pendingRequests.Add(message); + } } else { @@ -930,7 +933,11 @@ namespace Tango.Transport LogManager.Log("Searching for pending request token: " + container.Token, LogCategory.Debug); - TransportMessageBase request = _pendingRequests.ToList().SingleOrDefault(x => x.Token == container.Token); + TransportMessageBase request = null; + lock (_pendingRequests) + { + request = _pendingRequests.ToList().SingleOrDefault(x => x.Token == container.Token); + } if (request != null) { diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 910b4d1ea..ed2c4676e 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -240,6 +240,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.Events", "PPC\Mod EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.MachineStudio.Storage", "MachineStudio\Modules\Tango.MachineStudio.Storage\Tango.MachineStudio.Storage.csproj", "{5991F6B5-EA4E-41E9-A4F6-7D3A50010FD6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.FirmwarePackageGenerator", "Utilities\Tango.FirmwarePackageGenerator\Tango.FirmwarePackageGenerator.csproj", "{43135FB9-41DB-4F87-9771-CF2C762027C0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution AppVeyor|Any CPU = AppVeyor|Any CPU @@ -4283,6 +4285,46 @@ Global {5991F6B5-EA4E-41E9-A4F6-7D3A50010FD6}.Release|x64.Build.0 = Release|Any CPU {5991F6B5-EA4E-41E9-A4F6-7D3A50010FD6}.Release|x86.ActiveCfg = Release|Any CPU {5991F6B5-EA4E-41E9-A4F6-7D3A50010FD6}.Release|x86.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|Any CPU.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|Any CPU.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|ARM.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|ARM.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|ARM64.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|ARM64.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|x64.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|x64.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|x86.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.AppVeyor|x86.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|ARM.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|ARM.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|ARM64.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|x64.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|x64.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|x86.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Debug|x86.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|Any CPU.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|Any CPU.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|ARM.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|ARM.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|ARM64.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|ARM64.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|x64.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|x64.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|x86.ActiveCfg = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.DefaultBuild|x86.Build.0 = Debug|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|Any CPU.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|ARM.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|ARM.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|ARM64.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|ARM64.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|x64.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|x64.Build.0 = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|x86.ActiveCfg = Release|Any CPU + {43135FB9-41DB-4F87-9771-CF2C762027C0}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4357,14 +4399,15 @@ Global {04FEBB02-F782-4B96-B47D-F6902AFA43BE} = {0048447D-1D94-4E60-9DAD-7349C777CB4E} {A8077B3E-8DD6-4572-8EC4-A27BDC91B70A} = {0048447D-1D94-4E60-9DAD-7349C777CB4E} {5991F6B5-EA4E-41E9-A4F6-7D3A50010FD6} = {B2AF4F3F-2828-47C3-8F3E-A0EA0BD66FF8} + {43135FB9-41DB-4F87-9771-CF2C762027C0} = {5F6BBAA8-EAD0-4B18-97E5-55B4F56DD760} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_UpdateFileVersion = False - BuildVersion_StartDate = 2000/1/1 - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs BuildVersion_UseGlobalSettings = False + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_StartDate = 2000/1/1 + BuildVersion_UpdateFileVersion = False + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.config b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.config new file mode 100644 index 000000000..be3d2b956 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.config @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml new file mode 100644 index 000000000..acec406cb --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml.cs new file mode 100644 index 000000000..39bd940b8 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.FirmwarePackageGenerator +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Images/firmware_upgrade.png b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Images/firmware_upgrade.png new file mode 100644 index 000000000..fc0799143 Binary files /dev/null and b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Images/firmware_upgrade.png differ diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml new file mode 100644 index 000000000..76b6f8aa4 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + Fill the grid below to add firmware version files. + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml.cs new file mode 100644 index 000000000..9aa79f469 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindow.xaml.cs @@ -0,0 +1,43 @@ +using MahApps.Metro.Controls; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.FirmwarePackageGenerator +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : MetroWindow + { + public MainWindow() + { + InitializeComponent(); + DataContext = new MainWindowVM(); + } + + private void DataGrid_AddingNewItem(object sender, AddingNewItemEventArgs e) + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Filter = "Firmware Package Files|*.bin;*.fpga"; + if (dlg.ShowDialog().Value) + { + VersionFileModel item = new VersionFileModel(); + item.Path = dlg.FileName; + e.NewItem = item; + } + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindowVM.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindowVM.cs new file mode 100644 index 000000000..718aa3aac --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/MainWindowVM.cs @@ -0,0 +1,103 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.PMR.IO; +using Tango.SharedUI; +using Google.Protobuf; +using Ionic.Zip; +using System.Windows; + +namespace Tango.FirmwarePackageGenerator +{ + public class MainWindowVM : ViewModel + { + private ObservableCollection _versionFiles; + public ObservableCollection VersionFiles + { + get { return _versionFiles; } + set { _versionFiles = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand GenerateCommand { get; set; } + + public MainWindowVM() + { + VersionFiles = new ObservableCollection(); + GenerateCommand = new RelayCommand(Generate); + } + + private void Generate() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Save Firmware Package File"; + dlg.Filter = "Tango Firmware Package|*.tfp"; + dlg.DefaultExt = ".tfp"; + dlg.FileName = "firmware_package.tfp"; + if (dlg.ShowDialog().Value) + { + try + { + VersionPackageDescriptor descriptor = new VersionPackageDescriptor(); + foreach (var item in VersionFiles) + { + descriptor.FileDescriptors.Add(new VersionFileDescriptor() + { + Destination = item.Destination, + FileName = item.FileName, + Version = item.Version, + }); + } + + using (MemoryStream ms = new MemoryStream()) + { + descriptor.WriteTo(ms); + + using (var zip = new ZipFile()) + { + zip.AddEntry("package.cfg", ms.ToArray()); + foreach (var item in VersionFiles) + { + zip.AddFile(item.Path, "/"); + } + + zip.Save(dlg.FileName); + } + } + + //Validate + using (ZipFile zip = ZipFile.Read(dlg.FileName)) + { + var reader = zip.Entries.SingleOrDefault(x => x.FileName == "package.cfg").OpenReader(); + var descriptor2 = VersionPackageDescriptor.Parser.ParseFrom(reader); + if (descriptor.ToString() != descriptor2.ToString()) + { + throw new IOException("The generated package does not match the source package."); + } + } + + ShowInfo("Package generated successfully."); + } + catch (Exception ex) + { + ShowError($"Error while trying to generate the package.\n{ex.Message}"); + } + } + } + + private void ShowError(String error) + { + MessageBox.Show(error, "PPC Publisher", MessageBoxButton.OK, MessageBoxImage.Error); + } + + private void ShowInfo(String message) + { + MessageBox.Show(message, "PPC Publisher", MessageBoxButton.OK, MessageBoxImage.Information); + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..b9727e630 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/AssemblyInfo.cs @@ -0,0 +1,7 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango - Firmware Package Generator Utility")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.Designer.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.Designer.cs new file mode 100644 index 000000000..30d0ee544 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.FirmwarePackageGenerator.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.FirmwarePackageGenerator.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.resx b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.Designer.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.Designer.cs new file mode 100644 index 000000000..c3d44ce2c --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.FirmwarePackageGenerator.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.settings b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Tango.FirmwarePackageGenerator.csproj b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Tango.FirmwarePackageGenerator.csproj new file mode 100644 index 000000000..4ca1eb322 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/Tango.FirmwarePackageGenerator.csproj @@ -0,0 +1,134 @@ + + + + + Debug + AnyCPU + {43135FB9-41DB-4F87-9771-CF2C762027C0} + WinExe + Tango.FirmwarePackageGenerator + fpgen + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + ..\..\Build\Utilities\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\..\Build\Utilities\Debug\ + TRACE + prompt + 4 + + + + ..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + + ..\..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll + + + ..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll + + + + + ..\..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + MSBuild:Compile + Designer + + + GlobalVersionInfo.cs + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {e4927038-348d-4295-aaf4-861c58cb3943} + Tango.PMR + + + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} + Tango.SharedUI + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/VersionFileModel.cs b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/VersionFileModel.cs new file mode 100644 index 000000000..1431fa74d --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/VersionFileModel.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.PMR.IO; + +namespace Tango.FirmwarePackageGenerator +{ + public class VersionFileModel : ExtendedObject + { + public VersionFileModel() + { + Version = "1.0.0.0"; + } + + private String _path; + public String Path + { + get { return _path; } + set { _path = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(FileName)); } + } + + public String FileName + { + get { return System.IO.Path.GetFileName(Path); } + } + + private String _version; + public String Version + { + get { return _version; } + set { _version = value; RaisePropertyChangedAuto(); } + } + + private VersionFileDestination _destination; + public VersionFileDestination Destination + { + get { return _destination; } + set { _destination = value; RaisePropertyChangedAuto(); } + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/packages.config b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/packages.config new file mode 100644 index 000000000..5521d9817 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.FirmwarePackageGenerator/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file -- cgit v1.3.1