From 113e6f9a315a3cf3379eeb8e7c66b92fe839d56c Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 27 Mar 2019 14:18:17 +0200 Subject: Improved PPC technician mode. Added logs filtering pause/resume/clear. --- .../Connection/DefaultMachineProvider.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs') 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 9a7e29bb7..82d805a70 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -89,7 +89,7 @@ namespace Tango.PPC.Common.Connection { try { - LogManager.Log("Starting machine connection procedure..."); + LogManager.Log("Starting machine connection procedure...", LogCategory.Debug); var settings = SettingsManager.Default.GetOrCreate(); @@ -99,19 +99,19 @@ namespace Tango.PPC.Common.Connection { TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate().MachineScanningTimeoutSeconds); - LogManager.Log("Scanning for machine on available serial ports..."); + LogManager.Log("Scanning for machine on available serial ports...", LogCategory.Debug); Transport.Discovery.UsbCommunicationScanner scanner = new Transport.Discovery.UsbCommunicationScanner(UsbSerialBaudRates.BR_115200); var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, timeout); - LogManager.Log("Machine discovered on port: " + response.Adapter.Address); - LogManager.Log("Device Information:"); - LogManager.Log(response.Response.DeviceInformation.ToJsonString()); + LogManager.Log("Machine discovered on port: " + response.Adapter.Address, LogCategory.Debug); + LogManager.Log("Device Information:", LogCategory.Debug); + LogManager.Log(response.Response.DeviceInformation.ToJsonString(), LogCategory.Debug); - LogManager.Log("Disconnecting machine operator..."); + LogManager.Log("Disconnecting machine operator...", LogCategory.Debug); await MachineOperator.Disconnect(); MachineOperator.Adapter = response.Adapter; MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp; - LogManager.Log("Connecting machine operator..."); + LogManager.Log("Connecting machine operator...", LogCategory.Debug); await MachineOperator.Connect(); @@ -120,7 +120,7 @@ namespace Tango.PPC.Common.Connection } else { - LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}..."); + LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...", LogCategory.Debug); UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200); MachineOperator.Adapter = adapter; -- cgit v1.3.1 From c2945492e7c4d168c36b632d1f28dd8ca569b5ac Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 22 Apr 2019 19:49:09 +0300 Subject: Improved ExternalBridge discovery greatly! Implemented volume gradient generation! --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../ViewModels/MainViewVM.cs | 2 +- .../Views/JobView.xaml | 12 +- .../Connection/DefaultMachineProvider.cs | 17 ++- .../PPC/Tango.PPC.Common/PPCSettings.cs | 19 +++ .../Tango.Emulations/Emulators/MachineEmulator.cs | 7 +- .../ExternalBridge/ExternalBridgeScanner.cs | 57 +++++---- .../ExternalBridge/ExternalBridgeService.cs | 2 + .../DefaultGradientGenerationConfiguration.cs | 135 ++++++++++++++++++--- .../Tango.Transport/Discovery/DiscoveredService.cs | 14 ++- .../Discovery/UdpDiscoveryClient.cs | 23 +++- .../Discovery/UdpDiscoveryService.cs | 42 +++++-- .../Tango.Transport/Servers/TcpServer.cs | 5 +- 18 files changed, 273 insertions(+), 62 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 2ad3500d7..84785d8cf 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 64c4734b7..5e10994a1 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 430d0c50d..7670a3170 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 51139d1a5..1cf272342 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 84eb6afc9..548dda3df 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index f3b9858f1..550ccbeae 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index db9d9dbae..0299940d3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1386,7 +1386,7 @@ namespace Tango.MachineStudio.Developer.ViewModels InvokeUI(() => { - _notification.ShowError("Job failed. " + ex.Message); + _notification.ShowError("Job failed. " + ex.FlattenMessage()); StopRecordingIfInProgress(); }); }; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index c4c831011..bfa951c3b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -865,9 +865,15 @@ - - - Enable Gradient Generation + + Generate Gradient + + Resolution: + + + + + 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 82d805a70..3ffb6f634 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -79,6 +79,13 @@ namespace Tango.PPC.Common.Connection MachineOperator.UseKeepAlive = true; MachineOperator.EnableDiagnostics = false; MachineOperator.EnableEmbeddedDebugging = false; + + var settings = SettingsManager.Default.GetOrCreate(); + + MachineOperator.JobUploadStrategy = settings.JobUploadStrategy; + + MachineOperator.GradientGenerationConfiguration.IsEnabled = settings.EnableGradientGeneration; + MachineOperator.GradientGenerationConfiguration.ResolutionCM = settings.GradientGenerationResolution; } private async void ConnectionThreadMethod() @@ -125,7 +132,15 @@ namespace Tango.PPC.Common.Connection UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200); MachineOperator.Adapter = adapter; MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp; - await MachineOperator.Connect(); + try + { + await MachineOperator.Connect(); + } + catch (Exception) + { + await adapter.Disconnect(); + throw; + } await Task.Delay(1000); await MachineOperator.UploadHardwareConfiguration(Machine.Configuration.HardwareVersion, Machine.Configuration); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index 32181a753..698dbf374 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -5,6 +5,7 @@ using System.ServiceModel; using System.Text; using System.Threading.Tasks; using Tango.Logging; +using Tango.PMR.Printing; using Tango.Settings; using Tango.Web; @@ -81,6 +82,21 @@ namespace Tango.PPC.Common /// public bool EnableTechnicianModeByDefault { get; set; } + /// + /// Gets or sets the job upload strategy. + /// + public JobUploadStrategy JobUploadStrategy { get; set; } + + /// + /// Gets or sets a value indicating whether to enable gradient generation. + /// + public bool EnableGradientGeneration { get; set; } + + /// + /// Gets or sets the gradient generation resolution. + /// + public int GradientGenerationResolution { get; set; } + /// /// Gets the machine service address. /// @@ -95,6 +111,9 @@ namespace Tango.PPC.Common /// public PPCSettings() { + JobUploadStrategy = JobUploadStrategy.JobDescriptionFile; + EnableGradientGeneration = true; + GradientGenerationResolution = 20; MachineScanningTimeoutSeconds = 20; LoggingCategories = new List(); EmbeddedComPort = null; diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index f1d9487ff..7f99c8161 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -29,6 +29,7 @@ using Tango.PMR.IO; using System.IO; using Tango.Integration.Operation; using Tango.PMR.FirmwareUpgrade; +using System.Diagnostics; namespace Tango.Emulations.Emulators { @@ -68,6 +69,7 @@ namespace Tango.Emulations.Emulators private List _valveStates; private JobTicket _current_job_ticket; private String _current_job_resume_token; + private FileUploadRequest _lastFileUploadRequest; #region Properties @@ -1038,7 +1040,7 @@ namespace Tango.Emulations.Emulators response.Items.Add(new PMR.IO.FileInfo() { Attribute = FileAttribute.Directory, - FullPath = replaceSlash ? dir.Replace("\\","/") : dir, + FullPath = replaceSlash ? dir.Replace("\\", "/") : dir, LastModifiedDate = dirInfo.LastWriteTime.DayOfYear, LastModifiedTime = dirInfo.LastWriteTime.Hour, Name = Path.GetFileName(dir), @@ -1143,6 +1145,7 @@ namespace Tango.Emulations.Emulators private void HandleFileUploadRequest(TangoMessage request) { var message = request.Message; + _lastFileUploadRequest = message; Transporter.SendResponse(new FileUploadResponse() { MaxChunkLength = MAX_CHUNK_LENGTH, @@ -1160,6 +1163,8 @@ namespace Tango.Emulations.Emulators { byte[] buffer = message.Buffer.ToByteArray(); fs.Write(buffer, 0, buffer.Length); + + Debug.WriteLine($"Emulator file upload '{_lastFileUploadRequest.Path}' {fs.Length}/{_lastFileUploadRequest.Length} ..."); } Transporter.SendResponse(new FileChunkUploadResponse(), request.Container.Token); diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs index 110895bdd..0b1ac9c0e 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs @@ -32,12 +32,13 @@ namespace Tango.Integration.ExternalBridge private Thread _usbDiscoveryThread; private UdpClient _server; private IntegrationSettings _settings; + private const int DISCOVERY_PORT = 8888; - private ObservableCollection _availableMachines; + private SynchronizedObservableCollection _availableMachines; /// /// Gets the available machines. /// - public ObservableCollection AvailableMachines + public SynchronizedObservableCollection AvailableMachines { get { return _availableMachines; } private set { _availableMachines = value; RaisePropertyChangedAuto(); } @@ -60,7 +61,7 @@ namespace Tango.Integration.ExternalBridge { _settings = SettingsManager.Default.GetOrCreate(); _server = new UdpClient(_settings.ExternalBridgeServiceDiscoveryPort); - AvailableMachines = new ObservableCollection(); + AvailableMachines = new SynchronizedObservableCollection(); } /// @@ -136,42 +137,50 @@ namespace Tango.Integration.ExternalBridge { try { - var ClientEp = new IPEndPoint(IPAddress.Any, 0); + var ClientEp = new IPEndPoint(IPAddress.Any, DISCOVERY_PORT); _server.EnableBroadcast = true; var ClientRequestData = _server.Receive(ref ClientEp); ExternalBridgeUdpDiscoveryPacket packet = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(ClientRequestData); - if (packet.Time == String.Empty || (DateTime.Now - ParseDateTime(packet.Time)).TotalSeconds < 6) + String address = ClientEp.Address.ToString(); + + //validate service existence using TCP connection. + try + { + TcpClient client = new TcpClient(); + client.Connect(address, DISCOVERY_PORT); + client.Dispose(); + } + catch { - if (!AvailableMachines.OfType().ToList().Exists(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == ClientEp.Address.ToString())) + var disconnected_machine = AvailableMachines.OfType().ToList().FirstOrDefault(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == address); + + if (disconnected_machine != null) { - ExternalBridgeTcpClient newMachine = new ExternalBridgeTcpClient(packet.SerialNumber, ClientEp.Address.ToString()); + LogManager.Log("Disconnected machine detected via TCP: " + disconnected_machine.SerialNumber); + AvailableMachines.Remove(disconnected_machine); + } - LogManager.Log("Found a new machine via TCP " + newMachine.SerialNumber); + continue; + } - ThreadsHelper.InvokeUINow(() => - { - AvailableMachines.Insert(1, newMachine); - }); - } + if (!AvailableMachines.OfType().ToList().Exists(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == address)) + { + ExternalBridgeTcpClient newMachine = new ExternalBridgeTcpClient(packet.SerialNumber, address); + + LogManager.Log("Found a new machine via TCP " + newMachine.SerialNumber); + + ThreadsHelper.InvokeUINow(() => + { + AvailableMachines.Insert(1, newMachine); + }); } - //else if (packet.Time != String.Empty && (DateTime.Now - DateTime.Parse(packet.Time)).TotalSeconds > 5) - //{ - // var machine = AvailableMachines.OfType().ToList().FirstOrDefault(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == ClientEp.Address.ToString()); - - // if (machine != null) - // { - // AvailableMachines.Remove(machine); - // } - //} } catch (Exception ex) { LogManager.Log(ex); } - - //Thread.Sleep(1000); } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 90d8995b0..3f4f8559c 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -28,6 +28,8 @@ namespace Tango.Integration.ExternalBridge private bool _send_app_logs; private String _app_logs_token; private Dictionary> _messageHandlers; + private const int DISCOVERY_PORT = 8888; + private const int EXTERNAL_BRIDGE_PORT = 1984; #region Events diff --git a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs index d4cc9ce21..68fd14ac2 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs @@ -16,6 +16,15 @@ namespace Tango.Integration.Operation /// public class DefaultGradientGenerationConfiguration : ExtendedObject, IGradientGenerationConfiguration { + private class CMYK + { + public double C { get; set; } + public double M { get; set; } + public double Y { get; set; } + public double K { get; set; } + public double OffsetPercent { get; set; } + } + private bool _isEnabled; /// /// Gets or sets a value indicating whether to generate the gradient steps. @@ -62,28 +71,64 @@ namespace Tango.Integration.Operation int stopIndex = 1; - for (double cm = 0; cm < segment.Length; cm += (ResolutionCM / 100d)) + var colorSpace = segment.BrushStops.First().BrushColorSpace; + + //validate all brush stops in the segment are the same color space! + if (segment.BrushStops.ToList().Exists(x => x.BrushColorSpace != colorSpace)) + { + throw new ArgumentException("Cannot generate gradient using multiple color spaces on the same segment."); + } + + if (ResolutionCM > segment.Length * 100d) + { + return segment.BrushStops.ToList(); + } + + var refStop = segment.BrushStops.First().Clone(segment); + + for (double cm = 0; cm <= segment.Length; cm += (ResolutionCM / 100d)) { double offset = (double)cm / segment.Length; - var color = GetRelativeColor(segment.BrushStops.ToList(), offset); - var output = TangoColorConverter.GetSuggestions(segment.Job, color, true); + if (colorSpace == ColorSpaces.RGB || colorSpace == ColorSpaces.LAB || colorSpace == ColorSpaces.CMYK) + { + var color = GetRelativeRGB(segment.BrushStops.ToList(), offset); + var output = TangoColorConverter.GetSuggestions(segment.Job, color, true); + + BrushStop s = new BrushStop(); + s.Segment = segment; + s.ColorSpace = new ColorSpace(); + s.ColorSpace.Code = ColorSpaces.RGB.ToInt32(); + s.Corrected = true; + s.OffsetPercent = offset * 100d; + s.OffsetMeters = segment.Length * offset; + s.Red = color.R; + s.Green = color.G; + s.Blue = color.B; + s.StopIndex = stopIndex++; + + TangoColorConverter.ApplyBrushStopCorrection(s, processParameters, output); + + stops.Add(s); + } + else if (colorSpace == ColorSpaces.Volume || colorSpace == ColorSpaces.Twine) + { + var cmyk = GetRelativeCMYK(segment.BrushStops.ToList(), offset); + var stop = refStop.Clone(segment); - BrushStop s = new BrushStop(); - s.Segment = segment; - s.ColorSpace = new ColorSpace(); - s.ColorSpace.Code = ColorSpaces.RGB.ToInt32(); - s.Corrected = true; - s.OffsetPercent = offset * 100d; - s.OffsetMeters = segment.Length * offset; - s.Red = color.R; - s.Green = color.G; - s.Blue = color.B; - s.StopIndex = stopIndex++; + stop.OffsetPercent = offset * 100d; + stop.OffsetMeters = segment.Length * offset; + stop.StopIndex = stopIndex++; - TangoColorConverter.ApplyBrushStopCorrection(s, processParameters, output); + stop.SetVolume(LiquidTypes.Cyan, cmyk.C); + stop.SetVolume(LiquidTypes.Magenta, cmyk.M); + stop.SetVolume(LiquidTypes.Yellow, cmyk.Y); + stop.SetVolume(LiquidTypes.Black, cmyk.K); - stops.Add(s); + stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + + stops.Add(stop); + } progress?.Invoke(new PreparingJobProgressEventArgs() { @@ -93,6 +138,9 @@ namespace Tango.Integration.Operation }); } + stops.Last().OffsetPercent = 100; + stops.Last().OffsetMeters = segment.Length; + progress?.Invoke(new PreparingJobProgressEventArgs() { Job = job, @@ -103,7 +151,60 @@ namespace Tango.Integration.Operation return stops; } - private Color GetRelativeColor(List brushStopsCollection, double offset) + private CMYK GetRelativeCMYK(List brushStopsCollection, double offset) + { + BrushStop refStop = brushStopsCollection.First().Clone(); + + brushStopsCollection = brushStopsCollection.Select(x => x.Clone()).ToList(); + brushStopsCollection.ForEach(x => x.OffsetPercent = x.OffsetPercent / 100d); + + var cmykCollection = brushStopsCollection.Select(x => GetCMYK(x)).ToList(); + + var stop = cmykCollection.SingleOrDefault(f => f.OffsetPercent == offset); + if (stop != null) return stop; + + CMYK before = cmykCollection.Where(w => w.OffsetPercent == cmykCollection.Min(m => m.OffsetPercent)).First(); + CMYK after = cmykCollection.Where(w => w.OffsetPercent == cmykCollection.Max(m => m.OffsetPercent)).First(); + + foreach (var gs in cmykCollection) + { + if (gs.OffsetPercent < offset && gs.OffsetPercent > before.OffsetPercent) + { + before = gs; + } + if (gs.OffsetPercent > offset && gs.OffsetPercent < after.OffsetPercent) + { + after = gs; + } + } + + CMYK cmyk = new CMYK(); + + cmyk.C = (float)((offset - before.OffsetPercent) * (after.C - before.C) / (after.OffsetPercent - before.OffsetPercent) + before.C); + cmyk.M = (float)((offset - before.OffsetPercent) * (after.M - before.M) / (after.OffsetPercent - before.OffsetPercent) + before.M); + cmyk.Y = (float)((offset - before.OffsetPercent) * (after.Y - before.Y) / (after.OffsetPercent - before.OffsetPercent) + before.Y); + cmyk.K = (float)((offset - before.OffsetPercent) * (after.K - before.K) / (after.OffsetPercent - before.OffsetPercent) + before.K); + + //cmyk.C *= 100d; + //cmyk.M *= 100d; + //cmyk.Y *= 100d; + //cmyk.K *= 100d; + + return cmyk; + } + + private CMYK GetCMYK(BrushStop stop) + { + CMYK cmyk = new CMYK(); + cmyk.C = stop.GetVolume(LiquidTypes.Cyan); + cmyk.M = stop.GetVolume(LiquidTypes.Magenta); + cmyk.Y = stop.GetVolume(LiquidTypes.Yellow); + cmyk.K = stop.GetVolume(LiquidTypes.Black); + cmyk.OffsetPercent = stop.OffsetPercent; + return cmyk; + } + + private Color GetRelativeRGB(List brushStopsCollection, double offset) { brushStopsCollection = brushStopsCollection.Select(x => x.ShallowClone()).ToList(); brushStopsCollection.ForEach(x => x.OffsetPercent = x.OffsetPercent / 100d); diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs index 27750492e..94e20a8b4 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs @@ -14,6 +14,8 @@ namespace Tango.Transport.Discovery /// public class DiscoveredService : EventArgs where DiscoveryMessage : IMessage { + private Func _validateDiscoveryAction; + /// /// Gets or sets the discovery message. /// @@ -35,11 +37,21 @@ namespace Tango.Transport.Discovery /// The address. /// The message. /// The host name. - public DiscoveredService(String address, String hostName, DiscoveryMessage message) + public DiscoveredService(String address, String hostName, DiscoveryMessage message, Func validateDiscoveryAction) { HostName = hostName; Address = address; Message = message; + _validateDiscoveryAction = validateDiscoveryAction; + } + + /// + /// Validates the service existence using a TCP request. + /// + /// + public bool ValidateServiceExistence() + { + return _validateDiscoveryAction(); } } } diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs index 9d043023b..773ba288a 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs @@ -88,7 +88,7 @@ namespace Tango.Transport.Discovery { UdpClient udpClient = new UdpClient(Port); udpClient.Client.ReceiveTimeout = (int)Interval.TotalMilliseconds; - var endPoint = new IPEndPoint(IPAddress.Any, 0); + var endPoint = new IPEndPoint(IPAddress.Any, Port); while (IsStarted) { @@ -110,12 +110,29 @@ namespace Tango.Transport.Discovery message = (DiscoveryMessage)parser.ParseFrom(data); var host = Dns.GetHostEntry(endPoint.Address); + string address = endPoint.Address.ToString(); ServiceDiscovered?.Invoke(this, new DiscoveredService( - endPoint.Address.ToString(), + address, host != null ? host.HostName : "Unresolved", - message)); + message + , () => + { + + try + { + TcpClient client = new TcpClient(); + client.Connect(address, Port); + client.Dispose(); + return true; + } + catch + { + return false; + } + + })); } } diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs index 1fa486e68..c37ab7f51 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs @@ -7,7 +7,9 @@ using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Timers; +using Tango.Core; using Tango.PMR.Discovery; +using Tango.Transport.Servers; namespace Tango.Transport.Discovery { @@ -15,9 +17,10 @@ namespace Tango.Transport.Discovery /// Represents UDP discovery service broadcasting a discovery message of type . /// /// - public class UdpDiscoveryService : IDiscoveryService where DiscoveryMessage : IMessage + public class UdpDiscoveryService : ExtendedObject, IDiscoveryService where DiscoveryMessage : IMessage { private Timer _timer; + private TcpServer _tcpValidationServer; /// /// Occurs before broadcasting the discovery message and gives a chance to modify the packet message. @@ -60,6 +63,11 @@ namespace Tango.Transport.Discovery public UdpDiscoveryService(int port) : this() { Port = port; + _tcpValidationServer = new TcpServer(Port); + _tcpValidationServer.ClientConnected += (x, e) => + { + e.Socket.Dispose(); + }; } /// @@ -79,6 +87,8 @@ namespace Tango.Transport.Discovery { if (!IsStarted) { + _tcpValidationServer.Start(); + _timer = new Timer(); _timer.Interval = Interval.TotalMilliseconds; _timer.Elapsed += _timer_Elapsed; @@ -96,6 +106,10 @@ namespace Tango.Transport.Discovery { if (IsStarted) { + _tcpValidationServer.Stop(); + + //Transmit the discovery packet one more time so clients can tell that we have disconnected. + BroadcastDiscoveryPacket(); _timer.Stop(); IsStarted = false; } @@ -108,18 +122,30 @@ namespace Tango.Transport.Discovery /// The instance containing the event data. private void _timer_Elapsed(object sender, ElapsedEventArgs e) { - UdpClient client = new UdpClient(); + BroadcastDiscoveryPacket(); + } + + private void BroadcastDiscoveryPacket() + { + try + { + UdpClient client = new UdpClient(); - IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Port); + IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Port); - BeforeBroadcasting?.Invoke(this, CurrentDiscoveryMessage); + BeforeBroadcasting?.Invoke(this, CurrentDiscoveryMessage); - byte[] bytes = CurrentDiscoveryMessage.ToByteArray(); + byte[] bytes = CurrentDiscoveryMessage.ToByteArray(); - client.EnableBroadcast = true; - client.Send(bytes, bytes.Length, endPoint); + client.EnableBroadcast = true; + client.Send(bytes, bytes.Length, endPoint); - client.Close(); + client.Close(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error broadcasting discovery packet."); + } } } } diff --git a/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs b/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs index d6e2ad1d0..29cc3c7e8 100644 --- a/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs +++ b/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs @@ -60,7 +60,7 @@ namespace Tango.Transport.Servers Listener = new TcpListener(System.Net.IPAddress.Any, Port); Listener.Start(); IsStarted = true; - LogManager.Log("Server Started!"); + LogManager.Log($"TCP started on port {Port}."); WaitForConnection(); } } @@ -73,7 +73,7 @@ namespace Tango.Transport.Servers { Listener.Stop(); IsStarted = false; - LogManager.Log("Server Stopped!"); + LogManager.Log($"TCP stopped on port {Port}."); } } @@ -110,7 +110,6 @@ namespace Tango.Transport.Servers protected virtual void OnClientConnected(TcpClient socket) { - LogManager.Log("New client connected."); ClientConnected?.Invoke(this, new ClientConnectedEventArgs(socket)); } -- cgit v1.3.1 From f95997c235bab4106f4bdfa33b4b8adb9921bb48 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 23 Apr 2019 12:21:12 +0300 Subject: Added guidance to event types. Implemented general event view on PPC. Improved job resume tracking. Improved job resume on PPC. Added corruption emulation to machine emulator. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes .../Build/Shortcuts/Machine Emulator.lnk | Bin 1530 -> 1445 bytes .../Tango.PPC.Events/EventsViews/GeneralView.xaml | 25 +++- .../Tango.PPC.Events/Images/machine_small.png | Bin 0 -> 37734 bytes .../Tango.PPC.Events/Tango.PPC.Events.csproj | 5 +- .../Tango.PPC.Events/ViewModels/MainViewVM.cs | 2 +- .../Modules/Tango.PPC.Events/Views/MainView.xaml | 4 +- .../Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs | 2 + .../Tango.PPC.Jobs/ViewModels/MainViewVM.cs | 10 +- .../Connection/DefaultMachineProvider.cs | 10 +- .../PPC/Tango.PPC.Common/Resources/Merged.xaml | 1 + .../Visual_Studio/Tango.BL/DTO/EventTypeDTOBase.cs | 8 ++ .../Tango.BL/Entities/EventTypeBase.cs | 38 ++++++ .../Tango.DAL.Remote/DB/EVENT_TYPES.cs | 1 + .../Tango.DAL.Remote/DB/RemoteADO.edmx | 3 + .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 140 ++++++++++----------- .../Tango.Emulations/Emulators/MachineEmulator.cs | 72 +++++++---- .../Tango.Integration/Operation/JobHandler.cs | 2 +- .../Tango.Integration/Operation/MachineOperator.cs | 12 +- .../Converters/StringToLinesConverter.cs | 32 +++++ .../Tango.SharedUI/Tango.SharedUI.csproj | 3 +- .../Visual_Studio/Tango.Transport/ITransporter.cs | 5 + .../Tango.Transport/TransporterBase.cs | 8 +- Software/Visual_Studio/Tango.sln | 12 +- .../Tango.EventsTypesGenerator/Program.cs | 1 + .../Tango.MachineEM.UI/Views/MainView.xaml | 1 + 29 files changed, 282 insertions(+), 115 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Images/machine_small.png create mode 100644 Software/Visual_Studio/Tango.SharedUI/Converters/StringToLinesConverter.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 87b59afc3..385ec2708 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 79746966d..c94ea41e5 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 7670a3170..488624b20 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 1cf272342..6e8a53f2e 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 697cc906e..10e5b56da 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/GeneralView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/GeneralView.xaml index edec8cb55..8ba021afb 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/GeneralView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/GeneralView.xaml @@ -3,10 +3,29 @@ 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:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:local="clr-namespace:Tango.PPC.Events.EventsViews" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> - - + d:DesignHeight="220" d:DesignWidth="750" d:DataContext="{d:DesignInstance Type=entities:MachinesEvent, IsDesignTimeCreatable=False}"> + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Images/machine_small.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Images/machine_small.png new file mode 100644 index 000000000..8b86bfe25 Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Images/machine_small.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj index 815223834..e446e3812 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj @@ -167,10 +167,13 @@ + + + - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs index 9ee24ad38..49e0763d9 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs @@ -132,7 +132,7 @@ namespace Tango.PPC.Events.ViewModels var notificationItem = new MessageNotificationItem(); notificationItem.CanClose = false; notificationItem.Message = ev.EventType.Title; - notificationItem.ExpandedMessage = ev.Description; + notificationItem.ExpandedMessage = ev.EventType.Description; notificationItem.Pressed += async (_, __) => { SelectedEventsSource = EventsSource.CURRENT; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml index 3477a5349..af42a5576 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml @@ -83,7 +83,7 @@ - + @@ -168,7 +168,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs index d37ce7583..103a10b28 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs @@ -141,6 +141,8 @@ namespace Tango.PPC.Jobs.ViewModels e.JobHandler.StatusChanged += JobHandler_StatusChanged; e.JobHandler.SpoolChangeRequired += JobHandler_SpoolChangeRequired; e.JobHandler.Stopped += JobHandler_Stopped; + + _stop_job_btn.Push(); } /// diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs index d72f4544a..ed1e28f55 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs @@ -23,6 +23,8 @@ namespace Tango.PPC.Jobs.ViewModels /// public class MainViewVM : PPCViewModel { + private NotificationItem _last_failed_job_notification; + /// /// Called when the application has been started. /// @@ -52,6 +54,12 @@ namespace Tango.PPC.Jobs.ViewModels InvokeUI(() => { NavigationManager.NavigateTo(nameof(JobProgressView)); + + if (_last_failed_job_notification != null) + { + _last_failed_job_notification.Close(); + _last_failed_job_notification = null; + } }); } catch (Exception ex) @@ -71,7 +79,7 @@ namespace Tango.PPC.Jobs.ViewModels /// The instance containing the event data. private void MachineOperator_PrintingFailed(object sender, PrintingFailedEventArgs e) { - NotificationProvider.PushNotification(new MessageNotificationItem( + _last_failed_job_notification = NotificationProvider.PushNotification(new MessageNotificationItem( String.Format("'{0}' failed.", e.Job.Name), String.Format("The job '{1}' has failed due to unexpected error.{0}{2}{0}{0}Tap to view this job details.", Environment.NewLine, e.Job.Name, e.Exception), MessageNotificationItem.MessageNotificationItemTypes.Error, () => { 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 3ffb6f634..61ddfdb2b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -119,7 +119,15 @@ namespace Tango.PPC.Common.Connection MachineOperator.Adapter = response.Adapter; MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp; LogManager.Log("Connecting machine operator...", LogCategory.Debug); - await MachineOperator.Connect(); + try + { + await MachineOperator.Connect(); + } + catch (Exception) + { + await response.Adapter.Disconnect(); + throw; + } await Task.Delay(1000); 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 62f248a8c..b5b9f9b23 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Merged.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Merged.xaml @@ -48,6 +48,7 @@ +