Added code for the site latitude

and started work on the longitude.
This commit is contained in:
2019-05-01 00:22:15 +01:00
parent 90eb1c604b
commit ef982a3aba
6 changed files with 509 additions and 158 deletions
@@ -9,6 +9,8 @@ namespace ASCOM.MeadeAutostar497.Controller
bool Slewing { get; }
DateTime utcDate { get; set; }
double SiteLatitude { get; set; }
double SiteLongitude { get; set; }
void AbortSlew();
}
}
@@ -1,6 +1,7 @@
using System;
using System.IO.Ports;
using System.Linq;
using ASCOM.Utilities;
namespace ASCOM.MeadeAutostar497.Controller
{
@@ -165,6 +166,59 @@ namespace ASCOM.MeadeAutostar497.Controller
}
public double SiteLatitude
{
get
{
var latitude = SerialPort.CommandTerminated( ":Gt#", "#");
double lat = int.Parse(latitude.Substring(1, 2));
lat = lat + double.Parse(latitude.Substring(4, 2)) / 60;
if (latitude.Length == 9)
lat = lat + double.Parse(latitude.Substring(7, 2)) / 60 / 60;
if (latitude[0] == '-')
lat = -lat;
return lat;
}
set
{
if (value > 90)
throw new ASCOM.InvalidValueException("Latitude cannot be greater than 90 degrees.");
if (value < -90)
throw new ASCOM.InvalidValueException("Latitude cannot be less than -90 degrees.");
int dd = Convert.ToInt32(Math.Floor(value));
int mm = Convert.ToInt32(60 * (value - dd));
var result = SerialPort.CommandChar($":Sts{dd:00}*{mm:00}#");
if (result != '1')
throw new InvalidOperationException("Failed to set site latitude.");
}
}
public double SiteLongitude
{
get
{
var longitude = SerialPort.CommandTerminated(":Gg#", "#");
double l = int.Parse(longitude.Substring(0, 3));
l = l + double.Parse(longitude.Substring(4, 2)) / 60;
if (longitude.Length == 9)
l = l + double.Parse(longitude.Substring(7, 2)) / 60 / 60;
return l;
}
set
{
throw new ASCOM.PropertyNotImplementedException("not done yet.");
}
}
public void AbortSlew()
{
SerialPort.Command("#:Q#");