Second and subsequent Connections to the telescope driver now no longer trigger resetting the Guide rate and precision. It's assumed they are already set correctly.
This commit is contained in:
@@ -23,6 +23,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
private Mock<IAstroMaths> _astroMathsMock;
|
||||
|
||||
private ProfileProperties _profileProperties;
|
||||
private ConnectionInfo _connectionInfo;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
@@ -45,6 +46,10 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Func<ASCOM.Meade.net.Telescope.TelescopeDateDetails>>())).Returns<Func<ASCOM.Meade.net.Telescope.TelescopeDateDetails>>( (func) => func());
|
||||
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Func<AltitudeData>>())).Returns<Func<AltitudeData>>((func) => func());
|
||||
|
||||
_connectionInfo = new ConnectionInfo {Connections = 1, SameDevice = 1};
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny<string>())).Returns( () => _connectionInfo );
|
||||
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties);
|
||||
|
||||
@@ -350,7 +355,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
|
||||
_telescope.Connected = true;
|
||||
|
||||
_sharedResourcesWrapperMock.Verify( x => x.Connect("Serial"), Times.Once);
|
||||
_sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny<string>()), Times.Once);
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#"), Times.Once);
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once);
|
||||
@@ -361,26 +366,26 @@ namespace Meade.net.Telescope.UnitTests
|
||||
public void Connected_Set_SettingTrueWhenTrue_ThenDoesNothing()
|
||||
{
|
||||
ConnectTelescope();
|
||||
_sharedResourcesWrapperMock.Verify( x => x.Connect(It.IsAny<string>()),Times.Once);
|
||||
_sharedResourcesWrapperMock.Verify( x => x.Connect(It.IsAny<string>(), It.IsAny<string>()),Times.Once);
|
||||
|
||||
//act
|
||||
_telescope.Connected = true;
|
||||
|
||||
//assert
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny<string>()), Times.Once);
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects()
|
||||
{
|
||||
ConnectTelescope();
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny<string>()), Times.Once);
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
|
||||
//act
|
||||
_telescope.Connected = false;
|
||||
|
||||
//assert
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Disconnect(It.IsAny<string>()), Times.Once());
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Disconnect(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -395,7 +400,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_telescope.Connected = true;
|
||||
|
||||
//assert
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Disconnect(It.IsAny<string>()), Times.Once());
|
||||
_sharedResourcesWrapperMock.Verify(x => x.Disconnect(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[TestCase("Autostar", "30Ab", false)]
|
||||
@@ -771,6 +776,22 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce);
|
||||
}
|
||||
|
||||
[TestCase("High", false, true)]
|
||||
[TestCase("High", true, true)]
|
||||
[TestCase("Low", false, false)]
|
||||
[TestCase("Low", true, false)]
|
||||
public void Precision_Set_WhenSecondConnectionMade_ThenTelescopePrecisionNotChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision)
|
||||
{
|
||||
_profileProperties.Precision = desiredPresision;
|
||||
|
||||
_connectionInfo.SameDevice = 2;
|
||||
_connectionInfo.Connections = 2;
|
||||
|
||||
_telescope.Connected = true;
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSetPark_Get_ReturnsFalse()
|
||||
{
|
||||
|
||||
@@ -277,7 +277,6 @@ namespace ASCOM.Meade.net
|
||||
$"Site {actionParameters} not allowed, must be between 1 and 4");
|
||||
|
||||
}
|
||||
break;
|
||||
case "setname":
|
||||
switch (parames[1])
|
||||
{
|
||||
@@ -374,12 +373,11 @@ namespace ASCOM.Meade.net
|
||||
ReadProfile();
|
||||
|
||||
LogMessage("Connected Set", "Connecting to port {0}", _comPort);
|
||||
_sharedResourcesWrapper.Connect("Serial");
|
||||
var connectionInfo = _sharedResourcesWrapper.Connect("Serial", DriverId);
|
||||
try
|
||||
{
|
||||
LogMessage("Connected Set", $"Connected to port {_comPort}. Product: {_sharedResourcesWrapper.ProductName} Version:{_sharedResourcesWrapper.FirmwareVersion}");
|
||||
|
||||
SetLongFormat(true);
|
||||
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
|
||||
_targetDeclination = InvalidParameter;
|
||||
_targetRightAscension = InvalidParameter;
|
||||
@@ -388,16 +386,22 @@ namespace ASCOM.Meade.net
|
||||
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
|
||||
IsConnected = true;
|
||||
|
||||
if (CanSetGuideRates)
|
||||
if (connectionInfo.SameDevice == 1)
|
||||
{
|
||||
SetNewGuideRate( _guideRate, "Connect" );
|
||||
}
|
||||
//These settings are applied only when the first device connects to the telescope.
|
||||
SetLongFormat(true);
|
||||
|
||||
SetTelescopePrecision("Connect");
|
||||
if (CanSetGuideRates)
|
||||
{
|
||||
SetNewGuideRate(_guideRate, "Connect");
|
||||
}
|
||||
|
||||
SetTelescopePrecision("Connect");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_sharedResourcesWrapper.Disconnect("Serial");
|
||||
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -409,7 +413,7 @@ namespace ASCOM.Meade.net
|
||||
else
|
||||
{
|
||||
LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
|
||||
_sharedResourcesWrapper.Disconnect("Serial");
|
||||
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||
IsConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace ASCOM.Meade.net
|
||||
try
|
||||
{
|
||||
ReadProfile();
|
||||
_sharedResourcesWrapper.Connect("Serial");
|
||||
_sharedResourcesWrapper.Connect("Serial", DriverId);
|
||||
try
|
||||
{
|
||||
SelectSite(1);
|
||||
@@ -189,7 +189,7 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_sharedResourcesWrapper.Disconnect("Serial");
|
||||
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ namespace ASCOM.Meade.net
|
||||
else
|
||||
{
|
||||
LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
|
||||
_sharedResourcesWrapper.Disconnect("Serial");
|
||||
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||
IsConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace ASCOM.Meade.net
|
||||
{
|
||||
public class ConnectionInfo
|
||||
{
|
||||
public int Connections { get; set; }
|
||||
public int SameDevice { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -122,6 +122,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ClassFactory.cs" />
|
||||
<Compile Include="ConnectionInfo.cs" />
|
||||
<Compile Include="frmMain.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -260,12 +260,15 @@ namespace ASCOM.Meade.net
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, DeviceHardware> _connectedDevices = new Dictionary<string, DeviceHardware>();
|
||||
|
||||
private static readonly Dictionary<string, DeviceHardware> _connectedDeviceIds = new Dictionary<string, DeviceHardware>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This is called in the driver Connect(true) property,
|
||||
/// it add the device id to the list of devices if it's not there and increments the device count.
|
||||
/// </summary>
|
||||
/// <param name="deviceId"></param>
|
||||
public static void Connect(string deviceId)
|
||||
public static ConnectionInfo Connect(string deviceId, string driverId)
|
||||
{
|
||||
lock (LockObject)
|
||||
{
|
||||
@@ -273,6 +276,10 @@ namespace ASCOM.Meade.net
|
||||
_connectedDevices.Add(deviceId, new DeviceHardware());
|
||||
_connectedDevices[deviceId].Count++; // increment the value
|
||||
|
||||
if (!_connectedDeviceIds.ContainsKey(driverId))
|
||||
_connectedDeviceIds.Add(driverId, new DeviceHardware());
|
||||
_connectedDeviceIds[driverId].Count++; // increment the value
|
||||
|
||||
if (deviceId == "Serial")
|
||||
{
|
||||
if (_connectedDevices[deviceId].Count == 1)
|
||||
@@ -292,10 +299,16 @@ namespace ASCOM.Meade.net
|
||||
FirmwareVersion = SendString(":GVN#");
|
||||
}
|
||||
}
|
||||
|
||||
return new ConnectionInfo
|
||||
{
|
||||
Connections = _connectedDevices[deviceId].Count,
|
||||
SameDevice = _connectedDeviceIds[driverId].Count
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static void Disconnect(string deviceId)
|
||||
public static void Disconnect(string deviceId, string driverId)
|
||||
{
|
||||
lock (LockObject)
|
||||
{
|
||||
@@ -311,6 +324,11 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_connectedDeviceIds.ContainsKey(driverId))
|
||||
{
|
||||
_connectedDeviceIds[driverId].Count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace ASCOM.Meade.net.Wrapper
|
||||
{
|
||||
public interface ISharedResourcesWrapper
|
||||
{
|
||||
void Connect(string deviceId);
|
||||
void Disconnect(string deviceId);
|
||||
ConnectionInfo Connect(string deviceId, string driverId);
|
||||
void Disconnect(string deviceId, string driverId);
|
||||
|
||||
string ProductName { get; }
|
||||
|
||||
@@ -29,14 +29,14 @@ namespace ASCOM.Meade.net.Wrapper
|
||||
|
||||
public class SharedResourcesWrapper : ISharedResourcesWrapper
|
||||
{
|
||||
public void Connect(string deviceId)
|
||||
public ConnectionInfo Connect(string deviceId, string driverId)
|
||||
{
|
||||
SharedResources.Connect( deviceId);
|
||||
return SharedResources.Connect(deviceId, driverId);
|
||||
}
|
||||
|
||||
public void Disconnect(string deviceId)
|
||||
public void Disconnect(string deviceId, string driverId)
|
||||
{
|
||||
SharedResources.Disconnect(deviceId);
|
||||
SharedResources.Disconnect(deviceId, driverId);
|
||||
}
|
||||
|
||||
public string ProductName => SharedResources.ProductName;
|
||||
|
||||
Reference in New Issue
Block a user