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] [Test]
public void CanUnpark_Get_ReturnsFalse() public void CanUnpark_NotConnected_ThrowsException()
{ {
var exception = Assert.Throws<NotConnectedException>(() =>
{
var result = _telescope.CanUnpark;
});
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; var result = _telescope.CanUnpark;
Assert.That(result, Is.True); 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] [Test]
@@ -1702,12 +1743,6 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(result, Is.EqualTo(settleTime)); Assert.That(result, Is.EqualTo(settleTime));
} }
[Test]
public void Unpark_ThenDoesNotThrowException()
{
Assert.DoesNotThrow(() => { _telescope.Unpark(); });
}
[Test] [Test]
public void SiteLatitude_Get_WhenNotConnected_ThenThrowsException() public void SiteLatitude_Get_WhenNotConnected_ThenThrowsException()
{ {
@@ -1732,7 +1767,7 @@ namespace Meade.net.Telescope.UnitTests
var result = _telescope.SiteLatitude; 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)); Assert.That(result,Is.EqualTo(siteLatitudeValue));
} }
+103 -53
View File
@@ -409,6 +409,9 @@ namespace ASCOM.Meade.net
{ {
LogMessage("Connected Set", "Making first connection telescope adjustments"); 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. //These settings are applied only when the first device connects to the telescope.
SetLongFormat(true); SetLongFormat(true);
@@ -1248,9 +1251,11 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("CanUnpark");
//todo make this return false for non LX-200 GPS telescopes //todo make this return false for non LX-200 GPS telescopes
LogMessage("CanUnpark", "Get - " + true); LogMessage("CanUnpark", "Get - " + true);
return true; return SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS;
} }
} }
@@ -1549,10 +1554,11 @@ namespace ASCOM.Meade.net
if (AtPark) if (AtPark)
return; 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#"); SharedResourcesWrapper.SendBlind(":hP#");
//:hP# Autostar, Autostar II and LX 16”Slew to Park Position //:hP# Autostar, Autostar II and LX 16”Slew to Park Position
//Returns: Nothing //Returns: Nothing
AtPark = true;
} }
private bool _userNewerPulseGuiding = true; private bool _userNewerPulseGuiding = true;
@@ -1803,20 +1809,31 @@ namespace ASCOM.Meade.net
} }
} }
private double _lastGoodSiteLatitude;
public double SiteLatitude public double SiteLatitude
{ {
get get
{ {
CheckConnected("SiteLatitude Get"); CheckConnected("SiteLatitude Get");
try
{
CheckParked();
var latitude = SharedResourcesWrapper.SendString(":Gt#"); var latitude = SharedResourcesWrapper.SendString(":Gt#");
//:Gt# Get Current Site Latitude //:Gt# Get Current Site Latitude
//Returns: sDD* MM# //Returns: sDD* MM#
//The latitude of the current site. Positive inplies North latitude. //The latitude of the current site. Positive inplies North latitude.
var siteLatitude = _utilities.DMSToDegrees(latitude); var siteLatitude = _utilities.DMSToDegrees(latitude);
LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}"); LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}");
return siteLatitude;
_lastGoodSiteLatitude = siteLatitude;
return siteLatitude;
}
catch (ParkedException)
{
return _lastGoodSiteLatitude;
}
} }
set set
{ {
@@ -1845,26 +1862,39 @@ namespace ASCOM.Meade.net
//1 - Valid //1 - Valid
if (result != "1") if (result != "1")
throw new InvalidOperationException("Failed to set site latitude."); throw new InvalidOperationException("Failed to set site latitude.");
_lastGoodSiteLatitude = value;
} }
} }
private double _lastGoodSiteLongitude;
public double SiteLongitude public double SiteLongitude
{ {
get get
{ {
CheckConnected("SiteLongitude Get"); CheckConnected("SiteLongitude Get");
try
{
CheckParked();
var longitude = SharedResourcesWrapper.SendString(":Gg#"); var longitude = SharedResourcesWrapper.SendString(":Gg#");
//:Gg# Get Current Site Longitude //:Gg# Get Current Site Longitude
//Returns: sDDD*MM# //Returns: sDDD*MM#
//The current site Longitude. East Longitudes are expressed as negative //The current site Longitude. East Longitudes are expressed as negative
double siteLongitude = -_utilities.DMSToDegrees(longitude); double siteLongitude = -_utilities.DMSToDegrees(longitude);
if (siteLongitude < -180) if (siteLongitude < -180)
siteLongitude = siteLongitude + 360; siteLongitude = siteLongitude + 360;
LogMessage("SiteLongitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLongitude)}"); LogMessage("SiteLongitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLongitude)}");
return siteLongitude; _lastGoodSiteLongitude = siteLongitude;
return siteLongitude;
}
catch (ParkedException)
{
return _lastGoodSiteLongitude;
}
} }
set set
{ {
@@ -1898,6 +1928,8 @@ namespace ASCOM.Meade.net
//1 - Valid //1 - Valid
if (result != "1") if (result != "1")
throw new InvalidOperationException("Failed to set site longitude."); throw new InvalidOperationException("Failed to set site longitude.");
_lastGoodSiteLongitude = value;
} }
} }
@@ -2162,7 +2194,15 @@ namespace ASCOM.Meade.net
if (_isGuiding) if (_isGuiding)
return false; 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. //:D# Requests a string of bars indicating the distance to the current target location.
//Returns: //Returns:
//LX200's a string of bar characters indicating the distance. //LX200's a string of bar characters indicating the distance.
@@ -2488,46 +2528,53 @@ namespace ASCOM.Meade.net
get get
{ {
CheckConnected("UTCDate Get"); CheckConnected("UTCDate Get");
LogMessage("UTCDate", "Get started"); LogMessage("UTCDate", "Get started");
try
var telescopeDateDetails = SharedResourcesWrapper.Lock(() =>
{ {
var tdd = new TelescopeDateDetails CheckParked();
var telescopeDateDetails = SharedResourcesWrapper.Lock(() =>
{ {
TelescopeDate = SharedResourcesWrapper.SendString(":GC#"), var tdd = new TelescopeDateDetails
//:GC# Get current date. {
//Returns: MM/DD/YY# TelescopeDate = SharedResourcesWrapper.SendString(":GC#"),
//The current local calendar date for the telescope. //:GC# Get current date.
TelescopeTime = SharedResourcesWrapper.SendString(":GL#"), //Returns: MM/DD/YY#
//:GL# Get Local Time in 24 hour format //The current local calendar date for the telescope.
//Returns: HH:MM:SS# TelescopeTime = SharedResourcesWrapper.SendString(":GL#"),
//The Local Time in 24 - hour Format //:GL# Get Local Time in 24 hour format
UtcCorrection = GetUtcCorrection() //Returns: HH:MM:SS#
}; //The Local Time in 24 - hour Format
UtcCorrection = GetUtcCorrection()
};
return tdd; return tdd;
}); });
int month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger(); int month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger();
int day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger(); int day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger();
int year = telescopeDateDetails.TelescopeDate.Substring(6, 2).ToInteger(); int year = telescopeDateDetails.TelescopeDate.Substring(6, 2).ToInteger();
if (year < 2000) //todo fix this hack that will create a Y2K100 bug if (year < 2000) //todo fix this hack that will create a Y2K100 bug
{ {
year = year + 2000; year = year + 2000;
}
int hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger();
int minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger();
int second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger();
var utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) +
telescopeDateDetails.UtcCorrection;
LogMessage("UTCDate", "Get - " + utcDate.ToString("MM/dd/yy HH:mm:ss"));
return utcDate;
}
catch (ParkedException e)
{
return DateTime.UtcNow;
} }
int hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger();
int minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger();
int second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger();
var utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) +
telescopeDateDetails.UtcCorrection;
LogMessage("UTCDate", "Get - " + utcDate.ToString("MM/dd/yy HH:mm:ss"));
return utcDate;
} }
set set
{ {
@@ -2575,8 +2622,11 @@ namespace ASCOM.Meade.net
public void Unpark() public void Unpark()
{ {
LogMessage("Unpark", "Unparking telescope"); 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) if (!AtPark)
return; return;
+1 -1
View File
@@ -76,7 +76,7 @@ namespace ASCOM.Meade.net
SendDateTime = profileProperties.SendDateTime; SendDateTime = profileProperties.SendDateTime;
ParkedBehaviour = profileProperties.ParkedBehaviour; ParkedBehaviour = profileProperties.ParkedBehaviour;
var ParkedAltAz = new HorizonCoordinates ParkedAltAz = new HorizonCoordinates
{ {
Altitude = profileProperties.ParkedAlt, Altitude = profileProperties.ParkedAlt,
Azimuth = profileProperties.ParkedAz Azimuth = profileProperties.ParkedAz
+24 -2
View File
@@ -17,6 +17,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using ASCOM.Meade.net.Wrapper; using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities; using ASCOM.Utilities;
@@ -104,7 +105,17 @@ namespace ASCOM.Meade.net
else else
SharedSerial.Transmit(message); SharedSerial.Transmit(message);
return SharedSerial.ReceiveTerminated("#").TrimEnd('#'); 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;
}
} }
} }
@@ -114,7 +125,18 @@ namespace ASCOM.Meade.net
{ {
SharedSerial.ClearBuffers(); SharedSerial.ClearBuffers();
SharedSerial.Transmit(message); SharedSerial.Transmit(message);
return SharedSerial.ReceiveCounted(1);
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;
}
} }
} }