Refactored code

Added support for setting the guide rate on the RCX400
This commit is contained in:
2022-07-17 12:03:32 +01:00
parent 5f75916116
commit 5f3157a58d
2 changed files with 114 additions and 103 deletions
@@ -965,24 +965,16 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CanSetGuideRates Get")); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CanSetGuideRates Get"));
} }
[Test] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee, false)]
public void CanSetGuideRates_Get_WhenConnectedToAutostar_ThenReturnsFalse() [TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G, true )]
[TestCase(TelescopeList.RCX400, TelescopeList.RCX400_22I, true)]
public void CanSetGuideRates_Get_WhenConnectedToTelescope_ThenReturnsExpectedValue( string productName, string firmware, bool expectedResult)
{ {
ConnectTelescope(); ConnectTelescope(productName, firmware);
var result = _telescope.CanSetGuideRates; var result = _telescope.CanSetGuideRates;
Assert.That(result, Is.False); Assert.That(result, Is.EqualTo(expectedResult));
}
[Test]
public void CanSetGuideRates_Get_WhenConnectedToLX200GPS_ThenReturnsTrue()
{
ConnectTelescope(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G);
var result = _telescope.CanSetGuideRates;
Assert.That(result, Is.True);
} }
[Test] [Test]
@@ -1195,6 +1187,7 @@ namespace Meade.net.Telescope.UnitTests
} }
[TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G, true)] [TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G, true)]
[TestCase(TelescopeList.RCX400, TelescopeList.RCX400_22I, true)]
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, false)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, false)]
public void CanUnpark_Get_ReturnsExpectedValue(string productVersion, string firmware, bool expectedResult) public void CanUnpark_Get_ReturnsExpectedValue(string productVersion, string firmware, bool expectedResult)
{ {
+53 -35
View File
@@ -579,33 +579,38 @@ namespace ASCOM.Meade.net
LogMessage("SendTimeTimeToHandbox", $"SendDateTime: {_profileProperties.SendDateTime}"); LogMessage("SendTimeTimeToHandbox", $"SendDateTime: {_profileProperties.SendDateTime}");
if (_profileProperties.SendDateTime) if (_profileProperties.SendDateTime)
{ {
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) switch (SharedResourcesWrapper.ProductName)
{
case TelescopeList.LX200GPS:
case TelescopeList.RCX400:
{ {
LogMessage("SendTimeTimeToHandbox", LogMessage("SendTimeTimeToHandbox",
$"LX200GPS Detecting if daylight savings message on screen: {_profileProperties.SendDateTime}"); $"{SharedResourcesWrapper.ProductName} Detecting if daylight savings message on screen: {_profileProperties.SendDateTime}");
var displayText = Action("Handbox", "readdisplay"); var displayText = Action("Handbox", "readdisplay");
LogMessage("SendTimeTimeToHandbox", $"Current Handset display: {displayText}"); LogMessage("SendTimeTimeToHandbox", $"Current Handset display: {displayText}");
if (displayText.Contains("Daylight")) if (displayText.Contains("Daylight"))
{ {
LogMessage("SendTimeTimeToHandbox", LogMessage("SendTimeTimeToHandbox",
$"LX200GPS Setting Date time and bypassing settings screens: {_profileProperties.SendDateTime}"); $"{SharedResourcesWrapper.ProductName} Setting Date time and bypassing settings screens: {_profileProperties.SendDateTime}");
BypassHandboxEntryForAutostarII(); BypassHandboxEntryForAutostarII();
} }
else else
{ {
LogMessage("SendTimeTimeToHandbox", LogMessage("SendTimeTimeToHandbox",
$"LX200GPS Sending current date and time: {_profileProperties.SendDateTime}"); $"{SharedResourcesWrapper.ProductName} Sending current date and time: {_profileProperties.SendDateTime}");
SendCurrentDateTime(); SendCurrentDateTime();
LogMessage("SendTimeTimeToHandbox", LogMessage("SendTimeTimeToHandbox",
$"LX200GPS Attempting manual bypass of prompts: {_profileProperties.SendDateTime}"); $"{SharedResourcesWrapper.ProductName} Attempting manual bypass of prompts: {_profileProperties.SendDateTime}");
ApplySkipAutoStarPrompts(); ApplySkipAutoStarPrompts();
} }
break;
} }
else default:
{ LogMessage("Connected Set", $"{SharedResourcesWrapper.ProductName} Attempting manual bypass of prompts");
LogMessage("Connected Set", "Autostar Attempting manual bypass of prompts");
ApplySkipAutoStarPrompts(); ApplySkipAutoStarPrompts();
SendCurrentDateTime(); SendCurrentDateTime();
break;
} }
} }
} }
@@ -647,7 +652,10 @@ namespace ASCOM.Meade.net
private void ApplySkipAutoStarPrompts() private void ApplySkipAutoStarPrompts()
{ {
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS || SharedResourcesWrapper.ProductName == TelescopeList.RCX400) switch (SharedResourcesWrapper.ProductName)
{
case TelescopeList.LX200GPS:
case TelescopeList.RCX400:
{ {
var displayText = Action("Handbox", "readdisplay"); var displayText = Action("Handbox", "readdisplay");
@@ -659,8 +667,10 @@ namespace ASCOM.Meade.net
_utilities.WaitForMilliseconds(2000); _utilities.WaitForMilliseconds(2000);
} }
} }
break;
} }
else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) default:
{ {
var i = 10; var i = 10;
while (i > 0) while (i > 0)
@@ -676,6 +686,9 @@ namespace ASCOM.Meade.net
_utilities.WaitForMilliseconds(500); _utilities.WaitForMilliseconds(500);
i--; i--;
} }
break;
}
} }
} }
@@ -707,26 +720,20 @@ namespace ASCOM.Meade.net
return false; return false;
case "pulse guiding": case "pulse guiding":
return true; return true;
default: default:
if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) switch (SharedResourcesWrapper.ProductName)
{ {
case TelescopeList.Autostar497:
return FirmwareIsGreaterThan(TelescopeList.Autostar497_31Ee); return FirmwareIsGreaterThan(TelescopeList.Autostar497_31Ee);
} case TelescopeList.LX200GPS:
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS)
{
return true; return true;
} case TelescopeList.RCX400:
if (SharedResourcesWrapper.ProductName == TelescopeList.RCX400)
{
return FirmwareIsGreaterThan(TelescopeList.RCX400_22I); return FirmwareIsGreaterThan(TelescopeList.RCX400_22I);
} default:
return false; return false;
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LogMessage("IsNewPulseGuidingSupported", $"Error: {ex.Message}"); LogMessage("IsNewPulseGuidingSupported", $"Error: {ex.Message}");
@@ -746,13 +753,15 @@ namespace ASCOM.Meade.net
private bool IsGuideRateSettingSupported() private bool IsGuideRateSettingSupported()
{ {
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) switch (SharedResourcesWrapper.ProductName)
{ {
case TelescopeList.LX200GPS:
case TelescopeList.RCX400:
return true; return true;
} default:
return false; return false;
} }
}
private bool IsGwCommandSupported() private bool IsGwCommandSupported()
{ {
@@ -1230,15 +1239,17 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("Altitude Get"); CheckConnected("Altitude Get");
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) switch (SharedResourcesWrapper.ProductName)
{ {
case TelescopeList.LX200GPS:
case TelescopeList.RCX400:
return GetRealTelescopeAltitude(); return GetRealTelescopeAltitude();
} default:
var altAz = CalcAltAzFromTelescopeEqData(); var altAz = CalcAltAzFromTelescopeEqData();
LogMessage("Altitude", $"{altAz.Altitude}"); LogMessage("Altitude", $"{altAz.Altitude}");
return altAz.Altitude; return altAz.Altitude;
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LogMessage("Altitude Get", $"Error: {ex.Message}"); LogMessage("Altitude Get", $"Error: {ex.Message}");
@@ -1394,15 +1405,17 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("Azimuth Get"); CheckConnected("Azimuth Get");
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) switch (SharedResourcesWrapper.ProductName)
{ {
case TelescopeList.LX200GPS:
case TelescopeList.RCX400:
return GetRealTelescopeAzimuth(); return GetRealTelescopeAzimuth();
} default:
var altAz = CalcAltAzFromTelescopeEqData(); var altAz = CalcAltAzFromTelescopeEqData();
LogMessage("Azimuth Get", $"{altAz.Azimuth}"); LogMessage("Azimuth Get", $"{altAz.Azimuth}");
return altAz.Azimuth; return altAz.Azimuth;
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LogMessage("Azimuth Get", $"Error: {ex.Message}"); LogMessage("Azimuth Get", $"Error: {ex.Message}");
@@ -1754,6 +1767,7 @@ namespace ASCOM.Meade.net
var unParkableScopes = new List<string> var unParkableScopes = new List<string>
{ {
TelescopeList.LX200GPS, TelescopeList.LX200GPS,
TelescopeList.RCX400,
TelescopeList.LX200CLASSIC TelescopeList.LX200CLASSIC
}; };
@@ -3812,16 +3826,17 @@ namespace ASCOM.Meade.net
if (!AtPark) if (!AtPark)
return; return;
if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) switch (SharedResourcesWrapper.ProductName)
{ {
case TelescopeList.RCX400:
case TelescopeList.LX200GPS:
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();
} break;
else if (SharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC) case TelescopeList.LX200CLASSIC:
{ {
if (SharedResourcesWrapper.RestartTracking) if (SharedResourcesWrapper.RestartTracking)
{ {
@@ -3829,6 +3844,9 @@ namespace ASCOM.Meade.net
Tracking = true; Tracking = true;
LogMessage("Unpark", "Turning tracking on completed"); LogMessage("Unpark", "Turning tracking on completed");
} }
break;
}
} }
SharedResourcesWrapper.SetParked(false, null, false); SharedResourcesWrapper.SetParked(false, null, false);