Fixed some issued with the telescope parking and unparking. Now reports reported correctly for the LX200GPS, and Autostars

This commit is contained in:
2021-04-24 22:29:11 +01:00
parent f9bb2aa879
commit 7eec6c0008
4 changed files with 173 additions and 66 deletions
@@ -966,11 +966,52 @@ namespace Meade.net.Telescope.UnitTests
}
[Test]
public void CanUnpark_Get_ReturnsFalse()
public void CanUnpark_NotConnected_ThrowsException()
{
var exception = Assert.Throws<NotConnectedException>(() =>
{
var result = _telescope.CanUnpark;
});
Assert.That(result, Is.True);
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CanUnpark"));
}
[TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G, true)]
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, false)]
public void CanUnpark_Get_ReturnsExpectedValue(string productVersion, string firmware, bool expectedResult)
{
ConnectTelescope(productVersion, firmware);
var result = _telescope.CanUnpark;
Assert.That(result, Is.EqualTo(expectedResult));
}
[Test]
public void Unpark_NotConnect_ThrowsException()
{
var exception = Assert.Throws<NotConnectedException>(() =>
{
_telescope.Unpark();
});
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: Unpark"));
}
[TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G, true)]
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, false)]
public void Unpark_ThenDoesNotThrowException(string productVersion, string firmware, bool canUnPark)
{
ConnectTelescope(productVersion, firmware);
if (canUnPark)
Assert.DoesNotThrow(() => { _telescope.Unpark(); });
else
{
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescope.Unpark(); });
Assert.That(exception.Message, Is.EqualTo("Unable to unpark this telescope type"));
}
}
[Test]
@@ -1702,12 +1743,6 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(result, Is.EqualTo(settleTime));
}
[Test]
public void Unpark_ThenDoesNotThrowException()
{
Assert.DoesNotThrow(() => { _telescope.Unpark(); });
}
[Test]
public void SiteLatitude_Get_WhenNotConnected_ThenThrowsException()
{
@@ -1732,7 +1767,7 @@ namespace Meade.net.Telescope.UnitTests
var result = _telescope.SiteLatitude;
_sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.Once);
_sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.AtLeastOnce);
Assert.That(result,Is.EqualTo(siteLatitudeValue));
}
+55 -5
View File
@@ -409,6 +409,9 @@ namespace ASCOM.Meade.net
{
LogMessage("Connected Set", "Making first connection telescope adjustments");
LogMessage("Connected Set", $"Site Longitude: {SiteLongitude}");
LogMessage("Connected Set", $"Site Latitude: {SiteLatitude}");
//These settings are applied only when the first device connects to the telescope.
SetLongFormat(true);
@@ -1248,9 +1251,11 @@ namespace ASCOM.Meade.net
{
get
{
CheckConnected("CanUnpark");
//todo make this return false for non LX-200 GPS telescopes
LogMessage("CanUnpark", "Get - " + true);
return true;
return SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS;
}
}
@@ -1549,10 +1554,11 @@ namespace ASCOM.Meade.net
if (AtPark)
return;
//Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued.
AtPark = true;
SharedResourcesWrapper.SendBlind(":hP#");
//:hP# Autostar, Autostar II and LX 16”Slew to Park Position
//Returns: Nothing
AtPark = true;
}
private bool _userNewerPulseGuiding = true;
@@ -1803,11 +1809,15 @@ namespace ASCOM.Meade.net
}
}
private double _lastGoodSiteLatitude;
public double SiteLatitude
{
get
{
CheckConnected("SiteLatitude Get");
try
{
CheckParked();
var latitude = SharedResourcesWrapper.SendString(":Gt#");
//:Gt# Get Current Site Latitude
@@ -1816,8 +1826,15 @@ namespace ASCOM.Meade.net
var siteLatitude = _utilities.DMSToDegrees(latitude);
LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}");
_lastGoodSiteLatitude = siteLatitude;
return siteLatitude;
}
catch (ParkedException)
{
return _lastGoodSiteLatitude;
}
}
set
{
LogMessage("SiteLatitude Set", $"{_utilitiesExtra.DegreesToDMS(value)}");
@@ -1845,14 +1862,21 @@ namespace ASCOM.Meade.net
//1 - Valid
if (result != "1")
throw new InvalidOperationException("Failed to set site latitude.");
_lastGoodSiteLatitude = value;
}
}
private double _lastGoodSiteLongitude;
public double SiteLongitude
{
get
{
CheckConnected("SiteLongitude Get");
try
{
CheckParked();
var longitude = SharedResourcesWrapper.SendString(":Gg#");
//:Gg# Get Current Site Longitude
@@ -1864,8 +1888,14 @@ namespace ASCOM.Meade.net
siteLongitude = siteLongitude + 360;
LogMessage("SiteLongitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLongitude)}");
_lastGoodSiteLongitude = siteLongitude;
return siteLongitude;
}
catch (ParkedException)
{
return _lastGoodSiteLongitude;
}
}
set
{
var newLongitude = value;
@@ -1898,6 +1928,8 @@ namespace ASCOM.Meade.net
//1 - Valid
if (result != "1")
throw new InvalidOperationException("Failed to set site longitude.");
_lastGoodSiteLongitude = value;
}
}
@@ -2162,7 +2194,15 @@ namespace ASCOM.Meade.net
if (_isGuiding)
return false;
var result = SharedResourcesWrapper.SendString(":D#");
var result = string.Empty;
try
{
result = SharedResourcesWrapper.SendString(":D#");
}
catch (TimeoutException)
{
result = string.Empty;
}
//:D# Requests a string of bars indicating the distance to the current target location.
//Returns:
//LX200's a string of bar characters indicating the distance.
@@ -2488,8 +2528,10 @@ namespace ASCOM.Meade.net
get
{
CheckConnected("UTCDate Get");
LogMessage("UTCDate", "Get started");
try
{
CheckParked();
var telescopeDateDetails = SharedResourcesWrapper.Lock(() =>
{
@@ -2529,6 +2571,11 @@ namespace ASCOM.Meade.net
return utcDate;
}
catch (ParkedException e)
{
return DateTime.UtcNow;
}
}
set
{
LogMessage("UTCDate", "Set - " + value.ToString("MM/dd/yy HH:mm:ss"));
@@ -2575,8 +2622,11 @@ namespace ASCOM.Meade.net
public void Unpark()
{
LogMessage("Unpark", "Unparking telescope");
CheckConnected("Unpark");
if (SharedResourcesWrapper.ProductName != TelescopeList.LX200GPS)
throw new InvalidOperationException("Unable to unpark this telescope type");
//todo make this return only work for LX-200 GPS telescopes
if (!AtPark)
return;
+1 -1
View File
@@ -76,7 +76,7 @@ namespace ASCOM.Meade.net
SendDateTime = profileProperties.SendDateTime;
ParkedBehaviour = profileProperties.ParkedBehaviour;
var ParkedAltAz = new HorizonCoordinates
ParkedAltAz = new HorizonCoordinates
{
Altitude = profileProperties.ParkedAlt,
Azimuth = profileProperties.ParkedAz
+22
View File
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities;
@@ -104,8 +105,18 @@ namespace ASCOM.Meade.net
else
SharedSerial.Transmit(message);
try
{
return SharedSerial.ReceiveTerminated("#").TrimEnd('#');
}
catch (COMException ex)
{
if (ex.Message.Contains("Timed out waiting for received data"))
throw new TimeoutException(ex.Message, ex);
throw;
}
}
}
public static string SendChar(string message)
@@ -114,8 +125,19 @@ namespace ASCOM.Meade.net
{
SharedSerial.ClearBuffers();
SharedSerial.Transmit(message);
try
{
return SharedSerial.ReceiveCounted(1);
}
catch (COMException ex)
{
if (ex.Message.Contains("Timed out waiting for received data"))
throw new TimeoutException(ex.Message, ex);
throw;
}
}
}
public static string ReadTerminated()