diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-19 04:53:19 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-19 04:53:19 +0300 |
| commit | 1ba3500b421ddc58888a909fefdf2e2792c8e2be (patch) | |
| tree | 57d9a908d0c57bc65cd9f3e6f2cc616fbbfcbe04 /Software/Visual_Studio | |
| parent | b9d18dcd6e6795ed2c870a73e3111b608118a35b (diff) | |
| download | Tango-1ba3500b421ddc58888a909fefdf2e2792c8e2be.tar.gz Tango-1ba3500b421ddc58888a909fefdf2e2792c8e2be.zip | |
Implemeneted continuous ActivateVersionRequest.
Added Progress & Total.
Diffstat (limited to 'Software/Visual_Studio')
3 files changed, 115 insertions, 11 deletions
diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 5c260f639..40900f9b4 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -715,13 +715,13 @@ namespace Tango.Emulations.Emulators Task.Factory.StartNew(() => { MachineStatus.State = MachineState.RunningJob; - + List<int> calculatedStopIndexes = new List<int>(); double progress = 0; double lastProgress = 0; Stopwatch watch = new Stopwatch(); Dictionary<int, IDSPackLevel> dispenserindexToPacklevel = new Dictionary<int, IDSPackLevel>(); - + for (int i = 0; i < units; i++) { @@ -778,8 +778,8 @@ namespace Tango.Emulations.Emulators var nextStop = segment.BrushStops[index + 1]; nextStopPosition = nextStop.OffsetMeters; } - - if(!calculatedStopIndexes.Contains(stop.Index)) + + if (!calculatedStopIndexes.Contains(stop.Index)) { var brushStopPosition = currentPosition + stop.OffsetMeters; if (brushStopPosition >= lastProgress && brushStopPosition <= progress) @@ -788,7 +788,7 @@ namespace Tango.Emulations.Emulators { var quantity = dispenser.NanoliterPerCentimeter * (nextStopPosition - stop.OffsetMeters) * 100d; IDSPackLevel packLevel; - if(!dispenserindexToPacklevel.TryGetValue(dispenser.Index, out packLevel)) + if (!dispenserindexToPacklevel.TryGetValue(dispenser.Index, out packLevel)) { packLevel = MachineStatus.IDSPacksLevels.SingleOrDefault(x => x.Index == dispenser.Index); dispenserindexToPacklevel.Add(dispenser.Index, packLevel); @@ -806,7 +806,7 @@ namespace Tango.Emulations.Emulators } watch.Stop(); lastProgress = progress; - int delay = (100 - (int)watch.ElapsedMilliseconds) > 0? (100 - (int)watch.ElapsedMilliseconds) : 5; + int delay = (100 - (int)watch.ElapsedMilliseconds) > 0 ? (100 - (int)watch.ElapsedMilliseconds) : 5; Thread.Sleep(delay); if (_cancelJob) @@ -1468,7 +1468,22 @@ namespace Tango.Emulations.Emulators VersionPackageDescriptor package = VersionPackageDescriptor.Parser.ParseFrom(fs); } - Transporter.SendResponse<ActivateVersionResponse>(new ActivateVersionResponse(), request.Container.Token); + for (int i = 0; i < 100; i++) + { + Transporter.SendResponse<ActivateVersionResponse>(new ActivateVersionResponse() + { + Progress = i + 1, + Total = 100 + }, request.Container.Token); + + Thread.Sleep(10); + } + + Transporter.SendResponse<ActivateVersionResponse>(new ActivateVersionResponse() + { + Progress = 100, + Total = 100 + }, request.Container.Token, new TransportResponseConfig() { Completed = true }); } catch (Exception ex) { diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 57613aae2..a95d34e96 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -3612,11 +3612,43 @@ namespace Tango.Integration.Operation { try { + TaskCompletionSource<object> activationCompletion = new TaskCompletionSource<object>(); + + bool completed = false; + LogManager.Log("Activating version..."); + upgradeHandler.RaiseProgress(upgradeHandler.Total, FirmwareUpgradeStatus.Activating, "Activating version..."); + var activateRequest = new ActivateVersionRequest(); activateRequest.Path = package_folder; - var activateResponse = SendRequest<ActivateVersionRequest, ActivateVersionResponse>(activateRequest, new TransportRequestConfig() { Timeout = TimeSpan.FromSeconds(10), ShouldLog = true }).Result; + + SendContinuousRequest<ActivateVersionRequest, ActivateVersionResponse>(activateRequest, new TransportContinuousRequestConfig() { Timeout = TimeSpan.FromSeconds(10), ContinuousTimeout = TimeSpan.FromSeconds(10), ShouldLog = true }) + .Subscribe((response) => + { + if (!completed && response.Message.Progress > 0) + { + upgradeHandler.Total = (long)response.Message.Total; + upgradeHandler.RaiseProgress((long)response.Message.Progress, FirmwareUpgradeStatus.Activating, "Activating version..."); + } + }, (ex) => + { + if (!completed) + { + completed = true; + activationCompletion.SetException(ex); + } + }, () => + { + if (!completed) + { + completed = true; + activationCompletion.SetResult(true); + } + }); + + var result = activationCompletion.Task.GetAwaiter().GetResult(); + postActivation(); } catch (Exception ex) diff --git a/Software/Visual_Studio/Tango.PMR/FirmwareUpgrade/ActivateVersionResponse.cs b/Software/Visual_Studio/Tango.PMR/FirmwareUpgrade/ActivateVersionResponse.cs index 0774d0083..884b904e8 100644 --- a/Software/Visual_Studio/Tango.PMR/FirmwareUpgrade/ActivateVersionResponse.cs +++ b/Software/Visual_Studio/Tango.PMR/FirmwareUpgrade/ActivateVersionResponse.cs @@ -23,12 +23,13 @@ namespace Tango.PMR.FirmwareUpgrade { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "Ch1BY3RpdmF0ZVZlcnNpb25SZXNwb25zZS5wcm90bxIZVGFuZ28uUE1SLkZp", - "cm13YXJlVXBncmFkZSIZChdBY3RpdmF0ZVZlcnNpb25SZXNwb25zZUIlCiNj", - "b20udHdpbmUudGFuZ28ucG1yLmZpcm13YXJldXBncmFkZWIGcHJvdG8z")); + "cm13YXJlVXBncmFkZSI6ChdBY3RpdmF0ZVZlcnNpb25SZXNwb25zZRIQCghQ", + "cm9ncmVzcxgBIAEoARINCgVUb3RhbBgCIAEoAUIlCiNjb20udHdpbmUudGFu", + "Z28ucG1yLmZpcm13YXJldXBncmFkZWIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.FirmwareUpgrade.ActivateVersionResponse), global::Tango.PMR.FirmwareUpgrade.ActivateVersionResponse.Parser, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.FirmwareUpgrade.ActivateVersionResponse), global::Tango.PMR.FirmwareUpgrade.ActivateVersionResponse.Parser, new[]{ "Progress", "Total" }, null, null, null) })); } #endregion @@ -59,6 +60,8 @@ namespace Tango.PMR.FirmwareUpgrade { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public ActivateVersionResponse(ActivateVersionResponse other) : this() { + progress_ = other.progress_; + total_ = other.total_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -66,6 +69,28 @@ namespace Tango.PMR.FirmwareUpgrade { return new ActivateVersionResponse(this); } + /// <summary>Field number for the "Progress" field.</summary> + public const int ProgressFieldNumber = 1; + private double progress_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double Progress { + get { return progress_; } + set { + progress_ = value; + } + } + + /// <summary>Field number for the "Total" field.</summary> + public const int TotalFieldNumber = 2; + private double total_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double Total { + get { return total_; } + set { + total_ = value; + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as ActivateVersionResponse); @@ -79,12 +104,16 @@ namespace Tango.PMR.FirmwareUpgrade { if (ReferenceEquals(other, this)) { return true; } + if (Progress != other.Progress) return false; + if (Total != other.Total) return false; return true; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; + if (Progress != 0D) hash ^= Progress.GetHashCode(); + if (Total != 0D) hash ^= Total.GetHashCode(); return hash; } @@ -95,11 +124,25 @@ namespace Tango.PMR.FirmwareUpgrade { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { + if (Progress != 0D) { + output.WriteRawTag(9); + output.WriteDouble(Progress); + } + if (Total != 0D) { + output.WriteRawTag(17); + output.WriteDouble(Total); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; + if (Progress != 0D) { + size += 1 + 8; + } + if (Total != 0D) { + size += 1 + 8; + } return size; } @@ -108,6 +151,12 @@ namespace Tango.PMR.FirmwareUpgrade { if (other == null) { return; } + if (other.Progress != 0D) { + Progress = other.Progress; + } + if (other.Total != 0D) { + Total = other.Total; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -118,6 +167,14 @@ namespace Tango.PMR.FirmwareUpgrade { default: input.SkipLastField(); break; + case 9: { + Progress = input.ReadDouble(); + break; + } + case 17: { + Total = input.ReadDouble(); + break; + } } } } |
