Added support for parking the scope
Added support for reading the scope Azimuth
This commit is contained in:
@@ -7,7 +7,6 @@ using ASCOM.DeviceInterface;
|
||||
using ASCOM.MeadeAutostar497.Controller;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using InvalidOperationException = ASCOM.InvalidOperationException;
|
||||
|
||||
namespace MeadeAutostar497.UnitTests
|
||||
{
|
||||
@@ -30,20 +29,21 @@ namespace MeadeAutostar497.UnitTests
|
||||
|
||||
serialMock = new Mock<ISerialProcessor>();
|
||||
serialMock.SetupAllProperties();
|
||||
serialMock.Setup(x => x.GetPortNames()).Returns( () => _availableComPorts.ToArray());
|
||||
serialMock.Setup(x => x.CommandTerminated(It.IsAny<string>(), It.IsAny<string>())).Returns(() => _stringToRecieve);
|
||||
serialMock.Setup(x => x.GetPortNames()).Returns(() => _availableComPorts.ToArray());
|
||||
serialMock.Setup(x => x.CommandTerminated(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(() => _stringToRecieve);
|
||||
serialMock.Setup(x => x.IsOpen).Returns(() => _isConnected);
|
||||
|
||||
//Todo inject the serialMock instead of using a singleton to increase code stability.
|
||||
|
||||
_telescopeController = TelescopeController.Instance;
|
||||
_telescopeController.Connected = false;
|
||||
_telescopeController.SerialPort = serialMock.Object;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_isConnected = false;
|
||||
_telescopeController.Connected = false;
|
||||
_telescopeController.Port = "COM1";
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace MeadeAutostar497.UnitTests
|
||||
public void WhenOpensComPortToNonAutostarThrowException()
|
||||
{
|
||||
Assert.That(serialMock.Object.IsOpen, Is.False);
|
||||
var exception = Assert.Throws<InvalidOperationException>(() => { _telescopeController.Connected = true; });
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.Connected = true; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to communicate with telescope."));
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace MeadeAutostar497.UnitTests
|
||||
|
||||
Mock<ISerialProcessor> newSerialMock = new Mock<ISerialProcessor>();
|
||||
|
||||
var exception = Assert.Throws<InvalidOperationException>( () => { _telescopeController.SerialPort = newSerialMock.Object; });
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>( () => { _telescopeController.SerialPort = newSerialMock.Object; });
|
||||
|
||||
Assert.That(exception, Is.Not.Null);
|
||||
Assert.That(exception.Message, Is.EqualTo("Please disconnect before changing the serial engine."));
|
||||
@@ -141,7 +141,7 @@ namespace MeadeAutostar497.UnitTests
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
var exception = Assert.Throws<InvalidOperationException>( () => _telescopeController.Port = "COM2");
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>( () => _telescopeController.Port = "COM2");
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Please disconnect from the scope before changing port."));
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace MeadeAutostar497.UnitTests
|
||||
[Test]
|
||||
public void SettingPortToInvalidPortFails()
|
||||
{
|
||||
var exception = Assert.Throws<InvalidOperationException>(() => _telescopeController.Port = "COM5");
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => _telescopeController.Port = "COM5");
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Unable to select port COM5 as it does not exist."));
|
||||
|
||||
@@ -318,7 +318,7 @@ namespace MeadeAutostar497.UnitTests
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<InvalidOperationException>(() => { _telescopeController.SiteLatitude = 10; });
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.SiteLatitude = 10; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude."));
|
||||
}
|
||||
@@ -383,7 +383,7 @@ namespace MeadeAutostar497.UnitTests
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<InvalidOperationException>(() => { _telescopeController.SiteLongitude = 10; });
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.SiteLongitude = 10; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude."));
|
||||
}
|
||||
@@ -482,7 +482,6 @@ namespace MeadeAutostar497.UnitTests
|
||||
public void AtParkIsFalseByDefault()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
Assert.That( _telescopeController.AtPark, Is.False );
|
||||
@@ -522,5 +521,20 @@ namespace MeadeAutostar497.UnitTests
|
||||
|
||||
serialMock.Verify(x => x.Command(":hP#"), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase("356*13",356.21666666666664)]
|
||||
[TestCase("356*13'21", 356.22249999999997)]
|
||||
public void Azimuth_CanGetValue( string response, double expectedResult )
|
||||
{
|
||||
serialMock.Setup(x => x.CommandTerminated(":GZ#", "#")).Returns(response);
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var az = _telescopeController.Azimuth;
|
||||
|
||||
Assert.That( az, Is.EqualTo(expectedResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,8 +358,9 @@ namespace ASCOM.MeadeAutostar497
|
||||
{
|
||||
get
|
||||
{
|
||||
tl.LogMessage("Azimuth Get", "Not implemented");
|
||||
throw new ASCOM.PropertyNotImplementedException("Azimuth", false);
|
||||
var az = _telescopeController.Azimuth;
|
||||
tl.LogMessage("Azimuth Get", $"{az}");
|
||||
return az;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
double SiteLongitude { get; set; }
|
||||
AlignmentModes AlignmentMode { get; set; }
|
||||
bool AtPark { get; }
|
||||
double Azimuth { get; }
|
||||
void AbortSlew();
|
||||
void PulseGuide(GuideDirections direction, int duration);
|
||||
void Park();
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
|
||||
public static TelescopeController Instance => lazy.Value;
|
||||
|
||||
//todo remove this as it can cause problems in production
|
||||
private ISerialProcessor _serialPort;
|
||||
public ISerialProcessor SerialPort
|
||||
{
|
||||
@@ -68,6 +69,7 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
//Connecting
|
||||
try
|
||||
{
|
||||
_parked = false;
|
||||
SerialPort.DtrEnable = false;
|
||||
SerialPort.RtsEnable = false;
|
||||
SerialPort.BaudRate = 9600;
|
||||
@@ -90,6 +92,7 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
{
|
||||
//Disconnecting
|
||||
SerialPort.Close();
|
||||
_parked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,16 +218,22 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
}
|
||||
}
|
||||
|
||||
private double DMSToDouble(string DMS)
|
||||
{
|
||||
double l = int.Parse(DMS.Substring(0, 3));
|
||||
l = l + double.Parse(DMS.Substring(4, 2)) / 60;
|
||||
if (DMS.Length == 9)
|
||||
l = l + double.Parse(DMS.Substring(7, 2)) / 60 / 60;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
public double SiteLongitude
|
||||
{
|
||||
get
|
||||
{
|
||||
var longitude = SerialPort.CommandTerminated(":Gg#", "#");
|
||||
|
||||
double l = int.Parse(longitude.Substring(0, 3));
|
||||
l = l + double.Parse(longitude.Substring(4, 2)) / 60;
|
||||
if (longitude.Length == 9)
|
||||
l = l + double.Parse(longitude.Substring(7, 2)) / 60 / 60;
|
||||
double l = DMSToDouble(longitude);
|
||||
|
||||
if (l > 180)
|
||||
l = l - 360;
|
||||
@@ -254,6 +263,12 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
get
|
||||
{
|
||||
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.
|
||||
|
||||
switch (alignmentString[0])
|
||||
{
|
||||
@@ -263,22 +278,21 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
default:
|
||||
throw new ASCOM.InvalidValueException($"unknown alignment returned from telescope: {alignmentString[0]}");
|
||||
}
|
||||
//: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.
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case AlignmentModes.algAltAz: SerialPort.Command(":AA#");
|
||||
case AlignmentModes.algAltAz:
|
||||
SerialPort.Command(":AA#");
|
||||
//:AA# Sets telescope the AltAz alignment mode
|
||||
//Returns: nothing
|
||||
break;
|
||||
case AlignmentModes.algPolar:
|
||||
case AlignmentModes.algGermanPolar:
|
||||
SerialPort.Command(":AP#");
|
||||
//:AP# Sets telescope to Polar alignment mode
|
||||
//Returns: nothing
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(value), value, null);
|
||||
@@ -286,10 +300,6 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
|
||||
//:AL# Sets telescope to Land alignment mode
|
||||
//Returns: nothing
|
||||
//:AP# Sets telescope to Polar alignment mode
|
||||
//Returns: nothing
|
||||
//:AA# Sets telescope the AltAz alignment mode
|
||||
//Returns: nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +307,21 @@ namespace ASCOM.MeadeAutostar497.Controller
|
||||
|
||||
public bool AtPark => _parked;
|
||||
|
||||
public double Azimuth
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = SerialPort.CommandTerminated(":GZ#", "#");
|
||||
//:GZ# Get telescope azimuth
|
||||
//Returns: DDD*MM#T or DDD*MM’SS#
|
||||
//The current telescope Azimuth depending on the selected precision.
|
||||
|
||||
double az = DMSToDouble(result);
|
||||
|
||||
return az;
|
||||
}
|
||||
}
|
||||
|
||||
public void AbortSlew()
|
||||
{
|
||||
SerialPort.Command("#:Q#");
|
||||
|
||||
Reference in New Issue
Block a user