From 700802033b3f729ec6875ae147f5b2b869798a08 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 14:00:29 +0100 Subject: [PATCH] Added Alt Az coordinates to the connected message. --- .../TelescopeUnitTests.cs | 4 +- Meade.net.Telescope/Telescope.cs | 110 +++++++++++------- Meade.net/SharedResources.cs | 3 +- 3 files changed, 69 insertions(+), 48 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f668703..36ff739 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -477,7 +477,7 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } } @@ -488,7 +488,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(TelescopeList.LX200GPS, string.Empty); _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); } diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ffeead3..0095144 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -503,8 +503,9 @@ namespace ASCOM.Meade.net } var raAndDec = GetTelescopeRaAndDec(); + var altAndAz = GetTelescopeAltAz(); LogMessage("Connected Set", - $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); + $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)} Az={altAndAz.Azimuth} Alt={altAndAz.Altitude}"); } catch (Exception) { @@ -1102,28 +1103,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - try - { - CheckParked(); - - //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! - var result = SharedResourcesWrapper.SendString("GA"); - //:GA# Get Telescope Altitude - //Returns: sDD* MM# or sDD*MM'SS# - //The current scope altitude. The returned format depending on the current precision setting. - - var alt = _utilities.DMSToDegrees(result); - LogMessage("Altitude", $"{alt}"); - return alt; - } - catch (ParkedException) - { - var parkedPosition = SharedResourcesWrapper.ParkedPosition; - if (parkedPosition != null) - return parkedPosition.Altitude; - - throw; - } + return GetRealTelescopeAltitude(); } var altAz = CalcAltAzFromTelescopeEqData(); @@ -1132,6 +1112,32 @@ namespace ASCOM.Meade.net } } + private double GetRealTelescopeAltitude() + { + try + { + CheckParked(); + + //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! + var result = SharedResourcesWrapper.SendString("GA"); + //:GA# Get Telescope Altitude + //Returns: sDD* MM# or sDD*MM'SS# + //The current scope altitude. The returned format depending on the current precision setting. + + var alt = _utilities.DMSToDegrees(result); + LogMessage("Altitude", $"{alt}"); + return alt; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Altitude; + + throw; + } + } + private HorizonCoordinates CalcAltAzFromTelescopeEqData() { var altitudeData = new AltitudeData @@ -1159,6 +1165,15 @@ namespace ASCOM.Meade.net }; } + private HorizonCoordinates GetTelescopeAltAz() + { + return new HorizonCoordinates() + { + Altitude = GetRealTelescopeAltitude(), + Azimuth = GetRealTelescopeAzimuth() + }; + } + public double ApertureArea { get @@ -1212,28 +1227,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - try - { - CheckParked(); - - var result = SharedResourcesWrapper.SendString("GZ"); - //:GZ# Get telescope azimuth - //Returns: DDD*MM#T or DDD*MM'SS# - //The current telescope Azimuth depending on the selected precision. - - double az = _utilities.DMSToDegrees(result); - - LogMessage("Azimuth Get", $"{az}"); - return az; - } - catch (ParkedException) - { - var parkedPosition = SharedResourcesWrapper.ParkedPosition; - if (parkedPosition != null) - return parkedPosition.Azimuth; - - throw; - } + return GetRealTelescopeAzimuth(); } var altAz = CalcAltAzFromTelescopeEqData(); @@ -1242,6 +1236,32 @@ namespace ASCOM.Meade.net } } + private double GetRealTelescopeAzimuth() + { + try + { + CheckParked(); + + var result = SharedResourcesWrapper.SendString("GZ"); + //:GZ# Get telescope azimuth + //Returns: DDD*MM#T or DDD*MM'SS# + //The current telescope Azimuth depending on the selected precision. + + double az = _utilities.DMSToDegrees(result); + + LogMessage("Azimuth Get", $"{az}"); + return az; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Azimuth; + + throw; + } + } + public bool CanFindHome { get diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 4ad7cf6..aac7262 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -391,8 +391,9 @@ namespace ASCOM.Meade.net SharedSerial.Parity = (SerialParity)Enum.Parse(typeof(SerialParity), profileProperties.Parity); SharedSerial.Speed = (SerialSpeed)profileProperties.Speed; SharedSerial.Handshake = (SerialHandshake)Enum.Parse(typeof(SerialHandshake), profileProperties.Handshake); + SharedSerial.ReceiveTimeout = 5; //5 second timeout; SharedSerial.Connected = true; - + try { ProductName = SendString("GVP");