diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-06 15:48:47 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-06 15:48:47 +0200 |
| commit | e47f736bca350350a55fa287093dad560da8f678 (patch) | |
| tree | e74e726fd90cb6e791ecb5872010cb6eb61a13c8 /Software/Visual_Studio | |
| parent | 1eb3962e5923cbb398c5ebad505e69f4617f963f (diff) | |
| download | Tango-e47f736bca350350a55fa287093dad560da8f678.tar.gz Tango-e47f736bca350350a55fa287093dad560da8f678.zip | |
Working on PPC firmware upgrade !!!
Diffstat (limited to 'Software/Visual_Studio')
24 files changed, 513 insertions, 140 deletions
diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk Binary files differindex c7966c7a9..fe3b0d60c 100644 --- a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk +++ b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk 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 @@ -41,6 +41,11 @@ namespace Tango.PPC.Common.Application event EventHandler SetupRequired; /// <summary> + /// Occurs when firmware upgrade is required. + /// </summary> + event EventHandler FirmwareUpgradeRequired; + + /// <summary> /// Occurs when the application has encountered an error when initializing. /// </summary> event EventHandler<Exception> ApplicationInitializationError; 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 /// </summary> SemiSetup = 1, /// <summary> - /// Application is ready to run as normal. + /// The application has been updated and should start in firmware upgrade mode. /// </summary> - Ready = 2, + FirmwareUpgrade = 2, /// <summary> - /// Updater utility should update the application assemblies and start the main application with startup arguments. + /// Application is ready to run as normal. /// </summary> - 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<IMachineOperator> 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<PPCSettings>(); + + var demo = settings.DemoMode; + + if (!demo) + { + if (String.IsNullOrWhiteSpace(settings.EmbeddedComPort)) + { + TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate<PPCSettings>().MachineScanningTimeoutSeconds); + + LogManager.Default.Log("Scanning for machine on available serial ports..."); + Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(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; + } + /// <summary> /// Tries to connect to the machine by scanning all available serial ports. /// The timeout for a scan cycle is specified on <see cref="PPCSettings.MachineScanningTimeoutSeconds"/>. 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<FirmwareUpgradeHandler> 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<FirmwareUpgradeHandler> 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 + { + /// <summary> + /// Performs a firmware upgrade. + /// </summary> + Task<FirmwareUpgradeHandler> PerformUpgrade(); + + /// <summary> + /// Performs a firmware upgrade from the specified TFP stream . + /// </summary> + Task<FirmwareUpgradeHandler> 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 @@ <Compile Include="ExtensionMethods\ObservableCollectionExtensions.cs" /> <Compile Include="ExternalBridge\IPPCExternalBridgeService.cs" /> <Compile Include="ExternalBridge\PPCExternalBridgeService.cs" /> + <Compile Include="FirmwareUpgrade\DefaultFirmwareUpgrader.cs" /> + <Compile Include="FirmwareUpgrade\IFirmwareUpgrader.cs" /> <Compile Include="IPPCView.cs" /> <Compile Include="MachineSetup\IMachineSetupManager.cs" /> <Compile Include="MachineSetup\MachineSetupManager.cs" /> @@ -325,7 +327,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ 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}"> <Window.Resources> <converters:EnumToItemsSourceConverter x:Key="EnumToItemsSourceConverter" /> @@ -80,6 +80,12 @@ </DataGrid.Columns> </DataGrid> + <TextBlock Margin="0 20 0 0">Firmware Upgrade Package</TextBlock> + <DockPanel Margin="0 5 0 0"> + <Button DockPanel.Dock="Right" Margin="10 0 0 0" Command="{Binding FirmwareUpgradePackageBrowseCommand}">BROWSE</Button> + <TextBox IsReadOnly="True" Text="{Binding FirmwareUpgradeFilePath}"></TextBox> + </DockPanel> + <StackPanel Margin="0 30 0 0"> <TextBlock>Comments</TextBlock> 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<SequenceItem> _provisionSequenceItems; public ObservableCollection<SequenceItem> 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 Binary files differnew file mode 100644 index 000000000..8e7ec780c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/chip_128px.png 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 @@ -63,6 +63,11 @@ namespace Tango.PPC.UI.PPCApplication public event EventHandler SetupRequired; /// <summary> + /// Occurs when firmware upgrade is required. + /// </summary> + public event EventHandler FirmwareUpgradeRequired; + + /// <summary> /// Occurs when the main window content has been rendered. /// </summary> public event EventHandler ContentRendered; @@ -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 @@ <Compile Include="Threading\DefaultDispatcherProvider.cs" /> <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\ExternalBridgeViewVM.cs" /> + <Compile Include="ViewModels\FirmwareUpgradeViewVM.cs" /> <Compile Include="ViewModels\LayoutViewVM.cs" /> <Compile Include="ViewModels\LoadingErrorViewVM.cs" /> <Compile Include="ViewModels\LoadingViewVM.cs" /> @@ -140,12 +141,16 @@ <Compile Include="ViewModels\MachineSetupViewVM.cs" /> <Compile Include="ViewModels\MainViewVM.cs" /> <Compile Include="ViewModels\MachineUpdateViewVM.cs" /> + <Compile Include="ViewsContracts\IFirmwareUpgradeView.cs" /> <Compile Include="ViewsContracts\ILayoutView.cs" /> <Compile Include="ViewsContracts\IMachineSetupView.cs" /> <Compile Include="ViewsContracts\IMachineUpdateView.cs" /> <Compile Include="Views\ExternalBridgeView.xaml.cs"> <DependentUpon>ExternalBridgeView.xaml</DependentUpon> </Compile> + <Compile Include="Views\FirmwareUpgradeView.xaml.cs"> + <DependentUpon>FirmwareUpgradeView.xaml</DependentUpon> + </Compile> <Compile Include="Views\LayoutView.xaml.cs"> <DependentUpon>LayoutView.xaml</DependentUpon> </Compile> @@ -203,6 +208,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\FirmwareUpgradeView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Views\LayoutView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -393,6 +402,7 @@ <Link>Tango.ColorLib.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Resource Include="Images\chip_128px.png" /> <Resource Include="Images\warning-red.png" /> <Resource Include="Images\update.png" /> <Resource Include="Images\flash-drive.png" /> @@ -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)"</PostBuildEvent> +copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" + +del "$(TargetDir)firmware_package.tfp"</PostBuildEvent> </PropertyGroup> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ 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<IPPCExternalBridgeService, PPCExternalBridgeService>(); TangoIOC.Default.Register<IMachineSetupManager, MachineSetupManager>(); TangoIOC.Default.Register<IMachineUpdateManager, MachineUpdateManager>(); + TangoIOC.Default.Register<IFirmwareUpgrader, DefaultFirmwareUpgrader>(); TangoIOC.Default.Register<IPrintingManager, DefaultPrintingManager>(); TangoIOC.Default.Register<IConnectivityProvider, DefaultConnectivityProvider>(); TangoIOC.Default.Register<IStorageProvider, DefaultStorageProvider>(); @@ -88,6 +90,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<ExternalBridgeViewVM>(); TangoIOC.Default.Register<MachineSetupViewVM>(); TangoIOC.Default.Register<MachineUpdateViewVM>(); + TangoIOC.Default.Register<FirmwareUpgradeViewVM>(); TangoIOC.Default.Register<LoadingErrorViewVM>(); @@ -163,6 +166,14 @@ namespace Tango.PPC.UI } } + public static FirmwareUpgradeViewVM FirmwareUpgradeViewVM + { + get + { + return TangoIOC.Default.GetInstance<FirmwareUpgradeViewVM>(); + } + } + 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<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) { 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 @@ +<UserControl x:Class="Tango.PPC.UI.Views.FirmwareUpgradeView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" + xmlns:local="clr-namespace:Tango.PPC.UI.Views" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:global="clr-namespace:Tango.PPC.UI" + xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" + mc:Ignorable="d" + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:FirmwareUpgradeViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.FirmwareUpgradeViewVM}"> + <Grid Background="{StaticResource TangoPrimaryBackgroundBrush}"> + <Grid> + <DockPanel> + + <StackPanel DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 100 0 0"> + <Image Source="/Images/chip_128px.png" Width="128" Height="128" /> + <TextBlock HorizontalAlignment="Center" FontSize="{StaticResource TangoHeaderFontSize}" Margin="50">FIRMWARE UPGRADE</TextBlock> + </StackPanel> + + <controls:NavigationControl x:Name="navigationControl" TransitionType="Slide" KeepElementsAttached="True" Margin="0 20 0 0" SelectedIndex="0"> + <Grid controls:NavigationControl.NavigationName="FirmwareProgressView"> + <StackPanel HorizontalAlignment="Center" Margin="0 0 0 0"> + <TextBlock TextAlignment="Center" LineHeight="40" Margin="20 0" TextWrapping="Wrap" FontSize="{StaticResource TangoTitleFontSize}"> + <Run>Now it's time to perform a firmware upgrade and verify the connection to the machine's embedded firmware. Please wait..</Run> + </TextBlock> + <TextBlock Text="{Binding Status}" DockPanel.Dock="Top" Margin="20 300 20 0" FontSize="{StaticResource TangoTitleFontSize}" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center"></TextBlock> + <touch:TouchProgressBar Height="20" Width="700" Margin="0 40 0 0" IsIndeterminate="{Binding IsIntermediate}" Maximum="{Binding MaxProgress}" Value="{Binding Progress}" /> + </StackPanel> + </Grid> + + <Grid controls:NavigationControl.NavigationName="FirmwareCompletedView"> + <StackPanel HorizontalAlignment="Center" Margin="0 50 0 0"> + <touch:TouchIcon Icon="Check" Foreground="{StaticResource TangoPrimaryAccentBrush}" Width="70" Height="70" /> + <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0 10 0 0" Foreground="{StaticResource TangoPrimaryAccentBrush}" FontSize="{StaticResource TangoHeaderFontSize}">Machine is ready!</TextBlock> + + <touch:TouchButton Margin="0 200 0 0" Padding="20" Width="300" CornerRadius="35" Command="{Binding CompleteCommand}">RESTART</touch:TouchButton> + </StackPanel> + </Grid> + + <Grid controls:NavigationControl.NavigationName="FirmwareFailedView"> + <StackPanel HorizontalAlignment="Center" Margin="0 50 0 0"> + <touch:TouchIcon Icon="AlertOctagon" Foreground="{StaticResource TangoErrorBrush}" Width="70" Height="70" /> + <TextBlock VerticalAlignment="Center" Margin="0 10 0 0" Foreground="{StaticResource TangoErrorBrush}" FontSize="{StaticResource TangoTitleFontSize}">Firmware upgrade failed, tap 'try again' to restart the process.</TextBlock> + + <touch:TouchButton Margin="0 200 0 0" Padding="20" Width="300" CornerRadius="35" Command="{Binding TryAgainCommand}">TRY AGAIN</touch:TouchButton> + </StackPanel> + </Grid> + + </controls:NavigationControl> + </DockPanel> + </Grid> + </Grid> +</UserControl> 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 +{ + /// <summary> + /// Interaction logic for FirmwareUpgradeView.xaml + /// </summary> + public partial class FirmwareUpgradeView : UserControl, IFirmwareUpgradeView + { + public FirmwareUpgradeView() + { + InitializeComponent(); + TangoIOC.Default.Register<IFirmwareUpgradeView>(this); + } + + public Task NavigateTo(FirmwareUpgradeViewVM.FirmUpgradeView view) + { + TaskCompletionSource<object> source = new TaskCompletionSource<object>(); + + 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 @@ <Grid controls:NavigationControl.NavigationName="WelcomeView"> <StackPanel HorizontalAlignment="Center" Margin="0 100 0 0"> - <TextBlock TextAlignment="Center" LineHeight="20" Margin="20 0" TextWrapping="Wrap" FontSize="{StaticResource TangoTitleFontSize}"> + <TextBlock TextAlignment="Center" LineHeight="40" Margin="20 0" TextWrapping="Wrap" FontSize="{StaticResource TangoTitleFontSize}"> <Run>Welcome to the machine setup wizard!</Run> <Run>In the next steps the software will gather required information, perform tests and apply an initial configuration to this machine.</Run> <LineBreak/> @@ -67,29 +67,9 @@ </StackPanel> </Grid> - <Grid controls:NavigationControl.NavigationName="EmbeddedWelcomeView"> - <StackPanel HorizontalAlignment="Center" Margin="0 100 0 0"> - <TextBlock TextAlignment="Center" LineHeight="20" Margin="20 0" TextWrapping="Wrap" FontSize="{StaticResource TangoTitleFontSize}"> - <Run>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'.</Run> - </TextBlock> - - <StackPanel Orientation="Horizontal" Margin="0 250 0 0" HorizontalAlignment="Center"> - <touch:TouchButton Margin="10" Background="{StaticResource TangoGrayBrush}" Padding="20" Width="300" CornerRadius="35" Command="{Binding SkipEmbeddedTestCommand}">SKIP</touch:TouchButton> - <touch:TouchButton Margin="10" Padding="20" Width="300" CornerRadius="35" Command="{Binding PerformEmbeddedTestCommand}">PERFORM TEST</touch:TouchButton> - </StackPanel> - </StackPanel> - </Grid> - - <Grid controls:NavigationControl.NavigationName="EmbeddedTestView"> - <StackPanel HorizontalAlignment="Center" Margin="0 200 0 0"> - <TextBlock Text="{Binding MachineConnectionStatus}" DockPanel.Dock="Top" Margin="20 0" FontSize="{StaticResource TangoTitleFontSize}" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center"></TextBlock> - <touch:TouchProgressBar Height="20" Width="700" Margin="0 40 0 0" IsIndeterminate="True" /> - </StackPanel> - </Grid> - <Grid controls:NavigationControl.NavigationName="SetupWelcomeView"> <StackPanel> - <TextBlock TextAlignment="Center" LineHeight="25" FontSize="{StaticResource TangoTitleFontSize}" Margin="40 0" TextWrapping="Wrap"> + <TextBlock TextAlignment="Center" LineHeight="40" FontSize="{StaticResource TangoTitleFontSize}" Margin="40 0" TextWrapping="Wrap"> The next step is to download the latest software package and synchronize the machine data. Please enter your machine serial number and press 'install'. </TextBlock> @@ -110,7 +90,7 @@ <Grid controls:NavigationControl.NavigationName="SetupProgressView"> <StackPanel> <TextBlock TextAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}"> - <Run>Please wait while we setting up this machine.</Run> + <Run>Please wait while we're setting up this machine.</Run> <Run>Do not turn off this PC.</Run> </TextBlock> @@ -126,7 +106,7 @@ </Style> </touch:TouchBusyIndicator.Style> </touch:TouchBusyIndicator> - <touch:TouchStepProgressBar FontSize="10" Width="720" Height="50" Margin="0 100 0 0" ItemsSource="{Binding Source={x:Type setup:MachineSetupSteps},Converter={StaticResource EnumToItemsSourceConverter}}" SelectedValue="{Binding MachineSetupManager.CurrentStep}" SelectedValuePath="Value" DisplayMemberPath="DisplayName" /> + <touch:TouchStepProgressBar FontSize="12" Width="720" Height="50" Margin="0 100 0 0" ItemsSource="{Binding Source={x:Type setup:MachineSetupSteps},Converter={StaticResource EnumToItemsSourceConverter}}" SelectedValue="{Binding MachineSetupManager.CurrentStep}" SelectedValuePath="Value" DisplayMemberPath="DisplayName" /> <StackPanel Margin="100 100 100 0" Visibility="{Binding MachineSetupManager.CurrentStep,Converter={StaticResource EnumToVisibilityConverter},ConverterParameter='DownloadingPackage'}"> <TextBlock Text="{Binding MachineSetupManager.DownloadingPackagesStatus,Mode=OneWay}"></TextBlock> 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 @@ <local:ExternalBridgeView></local:ExternalBridgeView> <local:MachineSetupView></local:MachineSetupView> <local:MachineUpdateView></local:MachineUpdateView> + <local:FirmwareUpgradeView></local:FirmwareUpgradeView> </controls:NavigationControl> </touch:TouchPanel> 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 + { + /// <summary> + /// Navigates to the specified firmware upgrade view. + /// </summary> + /// <param name="view">The view.</param> + 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<UsbSerialBaudRates>("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(); } |
