@@ -3,6 +3,7 @@ using System.Globalization;
|
||||
using System.Reflection;
|
||||
using ASCOM;
|
||||
using ASCOM.Astrometry.AstroUtils;
|
||||
using ASCOM.Astrometry.NOVAS;
|
||||
using ASCOM.DeviceInterface;
|
||||
using ASCOM.Meade.net;
|
||||
using ASCOM.Meade.net.AstroMaths;
|
||||
@@ -42,6 +43,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
private Mock<ISharedResourcesWrapper> _sharedResourcesWrapperMock;
|
||||
private Mock<IAstroMaths> _astroMathsMock;
|
||||
private Mock<IClock> _clockMock;
|
||||
private Mock<INOVAS31> _novasMock;
|
||||
|
||||
private ProfileProperties _profileProperties;
|
||||
private ConnectionInfo _connectionInfo;
|
||||
@@ -105,8 +107,10 @@ namespace Meade.net.Telescope.UnitTests
|
||||
|
||||
_clockMock = new Mock<IClock>();
|
||||
|
||||
_novasMock = new Mock<INOVAS31>();
|
||||
|
||||
_telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object,
|
||||
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object);
|
||||
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object);
|
||||
}
|
||||
|
||||
private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee)
|
||||
@@ -1199,15 +1203,89 @@ namespace Meade.net.Telescope.UnitTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DestinationSideOfPier_ThenThrowsException()
|
||||
public void DestinationSideOfPier_WhenNotConnected_ThenThrowsException()
|
||||
{
|
||||
var excpetion = Assert.Throws<MethodNotImplementedException>(() =>
|
||||
var excpetion = Assert.Throws<NotConnectedException>(() =>
|
||||
{
|
||||
var result = _telescope.DestinationSideOfPier(0, 0);
|
||||
Assert.Fail($"{result} should not have returned");
|
||||
});
|
||||
|
||||
Assert.That(excpetion.Method, Is.EqualTo("DestinationSideOfPier"));
|
||||
Assert.That(excpetion.Message, Is.EqualTo("Not connected to telescope when trying to execute: DestinationSideOfPier"));
|
||||
}
|
||||
|
||||
[TestCase(1, 1, 4, PierSide.pierEast)]
|
||||
[TestCase(1, -1, 4, PierSide.pierEast)]
|
||||
[TestCase(4, 1, 1, PierSide.pierWest)]
|
||||
[TestCase(4, -1, 1, PierSide.pierWest)]
|
||||
[TestCase(0, 0, 0, PierSide.pierUnknown)]
|
||||
[TestCase(5, 0, 5, PierSide.pierUnknown)]
|
||||
[TestCase(23.8, 1, 23.9, PierSide.pierEast)]
|
||||
[TestCase(23.8, -1, 23.9, PierSide.pierEast)]
|
||||
[TestCase(23.9, 1, 1, PierSide.pierEast)]
|
||||
[TestCase(23.9, -1, 1, PierSide.pierEast)]
|
||||
[TestCase(1, 1, 23.9, PierSide.pierWest)]
|
||||
[TestCase(1, -1, 23.9, PierSide.pierWest)]
|
||||
public void DestinationSideOfPier_WhenHASiderealTimeDiffIsNotNull_ThenSideOfPierIsCalculated(double ra, double dec, double siderealTime, PierSide expectedDSOP)
|
||||
{
|
||||
// given
|
||||
// SideralTime uses ConditionRA to normalize to 0..24h, so we use it to mock the property
|
||||
_astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny<double>())).Returns(siderealTime);
|
||||
|
||||
var ha = siderealTime - ra;
|
||||
var normalisedHA = ha > 12 ? ha - 24 : ha < -12 ? ha + 24 : ha;
|
||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.Is<double>(v => v == ha))).Returns(normalisedHA);
|
||||
|
||||
ConnectTelescope();
|
||||
|
||||
// when
|
||||
var actualDSOP = _telescope.DestinationSideOfPier(ra, dec);
|
||||
|
||||
// then
|
||||
Assert.That(siderealTime, Is.InRange(0, 24 + double.Epsilon));
|
||||
Assert.That(normalisedHA, Is.InRange(-12, 12 + double.Epsilon));
|
||||
Assert.That(actualDSOP, Is.EqualTo(expectedDSOP));
|
||||
|
||||
_astroUtilsMock.Verify(x => x.ConditionRA(It.IsAny<double>()), Times.Once);
|
||||
_astroUtilsMock.Verify(x => x.ConditionHA(It.Is<double>(v => v == ha)), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiderealTime_Get_WhenNotConnected_ThenThrowsException()
|
||||
{
|
||||
// when
|
||||
var exception = Assert.Throws<NotConnectedException>(() =>
|
||||
{
|
||||
var result = _telescope.SiderealTime;
|
||||
Assert.Fail($"{result} should not have returned");
|
||||
});
|
||||
|
||||
// then
|
||||
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiderealTime Get"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiderealTime_Get_WhenNOVASErrors_ThenThrowsException()
|
||||
{
|
||||
// given
|
||||
double gst = 0.0;
|
||||
_novasMock
|
||||
.Setup(x => x.SiderealTime(It.IsAny<double>(), It.IsAny<double>(), It.IsAny<double>(), ASCOM.Astrometry.GstType.GreenwichApparentSiderealTime, ASCOM.Astrometry.Method.EquinoxBased, ASCOM.Astrometry.Accuracy.Reduced, ref gst))
|
||||
.Returns(3)
|
||||
.Verifiable();
|
||||
|
||||
ConnectTelescope();
|
||||
|
||||
// when
|
||||
var exception = Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
var result = _telescope.SiderealTime;
|
||||
Assert.Fail($"{result} should not have returned");
|
||||
});
|
||||
|
||||
// then
|
||||
Assert.That(exception.Message, Is.EqualTo("NOVAS 3.1 SiderealTime returned: 3 in SiderealTime"));
|
||||
_novasMock.Verify();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1743,8 +1821,11 @@ namespace Meade.net.Telescope.UnitTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SideOfPier_Get_ThenThrowsException()
|
||||
public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException()
|
||||
{
|
||||
// LX200 classic is a fork mounted scope so it does not support meridian flips
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(TelescopeList.LX200CLASSIC);
|
||||
|
||||
var excpetion = Assert.Throws<PropertyNotImplementedException>(() =>
|
||||
{
|
||||
var result = _telescope.SideOfPier;
|
||||
@@ -2761,6 +2842,9 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[Test]
|
||||
public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete()
|
||||
{
|
||||
// avoid calling SideOfPier because it will call Slewing
|
||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns(+1);
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0");
|
||||
|
||||
var slewCounter = 0;
|
||||
@@ -2781,6 +2865,7 @@ 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]
|
||||
@@ -2841,6 +2926,9 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[Test]
|
||||
public void SlewToCoordinates_WhenCalled_ThenSetsTargetAndSlews()
|
||||
{
|
||||
// avoid calling SideOfPier because it will call Slewing
|
||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns(+1);
|
||||
|
||||
_testProperties.rightAscension = 1;
|
||||
var declination = 2;
|
||||
|
||||
@@ -2875,6 +2963,7 @@ 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]
|
||||
@@ -2963,6 +3052,9 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[Test]
|
||||
public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews()
|
||||
{
|
||||
// avoid calling SideOfPier because it will call Slewing
|
||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns(+1);
|
||||
|
||||
_testProperties.rightAscension = 10.0;
|
||||
_testProperties.declination = 20;
|
||||
var azimuth = 30;
|
||||
@@ -2995,6 +3087,7 @@ 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]
|
||||
|
||||
@@ -57,7 +57,8 @@ namespace ASCOM.Meade.net
|
||||
private readonly IUtilExtra _utilitiesExtra;
|
||||
|
||||
/// <summary>
|
||||
/// Private variable to hold an ASCOM AstroUtilities object to provide the Range method
|
||||
/// Private variable to hold an ASCOM AstroUtilities object to provide the <see cref="IAstroUtils.Range(double, double, bool, double, bool)"> method
|
||||
/// and <see cref="IAstroUtils.ConditionHA(double)"/>
|
||||
/// </summary>
|
||||
private readonly IAstroUtils _astroUtilities;
|
||||
|
||||
@@ -65,6 +66,8 @@ namespace ASCOM.Meade.net
|
||||
|
||||
private readonly IClock _clock;
|
||||
|
||||
private readonly INOVAS31 _novas;
|
||||
|
||||
/// <summary>
|
||||
/// Private variable to hold number of decimals for RA
|
||||
/// </summary>
|
||||
@@ -92,6 +95,7 @@ namespace ASCOM.Meade.net
|
||||
_astroUtilities = new AstroUtils(); // Initialise astro utilities object
|
||||
_astroMaths = new AstroMaths.AstroMaths();
|
||||
_clock = new Clock();
|
||||
_novas = new NOVAS31();
|
||||
|
||||
Initialise(nameof(Telescope));
|
||||
}
|
||||
@@ -125,7 +129,7 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
|
||||
public Telescope(IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities,
|
||||
ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base(
|
||||
ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock, INOVAS31 novas) : base(
|
||||
sharedResourcesWrapper)
|
||||
{
|
||||
_clock = clock;
|
||||
@@ -133,6 +137,7 @@ namespace ASCOM.Meade.net
|
||||
_utilitiesExtra = utilExtra; //Initialise util object
|
||||
_astroUtilities = astroUtilities; // Initialise astro utilities object
|
||||
_astroMaths = astroMaths;
|
||||
_novas = novas;
|
||||
|
||||
Initialise(nameof(Telescope));
|
||||
}
|
||||
@@ -339,6 +344,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public void CommandBlind(string command, bool raw)
|
||||
{
|
||||
LogMessage("CommandBlind", "raw: {0} command {0}", raw, command);
|
||||
CheckConnected("CommandBlind");
|
||||
// Call CommandString and return as soon as it finishes
|
||||
//this.CommandString(command, raw);
|
||||
@@ -346,14 +352,16 @@ namespace ASCOM.Meade.net
|
||||
// or
|
||||
//throw new ASCOM.MethodNotImplementedException("CommandBlind");
|
||||
// DO NOT have both these sections! One or the other
|
||||
LogMessage("CommandBlind", "Completed");
|
||||
}
|
||||
|
||||
public bool CommandBool(string command, bool raw)
|
||||
{
|
||||
LogMessage("CommandBool", "raw: {0} command {0}", raw, command);
|
||||
CheckConnected("CommandBool");
|
||||
//string ret = CommandString(command, raw);
|
||||
return SharedResourcesWrapper.SendBool(command, raw);
|
||||
// TODO decode the return string and return true or false
|
||||
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
|
||||
@@ -361,11 +369,14 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public string CommandString(string command, bool raw)
|
||||
{
|
||||
LogMessage("CommandString", "raw: {0} command {0}", raw, command);
|
||||
CheckConnected("CommandString");
|
||||
// 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
|
||||
return SharedResourcesWrapper.SendString(command, raw);
|
||||
var result = SharedResourcesWrapper.SendString(command, raw);
|
||||
LogMessage("CommandBool", "Completed: {0}", result);
|
||||
return result;
|
||||
//throw new ASCOM.MethodNotImplementedException("CommandString");
|
||||
}
|
||||
|
||||
@@ -601,6 +612,18 @@ 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;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool FirmwareIsGreaterThan(string minVersion)
|
||||
{
|
||||
var currentVersion = SharedResourcesWrapper.FirmwareVersion;
|
||||
@@ -1362,8 +1385,18 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public PierSide DestinationSideOfPier(double rightAscension, double declination)
|
||||
{
|
||||
LogMessage("DestinationSideOfPier Get", "Not implemented");
|
||||
throw new MethodNotImplementedException("DestinationSideOfPier");
|
||||
CheckConnected("DestinationSideOfPier");
|
||||
|
||||
double hourAngle = _astroUtilities.ConditionHA(SiderealTime - rightAscension);
|
||||
|
||||
var destinationSOP = hourAngle > 0
|
||||
? PierSide.pierEast :
|
||||
(hourAngle < 0 ? PierSide.pierWest : SideOfPier);
|
||||
|
||||
LogMessage("DestinationSideOfPier",
|
||||
$"Destination SOP of RA {rightAscension.ToString(CultureInfo.InvariantCulture)} is {destinationSOP}");
|
||||
|
||||
return destinationSOP;
|
||||
}
|
||||
|
||||
public bool DoesRefraction
|
||||
@@ -1549,12 +1582,16 @@ namespace ASCOM.Meade.net
|
||||
//:Me# Move Telescope East at current slew rate
|
||||
//Returns: Nothing
|
||||
_movingPrimary = true;
|
||||
// in principle we could calculate the current side of pier, but unknown is the safer option.
|
||||
_pierSide = PierSide.pierUnknown;
|
||||
break;
|
||||
case ComparisonResult.Lower:
|
||||
SharedResourcesWrapper.SendBlind("Mw");
|
||||
//:Mw# Move Telescope West at current slew rate
|
||||
//Returns: Nothing
|
||||
_movingPrimary = true;
|
||||
// in principle we could calculate the current side of pier, but unknown is the safer option.
|
||||
_pierSide = PierSide.pierUnknown;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -1814,10 +1851,25 @@ namespace ASCOM.Meade.net
|
||||
throw new MethodNotImplementedException("SetPark");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start with <see cref="PierSide.pierUnknown"/>.
|
||||
/// As we do not know the physical declination axis position, we have to keep track manually.
|
||||
/// </summary>
|
||||
private PierSide _pierSide = PierSide.pierUnknown;
|
||||
public PierSide SideOfPier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsMeridianFlipOnSlewSupported())
|
||||
{
|
||||
// while mount is slewing return unknown, this is required since
|
||||
// DoSlewAsync updates _pierSide before slew is finished
|
||||
var pierSide = Slewing ? PierSide.pierUnknown : _pierSide;
|
||||
|
||||
LogMessage("SideOfPier", "Get - " + pierSide);
|
||||
return pierSide;
|
||||
}
|
||||
|
||||
LogMessage("SideOfPier Get", "Not implemented");
|
||||
throw new PropertyNotImplementedException("SideOfPier", false);
|
||||
}
|
||||
@@ -1833,15 +1885,20 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckConnected("SiderealTime Get");
|
||||
|
||||
// Now using NOVAS 3.1
|
||||
double siderealTime = 0.0;
|
||||
using (var novas = new NOVAS31())
|
||||
{
|
||||
|
||||
var jd = _utilities.DateUTCToJulian(_clock.UtcNow);
|
||||
novas.SiderealTime(jd, 0, novas.DeltaT(jd),
|
||||
var siderealTimeResult = _novas.SiderealTime(jd, 0, _novas.DeltaT(jd),
|
||||
GstType.GreenwichApparentSiderealTime,
|
||||
Method.EquinoxBased,
|
||||
Accuracy.Reduced, ref siderealTime);
|
||||
|
||||
if (siderealTimeResult != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"NOVAS 3.1 SiderealTime returned: {siderealTimeResult} in SiderealTime");
|
||||
}
|
||||
|
||||
// Allow for the longitude
|
||||
@@ -2110,6 +2167,14 @@ namespace ASCOM.Meade.net
|
||||
case "0":
|
||||
//We're slewing everything should be working just fine.
|
||||
LogMessage("DoSlewAsync", "Slewing to target");
|
||||
|
||||
if (IsMeridianFlipOnSlewSupported())
|
||||
{
|
||||
// Update side of pier to destination side of pier
|
||||
// Assumption: Mount will do meridian flip if required
|
||||
_pierSide = DestinationSideOfPier(TargetRightAscension, TargetDeclination);
|
||||
}
|
||||
|
||||
SetSlewingMinEndTime();
|
||||
break;
|
||||
case "1":
|
||||
@@ -2715,6 +2780,9 @@ namespace ASCOM.Meade.net
|
||||
BypassHandboxEntryForAutostarII();
|
||||
|
||||
SharedResourcesWrapper.SetParked(false, null);
|
||||
|
||||
// reset side of pier
|
||||
SideOfPier = PierSide.pierUnknown;
|
||||
}
|
||||
|
||||
private bool BypassHandboxEntryForAutostarII()
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public void CommandBlind(string command, bool raw)
|
||||
{
|
||||
LogMessage("CommandBlind", "raw: {0} command {0}", raw, command);
|
||||
CheckConnected("CommandBlind");
|
||||
// Call CommandString and return as soon as it finishes
|
||||
//this.CommandString(command, raw);
|
||||
@@ -108,14 +109,16 @@ namespace ASCOM.Meade.net
|
||||
// or
|
||||
//throw new ASCOM.MethodNotImplementedException("CommandBlind");
|
||||
// DO NOT have both these sections! One or the other
|
||||
LogMessage("CommandBlind", "Completed");
|
||||
}
|
||||
|
||||
public bool CommandBool(string command, bool raw)
|
||||
{
|
||||
LogMessage("CommandBool", "raw: {0} command {0}", raw, command);
|
||||
CheckConnected("CommandBool");
|
||||
//string ret = CommandString(command, raw);
|
||||
return SharedResourcesWrapper.SendBool(command, raw);
|
||||
// decode the return string and return true or false
|
||||
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
|
||||
@@ -123,11 +126,14 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public string CommandString(string command, bool raw)
|
||||
{
|
||||
LogMessage("CommandString", "raw: {0} command {0}", raw, command);
|
||||
CheckConnected("CommandString");
|
||||
// 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
|
||||
return SharedResourcesWrapper.SendString(command, raw);
|
||||
var result = SharedResourcesWrapper.SendString(command, raw);
|
||||
LogMessage("CommandBool", "Completed: {0}", result);
|
||||
return result;
|
||||
//throw new ASCOM.MethodNotImplementedException("CommandString");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user