Added support for UTC offset.
This commit is contained in:
@@ -32,6 +32,7 @@ namespace MeadeAutostar497.UnitTests
|
|||||||
serialMock.Setup(x => x.IsOpen).Returns(() => _isConnected);
|
serialMock.Setup(x => x.IsOpen).Returns(() => _isConnected);
|
||||||
|
|
||||||
_telescopeController = TelescopeController.Instance;
|
_telescopeController = TelescopeController.Instance;
|
||||||
|
_telescopeController.Connected = false;
|
||||||
_telescopeController.SerialPort = serialMock.Object;
|
_telescopeController.SerialPort = serialMock.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ namespace MeadeAutostar497.UnitTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void utcDate_Get_ReturnsExpectedValue()
|
public void utcDate_Get_ReturnsExpectedValue()
|
||||||
{
|
{
|
||||||
DateTime expectedDate = new DateTime(2019, 04, 30, 12, 32, 24, DateTimeKind.Utc);
|
DateTime expectedDate = new DateTime(2019, 04, 30, 11, 32, 24, DateTimeKind.Local);
|
||||||
|
|
||||||
var dateString = "04/30/19";
|
var dateString = "04/30/19";
|
||||||
var timeString = "12:32:24";
|
var timeString = "12:32:24";
|
||||||
@@ -204,6 +205,7 @@ namespace MeadeAutostar497.UnitTests
|
|||||||
|
|
||||||
_telescopeController.Connected = true;
|
_telescopeController.Connected = true;
|
||||||
|
|
||||||
|
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||||
serialMock.Setup(x => x.CommandTerminated(":GC#", "#")).Returns(dateString);
|
serialMock.Setup(x => x.CommandTerminated(":GC#", "#")).Returns(dateString);
|
||||||
serialMock.Setup(x => x.CommandTerminated(":GL#", "#")).Returns(timeString);
|
serialMock.Setup(x => x.CommandTerminated(":GL#", "#")).Returns(timeString);
|
||||||
|
|
||||||
@@ -216,7 +218,9 @@ namespace MeadeAutostar497.UnitTests
|
|||||||
public void utcDate_Set_SetsTelescopeDateAndTime()
|
public void utcDate_Set_SetsTelescopeDateAndTime()
|
||||||
{
|
{
|
||||||
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
||||||
serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
|
||||||
|
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||||
|
serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour+1:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
||||||
serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
||||||
|
|
||||||
_isConnected = true;
|
_isConnected = true;
|
||||||
@@ -230,6 +234,8 @@ namespace MeadeAutostar497.UnitTests
|
|||||||
public void utcDate_Set_ThrowsExceptionWhenTimeInvalid()
|
public void utcDate_Set_ThrowsExceptionWhenTimeInvalid()
|
||||||
{
|
{
|
||||||
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
||||||
|
|
||||||
|
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||||
//serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
//serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
||||||
serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
||||||
|
|
||||||
@@ -245,8 +251,10 @@ namespace MeadeAutostar497.UnitTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void utcDate_Set_ThrowsExceptionWhenDateInvalid()
|
public void utcDate_Set_ThrowsExceptionWhenDateInvalid()
|
||||||
{
|
{
|
||||||
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Local);
|
||||||
serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
|
||||||
|
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||||
|
serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour+1:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
||||||
//serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
//serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
||||||
|
|
||||||
_isConnected = true;
|
_isConnected = true;
|
||||||
|
|||||||
@@ -131,15 +131,20 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
int minute = telescopeTime.Substring(3, 2).ToInteger();
|
int minute = telescopeTime.Substring(3, 2).ToInteger();
|
||||||
int second = telescopeTime.Substring(6, 2).ToInteger();
|
int second = telescopeTime.Substring(6, 2).ToInteger();
|
||||||
|
|
||||||
|
var utcCorrection = GetUtcCorrection();
|
||||||
|
|
||||||
//Todo is this telescope local time, or real utc?
|
//Todo is this telescope local time, or real utc?
|
||||||
var newDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
|
var newDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) + utcCorrection;
|
||||||
|
|
||||||
return newDate;
|
return newDate;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
var utcCorrection = GetUtcCorrection();
|
||||||
|
var localDateTime = value - utcCorrection;
|
||||||
|
|
||||||
//Todo is this telescope local time, or real utc?
|
//Todo is this telescope local time, or real utc?
|
||||||
var timeResult = SerialPort.CommandChar($":SL{value:HH:mm:ss}#");
|
var timeResult = SerialPort.CommandChar($":SL{localDateTime:HH:mm:ss}#");
|
||||||
if (timeResult != '1')
|
if (timeResult != '1')
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Failed to set local time");
|
throw new InvalidOperationException("Failed to set local time");
|
||||||
@@ -148,7 +153,7 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
SerialPort.Lock();
|
SerialPort.Lock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dateResult = SerialPort.CommandChar($":SC{value:MM/dd/yy}#");
|
var dateResult = SerialPort.CommandChar($":SC{localDateTime:MM/dd/yy}#");
|
||||||
if (dateResult != '1')
|
if (dateResult != '1')
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Failed to set local date");
|
throw new InvalidOperationException("Failed to set local date");
|
||||||
@@ -166,6 +171,14 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeSpan GetUtcCorrection()
|
||||||
|
{
|
||||||
|
string utcOffSet = SerialPort.CommandTerminated(":GG#", "#");
|
||||||
|
double utcOffsetHours = double.Parse(utcOffSet);
|
||||||
|
TimeSpan utcCorrection = TimeSpan.FromHours(utcOffsetHours);
|
||||||
|
return utcCorrection;
|
||||||
|
}
|
||||||
|
|
||||||
public double SiteLatitude
|
public double SiteLatitude
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
Reference in New Issue
Block a user