Update unit tests to support GW command

SideOfPier also supports German EQ
This commit is contained in:
Sebastian Godelet
2021-06-27 18:57:17 +10:00
parent 74440b6b3b
commit a3408a86c3
5 changed files with 72 additions and 58 deletions
@@ -121,8 +121,9 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object);
}
private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee)
private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee, string alignmentStatus = "GT0")
{
_sharedResourcesWrapperMock.Setup(x => x.SendChars("GW", false, 3)).Returns(alignmentStatus);
_sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns( () => _testProperties.SiteLatitudeString);
_utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue);
@@ -778,9 +779,8 @@ namespace Meade.net.Telescope.UnitTests
{
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns(telescopeMode);
_sharedResourcesWrapperMock.Setup(x => x.SendString("GW", false)).Returns($"{telescopeMode}N0");
ConnectTelescope(productName, firmware);
ConnectTelescope(productName, firmware, $"{telescopeMode}N0");
var actualResult = _telescope.AlignmentMode;
@@ -1942,7 +1942,7 @@ namespace Meade.net.Telescope.UnitTests
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns<double>(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA);
_astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny<double>())).Returns<double>(pRA => pRA < 0 ? pRA + 24 : pRA >= 24 ? pRA - 24 : pRA);
ConnectTelescope();
ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_43Eg);
Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1));
_telescope.SlewToCoordinates(ra, dec);
@@ -2056,7 +2056,8 @@ namespace Meade.net.Telescope.UnitTests
// Setup DestinationSideOfPier
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns<double>(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA);
ConnectTelescope();
// Use firmware that supports GW
ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_43Eg);
// when
_telescope.SlewToCoordinatesAsync(ra, dec);
@@ -3203,7 +3204,6 @@ namespace Meade.net.Telescope.UnitTests
_telescope.SlewToTarget();
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
_astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny<double>()), Times.Once);
}
[Test]
@@ -3298,7 +3298,6 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
_astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny<double>()), Times.Once);
}
[Test]
@@ -3419,7 +3418,6 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination));
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
_astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny<double>()), Times.Once);
}
[Test]
+3 -1
View File
@@ -5,6 +5,8 @@ namespace ASCOM.Meade.net
NeedsAlignment,
OneStarAligned,
TwoStarAligned,
ThreeStarAligned
ThreeStarAligned,
AlignedOnHome,
ScopeWasParked,
}
}
+49 -42
View File
@@ -360,9 +360,6 @@ namespace ASCOM.Meade.net
var result = SharedResourcesWrapper.SendBool(command, raw);
LogMessage("CommandBool", "Completed: {0}", result);
return result;
// or
//throw new MethodNotImplementedException("CommandBool");
// DO NOT have both these sections! One or the other
}
public string CommandString(string command, bool raw)
@@ -372,10 +369,19 @@ namespace ASCOM.Meade.net
// it's a good idea to put all the low level communication with the device here,
// then all communication calls this function
// you need something to ensure that only one command is in progress at a time
var result = SharedResourcesWrapper.SendString(command, raw);
LogMessage("CommandBool", "Completed: {0}", result);
string result;
// :GW# is not terminated with a # for some reason, see reported comment
// https://bitbucket.org/cjdskunkworks/meadeautostar497/issues/24/get-set-tracking#comment-60586901
if (command == (raw ? ":GW#" : "GW"))
{
result = SharedResourcesWrapper.SendChars(command, raw, count: 3);
}
else
{
result = SharedResourcesWrapper.SendString(command, raw);
}
LogMessage("CommandString", "Completed: {0}", result);
return result;
//throw new ASCOM.MethodNotImplementedException("CommandString");
}
public void Dispose()
@@ -416,7 +422,6 @@ namespace ASCOM.Meade.net
$"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}");
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
_tracking = true;
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
IsConnected = true;
@@ -620,17 +625,13 @@ namespace ASCOM.Meade.net
return false;
}
// true iff the mount will perform a meridian flip when required
// TODO: Needs checking what mounts actually support this
private bool IsMeridianFlipOnSlewSupported()
{
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC)
{
return false;
}
private bool IsGWCommandSupported() => FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg);
return true;
}
// true iff the mount will perform a meridian flip when required
// According to "A User's Guide to the Meade LXD55 and LXD75 Telescopes" Autostar supports meridian flip so
// we assume that for any telescope that supports the GW command and is not in Alt-Az mode then
// meridian flip on slew is supported
private bool IsMeridianFlipOnSlewSupported() => IsGWCommandSupported() && AlignmentMode != AlignmentModes.algAltAz;
private bool FirmwareIsGreaterThan(string minVersion)
{
@@ -957,7 +958,7 @@ namespace ASCOM.Meade.net
CheckConnected("AlignmentMode Get");
if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
if (IsGWCommandSupported())
{
var alignmentStatus = GetScopeAlignmentStatus();
return alignmentStatus.AlignmentMode;
@@ -998,7 +999,7 @@ namespace ASCOM.Meade.net
CheckConnected("AlignmentMode Set");
//todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly
if (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
if (!IsGWCommandSupported())
throw new PropertyNotImplementedException("AlignmentMode", true);
switch (value)
@@ -1025,13 +1026,14 @@ namespace ASCOM.Meade.net
private AlignmentStatus GetScopeAlignmentStatus()
{
var alignmentString = SharedResourcesWrapper.SendString("GW");
var alignmentString = CommandString("GW", false);
//:GW# Get Scope Alignment Status
//Returns: <mount><tracking><alignment>#
// where:
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
//tracking: T - tracking, N - not tracking
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned.
//tracking: T - tracking, N - not tracking, S - sleeping
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned., H - Aligned on Home, P - Scope was parked
// https://www.cloudynights.com/topic/72166-lx-200-gps-serial-commands/
var alignmentStatus = new AlignmentStatus();
switch (alignmentString[0])
@@ -1046,8 +1048,8 @@ namespace ASCOM.Meade.net
alignmentStatus.AlignmentMode = AlignmentModes.algGermanPolar;
break;
}
alignmentStatus.Tracking = alignmentString[0] == 'T';
switch (alignmentString[1])
alignmentStatus.Tracking = alignmentString[1] == 'T';
switch (alignmentString[2])
{
case '0':
alignmentStatus.Status = Alignment.NeedsAlignment;
@@ -1061,9 +1063,14 @@ namespace ASCOM.Meade.net
case '3':
alignmentStatus.Status = Alignment.ThreeStarAligned;
break;
case 'H':
alignmentStatus.Status = Alignment.AlignedOnHome;
break;
case 'P':
alignmentStatus.Status = Alignment.ScopeWasParked;
break;
}
return alignmentStatus;
}
@@ -1228,7 +1235,7 @@ namespace ASCOM.Meade.net
switch (axis)
{
case TelescopeAxes.axisPrimary: return true; //RA or AZ
case TelescopeAxes.axisSecondary: return true; //Dev or Alt
case TelescopeAxes.axisSecondary: return true; //DEC or Alt
case TelescopeAxes.axisTertiary: return false; //rotator / derotator
default: throw new InvalidValueException("CanMoveAxis", axis.ToString(), "0 to 2");
}
@@ -1890,24 +1897,25 @@ namespace ASCOM.Meade.net
{
get
{
if (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
if (!IsMeridianFlipOnSlewSupported())
{
LogMessage("SideOfPier Get", "Not implemented");
throw new PropertyNotImplementedException("SideOfPier", false);
}
PierSide pierSide;
if (Slewing)
{
// because we update SideOfPier after initiating the slew command we return unknown while still slewing
pierSide = PierSide.pierUnknown;
}
else
{
var alignmentStatus = GetScopeAlignmentStatus();
if (alignmentStatus.AlignmentMode != AlignmentModes.algPolar)
throw new PropertyNotImplementedException("SideOfPier", false);
// while mount is slewing return unknown, this is required since
// DoSlewAsync updates _pierSide before slew is finished
var pierSide = Slewing ? PierSide.pierUnknown : SharedResourcesWrapper.SideOfPier;
LogMessage("SideOfPier", "Get - " + pierSide);
return pierSide;
pierSide = SharedResourcesWrapper.SideOfPier;
}
LogMessage("SideOfPier", "Get - " + pierSide);
return pierSide;
}
// ReSharper disable once ValueParameterNotUsed
set
@@ -2594,19 +2602,18 @@ namespace ASCOM.Meade.net
}
}
private bool _tracking = true;
public bool Tracking
{
get
{
LogMessage("Tracking", $"Get - {_tracking}");
if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
LogMessage("Tracking", "Get");
if (IsGWCommandSupported())
{
var alignmentStatus = GetScopeAlignmentStatus();
_tracking = alignmentStatus.Tracking;
return alignmentStatus.Tracking;
}
return _tracking;
return true;
}
set
{
+8 -7
View File
@@ -124,13 +124,17 @@ namespace ASCOM.Meade.net
public static bool SendBool(string command, bool raw = false)
{
var result = SendChar(command, raw);
return result == "1";
}
public static string SendChar(string command, bool raw = false)
{
return SendChars(command, raw, count: 1);
}
public static string SendChars(string command, bool raw = false, int count = 1)
{
lock (LockObject)
{
@@ -141,14 +145,11 @@ namespace ASCOM.Meade.net
try
{
return SharedSerial.ReceiveCounted(1);
return SharedSerial.ReceiveCounted(count);
}
catch (COMException ex)
catch (COMException ex) when (ex.Message.Contains("Timed out waiting for received data"))
{
if (ex.Message.Contains("Timed out waiting for received data"))
throw new TimeoutException(ex.Message, ex);
throw;
throw new TimeoutException(ex.Message, ex);
}
}
}
@@ -20,6 +20,7 @@ namespace ASCOM.Meade.net.Wrapper
void SendBlind(string message, bool raw = false);
bool SendBool(string command, bool raw = false);
string SendChar(string message, bool raw = false);
string SendChars(string message, bool raw = false, int count = 1);
string ReadTerminated();
@@ -94,6 +95,11 @@ namespace ASCOM.Meade.net.Wrapper
return SharedResources.SendChar(message, raw);
}
public string SendChars(string message, bool raw = false, int count = 1)
{
return SharedResources.SendChars(message, raw, count);
}
public string ReadTerminated()
{
return SharedResources.ReadTerminated();