diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-08-22 11:58:11 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-08-22 11:58:11 +0300 |
| commit | 0c97dba8c1443ee39029136c52bc3861702888e2 (patch) | |
| tree | 0eba2c6e9a170bb316045f67add60060734d4f0d | |
| parent | 884fce5075ca6a53cb5687feb0b01c6db0802f06 (diff) | |
| download | Tango-0c97dba8c1443ee39029136c52bc3861702888e2.tar.gz Tango-0c97dba8c1443ee39029136c52bc3861702888e2.zip | |
Added cartridge insertion validation handling.
Implemented a better keep alive mechanism.
26 files changed, 383 insertions, 91 deletions
diff --git a/Software/PMR/Messages/Diagnostics/CartridgeValidationRequest.proto b/Software/PMR/Messages/Diagnostics/CartridgeValidationRequest.proto index 6ea8ba407..432643e67 100644 --- a/Software/PMR/Messages/Diagnostics/CartridgeValidationRequest.proto +++ b/Software/PMR/Messages/Diagnostics/CartridgeValidationRequest.proto @@ -1,6 +1,5 @@ syntax = "proto3"; -import "Cartridge.proto"; import "CartridgeAction.proto"; package Tango.PMR.Diagnostics; @@ -8,6 +7,5 @@ option java_package = "com.twine.tango.pmr.diagnostics"; message CartridgeValidationRequest { - Cartridge Cartridge = 1; CartridgeAction Action = 2; }
\ No newline at end of file diff --git a/Software/PMR/Messages/Diagnostics/CartridgeValidationResponse.proto b/Software/PMR/Messages/Diagnostics/CartridgeValidationResponse.proto index f3212faa6..5656c7987 100644 --- a/Software/PMR/Messages/Diagnostics/CartridgeValidationResponse.proto +++ b/Software/PMR/Messages/Diagnostics/CartridgeValidationResponse.proto @@ -1,12 +1,10 @@ syntax = "proto3"; -import "Cartridge.proto"; - package Tango.PMR.Diagnostics; option java_package = "com.twine.tango.pmr.diagnostics"; message CartridgeValidationResponse { bool IsValid = 1; - Cartridge Cartridge = 2; + int32 Index = 2; }
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index 8ed2ff80e..26fd06d2d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -472,7 +472,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <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.Common/Resources/Merged.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Merged.xaml index b5b9f9b23..04021d6b6 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Merged.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Merged.xaml @@ -49,6 +49,7 @@ <converters:NullObjectToBooleanConverter x:Key="NullObjectToBooleanConverter" /> <converters:IsNullToVisibilityConverter x:Key="IsNullToVisibilityConverter" /> <converters:StringToLinesConverter x:Key="StringToLinesConverter" /> + <converters:ColorToIntegerConverter x:Key="ColorToIntegerConverter" /> <Style TargetType="FrameworkElement"> <Setter Property="TextElement.FontFamily" Value="{StaticResource TangoFlexoFontFamily}"></Setter> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationView.xaml new file mode 100644 index 000000000..e0c7ccbb6 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationView.xaml @@ -0,0 +1,67 @@ +<UserControl x:Class="Tango.PPC.UI.Dialogs.CartridgeValidationView" + 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:local="clr-namespace:Tango.PPC.UI.Dialogs" + xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + Background="{StaticResource TangoPrimaryBackgroundBrush}" d:DesignHeight="555" d:DesignWidth="560" Width="570" Height="700" d:DataContext="{d:DesignInstance Type=local:CartridgeValidationViewVM, IsDesignTimeCreatable=False}"> + + <Grid Margin="20"> + <DockPanel> + <Grid DockPanel.Dock="Bottom"> + <touch:TouchButton HorizontalAlignment="Left" CornerRadius="25" Command="{Binding CloseCommand}" Style="{StaticResource TangoHollowButton}" Width="150" Height="50" VerticalAlignment="Bottom">CANCEL</touch:TouchButton> + <touch:TouchButton HorizontalAlignment="Right" CornerRadius="25" Command="{Binding OKCommand}" Style="{StaticResource TangoHollowButton}" Width="150" Height="50" VerticalAlignment="Bottom">CONFIRM</touch:TouchButton> + </Grid> + <StackPanel DockPanel.Dock="Top"> + <Image Source="/Images/cartridge_validation.png" RenderOptions.BitmapScalingMode="Fant" Stretch="Uniform" Height="120"></Image> + <TextBlock HorizontalAlignment="Center" Margin="0 20 0 0" FontSize="{StaticResource TangoHeaderFontSize}">Validate Cartridge Type</TextBlock> + <TextBlock Margin="20 10" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center"> + Ink cartridge has been inserted to the system. Please validate the cartridge ink by selecting the correct color. + </TextBlock> + </StackPanel> + <Grid> + <touch:TouchStaticListBox HorizontalAlignment="Center" VerticalAlignment="Center" ItemsSource="{Binding IDSPacks}" SelectedItem="{Binding SelectedIDSPack}"> + <touch:TouchStaticListBox.ItemsPanel> + <ItemsPanelTemplate> + <WrapPanel /> + </ItemsPanelTemplate> + </touch:TouchStaticListBox.ItemsPanel> + <touch:TouchStaticListBox.ItemContainerStyle> + <Style TargetType="touch:TouchStaticListBoxItem"> + <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform> + </Setter.Value> + </Setter> + <Style.Triggers> + <Trigger Property="IsSelected" Value="True"> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleX="1.2" ScaleY="1.2"></ScaleTransform> + </Setter.Value> + </Setter> + </Trigger> + </Style.Triggers> + </Style> + </touch:TouchStaticListBox.ItemContainerStyle> + <touch:TouchStaticListBox.ItemTemplate> + <DataTemplate DataType="{x:Type entities:IdsPack}"> + <StackPanel Margin="15" Width="70"> + <Ellipse Width="70" Height="70"> + <Ellipse.Fill> + <SolidColorBrush Color="{Binding LiquidType.Color,Converter={StaticResource ColorToIntegerConverter}}"></SolidColorBrush> + </Ellipse.Fill> + </Ellipse> + <TextBlock Text="{Binding LiquidType.Name}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="0 10 0 0"></TextBlock> + </StackPanel> + </DataTemplate> + </touch:TouchStaticListBox.ItemTemplate> + </touch:TouchStaticListBox> + </Grid> + </DockPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationView.xaml.cs new file mode 100644 index 000000000..dbfb990b6 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationView.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.Dialogs +{ + /// <summary> + /// Interaction logic for TechnicianModeLoginView.xaml + /// </summary> + public partial class CartridgeValidationView : UserControl + { + public CartridgeValidationView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationViewVM.cs new file mode 100644 index 000000000..f901723a4 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/CartridgeValidationViewVM.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.SharedUI; + +namespace Tango.PPC.UI.Dialogs +{ + public class CartridgeValidationViewVM : DialogViewVM + { + private List<IdsPack> _idsPacks; + public List<IdsPack> IDSPacks + { + get { return _idsPacks; } + set { _idsPacks = value; RaisePropertyChangedAuto(); } + } + + private IdsPack _selectedIDSPack; + public IdsPack SelectedIDSPack + { + get { return _selectedIDSPack; } + set { _selectedIDSPack = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + public CartridgeValidationViewVM() + { + IDSPacks = new List<IdsPack>(); + } + + protected override bool CanOK() + { + return base.CanOK() && SelectedIDSPack != null; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/cartridge_validation.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/cartridge_validation.png Binary files differnew file mode 100644 index 000000000..373cb78c1 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/cartridge_validation.png diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index 5062df1d6..1c71b080d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -388,7 +388,7 @@ namespace Tango.PPC.UI.Notifications throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element."); } - return ShowDialog<T>(datacontext, Activator.CreateInstance(viewType) as FrameworkElement); + return ShowDialog<T>(datacontext, view); } /// <summary> 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 389f5d59b..c2025b733 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 @@ -122,9 +122,13 @@ <Compile Include="Connectivity\WiFiAuthenticationViewVM.cs" /> <Compile Include="Converters\AppBarItemConverter.cs" /> <Compile Include="Converters\ItemBaseConverter.cs" /> + <Compile Include="Dialogs\CartridgeValidationView.xaml.cs"> + <DependentUpon>CartridgeValidationView.xaml</DependentUpon> + </Compile> <Compile Include="Dialogs\ScreenLockView.xaml.cs"> <DependentUpon>ScreenLockView.xaml</DependentUpon> </Compile> + <Compile Include="Dialogs\CartridgeValidationViewVM.cs" /> <Compile Include="Dialogs\TechnicianModeLoginView.xaml.cs"> <DependentUpon>TechnicianModeLoginView.xaml</DependentUpon> </Compile> @@ -194,6 +198,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Dialogs\CartridgeValidationView.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Dialogs\ScreenLockView.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -311,6 +319,7 @@ <Resource Include="Images\GlobalStatus\service_Anim.gif" /> <Resource Include="Images\GlobalStatus\shutdown_icon_Anim.gif" /> <Resource Include="Images\GlobalStatus\standby_Anim.gif" /> + <Resource Include="Images\cartridge_validation.png" /> <Content Include="Manifests\release.xml" /> <Content Include="Manifests\debug.xml" /> <None Include="packages.config" /> @@ -546,7 +555,7 @@ 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/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index a4f550a39..01a47539e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Windows.Threading; using Tango.Core.DI; using Tango.Integration.ExternalBridge; +using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; @@ -14,6 +15,7 @@ using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.WatchDog; +using Tango.PPC.UI.Dialogs; using Tango.SharedUI; namespace Tango.PPC.UI.ViewModels @@ -49,6 +51,13 @@ namespace Tango.PPC.UI.ViewModels /// </summary> public override void OnApplicationStarted() { + + } + + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineProvider.MachineOperator.CartridgeValidationRequestReceived += MachineOperator_CartridgeValidationRequestReceived; } #region Event Handlers @@ -63,6 +72,26 @@ namespace Tango.PPC.UI.ViewModels CurrentDateTime = DateTime.Now; } + private void MachineOperator_CartridgeValidationRequestReceived(object sender, CartridgeValidationEventArgs e) + { + InvokeUI(async () => + { + var vm = await NotificationProvider.ShowDialog<CartridgeValidationViewVM>(new CartridgeValidationViewVM() + { + IDSPacks = MachineProvider.Machine.Configuration.NoneEmptyIdsPacks.ToList(), + }); + + if (vm.DialogResult) + { + e.Approve(vm.SelectedIDSPack.PackIndex); + } + else + { + e.Decline(); + } + }); + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 0a219b824..dea2ddb69 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -1312,6 +1312,16 @@ namespace Tango.Emulations.Emulators #region Public Methods + public async Task<int> ValidateCartridge() + { + var response = await Transporter.SendRequest<CartridgeValidationRequest, CartridgeValidationResponse>(new CartridgeValidationRequest() + { + Action = CartridgeAction.Inserted, + + }, TimeSpan.FromSeconds(10)); + + return response.Message.Index; + } #endregion } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 648046bd2..b7921aac3 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -145,6 +145,8 @@ namespace Tango.Integration.ExternalBridge _tcpServer.ClientConnected += _tcpServer_ClientConnected; LogManager.NewLog += LogManager_NewLog; + + KeepAliveTimeout = TimeSpan.FromSeconds(5); } /// <summary> diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs index ef00133df..9adc1f223 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs @@ -251,6 +251,7 @@ namespace Tango.Integration.ExternalBridge SerialNumber = serialNumber; Machine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == serialNumber); IPAddress = ipAddress; + KeepAliveTimeout = TimeSpan.FromSeconds(5); UseKeepAlive = false; EnableDiagnostics = true; } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/CartridgeValidationEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/CartridgeValidationEventArgs.cs new file mode 100644 index 000000000..6ef6e43c6 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/CartridgeValidationEventArgs.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Diagnostics; + +namespace Tango.Integration.Operation +{ + /// <summary> + /// Represents a cartridge validation request event arguments. + /// </summary> + /// <seealso cref="System.EventArgs" /> + public class CartridgeValidationEventArgs : EventArgs + { + private Action<int> _approveAction; + private Action _declineAction; + + /// <summary> + /// Initializes a new instance of the <see cref="CartridgeValidationEventArgs"/> class. + /// </summary> + /// <param name="request">The request.</param> + /// <param name="approveAction">The approve action.</param> + public CartridgeValidationEventArgs(CartridgeValidationRequest request, Action<int> approveAction,Action declineAction) + { + Request = request; + _approveAction = approveAction; + _declineAction = declineAction; + } + + /// <summary> + /// Gets the request. + /// </summary> + public CartridgeValidationRequest Request { get; private set; } + + /// <summary> + /// Sends approved response for the specified cartridge index. + /// </summary> + /// <param name="cartridgeIndex">The cartridge index.</param> + public void Approve(int cartridgeIndex) + { + _approveAction(cartridgeIndex); + } + + public void Decline() + { + _declineAction(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index 89c947764..ae303563b 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -168,6 +168,11 @@ namespace Tango.Integration.Operation event EventHandler<MachineStatus> MachineStatusChanged; /// <summary> + /// Occurs when a new cartridge validation request has been received. + /// </summary> + event EventHandler<CartridgeValidationEventArgs> CartridgeValidationRequestReceived; + + /// <summary> /// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages. /// </summary> bool EnableDiagnostics { get; set; } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 3fd24b20b..0c842d0da 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -138,6 +138,11 @@ namespace Tango.Integration.Operation public event EventHandler<MachineStatus> MachineStatusChanged; /// <summary> + /// Occurs when a new cartridge validation request has been received. + /// </summary> + public event EventHandler<CartridgeValidationEventArgs> CartridgeValidationRequestReceived; + + /// <summary> /// Occurs when a request has been sent. /// </summary> public event EventHandler<IMessage> RequestSent; @@ -777,6 +782,20 @@ namespace Tango.Integration.Operation } /// <summary> + /// Called when a new request has been received. + /// </summary> + /// <param name="container">The request.</param> + protected override void OnRequestReceived(MessageContainer container) + { + base.OnRequestReceived(container); + + if (container.Type == MessageType.CartridgeValidationRequest) + { + OnCartridgeValidationRequestReceived(container.Token, MessageFactory.ExtractMessageFromContainer<CartridgeValidationRequest>(container)); + } + } + + /// <summary> /// Called when the response has been sent /// </summary> /// <param name="response">The response.</param> @@ -803,6 +822,34 @@ namespace Tango.Integration.Operation StatusChanged?.Invoke(this, status); } + /// <summary> + /// Called when the cartridge validation request has been received. + /// </summary> + /// <param name="request">The request.</param> + protected virtual void OnCartridgeValidationRequestReceived(String token, CartridgeValidationRequest request) + { + CartridgeValidationEventArgs e = new CartridgeValidationEventArgs(request, (index) => + { + //Approve + SendResponse<CartridgeValidationResponse>(new CartridgeValidationResponse() + { + IsValid = true, + Index = index, + }, token).Wait(); + + }, () => + { + //Decline + SendResponse<CartridgeValidationResponse>(new CartridgeValidationResponse() + { + + }, token).Wait(); + + }); + + CartridgeValidationRequestReceived?.Invoke(this, e); + } + #endregion #region Override Methods diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index bbd9f8c0d..62ff18fb6 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -99,6 +99,7 @@ <Compile Include="JobRuns\BasicJobRunsLogger.cs" /> <Compile Include="JobRuns\IJobRunsLogger.cs" /> <Compile Include="Logging\EmbeddedLogFileParser.cs" /> + <Compile Include="Operation\CartridgeValidationEventArgs.cs" /> <Compile Include="Operation\DefaultMachineEventsStateProvider.cs" /> <Compile Include="Logging\EmbeddedLogItem.cs" /> <Compile Include="Operation\DefaultGradientGenerationConfiguration.cs" /> @@ -192,7 +193,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <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/Tango.PMR/Diagnostics/CartridgeValidationRequest.cs b/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationRequest.cs index 149c2b6cb..5dc0fa044 100644 --- a/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationRequest.cs +++ b/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationRequest.cs @@ -23,16 +23,14 @@ namespace Tango.PMR.Diagnostics { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "CiBDYXJ0cmlkZ2VWYWxpZGF0aW9uUmVxdWVzdC5wcm90bxIVVGFuZ28uUE1S", - "LkRpYWdub3N0aWNzGg9DYXJ0cmlkZ2UucHJvdG8aFUNhcnRyaWRnZUFjdGlv", - "bi5wcm90byKJAQoaQ2FydHJpZGdlVmFsaWRhdGlvblJlcXVlc3QSMwoJQ2Fy", - "dHJpZGdlGAEgASgLMiAuVGFuZ28uUE1SLkRpYWdub3N0aWNzLkNhcnRyaWRn", - "ZRI2CgZBY3Rpb24YAiABKA4yJi5UYW5nby5QTVIuRGlhZ25vc3RpY3MuQ2Fy", - "dHJpZGdlQWN0aW9uQiEKH2NvbS50d2luZS50YW5nby5wbXIuZGlhZ25vc3Rp", - "Y3NiBnByb3RvMw==")); + "LkRpYWdub3N0aWNzGhVDYXJ0cmlkZ2VBY3Rpb24ucHJvdG8iVAoaQ2FydHJp", + "ZGdlVmFsaWRhdGlvblJlcXVlc3QSNgoGQWN0aW9uGAIgASgOMiYuVGFuZ28u", + "UE1SLkRpYWdub3N0aWNzLkNhcnRyaWRnZUFjdGlvbkIhCh9jb20udHdpbmUu", + "dGFuZ28ucG1yLmRpYWdub3N0aWNzYgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Tango.PMR.Diagnostics.CartridgeReflection.Descriptor, global::Tango.PMR.Diagnostics.CartridgeActionReflection.Descriptor, }, + new pbr::FileDescriptor[] { global::Tango.PMR.Diagnostics.CartridgeActionReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Diagnostics.CartridgeValidationRequest), global::Tango.PMR.Diagnostics.CartridgeValidationRequest.Parser, new[]{ "Cartridge", "Action" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Diagnostics.CartridgeValidationRequest), global::Tango.PMR.Diagnostics.CartridgeValidationRequest.Parser, new[]{ "Action" }, null, null, null) })); } #endregion @@ -63,7 +61,6 @@ namespace Tango.PMR.Diagnostics { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public CartridgeValidationRequest(CartridgeValidationRequest other) : this() { - Cartridge = other.cartridge_ != null ? other.Cartridge.Clone() : null; action_ = other.action_; } @@ -72,17 +69,6 @@ namespace Tango.PMR.Diagnostics { return new CartridgeValidationRequest(this); } - /// <summary>Field number for the "Cartridge" field.</summary> - public const int CartridgeFieldNumber = 1; - private global::Tango.PMR.Diagnostics.Cartridge cartridge_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public global::Tango.PMR.Diagnostics.Cartridge Cartridge { - get { return cartridge_; } - set { - cartridge_ = value; - } - } - /// <summary>Field number for the "Action" field.</summary> public const int ActionFieldNumber = 2; private global::Tango.PMR.Diagnostics.CartridgeAction action_ = 0; @@ -107,7 +93,6 @@ namespace Tango.PMR.Diagnostics { if (ReferenceEquals(other, this)) { return true; } - if (!object.Equals(Cartridge, other.Cartridge)) return false; if (Action != other.Action) return false; return true; } @@ -115,7 +100,6 @@ namespace Tango.PMR.Diagnostics { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (cartridge_ != null) hash ^= Cartridge.GetHashCode(); if (Action != 0) hash ^= Action.GetHashCode(); return hash; } @@ -127,10 +111,6 @@ namespace Tango.PMR.Diagnostics { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { - if (cartridge_ != null) { - output.WriteRawTag(10); - output.WriteMessage(Cartridge); - } if (Action != 0) { output.WriteRawTag(16); output.WriteEnum((int) Action); @@ -140,9 +120,6 @@ namespace Tango.PMR.Diagnostics { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (cartridge_ != null) { - size += 1 + pb::CodedOutputStream.ComputeMessageSize(Cartridge); - } if (Action != 0) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Action); } @@ -154,12 +131,6 @@ namespace Tango.PMR.Diagnostics { if (other == null) { return; } - if (other.cartridge_ != null) { - if (cartridge_ == null) { - cartridge_ = new global::Tango.PMR.Diagnostics.Cartridge(); - } - Cartridge.MergeFrom(other.Cartridge); - } if (other.Action != 0) { Action = other.Action; } @@ -173,13 +144,6 @@ namespace Tango.PMR.Diagnostics { default: input.SkipLastField(); break; - case 10: { - if (cartridge_ == null) { - cartridge_ = new global::Tango.PMR.Diagnostics.Cartridge(); - } - input.ReadMessage(cartridge_); - break; - } case 16: { action_ = (global::Tango.PMR.Diagnostics.CartridgeAction) input.ReadEnum(); break; diff --git a/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationResponse.cs b/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationResponse.cs index 7463f0270..e128809df 100644 --- a/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationResponse.cs +++ b/Software/Visual_Studio/Tango.PMR/Diagnostics/CartridgeValidationResponse.cs @@ -23,14 +23,13 @@ namespace Tango.PMR.Diagnostics { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "CiFDYXJ0cmlkZ2VWYWxpZGF0aW9uUmVzcG9uc2UucHJvdG8SFVRhbmdvLlBN", - "Ui5EaWFnbm9zdGljcxoPQ2FydHJpZGdlLnByb3RvImMKG0NhcnRyaWRnZVZh", - "bGlkYXRpb25SZXNwb25zZRIPCgdJc1ZhbGlkGAEgASgIEjMKCUNhcnRyaWRn", - "ZRgCIAEoCzIgLlRhbmdvLlBNUi5EaWFnbm9zdGljcy5DYXJ0cmlkZ2VCIQof", - "Y29tLnR3aW5lLnRhbmdvLnBtci5kaWFnbm9zdGljc2IGcHJvdG8z")); + "Ui5EaWFnbm9zdGljcyI9ChtDYXJ0cmlkZ2VWYWxpZGF0aW9uUmVzcG9uc2US", + "DwoHSXNWYWxpZBgBIAEoCBINCgVJbmRleBgCIAEoBUIhCh9jb20udHdpbmUu", + "dGFuZ28ucG1yLmRpYWdub3N0aWNzYgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Tango.PMR.Diagnostics.CartridgeReflection.Descriptor, }, + new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Diagnostics.CartridgeValidationResponse), global::Tango.PMR.Diagnostics.CartridgeValidationResponse.Parser, new[]{ "IsValid", "Cartridge" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Diagnostics.CartridgeValidationResponse), global::Tango.PMR.Diagnostics.CartridgeValidationResponse.Parser, new[]{ "IsValid", "Index" }, null, null, null) })); } #endregion @@ -62,7 +61,7 @@ namespace Tango.PMR.Diagnostics { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public CartridgeValidationResponse(CartridgeValidationResponse other) : this() { isValid_ = other.isValid_; - Cartridge = other.cartridge_ != null ? other.Cartridge.Clone() : null; + index_ = other.index_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -81,14 +80,14 @@ namespace Tango.PMR.Diagnostics { } } - /// <summary>Field number for the "Cartridge" field.</summary> - public const int CartridgeFieldNumber = 2; - private global::Tango.PMR.Diagnostics.Cartridge cartridge_; + /// <summary>Field number for the "Index" field.</summary> + public const int IndexFieldNumber = 2; + private int index_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public global::Tango.PMR.Diagnostics.Cartridge Cartridge { - get { return cartridge_; } + public int Index { + get { return index_; } set { - cartridge_ = value; + index_ = value; } } @@ -106,7 +105,7 @@ namespace Tango.PMR.Diagnostics { return true; } if (IsValid != other.IsValid) return false; - if (!object.Equals(Cartridge, other.Cartridge)) return false; + if (Index != other.Index) return false; return true; } @@ -114,7 +113,7 @@ namespace Tango.PMR.Diagnostics { public override int GetHashCode() { int hash = 1; if (IsValid != false) hash ^= IsValid.GetHashCode(); - if (cartridge_ != null) hash ^= Cartridge.GetHashCode(); + if (Index != 0) hash ^= Index.GetHashCode(); return hash; } @@ -129,9 +128,9 @@ namespace Tango.PMR.Diagnostics { output.WriteRawTag(8); output.WriteBool(IsValid); } - if (cartridge_ != null) { - output.WriteRawTag(18); - output.WriteMessage(Cartridge); + if (Index != 0) { + output.WriteRawTag(16); + output.WriteInt32(Index); } } @@ -141,8 +140,8 @@ namespace Tango.PMR.Diagnostics { if (IsValid != false) { size += 1 + 1; } - if (cartridge_ != null) { - size += 1 + pb::CodedOutputStream.ComputeMessageSize(Cartridge); + if (Index != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Index); } return size; } @@ -155,11 +154,8 @@ namespace Tango.PMR.Diagnostics { if (other.IsValid != false) { IsValid = other.IsValid; } - if (other.cartridge_ != null) { - if (cartridge_ == null) { - cartridge_ = new global::Tango.PMR.Diagnostics.Cartridge(); - } - Cartridge.MergeFrom(other.Cartridge); + if (other.Index != 0) { + Index = other.Index; } } @@ -175,11 +171,8 @@ namespace Tango.PMR.Diagnostics { IsValid = input.ReadBool(); break; } - case 18: { - if (cartridge_ == null) { - cartridge_ = new global::Tango.PMR.Diagnostics.Cartridge(); - } - input.ReadMessage(cartridge_); + case 16: { + Index = input.ReadInt32(); break; } } diff --git a/Software/Visual_Studio/Tango.Touch/Styles/TouchButton.xaml b/Software/Visual_Studio/Tango.Touch/Styles/TouchButton.xaml index d8d843b78..2fd056b6d 100644 --- a/Software/Visual_Studio/Tango.Touch/Styles/TouchButton.xaml +++ b/Software/Visual_Studio/Tango.Touch/Styles/TouchButton.xaml @@ -47,6 +47,12 @@ <Setter Property="BorderBrush" Value="{StaticResource TangoPrimaryAccentBrush}"></Setter> <Setter Property="RippleBrush" Value="{StaticResource TangoRippleDarkBrush}"></Setter> <Setter Property="EnableDropShadow" Value="False"></Setter> + <Style.Triggers> + <Trigger Property="IsEnabled" Value="False"> + <Setter Property="BorderBrush" Value="{StaticResource TangoDisabledBackgroundBrush}"></Setter> + <Setter Property="Foreground" Value="{StaticResource TangoDisabledBackgroundBrush}"></Setter> + </Trigger> + </Style.Triggers> </Style> <Style x:Key="TangoMessageBoxButton" TargetType="{x:Type controls:TouchButton}" BasedOn="{StaticResource TangoFlatButton}"> diff --git a/Software/Visual_Studio/Tango.Transport/ITransporter.cs b/Software/Visual_Studio/Tango.Transport/ITransporter.cs index 7424a4684..073e60259 100644 --- a/Software/Visual_Studio/Tango.Transport/ITransporter.cs +++ b/Software/Visual_Studio/Tango.Transport/ITransporter.cs @@ -154,6 +154,11 @@ namespace Tango.Transport bool UseKeepAlive { get; set; } /// <summary> + /// Gets or sets the keep alive timeout. + /// </summary> + TimeSpan KeepAliveTimeout { get; set; } + + /// <summary> /// Gets or sets a value indicating whether to auto respond to keep alive requests. /// </summary> bool EnableKeepAliveAutoResponse { get; set; } diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs index d3d8730f0..8727bb723 100644 --- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs @@ -35,6 +35,7 @@ namespace Tango.Transport private Thread _keepAliveThread; private ITransportAdapter _adapter; private Dictionary<String, PendingResponse> _pendingResponses; + private DateTime _lastKeepAliveTime; #region Events @@ -123,6 +124,11 @@ namespace Tango.Transport } /// <summary> + /// Gets or sets the keep alive timeout. + /// </summary> + public TimeSpan KeepAliveTimeout { get; set; } + + /// <summary> /// Gets or sets a value indicating whether to auto respond to keep alive requests. /// </summary> public bool EnableKeepAliveAutoResponse { get; set; } @@ -201,6 +207,7 @@ namespace Tango.Transport /// <param name="data">The data.</param> protected virtual void OnAdapterDataAvailable(object sender, byte[] data) { + _lastKeepAliveTime = DateTime.Now; EnqueueMessageIn(data); } @@ -259,6 +266,7 @@ namespace Tango.Transport _arrivedResponses = new ProducerConsumerQueue<byte[]>(); RequestTimeout = TimeSpan.FromSeconds(5); EnableKeepAliveAutoResponse = true; + KeepAliveTimeout = TimeSpan.FromSeconds(2); } /// <summary> @@ -1163,7 +1171,7 @@ namespace Tango.Transport { if (_arrivedResponses.Count == 0) { - var response = SendRequest<KeepAliveRequest, KeepAliveResponse>(new KeepAliveRequest(), TimeSpan.FromSeconds(2)).Result; + var response = SendRequest<KeepAliveRequest, KeepAliveResponse>(new KeepAliveRequest(), KeepAliveTimeout).Result; } else { @@ -1177,8 +1185,15 @@ namespace Tango.Transport if (UseKeepAlive) { - OnFailed(new KeepAliveException("The transporter has not received a KeepAlive response within the given time.")); - return; + if (DateTime.Now - _lastKeepAliveTime > KeepAliveTimeout) + { + OnFailed(new KeepAliveException("The transporter has not received a KeepAlive response within the given time.")); + return; + } + else + { + LogManager.Log("The transporter has not received a KeepAlive response within the given time, but was ignored due to other message received within the given time.", LogCategory.Warning); + } } } catch (ThreadAbortException) diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index b6c7e840a..ba19c73d2 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -5467,12 +5467,12 @@ Global {7D0FCE3C-9A37-439C-9F9F-B26CFD6A8A33} = {B2AF4F3F-2828-47C3-8F3E-A0EA0BD66FF8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_UpdateFileVersion = False - BuildVersion_StartDate = 2000/1/1 - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs BuildVersion_UseGlobalSettings = False + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_StartDate = 2000/1/1 + BuildVersion_UpdateFileVersion = False + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs index 8e5393eda..1662a3ede 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs @@ -96,6 +96,11 @@ namespace Tango.MachineEM.UI.ViewModels /// </summary> public RelayCommand ClearCommand { get; set; } + /// <summary> + /// Gets or sets the validate cartridge command. + /// </summary> + public RelayCommand ValidateCartridgeCommand { get; set; } + #endregion #region Constructors @@ -125,6 +130,7 @@ namespace Tango.MachineEM.UI.ViewModels StopCommand = new RelayCommand(Stop, (x) => Emulator.IsStarted); CancelCommand = new RelayCommand(Cancel, (x) => _running); ClearCommand = new RelayCommand(() => Log = String.Empty); + ValidateCartridgeCommand = new RelayCommand(ValidateCartridge, (x) => Emulator.IsStarted); Ports = new List<string>() { @@ -198,6 +204,20 @@ namespace Tango.MachineEM.UI.ViewModels } + private async void ValidateCartridge() + { + LogManager.Log("Sending cartridge validation request..."); + try + { + var index = await Emulator.ValidateCartridge(); + LogManager.Log($"Cartridge validation response received: '{index}'."); + } + catch (Exception ex) + { + LogManager.Log(ex, "Cartridge validation request failed."); + } + } + #endregion } } diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml index f9252d970..51cc1d3ec 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml @@ -10,7 +10,7 @@ xmlns:vm="clr-namespace:Tango.MachineEM.UI.ViewModels" xmlns:local="clr-namespace:Tango.MachineEM.UI.Views" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1200" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" > + d:DesignHeight="720" d:DesignWidth="1300" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" > <UserControl.Resources> <converters:BooleanInverseConverter x:Key="BooleanInverseConverter"></converters:BooleanInverseConverter> @@ -179,6 +179,12 @@ <SolidColorBrush Color="#151515" Opacity="0.8" /> </Grid.Background> <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Margin="5"> + <Button Margin="5" MinWidth="100" Style="{StaticResource AccentedSquareButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding ValidateCartridgeCommand}"> + <StackPanel Orientation="Horizontal"> + <fa:ImageAwesome Icon="FlagCheckered" Width="16"></fa:ImageAwesome> + <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">CARTRIDGE VALIDATION</TextBlock> + </StackPanel> + </Button> <ToggleButton Style="{StaticResource AccentedSquareButtonStyle}" BorderThickness="0" x:Name="toggleLevels" MinWidth="140" Margin="5 5 20 5"> <StackPanel Orientation="Horizontal"> <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">STATUS</TextBlock> |
