Merged in feature/GWSupport-update (pull request #35)
Feature/GWSupport update
This commit is contained in:
@@ -18,20 +18,23 @@ namespace Meade.net.Telescope.UnitTests
|
||||
{
|
||||
public class TestProperties
|
||||
{
|
||||
internal string telescopeRaResult = "HH:MM:SS";
|
||||
internal double rightAscension = 1.2; //todo rename to declination;
|
||||
internal double declination = 45;
|
||||
internal string telescopeRaResult { get; set; } = "HH:MM:SS";
|
||||
internal double rightAscension { get; set; } = 1.2; //todo rename to declination;
|
||||
internal double declination { get; set; } = 45;
|
||||
|
||||
internal string SiteLatitudeString = "testLatString";
|
||||
internal double SiteLatitudeValue = 123.45;
|
||||
internal string SiteLatitudeString { get; set; } = "testLatString";
|
||||
internal double SiteLatitudeValue { get; set; } = 123.45;
|
||||
|
||||
internal string telescopeDate = "10/15/20";
|
||||
internal string telescopeTime = "20:15:10";
|
||||
internal string telescopeUtcCorrection = "-1.0";
|
||||
internal string telescopeDate { get; set; } = "10/15/20";
|
||||
internal string telescopeTime { get; set; } = "20:15:10";
|
||||
internal string telescopeUtcCorrection { get; set; } = "-1.0";
|
||||
|
||||
internal double hourAngle;
|
||||
internal int telescopeAltitude = 45;
|
||||
internal int telescopeAzimuth = 200;
|
||||
internal double hourAngle { get; set; }
|
||||
internal int telescopeAltitude { get; set; } = 45;
|
||||
internal int telescopeAzimuth { get; set; } = 200;
|
||||
|
||||
internal char[] AlignmentStatus { get; set; }
|
||||
internal string TrackingRate { get; set; }
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
@@ -121,8 +124,14 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.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, string alignmentStatus = "GT0")
|
||||
{
|
||||
_testProperties.AlignmentStatus = alignmentStatus.ToCharArray();
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendChars("GW", false, 3)).Returns(() => new string(_testProperties.AlignmentStatus));
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendBlind("AP", false)).Callback(() => _testProperties.AlignmentStatus[1] = 'T');
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendBlind("AL", false)).Callback(() => _testProperties.AlignmentStatus[1] = 'N');
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns( () => _testProperties.SiteLatitudeString);
|
||||
_utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue);
|
||||
|
||||
@@ -133,6 +142,12 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(() => _testProperties.telescopeTime);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(() => _testProperties.telescopeUtcCorrection);
|
||||
|
||||
const string siderealTrackingRate = "+60.1";
|
||||
_testProperties.TrackingRate = siderealTrackingRate;
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendString("GT", false)).Returns(() => _testProperties.TrackingRate);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendBlind("TL", false)).Callback(() => _testProperties.TrackingRate = "lunar");
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendBlind("TQ", false)).Callback(() => _testProperties.TrackingRate = siderealTrackingRate);
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion);
|
||||
|
||||
@@ -144,6 +159,8 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked);
|
||||
_sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition);
|
||||
|
||||
_sharedResourcesWrapperMock.SetupProperty(x => x.IsGuiding);
|
||||
|
||||
_astroMathsMock
|
||||
.Setup(x => x.ConvertHozToEq(It.IsAny<DateTime>(), It.IsAny<double>(), It.IsAny<double>(),
|
||||
It.IsAny<HorizonCoordinates>())).Returns(() => new EquatorialCoordinates { Declination = _testProperties.declination, RightAscension = _testProperties.rightAscension });
|
||||
@@ -769,15 +786,17 @@ namespace Meade.net.Telescope.UnitTests
|
||||
}
|
||||
|
||||
|
||||
[TestCase("A", AlignmentModes.algAltAz)]
|
||||
[TestCase("P", AlignmentModes.algPolar)]
|
||||
[TestCase("G", AlignmentModes.algGermanPolar)]
|
||||
public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode)
|
||||
[TestCase("A", AlignmentModes.algAltAz, TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee)]
|
||||
[TestCase("P", AlignmentModes.algPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee)]
|
||||
[TestCase("A", AlignmentModes.algAltAz, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)]
|
||||
[TestCase("P", AlignmentModes.algPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)]
|
||||
[TestCase("G", AlignmentModes.algGermanPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)]
|
||||
public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode, string productName, string firmware)
|
||||
{
|
||||
const char ack = (char)6;
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), true)).Returns(telescopeMode);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns(telescopeMode);
|
||||
|
||||
ConnectTelescope();
|
||||
ConnectTelescope(productName, firmware, $"{telescopeMode}N0");
|
||||
|
||||
var actualResult = _telescope.AlignmentMode;
|
||||
|
||||
@@ -1109,12 +1128,15 @@ namespace Meade.net.Telescope.UnitTests
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSetTracking_Get_ReturnsTrue()
|
||||
[TestCase(TelescopeList.Autostar497_30Ee, false)]
|
||||
[TestCase(TelescopeList.Autostar497_43Eg, true)]
|
||||
public void CanSetTracking_Get_ReturnsTrueIffGWCommandIsSupported(string firmware, bool supported)
|
||||
{
|
||||
ConnectTelescope(firmwareVersion: firmware);
|
||||
|
||||
var result = _telescope.CanSetTracking;
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
Assert.That(result, Is.EqualTo(supported));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1939,7 +1961,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns<double>(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA);
|
||||
_astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny<double>())).Returns<double>(pRA => pRA < 0 ? pRA + 24 : pRA >= 24 ? pRA - 24 : pRA);
|
||||
|
||||
ConnectTelescope();
|
||||
ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_43Eg);
|
||||
Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1));
|
||||
|
||||
_telescope.SlewToCoordinates(ra, dec);
|
||||
@@ -2053,7 +2075,8 @@ namespace Meade.net.Telescope.UnitTests
|
||||
// Setup DestinationSideOfPier
|
||||
_astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny<double>())).Returns<double>(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA);
|
||||
|
||||
ConnectTelescope();
|
||||
// Use firmware that supports GW
|
||||
ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_43Eg);
|
||||
|
||||
// when
|
||||
_telescope.SlewToCoordinatesAsync(ra, dec);
|
||||
@@ -2646,11 +2669,26 @@ namespace Meade.net.Telescope.UnitTests
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void Tracking_SetAndGet_WhenValueSet_ThenCanGetNewValue(bool tracking)
|
||||
public void Tracking_Set_WhenCanSetTrackingIsFalse_ThenThrowsNotImplementedException(bool tracking)
|
||||
{
|
||||
// GW is not supported, so CanSetTracking is false
|
||||
ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_30Ee);
|
||||
|
||||
Assert.Throws<ASCOM.NotImplementedException>( () => { _telescope.Tracking = tracking; } );
|
||||
}
|
||||
|
||||
[TestCase(true, "AP")]
|
||||
[TestCase(false, "AL")]
|
||||
public void Tracking_Set_WhenCanSetTrackingIsTrue_ThenValueIsUpdated(bool tracking, string alignmentCommand)
|
||||
{
|
||||
// GW is supported, so CanSetTracking is true
|
||||
ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_43Eg);
|
||||
|
||||
_telescope.Tracking = tracking;
|
||||
|
||||
Assert.That(_telescope.Tracking, Is.EqualTo(tracking));
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(alignmentCommand, false), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -2668,7 +2706,10 @@ namespace Meade.net.Telescope.UnitTests
|
||||
|
||||
_telescope.TrackingRate = rate;
|
||||
|
||||
Assert.That(_telescope.TrackingRate, Is.EqualTo(rate));
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(commandString, false), Times.Once);
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendString("GT", false), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -2972,7 +3013,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return.
|
||||
[TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", false)]
|
||||
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)]
|
||||
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\u007f", true)]
|
||||
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\x007f", true)]
|
||||
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)]
|
||||
public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing)
|
||||
{
|
||||
@@ -3202,7 +3243,6 @@ 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]
|
||||
@@ -3297,7 +3337,6 @@ 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]
|
||||
@@ -3418,7 +3457,6 @@ 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]
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace ASCOM.Meade.net
|
||||
{
|
||||
public enum Alignment
|
||||
{
|
||||
NeedsAlignment,
|
||||
OneStarAligned,
|
||||
TwoStarAligned,
|
||||
ThreeStarAligned,
|
||||
AlignedOnHome,
|
||||
ScopeWasParked,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using ASCOM.DeviceInterface;
|
||||
|
||||
namespace ASCOM.Meade.net
|
||||
{
|
||||
public class AlignmentStatus
|
||||
{
|
||||
public AlignmentModes AlignmentMode { get; set; }
|
||||
public bool Tracking { get; set; }
|
||||
public Alignment Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
@@ -118,6 +118,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Alignment.cs" />
|
||||
<Compile Include="AlignmentStatus.cs" />
|
||||
<Compile Include="AstroMaths\AltitudeData.cs" />
|
||||
<Compile Include="AstroMaths\AstroMathExtensions.cs" />
|
||||
<Compile Include="AstroMaths\AstroMaths.cs" />
|
||||
|
||||
+153
-118
@@ -140,9 +140,6 @@ namespace ASCOM.Meade.net
|
||||
Initialise(nameof(Telescope));
|
||||
}
|
||||
|
||||
private bool _isGuiding;
|
||||
|
||||
private bool _isTargetCoordinateInitRequired = true;
|
||||
//
|
||||
// PUBLIC COM INTERFACE ITelescopeV3 IMPLEMENTATION
|
||||
//
|
||||
@@ -360,9 +357,6 @@ namespace ASCOM.Meade.net
|
||||
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
|
||||
}
|
||||
|
||||
public string CommandString(string command, bool raw)
|
||||
@@ -372,10 +366,19 @@ namespace ASCOM.Meade.net
|
||||
// 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
|
||||
var result = SharedResourcesWrapper.SendString(command, raw);
|
||||
LogMessage("CommandBool", "Completed: {0}", result);
|
||||
string result;
|
||||
// :GW# is not terminated with a # for some reason, see reported comment
|
||||
// https://bitbucket.org/cjdskunkworks/meadeautostar497/issues/24/get-set-tracking#comment-60586901
|
||||
if (command == (raw ? ":GW#" : "GW"))
|
||||
{
|
||||
result = SharedResourcesWrapper.SendChars(command, raw, count: 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = SharedResourcesWrapper.SendString(command, raw);
|
||||
}
|
||||
LogMessage("CommandString", "Completed: {0}", result);
|
||||
return result;
|
||||
//throw new ASCOM.MethodNotImplementedException("CommandString");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -416,7 +419,6 @@ namespace ASCOM.Meade.net
|
||||
$"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}");
|
||||
|
||||
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
|
||||
_tracking = true;
|
||||
|
||||
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
|
||||
IsConnected = true;
|
||||
@@ -620,22 +622,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;
|
||||
}
|
||||
private bool IsGWCommandSupported() => FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg);
|
||||
|
||||
return true;
|
||||
}
|
||||
// true iff the mount will perform a meridian flip when required
|
||||
// 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
|
||||
// meridian flip on slew is supported
|
||||
private bool IsMeridianFlipOnSlewSupported() => IsGWCommandSupported() && AlignmentMode != AlignmentModes.algAltAz;
|
||||
|
||||
private bool FirmwareIsGreaterThan(string minVersion)
|
||||
{
|
||||
var currentVersion = SharedResourcesWrapper.FirmwareVersion;
|
||||
var comparison = String.Compare(currentVersion, minVersion, StringComparison.Ordinal);
|
||||
var comparison = string.Compare(currentVersion, minVersion, StringComparison.Ordinal);
|
||||
return comparison >= 0;
|
||||
}
|
||||
|
||||
@@ -647,16 +645,16 @@ namespace ASCOM.Meade.net
|
||||
if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC)
|
||||
return false;
|
||||
|
||||
if (!_isTargetCoordinateInitRequired)
|
||||
return _isTargetCoordinateInitRequired;
|
||||
if (!SharedResourcesWrapper.IsTargetCoordinateInitRequired)
|
||||
return SharedResourcesWrapper.IsTargetCoordinateInitRequired;
|
||||
|
||||
if (!IsConnected)
|
||||
return true;
|
||||
|
||||
if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC)
|
||||
{
|
||||
_isTargetCoordinateInitRequired = false;
|
||||
return _isTargetCoordinateInitRequired;
|
||||
SharedResourcesWrapper.IsTargetCoordinateInitRequired = false;
|
||||
return SharedResourcesWrapper.IsTargetCoordinateInitRequired;
|
||||
}
|
||||
|
||||
const double eps = 0.00001d;
|
||||
@@ -665,16 +663,16 @@ namespace ASCOM.Meade.net
|
||||
//target RA == 0
|
||||
if (Math.Abs(rightTargetAscension) > eps)
|
||||
{
|
||||
_isTargetCoordinateInitRequired = false;
|
||||
return _isTargetCoordinateInitRequired;
|
||||
SharedResourcesWrapper.IsTargetCoordinateInitRequired = false;
|
||||
return SharedResourcesWrapper.IsTargetCoordinateInitRequired;
|
||||
}
|
||||
|
||||
double targetDeclination = Declination;
|
||||
//target DE == 0
|
||||
if (Math.Abs(targetDeclination) > eps)
|
||||
{
|
||||
_isTargetCoordinateInitRequired = false;
|
||||
return _isTargetCoordinateInitRequired;
|
||||
SharedResourcesWrapper.IsTargetCoordinateInitRequired = false;
|
||||
return SharedResourcesWrapper.IsTargetCoordinateInitRequired;
|
||||
}
|
||||
|
||||
//target coordinates are equal current coordinates
|
||||
@@ -682,12 +680,12 @@ namespace ASCOM.Meade.net
|
||||
(Math.Abs(Declination - targetDeclination) <= eps))
|
||||
{
|
||||
LogMessage("IsTargetCoordinateInitRequired", "0 diff -> false");
|
||||
_isTargetCoordinateInitRequired = false;
|
||||
return _isTargetCoordinateInitRequired;
|
||||
SharedResourcesWrapper.IsTargetCoordinateInitRequired = false;
|
||||
return SharedResourcesWrapper.IsTargetCoordinateInitRequired;
|
||||
}
|
||||
|
||||
LogMessage("IsTargetCoordinateInitRequired", $"{_isTargetCoordinateInitRequired}");
|
||||
return _isTargetCoordinateInitRequired;
|
||||
LogMessage("IsTargetCoordinateInitRequired", $"{SharedResourcesWrapper.IsTargetCoordinateInitRequired}");
|
||||
return SharedResourcesWrapper.IsTargetCoordinateInitRequired;
|
||||
}
|
||||
|
||||
private void InitTargetCoordinates()
|
||||
@@ -701,7 +699,7 @@ namespace ASCOM.Meade.net
|
||||
SyncToCoordinates(raAndDec.RightAscension, raAndDec.Declination);
|
||||
|
||||
//do it only once
|
||||
_isTargetCoordinateInitRequired = false;
|
||||
SharedResourcesWrapper.IsTargetCoordinateInitRequired = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -957,28 +955,21 @@ namespace ASCOM.Meade.net
|
||||
|
||||
CheckConnected("AlignmentMode Get");
|
||||
|
||||
const char ack = (char) 6;
|
||||
|
||||
var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString(), true);
|
||||
if (IsGWCommandSupported())
|
||||
{
|
||||
var alignmentStatus = GetScopeAlignmentStatus();
|
||||
return alignmentStatus.AlignmentMode;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char ack = (char)6;
|
||||
//ACK <0x06> Query of alignment mounting mode.
|
||||
//Returns:
|
||||
//A If scope in AltAz Mode
|
||||
//D If scope is currently in the Downloader[Autostar II & Autostar]
|
||||
//L If scope in Land Mode
|
||||
//P If scope in Polar Mode
|
||||
|
||||
//todo implement GW Command - Supported in Autostar 43Eg and above
|
||||
//if FirmwareIsGreaterThan(TelescopeList.Autostar497_43EG)
|
||||
//{
|
||||
//var alignmentString = SerialPort.CommandTerminated(":GW#", "#");
|
||||
//:GW# Get Scope Alignment Status
|
||||
//Returns: <mount><tracking><alignment>#
|
||||
// where:
|
||||
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
|
||||
//tracking: T - tracking, N - not tracking
|
||||
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned.
|
||||
//}
|
||||
|
||||
var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString());
|
||||
AlignmentModes alignmentMode;
|
||||
switch (alignmentString)
|
||||
{
|
||||
@@ -988,9 +979,9 @@ namespace ASCOM.Meade.net
|
||||
case "P":
|
||||
alignmentMode = AlignmentModes.algPolar;
|
||||
break;
|
||||
case "G":
|
||||
alignmentMode = AlignmentModes.algGermanPolar;
|
||||
break;
|
||||
//case "G":
|
||||
// alignmentMode = AlignmentModes.algGermanPolar;
|
||||
// break;
|
||||
default:
|
||||
throw new InvalidValueException(
|
||||
$"unknown alignment returned from telescope: {alignmentString}");
|
||||
@@ -999,12 +990,13 @@ namespace ASCOM.Meade.net
|
||||
LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}");
|
||||
return alignmentMode;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
CheckConnected("AlignmentMode Set");
|
||||
|
||||
//todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly
|
||||
if (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
|
||||
if (!IsGWCommandSupported())
|
||||
throw new PropertyNotImplementedException("AlignmentMode", true);
|
||||
|
||||
switch (value)
|
||||
@@ -1029,6 +1021,56 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
|
||||
private AlignmentStatus GetScopeAlignmentStatus()
|
||||
{
|
||||
var alignmentString = CommandString("GW", false);
|
||||
//:GW# Get Scope Alignment Status
|
||||
//Returns: <mount><tracking><alignment>#
|
||||
// where:
|
||||
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
|
||||
//tracking: T - tracking, N - not tracking, S - sleeping
|
||||
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned., H - Aligned on Home, P - Scope was parked
|
||||
// https://www.cloudynights.com/topic/72166-lx-200-gps-serial-commands/
|
||||
|
||||
var alignmentStatus = new AlignmentStatus();
|
||||
switch (alignmentString[0])
|
||||
{
|
||||
case 'A':
|
||||
alignmentStatus.AlignmentMode = AlignmentModes.algAltAz;
|
||||
break;
|
||||
case 'P':
|
||||
alignmentStatus.AlignmentMode = AlignmentModes.algPolar;
|
||||
break;
|
||||
case 'G':
|
||||
alignmentStatus.AlignmentMode = AlignmentModes.algGermanPolar;
|
||||
break;
|
||||
}
|
||||
alignmentStatus.Tracking = alignmentString[1] == 'T';
|
||||
switch (alignmentString[2])
|
||||
{
|
||||
case '0':
|
||||
alignmentStatus.Status = Alignment.NeedsAlignment;
|
||||
break;
|
||||
case '1':
|
||||
alignmentStatus.Status = Alignment.OneStarAligned;
|
||||
break;
|
||||
case '2':
|
||||
alignmentStatus.Status = Alignment.TwoStarAligned;
|
||||
break;
|
||||
case '3':
|
||||
alignmentStatus.Status = Alignment.ThreeStarAligned;
|
||||
break;
|
||||
case 'H':
|
||||
alignmentStatus.Status = Alignment.AlignedOnHome;
|
||||
break;
|
||||
case 'P':
|
||||
alignmentStatus.Status = Alignment.ScopeWasParked;
|
||||
break;
|
||||
}
|
||||
|
||||
return alignmentStatus;
|
||||
}
|
||||
|
||||
public double Altitude
|
||||
{
|
||||
get
|
||||
@@ -1190,7 +1232,7 @@ namespace ASCOM.Meade.net
|
||||
switch (axis)
|
||||
{
|
||||
case TelescopeAxes.axisPrimary: return true; //RA or AZ
|
||||
case TelescopeAxes.axisSecondary: return true; //Dev or Alt
|
||||
case TelescopeAxes.axisSecondary: return true; //DEC or Alt
|
||||
case TelescopeAxes.axisTertiary: return false; //rotator / derotator
|
||||
default: throw new InvalidValueException("CanMoveAxis", axis.ToString(), "0 to 2");
|
||||
}
|
||||
@@ -1267,8 +1309,9 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
get
|
||||
{
|
||||
LogMessage("CanSetTracking", "Get - " + true);
|
||||
return true;
|
||||
var canSetTracking = IsGWCommandSupported();
|
||||
LogMessage("CanSetTracking", "Get - " + canSetTracking);
|
||||
return canSetTracking;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1338,7 +1381,6 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
|
||||
private double _lastGoodDeclination;
|
||||
|
||||
public double Declination
|
||||
{
|
||||
@@ -1357,7 +1399,6 @@ namespace ASCOM.Meade.net
|
||||
double declination = _utilities.DMSToDegrees(result);
|
||||
|
||||
LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}");
|
||||
_lastGoodDeclination = declination;
|
||||
return declination;
|
||||
}
|
||||
catch (ParkedException)
|
||||
@@ -1565,7 +1606,7 @@ namespace ASCOM.Meade.net
|
||||
switch (rate.Compare(0))
|
||||
{
|
||||
case ComparisonResult.Equals:
|
||||
if (!_isGuiding)
|
||||
if (!SharedResourcesWrapper.IsGuiding)
|
||||
{
|
||||
SetSlewingMinEndTime();
|
||||
}
|
||||
@@ -1596,7 +1637,7 @@ namespace ASCOM.Meade.net
|
||||
switch (rate.Compare(0))
|
||||
{
|
||||
case ComparisonResult.Equals:
|
||||
if (!_isGuiding)
|
||||
if (!SharedResourcesWrapper.IsGuiding)
|
||||
{
|
||||
SetSlewingMinEndTime();
|
||||
}
|
||||
@@ -1644,7 +1685,9 @@ namespace ASCOM.Meade.net
|
||||
Altitude = Altitude,
|
||||
Azimuth = Azimuth,
|
||||
RightAscension = RightAscension,
|
||||
Declination = Declination
|
||||
Declination = Declination,
|
||||
SiteLatitude = SiteLatitude,
|
||||
SiteLongitude = SiteLongitude
|
||||
};
|
||||
break;
|
||||
case ParkedBehaviour.ReportCoordinates:
|
||||
@@ -1658,7 +1701,9 @@ namespace ASCOM.Meade.net
|
||||
Altitude = ParkedAltAz.Altitude,
|
||||
Azimuth = ParkedAltAz.Azimuth,
|
||||
RightAscension = raDec.RightAscension,
|
||||
Declination = raDec.Declination
|
||||
Declination = raDec.Declination,
|
||||
SiteLatitude = latitude,
|
||||
SiteLongitude = longitude
|
||||
};
|
||||
break;
|
||||
default:
|
||||
@@ -1685,7 +1730,7 @@ namespace ASCOM.Meade.net
|
||||
if (IsSlewingToTarget())
|
||||
throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target.");
|
||||
|
||||
_isGuiding = true;
|
||||
SharedResourcesWrapper.IsGuiding = true;
|
||||
try
|
||||
{
|
||||
if (SharedResourcesWrapper.MovingPrimary &&
|
||||
@@ -1768,7 +1813,7 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isGuiding = false;
|
||||
SharedResourcesWrapper.IsGuiding = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1792,7 +1837,6 @@ namespace ASCOM.Meade.net
|
||||
return _utilities.HMSToHours(hms);
|
||||
}
|
||||
|
||||
double _lastGoodRightAsension;
|
||||
|
||||
public double RightAscension
|
||||
{
|
||||
@@ -1811,7 +1855,6 @@ namespace ASCOM.Meade.net
|
||||
double rightAscension = HmToHours(result);
|
||||
|
||||
LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}");
|
||||
_lastGoodRightAsension = rightAscension;
|
||||
return rightAscension;
|
||||
}
|
||||
catch (ParkedException)
|
||||
@@ -1852,19 +1895,26 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsMeridianFlipOnSlewSupported())
|
||||
if (!IsMeridianFlipOnSlewSupported())
|
||||
{
|
||||
// while mount is slewing return unknown, this is required since
|
||||
// DoSlewAsync updates _pierSide before slew is finished
|
||||
var pierSide = Slewing ? PierSide.pierUnknown : SharedResourcesWrapper.SideOfPier;
|
||||
LogMessage("SideOfPier Get", "Not implemented");
|
||||
throw new PropertyNotImplementedException("SideOfPier", false);
|
||||
}
|
||||
|
||||
PierSide pierSide;
|
||||
if (Slewing)
|
||||
{
|
||||
// because we update SideOfPier after initiating the slew command we return unknown while still slewing
|
||||
pierSide = PierSide.pierUnknown;
|
||||
}
|
||||
else
|
||||
{
|
||||
pierSide = SharedResourcesWrapper.SideOfPier;
|
||||
}
|
||||
|
||||
LogMessage("SideOfPier", "Get - " + pierSide);
|
||||
return pierSide;
|
||||
}
|
||||
|
||||
LogMessage("SideOfPier Get", "Not implemented");
|
||||
throw new PropertyNotImplementedException("SideOfPier", false);
|
||||
}
|
||||
// ReSharper disable once ValueParameterNotUsed
|
||||
set
|
||||
{
|
||||
@@ -1931,7 +1981,6 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
|
||||
private double? _lastGoodSiteLatitude;
|
||||
public double SiteLatitude
|
||||
{
|
||||
get
|
||||
@@ -1950,19 +1999,14 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
var siteLatitude = _utilities.DMSToDegrees(latitude);
|
||||
LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}");
|
||||
|
||||
_lastGoodSiteLatitude = siteLatitude;
|
||||
return siteLatitude;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("unable to get site latitude from telescope.");
|
||||
}
|
||||
catch (ParkedException)
|
||||
catch (ParkedException) when (ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition)
|
||||
{
|
||||
if (ParkedBehaviour == ParkedBehaviour.NoCoordinates)
|
||||
throw;
|
||||
|
||||
return _lastGoodSiteLatitude.Value;
|
||||
return parkedPosition.SiteLatitude;
|
||||
}
|
||||
}
|
||||
set
|
||||
@@ -1992,12 +2036,9 @@ namespace ASCOM.Meade.net
|
||||
//1 - Valid
|
||||
if (result != "1")
|
||||
throw new InvalidOperationException("Failed to set site latitude.");
|
||||
|
||||
_lastGoodSiteLatitude = value;
|
||||
}
|
||||
}
|
||||
|
||||
private double _lastGoodSiteLongitude;
|
||||
|
||||
public double SiteLongitude
|
||||
{
|
||||
@@ -2015,18 +2056,15 @@ namespace ASCOM.Meade.net
|
||||
double siteLongitude = -_utilities.DMSToDegrees(longitude);
|
||||
|
||||
if (siteLongitude < -180)
|
||||
siteLongitude = siteLongitude + 360;
|
||||
siteLongitude += 360;
|
||||
|
||||
LogMessage("SiteLongitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLongitude)}");
|
||||
_lastGoodSiteLongitude = siteLongitude;
|
||||
|
||||
return siteLongitude;
|
||||
}
|
||||
catch (ParkedException)
|
||||
catch (ParkedException) when (ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition)
|
||||
{
|
||||
if (ParkedBehaviour == ParkedBehaviour.NoCoordinates)
|
||||
throw;
|
||||
|
||||
return _lastGoodSiteLongitude;
|
||||
return parkedPosition.SiteLongitude;
|
||||
}
|
||||
}
|
||||
set
|
||||
@@ -2061,8 +2099,6 @@ namespace ASCOM.Meade.net
|
||||
//1 - Valid
|
||||
if (result != "1")
|
||||
throw new InvalidOperationException("Failed to set site longitude.");
|
||||
|
||||
_lastGoodSiteLongitude = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2269,7 +2305,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
private bool MovingAxis()
|
||||
{
|
||||
if (_isGuiding)
|
||||
if (SharedResourcesWrapper.IsGuiding)
|
||||
return false;
|
||||
|
||||
return SharedResourcesWrapper.MovingPrimary || SharedResourcesWrapper.MovingSecondary;
|
||||
@@ -2321,7 +2357,7 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
CheckConnected("IsSlewingToTarget");
|
||||
|
||||
if (_isGuiding)
|
||||
if (SharedResourcesWrapper.IsGuiding)
|
||||
return false;
|
||||
|
||||
string result;
|
||||
@@ -2550,41 +2586,42 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
|
||||
private bool _tracking = true;
|
||||
public bool Tracking
|
||||
{
|
||||
get
|
||||
{
|
||||
LogMessage("Tracking", $"Get - {_tracking}");
|
||||
return _tracking;
|
||||
LogMessage("Tracking", "Get");
|
||||
if (IsGWCommandSupported())
|
||||
{
|
||||
var alignmentStatus = GetScopeAlignmentStatus();
|
||||
return alignmentStatus.Tracking;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
set
|
||||
{
|
||||
LogMessage("Tracking Set", $"{value}");
|
||||
_tracking = value;
|
||||
}
|
||||
if (!CanSetTracking)
|
||||
{
|
||||
throw new ASCOM.NotImplementedException("Tracking Set");
|
||||
}
|
||||
|
||||
private DriveRates _trackingRate = DriveRates.driveSidereal;
|
||||
LogMessage("Tracking Set", $"{value}");
|
||||
SharedResourcesWrapper.SendBlind(value ? "AP" : "AL");
|
||||
}
|
||||
}
|
||||
|
||||
public DriveRates TrackingRate
|
||||
{
|
||||
get
|
||||
{
|
||||
//todo implement this with the GW command
|
||||
//var result = SerialPort.CommandTerminated(":GT#", "#");
|
||||
var rate = CommandString("GT", false);
|
||||
|
||||
//double rate = double.Parse(result);
|
||||
if (rate == "+60.1")
|
||||
return DriveRates.driveSidereal;
|
||||
|
||||
|
||||
//if (rate == 60.1)
|
||||
// return DriveRates.driveLunar;
|
||||
//else if (rate == 60.1)
|
||||
// return DriveRates.driveSidereal;
|
||||
|
||||
//return DriveRates.driveKing;
|
||||
LogMessage("TrackingRate Get", $"{_trackingRate}");
|
||||
return _trackingRate;
|
||||
// we only support two rates ATM so return lunar tracking rate
|
||||
return DriveRates.driveLunar;
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -2616,8 +2653,6 @@ namespace ASCOM.Meade.net
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(value), value, null);
|
||||
}
|
||||
|
||||
_trackingRate = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -649,5 +649,11 @@ namespace Meade.net.UnitTests
|
||||
|
||||
[Test]
|
||||
public void CheckTargetRightAscensionIsNullByDefault() => Assert.That(SharedResources.TargetRightAscension.HasValue, Is.False);
|
||||
|
||||
[Test]
|
||||
public void CheckIsTargetCoordinateInitRequired() => Assert.That(SharedResources.IsTargetCoordinateInitRequired, Is.True);
|
||||
|
||||
[Test]
|
||||
public void CheckIsGuiding() => Assert.That(SharedResources.IsGuiding, Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,7 @@ namespace ASCOM.Meade.net
|
||||
public double Azimuth { get; set; }
|
||||
public double RightAscension { get; set; }
|
||||
public double Declination { get; set; }
|
||||
public double SiteLongitude { get; set; }
|
||||
public double SiteLatitude { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -124,13 +124,17 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static bool SendBool(string command, bool raw = false)
|
||||
{
|
||||
|
||||
var result = SendChar(command, raw);
|
||||
|
||||
return result == "1";
|
||||
}
|
||||
|
||||
public static string SendChar(string command, bool raw = false)
|
||||
{
|
||||
return SendChars(command, raw, count: 1);
|
||||
}
|
||||
|
||||
public static string SendChars(string command, bool raw = false, int count = 1)
|
||||
{
|
||||
lock (LockObject)
|
||||
{
|
||||
@@ -141,14 +145,11 @@ namespace ASCOM.Meade.net
|
||||
|
||||
try
|
||||
{
|
||||
return SharedSerial.ReceiveCounted(1);
|
||||
return SharedSerial.ReceiveCounted(count);
|
||||
}
|
||||
catch (COMException ex)
|
||||
catch (COMException ex) when (ex.Message.Contains("Timed out waiting for received data"))
|
||||
{
|
||||
if (ex.Message.Contains("Timed out waiting for received data"))
|
||||
throw new TimeoutException(ex.Message, ex);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -575,5 +576,19 @@ namespace ASCOM.Meade.net
|
||||
get => _earliestNonSlewingTime;
|
||||
internal set => _earliestNonSlewingTime.Set(value);
|
||||
}
|
||||
|
||||
private static readonly ThreadSafeValue<bool> _isTargetCoordinateInitRequired = true;
|
||||
public static bool IsTargetCoordinateInitRequired
|
||||
{
|
||||
get => _isTargetCoordinateInitRequired;
|
||||
internal set => _isTargetCoordinateInitRequired.Set(value);
|
||||
}
|
||||
|
||||
private static readonly ThreadSafeValue<bool> _isGuiding = false;
|
||||
public static bool IsGuiding
|
||||
{
|
||||
get => _isGuiding;
|
||||
internal set => _isGuiding.Set(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ namespace ASCOM.Meade.net.Wrapper
|
||||
void SendBlind(string message, bool raw = false);
|
||||
bool SendBool(string command, bool raw = false);
|
||||
string SendChar(string message, bool raw = false);
|
||||
string SendChars(string message, bool raw = false, int count = 1);
|
||||
|
||||
string ReadTerminated();
|
||||
|
||||
@@ -46,6 +47,10 @@ namespace ASCOM.Meade.net.Wrapper
|
||||
bool MovingSecondary { get; set; }
|
||||
|
||||
DateTime EarliestNonSlewingTime { get; set; }
|
||||
|
||||
bool IsTargetCoordinateInitRequired { get; set; }
|
||||
|
||||
bool IsGuiding { get; set; }
|
||||
}
|
||||
|
||||
public class SharedResourcesWrapper : ISharedResourcesWrapper
|
||||
@@ -94,6 +99,11 @@ namespace ASCOM.Meade.net.Wrapper
|
||||
return SharedResources.SendChar(message, raw);
|
||||
}
|
||||
|
||||
public string SendChars(string message, bool raw = false, int count = 1)
|
||||
{
|
||||
return SharedResources.SendChars(message, raw, count);
|
||||
}
|
||||
|
||||
public string ReadTerminated()
|
||||
{
|
||||
return SharedResources.ReadTerminated();
|
||||
@@ -175,5 +185,17 @@ namespace ASCOM.Meade.net.Wrapper
|
||||
get => SharedResources.EarliestNonSlewingTime;
|
||||
set => SharedResources.EarliestNonSlewingTime = value;
|
||||
}
|
||||
|
||||
public bool IsTargetCoordinateInitRequired
|
||||
{
|
||||
get => SharedResources.IsTargetCoordinateInitRequired;
|
||||
set => SharedResources.IsTargetCoordinateInitRequired = value;
|
||||
}
|
||||
|
||||
public bool IsGuiding
|
||||
{
|
||||
get => SharedResources.IsGuiding;
|
||||
set => SharedResources.IsGuiding = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user