Added support for the GW Command.

Removed the implementation of Tracking Set as this does not do anything in the code.
Set Can Set Tracking to false.
Get tracking always returns true is the GW command is not supported.
This commit is contained in:
2021-03-10 19:25:27 +00:00
parent 8713154e84
commit 21e7bcd530
5 changed files with 123 additions and 54 deletions
@@ -621,15 +621,18 @@ 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())).Returns(telescopeMode);
_sharedResourcesWrapperMock.Setup(x => x.SendString(":GW#")).Returns($"{telescopeMode}N0");
ConnectTelescope();
ConnectTelescope(productName, firmware);
var actualResult = _telescope.AlignmentMode;
@@ -897,11 +900,11 @@ namespace Meade.net.Telescope.UnitTests
}
[Test]
public void CanSetTracking_Get_ReturnsTrue()
public void CanSetTracking_Get_ReturnsFalse()
{
var result = _telescope.CanSetTracking;
Assert.That(result, Is.True);
Assert.That(result, Is.False);
}
[Test]
@@ -2121,11 +2124,9 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(true)]
[TestCase(false)]
public void Tracking_SetAndGet_WhenValueSet_ThenCanGetNewValue(bool tracking)
public void Tracking_Set_ThenThrowsNotImplementedException(bool tracking)
{
_telescope.Tracking = tracking;
Assert.That(_telescope.Tracking, Is.EqualTo( tracking));
Assert.Throws<ASCOM.NotImplementedException>( () => { _telescope.Tracking = tracking; } );
}
[Test]
+10
View File
@@ -0,0 +1,10 @@
namespace ASCOM.Meade.net
{
public enum Alignment
{
NeedsAlignment,
OneStarAligned,
TwoStarAligned,
ThreeStarAligned
}
}
+11
View File
@@ -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; }
}
}
@@ -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" />
+88 -43
View File
@@ -510,7 +510,7 @@ namespace ASCOM.Meade.net
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;
}
@@ -830,47 +830,41 @@ namespace ASCOM.Meade.net
CheckConnected("AlignmentMode Get");
const char ack = (char) 6;
var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString());
//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.
//}
AlignmentModes alignmentMode;
switch (alignmentString)
if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
{
case "A":
alignmentMode = AlignmentModes.algAltAz;
break;
case "P":
alignmentMode = AlignmentModes.algPolar;
break;
case "G":
alignmentMode = AlignmentModes.algGermanPolar;
break;
default:
throw new InvalidValueException(
$"unknown alignment returned from telescope: {alignmentString}");
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
var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString());
AlignmentModes alignmentMode;
switch (alignmentString)
{
case "A":
alignmentMode = AlignmentModes.algAltAz;
break;
case "P":
alignmentMode = AlignmentModes.algPolar;
break;
//case "G":
// alignmentMode = AlignmentModes.algGermanPolar;
// break;
default:
throw new InvalidValueException(
$"unknown alignment returned from telescope: {alignmentString}");
}
LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}");
return alignmentMode;
LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}");
return alignmentMode;
}
}
set
{
@@ -901,6 +895,50 @@ namespace ASCOM.Meade.net
//Returns: nothing
}
}
private AlignmentStatus GetScopeAlignmentStatus()
{
var alignmentString = SharedResourcesWrapper.SendString(":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 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[0] == 'T';
switch (alignmentString[1])
{
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;
}
return alignmentStatus;
}
public double Altitude
{
@@ -1111,8 +1149,8 @@ namespace ASCOM.Meade.net
{
get
{
LogMessage("CanSetTracking", "Get - " + true);
return true;
LogMessage("CanSetTracking", "Get - " + false);
return false;
}
}
@@ -2236,12 +2274,19 @@ namespace ASCOM.Meade.net
get
{
LogMessage("Tracking", $"Get - {_tracking}");
if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
{
var alignmentStatus = GetScopeAlignmentStatus();
_tracking = alignmentStatus.Tracking;
}
return _tracking;
}
set
{
LogMessage("Tracking Set", $"{value}");
_tracking = value;
throw new ASCOM.NotImplementedException("Tracking Set");
//LogMessage("Tracking Set", $"{value}");
//_tracking = value;
}
}