Impemented the code changes to return co-ordinated when the telescope is parked.

Also added loads of checks for if the telescope is parked.
This commit is contained in:
2021-04-24 20:52:21 +01:00
parent f4eafa668d
commit 18ea52c972
6 changed files with 97 additions and 25 deletions
@@ -90,6 +90,10 @@
<Project>{64308775-bd4a-469c-bcab-3ed830b811af}</Project> <Project>{64308775-bd4a-469c-bcab-3ed830b811af}</Project>
<Name>Meade.net.Telescope</Name> <Name>Meade.net.Telescope</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Meade.net\Meade.net.csproj">
<Project>{3689a2cb-94c5-4012-a5cf-7e7d1dd27143}</Project>
<Name>Meade.net</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
@@ -122,7 +122,6 @@
<Compile Include="AstroMaths\AstroMathExtensions.cs" /> <Compile Include="AstroMaths\AstroMathExtensions.cs" />
<Compile Include="AstroMaths\AstroMaths.cs" /> <Compile Include="AstroMaths\AstroMaths.cs" />
<Compile Include="AstroMaths\EquatorialCoordinates.cs" /> <Compile Include="AstroMaths\EquatorialCoordinates.cs" />
<Compile Include="AstroMaths\HorizonCoordinates.cs" />
<Compile Include="AstroMaths\IAstroMaths.cs" /> <Compile Include="AstroMaths\IAstroMaths.cs" />
<Compile Include="Clock.cs" /> <Compile Include="Clock.cs" />
<Compile Include="ComparisonResult.cs" /> <Compile Include="ComparisonResult.cs" />
+63
View File
@@ -878,6 +878,7 @@ namespace ASCOM.Meade.net
public void AbortSlew() public void AbortSlew()
{ {
CheckConnected("AbortSlew"); CheckConnected("AbortSlew");
CheckParked();
LogMessage("AbortSlew", "Aborting slew"); LogMessage("AbortSlew", "Aborting slew");
SharedResourcesWrapper.SendBlind(":Q#"); SharedResourcesWrapper.SendBlind(":Q#");
@@ -889,6 +890,12 @@ namespace ASCOM.Meade.net
SetSlewingMinEndTime(); SetSlewingMinEndTime();
} }
private void CheckParked()
{
if (AtPark)
throw new ParkedException("Telescope is parked");
}
public AlignmentModes AlignmentMode public AlignmentModes AlignmentMode
{ {
get get
@@ -1247,11 +1254,16 @@ namespace ASCOM.Meade.net
} }
} }
private double _lastGoodDeclination;
public double Declination public double Declination
{ {
get get
{ {
CheckConnected("Declination Get"); CheckConnected("Declination Get");
try
{
CheckParked();
var result = SharedResourcesWrapper.SendString(":GD#"); var result = SharedResourcesWrapper.SendString(":GD#");
//:GD# Get Telescope Declination. //:GD# Get Telescope Declination.
@@ -1261,8 +1273,23 @@ namespace ASCOM.Meade.net
double declination = _utilities.DMSToDegrees(result); double declination = _utilities.DMSToDegrees(result);
LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}"); LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}");
_lastGoodDeclination = declination;
return declination; return declination;
} }
catch (ParkedException)
{
switch (ParkedBehaviour)
{
case ParkedBehaviour.LastGoodPosition:
return _lastGoodDeclination;
case ParkedBehaviour.ReportCoordinates:
var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz);
return raDec.Declination;
default:
throw;
}
}
}
} }
public double DeclinationRate public double DeclinationRate
@@ -1413,6 +1440,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); LogMessage("MoveAxis", $"Axis={axis} rate={rate}");
CheckConnected("MoveAxis"); CheckConnected("MoveAxis");
CheckParked();
var absRate = Math.Abs(rate); var absRate = Math.Abs(rate);
@@ -1535,6 +1563,7 @@ namespace ASCOM.Meade.net
try try
{ {
CheckConnected("PulseGuide"); CheckConnected("PulseGuide");
CheckParked();
if (IsSlewingToTarget()) if (IsSlewingToTarget())
throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target."); throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target.");
@@ -1645,11 +1674,17 @@ namespace ASCOM.Meade.net
return _utilities.HMSToHours(hms); return _utilities.HMSToHours(hms);
} }
double _lastGoodRightAsension;
public double RightAscension public double RightAscension
{ {
get get
{ {
CheckConnected("RightAscension Get"); CheckConnected("RightAscension Get");
try
{
CheckParked();
var result = SharedResourcesWrapper.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#
@@ -1658,8 +1693,24 @@ namespace ASCOM.Meade.net
double rightAscension = HmToHours(result); double rightAscension = HmToHours(result);
LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}");
_lastGoodRightAsension = rightAscension;
return rightAscension; return rightAscension;
} }
catch (ParkedException)
{
switch (ParkedBehaviour)
{
case ParkedBehaviour.LastGoodPosition:
return _lastGoodRightAsension;
case ParkedBehaviour.ReportCoordinates:
var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz);
return raDec.RightAscension;
default:
throw;
}
}
}
} }
public double RightAscensionRate public double RightAscensionRate
@@ -1870,6 +1921,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}");
CheckConnected("SlewToAltAz"); CheckConnected("SlewToAltAz");
CheckParked();
SlewToAltAzAsync(azimuth, altitude); SlewToAltAzAsync(azimuth, altitude);
@@ -1882,6 +1934,7 @@ namespace ASCOM.Meade.net
public void SlewToAltAzAsync(double azimuth, double altitude) public void SlewToAltAzAsync(double azimuth, double altitude)
{ {
CheckConnected("SlewToAltAzAsync"); CheckConnected("SlewToAltAzAsync");
CheckParked();
if (altitude > 90) if (altitude > 90)
throw new InvalidValueException("Altitude cannot be greater than 90."); throw new InvalidValueException("Altitude cannot be greater than 90.");
@@ -1922,6 +1975,7 @@ namespace ASCOM.Meade.net
private void DoSlewAsync(bool polar) private void DoSlewAsync(bool polar)
{ {
CheckConnected("DoSlewAsync"); CheckConnected("DoSlewAsync");
CheckParked();
SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.Lock(() =>
{ {
@@ -1986,6 +2040,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}");
CheckConnected("SlewToCoordinates"); CheckConnected("SlewToCoordinates");
CheckParked();
SlewToCoordinatesAsync(rightAscension, declination); SlewToCoordinatesAsync(rightAscension, declination);
@@ -2001,6 +2056,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}"); LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}");
CheckConnected("SlewToCoordinatesAsync"); CheckConnected("SlewToCoordinatesAsync");
CheckParked();
SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.Lock(() =>
{ {
@@ -2016,6 +2072,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SlewToTarget", "Executing"); LogMessage("SlewToTarget", "Executing");
CheckConnected("SlewToTarget"); CheckConnected("SlewToTarget");
CheckParked();
SlewToTargetAsync(); SlewToTargetAsync();
while (Slewing) while (Slewing)
@@ -2029,6 +2086,7 @@ namespace ASCOM.Meade.net
public void SlewToTargetAsync() public void SlewToTargetAsync()
{ {
CheckConnected("SlewToTargetAsync"); CheckConnected("SlewToTargetAsync");
CheckParked();
if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter)) if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter))
throw new InvalidOperationException("No target selected to slew to."); throw new InvalidOperationException("No target selected to slew to.");
@@ -2167,6 +2225,7 @@ namespace ASCOM.Meade.net
LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}");
LogMessage("SyncToCoordinates", $"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}"); LogMessage("SyncToCoordinates", $"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}");
CheckConnected("SyncToCoordinates"); CheckConnected("SyncToCoordinates");
CheckParked();
SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.Lock(() =>
{ {
@@ -2181,6 +2240,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("SyncToTarget", "Executing"); LogMessage("SyncToTarget", "Executing");
CheckConnected("SyncToTarget"); CheckConnected("SyncToTarget");
CheckParked();
var result = SharedResourcesWrapper.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.
@@ -2234,6 +2294,7 @@ namespace ASCOM.Meade.net
LogMessage("TargetDeclination Set", $"{value}"); LogMessage("TargetDeclination Set", $"{value}");
CheckConnected("TargetDeclination Set"); CheckConnected("TargetDeclination Set");
CheckParked();
if (value > 90) if (value > 90)
throw new InvalidValueException("Declination cannot be greater than 90."); throw new InvalidValueException("Declination cannot be greater than 90.");
@@ -2289,6 +2350,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("TargetRightAscension Set", $"{value}"); LogMessage("TargetRightAscension Set", $"{value}");
CheckConnected("TargetRightAscension Set"); CheckConnected("TargetRightAscension Set");
CheckParked();
if (value < 0) if (value < 0)
throw new InvalidValueException("Right ascension value cannot be below 0"); throw new InvalidValueException("Right ascension value cannot be below 0");
@@ -2357,6 +2419,7 @@ namespace ASCOM.Meade.net
{ {
LogMessage("TrackingRate Set", $"{value}"); LogMessage("TrackingRate Set", $"{value}");
CheckConnected("TrackingRate Set"); CheckConnected("TrackingRate Set");
CheckParked();
switch (value) switch (value)
{ {
+2
View File
@@ -137,6 +137,7 @@
<DependentUpon>frmMain.cs</DependentUpon> <DependentUpon>frmMain.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="GarbageCollection.cs" /> <Compile Include="GarbageCollection.cs" />
<Compile Include="AstroMaths\HorizonCoordinates.cs" />
<Compile Include="LocalServer.cs" /> <Compile Include="LocalServer.cs" />
<Compile Include="MeadeTelescopeBase.cs" /> <Compile Include="MeadeTelescopeBase.cs" />
<Compile Include="ParkedBehaviour.cs" /> <Compile Include="ParkedBehaviour.cs" />
@@ -201,6 +202,7 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
+10 -6
View File
@@ -1,6 +1,7 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ASCOM.Meade.net.AstroMaths;
using ASCOM.Meade.net.Wrapper; using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities; using ASCOM.Utilities;
@@ -30,8 +31,7 @@ namespace ASCOM.Meade.net
protected short ProfileSettleTime; protected short ProfileSettleTime;
protected bool SendDateTime; protected bool SendDateTime;
protected ParkedBehaviour ParkedBehaviour; protected ParkedBehaviour ParkedBehaviour;
protected double ParkedAzimuth; protected HorizonCoordinates ParkedAltAz;
protected double ParkedAlt;
protected readonly ISharedResourcesWrapper SharedResourcesWrapper; protected readonly ISharedResourcesWrapper SharedResourcesWrapper;
@@ -75,8 +75,12 @@ namespace ASCOM.Meade.net
ProfileSettleTime = profileProperties.SettleTime; ProfileSettleTime = profileProperties.SettleTime;
SendDateTime = profileProperties.SendDateTime; SendDateTime = profileProperties.SendDateTime;
ParkedBehaviour = profileProperties.ParkedBehaviour; ParkedBehaviour = profileProperties.ParkedBehaviour;
ParkedAlt = profileProperties.ParkedAlt;
ParkedAzimuth = profileProperties.ParkedAz; var ParkedAltAz = new HorizonCoordinates
{
Altitude = profileProperties.ParkedAlt,
Azimuth = profileProperties.ParkedAz
};
LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}");
LogMessage("ReadProfile", $"Com Port: {ComPort}"); LogMessage("ReadProfile", $"Com Port: {ComPort}");
@@ -89,8 +93,8 @@ namespace ASCOM.Meade.net
LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}");
LogMessage("ReadProfile", $"Send date and time on connect: {SendDateTime}"); LogMessage("ReadProfile", $"Send date and time on connect: {SendDateTime}");
LogMessage("ReadProfile", $"Parked Behaviour: {ParkedBehaviour}"); LogMessage("ReadProfile", $"Parked Behaviour: {ParkedBehaviour}");
LogMessage("ReadProfile", $"Parked Alt: {ParkedAlt}"); LogMessage("ReadProfile", $"Parked Alt: {ParkedAltAz.Altitude}");
LogMessage("ReadProfile", $"Parked Az: {ParkedAzimuth}"); LogMessage("ReadProfile", $"Parked Az: {ParkedAltAz.Azimuth}");
} }
/// <summary> /// <summary>