diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-08-04 12:59:34 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-08-04 12:59:34 +0300 |
| commit | c2471c200471e62b80133542183eb14af7c79bc7 (patch) | |
| tree | b8171eb2bbc94cac456c4b653efad315e17ae681 /Software/Visual_Studio | |
| parent | a21bffd43acbffcec36cc34bc8d03c2eb8358769 (diff) | |
| download | Tango-c2471c200471e62b80133542183eb14af7c79bc7.tar.gz Tango-c2471c200471e62b80133542183eb14af7c79bc7.zip | |
Implemented emergency switch.
Diffstat (limited to 'Software/Visual_Studio')
16 files changed, 359 insertions, 3 deletions
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 7b3d85b75..46a7eeb62 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -158,6 +158,9 @@ namespace Tango.PPC.Common.Connection await Task.Delay(1000); await MachineOperator.UploadHardwareConfiguration(Machine.Configuration.HardwareVersion, Machine.Configuration); MachineOperator.UseKeepAlive = true; + + MachineOperator.EmergencyNotificationProvider.Address = settings.EmergencyComPort; + MachineOperator.EmergencyNotificationProvider.IsEnabled = settings.EnableEmergencyNotifications; } } else @@ -180,6 +183,9 @@ namespace Tango.PPC.Common.Connection await Task.Delay(1000); await MachineOperator.UploadHardwareConfiguration(Machine.Configuration.HardwareVersion, Machine.Configuration); + + MachineOperator.EmergencyNotificationProvider.Address = settings.EmergencyComPort; + MachineOperator.EmergencyNotificationProvider.IsEnabled = settings.EnableEmergencyNotifications; } } catch (Exception ex) 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 e3129b970..b4562054c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Navigation/NavigationView.cs @@ -21,6 +21,7 @@ namespace Tango.PPC.Common.Navigation ExternalBridgeView, HomeModule, ShutdownView, - RestartingSystemView + RestartingSystemView, + EmergencyView } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index e98a03404..b495ec54d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -123,6 +123,16 @@ namespace Tango.PPC.Common public String LockScreenPassword { get; set; } /// <summary> + /// Gets or sets the enable emergency notifications. + /// </summary> + public bool EnableEmergencyNotifications { get; set; } + + /// <summary> + /// Gets or sets the emergency COM port. + /// </summary> + public String EmergencyComPort { get; set; } + + /// <summary> /// Gets the machine service address. /// </summary> /// <returns></returns> @@ -149,6 +159,8 @@ namespace Tango.PPC.Common LockScreenPassword = "1111"; DeploymentSlot = DeploymentSlot.TEST; EnableWatchDog = true; + EnableEmergencyNotifications = true; + EmergencyComPort = "COM1"; } } } 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 9b3b58c67..389f5d59b 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 @@ -143,6 +143,7 @@ <Compile Include="Printing\DefaultPrintingManager.cs" /> <Compile Include="Threading\DefaultDispatcherProvider.cs" /> <Compile Include="ViewModelLocator.cs" /> + <Compile Include="ViewModels\EmergencyViewVM.cs" /> <Compile Include="ViewModels\ExternalBridgeViewVM.cs" /> <Compile Include="ViewModels\LayoutViewVM.cs" /> <Compile Include="ViewModels\LoadingErrorViewVM.cs" /> @@ -162,6 +163,9 @@ <Compile Include="Views\LayoutView.xaml.cs"> <DependentUpon>LayoutView.xaml</DependentUpon> </Compile> + <Compile Include="Views\EmergencyView.xaml.cs"> + <DependentUpon>EmergencyView.xaml</DependentUpon> + </Compile> <Compile Include="Views\LoadingErrorView.xaml.cs"> <DependentUpon>LoadingErrorView.xaml</DependentUpon> </Compile> @@ -234,6 +238,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Views\EmergencyView.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Views\LoadingErrorView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -538,7 +546,7 @@ del "$(TargetDir)firmware_package.tfp"</PostBuildEvent> </PropertyGroup> <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.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 3517abbb2..67b5dc19b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -106,6 +106,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register<LoadingErrorViewVM>(); TangoIOC.Default.Register<NoPermissionsViewVM>(); TangoIOC.Default.Register<RestartingSystemViewVM>(); + TangoIOC.Default.Register<EmergencyViewVM>(); TangoIOC.Default.GetInstance<IPPCApplicationManager>().ContentRendered += (_, __) => @@ -203,5 +204,13 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance<RestartingSystemViewVM>(); } } + + public static EmergencyViewVM EmergencyViewVM + { + get + { + return TangoIOC.Default.GetInstance<EmergencyViewVM>(); + } + } } }
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs new file mode 100644 index 000000000..87b3c012b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/EmergencyViewVM.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Emergency; +using Tango.PPC.Common; +using Tango.PPC.Common.Navigation; + +namespace Tango.PPC.UI.ViewModels +{ + public class EmergencyViewVM : PPCViewModel + { + private bool _isActive; + + public override void OnApplicationStarted() + { + + } + + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineProvider.MachineOperator.EmergencyNotificationProvider.StatusChanged += EmergencyNotificationProvider_StatusChanged; + } + + private void EmergencyNotificationProvider_StatusChanged(object sender, EmergencyStatusChangedEventArgs e) + { + InvokeUI(async () => + { + if (e.Status == EmergencyStatus.On && !_isActive) + { + LogManager.Log("Emergency switch activated..."); + _isActive = true; + await NavigationManager.NavigateTo(NavigationView.EmergencyView); + } + else if (_isActive) + { + LogManager.Log("Emergency switch deactivated..."); + _isActive = false; + await NavigationManager.NavigateTo(NavigationView.LayoutView); + } + + if (e.Status == EmergencyStatus.Error && e.ErrorException != null) + { + LogManager.Log(e.ErrorException, "Error occurred while detecting emergency switch."); + } + }); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/EmergencyView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/EmergencyView.xaml new file mode 100644 index 000000000..dfc70e602 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/EmergencyView.xaml @@ -0,0 +1,21 @@ +<UserControl x:Class="Tango.PPC.UI.Views.EmergencyView" + 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:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" + xmlns:global="clr-namespace:Tango.PPC.UI" + xmlns:local="clr-namespace:Tango.PPC.UI.Views" + mc:Ignorable="d" + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:EmergencyViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.EmergencyViewVM}"> + <Grid> + <DockPanel Margin="20 60 20 20"> + <StackPanel DockPanel.Dock="Top"> + <Image Source="../Images/warning-red.png" Width="300" Stretch="Uniform" HorizontalAlignment="Center"></Image> + <TextBlock HorizontalAlignment="Center" Margin="0 40 0 0" FontSize="{StaticResource TangoHeaderFontSize}">Emergency Switch Activated</TextBlock> + <TextBlock HorizontalAlignment="Center" Margin="0 20 0 0" FontSize="{StaticResource TangoTitleFontSize}">Please release the emergency switch to exit this screen.</TextBlock> + </StackPanel> + </DockPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/EmergencyView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/EmergencyView.xaml.cs new file mode 100644 index 000000000..6c5020fbe --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/EmergencyView.xaml.cs @@ -0,0 +1,28 @@ +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.PPC.UI.Views +{ + /// <summary> + /// Interaction logic for LoadingErrorView.xaml + /// </summary> + public partial class EmergencyView : UserControl + { + public EmergencyView() + { + InitializeComponent(); + } + } +} 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 005edb182..5accd8ff3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -92,6 +92,7 @@ <local:MachineSetupView></local:MachineSetupView> <local:MachineUpdateView></local:MachineUpdateView> <local:RestartingSystemView></local:RestartingSystemView> + <local:EmergencyView></local:EmergencyView> </controls:NavigationControl> </touch:TouchPanel> </Grid> diff --git a/Software/Visual_Studio/Tango.Integration/Emergency/EmergencyStatus.cs b/Software/Visual_Studio/Tango.Integration/Emergency/EmergencyStatus.cs new file mode 100644 index 000000000..85c35056f --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Emergency/EmergencyStatus.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Emergency +{ + public enum EmergencyStatus + { + Error, + Off, + On, + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Emergency/EmergencyStatusChangedEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Emergency/EmergencyStatusChangedEventArgs.cs new file mode 100644 index 000000000..aad8ab4b7 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Emergency/EmergencyStatusChangedEventArgs.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Emergency +{ + public class EmergencyStatusChangedEventArgs + { + public EmergencyStatus Status { get; set; } + public Exception ErrorException { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Emergency/IEmergencyNotificationProvider.cs b/Software/Visual_Studio/Tango.Integration/Emergency/IEmergencyNotificationProvider.cs new file mode 100644 index 000000000..9d8f0d421 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Emergency/IEmergencyNotificationProvider.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Emergency +{ + /// <summary> + /// Represents a machine emergency notification provider. + /// </summary> + public interface IEmergencyNotificationProvider + { + /// <summary> + /// Gets or sets a value indicating whether to enable emergency detection and notification. + /// </summary> + bool IsEnabled { get; set; } + + /// <summary> + /// Gets or sets the address/port of the detection device. + /// </summary> + String Address { get; set; } + + /// <summary> + /// Gets or sets the current emergency status. + /// </summary> + EmergencyStatus Status { get; set; } + + /// <summary> + /// Occurs when the emergency status has changed. + /// </summary> + event EventHandler<EmergencyStatusChangedEventArgs> StatusChanged; + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Emergency/UsbEmergencyNotificationProvider.cs b/Software/Visual_Studio/Tango.Integration/Emergency/UsbEmergencyNotificationProvider.cs new file mode 100644 index 000000000..ece9d39bb --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Emergency/UsbEmergencyNotificationProvider.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; + +namespace Tango.Integration.Emergency +{ + /// <summary> + /// Represents a USB serial port emergency switch notification provider. + /// </summary> + /// <seealso cref="Tango.Integration.Emergency.IEmergencyNotificationProvider" /> + public class UsbEmergencyNotificationProvider : IEmergencyNotificationProvider + { + private Timer _timer; + private bool _busy; + + /// <summary> + /// Gets or sets a value indicating whether to enable emergency detection and notification. + /// </summary> + public bool IsEnabled { get; set; } + + /// <summary> + /// Gets or sets the current emergency status. + /// </summary> + public EmergencyStatus Status { get; set; } + + /// <summary> + /// Gets or sets the address/port of the detection device. + /// </summary> + public string Address { get; set; } + + /// <summary> + /// Gets or sets the read timeout for the loop-back signal. + /// </summary> + public TimeSpan ReadTimeout { get; set; } + + /// <summary> + /// Gets or sets the signal output. + /// </summary> + public String SignalOutput { get; set; } + + /// <summary> + /// Occurs when the emergency status has changed. + /// </summary> + public event EventHandler<EmergencyStatusChangedEventArgs> StatusChanged; + + /// <summary> + /// Initializes a new instance of the <see cref="UsbEmergencyNotificationProvider"/> class. + /// </summary> + /// <param name="port">The port.</param> + public UsbEmergencyNotificationProvider(String port) + { + SignalOutput = "1"; + Address = port; + ReadTimeout = TimeSpan.FromMilliseconds(500); + _timer = new Timer(2000); + _timer.Elapsed += _timer_Elapsed; + _timer.Start(); + } + + /// <summary> + /// Called when the status has been changed. + /// </summary> + /// <param name="status">The status.</param> + /// <param name="errorException">The error exception.</param> + protected virtual void OnStatusChanged(EmergencyStatus status, Exception errorException = null) + { + if (Status != status) + { + Status = status; + StatusChanged?.Invoke(this, new EmergencyStatusChangedEventArgs() + { + Status = status, + ErrorException = errorException, + }); + } + } + + /// <summary> + /// Handles the Elapsed event of the _timer. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param> + private void _timer_Elapsed(object sender, ElapsedEventArgs e) + { + if (IsEnabled && !_busy) + { + _busy = true; + + SerialPort serial = new SerialPort(Address); + try + { + serial.ReadTimeout = (int)ReadTimeout.TotalMilliseconds; + serial.Open(); + + serial.Write(SignalOutput + "\n"); + + try + { + string output = serial.ReadLine(); + + if (output == SignalOutput) + { + OnStatusChanged(EmergencyStatus.On); + } + else + { + OnStatusChanged(EmergencyStatus.Off); + } + } + catch (TimeoutException) + { + OnStatusChanged(EmergencyStatus.Off); + } + catch (Exception ex) + { + OnStatusChanged(EmergencyStatus.Error, ex); + } + } + catch (Exception ex) + { + OnStatusChanged(EmergencyStatus.Error, ex); + } + finally + { + try + { + serial.Dispose(); + _busy = false; + } + catch { } + } + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index e110e6189..d5f55c0d8 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -21,6 +21,7 @@ using Tango.Integration.Upgrade; using Tango.PMR.IO; using Tango.PMR.FirmwareUpgrade; using Tango.Integration.JobRuns; +using Tango.Integration.Emergency; namespace Tango.Integration.Operation { @@ -66,6 +67,11 @@ namespace Tango.Integration.Operation IGradientGenerationConfiguration GradientGenerationConfiguration { get; set; } /// <summary> + /// Gets or sets the emergency notification provider. + /// </summary> + IEmergencyNotificationProvider EmergencyNotificationProvider { get; set; } + + /// <summary> /// Gets a value indicating whether this instance is printing. /// </summary> bool IsPrinting { get; } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index ba00d21e6..5a8d910be 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -36,6 +36,7 @@ using Tango.FirmwareUpdateLib.WPF; using Tango.FirmwareUpdateLib; using Tango.Core.ExtensionMethods; using Tango.ColorConversion; +using Tango.Integration.Emergency; namespace Tango.Integration.Operation { @@ -92,6 +93,7 @@ namespace Tango.Integration.Operation LogEmbeddedDebuggingToFile = true; FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; GradientGenerationConfiguration = new DefaultGradientGenerationConfiguration(); + EmergencyNotificationProvider = new UsbEmergencyNotificationProvider("COM1"); } /// <summary> @@ -397,6 +399,11 @@ namespace Tango.Integration.Operation set { _gradientGenerationConfiguration = value; RaisePropertyChangedAuto(); } } + /// <summary> + /// Gets or sets the emergency notification provider. + /// </summary> + public IEmergencyNotificationProvider EmergencyNotificationProvider { get; set; } + #endregion #region Virtual Methods diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 994a0ef2e..bbd9f8c0d 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -88,6 +88,10 @@ <Compile Include="Diagnostics\DiagnosticsFileRecorder.cs" /> <Compile Include="Diagnostics\DiagnosticsTimeCodeChannel.cs" /> <Compile Include="Diagnostics\DiagnosticsTimeCodeChannelFrame.cs" /> + <Compile Include="Emergency\UsbEmergencyNotificationProvider.cs" /> + <Compile Include="Emergency\EmergencyStatus.cs" /> + <Compile Include="Emergency\EmergencyStatusChangedEventArgs.cs" /> + <Compile Include="Emergency\IEmergencyNotificationProvider.cs" /> <Compile Include="ExtensionMethods\IExternalBridgeClientExtensions.cs" /> <Compile Include="ExternalBridge\ColorProfileRequestEventArgs.cs" /> <Compile Include="ExternalBridge\ExternalBridgeClientConnectedEventArgs.cs" /> @@ -188,7 +192,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <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 |
