Seperated the SlewSettleTime property from the ProfileSettle time, and implemented a delay on IsSlewing to use the combined SettleTimes
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using ASCOM;
|
using ASCOM;
|
||||||
using ASCOM.Astrometry.AstroUtils;
|
using ASCOM.Astrometry.AstroUtils;
|
||||||
@@ -22,6 +23,7 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
private Mock<IAstroUtils> _astroUtilsMock;
|
private Mock<IAstroUtils> _astroUtilsMock;
|
||||||
private Mock<ISharedResourcesWrapper> _sharedResourcesWrapperMock;
|
private Mock<ISharedResourcesWrapper> _sharedResourcesWrapperMock;
|
||||||
private Mock<IAstroMaths> _astroMathsMock;
|
private Mock<IAstroMaths> _astroMathsMock;
|
||||||
|
private Mock<IClock> _clockMock;
|
||||||
|
|
||||||
private ProfileProperties _profileProperties;
|
private ProfileProperties _profileProperties;
|
||||||
private ConnectionInfo _connectionInfo;
|
private ConnectionInfo _connectionInfo;
|
||||||
@@ -63,8 +65,10 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
|
|
||||||
_astroMathsMock = new Mock<IAstroMaths>();
|
_astroMathsMock = new Mock<IAstroMaths>();
|
||||||
|
|
||||||
|
_clockMock = new Mock<IClock>();
|
||||||
|
|
||||||
_telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object,
|
_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)
|
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"));
|
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Set"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(5)]
|
[Test]
|
||||||
[TestCase(10)]
|
public void SlewSettleTime_Get_ReturnsExpectedValue()
|
||||||
[TestCase(2)]
|
|
||||||
public void SlewSettleTime_Get_ReturnsExpectedValue(short settleTime)
|
|
||||||
{
|
{
|
||||||
_profileProperties.SettleTime = settleTime;
|
|
||||||
|
|
||||||
ConnectTelescope();
|
ConnectTelescope();
|
||||||
|
|
||||||
var result = _telescope.SlewSettleTime;
|
var result = _telescope.SlewSettleTime;
|
||||||
|
|
||||||
Assert.That(result, Is.EqualTo(settleTime));
|
Assert.That(result, Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(8)]
|
[TestCase(8)]
|
||||||
@@ -2339,6 +2339,64 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
|
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"),Times.Once);
|
_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, "", "||||||||", true)]
|
[TestCase(TelescopeList.LX200CLASSIC, "", "||||||||", true)]
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ASCOM.Meade.net
|
||||||
|
{
|
||||||
|
public class Clock : IClock
|
||||||
|
{
|
||||||
|
public DateTime UtcNow => DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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\EquatorialCoordinates.cs" />
|
||||||
<Compile Include="AstroMaths\HorizonCoordinates.cs" />
|
<Compile Include="AstroMaths\HorizonCoordinates.cs" />
|
||||||
<Compile Include="AstroMaths\IAstroMaths.cs" />
|
<Compile Include="AstroMaths\IAstroMaths.cs" />
|
||||||
|
<Compile Include="Clock.cs" />
|
||||||
<Compile Include="ComparisonResult.cs" />
|
<Compile Include="ComparisonResult.cs" />
|
||||||
<Compile Include="DoubleExtensions.cs" />
|
<Compile Include="DoubleExtensions.cs" />
|
||||||
|
<Compile Include="IClock.cs" />
|
||||||
<Compile Include="StringExtensions.cs" />
|
<Compile Include="StringExtensions.cs" />
|
||||||
<Compile Include="Telescope.cs" />
|
<Compile Include="Telescope.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -60,16 +60,20 @@ namespace ASCOM.Meade.net
|
|||||||
|
|
||||||
private readonly IAstroMaths _astroMaths;
|
private readonly IAstroMaths _astroMaths;
|
||||||
|
|
||||||
|
private readonly IClock _clock;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Private variable to hold number of decimals for RA
|
/// Private variable to hold number of decimals for RA
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int _digitsRa = 2;
|
private int _digitsRa = 2;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Private variable to hold number of decimals for DE
|
/// Private variable to hold number of decimals for Dec
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int _digitsDe = 2;
|
private int _digitsDe = 2;
|
||||||
|
|
||||||
|
private short _settleTime;
|
||||||
|
|
||||||
/// <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.
|
||||||
@@ -84,6 +88,7 @@ namespace ASCOM.Meade.net
|
|||||||
_utilitiesExtra = util; //Initialise util object
|
_utilitiesExtra = util; //Initialise util object
|
||||||
_astroUtilities = new AstroUtils(); // Initialise astro utilities object
|
_astroUtilities = new AstroUtils(); // Initialise astro utilities object
|
||||||
_astroMaths = new AstroMaths.AstroMaths();
|
_astroMaths = new AstroMaths.AstroMaths();
|
||||||
|
_clock = new Clock();
|
||||||
|
|
||||||
Initialise(nameof(Telescope));
|
Initialise(nameof(Telescope));
|
||||||
}
|
}
|
||||||
@@ -116,8 +121,9 @@ namespace ASCOM.Meade.net
|
|||||||
sb.AppendLine();
|
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
|
_utilities = util; //Initialise util object
|
||||||
_utilitiesExtra = utilExtra; //Initialise util object
|
_utilitiesExtra = utilExtra; //Initialise util object
|
||||||
_astroUtilities = astroUtilities; // Initialise astro utilities object
|
_astroUtilities = astroUtilities; // Initialise astro utilities object
|
||||||
@@ -1775,15 +1781,14 @@ namespace ASCOM.Meade.net
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
CheckConnected("SlewSettleTime Get");
|
CheckConnected("SlewSettleTime Get");
|
||||||
LogMessage("SlewSettleTime Get", $"{SettleTime} Seconds");
|
LogMessage("SlewSettleTime Get", $"{_settleTime} Seconds");
|
||||||
return SettleTime;
|
return _settleTime;
|
||||||
}
|
}
|
||||||
// ReSharper disable once ValueParameterNotUsed
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
CheckConnected("SlewSettleTime Set");
|
CheckConnected("SlewSettleTime Set");
|
||||||
LogMessage("SlewSettleTime Set", $"Setting from {SettleTime} to {value}");
|
LogMessage("SlewSettleTime Set", $"Setting from {_settleTime} to {value}");
|
||||||
SettleTime = value;
|
_settleTime = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1964,16 +1969,29 @@ namespace ASCOM.Meade.net
|
|||||||
return _movingPrimary || _movingSecondary;
|
return _movingPrimary || _movingSecondary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DateTime _earliestNonSlewingTime = DateTime.MinValue;
|
||||||
|
|
||||||
public bool Slewing
|
public bool Slewing
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var isSlewing = GetSlewing();
|
var isSlewing = GetSlewing();
|
||||||
|
|
||||||
|
if (isSlewing)
|
||||||
|
_earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime();
|
||||||
|
else if (_clock.UtcNow < _earliestNonSlewingTime)
|
||||||
|
isSlewing = true;
|
||||||
|
|
||||||
LogMessage("Slewing", $"Result = {isSlewing}");
|
LogMessage("Slewing", $"Result = {isSlewing}");
|
||||||
return isSlewing;
|
return isSlewing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeSpan GetTotalSlewingSettleTime()
|
||||||
|
{
|
||||||
|
return TimeSpan.FromSeconds( SlewSettleTime + ProfileSettleTime );
|
||||||
|
}
|
||||||
|
|
||||||
private bool GetSlewing()
|
private bool GetSlewing()
|
||||||
{
|
{
|
||||||
if (!Connected) return false;
|
if (!Connected) return false;
|
||||||
@@ -2001,7 +2019,7 @@ namespace ASCOM.Meade.net
|
|||||||
bool isSlewing = false;
|
bool isSlewing = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(result))
|
if (string.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
isSlewing = false;
|
isSlewing = false;
|
||||||
return isSlewing;
|
return isSlewing;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace ASCOM.Meade.net
|
|||||||
protected string Precision;
|
protected string Precision;
|
||||||
protected string GuidingStyle;
|
protected string GuidingStyle;
|
||||||
protected double SiteElevation;
|
protected double SiteElevation;
|
||||||
protected short SettleTime;
|
protected short ProfileSettleTime;
|
||||||
|
|
||||||
protected readonly ISharedResourcesWrapper SharedResourcesWrapper;
|
protected readonly ISharedResourcesWrapper SharedResourcesWrapper;
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ namespace ASCOM.Meade.net
|
|||||||
Precision = profileProperties.Precision;
|
Precision = profileProperties.Precision;
|
||||||
GuidingStyle = profileProperties.GuidingStyle.ToLower();
|
GuidingStyle = profileProperties.GuidingStyle.ToLower();
|
||||||
SiteElevation = profileProperties.SiteElevation;
|
SiteElevation = profileProperties.SiteElevation;
|
||||||
SettleTime = profileProperties.SettleTime;
|
ProfileSettleTime = profileProperties.SettleTime;
|
||||||
|
|
||||||
LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}");
|
LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}");
|
||||||
LogMessage("ReadProfile", $"Com Port: {ComPort}");
|
LogMessage("ReadProfile", $"Com Port: {ComPort}");
|
||||||
@@ -78,7 +78,7 @@ namespace ASCOM.Meade.net
|
|||||||
LogMessage("ReadProfile", $"Precision: {Precision}");
|
LogMessage("ReadProfile", $"Precision: {Precision}");
|
||||||
LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}");
|
LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}");
|
||||||
LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}");
|
LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}");
|
||||||
LogMessage("ReadProfile", $"Settle Time after slew: {SettleTime}");
|
LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user