Refactored code to use interrfaces in declarations, rather than concrete classes.

This commit is contained in:
2019-07-08 17:30:02 +01:00
parent bc90049798
commit ca3dd0e4fd
5 changed files with 64 additions and 149 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ namespace ASCOM.Meade.net
public EquatorialCoordinates equatorialCoordinates { get; set; } public EquatorialCoordinates equatorialCoordinates { get; set; }
} }
public class AstroMaths public class AstroMaths : IAstroMaths
{ {
//returns the decimal hour angle for given right ascension on a given datetime for a given logitude. //returns the decimal hour angle for given right ascension on a given datetime for a given logitude.
+17
View File
@@ -0,0 +1,17 @@
using System;
namespace ASCOM.Meade.net
{
public interface IAstroMaths
{
double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension);
double HourAngleToRightAscension(DateTime utcDateTime, double longitude, double hourAngle );
EquatorialCoordinates ConvertHozToEq( DateTime utcDateTime, double latitude, double longitude, HorizonCoordinates altAz);
HorizonCoordinates ConvertEqToHoz(double hourAngle, double latitude, EquatorialCoordinates raDec);
double DegreesToRadians(double degrees);
double RadiansToDegrees(double radians);
double DateTimeToDecimalHours( DateTime utcDateTime);
double UTtoGST(DateTime utcDateTime);
double GSTtoLST(double gst, double longitude);
}
}
@@ -89,6 +89,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AstroMaths.cs" /> <Compile Include="AstroMaths.cs" />
<Compile Include="IAstroMaths.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" />
+34 -84
View File
@@ -1,39 +1,7 @@
//tabs=4
// --------------------------------------------------------------------------------
// TODO fill in this information for your driver, then remove this line!
//
// ASCOM Telescope driver for Meade.net
//
// Description: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
// nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
// erat, sed diam voluptua. At vero eos et accusam et justo duo
// dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
// sanctus est Lorem ipsum dolor sit amet.
//
// Implements: ASCOM Telescope interface version: <To be completed by driver developer>
// Author: (XXX) Your N. Here <your@email.here>
//
// Edit Log:
//
// Date Who Vers Description
// ----------- --- ----- -------------------------------------------------------
// dd-mmm-yyyy XXX 6.0.0 Initial edit, created from ASCOM driver template
// --------------------------------------------------------------------------------
//
// This is used to define code in the template that is specific to one class implementation
// unused code canbe deleted and this definition removed.
#define Telescope #define Telescope
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ASCOM;
using ASCOM.Astrometry;
using ASCOM.Astrometry.AstroUtils; using ASCOM.Astrometry.AstroUtils;
using ASCOM.Utilities; using ASCOM.Utilities;
using ASCOM.DeviceInterface; using ASCOM.DeviceInterface;
@@ -41,6 +9,7 @@ using System.Globalization;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using ASCOM.Meade.net.Wrapper; using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities.Interfaces;
namespace ASCOM.Meade.net namespace ASCOM.Meade.net
{ {
@@ -77,29 +46,20 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
private static string driverDescription = "Meade Generic"; private static string driverDescription = "Meade Generic";
internal static string comPortProfileName = "COM Port"; // Constants used for Profile persistence
internal static string comPortDefault = "COM1";
internal static string traceStateProfileName = "Trace Level";
internal static string traceStateDefault = "false";
internal static string comPort; // Variables to hold the currrent device configuration internal static string comPort; // Variables to hold the currrent device configuration
/// <summary>
/// Private variable to hold the connected state
/// </summary>
private bool _connectedState;
/// <summary> /// <summary>
/// Private variable to hold an ASCOM Utilities object /// Private variable to hold an ASCOM Utilities object
/// </summary> /// </summary>
private Util utilities; private readonly IUtil _utilities;
private readonly IUtilExtra _utilitiesExtra;
/// <summary> /// <summary>
/// Private variable to hold an ASCOM AstroUtilities object to provide the Range method /// Private variable to hold an ASCOM AstroUtilities object to provide the Range method
/// </summary> /// </summary>
private AstroUtils astroUtilities; private readonly IAstroUtils _astroUtilities;
private readonly AstroMaths _astroMaths; private readonly IAstroMaths _astroMaths;
/// <summary> /// <summary>
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
@@ -119,9 +79,10 @@ namespace ASCOM.Meade.net
tl.LogMessage("Telescope", "Starting initialisation"); tl.LogMessage("Telescope", "Starting initialisation");
_connectedState = false; // Initialise connected to false IsConnected = false; // Initialise connected to false
utilities = new Util(); //Initialise util object _utilities = new Util(); //Initialise util object
astroUtilities = new AstroUtils(); // Initialise astro utilities object _utilitiesExtra = new Util(); //Initialise util object
_astroUtilities = new AstroUtils(); // Initialise astro utilities object
_sharedResourcesWrapper = new SharedResourcesWrapper(); _sharedResourcesWrapper = new SharedResourcesWrapper();
//TODO: Implement your additional construction here //TODO: Implement your additional construction here
@@ -297,10 +258,6 @@ namespace ASCOM.Meade.net
tl.Enabled = false; tl.Enabled = false;
tl.Dispose(); tl.Dispose();
tl = null; tl = null;
utilities.Dispose();
utilities = null;
astroUtilities.Dispose();
astroUtilities = null;
} }
public bool Connected public bool Connected
@@ -333,7 +290,7 @@ namespace ASCOM.Meade.net
_userNewerPulseGuiding = IsNewPulseGuidingSupported(); _userNewerPulseGuiding = IsNewPulseGuidingSupported();
_connectedState = true; IsConnected = true;
} }
catch (Exception) catch (Exception)
{ {
@@ -350,7 +307,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("Connected Set", "Disconnecting from port {0}", comPort); LogMessage("Connected Set", "Disconnecting from port {0}", comPort);
_sharedResourcesWrapper.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
_connectedState = false; IsConnected = false;
} }
} }
} }
@@ -385,7 +342,7 @@ namespace ASCOM.Meade.net
if (isLongFormat != setLongFormat) if (isLongFormat != setLongFormat)
{ {
utilities.WaitForMilliseconds(500); _utilities.WaitForMilliseconds(500);
_sharedResourcesWrapper.SendBlind(":U#"); _sharedResourcesWrapper.SendBlind(":U#");
//:U# Toggle between low/hi precision positions //:U# Toggle between low/hi precision positions
//Low - RA displays and messages HH:MM.T sDD*MM //Low - RA displays and messages HH:MM.T sDD*MM
@@ -835,9 +792,9 @@ namespace ASCOM.Meade.net
//Returns: sDD* MM# or sDD*MMSS# //Returns: sDD* MM# or sDD*MMSS#
//Depending upon the current precision setting for the telescope. //Depending upon the current precision setting for the telescope.
double declination = utilities.DMSToDegrees(result); double declination = _utilities.DMSToDegrees(result);
tl.LogMessage("Declination", "Get - " + utilities.DegreesToDMS(declination, ":", ":")); tl.LogMessage("Declination", "Get - " + _utilitiesExtra.DegreesToDMS(declination, ":", ":"));
return declination; return declination;
} }
} }
@@ -1090,7 +1047,7 @@ namespace ASCOM.Meade.net
//Returns Nothing //Returns Nothing
//LX200 Not Supported //LX200 Not Supported
utilities.WaitForMilliseconds(duration); //todo figure out if this is really needed _utilities.WaitForMilliseconds(duration); //todo figure out if this is really needed
} }
else else
{ {
@@ -1108,7 +1065,7 @@ namespace ASCOM.Meade.net
//Returns: Nothing //Returns: Nothing
//:Mw# Move Telescope West at current slew rate //:Mw# Move Telescope West at current slew rate
//Returns: Nothing //Returns: Nothing
utilities.WaitForMilliseconds(duration); _utilities.WaitForMilliseconds(duration);
_sharedResourcesWrapper.SendBlind($":Q{d}#"); _sharedResourcesWrapper.SendBlind($":Q{d}#");
//:Qe# Halt eastward Slews //:Qe# Halt eastward Slews
//Returns: Nothing //Returns: Nothing
@@ -1132,9 +1089,9 @@ namespace ASCOM.Meade.net
//Returns: HH: MM.T# or HH:MM:SS# //Returns: HH: MM.T# or HH:MM:SS#
//Depending which precision is set for the telescope //Depending which precision is set for the telescope
double rightAscension = utilities.HMSToHours(result); double rightAscension = _utilities.HMSToHours(result);
tl.LogMessage("RightAscension", "Get - " + utilities.HoursToHMS(rightAscension)); tl.LogMessage("RightAscension", "Get - " + _utilitiesExtra.HoursToHMS(rightAscension));
return rightAscension; return rightAscension;
} }
} }
@@ -1182,7 +1139,7 @@ namespace ASCOM.Meade.net
double siderealTime = 0.0; double siderealTime = 0.0;
using (var novas = new ASCOM.Astrometry.NOVAS.NOVAS31()) using (var novas = new ASCOM.Astrometry.NOVAS.NOVAS31())
{ {
var jd = utilities.DateUTCToJulian(DateTime.UtcNow); var jd = _utilities.DateUTCToJulian(DateTime.UtcNow);
novas.SiderealTime(jd, 0, novas.DeltaT(jd), novas.SiderealTime(jd, 0, novas.DeltaT(jd),
ASCOM.Astrometry.GstType.GreenwichApparentSiderealTime, ASCOM.Astrometry.GstType.GreenwichApparentSiderealTime,
ASCOM.Astrometry.Method.EquinoxBased, ASCOM.Astrometry.Method.EquinoxBased,
@@ -1193,7 +1150,7 @@ namespace ASCOM.Meade.net
siderealTime += SiteLongitude / 360.0 * 24.0; siderealTime += SiteLongitude / 360.0 * 24.0;
// Reduce to the range 0 to 24 hours // Reduce to the range 0 to 24 hours
siderealTime = astroUtilities.ConditionRA(siderealTime); siderealTime = _astroUtilities.ConditionRA(siderealTime);
tl.LogMessage("SiderealTime", "Get - " + siderealTime.ToString()); tl.LogMessage("SiderealTime", "Get - " + siderealTime.ToString());
return siderealTime; return siderealTime;
@@ -1225,13 +1182,13 @@ namespace ASCOM.Meade.net
//Returns: sDD* MM# //Returns: sDD* MM#
//The latitude of the current site. Positive inplies North latitude. //The latitude of the current site. Positive inplies North latitude.
var siteLatitude = utilities.DMSToDegrees(latitude); var siteLatitude = _utilities.DMSToDegrees(latitude);
tl.LogMessage("SiteLatitude Get", $"{utilities.DegreesToDMS(siteLatitude)}"); tl.LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}");
return siteLatitude; return siteLatitude;
} }
set set
{ {
tl.LogMessage("SiteLatitude Set", $"{utilities.DegreesToDMS(value)}"); tl.LogMessage("SiteLatitude Set", $"{_utilitiesExtra.DegreesToDMS(value)}");
CheckConnected("SiteLatitude Set"); CheckConnected("SiteLatitude Set");
@@ -1266,21 +1223,21 @@ namespace ASCOM.Meade.net
//:Gg# Get Current Site Longitude //:Gg# Get Current Site Longitude
//Returns: sDDD* MM# //Returns: sDDD* MM#
//The current site Longitude. East Longitudes are expressed as negative //The current site Longitude. East Longitudes are expressed as negative
double siteLongitude = utilities.DMSToDegrees(longitude); double siteLongitude = _utilities.DMSToDegrees(longitude);
if (siteLongitude > 180) if (siteLongitude > 180)
siteLongitude = siteLongitude - 360; siteLongitude = siteLongitude - 360;
siteLongitude = -siteLongitude; siteLongitude = -siteLongitude;
tl.LogMessage("SiteLongitude Get", $"{utilities.DegreesToDMS(siteLongitude)}"); tl.LogMessage("SiteLongitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLongitude)}");
return siteLongitude; return siteLongitude;
} }
set set
{ {
var newLongitude = value; var newLongitude = value;
tl.LogMessage("SiteLongitude Set", $"{utilities.DegreesToDMS(newLongitude)}"); tl.LogMessage("SiteLongitude Set", $"{_utilitiesExtra.DegreesToDMS(newLongitude)}");
CheckConnected("SiteLongitude Set"); CheckConnected("SiteLongitude Set");
@@ -1332,7 +1289,7 @@ namespace ASCOM.Meade.net
while (Slewing) //wait for slew to complete while (Slewing) //wait for slew to complete
{ {
utilities.WaitForMilliseconds(200); //be responsive to AbortSlew(); _utilities.WaitForMilliseconds(200); //be responsive to AbortSlew();
} }
} }
@@ -1350,7 +1307,7 @@ namespace ASCOM.Meade.net
//todo this serial string does not work. Calculate the EQ version instead. //todo this serial string does not work. Calculate the EQ version instead.
var dms = utilities.DegreesToDMS(value, "*", "'", "",0); var dms = _utilities.DegreesToDMS(value, "*", "'", "",0);
var s = value < 0 ? string.Empty : "+"; var s = value < 0 ? string.Empty : "+";
var result = _sharedResourcesWrapper.SendChar($":Sa{s}{dms}#"); var result = _sharedResourcesWrapper.SendChar($":Sa{s}{dms}#");
@@ -1379,7 +1336,7 @@ namespace ASCOM.Meade.net
//todo this serial string does not work. Calculate the EQ version instead. //todo this serial string does not work. Calculate the EQ version instead.
var dms = utilities.DegreesToDM(value, "*" ); var dms = _utilitiesExtra.DegreesToDM(value, "*" );
var result = _sharedResourcesWrapper.SendChar($":Sz{dms}#"); var result = _sharedResourcesWrapper.SendChar($":Sz{dms}#");
//:SzDDD*MM# //:SzDDD*MM#
@@ -1501,7 +1458,7 @@ namespace ASCOM.Meade.net
while (Slewing) //wait for slew to complete while (Slewing) //wait for slew to complete
{ {
utilities.WaitForMilliseconds(200); //be responsive to AbortSlew(); _utilities.WaitForMilliseconds(200); //be responsive to AbortSlew();
} }
tl.LogMessage("SlewToCoordinates", $"Slewing completed new coordinates Ra={RightAscension}, Dec={Declination}"); tl.LogMessage("SlewToCoordinates", $"Slewing completed new coordinates Ra={RightAscension}, Dec={Declination}");
@@ -1530,7 +1487,7 @@ namespace ASCOM.Meade.net
while (Slewing) while (Slewing)
{ {
utilities.WaitForMilliseconds(200); _utilities.WaitForMilliseconds(200);
} }
} }
@@ -1643,7 +1600,7 @@ namespace ASCOM.Meade.net
CheckConnected("TargetDeclination Set"); CheckConnected("TargetDeclination Set");
var dms = utilities.DegreesToDMS(value, "*", ":", ":", 2); var dms = _utilities.DegreesToDMS(value, "*", ":", ":", 2);
var s = value < 0 ? string.Empty : "+"; var s = value < 0 ? string.Empty : "+";
var command = $":Sd{s}{dms}#"; var command = $":Sd{s}{dms}#";
@@ -1697,7 +1654,7 @@ namespace ASCOM.Meade.net
CheckConnected("TargetRightAscension Set"); CheckConnected("TargetRightAscension Set");
//todo implement the low precision version //todo implement the low precision version
var hms = utilities.HoursToHMS(value, ":", ":", ":", 2); var hms = _utilities.HoursToHMS(value, ":", ":", ":", 2);
var response = _sharedResourcesWrapper.SendChar($":Sr{hms}#"); var response = _sharedResourcesWrapper.SendChar($":Sr{hms}#");
//:SrHH:MM.T# //:SrHH:MM.T#
//:SrHH:MM:SS# //:SrHH:MM:SS#
@@ -1992,14 +1949,7 @@ namespace ASCOM.Meade.net
/// <summary> /// <summary>
/// Returns true if there is a valid connection to the driver hardware /// Returns true if there is a valid connection to the driver hardware
/// </summary> /// </summary>
private bool IsConnected private bool IsConnected { get; set; }
{
get
{
// TODO check that the driver hardware connection exists and is connected to the hardware
return _connectedState;
}
}
/// <summary> /// <summary>
/// Use this function to throw an exception if we aren't connected to the hardware /// Use this function to throw an exception if we aren't connected to the hardware
+11 -64
View File
@@ -1,29 +1,3 @@
//tabs=4
// --------------------------------------------------------------------------------
// TODO fill in this information for your driver, then remove this line!
//
// ASCOM Focuser driver for Meade.net
//
// Description: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
// nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
// erat, sed diam voluptua. At vero eos et accusam et justo duo
// dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
// sanctus est Lorem ipsum dolor sit amet.
//
// Implements: ASCOM Focuser interface version: <To be completed by driver developer>
// Author: (XXX) Your N. Here <your@email.here>
//
// Edit Log:
//
// Date Who Vers Description
// ----------- --- ----- -------------------------------------------------------
// dd-mmm-yyyy XXX 6.0.0 Initial edit, created from ASCOM driver template
// --------------------------------------------------------------------------------
//
// This is used to define code in the template that is specific to one class implementation
// unused code canbe deleted and this definition removed.
#define Focuser #define Focuser
using System; using System;
@@ -77,27 +51,12 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
private static string driverDescription = "Meade Generic"; private static string driverDescription = "Meade Generic";
internal static string comPortProfileName = "COM Port"; // Constants used for Profile persistence
internal static string comPortDefault = "COM1";
internal static string traceStateProfileName = "Trace Level";
internal static string traceStateDefault = "false";
internal static string comPort; // Variables to hold the currrent device configuration internal static string comPort; // Variables to hold the currrent device configuration
/// <summary>
/// Private variable to hold the connected state
/// </summary>
private bool connectedState;
/// <summary> /// <summary>
/// Private variable to hold an ASCOM Utilities object /// Private variable to hold an ASCOM Utilities object
/// </summary> /// </summary>
private Util utilities; private readonly IUtil _utilities;
/// <summary>
/// Private variable to hold an ASCOM AstroUtilities object to provide the Range method
/// </summary>
private AstroUtils astroUtilities;
/// <summary> /// <summary>
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
@@ -117,9 +76,8 @@ namespace ASCOM.Meade.net
tl.LogMessage("Focuser", "Starting initialisation"); tl.LogMessage("Focuser", "Starting initialisation");
connectedState = false; // Initialise connected to false IsConnected = false; // Initialise connected to false
utilities = new Util(); //Initialise util object _utilities = new Util(); //Initialise util object
astroUtilities = new AstroUtils(); // Initialise astro utilities object
_sharedResourcesWrapper = new SharedResourcesWrapper(); _sharedResourcesWrapper = new SharedResourcesWrapper();
tl.LogMessage("Focuser", "Completed initialisation"); tl.LogMessage("Focuser", "Completed initialisation");
@@ -199,10 +157,6 @@ namespace ASCOM.Meade.net
tl.Enabled = false; tl.Enabled = false;
tl.Dispose(); tl.Dispose();
tl = null; tl = null;
utilities.Dispose();
utilities = null;
astroUtilities.Dispose();
astroUtilities = null;
} }
public bool Connected public bool Connected
@@ -228,7 +182,7 @@ namespace ASCOM.Meade.net
SelectSite(1); SelectSite(1);
SetLongFormat(true); SetLongFormat(true);
connectedState = true; IsConnected = true;
} }
catch (Exception) catch (Exception)
{ {
@@ -245,7 +199,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("Connected Set", "Disconnecting from port {0}", comPort); LogMessage("Connected Set", "Disconnecting from port {0}", comPort);
_sharedResourcesWrapper.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
connectedState = false; IsConnected = false;
} }
} }
} }
@@ -263,7 +217,7 @@ namespace ASCOM.Meade.net
if (isLongFormat != setLongFormat) if (isLongFormat != setLongFormat)
{ {
utilities.WaitForMilliseconds(500); _utilities.WaitForMilliseconds(500);
_sharedResourcesWrapper.SendBlind(":U#"); _sharedResourcesWrapper.SendBlind(":U#");
//:U# Toggle between low/hi precision positions //:U# Toggle between low/hi precision positions
//Low - RA displays and messages HH:MM.T sDD*MM //Low - RA displays and messages HH:MM.T sDD*MM
@@ -362,7 +316,7 @@ namespace ASCOM.Meade.net
//:FQ# Halt Focuser Motion //:FQ# Halt Focuser Motion
//Returns: Nothing //Returns: Nothing
utilities.WaitForMilliseconds(250); _utilities.WaitForMilliseconds(250);
} }
} }
@@ -452,7 +406,7 @@ namespace ASCOM.Meade.net
//:F<n># Autostar, Autostar II set focuser speed to <n> where <n> is an ASCII digit 1..4 //:F<n># Autostar, Autostar II set focuser speed to <n> where <n> is an ASCII digit 1..4
//Returns: Nothing //Returns: Nothing
//All others Not Supported //All others Not Supported
utilities.WaitForMilliseconds(100); _utilities.WaitForMilliseconds(100);
//A Single focus command sometimes gets lost on the #909, so sending lots of them solves the issue. //A Single focus command sometimes gets lost on the #909, so sending lots of them solves the issue.
Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
@@ -465,13 +419,13 @@ namespace ASCOM.Meade.net
//:F-# Start Focuser moving outward (away from objective) //:F-# Start Focuser moving outward (away from objective)
//Returns: None //Returns: None
utilities.WaitForMilliseconds(250); _utilities.WaitForMilliseconds(250);
} }
Halt(); Halt();
//This gives the focuser time to physically stop. //This gives the focuser time to physically stop.
utilities.WaitForMilliseconds(1000); _utilities.WaitForMilliseconds(1000);
}); });
} }
@@ -608,14 +562,7 @@ namespace ASCOM.Meade.net
/// <summary> /// <summary>
/// Returns true if there is a valid connection to the driver hardware /// Returns true if there is a valid connection to the driver hardware
/// </summary> /// </summary>
private bool IsConnected private bool IsConnected { get; set; }
{
get
{
// TODO check that the driver hardware connection exists and is connected to the hardware
return connectedState;
}
}
/// <summary> /// <summary>
/// Use this function to throw an exception if we aren't connected to the hardware /// Use this function to throw an exception if we aren't connected to the hardware