From b01d61382583d20e70e759e0397c40c39b76d57a Mon Sep 17 00:00:00 2001 From: rennmaus-coder <77056626+rennmaus-coder@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:05:28 +0100 Subject: [PATCH] remove redudant time fields; add conditions and triggers; fix time instructions / conditions --- ninaAPI/Properties/AssemblyInfo.cs | 4 +- ninaAPI/WebService/V2/Application/Sequence.cs | 153 +++++++++++------- ninaAPI/buildAndCopy.bat | 1 + 3 files changed, 97 insertions(+), 61 deletions(-) diff --git a/ninaAPI/Properties/AssemblyInfo.cs b/ninaAPI/Properties/AssemblyInfo.cs index c5fe519..16e81db 100644 --- a/ninaAPI/Properties/AssemblyInfo.cs +++ b/ninaAPI/Properties/AssemblyInfo.cs @@ -6,8 +6,8 @@ // [MANDATORY] The assembly versioning //Should be incremented for each new build of a plugin -[assembly: AssemblyVersion("2.1.0.2")] -[assembly: AssemblyFileVersion("2.1.0.2")] +[assembly: AssemblyVersion("2.1.0.3")] +[assembly: AssemblyFileVersion("2.1.0.3")] // [MANDATORY] The name of your plugin [assembly: AssemblyTitle("Advanced API")] diff --git a/ninaAPI/WebService/V2/Application/Sequence.cs b/ninaAPI/WebService/V2/Application/Sequence.cs index e13cde0..699969c 100644 --- a/ninaAPI/WebService/V2/Application/Sequence.cs +++ b/ninaAPI/WebService/V2/Application/Sequence.cs @@ -37,6 +37,9 @@ This Source Code Form is subject to the terms of the Mozilla Public using NINA.Sequencer.SequenceItem.Switch; using NINA.Sequencer.SequenceItem.Telescope; using System.IO; +using System.Security.Policy; +using NINA.Sequencer; +using System.Linq; namespace ninaAPI.WebService.V2 { @@ -65,7 +68,9 @@ public void SequenceJson() } else { - response.Response = getSequenceRecursivley(targets[0].Parent.Parent); + List json = getSequenceRecursivley(targets[0].Parent.Parent); + json.Add(new Hashtable() { { "GlobalTriggers", getTriggers(targets[0].Parent.Parent as SequenceContainer) } }); // Global triggers + response.Response = json; } } } @@ -78,95 +83,124 @@ public void SequenceJson() HttpContext.WriteToResponse(response); } - private static List getSequenceRecursivley(ISequenceContainer sequence) + private static List getConditions(SequenceContainer sequence) { - List result = new List(); - foreach (var item in sequence.Items) + List conditions = new List(); + foreach (var condition in sequence.Conditions) { - Hashtable it = new Hashtable + Hashtable ctable = new Hashtable { - { "Name", item.Name }, - { "Status", item.Status.ToString() }, - // { "Description", item.Description } + { "Name", condition.Name + "_Condition" }, + { "Status", condition.Status.ToString() } }; - - if (item is ISequenceTrigger t) + if (condition is TimeCondition c1) { - it["Name"] = item.Name + "_Trigger"; + ctable.Add("RemainingTime", c1.RemainingTime); + ctable.Add("TargetTime", c1.DateTime.Now + c1.RemainingTime); } - else if (item is ISequenceCondition c) + else if (condition is LoopForAltitudeBase c2) { - it["Name"] = item.Name + "_Condition"; + ctable.Add("Altitude", c2.Data.Offset); + ctable.Add("CurrentAltitude", c2.Data.CurrentAltitude); + ctable.Add("ExpectedTime", c2.Data.ExpectedTime); } - else if (item is ISequenceContainer container && item is not SmartExposure && item is not TakeManyExposures) + else if (condition is LoopCondition c3) { - it["Name"] = item.Name + "_Container"; - it.Add("Items", getSequenceRecursivley(container)); + ctable.Add("Iterations", c3.Iterations); + ctable.Add("CompletedIterations", c3.CompletedIterations); } - - if (item is AutofocusAfterExposures trigger) + else if (condition is MoonIlluminationCondition c5) { - it.Add("Exposures", trigger.ProgressExposures); - it.Add("DeltaExposures", trigger.AfterExposures); + ctable.Add("TargetIllumination", c5.UserMoonIllumination); + ctable.Add("CurrentIllumination", c5.CurrentMoonIllumination); } - else if (item is AutofocusAfterHFRIncreaseTrigger t2) + else if (condition is TimeSpanCondition c6) { - it.Add("HFRTrendPercentage", t2.HFRTrendPercentage); - it.Add("OriginalHFR", t2.OriginalHFR); - it.Add("SampleSize", t2.SampleSize); - it.Add("DeltaHFR", t2.Amount); + ctable.Add("RemainingTime", c6.RemainingTime); + ctable.Add("TargetTime", c6.DateTime.Now + c6.RemainingTime); } - else if (item is AutofocusAfterTemperatureChangeTrigger t3) + conditions.Add(ctable); + + } + return conditions; + } + + private static List getTriggers(SequenceContainer sequence) + { + List triggers = new List(); + foreach (var trigger in sequence.Triggers) + { + Hashtable triggertable = new Hashtable { - it.Add("DeltaTemperature", t3.DeltaT); - it.Add("TargetTemperature", t3.Amount); - } - else if (item is AutofocusAfterTimeTrigger t4) + { "Name", trigger.Name + "_Trigger" }, + { "Status", trigger.Status.ToString() } + }; + if (trigger is AutofocusAfterExposures t1) { - it.Add("DeltaTime", t4.Amount); - it.Add("ElapsedTime", t4.Elapsed); + triggertable.Add("Exposures", t1.ProgressExposures); + triggertable.Add("DeltaExposures", t1.AfterExposures); } - else if (item is DitherAfterExposures t5) + else if (trigger is AutofocusAfterHFRIncreaseTrigger t2) { - it.Add("Exposures", t5.ProgressExposures); - it.Add("TargetExposures", t5.AfterExposures); + triggertable.Add("HFRTrendPercentage", t2.HFRTrendPercentage); + triggertable.Add("OriginalHFR", t2.OriginalHFR); + triggertable.Add("SampleSize", t2.SampleSize); + triggertable.Add("DeltaHFR", t2.Amount); } - else if (item is MeridianFlipTrigger t6) + else if (trigger is AutofocusAfterTemperatureChangeTrigger t3) { - it.Add("TimeToFlip", t6.TimeToMeridianFlip); + triggertable.Add("DeltaTemperature", t3.DeltaT); + triggertable.Add("TargetTemperature", t3.Amount); } - else if (item is CenterAfterDriftTrigger t7) + else if (trigger is AutofocusAfterTimeTrigger t4) { - it.Add("Coordinates", t7.Coordinates); - it.Add("Drift", t7.LastDistanceArcMinutes); - it.Add("TargetDrift", t7.DistanceArcMinutes); + triggertable.Add("DeltaTime", t4.Amount); + triggertable.Add("ElapsedTime", t4.Elapsed); } - else if (item is TimeCondition c1) + else if (trigger is DitherAfterExposures t5) { - it.Add("RemainingTime", c1.RemainingTime); - it.Add("DateTime", c1.DateTime); + triggertable.Add("Exposures", t5.ProgressExposures); + triggertable.Add("TargetExposures", t5.AfterExposures); } - else if (item is LoopForAltitudeBase c2) + else if (trigger is MeridianFlipTrigger t6) { - it.Add("Altitude", c2.Data.Offset); - it.Add("CurrentAltitude", c2.Data.CurrentAltitude); - it.Add("ExpectedTime", c2.Data.ExpectedTime); + triggertable.Add("TimeToFlip", t6.TimeToMeridianFlip); } - else if (item is LoopCondition c3) + else if (trigger is CenterAfterDriftTrigger t7) { - it.Add("Iterations", c3.Iterations); - it.Add("CompletedIterations", c3.CompletedIterations); + triggertable.Add("Coordinates", t7.Coordinates); + triggertable.Add("Drift", t7.LastDistanceArcMinutes); + triggertable.Add("TargetDrift", t7.DistanceArcMinutes); } - else if (item is MoonIlluminationCondition c5) + triggers.Add(triggertable); + } + return triggers; + } + + private static List getSequenceRecursivley(ISequenceContainer sequence) + { + List result = new List(); + + foreach (var item in sequence.Items) + { + Hashtable it = new Hashtable { - it.Add("TargetIllumination", c5.UserMoonIllumination); - it.Add("CurrentIllumination", c5.CurrentMoonIllumination); - } - else if (item is TimeSpanCondition c6) + { "Name", item.Name }, + { "Status", item.Status.ToString() }, + // { "Description", item.Description } + }; + + if (item is ISequenceContainer container && item is not SmartExposure && item is not TakeManyExposures) { - it.Add("RemainingTime", c6.RemainingTime); - it.Add("DateTime", c6.DateTime); + it["Name"] = item.Name + "_Container"; + it.Add("Items", getSequenceRecursivley(container)); + if (container is SequenceContainer sc) + { + it.Add("Conditions", getConditions(sc)); + it.Add("Triggers", getTriggers(sc)); + } } + else if (item is CoolCamera i1) { it.Add("Temperature", i1.Temperature); @@ -302,7 +336,8 @@ private static List getSequenceRecursivley(ISequenceContainer sequenc } else if (item is WaitForTime i26) { - it.Add("Time", i26.DateTime); + it.Add("TargetTime", i26.DateTime.Now + i26.GetEstimatedDuration()); + it.Add("CalculatedWaitDuration", i26.GetEstimatedDuration()); } else if (item is WaitForTimeSpan i27) { diff --git a/ninaAPI/buildAndCopy.bat b/ninaAPI/buildAndCopy.bat index 489da31..0ea285e 100644 --- a/ninaAPI/buildAndCopy.bat +++ b/ninaAPI/buildAndCopy.bat @@ -16,6 +16,7 @@ cd .. cd nina.plugin.manifests git pull git pull https://AstroChris23@bitbucket.org/Isbeorn/nina.plugin.manifests.git +mkdir manifests\n\ninaAPI\3.0.0\%version% copy ..\ninaAPI\ninaAPI\manifest.json manifests\n\ninaAPI\3.0.0\%version%\manifest.json echo "Testing the manifest" node gather