Added extra check to ensure that slewing is return true whilst executing one of the ascom slew commands.

This commit is contained in:
2024-11-26 16:01:07 +00:00
parent 7554c1e213
commit c2bc2cfc7e
2 changed files with 100 additions and 79 deletions
@@ -2950,7 +2950,7 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(result, Is.False); Assert.That(result, Is.False);
_sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Exactly(2)); _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Exactly(1));
} }
[Test] [Test]
@@ -3317,8 +3317,6 @@ namespace Meade.net.Telescope.UnitTests
_telescope.TargetDeclination = 1; _telescope.TargetDeclination = 1;
_telescope.SlewToTarget(); _telescope.SlewToTarget();
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations - preTestItterations));
} }
[Test] [Test]
@@ -3402,8 +3400,6 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.RightAscension)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.RightAscension));
Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult));
_sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations - preTestItterations));
} }
[Test] [Test]
@@ -3526,7 +3522,6 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.RightAscension)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.RightAscension));
Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.Declination)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.Declination));
_sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations - preTestItterations));
} }
[Test] [Test]
@@ -3615,10 +3610,9 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Q", false), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Q", false), Times.Once);
var isSloSlewing = _telescope.Slewing; var isSlewing = _telescope.Slewing;
Assert.That(isSloSlewing, Is.False); Assert.That(isSlewing, Is.False);
_sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Exactly(2));
} }
[Test] [Test]
+46 -19
View File
@@ -23,7 +23,7 @@ namespace ASCOM.Meade.net
// Your driver's DeviceID is ASCOM.Meade.net.Telescope // Your driver's DeviceID is ASCOM.Meade.net.Telescope
// //
// The Guid attribute sets the CLSID for ASCOM.Meade.net.Telescope // The Guid attribute sets the CLSID for ASCOM.Meade.net.Telescope
// The ClassInterface/None addribute prevents an empty interface called // The ClassInterface/None attribute prevents an empty interface called
// _Meade.net from being created and used as the [default] interface // _Meade.net from being created and used as the [default] interface
// //
// Replace the not implemented exceptions with code to implement the function or // Replace the not implemented exceptions with code to implement the function or
@@ -78,6 +78,11 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
private int _digitsDe = 2; private int _digitsDe = 2;
/// <summary>
/// Used to make sure that the slewing property returns true when in the middle of an ascom slew command, anything above 0 means that we are inside slewing commands.
/// </summary>
private int _forceSlewingCount = 0;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Meade.net"/> class. /// Initializes a new instance of the <see cref="Meade.net"/> class.
/// Must be public for COM registration. /// Must be public for COM registration.
@@ -2860,6 +2865,9 @@ namespace ASCOM.Meade.net
} }
public void SlewToAltAzAsync(double azimuth, double altitude, bool polar) public void SlewToAltAzAsync(double azimuth, double altitude, bool polar)
{
_forceSlewingCount++;
try
{ {
try try
{ {
@@ -2906,6 +2914,11 @@ namespace ASCOM.Meade.net
throw; throw;
} }
} }
finally
{
_forceSlewingCount--;
}
}
private double TargetAltitude private double TargetAltitude
{ {
@@ -2992,14 +3005,12 @@ namespace ASCOM.Meade.net
LogMessage("DoSlewAsync", "Beginning slew sequence"); LogMessage("DoSlewAsync", "Beginning slew sequence");
CheckConnected("DoSlewAsync"); CheckConnected("DoSlewAsync");
CheckParked(); CheckParked();
if (Slewing) if (GetSlewing(true))
{ {
LogMessage("DoSlewAsync", "Cannot start a slew whilst slew is in progress."); LogMessage("DoSlewAsync", "Cannot start a slew whilst slew is in progress.");
throw new ASCOM.InvalidOperationException("Cannot start a slew whilst slew is in progress."); throw new ASCOM.InvalidOperationException("Cannot start a slew whilst slew is in progress.");
} }
switch (polar) switch (polar)
{ {
case true: case true:
@@ -3132,6 +3143,9 @@ namespace ASCOM.Meade.net
} }
public void SlewToCoordinatesAsync(double rightAscension, double declination) public void SlewToCoordinatesAsync(double rightAscension, double declination)
{
_forceSlewingCount++;
try
{ {
try try
{ {
@@ -3151,6 +3165,11 @@ namespace ASCOM.Meade.net
throw; throw;
} }
} }
finally
{
_forceSlewingCount--;
}
}
public void SlewToTarget() public void SlewToTarget()
{ {
@@ -3176,6 +3195,9 @@ namespace ASCOM.Meade.net
private const double InvalidParameter = -1000; private const double InvalidParameter = -1000;
public void SlewToTargetAsync() public void SlewToTargetAsync()
{
_forceSlewingCount++;
try
{ {
try try
{ {
@@ -3193,6 +3215,11 @@ namespace ASCOM.Meade.net
throw; throw;
} }
} }
finally
{
_forceSlewingCount--;
}
}
private bool MovingAxis() private bool MovingAxis()
{ {
@@ -3214,12 +3241,7 @@ namespace ASCOM.Meade.net
{ {
try try
{ {
var isSlewing = GetSlewing() || (IsConnected && IsSlewingToTarget()); var isSlewing = GetSlewing(false);
if (isSlewing)
SetSlewingMinEndTime();
else if (_clock.UtcNow < SharedResourcesWrapper.EarliestNonSlewingTime)
isSlewing = true;
LogMessage("Slewing", $"Result = {isSlewing}"); LogMessage("Slewing", $"Result = {isSlewing}");
return isSlewing; return isSlewing;
@@ -3242,19 +3264,24 @@ namespace ASCOM.Meade.net
return TimeSpan.FromSeconds( SlewSettleTime + _profileProperties.SettleTime ); return TimeSpan.FromSeconds( SlewSettleTime + _profileProperties.SettleTime );
} }
private bool GetSlewing() private bool GetSlewing(bool isInternalCall)
{ {
var result = false; var result = false;
try try
{ {
if (Connected) if (Connected)
result = MovingAxis() || IsSlewingToTarget(); result = (!isInternalCall && _forceSlewingCount > 0) || MovingAxis() || IsSlewingToTarget();
} }
finally finally
{ {
LogMessage("GetSlewing", $"Result = {result}"); LogMessage("GetSlewing", $"Result = {result}");
} }
if (result)
SetSlewingMinEndTime();
else if (_clock.UtcNow < SharedResourcesWrapper.EarliestNonSlewingTime)
result = true;
return result; return result;
} }
@@ -3809,18 +3836,18 @@ namespace ASCOM.Meade.net
UtcCorrection = GetUtcCorrection() UtcCorrection = GetUtcCorrection()
}; };
int month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger(); var month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger();
int day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger(); var day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger();
int year = telescopeDateDetails.TelescopeDate.Substring(6, 2).ToInteger(); var 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 += 2000;
} }
int hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger(); var hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger();
int minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger(); var minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger();
int second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger(); var second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger();
var utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) + var utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) +
telescopeDateDetails.UtcCorrection; telescopeDateDetails.UtcCorrection;