Modified the implementation of side of pier support detection. Hopefully will now,

Added extra checking to ensure that a slew cannot be started whilst a slew is in progress.
This commit is contained in:
2021-12-11 19:10:18 +00:00
parent a5a3bd5bd4
commit df7dfb7c04
6 changed files with 221 additions and 215 deletions
@@ -42,8 +42,6 @@ namespace Meade.net.Focuser.UnitTests
_sharedResourcesWrapperMock = new Mock<ISharedResourcesWrapper>(); _sharedResourcesWrapperMock = new Mock<ISharedResourcesWrapper>();
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Action>())).Callback<Action>(action => { action(); });
_sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() => _profileProperties); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() => _profileProperties);
_focuser = new ASCOM.Meade.net.Focuser(_utilMock.Object, _sharedResourcesWrapperMock.Object); _focuser = new ASCOM.Meade.net.Focuser(_utilMock.Object, _sharedResourcesWrapperMock.Object);
@@ -422,8 +420,6 @@ namespace Meade.net.Focuser.UnitTests
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once);
} }
_sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny<Action>()), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never);
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once()); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once());
@@ -455,8 +451,6 @@ namespace Meade.net.Focuser.UnitTests
_utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2)); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2));
} }
_sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny<Action>()), Times.Once);
} }
[Test] [Test]
@@ -95,9 +95,6 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MMSS"); _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MMSS");
_sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties);
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Action>())).Callback<Action>(action => { action(); });
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Func<ASCOM.Meade.net.Telescope.TelescopeDateDetails>>())).Returns<Func<ASCOM.Meade.net.Telescope.TelescopeDateDetails>>( func => func());
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Func<AltitudeData>>())).Returns<Func<AltitudeData>>(func => func());
_connectionInfo = new ConnectionInfo _connectionInfo = new ConnectionInfo
{ {
@@ -1930,11 +1927,12 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(excpetion.Method, Is.EqualTo("SetPark")); Assert.That(excpetion.Method, Is.EqualTo("SetPark"));
} }
[Test] [TestCase(TelescopeList.LX200CLASSIC, null)]
public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException() [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee)]
[TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42F)]
public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException(string model, string firmware)
{ {
// LX200 classic is a fork mounted scope so it does not support meridian flips ConnectTelescope(model, firmware);
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(TelescopeList.LX200CLASSIC);
var excpetion = Assert.Throws<PropertyNotImplementedException>(() => var excpetion = Assert.Throws<PropertyNotImplementedException>(() =>
{ {
@@ -1946,6 +1944,41 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(excpetion.AccessorSet, Is.False); Assert.That(excpetion.AccessorSet, Is.False);
} }
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)]
[TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G)]
public void SideOfPier_Get_WhenMeridianFlipSupported_ThenReturnsResult(string model, string firmware)
{
ConnectTelescope(model, firmware);
Assert.DoesNotThrow(() => { var result = _telescope.SideOfPier; });
}
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algAltAz, 'A')]
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algPolar, 'P')]
public void SideOfPier_Get_WhenMeridianFlipNotSupportedByAlignementMode_ThenThrowsException(string model, string firmware, AlignmentModes alignmode, char alignmentStatus)
{
ConnectTelescope(model, firmware);
_testProperties.AlignmentStatus = new[] { alignmentStatus, 'T', '1' };
var excpetion = Assert.Throws<PropertyNotImplementedException>(() =>
{
var result = _telescope.SideOfPier;
Assert.Fail($"{result} should not have returned");
});
Assert.That(excpetion.Property, Is.EqualTo("SideOfPier"));
Assert.That(excpetion.AccessorSet, Is.False);
}
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, 'G')]
public void SideOfPier_Get_WhenMeridianFlipSupportedByAlignementMode_ThenDoesNotThrow(string model, string firmware, AlignmentModes alignmode, char alignmentStatus)
{
ConnectTelescope(model, firmware);
_testProperties.AlignmentStatus = new[] { alignmentStatus, 'T', '1' };
Assert.DoesNotThrow(() => { var result = _telescope.SideOfPier; });
}
[Test] [Test]
public void SideOfPier_Set_ThenThrowsException() public void SideOfPier_Set_ThenThrowsException()
{ {
@@ -2119,7 +2152,7 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Verify(x => x.SendString("Gg", false), Times.Exactly(3)); _sharedResourcesWrapperMock.Verify(x => x.SendString("Gg", false), Times.Exactly(3));
_sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Exactly(2)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Exactly(2));
_sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Exactly(3)); _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.AtLeast(3));
} }
[Test] [Test]
@@ -3272,12 +3305,15 @@ namespace Meade.net.Telescope.UnitTests
{ {
_sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0");
var preTestItterations = 1;
var slewCounter = 0; var slewCounter = 0;
var iterations = 10; var iterations = 10;
_sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() =>
{ {
slewCounter++; slewCounter++;
if (slewCounter <= iterations) if (slewCounter <= preTestItterations)
return "";
else if (slewCounter <= iterations)
return "|"; return "|";
return ""; return "";
}); });
@@ -3289,7 +3325,7 @@ 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 - preTestItterations));
} }
[Test] [Test]
@@ -3366,12 +3402,15 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0");
var preTestItterations = 1;
var slewCounter = 0; var slewCounter = 0;
var iterations = 10; var iterations = 10;
_sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() =>
{ {
slewCounter++; slewCounter++;
if (slewCounter <= iterations) if (slewCounter <= preTestItterations)
return "";
else if (slewCounter <= iterations)
return "|"; return "|";
return ""; return "";
}); });
@@ -3383,7 +3422,7 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult));
_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 - preTestItterations));
} }
[Test] [Test]
@@ -3486,12 +3525,15 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0");
var preTestItterations = 1;
var slewCounter = 0; var slewCounter = 0;
var iterations = 10; var iterations = 10;
_sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() =>
{ {
slewCounter++; slewCounter++;
if (slewCounter <= iterations) if (slewCounter <= preTestItterations)
return "";
else if (slewCounter <= iterations)
return "|"; return "|";
return ""; return "";
}); });
@@ -3503,7 +3545,7 @@ 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("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 - preTestItterations));
} }
[Test] [Test]
+19 -34
View File
@@ -649,7 +649,7 @@ namespace ASCOM.Meade.net
// According to "A User's Guide to the Meade LXD55 and LXD75 Telescopes" Autostar supports meridian flip so // 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 // 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 // meridian flip on slew is supported
private bool IsMeridianFlipOnSlewSupported() => IsGwCommandSupported() && AlignmentMode != AlignmentModes.algAltAz; private bool IsMeridianFlipOnSlewSupported() => IsGwCommandSupported() && AlignmentMode == AlignmentModes.algGermanPolar;
private bool FirmwareIsGreaterThan(string minVersion) private bool FirmwareIsGreaterThan(string minVersion)
{ {
@@ -734,12 +734,10 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SetLongFormat", "Long coordinate format not supported for this mount"); LogMessage("SetLongFormat", "Long coordinate format not supported for this mount");
SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.IsLongFormat = false); SharedResourcesWrapper.IsLongFormat = false;
return; return;
} }
SharedResourcesWrapper.Lock(() =>
{
var result = SharedResourcesWrapper.SendString("GZ"); var result = SharedResourcesWrapper.SendString("GZ");
LogMessage("SetLongFormat", $"Get - Azimuth {result}"); LogMessage("SetLongFormat", $"Get - Azimuth {result}");
//:GZ# Get telescope azimuth //:GZ# Get telescope azimuth
@@ -766,7 +764,6 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} ");
} }
});
LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} ");
} }
@@ -1135,13 +1132,13 @@ namespace ASCOM.Meade.net
private HorizonCoordinates CalcAltAzFromTelescopeEqData() private HorizonCoordinates CalcAltAzFromTelescopeEqData()
{ {
var altitudeData = SharedResourcesWrapper.Lock(() => new AltitudeData var altitudeData = new AltitudeData
{ {
UtcDateTime = UTCDate, UtcDateTime = UTCDate,
SiteLongitude = SiteLongitude, SiteLongitude = SiteLongitude,
SiteLatitude = SiteLatitude, SiteLatitude = SiteLatitude,
EquatorialCoordinates = GetTelescopeRaAndDec() EquatorialCoordinates = GetTelescopeRaAndDec()
}); };
double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime,
altitudeData.SiteLongitude, altitudeData.SiteLongitude,
@@ -2181,29 +2178,24 @@ namespace ASCOM.Meade.net
var latitude = SiteLatitude; var latitude = SiteLatitude;
var longitude = SiteLongitude; var longitude = SiteLongitude;
SharedResourcesWrapper.Lock(() =>
{
var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz);
TargetRightAscension = raDec.RightAscension; TargetRightAscension = raDec.RightAscension;
TargetDeclination = raDec.Declination; TargetDeclination = raDec.Declination;
DoSlewAsync(true); DoSlewAsync(true);
//TargetAltitude = altitude;
//TargetAzimuth = azimuth;
//DoSlewAsync(false);
});
} }
private void DoSlewAsync(bool polar) private void DoSlewAsync(bool polar)
{ {
CheckConnected("DoSlewAsync"); CheckConnected("DoSlewAsync");
CheckParked(); CheckParked();
if (Slewing)
SharedResourcesWrapper.Lock(() =>
{ {
LogMessage("DoSlewAsync", "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:
@@ -2224,7 +2216,8 @@ namespace ASCOM.Meade.net
{ {
// Update side of pier to destination side of pier // Update side of pier to destination side of pier
// Assumption: Mount will do meridian flip if required // Assumption: Mount will do meridian flip if required
SharedResourcesWrapper.SideOfPier = DestinationSideOfPier(TargetRightAscension, TargetDeclination); SharedResourcesWrapper.SideOfPier =
DestinationSideOfPier(TargetRightAscension, TargetDeclination);
} }
SetSlewingMinEndTime(); SetSlewingMinEndTime();
@@ -2263,10 +2256,10 @@ namespace ASCOM.Meade.net
{ {
throw new InvalidOperationException("fault"); throw new InvalidOperationException("fault");
} }
SetSlewingMinEndTime(); SetSlewingMinEndTime();
break; break;
} }
});
} }
public void SlewToCoordinates(double rightAscension, double declination) public void SlewToCoordinates(double rightAscension, double declination)
@@ -2450,17 +2443,15 @@ namespace ASCOM.Meade.net
public void SyncToCoordinates(double rightAscension, double declination) public void SyncToCoordinates(double rightAscension, double declination)
{ {
LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}");
LogMessage("SyncToCoordinates", $"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}"); LogMessage("SyncToCoordinates",
$"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}");
CheckConnected("SyncToCoordinates"); CheckConnected("SyncToCoordinates");
CheckParked(); CheckParked();
SharedResourcesWrapper.Lock(() =>
{
TargetRightAscension = rightAscension; TargetRightAscension = rightAscension;
TargetDeclination = declination; TargetDeclination = declination;
SyncToTarget(); SyncToTarget();
});
} }
public void SyncToTarget() public void SyncToTarget()
@@ -2612,13 +2603,15 @@ namespace ASCOM.Meade.net
get get
{ {
LogMessage("Tracking", "Get"); LogMessage("Tracking", "Get");
bool isTracking = true;
if (IsGwCommandSupported()) if (IsGwCommandSupported())
{ {
var alignmentStatus = GetScopeAlignmentStatus(); var alignmentStatus = GetScopeAlignmentStatus();
return alignmentStatus.Tracking; isTracking = alignmentStatus.Tracking;
} }
return true; LogMessage("Tracking", $"Get = {isTracking}");
return isTracking;
} }
set set
{ {
@@ -2731,9 +2724,7 @@ namespace ASCOM.Meade.net
{ {
CheckParked(); CheckParked();
var telescopeDateDetails = SharedResourcesWrapper.Lock(() => var telescopeDateDetails = new TelescopeDateDetails
{
var tdd = new TelescopeDateDetails
{ {
TelescopeDate = SharedResourcesWrapper.SendString("GC"), TelescopeDate = SharedResourcesWrapper.SendString("GC"),
//:GC# Get current date. //:GC# Get current date.
@@ -2746,9 +2737,6 @@ namespace ASCOM.Meade.net
UtcCorrection = GetUtcCorrection() UtcCorrection = GetUtcCorrection()
}; };
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();
@@ -2783,8 +2771,6 @@ namespace ASCOM.Meade.net
CheckConnected("UTCDate Set"); CheckConnected("UTCDate Set");
SharedResourcesWrapper.Lock(() =>
{
var utcCorrection = GetUtcCorrection(); var utcCorrection = GetUtcCorrection();
var localDateTime = value - utcCorrection; var localDateTime = value - utcCorrection;
@@ -2816,7 +2802,6 @@ namespace ASCOM.Meade.net
//throwing away these two strings which represent //throwing away these two strings which represent
SharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data# SharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data#
SharedResourcesWrapper.ReadTerminated(); // # SharedResourcesWrapper.ReadTerminated(); // #
});
} }
} }
-3
View File
@@ -298,8 +298,6 @@ namespace ASCOM.Meade.net
if (ReverseFocusDirection) if (ReverseFocusDirection)
direction = !direction; direction = !direction;
SharedResourcesWrapper.Lock(() =>
{
//backlash compensation. //backlash compensation.
var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0; var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0;
@@ -320,7 +318,6 @@ namespace ASCOM.Meade.net
DynamicBreaking(direction); DynamicBreaking(direction);
//todo implement dynamic braking //todo implement dynamic braking
//dynamic breaking is sending the command to move in the opposite direction immediatly followed by the command to stop. //dynamic breaking is sending the command to move in the opposite direction immediatly followed by the command to stop.
});
} }
private void DynamicBreaking(bool directionOut) private void DynamicBreaking(bool directionOut)
+1
View File
@@ -23,6 +23,7 @@
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
public const string LX200GPS = "LX2001"; public const string LX200GPS = "LX2001";
public const string LX200GPS_42F = "4.2F";
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
public const string LX200GPS_42G = "4.2G"; public const string LX200GPS_42G = "4.2G";
#endregion #endregion
@@ -13,9 +13,6 @@ namespace ASCOM.Meade.net.Wrapper
string FirmwareVersion { get; } string FirmwareVersion { get; }
void Lock(Action action);
T Lock<T>(Func<T> func);
string SendString(string message, bool raw = false); string SendString(string message, bool raw = false);
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);
@@ -69,16 +66,6 @@ namespace ASCOM.Meade.net.Wrapper
public string FirmwareVersion => SharedResources.FirmwareVersion; public string FirmwareVersion => SharedResources.FirmwareVersion;
public void Lock(Action action)
{
SharedResources.Lock(action);
}
public T Lock<T>(Func<T> func)
{
return SharedResources.Lock(func);
}
public string SendString(string message, bool raw = false) public string SendString(string message, bool raw = false)
{ {
return SharedResources.SendString(message, raw); return SharedResources.SendString(message, raw);