Compare commits

..

9 Commits

Author SHA1 Message Date
ColinD 3d0464f379 Merged in develop (pull request #32)
Develop
2021-06-06 13:44:33 +00:00
Sebastian Godelet d1b5652228 Merged in feature/add-side-of-pier (pull request #31)
Implemented SideOfPier and DestinationSideOfPier

Approved-by: Colin Dawson
2021-06-06 13:23:49 +00:00
Sebastian Godelet 65e06f2d6c Implemented SideOfPier and DestinationSideOfPier
For telescopes that automatically perform a meridian flip we can
implement the SideOfPier property by updating the current side of pier
after a telescope slew (via DestinationSideOfPier)
2021-06-06 19:44:40 +10:00
ColinD b27e50275d Added extra logging for CommandBlind, CommandBool, and CommandString. 2021-05-09 15:20:45 +01:00
ColinD a101d3a2d7 Merged in develop (pull request #30)
Develop
2021-04-29 15:18:42 +00:00
ColinD d7637928b7 Made sure that the telescope doesn't think it's parked for the first Telescope to connect. 2021-04-27 22:14:22 +01:00
ColinD 486a9205ee Fixed the defect when one instance of the driver gets parked, the info is shared to the other instances. 2021-04-27 22:08:25 +01:00
ColinD 2c2c59290e Reinstated the Real Alt Az methods for the LX200GPS. Changes how the parked behaviour is implemented, so that it doesn't need to make as many calls. 2021-04-27 20:14:57 +01:00
ColinD 70e615bb4e Made sure that CommandString, CommandBool and CommandBlind work as expected, complete with Raw and non raw support. (Implementation is the same as one of the LX200 drivers.) 2021-04-26 20:51:41 +01:00
9 changed files with 994 additions and 692 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
File diff suppressed because it is too large Load Diff
+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";
+15 -8
View File
@@ -101,32 +101,39 @@ namespace ASCOM.Meade.net
public void CommandBlind(string command, bool raw) public void CommandBlind(string command, bool raw)
{ {
LogMessage("CommandBlind", "raw: {0} command {0}", raw, command);
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
LogMessage("CommandBlind", "Completed");
} }
public bool CommandBool(string command, bool raw) public bool CommandBool(string command, bool raw)
{ {
LogMessage("CommandBool", "raw: {0} command {0}", raw, command);
CheckConnected("CommandBool"); CheckConnected("CommandBool");
//string ret = CommandString(command, raw); var result = SharedResourcesWrapper.SendBool(command, raw);
// decode the return string and return true or false LogMessage("CommandBool", "Completed: {0}", result);
return result;
// 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
} }
public string CommandString(string command, bool raw) public string CommandString(string command, bool raw)
{ {
LogMessage("CommandString", "raw: {0} command {0}", raw, command);
CheckConnected("CommandString"); CheckConnected("CommandString");
// 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); var result = SharedResourcesWrapper.SendString(command, raw);
LogMessage("CommandBool", "Completed: {0}", result);
return result;
//throw new ASCOM.MethodNotImplementedException("CommandString"); //throw new ASCOM.MethodNotImplementedException("CommandString");
} }
@@ -225,7 +232,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 +336,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 +357,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;
} }
} }