Merged in develop (pull request #30)

Develop
This commit is contained in:
2021-04-29 15:18:42 +00:00
9 changed files with 800 additions and 665 deletions
+27 -23
View File
@@ -109,16 +109,17 @@ namespace Meade.net.Focuser.UnitTests
Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBlind")); Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBlind"));
} }
[Test] [TestCase(false)]
public void CommandBlind_WhenConnected_ThenSendsExpectedMessage() [TestCase(true)]
public void CommandBlind_WhenConnected_ThenSendsExpectedMessage(bool raw)
{ {
string expectedMessage = "test blind Message"; string expectedMessage = "test blind Message";
ConnectFocuser(); ConnectFocuser();
_focuser.CommandBlind(expectedMessage, true); _focuser.CommandBlind(expectedMessage, raw);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once);
} }
[Test] [Test]
@@ -130,16 +131,19 @@ namespace Meade.net.Focuser.UnitTests
Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBool")); Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBool"));
} }
[Test] [TestCase(false)]
public void CommandBool_WhenConnected_ThenSendsExpectedMessage() [TestCase(true)]
public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw)
{ {
string expectedMessage = "test blind Message"; string expectedMessage = "test blind Message";
_sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true);
ConnectFocuser(); ConnectFocuser();
var exception = Assert.Throws<MethodNotImplementedException>(() => { _focuser.CommandBool(expectedMessage, true); }); var result = _focuser.CommandBool(expectedMessage, raw);
Assert.That(exception.Message, Is.EqualTo("Method CommandBool is not implemented in this driver.")); _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once);
Assert.That(result, Is.True);
} }
[Test] [Test]
@@ -319,7 +323,7 @@ namespace Meade.net.Focuser.UnitTests
_focuser.Halt(); _focuser.Halt();
_sharedResourcesWrapperMock.Verify( x => x.SendBlind(":FQ#"), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("FQ", false), Times.AtLeastOnce);
} }
[Test] [Test]
@@ -334,13 +338,13 @@ namespace Meade.net.Focuser.UnitTests
[TestCase(false)] [TestCase(false)]
[TestCase(true)] [TestCase(true)]
public void Link_Get_ReturnsSameValueAsConnected( bool connected) public void Link_Get_ReturnsSameValueAsConnected(bool connected)
{ {
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee);
_focuser.Connected = connected; _focuser.Connected = connected;
Assert.That( _focuser.Link, Is.EqualTo(connected)); Assert.That(_focuser.Link, Is.EqualTo(connected));
} }
[TestCase(false)] [TestCase(false)]
@@ -394,12 +398,12 @@ namespace Meade.net.Focuser.UnitTests
_focuser.Move(0); _focuser.Move(0);
_utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Never);
} }
[TestCase(200)] [TestCase(200)]
[TestCase(-200)] [TestCase(-200)]
public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser( int position) public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser(int position)
{ {
_profileProperties.BacklashCompensation = 0; _profileProperties.BacklashCompensation = 0;
@@ -409,16 +413,16 @@ namespace Meade.net.Focuser.UnitTests
if (position < 0) if (position < 0)
{ {
_sharedResourcesWrapperMock.Verify( x => x.SendBlind(":F-#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never);
} }
else else
{ {
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Never);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once);
} }
_sharedResourcesWrapperMock.Verify( x => x.Lock(It.IsAny<Action>()), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny<Action>()), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never);
@@ -437,16 +441,16 @@ namespace Meade.net.Focuser.UnitTests
if (position < 0) if (position < 0)
{ {
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never);
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(1)); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(1));
} }
else else
{ {
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position) + _profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position) + _profileProperties.BacklashCompensation), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once);
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2)); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2));
@@ -503,7 +507,7 @@ namespace Meade.net.Focuser.UnitTests
{ {
var exception = Assert.Throws<PropertyNotImplementedException>(() => var exception = Assert.Throws<PropertyNotImplementedException>(() =>
{ {
var result = _focuser.Temperature; var result = _focuser.Temperature;
Assert.Fail($"{result} should not have a value"); Assert.Fail($"{result} should not have a value");
}); });
Assert.That(exception.Message, Is.EqualTo("Property read Temperature is not implemented in this driver.")); Assert.That(exception.Message, Is.EqualTo("Property read Temperature is not implemented in this driver."));
File diff suppressed because it is too large Load Diff
+237 -169
View File
@@ -45,12 +45,15 @@ namespace ASCOM.Meade.net
/// The DeviceID is used by ASCOM applications to load the driver at runtime. /// The DeviceID is used by ASCOM applications to load the driver at runtime.
/// </summary> /// </summary>
//internal static string driverID = "ASCOM.Meade.net.Telescope"; //internal static string driverID = "ASCOM.Meade.net.Telescope";
private static readonly string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ?? throw new System.InvalidOperationException()); private static readonly string DriverId =
Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ??
throw new System.InvalidOperationException());
/// <summary> /// <summary>
/// Private variable to hold an ASCOM Utilities object /// Private variable to hold an ASCOM Utilities object
/// </summary> /// </summary>
private readonly IUtil _utilities; private readonly IUtil _utilities;
private readonly IUtilExtra _utilitiesExtra; private readonly IUtilExtra _utilitiesExtra;
/// <summary> /// <summary>
@@ -73,7 +76,7 @@ namespace ASCOM.Meade.net
private int _digitsDe = 2; private int _digitsDe = 2;
private short _settleTime; 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.
@@ -121,7 +124,9 @@ namespace ASCOM.Meade.net
sb.AppendLine(); sb.AppendLine();
} }
public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base(sharedResourcesWrapper) public Telescope(IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities,
ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base(
sharedResourcesWrapper)
{ {
_clock = clock; _clock = clock;
_utilities = util; //Initialise util object _utilities = util; //Initialise util object
@@ -189,68 +194,68 @@ namespace ASCOM.Meade.net
{ {
//Read the screen //Read the screen
case "readdisplay": case "readdisplay":
var output = SharedResourcesWrapper.SendString(":ED#"); var output = SharedResourcesWrapper.SendString("ED");
return output; return output;
//top row of buttons //top row of buttons
case "enter": case "enter":
SharedResourcesWrapper.SendBlind(":EK13#"); SharedResourcesWrapper.SendBlind("EK13");
break; break;
case "mode": case "mode":
SharedResourcesWrapper.SendBlind(":EK9#"); SharedResourcesWrapper.SendBlind("EK9");
break; break;
case "longmode": case "longmode":
SharedResourcesWrapper.SendBlind(":EK11#"); SharedResourcesWrapper.SendBlind("EK11");
break; break;
case "goto": case "goto":
SharedResourcesWrapper.SendBlind(":EK24#"); SharedResourcesWrapper.SendBlind("EK24");
break; break;
case "0": //light and 0 case "0": //light and 0
SharedResourcesWrapper.SendBlind(":EK48#"); SharedResourcesWrapper.SendBlind("EK48");
break; break;
case "1": case "1":
SharedResourcesWrapper.SendBlind(":EK49#"); SharedResourcesWrapper.SendBlind("EK49");
break; break;
case "2": case "2":
SharedResourcesWrapper.SendBlind(":EK50#"); SharedResourcesWrapper.SendBlind("EK50");
break; break;
case "3": case "3":
SharedResourcesWrapper.SendBlind(":EK51#"); SharedResourcesWrapper.SendBlind("EK51");
break; break;
case "4": case "4":
SharedResourcesWrapper.SendBlind(":EK52#"); SharedResourcesWrapper.SendBlind("EK52");
break; break;
case "5": case "5":
SharedResourcesWrapper.SendBlind(":EK53#"); SharedResourcesWrapper.SendBlind("EK53");
break; break;
case "6": case "6":
SharedResourcesWrapper.SendBlind(":EK54#"); SharedResourcesWrapper.SendBlind("EK54");
break; break;
case "7": case "7":
SharedResourcesWrapper.SendBlind(":EK55#"); SharedResourcesWrapper.SendBlind("EK55");
break; break;
case "8": case "8":
SharedResourcesWrapper.SendBlind(":EK56#"); SharedResourcesWrapper.SendBlind("EK56");
break; break;
case "9": case "9":
SharedResourcesWrapper.SendBlind(":EK57#"); SharedResourcesWrapper.SendBlind("EK57");
break; break;
case "up": case "up":
SharedResourcesWrapper.SendBlind(":EK94#"); SharedResourcesWrapper.SendBlind("EK94");
break; break;
case "down": case "down":
SharedResourcesWrapper.SendBlind(":EK118#"); SharedResourcesWrapper.SendBlind("EK118");
break; break;
case "back": case "back":
SharedResourcesWrapper.SendBlind(":EK87#"); SharedResourcesWrapper.SendBlind("EK87");
break; break;
case "forward": case "forward":
SharedResourcesWrapper.SendBlind(":EK69#"); SharedResourcesWrapper.SendBlind("EK69");
break; break;
case "?": case "?":
SharedResourcesWrapper.SendBlind(":EK63#"); SharedResourcesWrapper.SendBlind("EK63");
break; break;
default: default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
@@ -280,6 +285,7 @@ namespace ASCOM.Meade.net
$"Site {actionParameters} not allowed, must be between 1 and 4"); $"Site {actionParameters} not allowed, must be between 1 and 4");
} }
break; break;
case "getname": case "getname":
switch (parames[1]) switch (parames[1])
@@ -314,6 +320,7 @@ namespace ASCOM.Meade.net
$"Site {actionParameters} not allowed, must be between 1 and 4"); $"Site {actionParameters} not allowed, must be between 1 and 4");
} }
break; break;
default: default:
throw new InvalidValueException( throw new InvalidValueException(
@@ -335,7 +342,7 @@ namespace ASCOM.Meade.net
CheckConnected("CommandBlind"); CheckConnected("CommandBlind");
// Call CommandString and return as soon as it finishes // Call CommandString and return as soon as it finishes
//this.CommandString(command, raw); //this.CommandString(command, raw);
SharedResourcesWrapper.SendBlind(command); SharedResourcesWrapper.SendBlind(command, raw);
// or // or
//throw new ASCOM.MethodNotImplementedException("CommandBlind"); //throw new ASCOM.MethodNotImplementedException("CommandBlind");
// DO NOT have both these sections! One or the other // DO NOT have both these sections! One or the other
@@ -345,9 +352,10 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("CommandBool"); CheckConnected("CommandBool");
//string ret = CommandString(command, raw); //string ret = CommandString(command, raw);
return SharedResourcesWrapper.SendBool(command, raw);
// TODO decode the return string and return true or false // TODO decode the return string and return true or false
// or // or
throw new MethodNotImplementedException("CommandBool"); //throw new MethodNotImplementedException("CommandBool");
// DO NOT have both these sections! One or the other // DO NOT have both these sections! One or the other
} }
@@ -395,7 +403,8 @@ namespace ASCOM.Meade.net
var connectionInfo = SharedResourcesWrapper.Connect("Serial", DriverId, Tl); var connectionInfo = SharedResourcesWrapper.Connect("Serial", DriverId, Tl);
try try
{ {
LogMessage("Connected Set", $"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); LogMessage("Connected Set",
$"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}");
_userNewerPulseGuiding = IsNewPulseGuidingSupported(); _userNewerPulseGuiding = IsNewPulseGuidingSupported();
_targetDeclination = InvalidParameter; _targetDeclination = InvalidParameter;
@@ -407,6 +416,7 @@ namespace ASCOM.Meade.net
if (connectionInfo.SameDevice == 1) if (connectionInfo.SameDevice == 1)
{ {
SharedResourcesWrapper.SetParked(false, null);
LogMessage("Connected Set", "Making first connection telescope adjustments"); LogMessage("Connected Set", "Making first connection telescope adjustments");
LogMessage("Connected Set", $"Site Longitude: {SiteLongitude}"); LogMessage("Connected Set", $"Site Longitude: {SiteLongitude}");
@@ -427,19 +437,23 @@ namespace ASCOM.Meade.net
{ {
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS)
{ {
LogMessage("Connected Set", $"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}"); LogMessage("Connected Set",
$"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}");
var displayText = Action("Handbox", "readdisplay"); var displayText = Action("Handbox", "readdisplay");
LogMessage("Connected Set", $"Current Handset display: {displayText}"); LogMessage("Connected Set", $"Current Handset display: {displayText}");
if (displayText.Contains("Daylight")) if (displayText.Contains("Daylight"))
{ {
LogMessage("Connected Set", $"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}"); LogMessage("Connected Set",
$"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}");
BypassHandboxEntryForAutostarII(); BypassHandboxEntryForAutostarII();
} }
else else
{ {
LogMessage("Connected Set", $"LX200GPS Sending current date and time: {SendDateTime}"); LogMessage("Connected Set",
$"LX200GPS Sending current date and time: {SendDateTime}");
SendCurrentDateTime("Connect"); SendCurrentDateTime("Connect");
LogMessage("Connected Set", $"LX200GPS Attempting manual bypass of prompts: {SendDateTime}"); LogMessage("Connected Set",
$"LX200GPS Attempting manual bypass of prompts: {SendDateTime}");
ApplySkipAutoStarPrompts("Connect"); ApplySkipAutoStarPrompts("Connect");
} }
@@ -454,11 +468,14 @@ namespace ASCOM.Meade.net
} }
else else
{ {
LogMessage("Connected Set", $"Skipping first connection telescope adjustments (current connections: {connectionInfo.SameDevice})"); LogMessage("Connected Set",
$"Skipping first connection telescope adjustments (current connections: {connectionInfo.SameDevice})");
CheckParked();
} }
var raAndDec = GetTelescopeRaAndDec(); var raAndDec = GetTelescopeRaAndDec();
LogMessage("Connected Set", $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); LogMessage("Connected Set",
$"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}");
} }
catch (Exception) catch (Exception)
{ {
@@ -570,6 +587,7 @@ namespace ASCOM.Meade.net
{ {
return false; return false;
} }
return true; return true;
} }
@@ -579,6 +597,7 @@ namespace ASCOM.Meade.net
{ {
return true; return true;
} }
return false; return false;
} }
@@ -605,7 +624,7 @@ namespace ASCOM.Meade.net
if (!IsConnected) if (!IsConnected)
return true; return true;
if(SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC)
{ {
_isTargetCoordinateInitRequired = false; _isTargetCoordinateInitRequired = false;
return _isTargetCoordinateInitRequired; return _isTargetCoordinateInitRequired;
@@ -628,9 +647,9 @@ namespace ASCOM.Meade.net
_isTargetCoordinateInitRequired = false; _isTargetCoordinateInitRequired = false;
return _isTargetCoordinateInitRequired; return _isTargetCoordinateInitRequired;
} }
//target coordinates are equal current coordinates //target coordinates are equal current coordinates
if((Math.Abs(RightAscension - rightTargetAscension ) <= eps) && if ((Math.Abs(RightAscension - rightTargetAscension) <= eps) &&
(Math.Abs(Declination - targetDeclination) <= eps)) (Math.Abs(Declination - targetDeclination) <= eps))
{ {
LogMessage("IsTargetCoordinateInitRequired", "0 diff -> false"); LogMessage("IsTargetCoordinateInitRequired", "0 diff -> false");
@@ -675,7 +694,7 @@ namespace ASCOM.Meade.net
SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.Lock(() =>
{ {
var result = SharedResourcesWrapper.SendString(":GZ#"); var result = SharedResourcesWrapper.SendString("GZ");
LogMessage("SetLongFormat", $"Get - Azimuth {result}"); LogMessage("SetLongFormat", $"Get - Azimuth {result}");
//:GZ# Get telescope azimuth //:GZ# Get telescope azimuth
//Returns: DDD*MM.T or DDD*MMSS# //Returns: DDD*MM.T or DDD*MMSS#
@@ -686,17 +705,17 @@ namespace ASCOM.Meade.net
if (IsLongFormat != setLongFormat) if (IsLongFormat != setLongFormat)
{ {
_utilities.WaitForMilliseconds(500); _utilities.WaitForMilliseconds(500);
SharedResourcesWrapper.SendBlind(":U#"); SharedResourcesWrapper.SendBlind("U");
//:U# Toggle between low/hi precision positions //:U# Toggle between low/hi precision positions
//Low - RA displays and messages HH:MM.T sDD*MM //Low - RA displays and messages HH:MM.T sDD*MM
//High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS
// Returns Nothing // Returns Nothing
result = SharedResourcesWrapper.SendString(":GZ#"); result = SharedResourcesWrapper.SendString("GZ");
IsLongFormat = result.Length > 6; IsLongFormat = result.Length > 6;
LogMessage("SetLongFormat", $"Get - Azimuth {result}"); LogMessage("SetLongFormat", $"Get - Azimuth {result}");
if (IsLongFormat == setLongFormat) if (IsLongFormat == setLongFormat)
LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} ");
} }
else else
{ {
LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} ");
@@ -709,7 +728,7 @@ namespace ASCOM.Meade.net
private bool TogglePrecision() private bool TogglePrecision()
{ {
LogMessage("TogglePrecision", "Toggling slewing precision"); LogMessage("TogglePrecision", "Toggling slewing precision");
var result = SharedResourcesWrapper.SendChar(":P#"); var result = SharedResourcesWrapper.SendChar("P");
//:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target.
//Returns: <string> //Returns: <string>
//“HIGH PRECISION” Current setting after this command. //“HIGH PRECISION” Current setting after this command.
@@ -729,9 +748,6 @@ namespace ASCOM.Meade.net
SharedResourcesWrapper.ReadCharacters(throwAwayCharacters); SharedResourcesWrapper.ReadCharacters(throwAwayCharacters);
//Make sure that the buffers are cleared out.
SharedResourcesWrapper.SendBlind("#");
return highPrecision; return highPrecision;
} }
@@ -749,7 +765,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnectedAndValidateSite(site, "SelectSite"); CheckConnectedAndValidateSite(site, "SelectSite");
SharedResourcesWrapper.SendBlind($":W{site}#"); SharedResourcesWrapper.SendBlind($"W{site}");
//:W<n># //:W<n>#
//Set current site to<n>, an ASCII digit in the range 1..4 //Set current site to<n>, an ASCII digit in the range 1..4
//Returns: Nothing //Returns: Nothing
@@ -775,7 +791,7 @@ namespace ASCOM.Meade.net
switch (site) switch (site)
{ {
case 1: case 1:
command = $":SM{sitename}#"; command = $"SM{sitename}";
//:SM<string># //:SM<string>#
//Set site 1s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. //Set site 1s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns: // Returns:
@@ -783,7 +799,7 @@ namespace ASCOM.Meade.net
//1 - Valid //1 - Valid
break; break;
case 2: case 2:
command = $":SN{sitename}#"; command = $"SN{sitename}";
//:SN<string># //:SN<string>#
//Set site 2s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. //Set site 2s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns: // Returns:
@@ -791,7 +807,7 @@ namespace ASCOM.Meade.net
//1 - Valid //1 - Valid
break; break;
case 3: case 3:
command = $":SO{sitename}#"; command = $"SO{sitename}";
//:SO<string># //:SO<string>#
//Set site 3s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. //Set site 3s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns: // Returns:
@@ -799,7 +815,7 @@ namespace ASCOM.Meade.net
//1 - Valid //1 - Valid
break; break;
case 4: case 4:
command = $":SP{sitename}#"; command = $"SP{sitename}";
//:SP<string># //:SP<string>#
//Set site 4s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. //Set site 4s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns: // Returns:
@@ -807,7 +823,8 @@ namespace ASCOM.Meade.net
//1 - Valid //1 - Valid
break; break;
default: default:
throw new ArgumentOutOfRangeException(nameof(site), site, Resources.Telescope_GetSiteName_Site_out_of_range); throw new ArgumentOutOfRangeException(nameof(site), site,
Resources.Telescope_GetSiteName_Site_out_of_range);
} }
var result = SharedResourcesWrapper.SendChar(command); var result = SharedResourcesWrapper.SendChar(command);
@@ -824,27 +841,28 @@ namespace ASCOM.Meade.net
switch (site) switch (site)
{ {
case 1: case 1:
return SharedResourcesWrapper.SendString(":GM#"); return SharedResourcesWrapper.SendString("GM");
//:GM# Get Site 1 Name //:GM# Get Site 1 Name
//Returns: <string># //Returns: <string>#
//A # terminated string with the name of the requested site. //A # terminated string with the name of the requested site.
case 2: case 2:
return SharedResourcesWrapper.SendString(":GN#"); return SharedResourcesWrapper.SendString("GN");
//:GN# Get Site 2 Name //:GN# Get Site 2 Name
//Returns: <string># //Returns: <string>#
//A # terminated string with the name of the requested site. //A # terminated string with the name of the requested site.
case 3: case 3:
return SharedResourcesWrapper.SendString(":GO#"); return SharedResourcesWrapper.SendString("GO");
//:GO# Get Site 3 Name //:GO# Get Site 3 Name
//Returns: <string># //Returns: <string>#
//A # terminated string with the name of the requested site. //A # terminated string with the name of the requested site.
case 4: case 4:
return SharedResourcesWrapper.SendString(":GP#"); return SharedResourcesWrapper.SendString("GP");
//:GP# Get Site 4 Name //:GP# Get Site 4 Name
//Returns: <string># //Returns: <string>#
//A # terminated string with the name of the requested site. //A # terminated string with the name of the requested site.
default: default:
throw new ArgumentOutOfRangeException(nameof(site), site, Resources.Telescope_GetSiteName_Site_out_of_range); throw new ArgumentOutOfRangeException(nameof(site), site,
Resources.Telescope_GetSiteName_Site_out_of_range);
} }
} }
@@ -864,11 +882,11 @@ namespace ASCOM.Meade.net
{ {
//string name = "Short driver name - please customise"; //string name = "Short driver name - please customise";
//var telescopeProduceName = _sharedResourcesWrapper.SendString(":GVP#"); //var telescopeProduceName = _sharedResourcesWrapper.SendString("GVP");
////:GVP# Get Telescope Product Name ////:GVP# Get Telescope Product Name
////Returns: <string># ////Returns: <string>#
//var firmwareVersion = _sharedResourcesWrapper.SendString(":GVN#"); //var firmwareVersion = _sharedResourcesWrapper.SendString("GVN");
////:GVN# Get Telescope Firmware Number ////:GVN# Get Telescope Firmware Number
////Returns: dd.d# ////Returns: dd.d#
@@ -882,14 +900,14 @@ namespace ASCOM.Meade.net
#endregion #endregion
#region ITelescope Implementation #region ITelescope Implementation
public void AbortSlew() public void AbortSlew()
{ {
CheckConnected("AbortSlew"); CheckConnected("AbortSlew");
CheckParked(); CheckParked();
LogMessage("AbortSlew", "Aborting slew"); LogMessage("AbortSlew", "Aborting slew");
SharedResourcesWrapper.SendBlind(":Q#"); SharedResourcesWrapper.SendBlind("Q");
//:Q# Halt all current slewing //:Q# Halt all current slewing
//Returns:Nothing //Returns:Nothing
@@ -914,7 +932,7 @@ namespace ASCOM.Meade.net
const char ack = (char) 6; const char ack = (char) 6;
var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString()); var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString(), true);
//ACK <0x06> Query of alignment mounting mode. //ACK <0x06> Query of alignment mounting mode.
//Returns: //Returns:
//A If scope in AltAz Mode //A If scope in AltAz Mode
@@ -925,13 +943,13 @@ namespace ASCOM.Meade.net
//todo implement GW Command - Supported in Autostar 43Eg and above //todo implement GW Command - Supported in Autostar 43Eg and above
//if FirmwareIsGreaterThan(TelescopeList.Autostar497_43EG) //if FirmwareIsGreaterThan(TelescopeList.Autostar497_43EG)
//{ //{
//var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); //var alignmentString = SerialPort.CommandTerminated(":GW#", "#");
//:GW# Get Scope Alignment Status //:GW# Get Scope Alignment Status
//Returns: <mount><tracking><alignment># //Returns: <mount><tracking><alignment>#
// where: // where:
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial //mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
//tracking: T - tracking, N - not tracking //tracking: T - tracking, N - not tracking
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned. //alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned.
//} //}
AlignmentModes alignmentMode; AlignmentModes alignmentMode;
@@ -960,18 +978,18 @@ namespace ASCOM.Meade.net
//todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly //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 (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg))
throw new PropertyNotImplementedException("AlignmentMode",true ); throw new PropertyNotImplementedException("AlignmentMode", true);
switch (value) switch (value)
{ {
case AlignmentModes.algAltAz: case AlignmentModes.algAltAz:
SharedResourcesWrapper.SendBlind(":AA#"); SharedResourcesWrapper.SendBlind("AA");
//:AA# Sets telescope the AltAz alignment mode //:AA# Sets telescope the AltAz alignment mode
//Returns: nothing //Returns: nothing
break; break;
case AlignmentModes.algPolar: case AlignmentModes.algPolar:
case AlignmentModes.algGermanPolar: case AlignmentModes.algGermanPolar:
SharedResourcesWrapper.SendBlind(":AP#"); SharedResourcesWrapper.SendBlind("AP");
//:AP# Sets telescope to Polar alignment mode //:AP# Sets telescope to Polar alignment mode
//Returns: nothing //Returns: nothing
break; break;
@@ -989,23 +1007,36 @@ namespace ASCOM.Meade.net
get get
{ {
CheckConnected("Altitude Get"); CheckConnected("Altitude Get");
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS)
{
try
{
CheckParked();
//firmware bug in 44Eg, :GA# is returning the dec, not the altitude!
var result = SharedResourcesWrapper.SendString("GA");
//:GA# Get Telescope Altitude
//Returns: sDD* MM# or sDD*MMSS#
//The current scope altitude. The returned format depending on the current precision setting.
var alt = _utilities.DMSToDegrees(result);
LogMessage("Altitude", $"{alt}");
return alt;
}
catch (ParkedException)
{
var parkedPosition = SharedResourcesWrapper.ParkedPosition;
if (parkedPosition != null)
return parkedPosition.Altitude;
throw;
}
}
var altAz = CalcAltAzFromTelescopeEqData(); var altAz = CalcAltAzFromTelescopeEqData();
LogMessage("Altitude", $"{altAz.Altitude}"); LogMessage("Altitude", $"{altAz.Altitude}");
return altAz.Altitude; return altAz.Altitude;
//firmware bug in 44Eg, :GA# is returning the dec, not the altitude!
//var result = _sharedResourcesWrapper.SendString(":GA#");
////:GA# Get Telescope Altitude
////Returns: sDD* MM# or sDD*MMSS#
////The current scope altitude. The returned format depending on the current precision setting.
//var alt = utilities.DMSToDegrees(result);
//LogMessage("Altitude", $"{alt}");
//return alt;
//LogMessage("Altitude Get", "Not implemented");
//throw new ASCOM.PropertyNotImplementedException("Altitude", false);
} }
} }
@@ -1019,9 +1050,11 @@ namespace ASCOM.Meade.net
EquatorialCoordinates = GetTelescopeRaAndDec() EquatorialCoordinates = GetTelescopeRaAndDec()
}); });
double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude, double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime,
altitudeData.SiteLongitude,
altitudeData.EquatorialCoordinates.RightAscension); altitudeData.EquatorialCoordinates.RightAscension);
var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.EquatorialCoordinates); var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude,
altitudeData.EquatorialCoordinates);
return altAz; return altAz;
} }
@@ -1060,17 +1093,15 @@ namespace ASCOM.Meade.net
return false; return false;
} }
} }
private bool _atPark;
public bool AtPark public bool AtPark
{ {
get get
{ {
LogMessage("AtPark", "Get - " + _atPark); var atPark = SharedResourcesWrapper.IsParked;
return _atPark; LogMessage("AtPark", "Get - " + atPark);
return atPark;
} }
private set => _atPark = value;
} }
public IAxisRates AxisRates(TelescopeAxes axis) public IAxisRates AxisRates(TelescopeAxes axis)
@@ -1085,15 +1116,31 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("Azimuth Get"); CheckConnected("Azimuth Get");
//var result = _sharedResourcesWrapper.SendString(":GZ#"); if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS)
//:GZ# Get telescope azimuth {
//Returns: DDD*MM#T or DDD*MMSS# try
//The current telescope Azimuth depending on the selected precision. {
CheckParked();
//double az = utilities.DMSToDegrees(result); var result = SharedResourcesWrapper.SendString("GZ");
//:GZ# Get telescope azimuth
//Returns: DDD*MM#T or DDD*MMSS#
//The current telescope Azimuth depending on the selected precision.
//LogMessage("Azimuth Get", $"{az}"); double az = _utilities.DMSToDegrees(result);
//return az;
LogMessage("Azimuth Get", $"{az}");
return az;
}
catch (ParkedException)
{
var parkedPosition = SharedResourcesWrapper.ParkedPosition;
if (parkedPosition != null)
return parkedPosition.Azimuth;
throw;
}
}
var altAz = CalcAltAzFromTelescopeEqData(); var altAz = CalcAltAzFromTelescopeEqData();
LogMessage("Azimuth Get", $"{altAz.Azimuth}"); LogMessage("Azimuth Get", $"{altAz.Azimuth}");
@@ -1275,7 +1322,7 @@ namespace ASCOM.Meade.net
{ {
CheckParked(); CheckParked();
var result = SharedResourcesWrapper.SendString(":GD#"); var result = SharedResourcesWrapper.SendString("GD");
//:GD# Get Telescope Declination. //:GD# Get Telescope Declination.
//Returns: sDD*MM# or sDD*MMSS# //Returns: sDD*MM# or sDD*MMSS#
//Depending upon the current precision setting for the telescope. //Depending upon the current precision setting for the telescope.
@@ -1288,16 +1335,11 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException) catch (ParkedException)
{ {
switch (ParkedBehaviour) var parkedPosition = SharedResourcesWrapper.ParkedPosition;
{ if (parkedPosition != null)
case ParkedBehaviour.LastGoodPosition: return parkedPosition.Declination;
return _lastGoodDeclination;
case ParkedBehaviour.ReportCoordinates: throw;
var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz);
return raDec.Declination;
default:
throw;
}
} }
} }
} }
@@ -1378,7 +1420,7 @@ namespace ASCOM.Meade.net
} }
LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)"); LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)");
SharedResourcesWrapper.SendBlind($":Rg{value:00.0}#"); SharedResourcesWrapper.SendBlind($"Rg{value:00.0}");
//:RgSS.S# //:RgSS.S#
//Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking
//Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed
@@ -1460,22 +1502,22 @@ namespace ASCOM.Meade.net
//do nothing, it's ok this time as we're halting the slew. //do nothing, it's ok this time as we're halting the slew.
break; break;
case 1: case 1:
SharedResourcesWrapper.SendBlind(":RG#"); SharedResourcesWrapper.SendBlind("RG");
//:RG# Set Slew rate to Guiding Rate (slowest) //:RG# Set Slew rate to Guiding Rate (slowest)
//Returns: Nothing //Returns: Nothing
break; break;
case 2: case 2:
SharedResourcesWrapper.SendBlind(":RC#"); SharedResourcesWrapper.SendBlind("RC");
//:RC# Set Slew rate to Centering rate (2nd slowest) //:RC# Set Slew rate to Centering rate (2nd slowest)
//Returns: Nothing //Returns: Nothing
break; break;
case 3: case 3:
SharedResourcesWrapper.SendBlind(":RM#"); SharedResourcesWrapper.SendBlind("RM");
//:RM# Set Slew rate to Find Rate (2nd Fastest) //:RM# Set Slew rate to Find Rate (2nd Fastest)
//Returns: Nothing //Returns: Nothing
break; break;
case 4: case 4:
SharedResourcesWrapper.SendBlind(":RS#"); SharedResourcesWrapper.SendBlind("RS");
//:RS# Set Slew rate to max (fastest) //:RS# Set Slew rate to max (fastest)
//Returns: Nothing //Returns: Nothing
break; break;
@@ -1495,21 +1537,21 @@ namespace ASCOM.Meade.net
} }
_movingPrimary = false; _movingPrimary = false;
SharedResourcesWrapper.SendBlind(":Qe#"); SharedResourcesWrapper.SendBlind("Qe");
//:Qe# Halt eastward Slews //:Qe# Halt eastward Slews
//Returns: Nothing //Returns: Nothing
SharedResourcesWrapper.SendBlind(":Qw#"); SharedResourcesWrapper.SendBlind("Qw");
//:Qw# Halt westward Slews //:Qw# Halt westward Slews
//Returns: Nothing //Returns: Nothing
break; break;
case ComparisonResult.Greater: case ComparisonResult.Greater:
SharedResourcesWrapper.SendBlind(":Me#"); SharedResourcesWrapper.SendBlind("Me");
//:Me# Move Telescope East at current slew rate //:Me# Move Telescope East at current slew rate
//Returns: Nothing //Returns: Nothing
_movingPrimary = true; _movingPrimary = true;
break; break;
case ComparisonResult.Lower: case ComparisonResult.Lower:
SharedResourcesWrapper.SendBlind(":Mw#"); SharedResourcesWrapper.SendBlind("Mw");
//:Mw# Move Telescope West at current slew rate //:Mw# Move Telescope West at current slew rate
//Returns: Nothing //Returns: Nothing
_movingPrimary = true; _movingPrimary = true;
@@ -1525,21 +1567,21 @@ namespace ASCOM.Meade.net
SetSlewingMinEndTime(); SetSlewingMinEndTime();
} }
_movingSecondary = false; _movingSecondary = false;
SharedResourcesWrapper.SendBlind(":Qn#"); SharedResourcesWrapper.SendBlind("Qn");
//:Qn# Halt northward Slews //:Qn# Halt northward Slews
//Returns: Nothing //Returns: Nothing
SharedResourcesWrapper.SendBlind(":Qs#"); SharedResourcesWrapper.SendBlind("Qs");
//:Qs# Halt southward Slews //:Qs# Halt southward Slews
//Returns: Nothing //Returns: Nothing
break; break;
case ComparisonResult.Greater: case ComparisonResult.Greater:
SharedResourcesWrapper.SendBlind(":Mn#"); SharedResourcesWrapper.SendBlind("Mn");
//:Mn# Move Telescope North at current slew rate //:Mn# Move Telescope North at current slew rate
//Returns: Nothing //Returns: Nothing
_movingSecondary = true; _movingSecondary = true;
break; break;
case ComparisonResult.Lower: case ComparisonResult.Lower:
SharedResourcesWrapper.SendBlind(":Ms#"); SharedResourcesWrapper.SendBlind("Ms");
//:Ms# Move Telescope South at current slew rate //:Ms# Move Telescope South at current slew rate
//Returns: Nothing //Returns: Nothing
_movingSecondary = true; _movingSecondary = true;
@@ -1559,9 +1601,40 @@ namespace ASCOM.Meade.net
if (AtPark) if (AtPark)
return; return;
ParkedPosition parkedPosition;
switch (ParkedBehaviour)
{
case ParkedBehaviour.LastGoodPosition:
parkedPosition = new ParkedPosition
{
Altitude = Altitude,
Azimuth = Azimuth,
RightAscension = RightAscension,
Declination = Declination
};
break;
case ParkedBehaviour.ReportCoordinates:
var utcDateTime = UTCDate;
var latitude = SiteLatitude;
var longitude = SiteLongitude;
var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, ParkedAltAz);
parkedPosition = new ParkedPosition
{
Altitude = ParkedAltAz.Altitude,
Azimuth = ParkedAltAz.Azimuth,
RightAscension = raDec.RightAscension,
Declination = raDec.Declination
};
break;
default:
parkedPosition = null;
break;
}
//Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued.
AtPark = true; SharedResourcesWrapper.SetParked(true, parkedPosition);
SharedResourcesWrapper.SendBlind(":hP#"); SharedResourcesWrapper.SendBlind("hP");
//:hP# Autostar, Autostar II and LX 16”Slew to Park Position //:hP# Autostar, Autostar II and LX 16”Slew to Park Position
//Returns: Nothing //Returns: Nothing
} }
@@ -1611,7 +1684,7 @@ namespace ASCOM.Meade.net
} }
LogMessage("PulseGuide", "Using new pulse guiding technique"); LogMessage("PulseGuide", "Using new pulse guiding technique");
SharedResourcesWrapper.SendBlind($":Mg{d}{duration:0000}#"); SharedResourcesWrapper.SendBlind($"Mg{d}{duration:0000}");
//:MgnDDDD# //:MgnDDDD#
//:MgsDDDD# //:MgsDDDD#
//:MgeDDDD# //:MgeDDDD#
@@ -1696,7 +1769,7 @@ namespace ASCOM.Meade.net
{ {
CheckParked(); CheckParked();
var result = SharedResourcesWrapper.SendString(":GR#"); var result = SharedResourcesWrapper.SendString("GR");
//:GR# Get Telescope RA //:GR# Get Telescope RA
//Returns: HH:MM.T# or HH:MM:SS# //Returns: HH:MM.T# or HH:MM:SS#
//Depending which precision is set for the telescope //Depending which precision is set for the telescope
@@ -1709,16 +1782,11 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException) catch (ParkedException)
{ {
switch (ParkedBehaviour) var parkedPosition = SharedResourcesWrapper.ParkedPosition;
{ if (parkedPosition != null)
case ParkedBehaviour.LastGoodPosition: return parkedPosition.RightAscension;
return _lastGoodRightAsension;
case ParkedBehaviour.ReportCoordinates: throw;
var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz);
return raDec.RightAscension;
default:
throw;
}
} }
} }
@@ -1824,7 +1892,7 @@ namespace ASCOM.Meade.net
{ {
CheckParked(); CheckParked();
var latitude = SharedResourcesWrapper.SendString(":Gt#"); var latitude = SharedResourcesWrapper.SendString("Gt");
//:Gt# Get Current Site Latitude //:Gt# Get Current Site Latitude
//Returns: sDD* MM# //Returns: sDD* MM#
//The latitude of the current site. Positive inplies North latitude. //The latitude of the current site. Positive inplies North latitude.
@@ -1865,7 +1933,7 @@ namespace ASCOM.Meade.net
var absValue = Math.Abs(value); var absValue = Math.Abs(value);
int d = Convert.ToInt32(Math.Floor(absValue)); int d = Convert.ToInt32(Math.Floor(absValue));
int m = Convert.ToInt32(60 * (absValue - d)); int m = Convert.ToInt32(60 * (absValue - d));
var commandString = $":St{sign}{d:00}*{m:00}#"; var commandString = $"St{sign}{d:00}*{m:00}";
var result = SharedResourcesWrapper.SendChar(commandString); var result = SharedResourcesWrapper.SendChar(commandString);
//:StsDD*MM# //:StsDD*MM#
@@ -1891,7 +1959,7 @@ namespace ASCOM.Meade.net
{ {
CheckParked(); CheckParked();
var longitude = SharedResourcesWrapper.SendString(":Gg#"); var longitude = SharedResourcesWrapper.SendString("Gg");
//:Gg# Get Current Site Longitude //:Gg# Get Current Site Longitude
//Returns: sDDD*MM# //Returns: sDDD*MM#
//The current site Longitude. East Longitudes are expressed as negative //The current site Longitude. East Longitudes are expressed as negative
@@ -1934,7 +2002,7 @@ namespace ASCOM.Meade.net
int d = Convert.ToInt32(Math.Floor(newLongitude)); int d = Convert.ToInt32(Math.Floor(newLongitude));
int m = Convert.ToInt32(60 * (newLongitude - d)); int m = Convert.ToInt32(60 * (newLongitude - d));
var commandstring = $":Sg{d:000}*{m:00}#"; var commandstring = $"Sg{d:000}*{m:00}";
var result = SharedResourcesWrapper.SendChar(commandstring); var result = SharedResourcesWrapper.SendChar(commandstring);
//:SgDDD*MM# //:SgDDD*MM#
@@ -2030,7 +2098,7 @@ namespace ASCOM.Meade.net
switch (polar) switch (polar)
{ {
case true: case true:
var response = SharedResourcesWrapper.SendChar(":MS#"); var response = SharedResourcesWrapper.SendChar("MS");
//:MS# Slew to Target Object //:MS# Slew to Target Object
//Returns: //Returns:
//0 Slew is Possible //0 Slew is Possible
@@ -2067,7 +2135,7 @@ namespace ASCOM.Meade.net
break; break;
case false: case false:
var maResponse = SharedResourcesWrapper.SendChar(":MA#"); var maResponse = SharedResourcesWrapper.SendChar("MA");
//:MA# Autostar, LX 16”, Autostar II Slew to target Alt and Az //:MA# Autostar, LX 16”, Autostar II Slew to target Alt and Az
//Returns: //Returns:
//0 - No fault //0 - No fault
@@ -2204,7 +2272,7 @@ namespace ASCOM.Meade.net
string result; string result;
try try
{ {
result = SharedResourcesWrapper.SendString(":D#"); result = SharedResourcesWrapper.SendString("D");
} }
catch (TimeoutException) catch (TimeoutException)
{ {
@@ -2289,7 +2357,7 @@ namespace ASCOM.Meade.net
CheckConnected("SyncToTarget"); CheckConnected("SyncToTarget");
CheckParked(); CheckParked();
var result = SharedResourcesWrapper.SendString(":CM#"); var result = SharedResourcesWrapper.SendString("CM");
//:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates.
//Returns: //Returns:
//LX200's - a "#" terminated string with the name of the object that was synced. //LX200's - a "#" terminated string with the name of the object that was synced.
@@ -2355,7 +2423,7 @@ namespace ASCOM.Meade.net
var s = value < 0 ? string.Empty : "+"; var s = value < 0 ? string.Empty : "+";
var command = $":Sd{s}{dms}#"; var command = $"Sd{s}{dms}";
LogMessage("TargetDeclination Set", $"{command}"); LogMessage("TargetDeclination Set", $"{command}");
var result = SharedResourcesWrapper.SendChar(command); var result = SharedResourcesWrapper.SendChar(command);
@@ -2409,7 +2477,7 @@ namespace ASCOM.Meade.net
_utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) :
_utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.');
var command = $":Sr{hms}#"; var command = $"Sr{hms}";
LogMessage("TargetRightAscension Set", $"{command}"); LogMessage("TargetRightAscension Set", $"{command}");
var response = SharedResourcesWrapper.SendChar(command); var response = SharedResourcesWrapper.SendChar(command);
//:SrHH:MM.T# //:SrHH:MM.T#
@@ -2471,12 +2539,12 @@ namespace ASCOM.Meade.net
switch (value) switch (value)
{ {
case DriveRates.driveSidereal: case DriveRates.driveSidereal:
SharedResourcesWrapper.SendBlind(":TQ#"); SharedResourcesWrapper.SendBlind("TQ");
//:TQ# Selects sidereal tracking rate //:TQ# Selects sidereal tracking rate
//Returns: Nothing //Returns: Nothing
break; break;
case DriveRates.driveLunar: case DriveRates.driveLunar:
SharedResourcesWrapper.SendBlind(":TL#"); SharedResourcesWrapper.SendBlind("TL");
//:TL# Set Lunar Tracking Rage //:TL# Set Lunar Tracking Rage
//Returns: Nothing //Returns: Nothing
break; break;
@@ -2513,7 +2581,7 @@ namespace ASCOM.Meade.net
private TimeSpan GetUtcCorrection() private TimeSpan GetUtcCorrection()
{ {
string utcOffSet = SharedResourcesWrapper.SendString(":GG#"); string utcOffSet = SharedResourcesWrapper.SendString("GG");
//:GG# Get UTC offset time //:GG# Get UTC offset time
//Returns: sHH# or sHH.H# //Returns: sHH# or sHH.H#
//The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the
@@ -2544,11 +2612,11 @@ namespace ASCOM.Meade.net
{ {
var tdd = new TelescopeDateDetails var tdd = new TelescopeDateDetails
{ {
TelescopeDate = SharedResourcesWrapper.SendString(":GC#"), TelescopeDate = SharedResourcesWrapper.SendString("GC"),
//:GC# Get current date. //:GC# Get current date.
//Returns: MM/DD/YY# //Returns: MM/DD/YY#
//The current local calendar date for the telescope. //The current local calendar date for the telescope.
TelescopeTime = SharedResourcesWrapper.SendString(":GL#"), TelescopeTime = SharedResourcesWrapper.SendString("GL"),
//:GL# Get Local Time in 24 hour format //:GL# Get Local Time in 24 hour format
//Returns: HH:MM:SS# //Returns: HH:MM:SS#
//The Local Time in 24 - hour Format //The Local Time in 24 - hour Format
@@ -2597,7 +2665,7 @@ namespace ASCOM.Meade.net
var utcCorrection = GetUtcCorrection(); var utcCorrection = GetUtcCorrection();
var localDateTime = value - utcCorrection; var localDateTime = value - utcCorrection;
string localStingCommand = $":SL{localDateTime:HH:mm:ss}#"; string localStingCommand = $"SL{localDateTime:HH:mm:ss}";
var timeResult = SharedResourcesWrapper.SendChar(localStingCommand); var timeResult = SharedResourcesWrapper.SendChar(localStingCommand);
//:SLHH:MM:SS# //:SLHH:MM:SS#
//Set the local Time //Set the local Time
@@ -2609,7 +2677,7 @@ namespace ASCOM.Meade.net
throw new InvalidOperationException("Failed to set local time"); throw new InvalidOperationException("Failed to set local time");
} }
string localDateCommand = $":SC{localDateTime:MM/dd/yy}#"; string localDateCommand = $"SC{localDateTime:MM/dd/yy}";
var dateResult = SharedResourcesWrapper.SendChar(localDateCommand); var dateResult = SharedResourcesWrapper.SendChar(localDateCommand);
//:SCMM/DD/YY# //:SCMM/DD/YY#
//Change Handbox Date to MM/DD/YY //Change Handbox Date to MM/DD/YY
@@ -2640,13 +2708,13 @@ namespace ASCOM.Meade.net
if (!AtPark) if (!AtPark)
return; return;
SharedResourcesWrapper.SendChar(":I#"); SharedResourcesWrapper.SendChar("I");
//:I# LX200 GPS Only - Causes the telescope to cease current operations and restart at its power on initialization. //:I# LX200 GPS Only - Causes the telescope to cease current operations and restart at its power on initialization.
//Returns: X once the handset restart has completed //Returns: X once the handset restart has completed
BypassHandboxEntryForAutostarII(); BypassHandboxEntryForAutostarII();
AtPark = false; SharedResourcesWrapper.SetParked(false, null);
} }
private bool BypassHandboxEntryForAutostarII() private bool BypassHandboxEntryForAutostarII()
@@ -2655,7 +2723,7 @@ namespace ASCOM.Meade.net
var localDateTime = _clock.UtcNow - utcCorrection; var localDateTime = _clock.UtcNow - utcCorrection;
//localDateTime: HH: mm: ss //localDateTime: HH: mm: ss
var result = SharedResourcesWrapper.SendChar($":hI{localDateTime:yyMMddHHmmss}#"); var result = SharedResourcesWrapper.SendChar($"hI{localDateTime:yyMMddHHmmss}");
//:hIYYMMDDHHMMSS# //:hIYYMMDDHHMMSS#
//Bypass handbox entry of daylight savings, date and time.Use the values supplied in this command.This feature is //Bypass handbox entry of daylight savings, date and time.Use the values supplied in this command.This feature is
//intended to allow use of the Autostar II from permanent installations where GPS reception is not possible, such as within //intended to allow use of the Autostar II from permanent installations where GPS reception is not possible, such as within
@@ -2774,4 +2842,4 @@ namespace ASCOM.Meade.net
} }
#endregion #endregion
} }
} }
+13 -12
View File
@@ -32,35 +32,36 @@ namespace Meade.net.UnitTests
Assert.That(SharedResources.SharedSerial,Is.EqualTo(_serialMock.Object)); Assert.That(SharedResources.SharedSerial,Is.EqualTo(_serialMock.Object));
} }
[Test] [TestCase(true, "Test")]
public void SendBlind_WhenCalled_Then_ClearsBuffersAndSendsMessage() [TestCase(false, "#:Test#")]
public void SendBlind_WhenCalled_Then_ClearsBuffersAndSendsMessage(bool raw, string expectedMessage)
{ {
var expectedMessage = "Test"; var sendMessage = "Test";
SharedResources.SendBlind(sendMessage, raw);
SharedResources.SendBlind(expectedMessage);
_serialMock.Verify(x=> x.ClearBuffers(), Times.Once); _serialMock.Verify(x=> x.ClearBuffers(), Times.Once);
_serialMock.Verify(x=>x.Transmit(expectedMessage), Times.Once); _serialMock.Verify(x=>x.Transmit(expectedMessage), Times.Once);
} }
[Test] [TestCase(false, "#:Test#")]
public void SendChar_WhenCalled_ThenSendsMessageAndReadsExpectedNumberOfCharacters() [TestCase(true, "Test")]
public void SendChar_WhenCalled_ThenSendsMessageAndReadsExpectedNumberOfCharacters(bool raw, string expectedCommand)
{ {
var expectedMessage = "Test"; var command = "Test";
var expectedResult = "A"; var expectedResult = "A";
_serialMock.Setup(x => x.ReceiveCounted(1)).Returns(expectedResult); _serialMock.Setup(x => x.ReceiveCounted(1)).Returns(expectedResult);
var result = SharedResources.SendChar(expectedMessage); var result = SharedResources.SendChar(command, raw);
_serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.ClearBuffers(), Times.Once);
_serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once); _serialMock.Verify(x => x.Transmit(expectedCommand), Times.Once);
_serialMock.Verify(x => x.ReceiveCounted(1), Times.Once); _serialMock.Verify(x => x.ReceiveCounted(1), Times.Once);
Assert.That(result, Is.EqualTo(expectedResult)); Assert.That(result, Is.EqualTo(expectedResult));
} }
[TestCase(false, "Test")] [TestCase(true, "Test")]
[TestCase(true, "#Test")] [TestCase(false, "#:Test#")]
public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound(bool includePrefix, string expectedMessage) public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound(bool includePrefix, string expectedMessage)
{ {
var transmitMessage = "Test"; var transmitMessage = "Test";
+7 -6
View File
@@ -104,7 +104,7 @@ namespace ASCOM.Meade.net
CheckConnected("CommandBlind"); CheckConnected("CommandBlind");
// Call CommandString and return as soon as it finishes // Call CommandString and return as soon as it finishes
//this.CommandString(command, raw); //this.CommandString(command, raw);
SharedResourcesWrapper.SendBlind(command); SharedResourcesWrapper.SendBlind(command, raw);
// or // or
//throw new ASCOM.MethodNotImplementedException("CommandBlind"); //throw new ASCOM.MethodNotImplementedException("CommandBlind");
// DO NOT have both these sections! One or the other // DO NOT have both these sections! One or the other
@@ -114,9 +114,10 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("CommandBool"); CheckConnected("CommandBool");
//string ret = CommandString(command, raw); //string ret = CommandString(command, raw);
return SharedResourcesWrapper.SendBool(command, raw);
// decode the return string and return true or false // decode the return string and return true or false
// or // or
throw new MethodNotImplementedException("CommandBool"); //throw new MethodNotImplementedException("CommandBool");
// DO NOT have both these sections! One or the other // DO NOT have both these sections! One or the other
} }
@@ -126,7 +127,7 @@ namespace ASCOM.Meade.net
// it's a good idea to put all the low level communication with the device here, // it's a good idea to put all the low level communication with the device here,
// then all communication calls this function // then all communication calls this function
// you need something to ensure that only one command is in progress at a time // you need something to ensure that only one command is in progress at a time
return SharedResourcesWrapper.SendString(command); return SharedResourcesWrapper.SendString(command, raw);
//throw new ASCOM.MethodNotImplementedException("CommandString"); //throw new ASCOM.MethodNotImplementedException("CommandString");
} }
@@ -225,7 +226,7 @@ namespace ASCOM.Meade.net
//todo fix this issue: A single halt command is sometimes missed by the #909 apm, so let's do it a few times to be safe. //todo fix this issue: A single halt command is sometimes missed by the #909 apm, so let's do it a few times to be safe.
SharedResourcesWrapper.SendBlind(":FQ#"); SharedResourcesWrapper.SendBlind("FQ");
//:FQ# Halt Focuser Motion //:FQ# Halt Focuser Motion
//Returns: Nothing //Returns: Nothing
} }
@@ -329,7 +330,7 @@ namespace ASCOM.Meade.net
private void MoveFocuser(bool directionOut, int steps) private void MoveFocuser(bool directionOut, int steps)
{ {
//_sharedResourcesWrapper.SendBlind(":FF#"); //_sharedResourcesWrapper.SendBlind("FF");
//:FF# Set Focus speed to fastest setting //:FF# Set Focus speed to fastest setting
//Returns: Nothing //Returns: Nothing
@@ -350,7 +351,7 @@ namespace ASCOM.Meade.net
private void PerformFocuserMove(bool directionOut) private void PerformFocuserMove(bool directionOut)
{ {
SharedResourcesWrapper.SendBlind(directionOut ? ":F+#" : ":F-#"); SharedResourcesWrapper.SendBlind(directionOut ? "F+" : "F-");
//:F+# Start Focuser moving inward (toward objective) //:F+# Start Focuser moving inward (toward objective)
//Returns: None //Returns: None
+1
View File
@@ -141,6 +141,7 @@
<Compile Include="LocalServer.cs" /> <Compile Include="LocalServer.cs" />
<Compile Include="MeadeTelescopeBase.cs" /> <Compile Include="MeadeTelescopeBase.cs" />
<Compile Include="ParkedBehaviour.cs" /> <Compile Include="ParkedBehaviour.cs" />
<Compile Include="ParkedPosition.cs" />
<Compile Include="ProfileFactory.cs" /> <Compile Include="ProfileFactory.cs" />
<Compile Include="ProfileProperties.cs" /> <Compile Include="ProfileProperties.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
+10
View File
@@ -0,0 +1,10 @@
namespace ASCOM.Meade.net
{
public class ParkedPosition
{
public double Altitude { get; set; }
public double Azimuth { get; set; }
public double RightAscension { get; set; }
public double Declination { get; set; }
}
}
+33 -9
View File
@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Windows.Forms; using System.Windows.Forms;
using ASCOM.Meade.net.Wrapper; using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities; using ASCOM.Utilities;
@@ -77,12 +78,13 @@ namespace ASCOM.Meade.net
} }
//todo add code to ensure that there is a minimum gap between commands. 5ms as default. //todo add code to ensure that there is a minimum gap between commands. 5ms as default.
public static void SendBlind(string message) public static void SendBlind(string message, bool raw = false)
{ {
lock (LockObject) lock (LockObject)
{ {
SharedSerial.ClearBuffers(); SharedSerial.ClearBuffers();
SharedSerial.Transmit(message); var encodedMessage = raw ? message : $"#:{message}#";
SharedSerial.Transmit(encodedMessage);
} }
} }
@@ -93,14 +95,16 @@ namespace ASCOM.Meade.net
/// and that the reply will always be terminated by a "#" character. /// and that the reply will always be terminated by a "#" character.
/// </summary> /// </summary>
/// <param name="message"></param> /// <param name="message"></param>
/// <param name="raw"></param>
/// <returns></returns> /// <returns></returns>
public static string SendString(string message, bool includePrefix = true) public static string SendString(string message, bool raw = false)
{ {
lock (LockObject) lock (LockObject)
{ {
SharedSerial.ClearBuffers(); SharedSerial.ClearBuffers();
SharedSerial.Transmit(includePrefix ? $"#{message}" : message); var encodedMessage = raw ? message : $"#:{message}#";
SharedSerial.Transmit(encodedMessage);
try try
{ {
@@ -116,12 +120,22 @@ namespace ASCOM.Meade.net
} }
} }
public static string SendChar(string message) 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)
{ {
lock (LockObject) lock (LockObject)
{ {
SharedSerial.ClearBuffers(); SharedSerial.ClearBuffers();
SharedSerial.Transmit(message);
var encodedMessage = raw ? command : $"#:{command}#";
SharedSerial.Transmit(encodedMessage);
try try
{ {
@@ -357,8 +371,8 @@ namespace ASCOM.Meade.net
try try
{ {
ProductName = SendString(":GVP#"); ProductName = SendString("GVP");
FirmwareVersion = SendString(":GVN#"); FirmwareVersion = SendString("GVN");
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -378,7 +392,7 @@ namespace ASCOM.Meade.net
try try
{ {
string utcOffSet = SendString(":GG#"); string utcOffSet = SendString("GG");
//:GG# Get UTC offset time //:GG# Get UTC offset time
//Returns: sHH# or sHH.H# //Returns: sHH# or sHH.H#
//The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the
@@ -479,5 +493,15 @@ namespace ASCOM.Meade.net
Count = 0; Count = 0;
} }
} }
public static void SetParked(bool atPark, ParkedPosition parkedPosition)
{
IsParked = atPark;
ParkedPosition = parkedPosition;
}
public static bool IsParked { get; private set; }
public static ParkedPosition ParkedPosition { get; private set; }
} }
} }
+28 -9
View File
@@ -15,9 +15,10 @@ namespace ASCOM.Meade.net.Wrapper
void Lock(Action action); void Lock(Action action);
T Lock<T>(Func<T> func); T Lock<T>(Func<T> func);
string SendString(string message, bool includePrefix = true); string SendString(string message, bool raw = false);
void SendBlind(string message); void SendBlind(string message, bool raw = false);
string SendChar(string message); bool SendBool(string command, bool raw = false);
string SendChar(string message, bool raw = false);
string ReadTerminated(); string ReadTerminated();
@@ -26,6 +27,10 @@ namespace ASCOM.Meade.net.Wrapper
void SetupDialog(); void SetupDialog();
void WriteProfile(ProfileProperties profileProperties); void WriteProfile(ProfileProperties profileProperties);
void ReadCharacters(int throwAwayCharacters); void ReadCharacters(int throwAwayCharacters);
void SetParked(bool atPark, ParkedPosition parkedPosition);
bool IsParked { get; }
ParkedPosition ParkedPosition { get; }
} }
public class SharedResourcesWrapper : ISharedResourcesWrapper public class SharedResourcesWrapper : ISharedResourcesWrapper
@@ -54,19 +59,24 @@ namespace ASCOM.Meade.net.Wrapper
return SharedResources.Lock(func); return SharedResources.Lock(func);
} }
public string SendString(string message, bool includePrefix = true) public string SendString(string message, bool raw = false)
{ {
return SharedResources.SendString(message, includePrefix); return SharedResources.SendString(message, raw);
} }
public void SendBlind(string message) public void SendBlind(string message, bool raw = false)
{ {
SharedResources.SendBlind(message); SharedResources.SendBlind(message, raw);
} }
public string SendChar(string message) public bool SendBool(string command, bool raw = false)
{ {
return SharedResources.SendChar(message); return SharedResources.SendBool(command, raw);
}
public string SendChar(string message,bool raw = false)
{
return SharedResources.SendChar(message, raw);
} }
public string ReadTerminated() public string ReadTerminated()
@@ -93,5 +103,14 @@ namespace ASCOM.Meade.net.Wrapper
{ {
SharedResources.WriteProfile(profileProperties); SharedResources.WriteProfile(profileProperties);
} }
public void SetParked(bool atPark, ParkedPosition parkedPosition)
{
SharedResources.SetParked(atPark, parkedPosition);
}
public bool IsParked => SharedResources.IsParked;
public ParkedPosition ParkedPosition => SharedResources.ParkedPosition;
} }
} }