From 68928a2289215853a94fc78300191882d6f7a73b Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 21:30:22 +0100 Subject: [PATCH 1/7] Added a config setting to be able to choose whether the telescope uses high or low precision. Set to Unchanged for the telescope settings to not be altered. --- .../TelescopeUnitTests.cs | 37 ++++++++ Meade.net.Telescope/Telescope.cs | 56 ++++++++++++ Meade.net/ProfileProperties.cs | 1 + Meade.net/SetupDialogForm.cs | 13 ++- Meade.net/SetupDialogForm.designer.cs | 22 +++++ Meade.net/SetupDialogForm.resx | 87 +++++++++++++++---- Meade.net/SharedResources.cs | 4 + 7 files changed, 203 insertions(+), 17 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index ec57f83..02430a6 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -31,6 +31,7 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.TraceLogger = false; _profileProperties.ComPort = "TestCom1"; _profileProperties.GuideRateArcSecondsPerSecond = 1.23; + _profileProperties.Precision = "Unchanged"; _utilMock = new Mock(); _utilExtraMock = new Mock(); @@ -734,6 +735,42 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); } + [Test] + public void Precision_Set_WhenConnectedAndPrecisionSetUnChanged_ThenDoesNotSetPrecision() + { + _telescope.Connected = true; + + _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#"), Times.Never); + } + + [TestCase("High", false, true)] + [TestCase("High", true, true)] + [TestCase("Low", false, false)] + [TestCase("Low", true, false)] + public void Precision_Set_WhenConnectedAndPrecisionSetHighScopeIsLow_ThenTelescopePrecisionChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision) + { + _profileProperties.Precision = desiredPresision; + var currentPrecision = telescopePrecision; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":P#")).Returns(() => + { + currentPrecision = !currentPrecision; + + switch (currentPrecision) + { + case true: + return "HIGH PRECISION"; + default: + return "LOW PRECISION"; + } + }); + + _telescope.Connected = true; + + Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":P#"), Times.AtLeastOnce); + } + [Test] public void CanSetPark_Get_ReturnsFalse() { diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a88b23d..a3051fd 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -243,6 +243,8 @@ namespace ASCOM.Meade.net var parames = actionParameters.ToLower().Split(' '); switch (parames[0]) { + case "count": + return "4"; case "select": switch (parames[1]) { @@ -391,6 +393,7 @@ namespace ASCOM.Meade.net SetNewGuideRate( _guideRate, "Connect" ); } + SetTelescopePrecision("Connect"); } catch (Exception) { @@ -412,6 +415,24 @@ namespace ASCOM.Meade.net } } + private void SetTelescopePrecision(string propertyName) + { + switch (_precision) + { + case "High": + TelescopePointingPrecision(true); + LogMessage(propertyName, $"High precision slewing selected"); + break; + case "Low": + TelescopePointingPrecision(false); + LogMessage(propertyName, $"Low precision slewing selected"); + break; + default: + LogMessage(propertyName, $"Precision slewing unchanged"); + break; + } + } + public bool IsNewPulseGuidingSupported() { if (_sharedResourcesWrapper.ProductName == TelescopeList.Autostar497) @@ -466,6 +487,39 @@ namespace ASCOM.Meade.net }); } + private bool TogglePrecision() + { + var result = _sharedResourcesWrapper.SendString(":P#"); + //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. + //Returns: + //“HIGH PRECISION” Current setting after this command. + //“LOW PRECISION” Current setting after this command. + + + bool highPrecision = false; + switch (result) + { + case "HIGH PRECISION": + highPrecision = true; + break; + } + + //Make sure that the buffers are cleared out. + _sharedResourcesWrapper.SendBlind("#"); + + return highPrecision; + } + + public void TelescopePointingPrecision(bool high) + { + var currentPrecision = TogglePrecision(); + + while (currentPrecision != high) + { + currentPrecision = TogglePrecision(); + } + } + public void SelectSite(int site) { CheckConnected("SelectSite"); @@ -1963,6 +2017,7 @@ namespace ASCOM.Meade.net } private DriveRates _trackingRate = DriveRates.driveSidereal; + private string _precision; public DriveRates TrackingRate { @@ -2249,6 +2304,7 @@ namespace ASCOM.Meade.net _tl.Enabled = profileProperties.TraceLogger; _comPort = profileProperties.ComPort; _guideRate = profileProperties.GuideRateArcSecondsPerSecond; + _precision = profileProperties.Precision; LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {_comPort}"); diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 6614cc8..02f047a 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -6,5 +6,6 @@ namespace ASCOM.Meade.net public string ComPort { get; set; } public bool TraceLogger { get; set; } public double GuideRateArcSecondsPerSecond { get; set; } + public string Precision { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 36c8dac..531aac0 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -49,15 +49,24 @@ namespace ASCOM.Meade.net } txtGuideRate.Text = profileProperties.GuideRateArcSecondsPerSecond.ToString(); + try + { + cboPrecision.SelectedItem = profileProperties.Precision; + } + catch (Exception e) + { + cboPrecision.SelectedItem = "Unchanged"; + } } - public ProfileProperties GetProfile() + public ProfileProperties GetProfile() { var profileProperties = new ProfileProperties { TraceLogger = chkTrace.Checked, ComPort = comboBoxComPort.SelectedItem.ToString(), - GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()) + GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()), + Precision = cboPrecision.SelectedText }; return profileProperties; diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index a714e67..0f875dd 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -40,6 +40,8 @@ namespace ASCOM.Meade.net this.txtGuideRate = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.lblPercentOfSiderealRate = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.cboPrecision = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); this.SuspendLayout(); // @@ -112,10 +114,28 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.lblPercentOfSiderealRate, "lblPercentOfSiderealRate"); this.lblPercentOfSiderealRate.Name = "lblPercentOfSiderealRate"; // + // label5 + // + resources.ApplyResources(this.label5, "label5"); + this.label5.Name = "label5"; + // + // cboPrecision + // + this.cboPrecision.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboPrecision.FormattingEnabled = true; + this.cboPrecision.Items.AddRange(new object[] { + resources.GetString("cboPrecision.Items"), + resources.GetString("cboPrecision.Items1"), + resources.GetString("cboPrecision.Items2")}); + resources.ApplyResources(this.cboPrecision, "cboPrecision"); + this.cboPrecision.Name = "cboPrecision"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.cboPrecision); + this.Controls.Add(this.label5); this.Controls.Add(this.lblPercentOfSiderealRate); this.Controls.Add(this.label4); this.Controls.Add(this.txtGuideRate); @@ -152,5 +172,7 @@ namespace ASCOM.Meade.net private System.Windows.Forms.TextBox txtGuideRate; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label lblPercentOfSiderealRate; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.ComboBox cboPrecision; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 99399de..09d1e2f 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 10 + 12 Bottom, Right @@ -172,7 +172,7 @@ $this - 9 + 11 12, 9 @@ -196,7 +196,7 @@ $this - 8 + 10 Top, Right @@ -223,7 +223,7 @@ $this - 7 + 9 True @@ -250,13 +250,13 @@ $this - 6 + 8 True - 77, 118 + 77, 136 69, 17 @@ -277,7 +277,7 @@ $this - 5 + 7 77, 87 @@ -298,13 +298,13 @@ $this - 4 + 6 True - 13, 225 + 10, 162 61, 13 @@ -325,10 +325,10 @@ $this - 3 + 5 - 80, 222 + 77, 159 46, 20 @@ -349,13 +349,13 @@ $this - 2 + 4 True - 132, 225 + 129, 162 122, 13 @@ -376,13 +376,13 @@ $this - 1 + 3 True - 132, 238 + 129, 175 105, 13 @@ -403,6 +403,63 @@ $this + 2 + + + True + + + 13, 194 + + + 50, 13 + + + 12 + + + Precision + + + label5 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + Unchanged + + + Low + + + High + + + 77, 191 + + + 69, 21 + + + 13 + + + cboPrecision + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 1e79de9..71d9653 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -159,6 +159,7 @@ namespace ASCOM.Meade.net private const string ComPortProfileName = "COM Port"; private const string TraceStateProfileName = "Trace Level"; private const string GuideRateProfileName = "Guide Rate Arc Seconds Per Second"; + private const string PrecisionProfileName = "Precision"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -170,6 +171,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString()); driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort); driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString()); + driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision); } } } @@ -177,6 +179,7 @@ namespace ASCOM.Meade.net private const string ComPortDefault = "COM1"; private const string TraceStateDefault = "false"; private const string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate + private const string PrecisionDefault = "Unchanged"; public static ProfileProperties ReadProfile() { @@ -189,6 +192,7 @@ namespace ASCOM.Meade.net profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault); profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault)); profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault)); + profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault); } return profileProperties; From 7542e86aeb0ec32d13a31ce111b239bcb3d3a2e4 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 21:39:07 +0100 Subject: [PATCH 2/7] Added missing log message for the new precision parameter. --- Meade.net.Telescope/Telescope.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a3051fd..ac28214 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2309,6 +2309,7 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {_comPort}"); LogMessage("ReadProfile", $"Guide Rate: {_guideRate}"); + LogMessage("ReadProfile", $"Precision: {_precision}"); } internal void WriteProfile() From 98feb748704bb479754a5e45ac3c178283888c80 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 22:26:58 +0100 Subject: [PATCH 3/7] Changed how the precision item is saved. Removed the case-sensitivity. --- Meade.net.Telescope/Telescope.cs | 6 +++--- Meade.net/SetupDialogForm.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ac28214..913e9d1 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -417,13 +417,13 @@ namespace ASCOM.Meade.net private void SetTelescopePrecision(string propertyName) { - switch (_precision) + switch (_precision.ToLower()) { - case "High": + case "high": TelescopePointingPrecision(true); LogMessage(propertyName, $"High precision slewing selected"); break; - case "Low": + case "low": TelescopePointingPrecision(false); LogMessage(propertyName, $"Low precision slewing selected"); break; diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 531aac0..874ecbc 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -66,7 +66,7 @@ namespace ASCOM.Meade.net TraceLogger = chkTrace.Checked, ComPort = comboBoxComPort.SelectedItem.ToString(), GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()), - Precision = cboPrecision.SelectedText + Precision = cboPrecision.SelectedItem.ToString() }; return profileProperties; From f10936a9e805a32a43f132efa45975bbcaf277dc Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 22:30:05 +0100 Subject: [PATCH 4/7] Changes the installer name to ASCOM Meade Generic --- Meade.net.Setup/Config.wxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Meade.net.Setup/Config.wxi b/Meade.net.Setup/Config.wxi index aed1c3c..c82ae63 100644 --- a/Meade.net.Setup/Config.wxi +++ b/Meade.net.Setup/Config.wxi @@ -11,7 +11,7 @@ UpgradeCode must be unique to this product and should not be changed for the product lifetime. --> - + From f6556716a54e4661b6c7c121ac4efe0aa20e4463 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 22:43:38 +0100 Subject: [PATCH 5/7] Modified the precision toggle to only use the first letter of the response rather than try to detect the entire string --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 8 ++++---- Meade.net.Telescope/Telescope.cs | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 02430a6..6f0f5d0 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -752,23 +752,23 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.Precision = desiredPresision; var currentPrecision = telescopePrecision; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":P#")).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":P#")).Returns(() => { currentPrecision = !currentPrecision; switch (currentPrecision) { case true: - return "HIGH PRECISION"; + return "H"; default: - return "LOW PRECISION"; + return "L"; } }); _telescope.Connected = true; Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":P#"), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 913e9d1..a882d82 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -489,17 +489,18 @@ namespace ASCOM.Meade.net private bool TogglePrecision() { - var result = _sharedResourcesWrapper.SendString(":P#"); + LogMessage("TogglePrecision", $"Toggling slewing precision"); + var result = _sharedResourcesWrapper.SendChar(":P#"); //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. //Returns: //“HIGH PRECISION” Current setting after this command. //“LOW PRECISION” Current setting after this command. - + LogMessage("TogglePrecision", $"Result: {result}"); bool highPrecision = false; switch (result) { - case "HIGH PRECISION": + case "H": highPrecision = true; break; } From e1a0d6449def2e224d414d6718d340973a4ff78a Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 22:57:24 +0100 Subject: [PATCH 6/7] Added ability to read an unterminated buffer when changing slewing precision --- Meade.net.Telescope/Telescope.cs | 5 +++++ Meade.net/SharedResources.cs | 8 ++++++++ Meade.net/Wrapper/SharedResourcesWrapper.cs | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a882d82..913033e 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -496,15 +496,20 @@ namespace ASCOM.Meade.net //“HIGH PRECISION” Current setting after this command. //“LOW PRECISION” Current setting after this command. + int throwAwayCharacters = "LOW PRECISION".Length - 1; + LogMessage("TogglePrecision", $"Result: {result}"); bool highPrecision = false; switch (result) { case "H": highPrecision = true; + throwAwayCharacters = "HIGH PRECISION".Length - 1; break; } + _sharedResourcesWrapper.ReadCharacters(throwAwayCharacters); + //Make sure that the buffers are cleared out. _sharedResourcesWrapper.SendBlind("#"); diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 71d9653..8d27adb 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -116,6 +116,14 @@ namespace ASCOM.Meade.net } } + public static string ReadCharacters(int throwAwayCharacters) + { + lock (LockObject) + { + return SharedSerial.ReceiveCounted(throwAwayCharacters); + } + } + /// /// Example of handling connecting to and disconnection from the /// shared serial port. diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index c2fda79..3417ce6 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -24,6 +24,7 @@ namespace ASCOM.Meade.net.Wrapper void SetupDialog(); void WriteProfile(ProfileProperties profileProperties); + string ReadCharacters(int throwAwayCharacters); } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -72,6 +73,11 @@ namespace ASCOM.Meade.net.Wrapper return SharedResources.ReadTerminated(); } + public string ReadCharacters(int throwAwayCharacters) + { + return SharedResources.ReadCharacters(throwAwayCharacters); + } + public ProfileProperties ReadProfile() { return SharedResources.ReadProfile(); From 81a3a29743ed5994c01c2cc7e7e887a5a1ea8ea2 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 18 Aug 2019 23:05:51 +0100 Subject: [PATCH 7/7] Made the Precision combobox a bit wider. --- Meade.net/SetupDialogForm.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 09d1e2f..fd6059a 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -445,7 +445,7 @@ 77, 191 - 69, 21 + 90, 21 13