Switched over the Telescope and focuser to access the SharedResources via a wrapper with an interface to help with unit testing

This commit is contained in:
2019-07-08 17:15:01 +01:00
parent a0a908d67d
commit bc90049798
5 changed files with 216 additions and 117 deletions
+97 -93
View File
@@ -40,6 +40,7 @@ using ASCOM.DeviceInterface;
using System.Globalization; using System.Globalization;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using ASCOM.Meade.net.Wrapper;
namespace ASCOM.Meade.net namespace ASCOM.Meade.net
{ {
@@ -105,6 +106,8 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
internal static TraceLogger tl; internal static TraceLogger tl;
private readonly ISharedResourcesWrapper _sharedResourcesWrapper;
/// <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.
@@ -119,6 +122,7 @@ namespace ASCOM.Meade.net
_connectedState = false; // Initialise connected to false _connectedState = false; // Initialise connected to false
utilities = new Util(); //Initialise util object utilities = new Util(); //Initialise util object
astroUtilities = new AstroUtils(); // Initialise astro utilities object astroUtilities = new AstroUtils(); // Initialise astro utilities object
_sharedResourcesWrapper = new SharedResourcesWrapper();
//TODO: Implement your additional construction here //TODO: Implement your additional construction here
_astroMaths = new AstroMaths(); _astroMaths = new AstroMaths();
@@ -142,7 +146,7 @@ namespace ASCOM.Meade.net
public void SetupDialog() public void SetupDialog()
{ {
tl.LogMessage("SetupDialog", "Opening setup dialog"); tl.LogMessage("SetupDialog", "Opening setup dialog");
SharedResources.SetupDialog(); _sharedResourcesWrapper.SetupDialog();
ReadProfile(); ReadProfile();
tl.LogMessage("SetupDialog", "complete"); tl.LogMessage("SetupDialog", "complete");
//// consider only showing the setup dialog if not connected //// consider only showing the setup dialog if not connected
@@ -180,68 +184,68 @@ namespace ASCOM.Meade.net
{ {
//Read the screen //Read the screen
case "readdisplay": case "readdisplay":
var output = SharedResources.SendString(":ED#"); var output = _sharedResourcesWrapper.SendString(":ED#");
return output; return output;
//top row of buttons //top row of buttons
case "enter": case "enter":
SharedResources.SendBlind(":EK13#"); _sharedResourcesWrapper.SendBlind(":EK13#");
break; break;
case "mode": case "mode":
SharedResources.SendBlind(":EK9#"); _sharedResourcesWrapper.SendBlind(":EK9#");
break; break;
case "longMode": case "longMode":
SharedResources.SendBlind(":EK11#"); _sharedResourcesWrapper.SendBlind(":EK11#");
break; break;
case "goto": case "goto":
SharedResources.SendBlind(":EK24#"); _sharedResourcesWrapper.SendBlind(":EK24#");
break; break;
case "0": //light and 0 case "0": //light and 0
SharedResources.SendBlind(":EK48#"); _sharedResourcesWrapper.SendBlind(":EK48#");
break; break;
case "1": case "1":
SharedResources.SendBlind(":EK49#"); _sharedResourcesWrapper.SendBlind(":EK49#");
break; break;
case "2": case "2":
SharedResources.SendBlind(":EK50#"); _sharedResourcesWrapper.SendBlind(":EK50#");
break; break;
case "3": case "3":
SharedResources.SendBlind(":EK51#"); _sharedResourcesWrapper.SendBlind(":EK51#");
break; break;
case "4": case "4":
SharedResources.SendBlind(":EK52#"); _sharedResourcesWrapper.SendBlind(":EK52#");
break; break;
case "5": case "5":
SharedResources.SendBlind(":EK53#"); _sharedResourcesWrapper.SendBlind(":EK53#");
break; break;
case "6": case "6":
SharedResources.SendBlind(":EK54#"); _sharedResourcesWrapper.SendBlind(":EK54#");
break; break;
case "7": case "7":
SharedResources.SendBlind(":EK55#"); _sharedResourcesWrapper.SendBlind(":EK55#");
break; break;
case "8": case "8":
SharedResources.SendBlind(":EK56#"); _sharedResourcesWrapper.SendBlind(":EK56#");
break; break;
case "9": case "9":
SharedResources.SendBlind(":EK57#"); _sharedResourcesWrapper.SendBlind(":EK57#");
break; break;
case "up": case "up":
SharedResources.SendBlind(":EK94#"); _sharedResourcesWrapper.SendBlind(":EK94#");
break; break;
case "down": case "down":
SharedResources.SendBlind(":EK118#"); _sharedResourcesWrapper.SendBlind(":EK118#");
break; break;
case "back": case "back":
SharedResources.SendBlind(":EK87#"); _sharedResourcesWrapper.SendBlind(":EK87#");
break; break;
case "forward": case "forward":
SharedResources.SendBlind(":EK69#"); _sharedResourcesWrapper.SendBlind(":EK69#");
break; break;
case "?": case "?":
SharedResources.SendBlind(":EK63#"); _sharedResourcesWrapper.SendBlind(":EK63#");
break; break;
default: default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
@@ -261,7 +265,7 @@ namespace ASCOM.Meade.net
CheckConnected("CommandBlind"); CheckConnected("CommandBlind");
// Call CommandString and return as soon as it finishes // Call CommandString and return as soon as it finishes
//this.CommandString(command, raw); //this.CommandString(command, raw);
SharedResources.SendBlind(command); _sharedResourcesWrapper.SendBlind(command);
// or // or
//throw new ASCOM.MethodNotImplementedException("CommandBlind"); //throw new ASCOM.MethodNotImplementedException("CommandBlind");
// DO NOT have both these sections! One or the other // DO NOT have both these sections! One or the other
@@ -283,7 +287,7 @@ namespace ASCOM.Meade.net
// it's a good idea to put all the low level communication with the device here, // it's a good idea to put all the low level communication with the device here,
// then all communication calls this function // then all communication calls this function
// you need something to ensure that only one command is in progress at a time // you need something to ensure that only one command is in progress at a time
return SharedResources.SendString(command); return _sharedResourcesWrapper.SendString(command);
//throw new ASCOM.MethodNotImplementedException("CommandString"); //throw new ASCOM.MethodNotImplementedException("CommandString");
} }
@@ -317,10 +321,10 @@ namespace ASCOM.Meade.net
LogMessage("Connected Set", "Connecting to port {0}", comPort); LogMessage("Connected Set", "Connecting to port {0}", comPort);
try try
{ {
SharedResources.Connect("Serial"); _sharedResourcesWrapper.Connect("Serial");
try try
{ {
LogMessage("Connected Set", $"Commented to port {comPort}. Product: {SharedResources.ProductName} Version:{SharedResources.FirmwareVersion}"); LogMessage("Connected Set", $"Commented to port {comPort}. Product: {_sharedResourcesWrapper.ProductName} Version:{_sharedResourcesWrapper.FirmwareVersion}");
SelectSite(1); SelectSite(1);
@@ -333,7 +337,7 @@ namespace ASCOM.Meade.net
} }
catch (Exception) catch (Exception)
{ {
SharedResources.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
throw; throw;
} }
} }
@@ -345,7 +349,7 @@ namespace ASCOM.Meade.net
else else
{ {
LogMessage("Connected Set", "Disconnecting from port {0}", comPort); LogMessage("Connected Set", "Disconnecting from port {0}", comPort);
SharedResources.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
_connectedState = false; _connectedState = false;
} }
} }
@@ -353,9 +357,9 @@ namespace ASCOM.Meade.net
private bool IsNewPulseGuidingSupported() private bool IsNewPulseGuidingSupported()
{ {
if (SharedResources.ProductName == SharedResources.AUTOSTAR497) if (_sharedResourcesWrapper.ProductName == _sharedResourcesWrapper.AUTOSTAR497)
{ {
return FirmwareIsGreaterThan(SharedResources.AUTOSTAR497_31EE); return FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_31EE);
} }
return false; return false;
@@ -363,16 +367,16 @@ namespace ASCOM.Meade.net
private bool FirmwareIsGreaterThan(string minVersion) private bool FirmwareIsGreaterThan(string minVersion)
{ {
var currentVersion = SharedResources.FirmwareVersion; var currentVersion = _sharedResourcesWrapper.FirmwareVersion;
var comparison = currentVersion.CompareTo(minVersion); var comparison = currentVersion.CompareTo(minVersion);
return (comparison >= 0); return (comparison >= 0);
} }
private void SetLongFormat(bool setLongFormat) private void SetLongFormat(bool setLongFormat)
{ {
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
var result = SharedResources.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#
//The current telescope Azimuth depending on the selected precision. //The current telescope Azimuth depending on the selected precision.
@@ -382,7 +386,7 @@ namespace ASCOM.Meade.net
if (isLongFormat != setLongFormat) if (isLongFormat != setLongFormat)
{ {
utilities.WaitForMilliseconds(500); utilities.WaitForMilliseconds(500);
SharedResources.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
//High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS
@@ -393,7 +397,7 @@ namespace ASCOM.Meade.net
private void SelectSite(int site) private void SelectSite(int site)
{ {
SharedResources.SendBlind($":W{site}#"); _sharedResourcesWrapper.SendBlind($":W{site}#");
//:W<n># //:W<n>#
//Set current site to<n>, an ASCII digit in the range 1..4 //Set current site to<n>, an ASCII digit in the range 1..4
//Returns: Nothing //Returns: Nothing
@@ -450,11 +454,11 @@ namespace ASCOM.Meade.net
{ {
//string name = "Short driver name - please customise"; //string name = "Short driver name - please customise";
//var telescopeProduceName = SharedResources.SendString(":GVP#"); //var telescopeProduceName = _sharedResourcesWrapper.SendString(":GVP#");
////:GVP# Get Telescope Product Name ////:GVP# Get Telescope Product Name
////Returns: <string># ////Returns: <string>#
//var firmwareVersion = SharedResources.SendString(":GVN#"); //var firmwareVersion = _sharedResourcesWrapper.SendString(":GVN#");
////:GVN# Get Telescope Firmware Number ////:GVN# Get Telescope Firmware Number
////Returns: dd.d# ////Returns: dd.d#
@@ -474,7 +478,7 @@ namespace ASCOM.Meade.net
CheckConnected("AbortSlew"); CheckConnected("AbortSlew");
tl.LogMessage("AbortSlew", "Aborting slew"); tl.LogMessage("AbortSlew", "Aborting slew");
SharedResources.SendBlind(":Q#"); _sharedResourcesWrapper.SendBlind(":Q#");
//:Q# Halt all current slewing //:Q# Halt all current slewing
//Returns:Nothing //Returns:Nothing
} }
@@ -489,7 +493,7 @@ namespace ASCOM.Meade.net
const char ack = (char) 6; const char ack = (char) 6;
var alignmentString = SharedResources.SendChar(ack.ToString()); var alignmentString = _sharedResourcesWrapper.SendChar(ack.ToString());
//ACK <0x06> Query of alignment mounting mode. //ACK <0x06> Query of alignment mounting mode.
//Returns: //Returns:
//A If scope in AltAz Mode //A If scope in AltAz Mode
@@ -533,13 +537,13 @@ namespace ASCOM.Meade.net
switch (value) switch (value)
{ {
case AlignmentModes.algAltAz: case AlignmentModes.algAltAz:
SharedResources.SendBlind(":AA#"); _sharedResourcesWrapper.SendBlind(":AA#");
//:AA# Sets telescope the AltAz alignment mode //:AA# Sets telescope the AltAz alignment mode
//Returns: nothing //Returns: nothing
break; break;
case AlignmentModes.algPolar: case AlignmentModes.algPolar:
case AlignmentModes.algGermanPolar: case AlignmentModes.algGermanPolar:
SharedResources.SendBlind(":AP#"); _sharedResourcesWrapper.SendBlind(":AP#");
//:AP# Sets telescope to Polar alignment mode //:AP# Sets telescope to Polar alignment mode
//Returns: nothing //Returns: nothing
break; break;
@@ -563,7 +567,7 @@ namespace ASCOM.Meade.net
return altAz.Altitude; return altAz.Altitude;
////todo firmware bug in 44Eg, :GA# is returning the dec, not the altitude! ////todo firmware bug in 44Eg, :GA# is returning the dec, not the altitude!
//var result = SharedResources.SendString(":GA#"); //var result = _sharedResourcesWrapper.SendString(":GA#");
////:GA# Get Telescope Altitude ////:GA# Get Telescope Altitude
////Returns: sDD* MM# or sDD*MMSS# ////Returns: sDD* MM# or sDD*MMSS#
////The current scope altitude. The returned format depending on the current precision setting. ////The current scope altitude. The returned format depending on the current precision setting.
@@ -579,7 +583,7 @@ namespace ASCOM.Meade.net
private HorizonCoordinates CalcAltAzFromTelescopeEqData() private HorizonCoordinates CalcAltAzFromTelescopeEqData()
{ {
var altitudeData = SharedResources.Lock(() => new AltitudeData var altitudeData = _sharedResourcesWrapper.Lock(() => new AltitudeData
{ {
UtcDateTime = this.UTCDate, UtcDateTime = this.UTCDate,
SiteLongitude = this.SiteLongitude, SiteLongitude = this.SiteLongitude,
@@ -648,7 +652,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("Azimuth get"); CheckConnected("Azimuth get");
//var result = SharedResources.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#
//The current telescope Azimuth depending on the selected precision. //The current telescope Azimuth depending on the selected precision.
@@ -826,7 +830,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("Declination Get"); CheckConnected("Declination Get");
var result = SharedResources.SendString(":GD#"); var result = _sharedResourcesWrapper.SendString(":GD#");
//:GD# Get Telescope Declination. //:GD# Get Telescope Declination.
//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.
@@ -952,22 +956,22 @@ namespace ASCOM.Meade.net
//do nothing, it's ok this time as we're halting the slew. //do nothing, it's ok this time as we're halting the slew.
break; break;
case 1: case 1:
SharedResources.SendBlind(":RG#"); _sharedResourcesWrapper.SendBlind(":RG#");
//:RG# Set Slew rate to Guiding Rate (slowest) //:RG# Set Slew rate to Guiding Rate (slowest)
//Returns: Nothing //Returns: Nothing
break; break;
case 2: case 2:
SharedResources.SendBlind(":RC#"); _sharedResourcesWrapper.SendBlind(":RC#");
//:RC# Set Slew rate to Centering rate (2nd slowest) //:RC# Set Slew rate to Centering rate (2nd slowest)
//Returns: Nothing //Returns: Nothing
break; break;
case 3: case 3:
SharedResources.SendBlind(":RM#"); _sharedResourcesWrapper.SendBlind(":RM#");
//:RM# Set Slew rate to Find Rate (2nd Fastest) //:RM# Set Slew rate to Find Rate (2nd Fastest)
//Returns: Nothing //Returns: Nothing
break; break;
case 4: case 4:
SharedResources.SendBlind(":RS#"); _sharedResourcesWrapper.SendBlind(":RS#");
//:RS# Set Slew rate to max (fastest) //:RS# Set Slew rate to max (fastest)
//Returns: Nothing //Returns: Nothing
break; break;
@@ -981,23 +985,23 @@ namespace ASCOM.Meade.net
if (rate == 0) if (rate == 0)
{ {
_movingPrimary = false; _movingPrimary = false;
SharedResources.SendBlind(":Qe#"); _sharedResourcesWrapper.SendBlind(":Qe#");
//:Qe# Halt eastward Slews //:Qe# Halt eastward Slews
//Returns: Nothing //Returns: Nothing
SharedResources.SendBlind(":Qw#"); _sharedResourcesWrapper.SendBlind(":Qw#");
//:Qw# Halt westward Slews //:Qw# Halt westward Slews
//Returns: Nothing //Returns: Nothing
} }
else if (rate > 0) else if (rate > 0)
{ {
SharedResources.SendBlind(":Me#"); _sharedResourcesWrapper.SendBlind(":Me#");
//:Me# Move Telescope East at current slew rate //:Me# Move Telescope East at current slew rate
//Returns: Nothing //Returns: Nothing
_movingPrimary = true; _movingPrimary = true;
} }
else else
{ {
SharedResources.SendBlind(":Mw#"); _sharedResourcesWrapper.SendBlind(":Mw#");
//:Mw# Move Telescope West at current slew rate //:Mw# Move Telescope West at current slew rate
//Returns: Nothing //Returns: Nothing
_movingPrimary = true; _movingPrimary = true;
@@ -1008,23 +1012,23 @@ namespace ASCOM.Meade.net
if (rate == 0) if (rate == 0)
{ {
_movingSecondary = false; _movingSecondary = false;
SharedResources.SendBlind(":Qn#"); _sharedResourcesWrapper.SendBlind(":Qn#");
//:Qn# Halt northward Slews //:Qn# Halt northward Slews
//Returns: Nothing //Returns: Nothing
SharedResources.SendBlind(":Qs#"); _sharedResourcesWrapper.SendBlind(":Qs#");
//:Qs# Halt southward Slews //:Qs# Halt southward Slews
//Returns: Nothing //Returns: Nothing
} }
else if (rate > 0) else if (rate > 0)
{ {
SharedResources.SendBlind(":Mn#"); _sharedResourcesWrapper.SendBlind(":Mn#");
//:Mn# Move Telescope North at current slew rate //:Mn# Move Telescope North at current slew rate
//Returns: Nothing //Returns: Nothing
_movingSecondary = true; _movingSecondary = true;
} }
else else
{ {
SharedResources.SendBlind(":Ms#"); _sharedResourcesWrapper.SendBlind(":Ms#");
//:Ms# Move Telescope South at current slew rate //:Ms# Move Telescope South at current slew rate
//Returns: Nothing //Returns: Nothing
_movingSecondary = true; _movingSecondary = true;
@@ -1044,7 +1048,7 @@ namespace ASCOM.Meade.net
if (AtPark) if (AtPark)
return; return;
SharedResources.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
AtPark = true; AtPark = true;
@@ -1076,7 +1080,7 @@ namespace ASCOM.Meade.net
if (_userNewerPulseGuiding) if (_userNewerPulseGuiding)
{ {
SharedResources.SendBlind($":Mg{d}{duration:0000}#"); _sharedResourcesWrapper.SendBlind($":Mg{d}{duration:0000}#");
//:MgnDDDD# //:MgnDDDD#
//:MgsDDDD# //:MgsDDDD#
//:MgeDDDD# //:MgeDDDD#
@@ -1090,12 +1094,12 @@ namespace ASCOM.Meade.net
} }
else else
{ {
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
SharedResources.SendBlind(":RG#"); //Make sure we are at guide rate _sharedResourcesWrapper.SendBlind(":RG#"); //Make sure we are at guide rate
//:RG# Set Slew rate to Guiding Rate (slowest) //:RG# Set Slew rate to Guiding Rate (slowest)
//Returns: Nothing //Returns: Nothing
SharedResources.SendBlind($":M{d}#"); _sharedResourcesWrapper.SendBlind($":M{d}#");
//:Me# Move Telescope East at current slew rate //:Me# Move Telescope East at current slew rate
//Returns: Nothing //Returns: Nothing
//:Mn# Move Telescope North at current slew rate //:Mn# Move Telescope North at current slew rate
@@ -1105,7 +1109,7 @@ namespace ASCOM.Meade.net
//: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);
SharedResources.SendBlind($":Q{d}#"); _sharedResourcesWrapper.SendBlind($":Q{d}#");
//:Qe# Halt eastward Slews //:Qe# Halt eastward Slews
//Returns: Nothing //Returns: Nothing
//:Qn# Halt northward Slews //:Qn# Halt northward Slews
@@ -1123,7 +1127,7 @@ namespace ASCOM.Meade.net
get get
{ {
CheckConnected("RightAscension Get"); CheckConnected("RightAscension Get");
var result = SharedResources.SendString(":GR#"); var result = _sharedResourcesWrapper.SendString(":GR#");
//:GR# Get Telescope RA //:GR# Get Telescope RA
//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
@@ -1216,7 +1220,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("SiteLatitude Get"); CheckConnected("SiteLatitude Get");
var latitude = SharedResources.SendString(":Gt#"); var latitude = _sharedResourcesWrapper.SendString(":Gt#");
//:Gt# Get Current Site Latitude //:Gt# Get Current Site Latitude
//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.
@@ -1241,7 +1245,7 @@ namespace ASCOM.Meade.net
int d = Convert.ToInt32(Math.Floor(value)); int d = Convert.ToInt32(Math.Floor(value));
int m = Convert.ToInt32(60 * (value - d)); int m = Convert.ToInt32(60 * (value - d));
var result = SharedResources.SendChar($":St{sign}{d:00}*{m:00}#"); var result = _sharedResourcesWrapper.SendChar($":St{sign}{d:00}*{m:00}#");
//:StsDD*MM# //:StsDD*MM#
//Sets the current site latitude to sDD* MM# //Sets the current site latitude to sDD* MM#
//Returns: //Returns:
@@ -1258,7 +1262,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("SiteLongitude Get"); CheckConnected("SiteLongitude Get");
var longitude = SharedResources.SendString(":Gg#"); var longitude = _sharedResourcesWrapper.SendString(":Gg#");
//: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
@@ -1294,7 +1298,7 @@ namespace ASCOM.Meade.net
int d = Convert.ToInt32(Math.Floor(newLongitude)); int d = Convert.ToInt32(Math.Floor(newLongitude));
int m = Convert.ToInt32(60 * (newLongitude - d)); int m = Convert.ToInt32(60 * (newLongitude - d));
var result = SharedResources.SendChar($":Sg{d:000}*{m:00}#"); var result = _sharedResourcesWrapper.SendChar($":Sg{d:000}*{m:00}#");
//:SgDDD*MM# //:SgDDD*MM#
//Set current sites longitude to DDD*MM an ASCII position string //Set current sites longitude to DDD*MM an ASCII position string
//Returns: //Returns:
@@ -1349,7 +1353,7 @@ namespace ASCOM.Meade.net
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 = SharedResources.SendChar($":Sa{s}{dms}#"); var result = _sharedResourcesWrapper.SendChar($":Sa{s}{dms}#");
//:SasDD*MM# //:SasDD*MM#
//Set target object altitude to sDD*MM# or sDD*MMSS# [LX 16”, Autostar, Autostar II] //Set target object altitude to sDD*MM# or sDD*MMSS# [LX 16”, Autostar, Autostar II]
//Returns: //Returns:
@@ -1377,7 +1381,7 @@ namespace ASCOM.Meade.net
var dms = utilities.DegreesToDM(value, "*" ); var dms = utilities.DegreesToDM(value, "*" );
var result = SharedResources.SendChar($":Sz{dms}#"); var result = _sharedResourcesWrapper.SendChar($":Sz{dms}#");
//:SzDDD*MM# //:SzDDD*MM#
//Sets the target Object Azimuth[LX 16” and Autostar II only] //Sets the target Object Azimuth[LX 16” and Autostar II only]
//Returns: //Returns:
@@ -1415,7 +1419,7 @@ namespace ASCOM.Meade.net
var latitude = SiteLatitude; var latitude = SiteLatitude;
var longitude = SiteLongitude; var longitude = SiteLongitude;
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz);
@@ -1435,12 +1439,12 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("DoSlewAsync"); CheckConnected("DoSlewAsync");
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
switch (polar) switch (polar)
{ {
case true: case true:
var response = SharedResources.SendChar(":MS#"); var response = _sharedResourcesWrapper.SendChar(":MS#");
//:MS# Slew to Target Object //:MS# Slew to Target Object
//Returns: //Returns:
//0 Slew is Possible //0 Slew is Possible
@@ -1455,12 +1459,12 @@ namespace ASCOM.Meade.net
break; break;
case "1": case "1":
//Below Horizon //Below Horizon
string belowHorizonMessage = SharedResources.ReadTerminated(); string belowHorizonMessage = _sharedResourcesWrapper.ReadTerminated();
tl.LogMessage("DoSlewAsync", $"Slew failed \"{belowHorizonMessage}\""); tl.LogMessage("DoSlewAsync", $"Slew failed \"{belowHorizonMessage}\"");
throw new ASCOM.InvalidOperationException(belowHorizonMessage); throw new ASCOM.InvalidOperationException(belowHorizonMessage);
case "2": case "2":
//Below Horizon //Below Horizon
string belowMinimumElevationMessage = SharedResources.ReadTerminated(); string belowMinimumElevationMessage = _sharedResourcesWrapper.ReadTerminated();
tl.LogMessage("DoSlewAsync", $"Slew failed \"{belowMinimumElevationMessage}\""); tl.LogMessage("DoSlewAsync", $"Slew failed \"{belowMinimumElevationMessage}\"");
throw new ASCOM.InvalidOperationException(belowMinimumElevationMessage); throw new ASCOM.InvalidOperationException(belowMinimumElevationMessage);
default: default:
@@ -1471,7 +1475,7 @@ namespace ASCOM.Meade.net
break; break;
case false: case false:
var maResponse = SharedResources.SendChar(":MA#"); var maResponse = _sharedResourcesWrapper.SendChar(":MA#");
//:MA# Autostar, LX 16”, Autostar II Slew to target Alt and Az //:MA# Autostar, LX 16”, Autostar II Slew to target Alt and Az
//Returns: //Returns:
//0 - No fault //0 - No fault
@@ -1508,7 +1512,7 @@ namespace ASCOM.Meade.net
tl.LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}"); tl.LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}");
CheckConnected("SlewToCoordinatesAsync"); CheckConnected("SlewToCoordinatesAsync");
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
TargetRightAscension = rightAscension; TargetRightAscension = rightAscension;
TargetDeclination = declination; TargetDeclination = declination;
@@ -1559,7 +1563,7 @@ namespace ASCOM.Meade.net
CheckConnected("Slewing Get"); CheckConnected("Slewing Get");
var result = SharedResources.SendString(":D#"); var result = _sharedResourcesWrapper.SendString(":D#");
//:D# Requests a string of bars indicating the distance to the current target location. //:D# Requests a string of bars indicating the distance to the current target location.
//Returns: //Returns:
//LX200's a string of bar characters indicating the distance. //LX200's a string of bar characters indicating the distance.
@@ -1582,7 +1586,7 @@ namespace ASCOM.Meade.net
tl.LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); tl.LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}");
CheckConnected("SyncToCoordinates"); CheckConnected("SyncToCoordinates");
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
TargetRightAscension = rightAscension; TargetRightAscension = rightAscension;
TargetDeclination = declination; TargetDeclination = declination;
@@ -1596,7 +1600,7 @@ namespace ASCOM.Meade.net
tl.LogMessage("SyncToTarget", "Executing"); tl.LogMessage("SyncToTarget", "Executing");
CheckConnected("SyncToTarget"); CheckConnected("SyncToTarget");
var result = SharedResources.SendString(":CM#"); var result = _sharedResourcesWrapper.SendString(":CM#");
//:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates.
//Returns: //Returns:
//LX200's - a "#" terminated string with the name of the object that was synced. //LX200's - a "#" terminated string with the name of the object that was synced.
@@ -1645,7 +1649,7 @@ namespace ASCOM.Meade.net
var command = $":Sd{s}{dms}#"; var command = $":Sd{s}{dms}#";
tl.LogMessage("TargetDeclination Set", $"{command}"); tl.LogMessage("TargetDeclination Set", $"{command}");
var result = SharedResources.SendChar(command); var result = _sharedResourcesWrapper.SendChar(command);
//:SdsDD*MM# //:SdsDD*MM#
//Set target object declination to sDD*MM or sDD*MM:SS depending on the current precision setting //Set target object declination to sDD*MM or sDD*MM:SS depending on the current precision setting
//Returns: //Returns:
@@ -1694,7 +1698,7 @@ namespace ASCOM.Meade.net
//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 = SharedResources.SendChar($":Sr{hms}#"); var response = _sharedResourcesWrapper.SendChar($":Sr{hms}#");
//:SrHH:MM.T# //:SrHH:MM.T#
//:SrHH:MM:SS# //:SrHH:MM:SS#
//Set target object RA to HH:MM.T or HH: MM: SS depending on the current precision setting. //Set target object RA to HH:MM.T or HH: MM: SS depending on the current precision setting.
@@ -1753,12 +1757,12 @@ namespace ASCOM.Meade.net
switch (value) switch (value)
{ {
case DriveRates.driveSidereal: case DriveRates.driveSidereal:
SharedResources.SendBlind(":TQ#"); _sharedResourcesWrapper.SendBlind(":TQ#");
//:TQ# Selects sidereal tracking rate //:TQ# Selects sidereal tracking rate
//Returns: Nothing //Returns: Nothing
break; break;
case DriveRates.driveLunar: case DriveRates.driveLunar:
SharedResources.SendBlind(":TL#"); _sharedResourcesWrapper.SendBlind(":TL#");
//:TL# Set Lunar Tracking Rage //:TL# Set Lunar Tracking Rage
//Returns: Nothing //Returns: Nothing
break; break;
@@ -1797,7 +1801,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("GetUtcCorrection"); CheckConnected("GetUtcCorrection");
string utcOffSet = SharedResources.SendString(":GG#"); string utcOffSet = _sharedResourcesWrapper.SendString(":GG#");
//:GG# Get UTC offset time //:GG# Get UTC offset time
//Returns: sHH# or sHH.H# //Returns: sHH# or sHH.H#
//The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the
@@ -1822,14 +1826,14 @@ namespace ASCOM.Meade.net
tl.LogMessage("UTCDate", "Get started"); tl.LogMessage("UTCDate", "Get started");
TelescopeDateDetails telescopeDateDetails = SharedResources.Lock(() => TelescopeDateDetails telescopeDateDetails = _sharedResourcesWrapper.Lock(() =>
{ {
TelescopeDateDetails tdd = new TelescopeDateDetails(); TelescopeDateDetails tdd = new TelescopeDateDetails();
tdd.telescopeDate = SharedResources.SendString(":GC#"); tdd.telescopeDate = _sharedResourcesWrapper.SendString(":GC#");
//:GC# Get current date. //:GC# Get current date.
//Returns: MM / DD / YY# //Returns: MM / DD / YY#
//The current local calendar date for the telescope. //The current local calendar date for the telescope.
tdd.telescopeTime = SharedResources.SendString(":GL#"); tdd.telescopeTime = _sharedResourcesWrapper.SendString(":GL#");
//:GL# Get Local Time in 24 hour format //:GL# Get Local Time in 24 hour format
//Returns: HH: MM: SS# //Returns: HH: MM: SS#
//The Local Time in 24 - hour Format //The Local Time in 24 - hour Format
@@ -1864,12 +1868,12 @@ namespace ASCOM.Meade.net
CheckConnected("UTCDate Set"); CheckConnected("UTCDate Set");
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
var utcCorrection = GetUtcCorrection(); var utcCorrection = GetUtcCorrection();
var localDateTime = value - utcCorrection; var localDateTime = value - utcCorrection;
var timeResult = SharedResources.SendChar($":SL{localDateTime:HH:mm:ss}#"); var timeResult = _sharedResourcesWrapper.SendChar($":SL{localDateTime:HH:mm:ss}#");
//:SLHH:MM:SS# //:SLHH:MM:SS#
//Set the local Time //Set the local Time
//Returns: //Returns:
@@ -1880,7 +1884,7 @@ namespace ASCOM.Meade.net
throw new InvalidOperationException("Failed to set local time"); throw new InvalidOperationException("Failed to set local time");
} }
var dateResult = SharedResources.SendChar($":SC{localDateTime:MM/dd/yy}#"); var dateResult = _sharedResourcesWrapper.SendChar($":SC{localDateTime:MM/dd/yy}#");
//:SCMM/DD/YY# //:SCMM/DD/YY#
//Change Handbox Date to MM/DD/YY //Change Handbox Date to MM/DD/YY
//Returns: <D><string> //Returns: <D><string>
@@ -1893,8 +1897,8 @@ namespace ASCOM.Meade.net
} }
//throwing away these two strings which represent //throwing away these two strings which represent
SharedResources.ReadTerminated(); //Updating Planetary Data# _sharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data#
SharedResources.ReadTerminated(); // # _sharedResourcesWrapper.ReadTerminated(); // #
}); });
} }
} }
@@ -2014,7 +2018,7 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
internal void ReadProfile() internal void ReadProfile()
{ {
var profileProperties = SharedResources.ReadProfile(); var profileProperties = _sharedResourcesWrapper.ReadProfile();
tl.Enabled = profileProperties.TraceLogger; tl.Enabled = profileProperties.TraceLogger;
comPort = profileProperties.ComPort; comPort = profileProperties.ComPort;
} }
+19 -15
View File
@@ -40,6 +40,7 @@ using ASCOM.DeviceInterface;
using System.Globalization; using System.Globalization;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities.Interfaces; using ASCOM.Utilities.Interfaces;
namespace ASCOM.Meade.net namespace ASCOM.Meade.net
@@ -103,6 +104,8 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
internal static TraceLogger tl; internal static TraceLogger tl;
private readonly ISharedResourcesWrapper _sharedResourcesWrapper;
/// <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.
@@ -117,6 +120,7 @@ namespace ASCOM.Meade.net
connectedState = false; // Initialise connected to false connectedState = false; // Initialise connected to false
utilities = new Util(); //Initialise util object utilities = new Util(); //Initialise util object
astroUtilities = new AstroUtils(); // Initialise astro utilities object astroUtilities = new AstroUtils(); // Initialise astro utilities object
_sharedResourcesWrapper = new SharedResourcesWrapper();
tl.LogMessage("Focuser", "Completed initialisation"); tl.LogMessage("Focuser", "Completed initialisation");
} }
@@ -137,7 +141,7 @@ namespace ASCOM.Meade.net
public void SetupDialog() public void SetupDialog()
{ {
tl.LogMessage("SetupDialog", "Opening setup dialog"); tl.LogMessage("SetupDialog", "Opening setup dialog");
SharedResources.SetupDialog(); _sharedResourcesWrapper.SetupDialog();
ReadProfile(); ReadProfile();
tl.LogMessage("SetupDialog", "complete"); tl.LogMessage("SetupDialog", "complete");
} }
@@ -162,7 +166,7 @@ namespace ASCOM.Meade.net
CheckConnected("CommandBlind"); CheckConnected("CommandBlind");
// Call CommandString and return as soon as it finishes // Call CommandString and return as soon as it finishes
//this.CommandString(command, raw); //this.CommandString(command, raw);
SharedResources.SendBlind(command); _sharedResourcesWrapper.SendBlind(command);
// or // or
//throw new ASCOM.MethodNotImplementedException("CommandBlind"); //throw new ASCOM.MethodNotImplementedException("CommandBlind");
// DO NOT have both these sections! One or the other // DO NOT have both these sections! One or the other
@@ -184,7 +188,7 @@ namespace ASCOM.Meade.net
// it's a good idea to put all the low level communication with the device here, // it's a good idea to put all the low level communication with the device here,
// then all communication calls this function // then all communication calls this function
// you need something to ensure that only one command is in progress at a time // you need something to ensure that only one command is in progress at a time
return SharedResources.SendString(command); return _sharedResourcesWrapper.SendString(command);
throw new ASCOM.MethodNotImplementedException("CommandString"); throw new ASCOM.MethodNotImplementedException("CommandString");
} }
@@ -218,7 +222,7 @@ namespace ASCOM.Meade.net
{ {
try try
{ {
SharedResources.Connect("Serial"); _sharedResourcesWrapper.Connect("Serial");
try try
{ {
SelectSite(1); SelectSite(1);
@@ -228,7 +232,7 @@ namespace ASCOM.Meade.net
} }
catch (Exception) catch (Exception)
{ {
SharedResources.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
throw; throw;
} }
} }
@@ -240,7 +244,7 @@ namespace ASCOM.Meade.net
else else
{ {
LogMessage("Connected Set", "Disconnecting from port {0}", comPort); LogMessage("Connected Set", "Disconnecting from port {0}", comPort);
SharedResources.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
connectedState = false; connectedState = false;
} }
} }
@@ -248,9 +252,9 @@ namespace ASCOM.Meade.net
private void SetLongFormat(bool setLongFormat) private void SetLongFormat(bool setLongFormat)
{ {
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
var result = SharedResources.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#
//The current telescope Azimuth depending on the selected precision. //The current telescope Azimuth depending on the selected precision.
@@ -260,7 +264,7 @@ namespace ASCOM.Meade.net
if (isLongFormat != setLongFormat) if (isLongFormat != setLongFormat)
{ {
utilities.WaitForMilliseconds(500); utilities.WaitForMilliseconds(500);
SharedResources.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
//High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS
@@ -271,7 +275,7 @@ namespace ASCOM.Meade.net
private void SelectSite(int site) private void SelectSite(int site)
{ {
SharedResources.SendBlind($":W{site}#"); _sharedResourcesWrapper.SendBlind($":W{site}#");
//:W<n># //:W<n>#
//Set current site to<n>, an ASCII digit in the range 1..4 //Set current site to<n>, an ASCII digit in the range 1..4
//Returns: Nothing //Returns: Nothing
@@ -354,7 +358,7 @@ namespace ASCOM.Meade.net
Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 1000) while (stopwatch.ElapsedMilliseconds < 1000)
{ {
SharedResources.SendBlind(":FQ#"); _sharedResourcesWrapper.SendBlind(":FQ#");
//:FQ# Halt Focuser Motion //:FQ# Halt Focuser Motion
//Returns: Nothing //Returns: Nothing
@@ -436,9 +440,9 @@ namespace ASCOM.Meade.net
private void MoveFocuser(bool directionOut, int steps) private void MoveFocuser(bool directionOut, int steps)
{ {
SharedResources.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
//SharedResources.SendBlind(":FF#"); //_sharedResourcesWrapper.SendBlind(":FF#");
//:FF# Set Focus speed to fastest setting //:FF# Set Focus speed to fastest setting
//Returns: Nothing //Returns: Nothing
@@ -454,7 +458,7 @@ namespace ASCOM.Meade.net
Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < steps) while (stopwatch.ElapsedMilliseconds < steps)
{ {
SharedResources.SendBlind(directionOut ? ":F+#" : ":F-#"); _sharedResourcesWrapper.SendBlind(directionOut ? ":F+#" : ":F-#");
//:F+# Start Focuser moving inward (toward objective) //:F+# Start Focuser moving inward (toward objective)
//Returns: None //Returns: None
@@ -630,7 +634,7 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
internal void ReadProfile() internal void ReadProfile()
{ {
var profileProperties = SharedResources.ReadProfile(); var profileProperties = _sharedResourcesWrapper.ReadProfile();
tl.Enabled = profileProperties.TraceLogger; tl.Enabled = profileProperties.TraceLogger;
comPort = profileProperties.ComPort; comPort = profileProperties.ComPort;
} }
+1
View File
@@ -103,6 +103,7 @@
<Compile Include="Localization\LocalisationHelper.cs" /> <Compile Include="Localization\LocalisationHelper.cs" />
<Compile Include="LocalServer.cs" /> <Compile Include="LocalServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wrapper\SharedResourcesWrapper.cs" />
<EmbeddedResource Include="frmMain.resx"> <EmbeddedResource Include="frmMain.resx">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<DependentUpon>frmMain.cs</DependentUpon> <DependentUpon>frmMain.cs</DependentUpon>
-8
View File
@@ -234,14 +234,6 @@ namespace ASCOM.Meade.net
#endregion #endregion
#region AutostarProducts
public const string AUTOSTAR497 = "Autostar";
public const string AUTOSTAR497_31EE = "31Ee";
#endregion
#region Multi Driver handling #region Multi Driver handling
public static string ProductName { get; private set; } = string.Empty; public static string ProductName { get; private set; } = string.Empty;
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ASCOM.Meade.net.Wrapper
{
public interface ISharedResourcesWrapper
{
string AUTOSTAR497 { get; }
string AUTOSTAR497_31EE { get; }
void Connect(string deviceId);
void Disconnect(string deviceId);
string ProductName { get; }
string FirmwareVersion { get; }
void Lock(Action action);
T Lock<T>(Func<T> func);
string SendString(string message);
void SendBlind(string message);
string SendChar(string message);
string ReadTerminated();
ProfileProperties ReadProfile();
void SetupDialog();
}
public class SharedResourcesWrapper : ISharedResourcesWrapper
{
#region AutostarProducts
public string AUTOSTAR497 => "Autostar";
public string AUTOSTAR497_31EE => "31Ee";
#endregion
public void Connect(string deviceId)
{
SharedResources.Connect( deviceId);
}
public void Disconnect(string deviceId)
{
SharedResources.Disconnect(deviceId);
}
public string ProductName => SharedResources.ProductName;
public string FirmwareVersion => SharedResources.FirmwareVersion;
public void Lock(Action action)
{
SharedResources.Lock(action);
}
public T Lock<T>(Func<T> func)
{
return SharedResources.Lock(func);
}
public string SendString(string message)
{
return SharedResources.SendString(message);
}
public void SendBlind(string message)
{
SharedResources.SendBlind(message);
}
public string SendChar(string message)
{
return SharedResources.SendChar(message);
}
public string ReadTerminated()
{
return SharedResources.ReadTerminated();
}
public ProfileProperties ReadProfile()
{
return SharedResources.ReadProfile();
}
public void SetupDialog()
{
SharedResources.SetupDialog();
}
}
}