Seperated the SlewSettleTime property from the ProfileSettle time, and implemented a delay on IsSlewing to use the combined SettleTimes

This commit is contained in:
2021-02-27 21:20:06 +00:00
parent db06002ebf
commit e9491da707
6 changed files with 115 additions and 19 deletions
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Reflection;
using ASCOM;
using ASCOM.Astrometry.AstroUtils;
@@ -22,6 +23,7 @@ namespace Meade.net.Telescope.UnitTests
private Mock<IAstroUtils> _astroUtilsMock;
private Mock<ISharedResourcesWrapper> _sharedResourcesWrapperMock;
private Mock<IAstroMaths> _astroMathsMock;
private Mock<IClock> _clockMock;
private ProfileProperties _profileProperties;
private ConnectionInfo _connectionInfo;
@@ -63,8 +65,10 @@ namespace Meade.net.Telescope.UnitTests
_astroMathsMock = new Mock<IAstroMaths>();
_clockMock = new Mock<IClock>();
_telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object,
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object);
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object);
}
private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee)
@@ -1654,18 +1658,14 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Set"));
}
[TestCase(5)]
[TestCase(10)]
[TestCase(2)]
public void SlewSettleTime_Get_ReturnsExpectedValue(short settleTime)
[Test]
public void SlewSettleTime_Get_ReturnsExpectedValue()
{
_profileProperties.SettleTime = settleTime;
ConnectTelescope();
var result = _telescope.SlewSettleTime;
Assert.That(result, Is.EqualTo(settleTime));
Assert.That(result, Is.EqualTo(0));
}
[TestCase(8)]
@@ -2340,6 +2340,64 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"),Times.Once);
}
[TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)]
[TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)]
[TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", false)]
[TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", true)]
[TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:09", true)]
[TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:10", false)]
[TestCase(0, 5, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)]
[TestCase(0, 5, "2021-10-03T20:36:00", "2021-10-03T20:36:05", false)]
[TestCase(0, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:05", true)]
[TestCase(0, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", false)]
[TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", true)]
[TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:24", true)]
[TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:25", false)]
public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime( short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing)
{
_profileProperties.SettleTime = profileSettleTime;
var timescalled = 0;
DateTime startSlewingDateTime = DateTime.ParseExact(startSlewing, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
DateTime endSlewingDatetime = DateTime.ParseExact(endSlewing, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
_clockMock.Setup(x => x.UtcNow).Returns(() =>
{
if (timescalled == 0)
{
timescalled++;
return startSlewingDateTime;
}
return endSlewingDatetime;
});
var slewingText = "|";
var notSlewingText = String.Empty;
_sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns( () =>
{
if (timescalled == 0)
{
return slewingText;
}
return notSlewingText;
});
ConnectTelescope();
_telescope.SlewSettleTime = settleTime;
var result = _telescope.Slewing;
Assert.That(result, Is.EqualTo(true));
result = _telescope.Slewing;
Assert.That(result, Is.EqualTo(isSlewing));
}
[TestCase(TelescopeList.LX200CLASSIC,"","|", true)]
[TestCase(TelescopeList.LX200CLASSIC, "", "||||||||", true)]
[TestCase(TelescopeList.LX200CLASSIC, "", "", false)]
+9
View File
@@ -0,0 +1,9 @@
using System;
namespace ASCOM.Meade.net
{
public class Clock : IClock
{
public DateTime UtcNow => DateTime.UtcNow;
}
}
+9
View File
@@ -0,0 +1,9 @@
using System;
namespace ASCOM.Meade.net
{
public interface IClock
{
DateTime UtcNow { get; }
}
}
@@ -124,8 +124,10 @@
<Compile Include="AstroMaths\EquatorialCoordinates.cs" />
<Compile Include="AstroMaths\HorizonCoordinates.cs" />
<Compile Include="AstroMaths\IAstroMaths.cs" />
<Compile Include="Clock.cs" />
<Compile Include="ComparisonResult.cs" />
<Compile Include="DoubleExtensions.cs" />
<Compile Include="IClock.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="Telescope.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+26 -8
View File
@@ -60,16 +60,20 @@ namespace ASCOM.Meade.net
private readonly IAstroMaths _astroMaths;
private readonly IClock _clock;
/// <summary>
/// Private variable to hold number of decimals for RA
/// </summary>
private int _digitsRa = 2;
/// <summary>
/// Private variable to hold number of decimals for DE
/// Private variable to hold number of decimals for Dec
/// </summary>
private int _digitsDe = 2;
private short _settleTime;
/// <summary>
/// Initializes a new instance of the <see cref="Meade.net"/> class.
/// Must be public for COM registration.
@@ -84,6 +88,7 @@ namespace ASCOM.Meade.net
_utilitiesExtra = util; //Initialise util object
_astroUtilities = new AstroUtils(); // Initialise astro utilities object
_astroMaths = new AstroMaths.AstroMaths();
_clock = new Clock();
Initialise(nameof(Telescope));
}
@@ -116,8 +121,9 @@ namespace ASCOM.Meade.net
sb.AppendLine();
}
public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths) : base(sharedResourcesWrapper)
public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base(sharedResourcesWrapper)
{
_clock = clock;
_utilities = util; //Initialise util object
_utilitiesExtra = utilExtra; //Initialise util object
_astroUtilities = astroUtilities; // Initialise astro utilities object
@@ -1775,15 +1781,14 @@ namespace ASCOM.Meade.net
get
{
CheckConnected("SlewSettleTime Get");
LogMessage("SlewSettleTime Get", $"{SettleTime} Seconds");
return SettleTime;
LogMessage("SlewSettleTime Get", $"{_settleTime} Seconds");
return _settleTime;
}
// ReSharper disable once ValueParameterNotUsed
set
{
CheckConnected("SlewSettleTime Set");
LogMessage("SlewSettleTime Set", $"Setting from {SettleTime} to {value}");
SettleTime = value;
LogMessage("SlewSettleTime Set", $"Setting from {_settleTime} to {value}");
_settleTime = value;
}
}
@@ -1964,16 +1969,29 @@ namespace ASCOM.Meade.net
return _movingPrimary || _movingSecondary;
}
private DateTime _earliestNonSlewingTime = DateTime.MinValue;
public bool Slewing
{
get
{
var isSlewing = GetSlewing();
if (isSlewing)
_earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime();
else if (_clock.UtcNow < _earliestNonSlewingTime)
isSlewing = true;
LogMessage("Slewing", $"Result = {isSlewing}");
return isSlewing;
}
}
private TimeSpan GetTotalSlewingSettleTime()
{
return TimeSpan.FromSeconds( SlewSettleTime + ProfileSettleTime );
}
private bool GetSlewing()
{
if (!Connected) return false;
@@ -2001,7 +2019,7 @@ namespace ASCOM.Meade.net
bool isSlewing = false;
try
{
if (string.IsNullOrWhiteSpace(result))
if (string.IsNullOrEmpty(result))
{
isSlewing = false;
return isSlewing;
+3 -3
View File
@@ -27,7 +27,7 @@ namespace ASCOM.Meade.net
protected string Precision;
protected string GuidingStyle;
protected double SiteElevation;
protected short SettleTime;
protected short ProfileSettleTime;
protected readonly ISharedResourcesWrapper SharedResourcesWrapper;
@@ -68,7 +68,7 @@ namespace ASCOM.Meade.net
Precision = profileProperties.Precision;
GuidingStyle = profileProperties.GuidingStyle.ToLower();
SiteElevation = profileProperties.SiteElevation;
SettleTime = profileProperties.SettleTime;
ProfileSettleTime = profileProperties.SettleTime;
LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}");
LogMessage("ReadProfile", $"Com Port: {ComPort}");
@@ -78,7 +78,7 @@ namespace ASCOM.Meade.net
LogMessage("ReadProfile", $"Precision: {Precision}");
LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}");
LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}");
LogMessage("ReadProfile", $"Settle Time after slew: {SettleTime}");
LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}");
}
/// <summary>