From e47f736bca350350a55fa287093dad560da8f678 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 6 Dec 2018 15:48:47 +0200 Subject: Working on PPC firmware upgrade !!! --- .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1516 bytes .../Application/IPPCApplicationManager.cs | 5 + .../PPC/Tango.PPC.Common/ApplicationStates.cs | 8 +- .../Connection/DefaultMachineProvider.cs | 64 ++++++++ .../FirmwareUpgrade/DefaultFirmwareUpgrader.cs | 31 ++++ .../FirmwareUpgrade/IFirmwareUpgrader.cs | 23 +++ .../Tango.PPC.Common/Navigation/NavigationView.cs | 1 + .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 4 +- .../PPC/Tango.PPC.Publisher/MainWindow.xaml | 8 +- .../PPC/Tango.PPC.Publisher/MainWindowVM.cs | 25 ++- .../PPC/Tango.PPC.UI/Images/chip_128px.png | Bin 0 -> 3377 bytes .../PPCApplication/DefaultPPCApplicationManager.cs | 12 +- .../PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs | 2 +- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 16 +- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 11 ++ .../ViewModels/FirmwareUpgradeViewVM.cs | 169 +++++++++++++++++++++ .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 98 +----------- .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 2 +- .../Tango.PPC.UI/Views/FirmwareUpgradeView.xaml | 55 +++++++ .../Tango.PPC.UI/Views/FirmwareUpgradeView.xaml.cs | 47 ++++++ .../PPC/Tango.PPC.UI/Views/MachineSetupView.xaml | 28 +--- .../PPC/Tango.PPC.UI/Views/MainView.xaml | 1 + .../ViewsContracts/IFirmwareUpgradeView.cs | 19 +++ .../Utilities/Tango.Stubs.CLI/Program.cs | 24 ++- 24 files changed, 513 insertions(+), 140 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/DefaultFirmwareUpgrader.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/IFirmwareUpgrader.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/chip_128px.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IFirmwareUpgradeView.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index c7966c7a9..fe3b0d60c 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs index 003229e65..a1f9f6d38 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs @@ -40,6 +40,11 @@ namespace Tango.PPC.Common.Application /// event EventHandler SetupRequired; + /// + /// Occurs when firmware upgrade is required. + /// + event EventHandler FirmwareUpgradeRequired; + /// /// Occurs when the application has encountered an error when initializing. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs index 7be896b0d..362b3941b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs @@ -21,12 +21,12 @@ namespace Tango.PPC.Common /// SemiSetup = 1, /// - /// Application is ready to run as normal. + /// The application has been updated and should start in firmware upgrade mode. /// - Ready = 2, + FirmwareUpgrade = 2, /// - /// Updater utility should update the application assemblies and start the main application with startup arguments. + /// Application is ready to run as normal. /// - Updating = 3, + Ready = 3, } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs index 5b85aab52..8ca943b8c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -118,6 +118,70 @@ namespace Tango.PPC.Common.Connection } } + public static async Task CreateMinimalMachineOperator() + { + var machineOperator = new MachineOperator(); + machineOperator.EnableDiagnostics = false; + machineOperator.EnableEmbeddedDebugging = false; + machineOperator.EnableEventsNotification = false; + machineOperator.EnableJobResume = false; + + LogManager.Default.Log("Starting machine connection procedure..."); + + var settings = SettingsManager.Default.GetOrCreate(); + + var demo = settings.DemoMode; + + if (!demo) + { + if (String.IsNullOrWhiteSpace(settings.EmbeddedComPort)) + { + TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate().MachineScanningTimeoutSeconds); + + LogManager.Default.Log("Scanning for machine on available serial ports..."); + Transport.Discovery.UsbCommunicationScanner scanner = new Transport.Discovery.UsbCommunicationScanner(UsbSerialBaudRates.BR_115200); + var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, timeout); + + LogManager.Default.Log("Machine discovered on port: " + response.Adapter.Address); + LogManager.Default.Log("Device Information:"); + LogManager.Default.Log(response.Response.DeviceInformation.ToJsonString()); + + LogManager.Default.Log("Disconnecting machine operator..."); + machineOperator.Adapter = response.Adapter; + machineOperator.JobHandlingMode = JobHandlerModes.SettingUp; + LogManager.Default.Log("Connecting machine operator..."); + await machineOperator.Connect(); + } + else + { + LogManager.Default.Log($"Connecting to machine on {settings.EmbeddedComPort}..."); + + UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200); + machineOperator.Adapter = adapter; + machineOperator.JobHandlingMode = JobHandlerModes.SettingUp; + await machineOperator.Connect(); + } + } + else + { + LogManager.Default.Log("Application in demo mode!"); + + LogManager.Default.Log("Starting embedded emulator..."); + MachineEmulator emulator = new MachineEmulator(new BasicTransporter(new MemoryTransportAdapter("emulator"))); + await emulator.Start(); + + LogManager.Default.Log("Emulator started. Connecting to emulator..."); + + MemoryTransportAdapter adapter = new MemoryTransportAdapter("emulator"); + machineOperator.Adapter = adapter; + machineOperator.JobHandlingMode = JobHandlerModes.SettingUp; + LogManager.Default.Log("Connecting machine operator..."); + await machineOperator.Connect(); + } + + return machineOperator; + } + /// /// Tries to connect to the machine by scanning all available serial ports. /// The timeout for a scan cycle is specified on . diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/DefaultFirmwareUpgrader.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/DefaultFirmwareUpgrader.cs new file mode 100644 index 000000000..bc8d3d718 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/DefaultFirmwareUpgrader.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Upgrade; +using Tango.PPC.Common.Connection; + +namespace Tango.PPC.Common.FirmwareUpgrade +{ + public class DefaultFirmwareUpgrader : IFirmwareUpgrader + { + public async Task PerformUpgrade() + { + var tfpPath = Path.Combine(Core.Helpers.AssemblyHelper.GetCurrentAssemblyFolder(), "firmware_package.tfp"); + var stream = new FileStream(tfpPath, FileMode.Open); + var handler = await PerformUpgrade(stream); + handler.Failed += (_, __) => stream.Dispose(); + handler.Completed += (_, __) => stream.Dispose(); + handler.Canceled += (_, __) => stream.Dispose(); + return handler; + } + + public async Task PerformUpgrade(Stream tfpStream) + { + var op = await DefaultMachineProvider.CreateMinimalMachineOperator(); + return await op.UpgradeFirmware(tfpStream); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/IFirmwareUpgrader.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/IFirmwareUpgrader.cs new file mode 100644 index 000000000..64f697833 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/FirmwareUpgrade/IFirmwareUpgrader.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Upgrade; + +namespace Tango.PPC.Common.FirmwareUpgrade +{ + public interface IFirmwareUpgrader + { + /// + /// Performs a firmware upgrade. + /// + Task PerformUpgrade(); + + /// + /// Performs a firmware upgrade from the specified TFP stream . + /// + Task PerformUpgrade(Stream tfpStream); + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs index eefb298f7..3c3a6e19b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs @@ -17,6 +17,7 @@ namespace Tango.PPC.Common.Navigation LoginView, MachineSetupView, MachineUpdateView, + FirmwareUpgradeView, ExternalBridgeView, StorageView, HomeModule, diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 67e5a4548..8fe107074 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -128,6 +128,8 @@ + + @@ -325,7 +327,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindow.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindow.xaml index 327cab826..b347ce2c1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindow.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindow.xaml @@ -8,7 +8,7 @@ xmlns:examiner="clr-namespace:Tango.SQLExaminer;assembly=Tango.SQLExaminer" xmlns:local="clr-namespace:Tango.PPC.Publisher" mc:Ignorable="d" - Title="Tango PPC Publisher" Height="980" Width="500" d:DataContext="{d:DesignInstance Type=local:MainWindowVM, IsDesignTimeCreatable=False}"> + Title="Tango PPC Publisher" Height="1000" Width="500" d:DataContext="{d:DesignInstance Type=local:MainWindowVM, IsDesignTimeCreatable=False}"> @@ -80,6 +80,12 @@ + Firmware Upgrade Package + + + + + Comments diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs index 081aeba22..881403ea8 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs @@ -70,6 +70,13 @@ namespace Tango.PPC.Publisher set { _currentVersion = value; RaisePropertyChangedAuto(); } } + private String _firmwareUpgradeFilePath; + public String FirmwareUpgradeFilePath + { + get { return _firmwareUpgradeFilePath; } + set { _firmwareUpgradeFilePath = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection _provisionSequenceItems; public ObservableCollection ProvisionSequenceItems { @@ -145,6 +152,8 @@ namespace Tango.PPC.Publisher public RelayCommand CreateTupCommand { get; set; } + public RelayCommand FirmwareUpgradePackageBrowseCommand { get; set; } + public MainWindowVM() { SelectedBuildConfiguration = "Release"; @@ -174,6 +183,7 @@ namespace Tango.PPC.Publisher PublishCommand = new RelayCommand(Publish); CreateTupCommand = new RelayCommand(PublishTupFile); + FirmwareUpgradePackageBrowseCommand = new RelayCommand(BrowseFirmwareUpgradePackage); } private async void OnSelectedMachineVersionChanged() @@ -288,6 +298,17 @@ namespace Tango.PPC.Publisher } } + private void BrowseFirmwareUpgradePackage() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select Tango Firmware Package"; + dlg.Filter = "Tango Firmware Package Files|*.tfp"; + if (dlg.ShowDialog().Value) + { + FirmwareUpgradeFilePath = dlg.FileName; + } + } + private void ShowError(String error) { MessageBox.Show(error, "PPC Publisher", MessageBoxButton.OK, MessageBoxImage.Error); @@ -303,8 +324,6 @@ namespace Tango.PPC.Publisher return MessageBox.Show(message, "PPC Publisher", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes; } - - private void CreateTupPackage(String filePath) { String _appPath = String.Format(AppDomain.CurrentDomain.BaseDirectory + "..\\{0}", SelectedBuildConfiguration); @@ -312,6 +331,8 @@ namespace Tango.PPC.Publisher using (ZipFile zip = new ZipFile()) { + zip.AddFile(FirmwareUpgradeFilePath, "/"); + String provision_dir = "Provision Scripts"; zip.AddDirectoryByName(provision_dir); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/chip_128px.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/chip_128px.png new file mode 100644 index 000000000..8e7ec780c Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/chip_128px.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 6b566dcd2..c5dab127c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -62,6 +62,11 @@ namespace Tango.PPC.UI.PPCApplication /// public event EventHandler SetupRequired; + /// + /// Occurs when firmware upgrade is required. + /// + public event EventHandler FirmwareUpgradeRequired; + /// /// Occurs when the main window content has been rendered. /// @@ -159,7 +164,7 @@ namespace Tango.PPC.UI.PPCApplication if (App.StartupArgs.Contains("-update_ok")) { LogManager.Log("Application started with '-update_ok' startup arguments. The application has been successfully updated."); - settings.ApplicationState = ApplicationStates.Ready; + settings.ApplicationState = ApplicationStates.FirmwareUpgrade; settings.Save(); } @@ -191,6 +196,11 @@ namespace Tango.PPC.UI.PPCApplication LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking setup required event!"); SetupRequired?.Invoke(this, new EventArgs()); } + else if (settings.ApplicationState == ApplicationStates.FirmwareUpgrade) + { + LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking firmware upgrade required event!"); + FirmwareUpgradeRequired?.Invoke(this, new EventArgs()); + } else { PostDbInitialize(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs index d61c0fb6a..629afdfea 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Properties/AssemblyInfo.cs @@ -8,4 +8,4 @@ using System.Windows; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Tango PPC Application")] -[assembly: AssemblyVersion("2.0.10.1608")] +[assembly: AssemblyVersion("2.0.11.1608")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index d74e989e9..ed0092a4d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -133,6 +133,7 @@ + @@ -140,12 +141,16 @@ + ExternalBridgeView.xaml + + FirmwareUpgradeView.xaml + LayoutView.xaml @@ -203,6 +208,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -393,6 +402,7 @@ Tango.ColorLib.dll PreserveNewest + @@ -459,11 +469,13 @@ copy /Y "$(SolutionDir)Referenced Assemblies\mscoree.dll" "$(TargetDir)" copy /Y "$(SolutionDir)Referenced Assemblies\msvcp140d.dll" "$(TargetDir)" copy /Y "$(SolutionDir)Referenced Assemblies\ucrtbased.dll" "$(TargetDir)" copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140.dll" "$(TargetDir)" -copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" +copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" + +del "$(TargetDir)firmware_package.tfp" - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 11751d822..4ab3f26bd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -10,6 +10,7 @@ using Tango.PPC.Common.Connectivity; using Tango.PPC.Common.Diagnostics; using Tango.PPC.Common.EventLogging; using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Common.FirmwareUpgrade; using Tango.PPC.Common.MachineSetup; using Tango.PPC.Common.MachineUpdate; using Tango.PPC.Common.Modules; @@ -75,6 +76,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); @@ -88,6 +90,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); @@ -163,6 +166,14 @@ namespace Tango.PPC.UI } } + public static FirmwareUpgradeViewVM FirmwareUpgradeViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } + public static LoadingErrorViewVM LoadingErrorViewVM { get diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs new file mode 100644 index 000000000..b7c36f263 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.PPC.Common; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.FirmwareUpgrade; +using Tango.PPC.Common.Navigation; +using Tango.PPC.UI.ViewsContracts; + +namespace Tango.PPC.UI.ViewModels +{ + public class FirmwareUpgradeViewVM : PPCViewModel + { + public enum FirmUpgradeView + { + FirmwareProgressView, + FirmwareCompletedView, + FirmwareFailedView, + } + + + private IFirmwareUpgrader _firmwareUpgrader; + + private String _status; + /// + /// Gets or sets the firmware upgrade status. + /// + public String Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + private long _maxProgress; + /// + /// Gets or sets the firmware upgrade maximum progress. + /// + public long MaxProgress + { + get { return _maxProgress; } + set { _maxProgress = value; RaisePropertyChangedAuto(); } + } + + private long _progress; + /// + /// Gets or sets the firmware upgrade progress. + /// + public long Progress + { + get { return _progress; } + set { _progress = value; RaisePropertyChangedAuto(); } + } + + private bool _isIntermediate; + /// + /// Gets or sets a value indicating whether firmware upgrade progress is intermediate. + /// + public bool IsIntermediate + { + get { return _isIntermediate; } + set { _isIntermediate = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the complete command. + /// + public RelayCommand CompleteCommand { get; set; } + + public RelayCommand TryAgainCommand { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The application manager. + /// The firmware upgrader. + public FirmwareUpgradeViewVM(IPPCApplicationManager applicationManager, IFirmwareUpgrader firmwareUpgrader) + { + _firmwareUpgrader = firmwareUpgrader; + applicationManager.FirmwareUpgradeRequired += ApplicationManager_FirmwareUpgradeRequired; + CompleteCommand = new RelayCommand(Complete); + TryAgainCommand = new RelayCommand(TryAgain); + } + + private async void Upgrade() + { + IsIntermediate = true; + Progress = 0; + Status = "Connecting to the embedded firmware device..."; + await Task.Delay(2000); + await NavigateTo(FirmUpgradeView.FirmwareProgressView); + try + { + var handler = await _firmwareUpgrader.PerformUpgrade(); + IsIntermediate = false; + + handler.Progress += (_, e) => + { + MaxProgress = e.Total; + Progress = e.Current; + Status = e.Message; + + if (e.Status != Integration.Upgrade.FirmwareUpgradeStatus.Uploading) + { + IsIntermediate = true; + } + }; + handler.Canceled += (_, __) => + { + NavigateTo(FirmUpgradeView.FirmwareFailedView); + }; + handler.Failed += (_, ex) => + { + NavigateTo(FirmUpgradeView.FirmwareFailedView); + }; + handler.Completed += (_, __) => + { + NavigateTo(FirmUpgradeView.FirmwareCompletedView); + }; + } + catch (Exception ex) + { + LogManager.Log(ex); + await NavigateTo(FirmUpgradeView.FirmwareFailedView); + } + } + + private void Complete() + { + Restart(); + } + + private async void TryAgain() + { + await NavigateTo(FirmUpgradeView.FirmwareProgressView); + Upgrade(); + } + + private async void ApplicationManager_FirmwareUpgradeRequired(object sender, EventArgs e) + { + LogManager.Log("SetupRequired event received. Navigating to FirmwareUpgradeView..."); + await NavigationManager.NavigateTo(NavigationView.FirmwareUpgradeView); + Upgrade(); + } + + private void Restart() + { + Settings.ApplicationState = ApplicationStates.Ready; + Settings.Save(); + ApplicationManager.Restart(); + } + + /// + /// Navigates to the specified view. + /// + /// The view. + private Task NavigateTo(FirmUpgradeView view) + { + return View.NavigateTo(view); + } + + public override void OnApplicationStarted() + { + + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index f778ff5a8..02cc4ba33 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -14,6 +14,7 @@ using Tango.Logging; using Tango.PMR.Connection; using Tango.PPC.Common; using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; using Tango.PPC.Common.MachineSetup; using Tango.PPC.Common.Navigation; using Tango.PPC.UI.ViewsContracts; @@ -46,8 +47,6 @@ namespace Tango.PPC.UI.ViewModels WelcomeView, WiFiSelectionView, WiFiTestView, - EmbeddedWelcomeView, - EmbeddedTestView, SetupWelcomeView, SetupProgressView, SetupCompletedView, @@ -103,13 +102,6 @@ namespace Tango.PPC.UI.ViewModels set { _state = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } - private String _machineConnectionStatus; - public String MachineConnectionStatus - { - get { return _machineConnectionStatus; } - set { _machineConnectionStatus = value; RaisePropertyChangedAuto(); } - } - #endregion #region Commands @@ -124,16 +116,6 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand NavigateToWiFiCommand { get; set; } - /// - /// Gets or sets the skip embedded test command. - /// - public RelayCommand SkipEmbeddedTestCommand { get; set; } - - /// - /// Gets or sets the perform embedded test command. - /// - public RelayCommand PerformEmbeddedTestCommand { get; set; } - /// /// Gets or sets the install command. /// @@ -168,8 +150,6 @@ namespace Tango.PPC.UI.ViewModels NavigateToWiFiCommand = new RelayCommand(EnsureWiFi); - PerformEmbeddedTestCommand = new RelayCommand(PerformEmbeddedTest); - SkipEmbeddedTestCommand = new RelayCommand(SkipEmbeddedTest); InstallCommand = new RelayCommand(Install); RestartCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.WelcomeView); }); } @@ -260,7 +240,7 @@ namespace Tango.PPC.UI.ViewModels if (connected) { - await NavigateTo(MachineSetupView.EmbeddedWelcomeView); + await NavigateTo(MachineSetupView.SetupWelcomeView); } else { @@ -282,78 +262,6 @@ namespace Tango.PPC.UI.ViewModels #endregion - #region Embedded - - private async void PerformEmbeddedTest() - { - await NavigateTo(MachineSetupView.EmbeddedTestView); - - try - { - MachineConnectionStatus = "Scanning for the machine..."; - - LogManager.Log("Starting machine connection procedure..."); - - TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate().MachineScanningTimeoutSeconds); - - LogManager.Log("Scanning for machine on available serial ports..."); - Transport.Discovery.UsbCommunicationScanner scanner = new Transport.Discovery.UsbCommunicationScanner(UsbSerialBaudRates.BR_9600); - - scanner.ScanningPort += (port) => - { - MachineConnectionStatus = $"Scanning for the machine on {port}..."; - }; - - var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, timeout); - - MachineConnectionStatus = "Machine discovered on port: " + response.Adapter.Address + ", trying to connect..."; - - LogManager.Log("Machine discovered on port: " + response.Adapter.Address); - LogManager.Log("Device Information:"); - LogManager.Log(response.Response.DeviceInformation.ToJsonString()); - - LogManager.Log("Disconnecting machine operator..."); - - IMachineOperator op = new MachineOperator(response.Adapter); - - op.EnableDiagnostics = false; - op.EnableEmbeddedDebugging = false; - op.EnableEventsNotification = false; - - LogManager.Log("Connecting machine operator..."); - await op.Connect(); - - MachineConnectionStatus = "Test completed successfully!"; - - await Task.Delay(1000); - - try - { - await op.Disconnect(); - } - catch { } - - await NavigateTo(MachineSetupView.SetupWelcomeView); - } - catch (Exception ex) - { - LogManager.Log(ex, "Error while trying to scan and connect to the machine."); - MachineConnectionStatus = "Test Failed!"; - await Task.Delay(2000); - await NavigateTo(MachineSetupView.EmbeddedWelcomeView); - } - } - - private async void SkipEmbeddedTest() - { - if (await NotificationProvider.ShowQuestion("Are you sure you want to skip the machine communication test?")) - { - await NavigateTo(MachineSetupView.SetupWelcomeView); - } - } - - #endregion - #region Setup private async void Install() @@ -371,7 +279,7 @@ namespace Tango.PPC.UI.ViewModels Settings.Save(); State = MachineSetupStates.Completed; LogManager.Log("Machine setup completed."); - await NavigateTo(MachineSetupView.SetupCompletedView); + CompleteSetup(); } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index fc1de5de1..108752976 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -167,7 +167,7 @@ namespace Tango.PPC.UI.ViewModels { _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, Settings.MachineServiceAddress); LogManager.Log("Machine update completed."); - await NavigateTo(MachineUpdateView.UpdateCompletedView); + CompleteUpdate(); } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml new file mode 100644 index 000000000..985e00291 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml @@ -0,0 +1,55 @@ + + + + + + + + FIRMWARE UPGRADE + + + + + + + Now it's time to perform a firmware upgrade and verify the connection to the machine's embedded firmware. Please wait.. + + + + + + + + + + Machine is ready! + + RESTART + + + + + + + Firmware upgrade failed, tap 'try again' to restart the process. + + TRY AGAIN + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml.cs new file mode 100644 index 000000000..867309d6a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml.cs @@ -0,0 +1,47 @@ +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; +using Tango.Core.DI; +using Tango.PPC.UI.ViewModels; +using Tango.PPC.UI.ViewsContracts; + +namespace Tango.PPC.UI.Views +{ + /// + /// Interaction logic for FirmwareUpgradeView.xaml + /// + public partial class FirmwareUpgradeView : UserControl, IFirmwareUpgradeView + { + public FirmwareUpgradeView() + { + InitializeComponent(); + TangoIOC.Default.Register(this); + } + + public Task NavigateTo(FirmwareUpgradeViewVM.FirmUpgradeView view) + { + TaskCompletionSource source = new TaskCompletionSource(); + + this.BeginInvoke(() => + { + navigationControl.NavigateTo(view.ToString(), () => + { + source.SetResult(new object()); + }); + }); + + return source.Task; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml index d397cfa35..4ac6dab92 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml @@ -33,7 +33,7 @@ - + Welcome to the machine setup wizard! In the next steps the software will gather required information, perform tests and apply an initial configuration to this machine. @@ -67,29 +67,9 @@ - - - - It is recommended to perform a quick communication test with the machine before proceeding. Please turn on and connect the machine, then tap 'perform test'. - - - - SKIP - PERFORM TEST - - - - - - - - - - - - + The next step is to download the latest software package and synchronize the machine data. Please enter your machine serial number and press 'install'. @@ -110,7 +90,7 @@ - Please wait while we setting up this machine. + Please wait while we're setting up this machine. Do not turn off this PC. @@ -126,7 +106,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index 3436bb3bb..ed15180c4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -84,6 +84,7 @@ + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IFirmwareUpgradeView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IFirmwareUpgradeView.cs new file mode 100644 index 000000000..c32af83ba --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IFirmwareUpgradeView.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; +using static Tango.PPC.UI.ViewModels.FirmwareUpgradeViewVM; + +namespace Tango.PPC.UI.ViewsContracts +{ + public interface IFirmwareUpgradeView : IPPCView + { + /// + /// Navigates to the specified firmware upgrade view. + /// + /// The view. + Task NavigateTo(FirmUpgradeView view); + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs index a98072458..7564022d1 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs @@ -25,13 +25,14 @@ namespace Tango.Stubs.CLI private static void Run(string[] args) { - if (args == null || args.Length < 2 || args[0] == "?") + if (args == null || args.Length < 3 || args[0] == "?") { PrintHelp(); } String comPort = args[0].ToUpper(); - String stubName = args[1]; + String baudRate = args[1]; + String stubName = args[2]; var stubType = GetAvailableRequestResponseStubs().SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower()); if (stubType == null) @@ -41,7 +42,7 @@ namespace Tango.Stubs.CLI var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance); - if (stubProps.Length > args.Length - 2) + if (stubProps.Length > args.Length - 3) { PrintError("Not enough arguments for " + stubType.Name + "."); } @@ -54,7 +55,7 @@ namespace Tango.Stubs.CLI Object request = Activator.CreateInstance(stubType); - int argIndex = 2; + int argIndex = 3; foreach (var prop in stubProps) { String arg = args[argIndex++].ToString(); @@ -78,7 +79,14 @@ namespace Tango.Stubs.CLI byte[] requestData = container.ToByteArray(); - using (UsbTransportAdapter adapter = new UsbTransportAdapter(comPort)) + UsbSerialBaudRates rate = UsbSerialBaudRates.BR_115200; + + if (!Enum.TryParse("BR_" + baudRate, out rate)) + { + throw new ArgumentException("Invalid baud rate specified."); + } + + using (UsbTransportAdapter adapter = new UsbTransportAdapter(comPort, rate)) { Console.WriteLine("Connecting to machine on " + comPort + "..."); adapter.Connect().Wait(); @@ -112,7 +120,7 @@ namespace Tango.Stubs.CLI Console.WriteLine("Response Received:"); var type = typeof(MessageFactory).Assembly.GetType("Tango.PMR.Stubs." + responseContainer.Type.ToString()); MessageParser parser = type.GetProperty("Parser").GetValue(container) as MessageParser; - IMessage message = parser.ParseFrom(container.Data); + IMessage message = parser.ParseFrom(responseContainer.Data); Console.WriteLine(JsonConvert.SerializeObject(message, Formatting.Indented)); done = true; }); @@ -125,7 +133,7 @@ namespace Tango.Stubs.CLI } catch (Exception ex) { - PrintError(ex.Message); + PrintError(ex.FlattenMessage()); } } @@ -176,7 +184,7 @@ namespace Tango.Stubs.CLI { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(error); - Console.ForegroundColor = ConsoleColor.White; + Console.ForegroundColor = ConsoleColor.Gray; ExitError(); } -- cgit v1.3.1