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 Mock<IAstroMaths> _astroMathsMock;
|
||||||
|
|
||||||
private ProfileProperties _profileProperties;
|
private ProfileProperties _profileProperties;
|
||||||
|
private ConnectionInfo _connectionInfo;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void 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<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());
|
_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);
|
_sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties);
|
||||||
|
|
||||||
@@ -350,7 +355,7 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
|
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
|
||||||
_telescope.Connected = true;
|
_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.SendString(":GZ#"), Times.Once);
|
||||||
|
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),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()
|
public void Connected_Set_SettingTrueWhenTrue_ThenDoesNothing()
|
||||||
{
|
{
|
||||||
ConnectTelescope();
|
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
|
//act
|
||||||
_telescope.Connected = true;
|
_telescope.Connected = true;
|
||||||
|
|
||||||
//assert
|
//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]
|
[Test]
|
||||||
public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects()
|
public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects()
|
||||||
{
|
{
|
||||||
ConnectTelescope();
|
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
|
//act
|
||||||
_telescope.Connected = false;
|
_telescope.Connected = false;
|
||||||
|
|
||||||
//assert
|
//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]
|
[Test]
|
||||||
@@ -395,7 +400,7 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
_telescope.Connected = true;
|
_telescope.Connected = true;
|
||||||
|
|
||||||
//assert
|
//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)]
|
[TestCase("Autostar", "30Ab", false)]
|
||||||
@@ -771,6 +776,22 @@ namespace Meade.net.Telescope.UnitTests
|
|||||||
_sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce);
|
_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]
|
[Test]
|
||||||
public void CanSetPark_Get_ReturnsFalse()
|
public void CanSetPark_Get_ReturnsFalse()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -277,7 +277,6 @@ 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;
|
|
||||||
case "setname":
|
case "setname":
|
||||||
switch (parames[1])
|
switch (parames[1])
|
||||||
{
|
{
|
||||||
@@ -374,12 +373,11 @@ namespace ASCOM.Meade.net
|
|||||||
ReadProfile();
|
ReadProfile();
|
||||||
|
|
||||||
LogMessage("Connected Set", "Connecting to port {0}", _comPort);
|
LogMessage("Connected Set", "Connecting to port {0}", _comPort);
|
||||||
_sharedResourcesWrapper.Connect("Serial");
|
var connectionInfo = _sharedResourcesWrapper.Connect("Serial", DriverId);
|
||||||
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}");
|
||||||
|
|
||||||
SetLongFormat(true);
|
|
||||||
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
|
_userNewerPulseGuiding = IsNewPulseGuidingSupported();
|
||||||
_targetDeclination = InvalidParameter;
|
_targetDeclination = InvalidParameter;
|
||||||
_targetRightAscension = InvalidParameter;
|
_targetRightAscension = InvalidParameter;
|
||||||
@@ -388,16 +386,22 @@ namespace ASCOM.Meade.net
|
|||||||
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
|
LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}");
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
|
|
||||||
|
if (connectionInfo.SameDevice == 1)
|
||||||
|
{
|
||||||
|
//These settings are applied only when the first device connects to the telescope.
|
||||||
|
SetLongFormat(true);
|
||||||
|
|
||||||
if (CanSetGuideRates)
|
if (CanSetGuideRates)
|
||||||
{
|
{
|
||||||
SetNewGuideRate( _guideRate, "Connect" );
|
SetNewGuideRate(_guideRate, "Connect");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTelescopePrecision("Connect");
|
SetTelescopePrecision("Connect");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_sharedResourcesWrapper.Disconnect("Serial");
|
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,7 +413,7 @@ namespace ASCOM.Meade.net
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
|
LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
|
||||||
_sharedResourcesWrapper.Disconnect("Serial");
|
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||||
IsConnected = false;
|
IsConnected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace ASCOM.Meade.net
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ReadProfile();
|
ReadProfile();
|
||||||
_sharedResourcesWrapper.Connect("Serial");
|
_sharedResourcesWrapper.Connect("Serial", DriverId);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SelectSite(1);
|
SelectSite(1);
|
||||||
@@ -189,7 +189,7 @@ namespace ASCOM.Meade.net
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_sharedResourcesWrapper.Disconnect("Serial");
|
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ namespace ASCOM.Meade.net
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
|
LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
|
||||||
_sharedResourcesWrapper.Disconnect("Serial");
|
_sharedResourcesWrapper.Disconnect("Serial", DriverId);
|
||||||
IsConnected = false;
|
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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ClassFactory.cs" />
|
<Compile Include="ClassFactory.cs" />
|
||||||
|
<Compile Include="ConnectionInfo.cs" />
|
||||||
<Compile Include="frmMain.cs">
|
<Compile Include="frmMain.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -260,12 +260,15 @@ namespace ASCOM.Meade.net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly Dictionary<string, DeviceHardware> _connectedDevices = new Dictionary<string, DeviceHardware>();
|
private static readonly Dictionary<string, DeviceHardware> _connectedDevices = new Dictionary<string, DeviceHardware>();
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, DeviceHardware> _connectedDeviceIds = new Dictionary<string, DeviceHardware>();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called in the driver Connect(true) property,
|
/// 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.
|
/// it add the device id to the list of devices if it's not there and increments the device count.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deviceId"></param>
|
/// <param name="deviceId"></param>
|
||||||
public static void Connect(string deviceId)
|
public static ConnectionInfo Connect(string deviceId, string driverId)
|
||||||
{
|
{
|
||||||
lock (LockObject)
|
lock (LockObject)
|
||||||
{
|
{
|
||||||
@@ -273,6 +276,10 @@ namespace ASCOM.Meade.net
|
|||||||
_connectedDevices.Add(deviceId, new DeviceHardware());
|
_connectedDevices.Add(deviceId, new DeviceHardware());
|
||||||
_connectedDevices[deviceId].Count++; // increment the value
|
_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 (deviceId == "Serial")
|
||||||
{
|
{
|
||||||
if (_connectedDevices[deviceId].Count == 1)
|
if (_connectedDevices[deviceId].Count == 1)
|
||||||
@@ -292,10 +299,16 @@ namespace ASCOM.Meade.net
|
|||||||
FirmwareVersion = SendString(":GVN#");
|
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)
|
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
|
public interface ISharedResourcesWrapper
|
||||||
{
|
{
|
||||||
void Connect(string deviceId);
|
ConnectionInfo Connect(string deviceId, string driverId);
|
||||||
void Disconnect(string deviceId);
|
void Disconnect(string deviceId, string driverId);
|
||||||
|
|
||||||
string ProductName { get; }
|
string ProductName { get; }
|
||||||
|
|
||||||
@@ -29,14 +29,14 @@ namespace ASCOM.Meade.net.Wrapper
|
|||||||
|
|
||||||
public class SharedResourcesWrapper : ISharedResourcesWrapper
|
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;
|
public string ProductName => SharedResources.ProductName;
|
||||||
|
|||||||
Reference in New Issue
Block a user