Fixed the defect when one instance of the driver gets parked, the info is shared to the other instances.

This commit is contained in:
2021-04-27 22:08:25 +01:00
parent 2c2c59290e
commit 486a9205ee
7 changed files with 133 additions and 82 deletions
@@ -48,9 +48,15 @@ namespace Meade.net.Telescope.UnitTests
private TestProperties _testProperties; private TestProperties _testProperties;
private bool _isParked;
private ParkedPosition _parkedPosition;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_isParked = false;
_parkedPosition = null;
_testProperties = new TestProperties(); _testProperties = new TestProperties();
_profileProperties = new ProfileProperties _profileProperties = new ProfileProperties
@@ -118,6 +124,14 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion);
_sharedResourcesWrapperMock.Setup(x => x.SetParked(It.IsAny<bool>(), It.IsAny<ParkedPosition>())).Callback<bool,ParkedPosition>((isParked, parkedPostion) => {
_isParked = isParked;
_parkedPosition = parkedPostion;
});
_sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked);
_sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition);
_astroMathsMock _astroMathsMock
.Setup(x => x.ConvertHozToEq(It.IsAny<DateTime>(), It.IsAny<double>(), It.IsAny<double>(), .Setup(x => x.ConvertHozToEq(It.IsAny<DateTime>(), It.IsAny<double>(), It.IsAny<double>(),
It.IsAny<HorizonCoordinates>())).Returns(() => new EquatorialCoordinates { Declination = _testProperties.declination, RightAscension = _testProperties.rightAscension }); It.IsAny<HorizonCoordinates>())).Returns(() => new EquatorialCoordinates { Declination = _testProperties.declination, RightAscension = _testProperties.rightAscension });
@@ -127,7 +127,6 @@
<Compile Include="ComparisonResult.cs" /> <Compile Include="ComparisonResult.cs" />
<Compile Include="DoubleExtensions.cs" /> <Compile Include="DoubleExtensions.cs" />
<Compile Include="IClock.cs" /> <Compile Include="IClock.cs" />
<Compile Include="ParkedPosition.cs" />
<Compile Include="StringExtensions.cs" /> <Compile Include="StringExtensions.cs" />
<Compile Include="Telescope.cs" /> <Compile Include="Telescope.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
+64 -50
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>
@@ -74,8 +77,6 @@ namespace ASCOM.Meade.net
private short _settleTime; private short _settleTime;
private ParkedPosition _parkedPosition;
/// <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.
@@ -123,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
@@ -282,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])
@@ -316,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(
@@ -398,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;
@@ -430,19 +436,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");
} }
@@ -457,11 +467,13 @@ 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})");
} }
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)
{ {
@@ -573,6 +585,7 @@ namespace ASCOM.Meade.net
{ {
return false; return false;
} }
return true; return true;
} }
@@ -582,6 +595,7 @@ namespace ASCOM.Meade.net
{ {
return true; return true;
} }
return false; return false;
} }
@@ -807,7 +821,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);
@@ -844,7 +859,8 @@ namespace ASCOM.Meade.net
//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);
} }
} }
@@ -994,6 +1010,8 @@ namespace ASCOM.Meade.net
{ {
try try
{ {
CheckParked();
//firmware bug in 44Eg, :GA# is returning the dec, not the altitude! //firmware bug in 44Eg, :GA# is returning the dec, not the altitude!
var result = SharedResourcesWrapper.SendString("GA"); var result = SharedResourcesWrapper.SendString("GA");
//:GA# Get Telescope Altitude //:GA# Get Telescope Altitude
@@ -1006,13 +1024,11 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException) catch (ParkedException)
{ {
switch (ParkedBehaviour) var parkedPosition = SharedResourcesWrapper.ParkedPosition;
{ if (parkedPosition != null)
case ParkedBehaviour.NoCoordinates: return parkedPosition.Altitude;
throw; throw;
default:
return _parkedPosition.Altitude;
}
} }
} }
@@ -1032,9 +1048,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;
} }
@@ -1074,16 +1092,14 @@ namespace ASCOM.Meade.net
} }
} }
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)
@@ -1102,6 +1118,8 @@ namespace ASCOM.Meade.net
{ {
try try
{ {
CheckParked();
var result = SharedResourcesWrapper.SendString("GZ"); var result = SharedResourcesWrapper.SendString("GZ");
//:GZ# Get telescope azimuth //:GZ# Get telescope azimuth
//Returns: DDD*MM#T or DDD*MMSS# //Returns: DDD*MM#T or DDD*MMSS#
@@ -1114,13 +1132,11 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException) catch (ParkedException)
{ {
switch (ParkedBehaviour) var parkedPosition = SharedResourcesWrapper.ParkedPosition;
{ if (parkedPosition != null)
case ParkedBehaviour.NoCoordinates: return parkedPosition.Azimuth;
throw; throw;
default:
return _parkedPosition.Azimuth;
}
} }
} }
@@ -1317,13 +1333,11 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException) catch (ParkedException)
{ {
switch (ParkedBehaviour) var parkedPosition = SharedResourcesWrapper.ParkedPosition;
{ if (parkedPosition != null)
case ParkedBehaviour.NoCoordinates: return parkedPosition.Declination;
throw; throw;
default:
return _parkedPosition.Declination;
}
} }
} }
} }
@@ -1585,10 +1599,11 @@ namespace ASCOM.Meade.net
if (AtPark) if (AtPark)
return; return;
ParkedPosition parkedPosition;
switch (ParkedBehaviour) switch (ParkedBehaviour)
{ {
case ParkedBehaviour.LastGoodPosition: case ParkedBehaviour.LastGoodPosition:
_parkedPosition = new ParkedPosition parkedPosition = new ParkedPosition
{ {
Altitude = Altitude, Altitude = Altitude,
Azimuth = Azimuth, Azimuth = Azimuth,
@@ -1602,7 +1617,7 @@ namespace ASCOM.Meade.net
var longitude = SiteLongitude; var longitude = SiteLongitude;
var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, ParkedAltAz); var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, ParkedAltAz);
_parkedPosition = new ParkedPosition parkedPosition = new ParkedPosition
{ {
Altitude = ParkedAltAz.Altitude, Altitude = ParkedAltAz.Altitude,
Azimuth = ParkedAltAz.Azimuth, Azimuth = ParkedAltAz.Azimuth,
@@ -1610,12 +1625,13 @@ namespace ASCOM.Meade.net
Declination = raDec.Declination Declination = raDec.Declination
}; };
break; 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
@@ -1764,13 +1780,11 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException) catch (ParkedException)
{ {
switch (ParkedBehaviour) var parkedPosition = SharedResourcesWrapper.ParkedPosition;
{ if (parkedPosition != null)
case ParkedBehaviour.NoCoordinates: return parkedPosition.RightAscension;
throw; throw;
default:
return _parkedPosition.RightAscension;
}
} }
} }
@@ -2698,7 +2712,7 @@ namespace ASCOM.Meade.net
BypassHandboxEntryForAutostarII(); BypassHandboxEntryForAutostarII();
AtPark = false; SharedResourcesWrapper.SetParked(false, null);
} }
private bool BypassHandboxEntryForAutostarII() private bool BypassHandboxEntryForAutostarII()
+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
@@ -493,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; }
} }
} }
@@ -27,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
@@ -99,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;
} }
} }