aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-06 15:48:47 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-06 15:48:47 +0200
commite47f736bca350350a55fa287093dad560da8f678 (patch)
treee74e726fd90cb6e791ecb5872010cb6eb61a13c8 /Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels
parent1eb3962e5923cbb398c5ebad505e69f4617f963f (diff)
downloadTango-e47f736bca350350a55fa287093dad560da8f678.tar.gz
Tango-e47f736bca350350a55fa287093dad560da8f678.zip
Working on PPC firmware upgrade !!!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs169
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs98
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs2
3 files changed, 173 insertions, 96 deletions
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<IFirmwareUpgradeView>
+ {
+ public enum FirmUpgradeView
+ {
+ FirmwareProgressView,
+ FirmwareCompletedView,
+ FirmwareFailedView,
+ }
+
+
+ private IFirmwareUpgrader _firmwareUpgrader;
+
+ private String _status;
+ /// <summary>
+ /// Gets or sets the firmware upgrade status.
+ /// </summary>
+ public String Status
+ {
+ get { return _status; }
+ set { _status = value; RaisePropertyChangedAuto(); }
+ }
+
+ private long _maxProgress;
+ /// <summary>
+ /// Gets or sets the firmware upgrade maximum progress.
+ /// </summary>
+ public long MaxProgress
+ {
+ get { return _maxProgress; }
+ set { _maxProgress = value; RaisePropertyChangedAuto(); }
+ }
+
+ private long _progress;
+ /// <summary>
+ /// Gets or sets the firmware upgrade progress.
+ /// </summary>
+ public long Progress
+ {
+ get { return _progress; }
+ set { _progress = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isIntermediate;
+ /// <summary>
+ /// Gets or sets a value indicating whether firmware upgrade progress is intermediate.
+ /// </summary>
+ public bool IsIntermediate
+ {
+ get { return _isIntermediate; }
+ set { _isIntermediate = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the complete command.
+ /// </summary>
+ public RelayCommand CompleteCommand { get; set; }
+
+ public RelayCommand TryAgainCommand { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FirmwareUpgradeViewVM"/> class.
+ /// </summary>
+ /// <param name="applicationManager">The application manager.</param>
+ /// <param name="firmwareUpgrader">The firmware upgrader.</param>
+ 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();
+ }
+
+ /// <summary>
+ /// Navigates to the specified view.
+ /// </summary>
+ /// <param name="view">The view.</param>
+ 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
@@ -125,16 +117,6 @@ namespace Tango.PPC.UI.ViewModels
public RelayCommand NavigateToWiFiCommand { get; set; }
/// <summary>
- /// Gets or sets the skip embedded test command.
- /// </summary>
- public RelayCommand SkipEmbeddedTestCommand { get; set; }
-
- /// <summary>
- /// Gets or sets the perform embedded test command.
- /// </summary>
- public RelayCommand PerformEmbeddedTestCommand { get; set; }
-
- /// <summary>
/// Gets or sets the install command.
/// </summary>
public RelayCommand InstallCommand { get; set; }
@@ -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<PPCSettings>().MachineScanningTimeoutSeconds);
-
- LogManager.Log("Scanning for machine on available serial ports...");
- Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(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)
{