Update unit tests to support GW command
SideOfPier also supports German EQ
This commit is contained in:
@@ -121,8 +121,9 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object);
|
_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);
|
_sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns( () => _testProperties.SiteLatitudeString);
|
||||||
_utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue);
|
_utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue);
|
||||||
|
|
||||||
@@ -778,9 +779,8 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
{
|
{
|
||||||
const char ack = (char)6;
|
const char ack = (char)6;
|
||||||
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns(telescopeMode);
|
_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;
|
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.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);
|
_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));
|
Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1));
|
||||||
|
|
||||||
_telescope.SlewToCoordinates(ra, dec);
|
_telescope.SlewToCoordinates(ra, dec);
|
||||||
@@ -2056,7 +2056,8 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
// Setup DestinationSideOfPier
|
// Setup DestinationSideOfPier
|
||||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns<double>(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA);
|
_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
|
// when
|
||||||
_telescope.SlewToCoordinatesAsync(ra, dec);
|
_telescope.SlewToCoordinatesAsync(ra, dec);
|
||||||
@@ -3203,7 +3204,6 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
_telescope.SlewToTarget();
|
_telescope.SlewToTarget();
|
||||||
|
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
|
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
|
||||||
_astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny<double>()), Times.Once);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -3298,7 +3298,6 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once);
|
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once);
|
||||||
|
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
|
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
|
||||||
_astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny<double>()), Times.Once);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -3419,7 +3418,6 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination));
|
Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination));
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once);
|
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once);
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
|
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
|
||||||
_astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny<double>()), Times.Once);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace ASCOM.Meade.net
|
|||||||
NeedsAlignment,
|
NeedsAlignment,
|
||||||
OneStarAligned,
|
OneStarAligned,
|
||||||
TwoStarAligned,
|
TwoStarAligned,
|
||||||
ThreeStarAligned
|
ThreeStarAligned,
|
||||||
|
AlignedOnHome,
|
||||||
|
ScopeWasParked,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,9 +360,6 @@ namespace ASCOM.Meade.net
|
|||||||
var result = SharedResourcesWrapper.SendBool(command, raw);
|
var result = SharedResourcesWrapper.SendBool(command, raw);
|
||||||
LogMessage("CommandBool", "Completed: {0}", result);
|
LogMessage("CommandBool", "Completed: {0}", result);
|
||||||
return 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)
|
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,
|
// it's a good idea to put all the low level communication with the device here,
|
||||||
// then all communication calls this function
|
// then all communication calls this function
|
||||||
// you need something to ensure that only one command is in progress at a time
|
// you need something to ensure that only one command is in progress at a time
|
||||||
var result = SharedResourcesWrapper.SendString(command, raw);
|
string result;
|
||||||
LogMessage("CommandBool", "Completed: {0}", 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;
|
return result;
|
||||||
//throw new ASCOM.MethodNotImplementedException("CommandString");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -416,7 +422,6 @@ namespace ASCOM.Meade.net
|
|||||||
$"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}");
|
$"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}");
|
||||||
|
|
||||||
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
|
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
|
||||||
_tracking = true;
|
|
||||||
|
|
||||||
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
|
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
@@ -620,17 +625,13 @@ namespace ASCOM.Meade.net
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// true iff the mount will perform a meridian flip when required
|
private bool IsGWCommandSupported() => FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg);
|
||||||
// TODO: Needs checking what mounts actually support this
|
|
||||||
private bool IsMeridianFlipOnSlewSupported()
|
|
||||||
{
|
|
||||||
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
private bool FirmwareIsGreaterThan(string minVersion)
|
||||||
{
|
{
|
||||||
@@ -957,7 +958,7 @@ namespace ASCOM.Meade.net
|
|||||||
|
|
||||||
CheckConnected("AlignmentMode Get");
|
CheckConnected("AlignmentMode Get");
|
||||||
|
|
||||||
if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
|
if (IsGWCommandSupported())
|
||||||
{
|
{
|
||||||
var alignmentStatus = GetScopeAlignmentStatus();
|
var alignmentStatus = GetScopeAlignmentStatus();
|
||||||
return alignmentStatus.AlignmentMode;
|
return alignmentStatus.AlignmentMode;
|
||||||
@@ -998,7 +999,7 @@ namespace ASCOM.Meade.net
|
|||||||
CheckConnected("AlignmentMode Set");
|
CheckConnected("AlignmentMode Set");
|
||||||
|
|
||||||
//todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly
|
//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);
|
throw new PropertyNotImplementedException("AlignmentMode", true);
|
||||||
|
|
||||||
switch (value)
|
switch (value)
|
||||||
@@ -1025,13 +1026,14 @@ namespace ASCOM.Meade.net
|
|||||||
|
|
||||||
private AlignmentStatus GetScopeAlignmentStatus()
|
private AlignmentStatus GetScopeAlignmentStatus()
|
||||||
{
|
{
|
||||||
var alignmentString = SharedResourcesWrapper.SendString("GW");
|
var alignmentString = CommandString("GW", false);
|
||||||
//:GW# Get Scope Alignment Status
|
//:GW# Get Scope Alignment Status
|
||||||
//Returns: <mount><tracking><alignment>#
|
//Returns: <mount><tracking><alignment>#
|
||||||
// where:
|
// where:
|
||||||
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
|
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
|
||||||
//tracking: T - tracking, N - not tracking
|
//tracking: T - tracking, N - not tracking, S - sleeping
|
||||||
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned.
|
//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();
|
var alignmentStatus = new AlignmentStatus();
|
||||||
switch (alignmentString[0])
|
switch (alignmentString[0])
|
||||||
@@ -1046,8 +1048,8 @@ namespace ASCOM.Meade.net
|
|||||||
alignmentStatus.AlignmentMode = AlignmentModes.algGermanPolar;
|
alignmentStatus.AlignmentMode = AlignmentModes.algGermanPolar;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
alignmentStatus.Tracking = alignmentString[0] == 'T';
|
alignmentStatus.Tracking = alignmentString[1] == 'T';
|
||||||
switch (alignmentString[1])
|
switch (alignmentString[2])
|
||||||
{
|
{
|
||||||
case '0':
|
case '0':
|
||||||
alignmentStatus.Status = Alignment.NeedsAlignment;
|
alignmentStatus.Status = Alignment.NeedsAlignment;
|
||||||
@@ -1061,9 +1063,14 @@ namespace ASCOM.Meade.net
|
|||||||
case '3':
|
case '3':
|
||||||
alignmentStatus.Status = Alignment.ThreeStarAligned;
|
alignmentStatus.Status = Alignment.ThreeStarAligned;
|
||||||
break;
|
break;
|
||||||
|
case 'H':
|
||||||
|
alignmentStatus.Status = Alignment.AlignedOnHome;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
alignmentStatus.Status = Alignment.ScopeWasParked;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return alignmentStatus;
|
return alignmentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1228,7 +1235,7 @@ namespace ASCOM.Meade.net
|
|||||||
switch (axis)
|
switch (axis)
|
||||||
{
|
{
|
||||||
case TelescopeAxes.axisPrimary: return true; //RA or AZ
|
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
|
case TelescopeAxes.axisTertiary: return false; //rotator / derotator
|
||||||
default: throw new InvalidValueException("CanMoveAxis", axis.ToString(), "0 to 2");
|
default: throw new InvalidValueException("CanMoveAxis", axis.ToString(), "0 to 2");
|
||||||
}
|
}
|
||||||
@@ -1890,24 +1897,25 @@ namespace ASCOM.Meade.net
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
|
if (!IsMeridianFlipOnSlewSupported())
|
||||||
{
|
{
|
||||||
LogMessage("SideOfPier Get", "Not implemented");
|
LogMessage("SideOfPier Get", "Not implemented");
|
||||||
throw new PropertyNotImplementedException("SideOfPier", false);
|
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
|
else
|
||||||
{
|
{
|
||||||
var alignmentStatus = GetScopeAlignmentStatus();
|
pierSide = SharedResourcesWrapper.SideOfPier;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogMessage("SideOfPier", "Get - " + pierSide);
|
||||||
|
return pierSide;
|
||||||
}
|
}
|
||||||
// ReSharper disable once ValueParameterNotUsed
|
// ReSharper disable once ValueParameterNotUsed
|
||||||
set
|
set
|
||||||
@@ -2594,19 +2602,18 @@ namespace ASCOM.Meade.net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _tracking = true;
|
|
||||||
public bool Tracking
|
public bool Tracking
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
LogMessage("Tracking", $"Get - {_tracking}");
|
LogMessage("Tracking", "Get");
|
||||||
if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
|
if (IsGWCommandSupported())
|
||||||
{
|
{
|
||||||
var alignmentStatus = GetScopeAlignmentStatus();
|
var alignmentStatus = GetScopeAlignmentStatus();
|
||||||
_tracking = alignmentStatus.Tracking;
|
return alignmentStatus.Tracking;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _tracking;
|
return true;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,13 +124,17 @@ namespace ASCOM.Meade.net
|
|||||||
|
|
||||||
public static bool SendBool(string command, bool raw = false)
|
public static bool SendBool(string command, bool raw = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
var result = SendChar(command, raw);
|
var result = SendChar(command, raw);
|
||||||
|
|
||||||
return result == "1";
|
return result == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string SendChar(string command, bool raw = false)
|
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)
|
lock (LockObject)
|
||||||
{
|
{
|
||||||
@@ -141,14 +145,11 @@ namespace ASCOM.Meade.net
|
|||||||
|
|
||||||
try
|
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 new TimeoutException(ex.Message, ex);
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace ASCOM.Meade.net.Wrapper
|
|||||||
void SendBlind(string message, bool raw = false);
|
void SendBlind(string message, bool raw = false);
|
||||||
bool SendBool(string command, bool raw = false);
|
bool SendBool(string command, bool raw = false);
|
||||||
string SendChar(string message, bool raw = false);
|
string SendChar(string message, bool raw = false);
|
||||||
|
string SendChars(string message, bool raw = false, int count = 1);
|
||||||
|
|
||||||
string ReadTerminated();
|
string ReadTerminated();
|
||||||
|
|
||||||
@@ -94,6 +95,11 @@ namespace ASCOM.Meade.net.Wrapper
|
|||||||
return SharedResources.SendChar(message, raw);
|
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()
|
public string ReadTerminated()
|
||||||
{
|
{
|
||||||
return SharedResources.ReadTerminated();
|
return SharedResources.ReadTerminated();
|
||||||
|
|||||||
Reference in New Issue
Block a user