From df7dfb7c04e09b6eb1913686e3742dba18c59c26 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 11 Dec 2021 19:10:18 +0000 Subject: [PATCH 01/47] Modified the implementation of side of pier support detection. Hopefully will now, Added extra checking to ensure that a slew cannot be started whilst a slew is in progress. --- .../FocuserUnitTests.cs | 6 - .../TelescopeUnitTests.cs | 70 +++- Meade.net.Telescope/Telescope.cs | 305 +++++++++--------- Meade.net.focuser/Focuser.cs | 39 ++- Meade.net/TelescopeList.cs | 1 + Meade.net/Wrapper/SharedResourcesWrapper.cs | 15 +- 6 files changed, 221 insertions(+), 215 deletions(-) diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index e96a219..a898637 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -42,8 +42,6 @@ namespace Meade.net.Focuser.UnitTests _sharedResourcesWrapperMock = new Mock(); - _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); - _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() => _profileProperties); _focuser = new ASCOM.Meade.net.Focuser(_utilMock.Object, _sharedResourcesWrapperMock.Object); @@ -422,8 +420,6 @@ namespace Meade.net.Focuser.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); } - _sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny()), Times.Once); - _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once()); @@ -455,8 +451,6 @@ namespace Meade.net.Focuser.UnitTests _utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2)); } - - _sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny()), Times.Once); } [Test] diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 0e65afb..8fcf673 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -95,9 +95,6 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); - _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); - _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>( func => func()); - _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>(func => func()); _connectionInfo = new ConnectionInfo { @@ -1930,11 +1927,12 @@ namespace Meade.net.Telescope.UnitTests Assert.That(excpetion.Method, Is.EqualTo("SetPark")); } - [Test] - public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException() + [TestCase(TelescopeList.LX200CLASSIC, null)] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee)] + [TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42F)] + public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException(string model, string firmware) { - // LX200 classic is a fork mounted scope so it does not support meridian flips - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(TelescopeList.LX200CLASSIC); + ConnectTelescope(model, firmware); var excpetion = Assert.Throws(() => { @@ -1946,6 +1944,41 @@ namespace Meade.net.Telescope.UnitTests Assert.That(excpetion.AccessorSet, Is.False); } + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)] + [TestCase(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G)] + public void SideOfPier_Get_WhenMeridianFlipSupported_ThenReturnsResult(string model, string firmware) + { + ConnectTelescope(model, firmware); + + Assert.DoesNotThrow(() => { var result = _telescope.SideOfPier; }); + } + + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algAltAz, 'A')] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algPolar, 'P')] + public void SideOfPier_Get_WhenMeridianFlipNotSupportedByAlignementMode_ThenThrowsException(string model, string firmware, AlignmentModes alignmode, char alignmentStatus) + { + ConnectTelescope(model, firmware); + _testProperties.AlignmentStatus = new[] { alignmentStatus, 'T', '1' }; + + var excpetion = Assert.Throws(() => + { + var result = _telescope.SideOfPier; + Assert.Fail($"{result} should not have returned"); + }); + + Assert.That(excpetion.Property, Is.EqualTo("SideOfPier")); + Assert.That(excpetion.AccessorSet, Is.False); + } + + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, 'G')] + public void SideOfPier_Get_WhenMeridianFlipSupportedByAlignementMode_ThenDoesNotThrow(string model, string firmware, AlignmentModes alignmode, char alignmentStatus) + { + ConnectTelescope(model, firmware); + _testProperties.AlignmentStatus = new[] { alignmentStatus, 'T', '1' }; + + Assert.DoesNotThrow(() => { var result = _telescope.SideOfPier; }); + } + [Test] public void SideOfPier_Set_ThenThrowsException() { @@ -2119,7 +2152,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendString("Gg", false), Times.Exactly(3)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Exactly(2)); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Exactly(3)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.AtLeast(3)); } [Test] @@ -3272,12 +3305,15 @@ namespace Meade.net.Telescope.UnitTests { _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + var preTestItterations = 1; var slewCounter = 0; var iterations = 10; _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; - if (slewCounter <= iterations) + if (slewCounter <= preTestItterations) + return ""; + else if (slewCounter <= iterations) return "|"; return ""; }); @@ -3289,7 +3325,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTarget(); - _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations - preTestItterations)); } [Test] @@ -3366,12 +3402,15 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + var preTestItterations = 1; var slewCounter = 0; var iterations = 10; _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; - if (slewCounter <= iterations) + if (slewCounter <= preTestItterations) + return ""; + else if (slewCounter <= iterations) return "|"; return ""; }); @@ -3383,7 +3422,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); - _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations - preTestItterations)); } [Test] @@ -3486,12 +3525,15 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + var preTestItterations = 1; var slewCounter = 0; var iterations = 10; _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; - if (slewCounter <= iterations) + if (slewCounter <= preTestItterations) + return ""; + else if (slewCounter <= iterations) return "|"; return ""; }); @@ -3503,7 +3545,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); - _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations - preTestItterations)); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 261d9b3..d9d220d 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -649,7 +649,7 @@ namespace ASCOM.Meade.net // According to "A User's Guide to the Meade LXD55 and LXD75 Telescopes" Autostar supports meridian flip so // we assume that for any telescope that supports the GW command and is not in Alt-Az mode then // meridian flip on slew is supported - private bool IsMeridianFlipOnSlewSupported() => IsGwCommandSupported() && AlignmentMode != AlignmentModes.algAltAz; + private bool IsMeridianFlipOnSlewSupported() => IsGwCommandSupported() && AlignmentMode == AlignmentModes.algGermanPolar; private bool FirmwareIsGreaterThan(string minVersion) { @@ -734,39 +734,36 @@ namespace ASCOM.Meade.net { LogMessage("SetLongFormat", "Long coordinate format not supported for this mount"); - SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.IsLongFormat = false); + SharedResourcesWrapper.IsLongFormat = false; return; } - SharedResourcesWrapper.Lock(() => + var result = SharedResourcesWrapper.SendString("GZ"); + LogMessage("SetLongFormat", $"Get - Azimuth {result}"); + //:GZ# Get telescope azimuth + //Returns: DDD*MM.T or DDD*MM'SS# + //The current telescope Azimuth depending on the selected precision. + + SharedResourcesWrapper.IsLongFormat = result.Length > 6; + + if (SharedResourcesWrapper.IsLongFormat != setLongFormat) { - var result = SharedResourcesWrapper.SendString("GZ"); - LogMessage("SetLongFormat", $"Get - Azimuth {result}"); - //:GZ# Get telescope azimuth - //Returns: DDD*MM.T or DDD*MM'SS# - //The current telescope Azimuth depending on the selected precision. - + _utilities.WaitForMilliseconds(500); + SharedResourcesWrapper.SendBlind("U"); + //:U# Toggle between low/hi precision positions + //Low - RA displays and messages HH:MM.T sDD*MM + //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS + // Returns Nothing + result = SharedResourcesWrapper.SendString("GZ"); SharedResourcesWrapper.IsLongFormat = result.Length > 6; - - if (SharedResourcesWrapper.IsLongFormat != setLongFormat) - { - _utilities.WaitForMilliseconds(500); - SharedResourcesWrapper.SendBlind("U"); - //:U# Toggle between low/hi precision positions - //Low - RA displays and messages HH:MM.T sDD*MM - //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS - // Returns Nothing - result = SharedResourcesWrapper.SendString("GZ"); - SharedResourcesWrapper.IsLongFormat = result.Length > 6; - LogMessage("SetLongFormat", $"Get - Azimuth {result}"); - if (SharedResourcesWrapper.IsLongFormat == setLongFormat) - LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); - } - else - { + LogMessage("SetLongFormat", $"Get - Azimuth {result}"); + if (SharedResourcesWrapper.IsLongFormat == setLongFormat) LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); - } - }); + } + else + { + LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); + } LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); } @@ -1001,8 +998,8 @@ namespace ASCOM.Meade.net alignmentMode = AlignmentModes.algPolar; break; //case "G": - // alignmentMode = AlignmentModes.algGermanPolar; - // break; + //alignmentMode = AlignmentModes.algGermanPolar; + //break; default: throw new InvalidValueException( $"unknown alignment returned from telescope: {alignmentString}"); @@ -1135,13 +1132,13 @@ namespace ASCOM.Meade.net private HorizonCoordinates CalcAltAzFromTelescopeEqData() { - var altitudeData = SharedResourcesWrapper.Lock(() => new AltitudeData + var altitudeData = new AltitudeData { UtcDateTime = UTCDate, SiteLongitude = SiteLongitude, SiteLatitude = SiteLatitude, EquatorialCoordinates = GetTelescopeRaAndDec() - }); + }; double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude, @@ -2175,98 +2172,94 @@ namespace ASCOM.Meade.net LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}"); - HorizonCoordinates altAz = new HorizonCoordinates {Azimuth = azimuth, Altitude = altitude}; + HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude }; var utcDateTime = UTCDate; var latitude = SiteLatitude; var longitude = SiteLongitude; - SharedResourcesWrapper.Lock(() => - { - var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); + var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); - TargetRightAscension = raDec.RightAscension; - TargetDeclination = raDec.Declination; + TargetRightAscension = raDec.RightAscension; + TargetDeclination = raDec.Declination; - DoSlewAsync(true); - - //TargetAltitude = altitude; - //TargetAzimuth = azimuth; - - //DoSlewAsync(false); - }); + DoSlewAsync(true); } private void DoSlewAsync(bool polar) { CheckConnected("DoSlewAsync"); CheckParked(); - - SharedResourcesWrapper.Lock(() => + if (Slewing) { - switch (polar) - { - case true: - var response = SharedResourcesWrapper.SendChar("MS"); - //:MS# Slew to Target Object - //Returns: - //0 Slew is Possible - //1# Object Below Horizon w/string message - //2# Object Below Higher w/string message + LogMessage("DoSlewAsync", "Cannot start a slew whilst slew is in progress."); + throw new ASCOM.InvalidOperationException("Cannot start a slew whilst slew is in progress."); + } - switch (response) - { - case "0": - //We're slewing everything should be working just fine. - LogMessage("DoSlewAsync", "Slewing to target"); + switch (polar) + { + case true: + var response = SharedResourcesWrapper.SendChar("MS"); + //:MS# Slew to Target Object + //Returns: + //0 Slew is Possible + //1# Object Below Horizon w/string message + //2# Object Below Higher w/string message - if (IsMeridianFlipOnSlewSupported()) - { - // Update side of pier to destination side of pier - // Assumption: Mount will do meridian flip if required - SharedResourcesWrapper.SideOfPier = DestinationSideOfPier(TargetRightAscension, TargetDeclination); - } + switch (response) + { + case "0": + //We're slewing everything should be working just fine. + LogMessage("DoSlewAsync", "Slewing to target"); - SetSlewingMinEndTime(); - break; - case "1": - //Below Horizon - string belowHorizonMessage = SharedResourcesWrapper.ReadTerminated(); - LogMessage("DoSlewAsync", $"Slew failed \"{belowHorizonMessage}\""); - throw new InvalidOperationException(belowHorizonMessage); - case "2": - //Below minimum elevation - string belowMinimumElevationMessage = SharedResourcesWrapper.ReadTerminated(); - LogMessage("DoSlewAsync", $"Slew failed \"{belowMinimumElevationMessage}\""); - throw new InvalidOperationException(belowMinimumElevationMessage); - case "3": - //Telescope can hit the mount - string canHitMountMessage = SharedResourcesWrapper.ReadTerminated(); - LogMessage("DoSlewAsync", $"Slew failed \"{canHitMountMessage}\""); - throw new InvalidOperationException(canHitMountMessage); - default: - LogMessage("DoSlewAsync", $"Slew failed - unknown response \"{response}\""); - throw new DriverException("This error should not happen"); + if (IsMeridianFlipOnSlewSupported()) + { + // Update side of pier to destination side of pier + // Assumption: Mount will do meridian flip if required + SharedResourcesWrapper.SideOfPier = + DestinationSideOfPier(TargetRightAscension, TargetDeclination); + } - } + SetSlewingMinEndTime(); + break; + case "1": + //Below Horizon + string belowHorizonMessage = SharedResourcesWrapper.ReadTerminated(); + LogMessage("DoSlewAsync", $"Slew failed \"{belowHorizonMessage}\""); + throw new InvalidOperationException(belowHorizonMessage); + case "2": + //Below minimum elevation + string belowMinimumElevationMessage = SharedResourcesWrapper.ReadTerminated(); + LogMessage("DoSlewAsync", $"Slew failed \"{belowMinimumElevationMessage}\""); + throw new InvalidOperationException(belowMinimumElevationMessage); + case "3": + //Telescope can hit the mount + string canHitMountMessage = SharedResourcesWrapper.ReadTerminated(); + LogMessage("DoSlewAsync", $"Slew failed \"{canHitMountMessage}\""); + throw new InvalidOperationException(canHitMountMessage); + default: + LogMessage("DoSlewAsync", $"Slew failed - unknown response \"{response}\""); + throw new DriverException("This error should not happen"); - break; - case false: - var maResponse = SharedResourcesWrapper.SendChar("MA"); - //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az - //Returns: - //0 - No fault - //1 - Fault - //LX200 - Not supported + } - if (maResponse == "1") - { - throw new InvalidOperationException("fault"); - } - SetSlewingMinEndTime(); - break; - } - }); + break; + case false: + var maResponse = SharedResourcesWrapper.SendChar("MA"); + //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az + //Returns: + //0 - No fault + //1 - Fault + //LX200 - Not supported + + if (maResponse == "1") + { + throw new InvalidOperationException("fault"); + } + + SetSlewingMinEndTime(); + break; + } } public void SlewToCoordinates(double rightAscension, double declination) @@ -2450,17 +2443,15 @@ namespace ASCOM.Meade.net public void SyncToCoordinates(double rightAscension, double 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"); CheckParked(); - SharedResourcesWrapper.Lock(() => - { - TargetRightAscension = rightAscension; - TargetDeclination = declination; + TargetRightAscension = rightAscension; + TargetDeclination = declination; - SyncToTarget(); - }); + SyncToTarget(); } public void SyncToTarget() @@ -2612,13 +2603,15 @@ namespace ASCOM.Meade.net get { LogMessage("Tracking", "Get"); + bool isTracking = true; if (IsGwCommandSupported()) { var alignmentStatus = GetScopeAlignmentStatus(); - return alignmentStatus.Tracking; + isTracking = alignmentStatus.Tracking; } - return true; + LogMessage("Tracking", $"Get = {isTracking}"); + return isTracking; } set { @@ -2731,23 +2724,18 @@ namespace ASCOM.Meade.net { CheckParked(); - var telescopeDateDetails = SharedResourcesWrapper.Lock(() => + var telescopeDateDetails = new TelescopeDateDetails { - var tdd = new TelescopeDateDetails - { - TelescopeDate = SharedResourcesWrapper.SendString("GC"), - //:GC# Get current date. - //Returns: MM/DD/YY# - //The current local calendar date for the telescope. - TelescopeTime = SharedResourcesWrapper.SendString("GL"), - //:GL# Get Local Time in 24 hour format - //Returns: HH:MM:SS# - //The Local Time in 24 - hour Format - UtcCorrection = GetUtcCorrection() - }; - - return tdd; - }); + TelescopeDate = SharedResourcesWrapper.SendString("GC"), + //:GC# Get current date. + //Returns: MM/DD/YY# + //The current local calendar date for the telescope. + TelescopeTime = SharedResourcesWrapper.SendString("GL"), + //:GL# Get Local Time in 24 hour format + //Returns: HH:MM:SS# + //The Local Time in 24 - hour Format + UtcCorrection = GetUtcCorrection() + }; int month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger(); int day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger(); @@ -2783,40 +2771,37 @@ namespace ASCOM.Meade.net CheckConnected("UTCDate Set"); - SharedResourcesWrapper.Lock(() => + var utcCorrection = GetUtcCorrection(); + var localDateTime = value - utcCorrection; + + string localStingCommand = $"SL{localDateTime:HH:mm:ss}"; + var timeResult = SharedResourcesWrapper.SendChar(localStingCommand); + //:SLHH:MM:SS# + //Set the local Time + //Returns: + //0 - Invalid + //1 - Valid + if (timeResult != "1") { - var utcCorrection = GetUtcCorrection(); - var localDateTime = value - utcCorrection; + throw new InvalidOperationException("Failed to set local time"); + } - string localStingCommand = $"SL{localDateTime:HH:mm:ss}"; - var timeResult = SharedResourcesWrapper.SendChar(localStingCommand); - //:SLHH:MM:SS# - //Set the local Time - //Returns: - //0 - Invalid - //1 - Valid - if (timeResult != "1") - { - throw new InvalidOperationException("Failed to set local time"); - } + string localDateCommand = $"SC{localDateTime:MM/dd/yy}"; + var dateResult = SharedResourcesWrapper.SendChar(localDateCommand); + //:SCMM/DD/YY# + //Change Handbox Date to MM/DD/YY + //Returns: + //D = '0' if the date is invalid. The string is the null string. + //D = '1' for valid dates and the string is "Updating Planetary Data# #" + //Note: For Autostar II this is the UTC data! + if (dateResult != "1") + { + throw new InvalidOperationException("Failed to set local date"); + } - string localDateCommand = $"SC{localDateTime:MM/dd/yy}"; - var dateResult = SharedResourcesWrapper.SendChar(localDateCommand); - //:SCMM/DD/YY# - //Change Handbox Date to MM/DD/YY - //Returns: - //D = '0' if the date is invalid. The string is the null string. - //D = '1' for valid dates and the string is "Updating Planetary Data# #" - //Note: For Autostar II this is the UTC data! - if (dateResult != "1") - { - throw new InvalidOperationException("Failed to set local date"); - } - - //throwing away these two strings which represent - SharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data# - SharedResourcesWrapper.ReadTerminated(); // # - }); + //throwing away these two strings which represent + SharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data# + SharedResourcesWrapper.ReadTerminated(); // # } } diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index 8d3ac6c..d547177 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -297,30 +297,27 @@ namespace ASCOM.Meade.net var direction = position > 0; if (ReverseFocusDirection) direction = !direction; + + //backlash compensation. + var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0; - SharedResourcesWrapper.Lock(() => + var steps = Math.Abs(position) + backlashCompensationSteps; + + + MoveFocuser(direction, steps); + + + //todo refactor the backlash compensation to combine the commands into as few moves as practicle. + //ApplyBacklashCompensation(direction); + if (direction & backlashCompensationSteps != 0) { - //backlash compensation. - var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0; + Tl.LogMessage("Move", "Applying backlash compensation"); + MoveFocuser(!direction, backlashCompensationSteps); + } - var steps = Math.Abs(position) + backlashCompensationSteps; - - - MoveFocuser(direction, steps); - - - //todo refactor the backlash compensation to combine the commands into as few moves as practicle. - //ApplyBacklashCompensation(direction); - if (direction & backlashCompensationSteps != 0) - { - Tl.LogMessage("Move", "Applying backlash compensation"); - MoveFocuser(!direction, backlashCompensationSteps); - } - - DynamicBreaking(direction); - //todo implement dynamic braking - //dynamic breaking is sending the command to move in the opposite direction immediatly followed by the command to stop. - }); + DynamicBreaking(direction); + //todo implement dynamic braking + //dynamic breaking is sending the command to move in the opposite direction immediatly followed by the command to stop. } private void DynamicBreaking(bool directionOut) diff --git a/Meade.net/TelescopeList.cs b/Meade.net/TelescopeList.cs index e41f2e9..42f92d0 100644 --- a/Meade.net/TelescopeList.cs +++ b/Meade.net/TelescopeList.cs @@ -23,6 +23,7 @@ // ReSharper disable once InconsistentNaming public const string LX200GPS = "LX2001"; + public const string LX200GPS_42F = "4.2F"; // ReSharper disable once InconsistentNaming public const string LX200GPS_42G = "4.2G"; #endregion diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index 754f341..4499fd4 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -12,10 +12,7 @@ namespace ASCOM.Meade.net.Wrapper string ProductName { get; } string FirmwareVersion { get; } - - void Lock(Action action); - T Lock(Func func); - + string SendString(string message, bool raw = false); void SendBlind(string message, bool raw = false); bool SendBool(string command, bool raw = false); @@ -69,16 +66,6 @@ namespace ASCOM.Meade.net.Wrapper public string FirmwareVersion => SharedResources.FirmwareVersion; - public void Lock(Action action) - { - SharedResources.Lock(action); - } - - public T Lock(Func func) - { - return SharedResources.Lock(func); - } - public string SendString(string message, bool raw = false) { return SharedResources.SendString(message, raw); From 6786db65fe6d9511d211b1f25b2c54641b45532a Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Mon, 13 Dec 2021 12:58:40 +0000 Subject: [PATCH 02/47] Overridden the alignment status ToString to help with logging --- Meade.net.Telescope/AlignmentStatus.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Meade.net.Telescope/AlignmentStatus.cs b/Meade.net.Telescope/AlignmentStatus.cs index a602f5a..73403de 100644 --- a/Meade.net.Telescope/AlignmentStatus.cs +++ b/Meade.net.Telescope/AlignmentStatus.cs @@ -7,5 +7,10 @@ namespace ASCOM.Meade.net public AlignmentModes AlignmentMode { get; set; } public bool Tracking { get; set; } public Alignment Status { get; set; } + + public override string ToString() + { + return $"AlignmentStatus AlignmentMode={AlignmentMode};Tracking={Tracking};Status={Status}"; + } } } \ No newline at end of file From eda3a53d6ffbd812277a752410ee208d219bf298 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Mon, 13 Dec 2021 14:09:16 +0000 Subject: [PATCH 03/47] Added logging to MoxingAxis call to see if a telescope axis is moving --- Meade.net.Telescope/Telescope.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index d9d220d..72affd1 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2320,9 +2320,15 @@ namespace ASCOM.Meade.net private bool MovingAxis() { if (SharedResourcesWrapper.IsGuiding) + { + LogMessage("MovingAxis", $"Result = false (guiding is true)"); return false; + } - return SharedResourcesWrapper.MovingPrimary || SharedResourcesWrapper.MovingSecondary; + var movingAxis = SharedResourcesWrapper.MovingPrimary || SharedResourcesWrapper.MovingSecondary; + + LogMessage("MovingAxis", $"Result = {movingAxis} Primary={SharedResourcesWrapper.MovingPrimary} Secondary={SharedResourcesWrapper.MovingSecondary}"); + return movingAxis; } public bool Slewing From acb1533f21511e04bff6f23eb855b1c27698a746 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 15 Dec 2021 20:23:46 +0000 Subject: [PATCH 04/47] Upgraded the tracking rate detection, now detects solar, lunar and sidereal better than before. --- .../TelescopeUnitTests.cs | 8 +++-- Meade.net.Telescope/Telescope.cs | 31 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 8fcf673..8a94096 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -143,7 +143,7 @@ namespace Meade.net.Telescope.UnitTests _testProperties.TrackingRate = _siderealTrackingRate; _sharedResourcesWrapperMock.Setup(x => x.SendString("GT", false)).Returns(() => _testProperties.TrackingRate); - _sharedResourcesWrapperMock.Setup(x => x.SendBlind("TL", false)).Callback(() => _testProperties.TrackingRate = "lunar"); + _sharedResourcesWrapperMock.Setup(x => x.SendBlind("TL", false)).Callback(() => _testProperties.TrackingRate = "57.9"); _sharedResourcesWrapperMock.Setup(x => x.SendBlind("TQ", false)).Callback(() => _testProperties.TrackingRate = _siderealTrackingRate); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); @@ -2778,9 +2778,11 @@ namespace Meade.net.Telescope.UnitTests } [TestCase(DriveRates.driveSidereal, "60.1")] - [TestCase(DriveRates.driveLunar, "60.1")] + [TestCase(DriveRates.driveSolar, "60.0")] + [TestCase(DriveRates.driveLunar, "57.9")] [TestCase(DriveRates.driveSidereal, "+60.1")] - [TestCase(DriveRates.driveLunar, "+60.1")] + [TestCase(DriveRates.driveSolar, "+60.0")] + [TestCase(DriveRates.driveLunar, "+57.9")] public void TrackingRate_Get_WhenConnected_ThenSendsCommandToTelescope(DriveRates rate, string trackingRate) { _siderealTrackingRate = trackingRate; diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 72affd1..e7aae54 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2643,7 +2643,25 @@ namespace ASCOM.Meade.net rate = rate.Replace("+", string.Empty); - DriveRates result = rate == "60.1" ? DriveRates.driveSidereal : DriveRates.driveLunar; + DriveRates result; + + switch (rate) + { + case "60.1": + result = DriveRates.driveSidereal; + break; + case "60.0": + result = DriveRates.driveSolar; + break; + case "57.9": + result = DriveRates.driveLunar; + break; + default: + result = DriveRates.driveKing; + //If this is ever returned it is representing a fail condition. + break; + } + LogMessage("TrackingRate Get", $"{rate} {result}"); @@ -2672,14 +2690,15 @@ namespace ASCOM.Meade.net //:TL# Set Lunar Tracking Rage //Returns: Nothing break; - //case DriveRates.driveSolar: - // SerialPort.Command(":TS#"); + case DriveRates.driveSolar: + SharedResourcesWrapper.SendBlind("TS"); // //:TS# Select Solar tracking rate. [LS Only] // //Returns: Nothing - // break; + break; //case DriveRates.driveKing: - //:TM# Select custom tracking rate [ no-op in Autostar II] - //Returns: Nothing + // SharedResourcesWrapper.SendBlind("TM"); + // //:TM# Select custom tracking rate [ no-op in Autostar II] + // //Returns: Nothing // break; default: throw new ArgumentOutOfRangeException(nameof(value), value, null); From 7ac3c95c8e51ee8b089a1a2e94f416bf36627d31 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 17 Dec 2021 13:11:32 +0000 Subject: [PATCH 05/47] modified the get tracking code to make it less better. amd more tolerant of lunar speeds, taken from Nasa and other sources (Info from David Richards) --- .../TelescopeUnitTests.cs | 2 ++ .../Meade.net.Telescope.csproj | 2 ++ Meade.net.Telescope/Telescope.cs | 29 ++++++++----------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 8a94096..a088691 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2783,6 +2783,8 @@ namespace Meade.net.Telescope.UnitTests [TestCase(DriveRates.driveSidereal, "+60.1")] [TestCase(DriveRates.driveSolar, "+60.0")] [TestCase(DriveRates.driveLunar, "+57.9")] + [TestCase(DriveRates.driveLunar, "57.3")] + [TestCase(DriveRates.driveLunar, "58.9")] public void TrackingRate_Get_WhenConnected_ThenSendsCommandToTelescope(DriveRates rate, string trackingRate) { _siderealTrackingRate = trackingRate; diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index a884ce0..f51673b 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -128,6 +128,7 @@ + @@ -187,6 +188,7 @@ Meade.net + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index e7aae54..e417173 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2643,25 +2643,20 @@ namespace ASCOM.Meade.net rate = rate.Replace("+", string.Empty); + var rateDouble = double.Parse(rate); + DriveRates result; - switch (rate) - { - case "60.1": - result = DriveRates.driveSidereal; - break; - case "60.0": - result = DriveRates.driveSolar; - break; - case "57.9": - result = DriveRates.driveLunar; - break; - default: - result = DriveRates.driveKing; - //If this is ever returned it is representing a fail condition. - break; - } - + if (rateDouble.Equals(60.1)) + result = DriveRates.driveSidereal; + else if (rateDouble.Equals(60.0)) + result = DriveRates.driveSolar; + else if (rateDouble.Between(57.3, 58.9)) + result = DriveRates.driveLunar; + else + //If this is ever returned it is representing a fail condition. + //result = DriveRates.driveKing; + throw new ASCOM.InvalidValueException($"{rate} is not a supported tracking rate for meade mounts"); LogMessage("TrackingRate Get", $"{rate} {result}"); From 826f887bdfaa3d05f874c76afe349b33bbfaa7af Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 17 Dec 2021 13:16:20 +0000 Subject: [PATCH 06/47] Added mossing file --- .../ExtensionMethods/DoubelExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Meade.net.Telescope/ExtensionMethods/DoubelExtensions.cs diff --git a/Meade.net.Telescope/ExtensionMethods/DoubelExtensions.cs b/Meade.net.Telescope/ExtensionMethods/DoubelExtensions.cs new file mode 100644 index 0000000..85567ba --- /dev/null +++ b/Meade.net.Telescope/ExtensionMethods/DoubelExtensions.cs @@ -0,0 +1,10 @@ +namespace System +{ + static class DoubelExtensions + { + public static bool Between(this double value, double lower, double higher) + { + return value >= lower & value <= higher; + } + } +} From 1a66f41d78dc1557122aaf9d373d9a69254b1ba2 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 28 Apr 2022 21:29:36 +0100 Subject: [PATCH 07/47] Add support for the IsGuiding function --- Meade.net.Telescope/Telescope.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index e417173..902a2a8 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1577,10 +1577,10 @@ namespace ASCOM.Meade.net { get { - //Todo implement this if I can make the new pulse guiding async - LogMessage("IsPulseGuiding Get", "pulse guiding is synchronous for this driver"); + var isGuiding = SharedResourcesWrapper.IsGuiding; + LogMessage("IsPulseGuiding Get", $"result = {isGuiding}"); + return isGuiding; //throw new ASCOM.PropertyNotImplementedException("IsPulseGuiding", false); - return false; } } @@ -1764,7 +1764,7 @@ namespace ASCOM.Meade.net var coordinatesBeforeMove = GetTelescopeRaAndDec(); - if (_userNewerPulseGuiding && duration < 10000) + if (_userNewerPulseGuiding) { string d = string.Empty; switch (direction) From dc68bb0b4ca0f3289bc8935e5944cc02b9a00228 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 28 Apr 2022 23:55:35 +0100 Subject: [PATCH 08/47] Added Focal Length property to telescope setup screen --- .../TelescopeUnitTests.cs | 14 +- Meade.net.Telescope/Telescope.cs | 72 +++---- .../SharedResourcesUnitTests.cs | 21 ++ Meade.net.focuser/Focuser.cs | 10 +- Meade.net/MeadeTelescopeBase.cs | 79 +++---- Meade.net/ProfileProperties.cs | 1 + Meade.net/Properties/Resources.Designer.cs | 9 + Meade.net/Properties/Resources.resx | 3 + Meade.net/SetupDialogForm.cs | 21 +- Meade.net/SetupDialogForm.designer.cs | 25 +++ Meade.net/SetupDialogForm.resx | 203 ++++++++++++------ Meade.net/SharedResources.cs | 4 + 12 files changed, 313 insertions(+), 149 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index a088691..9cc12d8 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -84,7 +84,8 @@ namespace Meade.net.Telescope.UnitTests SendDateTime = false, ParkedBehaviour = ParkedBehaviour.NoCoordinates, ParkedAlt = 0, - ParkedAz = 180 + ParkedAz = 180, + FocalLength = 2000 }; _utilMock = new Mock(); @@ -1429,16 +1430,11 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void FocalLength_Get_ThenThrowsException() + public void FocalLength_Get_ThenReturnsValue() { - var excpetion = Assert.Throws(() => - { - var result = _telescope.FocalLength; - Assert.Fail($"{result} should not have returned"); - }); + var result = _telescope.FocalLength; - Assert.That(excpetion.Property, Is.EqualTo("FocalLength")); - Assert.That(excpetion.AccessorSet, Is.False); + Assert.That(result, Is.EqualTo(_profileProperties.FocalLength)); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 902a2a8..26e0428 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -419,12 +419,12 @@ namespace ASCOM.Meade.net { ReadProfile(); - LogMessage("Connected Set", "Connecting to port {0}", ComPort); + LogMessage("Connected Set", "Connecting to port {0}", _ComPort); var connectionInfo = SharedResourcesWrapper.Connect("Serial", DriverId, Tl); try { LogMessage("Connected Set", - $"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); + $"Connected to port {_ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); _userNewerPulseGuiding = IsNewPulseGuidingSupported(); @@ -444,7 +444,7 @@ namespace ASCOM.Meade.net if (CanSetGuideRates) { - SetNewGuideRate(GuideRate, "Connect"); + SetNewGuideRate(_GuideRate, "Connect"); } SetTelescopePrecision("Connect"); @@ -454,28 +454,28 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.TargetDeclination = InvalidParameter; SharedResourcesWrapper.TargetRightAscension = InvalidParameter; - LogMessage("Connected Set", $"SendDateTime: {SendDateTime}"); - if (SendDateTime) + LogMessage("Connected Set", $"SendDateTime: {_SendDateTime}"); + if (_SendDateTime) { if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { LogMessage("Connected Set", - $"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}"); + $"LX200GPS Detecting if daylight savings message on screen: {_SendDateTime}"); var displayText = Action("Handbox", "readdisplay"); LogMessage("Connected Set", $"Current Handset display: {displayText}"); if (displayText.Contains("Daylight")) { LogMessage("Connected Set", - $"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}"); + $"LX200GPS Setting Date time and bypassing settings screens: {_SendDateTime}"); BypassHandboxEntryForAutostarII(); } else { LogMessage("Connected Set", - $"LX200GPS Sending current date and time: {SendDateTime}"); + $"LX200GPS Sending current date and time: {_SendDateTime}"); SendCurrentDateTime("Connect"); LogMessage("Connected Set", - $"LX200GPS Attempting manual bypass of prompts: {SendDateTime}"); + $"LX200GPS Attempting manual bypass of prompts: {_SendDateTime}"); ApplySkipAutoStarPrompts("Connect"); } @@ -514,12 +514,12 @@ namespace ASCOM.Meade.net } catch (Exception ex) { - LogMessage("Connected Set", "Error connecting to port {0} - {1}", ComPort, ex.Message); + LogMessage("Connected Set", "Error connecting to port {0} - {1}", _ComPort, ex.Message); } } else { - LogMessage("Connected Set", "Disconnecting from port {0}", ComPort); + LogMessage("Connected Set", "Disconnecting from port {0}", _ComPort); SharedResourcesWrapper.Disconnect("Serial", DriverId); IsConnected = false; } @@ -528,7 +528,7 @@ namespace ASCOM.Meade.net private void SendCurrentDateTime(string connect) { - if (SendDateTime) + if (_SendDateTime) { UTCDate = _clock.UtcNow; } @@ -570,7 +570,7 @@ namespace ASCOM.Meade.net private void SetTelescopePrecision(string propertyName) { - switch (Precision.ToLower()) + switch (_Precision.ToLower()) { case "high": TelescopePointingPrecision(true); @@ -588,7 +588,7 @@ namespace ASCOM.Meade.net public bool IsNewPulseGuidingSupported() { - switch (GuidingStyle) + switch (_GuidingStyle) { case "guide rate slew": return false; @@ -1501,7 +1501,7 @@ namespace ASCOM.Meade.net get { LogMessage("FocalLength Get", "Not implemented"); - throw new PropertyNotImplementedException("FocalLength", false); + return _focalLength; } } @@ -1528,7 +1528,7 @@ namespace ASCOM.Meade.net //info from RickB says that 15.04107 is a better value for - GuideRate = value; + _GuideRate = value; WriteProfile(); } @@ -1547,8 +1547,8 @@ namespace ASCOM.Meade.net { get { - var degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(GuideRate); - LogMessage("GuideRateDeclination Get", $"{GuideRate} arc seconds / second = {degreesPerSecond} degrees per second"); + var degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_GuideRate); + LogMessage("GuideRateDeclination Get", $"{_GuideRate} arc seconds / second = {degreesPerSecond} degrees per second"); return degreesPerSecond; } set @@ -1562,8 +1562,8 @@ namespace ASCOM.Meade.net { get { - double degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(GuideRate); - LogMessage("GuideRateRightAscension Get", $"{GuideRate} arc seconds / second = {degreesPerSecond} degrees per second"); + double degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_GuideRate); + LogMessage("GuideRateRightAscension Get", $"{_GuideRate} arc seconds / second = {degreesPerSecond} degrees per second"); return degreesPerSecond; } set @@ -1698,7 +1698,7 @@ namespace ASCOM.Meade.net return; ParkedPosition parkedPosition; - switch (ParkedBehaviour) + switch (_ParkedBehaviour) { case ParkedBehaviour.LastGoodPosition: parkedPosition = new ParkedPosition @@ -1715,12 +1715,12 @@ namespace ASCOM.Meade.net var utcDateTime = UTCDate; var latitude = SiteLatitude; var longitude = SiteLongitude; - var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, ParkedAltAz); + var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, _ParkedAltAz); parkedPosition = new ParkedPosition { - Altitude = ParkedAltAz.Altitude, - Azimuth = ParkedAltAz.Azimuth, + Altitude = _ParkedAltAz.Altitude, + Azimuth = _ParkedAltAz.Azimuth, RightAscension = raDec.RightAscension, Declination = raDec.Declination, SiteLatitude = latitude, @@ -1975,14 +1975,14 @@ namespace ASCOM.Meade.net } } - public new double SiteElevation + public double SiteElevation { get { CheckConnected("SiteElevation Get"); - LogMessage("SiteElevation", $"Get {base.SiteElevation}"); - return base.SiteElevation; + LogMessage("SiteElevation", $"Get {_SiteElevation}"); + return _SiteElevation; } // ReSharper disable once ValueParameterNotUsed set @@ -1990,14 +1990,14 @@ namespace ASCOM.Meade.net CheckConnected("SiteElevation Set"); LogMessage("SiteElevation", $"Set: {value}"); - if (Math.Abs(value - base.SiteElevation) < 0.1) + if (Math.Abs(value - _SiteElevation) < 0.1) { LogMessage("SiteElevation", "Set: no change detected"); return; } - LogMessage("SiteElevation", $"Set: {value} was {base.SiteElevation}"); - base.SiteElevation = value; + LogMessage("SiteElevation", $"Set: {value} was {_SiteElevation}"); + _SiteElevation = value; UpdateSiteElevation(); } } @@ -2025,7 +2025,7 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("unable to get site latitude from telescope."); } - catch (ParkedException) when (ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) + catch (ParkedException) when (_ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) { return parkedPosition.SiteLatitude; } @@ -2083,7 +2083,7 @@ namespace ASCOM.Meade.net return siteLongitude; } - catch (ParkedException) when (ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) + catch (ParkedException) when (_ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) { return parkedPosition.SiteLongitude; } @@ -2354,7 +2354,7 @@ namespace ASCOM.Meade.net private TimeSpan GetTotalSlewingSettleTime() { - return TimeSpan.FromSeconds( SlewSettleTime + ProfileSettleTime ); + return TimeSpan.FromSeconds( SlewSettleTime + _ProfileSettleTime ); } private bool GetSlewing() @@ -2779,7 +2779,7 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - if (ParkedBehaviour == ParkedBehaviour.NoCoordinates) + if (_ParkedBehaviour == ParkedBehaviour.NoCoordinates) throw; return _clock.UtcNow; @@ -2962,10 +2962,10 @@ namespace ASCOM.Meade.net var profileProperties = SharedResourcesWrapper.ReadProfile(); - if (Math.Abs(profileProperties.GuideRateArcSecondsPerSecond - GuideRate) > 0.0000001) + if (Math.Abs(profileProperties.GuideRateArcSecondsPerSecond - _GuideRate) > 0.0000001) { changed = true; - profileProperties.GuideRateArcSecondsPerSecond = GuideRate; + profileProperties.GuideRateArcSecondsPerSecond = _GuideRate; } if (changed) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index b9becdf..518c59c 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -171,6 +171,7 @@ namespace Meade.net.UnitTests string ParkedBehaviourDefault = "No Coordinates"; string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; + string FocalLengthDefault = "2000"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -222,6 +223,10 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) .Returns(() => ParkedAzimuthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) + .Returns(() => FocalLengthDefault); + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Send Date and time on connect", string.Empty, "false")) .Returns(() => SendDateTimeDefault); @@ -295,6 +300,7 @@ namespace Meade.net.UnitTests string ParkedBehaviourDefault = "No Coordinates"; string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; + string FocalLengthDefault = "2000"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -337,6 +343,9 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) .Returns(() => ParkedAzimuthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) + .Returns(() => FocalLengthDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -375,6 +384,7 @@ namespace Meade.net.UnitTests string ParkedBehaviourDefault = "No Coordinates"; string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; + string FocalLengthDefault = "2000"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -416,6 +426,9 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) .Returns(() => ParkedAzimuthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) + .Returns(() => FocalLengthDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -468,6 +481,7 @@ namespace Meade.net.UnitTests string ParkedBehaviourDefault = "No Coordinates"; string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; + string FocalLengthDefault = "2000"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -509,6 +523,9 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) .Returns(() => ParkedAzimuthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) + .Returns(() => FocalLengthDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -558,6 +575,7 @@ namespace Meade.net.UnitTests string ParkedBehaviourDefault = "No Coordinates"; string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; + string FocalLengthDefault = "2000"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -598,6 +616,9 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault)) .Returns(() => ParkedAzimuthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) + .Returns(() => FocalLengthDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index d547177..0ef3771 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -176,12 +176,12 @@ namespace ASCOM.Meade.net } catch (Exception ex) { - LogMessage("Connected Set", "Error connecting to port {0} - {1}", ComPort, ex.Message); + LogMessage("Connected Set", "Error connecting to port {0} - {1}", _ComPort, ex.Message); } } else { - LogMessage("Connected Set", "Disconnecting from port {0}", ComPort); + LogMessage("Connected Set", "Disconnecting from port {0}", _ComPort); SharedResourcesWrapper.Disconnect("Serial", DriverId); IsConnected = false; } @@ -295,11 +295,11 @@ namespace ASCOM.Meade.net return; var direction = position > 0; - if (ReverseFocusDirection) + if (_ReverseFocusDirection) direction = !direction; //backlash compensation. - var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0; + var backlashCompensationSteps = direction ? Math.Abs(_BacklashCompensation) : 0; var steps = Math.Abs(position) + backlashCompensationSteps; @@ -322,7 +322,7 @@ namespace ASCOM.Meade.net private void DynamicBreaking(bool directionOut) { - if (!UseDynamicBreaking) + if (!_UseDynamicBreaking) return; Tl.LogMessage("Move", "Applying dynamic breaking"); diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 5e4c942..a9bfca7 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -20,18 +20,19 @@ namespace ASCOM.Meade.net /// protected static readonly string DriverDescription = "Meade Generic"; - protected static string ComPort; // Variables to hold the currrent device configuration - protected static int BacklashCompensation; - protected static bool ReverseFocusDirection; - protected static bool UseDynamicBreaking; - protected double GuideRate; - protected string Precision; - protected string GuidingStyle; - protected double SiteElevation; - protected short ProfileSettleTime; - protected bool SendDateTime; - protected ParkedBehaviour ParkedBehaviour; - protected HorizonCoordinates ParkedAltAz; + protected static string _ComPort; // Variables to hold the currrent device configuration + protected static int _BacklashCompensation; + protected static bool _ReverseFocusDirection; + protected static bool _UseDynamicBreaking; + protected double _GuideRate; + protected string _Precision; + protected string _GuidingStyle; + protected double _SiteElevation; + protected short _ProfileSettleTime; + protected bool _SendDateTime; + protected ParkedBehaviour _ParkedBehaviour; + protected HorizonCoordinates _ParkedAltAz; + protected double _focalLength; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -64,37 +65,41 @@ namespace ASCOM.Meade.net { var profileProperties = SharedResourcesWrapper.ReadProfile(); Tl.Enabled = profileProperties.TraceLogger; - ComPort = profileProperties.ComPort; - BacklashCompensation = profileProperties.BacklashCompensation; - ReverseFocusDirection = profileProperties.ReverseFocusDirection; - UseDynamicBreaking = profileProperties.DynamicBreaking; - GuideRate = profileProperties.GuideRateArcSecondsPerSecond; - Precision = profileProperties.Precision; - GuidingStyle = profileProperties.GuidingStyle.ToLower(); - SiteElevation = profileProperties.SiteElevation; - ProfileSettleTime = profileProperties.SettleTime; - SendDateTime = profileProperties.SendDateTime; - ParkedBehaviour = profileProperties.ParkedBehaviour; + _ComPort = profileProperties.ComPort; + _BacklashCompensation = profileProperties.BacklashCompensation; + _ReverseFocusDirection = profileProperties.ReverseFocusDirection; + _UseDynamicBreaking = profileProperties.DynamicBreaking; + _GuideRate = profileProperties.GuideRateArcSecondsPerSecond; + _Precision = profileProperties.Precision; + _GuidingStyle = profileProperties.GuidingStyle.ToLower(); + _SiteElevation = profileProperties.SiteElevation; + _ProfileSettleTime = profileProperties.SettleTime; + _SendDateTime = profileProperties.SendDateTime; + _ParkedBehaviour = profileProperties.ParkedBehaviour; - ParkedAltAz = new HorizonCoordinates + _ParkedAltAz = new HorizonCoordinates { Altitude = profileProperties.ParkedAlt, Azimuth = profileProperties.ParkedAz }; + _focalLength = profileProperties.FocalLength; + LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); - LogMessage("ReadProfile", $"Com Port: {ComPort}"); - LogMessage("ReadProfile", $"Backlash Steps: {BacklashCompensation}"); - LogMessage("ReadProfile", $"Dynamic breaking: {UseDynamicBreaking}"); - LogMessage("ReadProfile", $"Guide Rate: {GuideRate}"); - LogMessage("ReadProfile", $"Precision: {Precision}"); - LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); - LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); - LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); - LogMessage("ReadProfile", $"Send date and time on connect: {SendDateTime}"); - LogMessage("ReadProfile", $"Parked Behaviour: {ParkedBehaviour}"); - LogMessage("ReadProfile", $"Parked Alt: {ParkedAltAz.Altitude}"); - LogMessage("ReadProfile", $"Parked Az: {ParkedAltAz.Azimuth}"); + LogMessage("ReadProfile", $"Com Port: {_ComPort}"); + LogMessage("ReadProfile", $"Backlash Steps: {_BacklashCompensation}"); + LogMessage("ReadProfile", $"Dynamic breaking: {_UseDynamicBreaking}"); + LogMessage("ReadProfile", $"Guide Rate: {_GuideRate}"); + LogMessage("ReadProfile", $"Precision: {_Precision}"); + LogMessage("ReadProfile", $"Guiding Style: {_GuidingStyle}"); + LogMessage("ReadProfile", $"Site Elevation: {_SiteElevation}"); + LogMessage("ReadProfile", $"Settle Time after slew: {_ProfileSettleTime}"); + LogMessage("ReadProfile", $"Send date and time on connect: {_SendDateTime}"); + LogMessage("ReadProfile", $"Parked Behaviour: {_ParkedBehaviour}"); + LogMessage("ReadProfile", $"Parked Alt: {_ParkedAltAz.Altitude}"); + LogMessage("ReadProfile", $"Parked Az: {_ParkedAltAz.Azimuth}"); + LogMessage("ReadProfile", $"Focal Length: {_focalLength}"); + } /// @@ -159,7 +164,7 @@ namespace ASCOM.Meade.net protected void UpdateSiteElevation() { var profileProperties = SharedResourcesWrapper.ReadProfile(); - profileProperties.SiteElevation = SiteElevation; + profileProperties.SiteElevation = _SiteElevation; SharedResourcesWrapper.WriteProfile(profileProperties); } } diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 8cd29c5..0e75d6b 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -23,5 +23,6 @@ namespace ASCOM.Meade.net public ParkedBehaviour ParkedBehaviour { get; set; } public double ParkedAlt { get; set; } public double ParkedAz { get; set; } + public double FocalLength { get; set; } } } \ No newline at end of file diff --git a/Meade.net/Properties/Resources.Designer.cs b/Meade.net/Properties/Resources.Designer.cs index c735eec..782d4a9 100644 --- a/Meade.net/Properties/Resources.Designer.cs +++ b/Meade.net/Properties/Resources.Designer.cs @@ -144,5 +144,14 @@ namespace ASCOM.Meade.net.Properties { return ResourceManager.GetString("SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_", resourceCulture); } } + + /// + /// Looks up a localized string similar to Please enter only numbers.. + /// + internal static string SetupDialogForm_txtFocalLength_TextChanged_1_Please_enter_only_numbers_ { + get { + return ResourceManager.GetString("SetupDialogForm_txtFocalLength_TextChanged_1_Please_enter_only_numbers_", resourceCulture); + } + } } } diff --git a/Meade.net/Properties/Resources.resx b/Meade.net/Properties/Resources.resx index 9de5db4..355a3f1 100644 --- a/Meade.net/Properties/Resources.resx +++ b/Meade.net/Properties/Resources.resx @@ -147,4 +147,7 @@ Valid are : -register, -unregister and -embedding Please enter only numbers. + + Please enter only numbers. + \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 3b7b039..fd661a4 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -188,6 +188,15 @@ namespace ASCOM.Meade.net txtParkedAz.Text = "180"; } + try + { + txtFocalLength.Text = profileProperties.FocalLength.ToString(CultureInfo.CurrentCulture); + } + catch (Exception) + { + txtFocalLength.Text = "2000"; + } + UpdateParkedItemsEnabled(); } @@ -214,7 +223,8 @@ namespace ASCOM.Meade.net SendDateTime = cbxSendDateTime.Checked, ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription(cboParkedBehaviour.SelectedItem.ToString()), ParkedAlt = double.Parse(txtParkedAlt.Text), - ParkedAz = double.Parse(txtParkedAz.Text) + ParkedAz = double.Parse(txtParkedAz.Text), + FocalLength = double.Parse(txtFocalLength.Text) }; return profileProperties; @@ -320,6 +330,15 @@ namespace ASCOM.Meade.net txtParkedAz.Text = txtParkedAz.Text.Remove(txtParkedAz.Text.Length - 1); } } + + private void txt_FocalLength_TextChanged_1(object sender, EventArgs e) + { + if (System.Text.RegularExpressions.Regex.IsMatch(txtFocalLength.Text, "[^0-9]")) + { + MessageBox.Show(Resources.SetupDialogForm_txtFocalLength_TextChanged_1_Please_enter_only_numbers_); + txtFocalLength.Text = txtFocalLength.Text.Remove(txtFocalLength.Text.Length - 1); + } + } } } diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index b401604..f710e6a 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -82,6 +82,9 @@ namespace ASCOM.Meade.net this.label24 = new System.Windows.Forms.Label(); this.txtParkedAlt = new System.Windows.Forms.TextBox(); this.txtParkedAz = new System.Windows.Forms.TextBox(); + this.label25 = new System.Windows.Forms.Label(); + this.txtFocalLength = new System.Windows.Forms.TextBox(); + this.label26 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).BeginInit(); @@ -389,10 +392,29 @@ namespace ASCOM.Meade.net this.txtParkedAz.Name = "txtParkedAz"; this.txtParkedAz.TextChanged += new System.EventHandler(this.txtParkedAz_TextChanged); // + // label25 + // + resources.ApplyResources(this.label25, "label25"); + this.label25.Name = "label25"; + // + // txtFocalLength + // + resources.ApplyResources(this.txtFocalLength, "txtFocalLength"); + this.txtFocalLength.Name = "txtFocalLength"; + this.txtFocalLength.TextChanged += new System.EventHandler(this.txt_FocalLength_TextChanged_1); + // + // label26 + // + resources.ApplyResources(this.label26, "label26"); + this.label26.Name = "label26"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label26); + this.Controls.Add(this.txtFocalLength); + this.Controls.Add(this.label25); this.Controls.Add(this.txtParkedAz); this.Controls.Add(this.txtParkedAlt); this.Controls.Add(this.label24); @@ -507,5 +529,8 @@ namespace ASCOM.Meade.net private Label label24; private TextBox txtParkedAlt; private TextBox txtParkedAz; + private Label label25; + private TextBox txtFocalLength; + private Label label26; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 2e52c51..706338b 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 47 + 50 Bottom, Right @@ -172,7 +172,7 @@ $this - 46 + 49 12, 9 @@ -196,7 +196,7 @@ $this - 45 + 48 Top, Right @@ -223,7 +223,7 @@ $this - 44 + 47 True @@ -250,7 +250,7 @@ $this - 43 + 46 True @@ -277,7 +277,7 @@ $this - 42 + 45 97, 87 @@ -298,13 +298,13 @@ $this - 41 + 44 True - 290, 169 + 290, 187 61, 13 @@ -325,13 +325,13 @@ $this - 40 + 43 17, 17 - 375, 166 + 375, 184 46, 20 @@ -355,13 +355,13 @@ $this - 39 + 42 True - 427, 169 + 427, 187 122, 13 @@ -382,13 +382,13 @@ $this - 38 + 41 True - 427, 182 + 427, 200 105, 13 @@ -409,13 +409,13 @@ $this - 37 + 40 True - 290, 201 + 290, 219 50, 13 @@ -436,7 +436,7 @@ $this - 36 + 39 Unchanged @@ -448,7 +448,7 @@ High - 375, 198 + 375, 216 90, 21 @@ -466,7 +466,7 @@ $this - 35 + 38 True @@ -475,7 +475,7 @@ NoControl - 290, 228 + 290, 246 67, 13 @@ -496,7 +496,7 @@ $this - 34 + 37 Auto @@ -508,7 +508,7 @@ Pulse guiding - 375, 225 + 375, 243 90, 21 @@ -526,7 +526,7 @@ $this - 33 + 36 True @@ -556,7 +556,7 @@ $this - 32 + 35 True @@ -589,7 +589,7 @@ $this - 31 + 34 375, 302 @@ -613,7 +613,7 @@ $this - 29 + 32 True @@ -643,7 +643,7 @@ $this - 30 + 33 True @@ -673,7 +673,7 @@ $this - 28 + 31 True @@ -706,7 +706,7 @@ $this - 27 + 30 True @@ -733,7 +733,7 @@ $this - 26 + 29 True @@ -760,7 +760,7 @@ $this - 25 + 28 True @@ -793,7 +793,7 @@ $this - 24 + 27 17, 17 @@ -829,13 +829,13 @@ $this - 6 + 9 True - 290, 96 + 290, 114 72, 13 @@ -856,10 +856,10 @@ $this - 23 + 26 - 375, 93 + 375, 111 100, 20 @@ -877,13 +877,13 @@ $this - 22 + 25 True - 481, 96 + 481, 114 38, 13 @@ -904,13 +904,13 @@ $this - 21 + 24 True - 290, 127 + 290, 145 56, 13 @@ -931,10 +931,10 @@ $this - 20 + 23 - 375, 125 + 375, 143 120, 20 @@ -952,13 +952,13 @@ $this - 19 + 22 True - 501, 127 + 501, 145 47, 13 @@ -979,7 +979,7 @@ $this - 18 + 21 True @@ -1006,7 +1006,7 @@ $this - 17 + 20 97, 163 @@ -1027,7 +1027,7 @@ $this - 16 + 19 97, 137 @@ -1048,7 +1048,7 @@ $this - 15 + 18 97, 190 @@ -1069,7 +1069,7 @@ $this - 14 + 17 97, 217 @@ -1090,7 +1090,7 @@ $this - 13 + 16 97, 244 @@ -1111,7 +1111,7 @@ $this - 12 + 15 True @@ -1138,7 +1138,7 @@ $this - 11 + 14 True @@ -1165,7 +1165,7 @@ $this - 10 + 13 True @@ -1192,7 +1192,7 @@ $this - 9 + 12 True @@ -1219,7 +1219,7 @@ $this - 8 + 11 True @@ -1252,7 +1252,7 @@ $this - 7 + 10 No Coordinates @@ -1282,7 +1282,7 @@ $this - 5 + 8 True @@ -1309,7 +1309,7 @@ $this - 4 + 7 True @@ -1336,7 +1336,7 @@ $this - 3 + 6 True @@ -1363,7 +1363,7 @@ $this - 2 + 5 697, 151 @@ -1384,7 +1384,7 @@ $this - 1 + 4 697, 177 @@ -1405,6 +1405,87 @@ $this + 3 + + + True + + + NoControl + + + 290, 90 + + + 69, 13 + + + 48 + + + Focal Length + + + label25 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + 375, 87 + + + 100, 20 + + + 49 + + + txtFocalLength + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + NoControl + + + 481, 90 + + + 23, 13 + + + 50 + + + mm + + + label26 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 2e51fdf..f813870 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -198,6 +198,7 @@ namespace ASCOM.Meade.net private const string ParkedBehaviourName = "Parked Behaviour"; private const string ParkedAltName = "Parked Altitude"; private const string ParkedAzimuthName = "Parked Azimuth"; + private const string FocalLengthName = "Focal Length (mm)"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -226,6 +227,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, ParkedBehaviourName, profileProperties.ParkedBehaviour.GetDescription()); driverProfile.WriteValue(DriverId, ParkedAltName, profileProperties.ParkedAlt.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, ParkedAzimuthName, profileProperties.ParkedAz.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, FocalLengthName, profileProperties.FocalLength.ToString(CultureInfo.InvariantCulture)); } } } @@ -250,6 +252,7 @@ namespace ASCOM.Meade.net private const string ParkedBehaviourDefault = "No Coordinates"; private const string ParkedAltDefault = "0"; private const string ParkedAzimuthDefault = "180"; + private const string FocalLengthDefault = "2000"; public static ProfileProperties ReadProfile() { @@ -280,6 +283,7 @@ namespace ASCOM.Meade.net profileProperties.ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription(driverProfile.GetValue(DriverId, ParkedBehaviourName, string.Empty, ParkedBehaviourDefault)); profileProperties.ParkedAlt = double.Parse(driverProfile.GetValue(DriverId, ParkedAltName, string.Empty, ParkedAltDefault), NumberFormatInfo.InvariantInfo); profileProperties.ParkedAz = double.Parse(driverProfile.GetValue(DriverId, ParkedAzimuthName, string.Empty, ParkedAzimuthDefault), NumberFormatInfo.InvariantInfo); + profileProperties.FocalLength = double.Parse(driverProfile.GetValue(DriverId, FocalLengthName, string.Empty, FocalLengthDefault), NumberFormatInfo.InvariantInfo); } return profileProperties; From f788320927d1b040f62a073fe117e913682e17ea Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 3 May 2022 21:57:25 +0100 Subject: [PATCH 09/47] Refactor to use ProfileProperties instead of assigning individual variables. Added support for ApertureArea and ApertureDiameter --- .../TelescopeUnitTests.cs | 27 +- Meade.net.Telescope/Telescope.cs | 88 ++--- .../SharedResourcesUnitTests.cs | 50 ++- Meade.net.focuser/Focuser.cs | 10 +- Meade.net/MeadeTelescopeBase.cs | 70 ++-- Meade.net/ProfileProperties.cs | 2 + Meade.net/SetupDialogForm.cs | 22 +- Meade.net/SetupDialogForm.designer.cs | 48 +++ Meade.net/SetupDialogForm.resx | 319 +++++++++++++----- Meade.net/SharedResources.cs | 8 + 10 files changed, 445 insertions(+), 199 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 9cc12d8..72761b7 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -636,12 +636,9 @@ namespace Meade.net.Telescope.UnitTests public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string guidingStyle, string productName, string firmware, bool isSupported) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); - _profileProperties.GuidingStyle = guidingStyle; - _telescope.Connected = true; + ConnectTelescope(productName, firmware); var result = _telescope.IsNewPulseGuidingSupported(); @@ -853,29 +850,19 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void ApertureArea_Get_ThrowsNotImplementedException() + public void ApertureArea_Get_ReturnsExpectedResult() { - var excpetion = Assert.Throws(() => - { - var result = _telescope.ApertureArea; - Assert.Fail($"{result} should not have returned"); - }); + var result = _telescope.ApertureArea; - Assert.That(excpetion.Property, Is.EqualTo("ApertureArea")); - Assert.That(excpetion.AccessorSet, Is.False); + Assert.That(result, Is.EqualTo(_profileProperties.ApertureArea / 1000)); } [Test] public void ApertureDiameter_Get_ThrowsNotImplementedException() { - var excpetion = Assert.Throws(() => - { - var result = _telescope.ApertureDiameter; - Assert.Fail($"{result} should not have returned"); - }); + var result = _telescope.ApertureDiameter; - Assert.That(excpetion.Property, Is.EqualTo("ApertureDiameter")); - Assert.That(excpetion.AccessorSet, Is.False); + Assert.That(result, Is.EqualTo(_profileProperties.ApertureDiameter / 1000)); } [Test] @@ -1434,7 +1421,7 @@ namespace Meade.net.Telescope.UnitTests { var result = _telescope.FocalLength; - Assert.That(result, Is.EqualTo(_profileProperties.FocalLength)); + Assert.That(result, Is.EqualTo(_profileProperties.FocalLength/1000)); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 26e0428..af929af 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -419,12 +419,12 @@ namespace ASCOM.Meade.net { ReadProfile(); - LogMessage("Connected Set", "Connecting to port {0}", _ComPort); + LogMessage("Connected Set", "Connecting to port {0}", _profileProperties.ComPort); var connectionInfo = SharedResourcesWrapper.Connect("Serial", DriverId, Tl); try { LogMessage("Connected Set", - $"Connected to port {_ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); + $"Connected to port {_profileProperties.ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); _userNewerPulseGuiding = IsNewPulseGuidingSupported(); @@ -444,7 +444,7 @@ namespace ASCOM.Meade.net if (CanSetGuideRates) { - SetNewGuideRate(_GuideRate, "Connect"); + SetNewGuideRate(_profileProperties.GuideRateArcSecondsPerSecond, "Connect"); } SetTelescopePrecision("Connect"); @@ -454,28 +454,28 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.TargetDeclination = InvalidParameter; SharedResourcesWrapper.TargetRightAscension = InvalidParameter; - LogMessage("Connected Set", $"SendDateTime: {_SendDateTime}"); - if (_SendDateTime) + LogMessage("Connected Set", $"SendDateTime: {_profileProperties.SendDateTime}"); + if (_profileProperties.SendDateTime) { if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { LogMessage("Connected Set", - $"LX200GPS Detecting if daylight savings message on screen: {_SendDateTime}"); + $"LX200GPS Detecting if daylight savings message on screen: {_profileProperties.SendDateTime}"); var displayText = Action("Handbox", "readdisplay"); LogMessage("Connected Set", $"Current Handset display: {displayText}"); if (displayText.Contains("Daylight")) { LogMessage("Connected Set", - $"LX200GPS Setting Date time and bypassing settings screens: {_SendDateTime}"); + $"LX200GPS Setting Date time and bypassing settings screens: {_profileProperties.SendDateTime}"); BypassHandboxEntryForAutostarII(); } else { LogMessage("Connected Set", - $"LX200GPS Sending current date and time: {_SendDateTime}"); + $"LX200GPS Sending current date and time: {_profileProperties.SendDateTime}"); SendCurrentDateTime("Connect"); LogMessage("Connected Set", - $"LX200GPS Attempting manual bypass of prompts: {_SendDateTime}"); + $"LX200GPS Attempting manual bypass of prompts: {_profileProperties.SendDateTime}"); ApplySkipAutoStarPrompts("Connect"); } @@ -514,12 +514,12 @@ namespace ASCOM.Meade.net } catch (Exception ex) { - LogMessage("Connected Set", "Error connecting to port {0} - {1}", _ComPort, ex.Message); + LogMessage("Connected Set", "Error connecting to port {0} - {1}", _profileProperties.ComPort, ex.Message); } } else { - LogMessage("Connected Set", "Disconnecting from port {0}", _ComPort); + LogMessage("Connected Set", "Disconnecting from port {0}", _profileProperties.ComPort); SharedResourcesWrapper.Disconnect("Serial", DriverId); IsConnected = false; } @@ -528,7 +528,7 @@ namespace ASCOM.Meade.net private void SendCurrentDateTime(string connect) { - if (_SendDateTime) + if (_profileProperties.SendDateTime) { UTCDate = _clock.UtcNow; } @@ -570,7 +570,7 @@ namespace ASCOM.Meade.net private void SetTelescopePrecision(string propertyName) { - switch (_Precision.ToLower()) + switch (_profileProperties.Precision.ToLower()) { case "high": TelescopePointingPrecision(true); @@ -588,7 +588,7 @@ namespace ASCOM.Meade.net public bool IsNewPulseGuidingSupported() { - switch (_GuidingStyle) + switch (_profileProperties.GuidingStyle.ToLower()) { case "guide rate slew": return false; @@ -1161,8 +1161,9 @@ namespace ASCOM.Meade.net { get { - LogMessage("ApertureArea Get", "Not implemented"); - throw new PropertyNotImplementedException("ApertureArea", false); + var apertureArea = _profileProperties.ApertureArea / 1000; + LogMessage("ApertureArea Get", $"{apertureArea}"); + return apertureArea; } } @@ -1170,8 +1171,9 @@ namespace ASCOM.Meade.net { get { - LogMessage("ApertureDiameter Get", "Not implemented"); - throw new PropertyNotImplementedException("ApertureDiameter", false); + var apertureDiameter = _profileProperties.ApertureDiameter / 1000; + LogMessage("ApertureDiameter Get", $"{apertureDiameter}"); + return apertureDiameter; } } @@ -1500,8 +1502,9 @@ namespace ASCOM.Meade.net { get { - LogMessage("FocalLength Get", "Not implemented"); - return _focalLength; + var focalLength = _profileProperties.FocalLength / 1000; + LogMessage("FocalLength Get", $"{focalLength}"); + return focalLength; } } @@ -1528,7 +1531,7 @@ namespace ASCOM.Meade.net //info from RickB says that 15.04107 is a better value for - _GuideRate = value; + _profileProperties.GuideRateArcSecondsPerSecond = value; WriteProfile(); } @@ -1547,8 +1550,8 @@ namespace ASCOM.Meade.net { get { - var degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_GuideRate); - LogMessage("GuideRateDeclination Get", $"{_GuideRate} arc seconds / second = {degreesPerSecond} degrees per second"); + var degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_profileProperties.GuideRateArcSecondsPerSecond); + LogMessage("GuideRateDeclination Get", $"{_profileProperties.GuideRateArcSecondsPerSecond} arc seconds / second = {degreesPerSecond} degrees per second"); return degreesPerSecond; } set @@ -1562,8 +1565,8 @@ namespace ASCOM.Meade.net { get { - double degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_GuideRate); - LogMessage("GuideRateRightAscension Get", $"{_GuideRate} arc seconds / second = {degreesPerSecond} degrees per second"); + double degreesPerSecond = ArcSecondPerSecondToDegreesPerSecond(_profileProperties.GuideRateArcSecondsPerSecond); + LogMessage("GuideRateRightAscension Get", $"{_profileProperties.GuideRateArcSecondsPerSecond} arc seconds / second = {degreesPerSecond} degrees per second"); return degreesPerSecond; } set @@ -1698,7 +1701,7 @@ namespace ASCOM.Meade.net return; ParkedPosition parkedPosition; - switch (_ParkedBehaviour) + switch (_profileProperties.ParkedBehaviour) { case ParkedBehaviour.LastGoodPosition: parkedPosition = new ParkedPosition @@ -1715,12 +1718,17 @@ namespace ASCOM.Meade.net var utcDateTime = UTCDate; var latitude = SiteLatitude; var longitude = SiteLongitude; - var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, _ParkedAltAz); + var parkedAltAz = new HorizonCoordinates() + { + Altitude = _profileProperties.ParkedAlt, + Azimuth = _profileProperties.ParkedAz + }; + var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, parkedAltAz); parkedPosition = new ParkedPosition { - Altitude = _ParkedAltAz.Altitude, - Azimuth = _ParkedAltAz.Azimuth, + Altitude = parkedAltAz.Altitude, + Azimuth = parkedAltAz.Azimuth, RightAscension = raDec.RightAscension, Declination = raDec.Declination, SiteLatitude = latitude, @@ -1981,8 +1989,8 @@ namespace ASCOM.Meade.net { CheckConnected("SiteElevation Get"); - LogMessage("SiteElevation", $"Get {_SiteElevation}"); - return _SiteElevation; + LogMessage("SiteElevation", $"Get {_profileProperties.SiteElevation}"); + return _profileProperties.SiteElevation; } // ReSharper disable once ValueParameterNotUsed set @@ -1990,14 +1998,14 @@ namespace ASCOM.Meade.net CheckConnected("SiteElevation Set"); LogMessage("SiteElevation", $"Set: {value}"); - if (Math.Abs(value - _SiteElevation) < 0.1) + if (Math.Abs(value - _profileProperties.SiteElevation) < 0.1) { LogMessage("SiteElevation", "Set: no change detected"); return; } - LogMessage("SiteElevation", $"Set: {value} was {_SiteElevation}"); - _SiteElevation = value; + LogMessage("SiteElevation", $"Set: {value} was {_profileProperties.SiteElevation}"); + _profileProperties.SiteElevation = value; UpdateSiteElevation(); } } @@ -2025,7 +2033,7 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("unable to get site latitude from telescope."); } - catch (ParkedException) when (_ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) + catch (ParkedException) when (_profileProperties.ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) { return parkedPosition.SiteLatitude; } @@ -2083,7 +2091,7 @@ namespace ASCOM.Meade.net return siteLongitude; } - catch (ParkedException) when (_ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) + catch (ParkedException) when (_profileProperties.ParkedBehaviour != ParkedBehaviour.NoCoordinates && SharedResourcesWrapper.ParkedPosition is var parkedPosition) { return parkedPosition.SiteLongitude; } @@ -2354,7 +2362,7 @@ namespace ASCOM.Meade.net private TimeSpan GetTotalSlewingSettleTime() { - return TimeSpan.FromSeconds( SlewSettleTime + _ProfileSettleTime ); + return TimeSpan.FromSeconds( SlewSettleTime + _profileProperties.SettleTime ); } private bool GetSlewing() @@ -2779,7 +2787,7 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - if (_ParkedBehaviour == ParkedBehaviour.NoCoordinates) + if (_profileProperties.ParkedBehaviour == ParkedBehaviour.NoCoordinates) throw; return _clock.UtcNow; @@ -2962,10 +2970,10 @@ namespace ASCOM.Meade.net var profileProperties = SharedResourcesWrapper.ReadProfile(); - if (Math.Abs(profileProperties.GuideRateArcSecondsPerSecond - _GuideRate) > 0.0000001) + if (Math.Abs(profileProperties.GuideRateArcSecondsPerSecond - _profileProperties.GuideRateArcSecondsPerSecond) > 0.0000001) { changed = true; - profileProperties.GuideRateArcSecondsPerSecond = _GuideRate; + profileProperties.GuideRateArcSecondsPerSecond = _profileProperties.GuideRateArcSecondsPerSecond; } if (changed) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 518c59c..30582f1 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -172,6 +172,8 @@ namespace Meade.net.UnitTests string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; string FocalLengthDefault = "2000"; + string ApertureAreaDefault = "32685"; + string ApertureDiameterDefault = "203"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -227,6 +229,15 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) .Returns(() => FocalLengthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault)) + .Returns(() => ApertureAreaDefault); + + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault)) + .Returns(() => ApertureDiameterDefault); + + profileWrapperMock.Setup(x => x.GetValue(DriverId, "Send Date and time on connect", string.Empty, "false")) .Returns(() => SendDateTimeDefault); @@ -300,7 +311,9 @@ namespace Meade.net.UnitTests string ParkedBehaviourDefault = "No Coordinates"; string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; - string FocalLengthDefault = "2000"; + string FocalLengthDefault = "2000"; + string ApertureAreaDefault = "32685"; + string ApertureDiameterDefault = "203"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -347,6 +360,15 @@ namespace Meade.net.UnitTests x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) .Returns(() => FocalLengthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault)) + .Returns(() => ApertureAreaDefault); + + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault)) + .Returns(() => ApertureDiameterDefault); + + Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -356,7 +378,7 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.Transmit("#:GVP#")).Callback(() => { serialPortReturn = ":GVP#"; }); _serialMock.Setup(x => x.Transmit("#:GG#")).Callback(() => { serialPortReturn = "0"; }); - _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns( () => serialPortReturn); + _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn); var result = Assert.Throws(() => { SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); }); Assert.That(result.Message, Is.EqualTo("Serial port is looping back data, something is wrong with the hardware.")); @@ -385,6 +407,8 @@ namespace Meade.net.UnitTests string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; string FocalLengthDefault = "2000"; + string ApertureAreaDefault = "32685"; + string ApertureDiameterDefault = "203"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -429,6 +453,12 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) .Returns(() => FocalLengthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault)) + .Returns(() => ApertureAreaDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault)) + .Returns(() => ApertureDiameterDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -482,6 +512,8 @@ namespace Meade.net.UnitTests string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; string FocalLengthDefault = "2000"; + string ApertureAreaDefault = "32685"; + string ApertureDiameterDefault = "203"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -526,6 +558,12 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) .Returns(() => FocalLengthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault)) + .Returns(() => ApertureAreaDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault)) + .Returns(() => ApertureDiameterDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); @@ -576,6 +614,8 @@ namespace Meade.net.UnitTests string ParkedAltDefault = "0"; string ParkedAzimuthDefault = "180"; string FocalLengthDefault = "2000"; + string ApertureAreaDefault = "32685"; + string ApertureDiameterDefault = "203"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); @@ -619,6 +659,12 @@ namespace Meade.net.UnitTests profileWrapperMock.Setup(x => x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault)) .Returns(() => FocalLengthDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault)) + .Returns(() => ApertureAreaDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault)) + .Returns(() => ApertureDiameterDefault); Mock profileFactoryMock = new Mock(); profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object); diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index 0ef3771..75ae1cc 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -176,12 +176,12 @@ namespace ASCOM.Meade.net } catch (Exception ex) { - LogMessage("Connected Set", "Error connecting to port {0} - {1}", _ComPort, ex.Message); + LogMessage("Connected Set", "Error connecting to port {0} - {1}", _profileProperties.ComPort, ex.Message); } } else { - LogMessage("Connected Set", "Disconnecting from port {0}", _ComPort); + LogMessage("Connected Set", "Disconnecting from port {0}", _profileProperties.ComPort); SharedResourcesWrapper.Disconnect("Serial", DriverId); IsConnected = false; } @@ -295,11 +295,11 @@ namespace ASCOM.Meade.net return; var direction = position > 0; - if (_ReverseFocusDirection) + if (_profileProperties.ReverseFocusDirection) direction = !direction; //backlash compensation. - var backlashCompensationSteps = direction ? Math.Abs(_BacklashCompensation) : 0; + var backlashCompensationSteps = direction ? Math.Abs(_profileProperties.BacklashCompensation) : 0; var steps = Math.Abs(position) + backlashCompensationSteps; @@ -322,7 +322,7 @@ namespace ASCOM.Meade.net private void DynamicBreaking(bool directionOut) { - if (!_UseDynamicBreaking) + if (!_profileProperties.DynamicBreaking) return; Tl.LogMessage("Move", "Applying dynamic breaking"); diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index a9bfca7..b7b2963 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -1,7 +1,6 @@ using System; using System.Reflection; using System.Runtime.InteropServices; -using ASCOM.Meade.net.AstroMaths; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities; @@ -20,21 +19,8 @@ namespace ASCOM.Meade.net /// protected static readonly string DriverDescription = "Meade Generic"; - protected static string _ComPort; // Variables to hold the currrent device configuration - protected static int _BacklashCompensation; - protected static bool _ReverseFocusDirection; - protected static bool _UseDynamicBreaking; - protected double _GuideRate; - protected string _Precision; - protected string _GuidingStyle; - protected double _SiteElevation; - protected short _ProfileSettleTime; - protected bool _SendDateTime; - protected ParkedBehaviour _ParkedBehaviour; - protected HorizonCoordinates _ParkedAltAz; - protected double _focalLength; - protected readonly ISharedResourcesWrapper SharedResourcesWrapper; + protected ProfileProperties _profileProperties; public MeadeTelescopeBase() { @@ -63,43 +49,25 @@ namespace ASCOM.Meade.net /// protected void ReadProfile() { - var profileProperties = SharedResourcesWrapper.ReadProfile(); - Tl.Enabled = profileProperties.TraceLogger; - _ComPort = profileProperties.ComPort; - _BacklashCompensation = profileProperties.BacklashCompensation; - _ReverseFocusDirection = profileProperties.ReverseFocusDirection; - _UseDynamicBreaking = profileProperties.DynamicBreaking; - _GuideRate = profileProperties.GuideRateArcSecondsPerSecond; - _Precision = profileProperties.Precision; - _GuidingStyle = profileProperties.GuidingStyle.ToLower(); - _SiteElevation = profileProperties.SiteElevation; - _ProfileSettleTime = profileProperties.SettleTime; - _SendDateTime = profileProperties.SendDateTime; - _ParkedBehaviour = profileProperties.ParkedBehaviour; - - _ParkedAltAz = new HorizonCoordinates - { - Altitude = profileProperties.ParkedAlt, - Azimuth = profileProperties.ParkedAz - }; - - _focalLength = profileProperties.FocalLength; + _profileProperties = SharedResourcesWrapper.ReadProfile(); + Tl.Enabled = _profileProperties.TraceLogger; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); - LogMessage("ReadProfile", $"Com Port: {_ComPort}"); - LogMessage("ReadProfile", $"Backlash Steps: {_BacklashCompensation}"); - LogMessage("ReadProfile", $"Dynamic breaking: {_UseDynamicBreaking}"); - LogMessage("ReadProfile", $"Guide Rate: {_GuideRate}"); - LogMessage("ReadProfile", $"Precision: {_Precision}"); - LogMessage("ReadProfile", $"Guiding Style: {_GuidingStyle}"); - LogMessage("ReadProfile", $"Site Elevation: {_SiteElevation}"); - LogMessage("ReadProfile", $"Settle Time after slew: {_ProfileSettleTime}"); - LogMessage("ReadProfile", $"Send date and time on connect: {_SendDateTime}"); - LogMessage("ReadProfile", $"Parked Behaviour: {_ParkedBehaviour}"); - LogMessage("ReadProfile", $"Parked Alt: {_ParkedAltAz.Altitude}"); - LogMessage("ReadProfile", $"Parked Az: {_ParkedAltAz.Azimuth}"); - LogMessage("ReadProfile", $"Focal Length: {_focalLength}"); - + LogMessage("ReadProfile", $"Com Port: {_profileProperties.ComPort}"); + LogMessage("ReadProfile", $"Backlash Steps: {_profileProperties.BacklashCompensation}"); + LogMessage("ReadProfile", $"Dynamic breaking: {_profileProperties.DynamicBreaking}"); + LogMessage("ReadProfile", $"Guide Rate: {_profileProperties.GuideRateArcSecondsPerSecond}"); + LogMessage("ReadProfile", $"Precision: {_profileProperties.Precision}"); + LogMessage("ReadProfile", $"Guiding Style: {_profileProperties.GuidingStyle}"); + LogMessage("ReadProfile", $"Site Elevation: {_profileProperties.SiteElevation}"); + LogMessage("ReadProfile", $"Settle Time after slew: {_profileProperties.SettleTime}"); + LogMessage("ReadProfile", $"Send date and time on connect: {_profileProperties.SendDateTime}"); + LogMessage("ReadProfile", $"Parked Behaviour: {_profileProperties.ParkedBehaviour}"); + LogMessage("ReadProfile", $"Parked Alt: {_profileProperties.ParkedAlt}"); + LogMessage("ReadProfile", $"Parked Az: {_profileProperties.ParkedAz}"); + LogMessage("ReadProfile", $"Focal Length: {_profileProperties.FocalLength}"); + LogMessage("ReadProfile", $"Aperture Area: {_profileProperties.ApertureArea}"); + LogMessage("ReadProfile", $"Aperture Area: {_profileProperties.ApertureDiameter}"); } /// @@ -164,7 +132,7 @@ namespace ASCOM.Meade.net protected void UpdateSiteElevation() { var profileProperties = SharedResourcesWrapper.ReadProfile(); - profileProperties.SiteElevation = _SiteElevation; + profileProperties.SiteElevation = _profileProperties.SiteElevation; SharedResourcesWrapper.WriteProfile(profileProperties); } } diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 0e75d6b..6a3833d 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -24,5 +24,7 @@ namespace ASCOM.Meade.net public double ParkedAlt { get; set; } public double ParkedAz { get; set; } public double FocalLength { get; set; } + public double ApertureArea { get; set; } + public double ApertureDiameter { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index fd661a4..2529e32 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -197,6 +197,24 @@ namespace ASCOM.Meade.net txtFocalLength.Text = "2000"; } + try + { + txtApertureArea.Text = profileProperties.ApertureArea.ToString(CultureInfo.CurrentCulture); + } + catch (Exception) + { + txtApertureArea.Text = "32685"; + } + + try + { + txtApertureDiameter.Text = profileProperties.ApertureDiameter.ToString(CultureInfo.CurrentCulture); + } + catch (Exception) + { + txtApertureDiameter.Text = "203"; + } + UpdateParkedItemsEnabled(); } @@ -224,7 +242,9 @@ namespace ASCOM.Meade.net ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription(cboParkedBehaviour.SelectedItem.ToString()), ParkedAlt = double.Parse(txtParkedAlt.Text), ParkedAz = double.Parse(txtParkedAz.Text), - FocalLength = double.Parse(txtFocalLength.Text) + FocalLength = double.Parse(txtFocalLength.Text), + ApertureArea = double.Parse(txtApertureArea.Text), + ApertureDiameter = double.Parse(txtApertureDiameter.Text) }; return profileProperties; diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index f710e6a..7d0266b 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -85,6 +85,12 @@ namespace ASCOM.Meade.net this.label25 = new System.Windows.Forms.Label(); this.txtFocalLength = new System.Windows.Forms.TextBox(); this.label26 = new System.Windows.Forms.Label(); + this.label27 = new System.Windows.Forms.Label(); + this.txtApertureDiameter = new System.Windows.Forms.TextBox(); + this.label28 = new System.Windows.Forms.Label(); + this.label29 = new System.Windows.Forms.Label(); + this.txtApertureArea = new System.Windows.Forms.TextBox(); + this.label30 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numDatabits)).BeginInit(); @@ -408,10 +414,46 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label26, "label26"); this.label26.Name = "label26"; // + // label27 + // + resources.ApplyResources(this.label27, "label27"); + this.label27.Name = "label27"; + // + // txtApetureDiameter + // + resources.ApplyResources(this.txtApertureDiameter, "txtApertureDiameter"); + this.txtApertureDiameter.Name = "txtApertureDiameter"; + // + // label28 + // + resources.ApplyResources(this.label28, "label28"); + this.label28.Name = "label28"; + // + // label29 + // + resources.ApplyResources(this.label29, "label29"); + this.label29.Name = "label29"; + // + // txtApetureArea + // + resources.ApplyResources(this.txtApertureArea, "txtApertureArea"); + this.txtApertureArea.Name = "txtApertureArea"; + // + // label30 + // + resources.ApplyResources(this.label30, "label30"); + this.label30.Name = "label30"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label29); + this.Controls.Add(this.txtApertureArea); + this.Controls.Add(this.label30); + this.Controls.Add(this.label27); + this.Controls.Add(this.txtApertureDiameter); + this.Controls.Add(this.label28); this.Controls.Add(this.label26); this.Controls.Add(this.txtFocalLength); this.Controls.Add(this.label25); @@ -532,5 +574,11 @@ namespace ASCOM.Meade.net private Label label25; private TextBox txtFocalLength; private Label label26; + private Label label27; + private TextBox txtApertureDiameter; + private Label label28; + private Label label29; + private TextBox txtApertureArea; + private Label label30; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 706338b..56169b2 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 50 + 56 Bottom, Right @@ -172,7 +172,7 @@ $this - 49 + 55 12, 9 @@ -196,7 +196,7 @@ $this - 48 + 54 Top, Right @@ -223,7 +223,7 @@ $this - 47 + 53 True @@ -250,13 +250,13 @@ $this - 46 + 52 True - 97, 305 + 97, 380 90, 17 @@ -277,7 +277,7 @@ $this - 45 + 51 97, 87 @@ -298,13 +298,13 @@ $this - 44 + 50 True - 290, 187 + 290, 262 61, 13 @@ -325,13 +325,10 @@ $this - 43 + 49 - - 17, 17 - - 375, 184 + 388, 259 46, 20 @@ -342,6 +339,9 @@ 10.0 + + 17, 17 + LX-200GPS only @@ -355,13 +355,13 @@ $this - 42 + 48 True - 427, 187 + 440, 262 122, 13 @@ -382,13 +382,13 @@ $this - 41 + 47 True - 427, 200 + 440, 275 105, 13 @@ -409,13 +409,13 @@ $this - 40 + 46 True - 290, 219 + 290, 294 50, 13 @@ -436,7 +436,7 @@ $this - 39 + 45 Unchanged @@ -448,7 +448,7 @@ High - 375, 216 + 388, 291 90, 21 @@ -466,7 +466,7 @@ $this - 38 + 44 True @@ -475,7 +475,7 @@ NoControl - 290, 246 + 290, 321 67, 13 @@ -496,7 +496,7 @@ $this - 37 + 43 Auto @@ -508,7 +508,7 @@ Pulse guiding - 375, 243 + 388, 318 90, 21 @@ -526,7 +526,7 @@ $this - 36 + 42 True @@ -556,7 +556,7 @@ $this - 35 + 41 True @@ -568,7 +568,7 @@ NoControl - 290, 284 + 290, 359 52, 13 @@ -589,10 +589,10 @@ $this - 34 + 40 - 375, 302 + 388, 377 46, 20 @@ -613,7 +613,7 @@ $this - 32 + 38 True @@ -622,7 +622,7 @@ NoControl - 290, 305 + 290, 380 79, 13 @@ -643,7 +643,7 @@ $this - 33 + 39 True @@ -652,7 +652,7 @@ NoControl - 427, 305 + 440, 380 20, 13 @@ -673,7 +673,7 @@ $this - 31 + 37 True @@ -706,13 +706,13 @@ $this - 30 + 36 True - 375, 328 + 388, 403 109, 17 @@ -733,13 +733,13 @@ $this - 29 + 35 True - 375, 351 + 388, 426 112, 17 @@ -760,7 +760,7 @@ $this - 28 + 34 True @@ -793,11 +793,8 @@ $this - 27 + 33 - - 17, 17 - True @@ -829,13 +826,13 @@ $this - 9 + 15 True - 290, 114 + 290, 189 72, 13 @@ -856,10 +853,10 @@ $this - 26 + 32 - 375, 111 + 388, 186 100, 20 @@ -877,13 +874,13 @@ $this - 25 + 31 True - 481, 114 + 494, 189 38, 13 @@ -904,13 +901,13 @@ $this - 24 + 30 True - 290, 145 + 290, 220 56, 13 @@ -931,10 +928,10 @@ $this - 23 + 29 - 375, 143 + 388, 218 120, 20 @@ -952,13 +949,13 @@ $this - 22 + 28 True - 501, 145 + 514, 220 47, 13 @@ -979,7 +976,7 @@ $this - 21 + 27 True @@ -1006,7 +1003,7 @@ $this - 20 + 26 97, 163 @@ -1027,7 +1024,7 @@ $this - 19 + 25 97, 137 @@ -1048,7 +1045,7 @@ $this - 18 + 24 97, 190 @@ -1069,7 +1066,7 @@ $this - 17 + 23 97, 217 @@ -1090,7 +1087,7 @@ $this - 16 + 22 97, 244 @@ -1111,7 +1108,7 @@ $this - 15 + 21 True @@ -1138,7 +1135,7 @@ $this - 14 + 20 True @@ -1165,7 +1162,7 @@ $this - 13 + 19 True @@ -1192,7 +1189,7 @@ $this - 12 + 18 True @@ -1219,7 +1216,7 @@ $this - 11 + 17 True @@ -1231,7 +1228,7 @@ NoControl - 15, 284 + 15, 359 73, 13 @@ -1252,7 +1249,7 @@ $this - 10 + 16 No Coordinates @@ -1282,7 +1279,7 @@ $this - 8 + 14 True @@ -1309,7 +1306,7 @@ $this - 7 + 13 True @@ -1336,7 +1333,7 @@ $this - 6 + 12 True @@ -1363,7 +1360,7 @@ $this - 5 + 11 697, 151 @@ -1384,7 +1381,7 @@ $this - 4 + 10 697, 177 @@ -1405,7 +1402,7 @@ $this - 3 + 9 True @@ -1435,10 +1432,10 @@ $this - 2 + 8 - 375, 87 + 388, 87 100, 20 @@ -1456,7 +1453,7 @@ $this - 1 + 7 True @@ -1465,7 +1462,7 @@ NoControl - 481, 90 + 494, 90 23, 13 @@ -1486,8 +1483,170 @@ $this + 6 + + + True + + + NoControl + + + 494, 114 + + + 23, 13 + + + 53 + + + mm + + + label27 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + 388, 111 + + + 100, 20 + + + 52 + + + txtApertureDiameter + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + + + True + + + NoControl + + + 290, 114 + + + 92, 13 + + + 51 + + + Aperture Diameter + + + label28 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 5 + + + True + + + NoControl + + + 494, 139 + + + 23, 13 + + + 56 + + + mm + + + label29 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 + + 388, 136 + + + 100, 20 + + + 55 + + + txtApertureArea + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + NoControl + + + 290, 139 + + + 72, 13 + + + 54 + + + Aperture Area + + + label30 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + True diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index f813870..4ad7cf6 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -199,6 +199,8 @@ namespace ASCOM.Meade.net private const string ParkedAltName = "Parked Altitude"; private const string ParkedAzimuthName = "Parked Azimuth"; private const string FocalLengthName = "Focal Length (mm)"; + private const string ApertureAreaName = "Aperture Area (mm²)"; + private const string ApertureDiameterName = "Aperture Diameter (mm)"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -228,6 +230,8 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, ParkedAltName, profileProperties.ParkedAlt.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, ParkedAzimuthName, profileProperties.ParkedAz.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, FocalLengthName, profileProperties.FocalLength.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, ApertureAreaName, profileProperties.ApertureArea.ToString(CultureInfo.InvariantCulture)); + driverProfile.WriteValue(DriverId, ApertureDiameterName, profileProperties.ApertureDiameter.ToString(CultureInfo.InvariantCulture)); } } } @@ -253,6 +257,8 @@ namespace ASCOM.Meade.net private const string ParkedAltDefault = "0"; private const string ParkedAzimuthDefault = "180"; private const string FocalLengthDefault = "2000"; + private const string ApertureAreaDefault = "32685"; + private const string ApertureDiameterDefault = "203"; public static ProfileProperties ReadProfile() { @@ -284,6 +290,8 @@ namespace ASCOM.Meade.net profileProperties.ParkedAlt = double.Parse(driverProfile.GetValue(DriverId, ParkedAltName, string.Empty, ParkedAltDefault), NumberFormatInfo.InvariantInfo); profileProperties.ParkedAz = double.Parse(driverProfile.GetValue(DriverId, ParkedAzimuthName, string.Empty, ParkedAzimuthDefault), NumberFormatInfo.InvariantInfo); profileProperties.FocalLength = double.Parse(driverProfile.GetValue(DriverId, FocalLengthName, string.Empty, FocalLengthDefault), NumberFormatInfo.InvariantInfo); + profileProperties.ApertureArea = double.Parse(driverProfile.GetValue(DriverId, ApertureAreaName, string.Empty, ApertureAreaDefault), NumberFormatInfo.InvariantInfo); + profileProperties.ApertureDiameter = double.Parse(driverProfile.GetValue(DriverId, ApertureDiameterName, string.Empty, ApertureDiameterDefault), NumberFormatInfo.InvariantInfo); } return profileProperties; From ed54487a8841a94c06b34b5fcb68f3b34e0673f9 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 5 May 2022 18:55:38 +0100 Subject: [PATCH 10/47] New Park routine for the LX-200 Classic, uses the same technique as the 5.0.4 driver. --- Meade.net.Telescope/Telescope.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index af929af..05dde95 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1398,7 +1398,6 @@ namespace ASCOM.Meade.net { CheckConnected("CanUnpark"); - //todo make this return false for non LX-200 GPS telescopes LogMessage("CanUnpark", "Get - " + true); return SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS; } @@ -1740,11 +1739,20 @@ namespace ASCOM.Meade.net break; } + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + { + SharedResourcesWrapper.SendBlind("hP"); + //:hP# Autostar, Autostar II and LX 16" Slew to Park Position + //Returns: Nothing + } + else + { + Tracking = false; + SlewToCoordinates(parkedPosition.RightAscension, parkedPosition.Declination); + } + //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. SharedResourcesWrapper.SetParked(true, parkedPosition); - SharedResourcesWrapper.SendBlind("hP"); - //:hP# Autostar, Autostar II and LX 16" Slew to Park Position - //Returns: Nothing } private bool _userNewerPulseGuiding = true; From 503eec38a3ad8384b83f366d9b86c575398a7a3f Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 5 May 2022 20:40:51 +0100 Subject: [PATCH 11/47] Added check to ensure that telescope is in Polar Mode when attempting to PulseGuide. CanPulseGuide also fails when scope is in AltAz mode. --- .../TelescopeUnitTests.cs | 40 +++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 9 ++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 72761b7..86918d3 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -18,6 +18,7 @@ namespace Meade.net.Telescope.UnitTests { public class TestProperties { + public string AlignmentMode { get; internal set; } = "P"; internal string telescopeRaResult { get; set; } = "HH:MM:SS"; internal double rightAscension { get; set; } = 1.2; //todo rename to declination; internal double declination { get; set; } = 45; @@ -155,6 +156,9 @@ namespace Meade.net.Telescope.UnitTests _parkedPosition = parkedPostion; }); + const char ack = (char)6; + _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns( () => _testProperties.AlignmentMode); + _sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked); _sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition); @@ -793,9 +797,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase("G", AlignmentModes.algGermanPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)] public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode, string productName, string firmware) { - const char ack = (char)6; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns(telescopeMode); - + _testProperties.AlignmentMode = telescopeMode; ConnectTelescope(productName, firmware, $"{telescopeMode}N0"); var actualResult = _telescope.AlignmentMode; @@ -806,6 +808,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void AlignmentMode_Get_WhenUnknownAlignmentMode_ThrowsException() { + _testProperties.AlignmentMode = ""; ConnectTelescope(); Assert.Throws(() => @@ -929,13 +932,25 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void CanPulseGuide_Get_ReturnsTrue() + public void CanPulseGuide_GetInPolarMode_ReturnsTrue() { + _testProperties.AlignmentMode = "P"; + ConnectTelescope(); var result = _telescope.CanPulseGuide; Assert.That(result, Is.True); } + [Test] + public void CanPulseGuide_GetInAltAzMode_ReturnsFalse() + { + _testProperties.AlignmentMode = "A"; + ConnectTelescope(); + var result = _telescope.CanPulseGuide; + + Assert.That(result, Is.False); + } + [Test] public void CanSetDeclinationRate_Get_ReturnsFalse() { @@ -1696,6 +1711,23 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst slewing to target.")); } + [TestCase(GuideDirections.guideEast)] + [TestCase(GuideDirections.guideWest)] + [TestCase(GuideDirections.guideNorth)] + [TestCase(GuideDirections.guideSouth)] + public void PulseGuide_WhenAltAzPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) + { + _testProperties.AlignmentMode = "A"; + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(""); + + var duration = 1; + ConnectTelescope(); + + var exception = Assert.Throws(() => _telescope.PulseGuide(direction, duration)); + + Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst in AltAz mode.")); + } + [TestCase(GuideDirections.guideEast, TelescopeAxes.axisPrimary)] [TestCase(GuideDirections.guideWest, TelescopeAxes.axisPrimary)] [TestCase(GuideDirections.guideNorth, TelescopeAxes.axisSecondary)] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index af929af..b16920a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1274,8 +1274,10 @@ namespace ASCOM.Meade.net { get { - LogMessage("CanPulseGuide", "Get - " + true); - return true; + CheckConnected("CanPulseGuide"); + var canPulseGuide = AlignmentMode != AlignmentModes.algAltAz; + LogMessage("CanPulseGuide", $"Get - {canPulseGuide}"); + return canPulseGuide; } } @@ -1759,6 +1761,9 @@ namespace ASCOM.Meade.net if (IsSlewingToTarget()) throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target."); + if (AlignmentMode == AlignmentModes.algAltAz) + throw new InvalidOperationException("Unable to PulseGuide whilst in AltAz mode."); + SharedResourcesWrapper.IsGuiding = true; try { From a68e86d8cd327287d835b46568d2043d3208f177 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 5 May 2022 20:56:18 +0100 Subject: [PATCH 12/47] Added unit tests for long duration pulse guides. --- .../TelescopeUnitTests.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 86918d3..f6fe1d2 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1663,13 +1663,16 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: PulseGuide")); } - [TestCase(GuideDirections.guideEast)] - [TestCase(GuideDirections.guideWest)] - [TestCase(GuideDirections.guideNorth)] - [TestCase(GuideDirections.guideSouth)] - public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailable_ThenSendsNewCommandsAndWaits(GuideDirections direction) + [TestCase(GuideDirections.guideEast, 0)] + [TestCase(GuideDirections.guideWest, 0)] + [TestCase(GuideDirections.guideNorth, 0)] + [TestCase(GuideDirections.guideSouth, 0)] + [TestCase(GuideDirections.guideEast, 22161)] + [TestCase(GuideDirections.guideWest, 22161)] + [TestCase(GuideDirections.guideNorth, 22161)] + [TestCase(GuideDirections.guideSouth, 22161)] + public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailable_ThenSendsNewCommandsAndWaits(GuideDirections direction, int duration) { - var duration = 0; ConnectTelescope(); _telescope.PulseGuide(direction, duration); From 57c5a34fe21a66a23b6b6de80ad66794691950ef Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Thu, 5 May 2022 18:55:38 +0100 Subject: [PATCH 13/47] New Park routine for the LX-200 Classic, uses the same technique as the 5.0.4 driver. --- Meade.net.Telescope/Telescope.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b16920a..f36c6b2 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1400,7 +1400,6 @@ namespace ASCOM.Meade.net { CheckConnected("CanUnpark"); - //todo make this return false for non LX-200 GPS telescopes LogMessage("CanUnpark", "Get - " + true); return SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS; } @@ -1742,11 +1741,20 @@ namespace ASCOM.Meade.net break; } + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + { + SharedResourcesWrapper.SendBlind("hP"); + //:hP# Autostar, Autostar II and LX 16" Slew to Park Position + //Returns: Nothing + } + else + { + Tracking = false; + SlewToCoordinates(parkedPosition.RightAscension, parkedPosition.Declination); + } + //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. SharedResourcesWrapper.SetParked(true, parkedPosition); - SharedResourcesWrapper.SendBlind("hP"); - //:hP# Autostar, Autostar II and LX 16" Slew to Park Position - //Returns: Nothing } private bool _userNewerPulseGuiding = true; From a9b8a60e43f22ed46d7166c23bb1578400da97ac Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 12:14:24 +0100 Subject: [PATCH 14/47] Changes LX200 Park to use Alt 0 Az 0. i.e. Pointing level and North --- Meade.net.Telescope/Telescope.cs | 100 +++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index f36c6b2..72f5955 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1750,7 +1750,8 @@ namespace ASCOM.Meade.net else { Tracking = false; - SlewToCoordinates(parkedPosition.RightAscension, parkedPosition.Declination); + var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; + SlewToAltAz(0, parkAlt, false); } //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. @@ -2161,12 +2162,17 @@ namespace ASCOM.Meade.net } public void SlewToAltAz(double azimuth, double altitude) + { + SlewToAltAz(azimuth, altitude, true); + } + + public void SlewToAltAz(double azimuth, double altitude, bool polar) { LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); CheckConnected("SlewToAltAz"); CheckParked(); - SlewToAltAzAsync(azimuth, altitude); + SlewToAltAzAsync(azimuth, altitude, polar); while (Slewing) //wait for slew to complete { @@ -2175,6 +2181,11 @@ namespace ASCOM.Meade.net } public void SlewToAltAzAsync(double azimuth, double altitude) + { + SlewToAltAzAsync(azimuth, altitude, true); + } + + public void SlewToAltAzAsync(double azimuth, double altitude, bool polar) { CheckConnected("SlewToAltAzAsync"); CheckParked(); @@ -2193,18 +2204,87 @@ namespace ASCOM.Meade.net LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}"); - HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude }; + if (polar) + { + HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude }; - var utcDateTime = UTCDate; - var latitude = SiteLatitude; - var longitude = SiteLongitude; + var utcDateTime = UTCDate; + var latitude = SiteLatitude; + var longitude = SiteLongitude; + var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); - var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); + TargetRightAscension = raDec.RightAscension; + TargetDeclination = raDec.Declination; + } + else + { + TargetAltitude = altitude; + TargetAzimuth = azimuth; + } - TargetRightAscension = raDec.RightAscension; - TargetDeclination = raDec.Declination; + DoSlewAsync(polar); + } - DoSlewAsync(true); + private double TargetAltitude + { + set + { + CheckConnected("TargetAltitude"); + CheckParked(); + + if (value < -90) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be below -90."); + + if (value > 90) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be above 90."); + + var dms = SharedResourcesWrapper.IsLongFormat ? + _utilities.DegreesToDMS(value, "*", "'", "", _digitsDe) : + _utilities.DegreesToDM(value, "*", "", _digitsDe); + + var s = value < 0 ? "-" : "+"; + + var command = $"Sa{s}{dms}"; + + LogMessage("TargetAltitude Set", $"{command}"); + var response = SharedResourcesWrapper.SendBool(command); + //:SasDD*MM# + // Set target object altitude to sDD*MM# or sDD*MM’SS# [LX 16”, Autostar, Autostar II] + // Returns: + // 1 Object within slew range + // 0 Object out of slew range + if (!response) + throw new InvalidOperationException("Target Altitude out of slew range."); + } + } + + private double TargetAzimuth + { + set + { + CheckConnected("TargetAzimuth"); + CheckParked(); + + if (value < 0) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be below 0."); + + if (value >= 360) + throw new ArgumentOutOfRangeException($"Target Altitude cannot be above 360."); + + var dms = _utilities.DegreesToDM(value, "*", "", _digitsDe); + + var command = $"Sz{dms}"; + + LogMessage("TargetAzimuth Set", $"{command}"); + var response = SharedResourcesWrapper.SendBool(command); + //:SzDDD*MM# + // Sets the target Object Azimuth[LX 16” and Autostar II only] + // Returns: + // 0 – Invalid + // 1 - Valid + if (!response) + throw new InvalidOperationException("Target Azimuth out of slew range."); + } } private void DoSlewAsync(bool polar) From ceca3a15dce6f48a115e83b2c1d79d833cf4e389 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 13:39:34 +0100 Subject: [PATCH 15/47] Added work around for LX200 classed to be able to turn tracking off when parking. --- Meade.net.Telescope/Telescope.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 72f5955..8d40d9d 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1749,7 +1749,11 @@ namespace ASCOM.Meade.net } else { - Tracking = false; + if (CanSetTracking) + Tracking = false; + else + SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; SlewToAltAz(0, parkAlt, false); } From ef498fc5a053e2071f3f6a93a1ada99683b7b22d Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 20:09:40 +0100 Subject: [PATCH 16/47] Added some debugging messages --- Meade.net.Telescope/Telescope.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 8d40d9d..b3e5706 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1749,16 +1749,27 @@ namespace ASCOM.Meade.net } else { + LogMessage("Park", $"Parking LX200 Classic"); if (CanSetTracking) + { + LogMessage("Park", $"Parking LX200 Classic - Setting Tracking False"); Tracking = false; + } else + { + LogMessage("Park", $"Setting Telescope to land targets."); SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + } + var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; + LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); SlewToAltAz(0, parkAlt, false); + LogMessage("Park", $"Arrived at park position"); } //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. + LogMessage("Park", $"Setting driver to parked"); SharedResourcesWrapper.SetParked(true, parkedPosition); } @@ -1768,7 +1779,7 @@ namespace ASCOM.Meade.net { LogMessage("PulseGuide", $"pulse guide direction {direction} duration {duration}"); try - { + { CheckConnected("PulseGuide"); CheckParked(); if (IsSlewingToTarget()) From af3cca76116358764569dc3e2bcc0b62fa59340c Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 6 May 2022 21:31:12 +0100 Subject: [PATCH 17/47] Modified the deubgging information. --- Meade.net.Telescope/Telescope.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b3e5706..222a176 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1750,18 +1750,17 @@ namespace ASCOM.Meade.net else { LogMessage("Park", $"Parking LX200 Classic"); - if (CanSetTracking) + LogMessage("Park", $"Setting Telescope to land targets."); + try { - LogMessage("Park", $"Parking LX200 Classic - Setting Tracking False"); - Tracking = false; - } - else - { - LogMessage("Park", $"Setting Telescope to land targets."); SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. + } + catch (Exception ex) + { + LogMessage("Park", $"AL command failed: {ex.Message}"); } - var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); SlewToAltAz(0, parkAlt, false); From 0c70688b60e34321149df6b9e205f4d140ba57a2 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 10:00:57 +0100 Subject: [PATCH 18/47] Removed the AL command as I think it's failing --- Meade.net.Telescope/Telescope.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 222a176..61bdf78 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -177,7 +177,7 @@ namespace ASCOM.Meade.net { get { - LogMessage("SupportedActions Get", "Returning empty arraylist"); + LogMessage("SupportedActions Get", "Returning Actions Array"); var supportedActions = new ArrayList {"handbox", "site"}; return supportedActions; } @@ -1750,16 +1750,16 @@ namespace ASCOM.Meade.net else { LogMessage("Park", $"Parking LX200 Classic"); - LogMessage("Park", $"Setting Telescope to land targets."); - try - { - SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. - _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. - } - catch (Exception ex) - { - LogMessage("Park", $"AL command failed: {ex.Message}"); - } + //LogMessage("Park", $"Setting Telescope to land targets."); + //try + //{ + // SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. + // _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. + //} + //catch (Exception ex) + //{ + // LogMessage("Park", $"AL command failed: {ex.Message}"); + //} var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); From 5e65ea79462a9769c596c28d2c3f3c9682b3c566 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 12:15:45 +0100 Subject: [PATCH 19/47] Added a log message for when connected check fails. --- Meade.net.Telescope/Telescope.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 61bdf78..96a22e1 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -3066,7 +3066,9 @@ namespace ASCOM.Meade.net { if (!IsConnected) { - throw new NotConnectedException($"Not connected to telescope when trying to execute: {message}"); + var msg = $"Not connected to telescope when trying to execute: {message}"; + LogMessage("CheckConnected", msg); + throw new NotConnectedException(msg); } } From 350dd23ed1abacfcdecf34864ce42735277aef63 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 12:22:46 +0100 Subject: [PATCH 20/47] Added more error checks for connected, and found a couple of logic holds in the code that sets the IsConnected property. --- .../TelescopeUnitTests.cs | 18 +++++------------- Meade.net.Telescope/Telescope.cs | 2 ++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f6fe1d2..f668703 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -221,9 +221,7 @@ namespace Meade.net.Telescope.UnitTests { string expectedResult = "test result string"; _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _telescope.Connected = true; - - + ConnectTelescope(); var actualResult = _telescope.Action("handbox", "readdisplay"); @@ -830,21 +828,17 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, "AP")] public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); - _telescope.Connected = true; + ConnectTelescope(productName, firmware); _telescope.AlignmentMode = alignmentMode; _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once); } - [TestCase("AUTOSTAR", "43Ef")] + [TestCase(TelescopeList.Autostar497, "43Ef")] public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); - _telescope.Connected = true; + ConnectTelescope(productName, firmware); var excpetion = Assert.Throws(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); @@ -983,9 +977,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void CanSetGuideRates_Get_WhenConnectedToLX200GPS_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.LX200GPS_42G); - _telescope.Connected = true; + ConnectTelescope(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G); var result = _telescope.CanSetGuideRates; diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 96a22e1..ffeead3 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -508,12 +508,14 @@ namespace ASCOM.Meade.net } catch (Exception) { + IsConnected = false; SharedResourcesWrapper.Disconnect("Serial", DriverId); throw; } } catch (Exception ex) { + IsConnected = false; LogMessage("Connected Set", "Error connecting to port {0} - {1}", _profileProperties.ComPort, ex.Message); } } From 700802033b3f729ec6875ae147f5b2b869798a08 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 14:00:29 +0100 Subject: [PATCH 21/47] Added Alt Az coordinates to the connected message. --- .../TelescopeUnitTests.cs | 4 +- Meade.net.Telescope/Telescope.cs | 110 +++++++++++------- Meade.net/SharedResources.cs | 3 +- 3 files changed, 69 insertions(+), 48 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f668703..36ff739 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -477,7 +477,7 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } } @@ -488,7 +488,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(TelescopeList.LX200GPS, string.Empty); _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); } diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ffeead3..0095144 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -503,8 +503,9 @@ namespace ASCOM.Meade.net } var raAndDec = GetTelescopeRaAndDec(); + var altAndAz = GetTelescopeAltAz(); LogMessage("Connected Set", - $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); + $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)} Az={altAndAz.Azimuth} Alt={altAndAz.Altitude}"); } catch (Exception) { @@ -1102,28 +1103,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - try - { - CheckParked(); - - //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! - var result = SharedResourcesWrapper.SendString("GA"); - //:GA# Get Telescope Altitude - //Returns: sDD* MM# or sDD*MM'SS# - //The current scope altitude. The returned format depending on the current precision setting. - - var alt = _utilities.DMSToDegrees(result); - LogMessage("Altitude", $"{alt}"); - return alt; - } - catch (ParkedException) - { - var parkedPosition = SharedResourcesWrapper.ParkedPosition; - if (parkedPosition != null) - return parkedPosition.Altitude; - - throw; - } + return GetRealTelescopeAltitude(); } var altAz = CalcAltAzFromTelescopeEqData(); @@ -1132,6 +1112,32 @@ namespace ASCOM.Meade.net } } + private double GetRealTelescopeAltitude() + { + try + { + CheckParked(); + + //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! + var result = SharedResourcesWrapper.SendString("GA"); + //:GA# Get Telescope Altitude + //Returns: sDD* MM# or sDD*MM'SS# + //The current scope altitude. The returned format depending on the current precision setting. + + var alt = _utilities.DMSToDegrees(result); + LogMessage("Altitude", $"{alt}"); + return alt; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Altitude; + + throw; + } + } + private HorizonCoordinates CalcAltAzFromTelescopeEqData() { var altitudeData = new AltitudeData @@ -1159,6 +1165,15 @@ namespace ASCOM.Meade.net }; } + private HorizonCoordinates GetTelescopeAltAz() + { + return new HorizonCoordinates() + { + Altitude = GetRealTelescopeAltitude(), + Azimuth = GetRealTelescopeAzimuth() + }; + } + public double ApertureArea { get @@ -1212,28 +1227,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - try - { - CheckParked(); - - var result = SharedResourcesWrapper.SendString("GZ"); - //:GZ# Get telescope azimuth - //Returns: DDD*MM#T or DDD*MM'SS# - //The current telescope Azimuth depending on the selected precision. - - double az = _utilities.DMSToDegrees(result); - - LogMessage("Azimuth Get", $"{az}"); - return az; - } - catch (ParkedException) - { - var parkedPosition = SharedResourcesWrapper.ParkedPosition; - if (parkedPosition != null) - return parkedPosition.Azimuth; - - throw; - } + return GetRealTelescopeAzimuth(); } var altAz = CalcAltAzFromTelescopeEqData(); @@ -1242,6 +1236,32 @@ namespace ASCOM.Meade.net } } + private double GetRealTelescopeAzimuth() + { + try + { + CheckParked(); + + var result = SharedResourcesWrapper.SendString("GZ"); + //:GZ# Get telescope azimuth + //Returns: DDD*MM#T or DDD*MM'SS# + //The current telescope Azimuth depending on the selected precision. + + double az = _utilities.DMSToDegrees(result); + + LogMessage("Azimuth Get", $"{az}"); + return az; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Azimuth; + + throw; + } + } + public bool CanFindHome { get diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 4ad7cf6..aac7262 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -391,8 +391,9 @@ namespace ASCOM.Meade.net SharedSerial.Parity = (SerialParity)Enum.Parse(typeof(SerialParity), profileProperties.Parity); SharedSerial.Speed = (SerialSpeed)profileProperties.Speed; SharedSerial.Handshake = (SerialHandshake)Enum.Parse(typeof(SerialHandshake), profileProperties.Handshake); + SharedSerial.ReceiveTimeout = 5; //5 second timeout; SharedSerial.Connected = true; - + try { ProductName = SendString("GVP"); From a204f9c57f9e6bbb51bca3263e76991376017392 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 16:54:22 +0100 Subject: [PATCH 22/47] Added more logging to DoSlewAsync, Added a retry to the AltAz Slew. --- Meade.net.Telescope/Telescope.cs | 47 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 0095144..4cae501 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2204,7 +2204,7 @@ namespace ASCOM.Meade.net public void SlewToAltAz(double azimuth, double altitude, bool polar) { - LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); + LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude} polar={polar}"); CheckConnected("SlewToAltAz"); CheckParked(); @@ -2238,7 +2238,7 @@ namespace ASCOM.Meade.net if (azimuth < 0) throw new InvalidValueException("Azimuth cannot be less than 0."); - LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}"); + LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude} polar={polar}"); if (polar) { @@ -2325,6 +2325,7 @@ namespace ASCOM.Meade.net private void DoSlewAsync(bool polar) { + LogMessage("DoSlewAsync", "Beginning slew sequence"); CheckConnected("DoSlewAsync"); CheckParked(); if (Slewing) @@ -2336,6 +2337,7 @@ namespace ASCOM.Meade.net switch (polar) { case true: + LogMessage("DoSlewAsync", "Executing Polar slew"); var response = SharedResourcesWrapper.SendChar("MS"); //:MS# Slew to Target Object //Returns: @@ -2382,23 +2384,44 @@ namespace ASCOM.Meade.net break; case false: - var maResponse = SharedResourcesWrapper.SendChar("MA"); - //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az - //Returns: - //0 - No fault - //1 - Fault - //LX200 - Not supported - - if (maResponse == "1") + Retry(6, () => { - throw new InvalidOperationException("fault"); - } + LogMessage("DoSlewAsync", "Executing Alt Az"); + var maResponse = SharedResourcesWrapper.SendChar("MA"); + //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az + //Returns: + //0 - No fault + //1 - Fault + //LX200 - Not supported + + if (maResponse != "0") + { + throw new InvalidOperationException($"fault ({maResponse})"); + } + }); SetSlewingMinEndTime(); break; } } + private void Retry(int i, Action action) + { + while (i >= 0) + { + try + { + action(); + break; + } + catch (Exception e) + { + LogMessage("Retry", $"Attempt failed {i} attempts remaining error: {e.Message}"); + } + i--; + } + } + public void SlewToCoordinates(double rightAscension, double declination) { LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); From 8eb093c13ad950dc20d32ccf73ca1736f00d41b8 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 18:09:37 +0100 Subject: [PATCH 23/47] Upgraded the align mode command to have a retry and added support for land mode. --- Meade.net.Telescope/Telescope.cs | 43 +++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 4cae501..ac62ae2 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -979,10 +979,13 @@ namespace ASCOM.Meade.net if (IsGwCommandSupported()) { var alignmentStatus = GetScopeAlignmentStatus(); + LogMessage("AlignmentMode Get", $"alignmode = {alignmentStatus.AlignmentMode}"); return alignmentStatus.AlignmentMode; } - else + + return Retry(6, () => { + LogMessage("AlignmentMode Get", $"Sending Ack code."); const char ack = (char)6; //ACK <0x06> Query of alignment mounting mode. //Returns: @@ -995,22 +998,29 @@ namespace ASCOM.Meade.net switch (alignmentString) { case "A": + LogMessage("AlignmentMode Get", $"Telescope is in AltAz"); alignmentMode = AlignmentModes.algAltAz; break; case "P": + LogMessage("AlignmentMode Get", $"Telescope is in Polar"); alignmentMode = AlignmentModes.algPolar; break; + case "L": + LogMessage("AlignmentMode Get", $"Telescope is in Land mode"); + alignmentMode = AlignmentModes.algAltAz; + break; //case "G": - //alignmentMode = AlignmentModes.algGermanPolar; - //break; + //alignmentMode = AlignmentModes.algGermanPolar; + //break; default: - throw new InvalidValueException( - $"unknown alignment returned from telescope: {alignmentString}"); + var msg = $"unknown alignment returned from telescope: {alignmentString}"; + LogMessage("AlignmentMode Get", msg); + throw new InvalidValueException(msg); } LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}"); return alignmentMode; - } + }); } set { @@ -2422,6 +2432,27 @@ namespace ASCOM.Meade.net } } + private T Retry(int i, Func func) + { + while (true) + { + try + { + return func(); + } + catch (Exception e) + { + LogMessage("Retry", $"Attempt failed {i} attempts remaining error: {e.Message}"); + if (i > 0) + { + i--; + } + else + throw; + } + } + } + public void SlewToCoordinates(double rightAscension, double declination) { LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); From 64e42f961c306c0e30552b30956514511260f554 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 7 May 2022 19:37:16 +0100 Subject: [PATCH 24/47] Maybe this is what's missing to get the telescope to park --- .../TelescopeUnitTests.cs | 16 +++++++------- Meade.net.Telescope/Telescope.cs | 21 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 36ff739..12eaea1 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2715,15 +2715,15 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.Tracking, Is.True); } - [TestCase(true)] - [TestCase(false)] - public void Tracking_Set_WhenCanSetTrackingIsFalse_ThenThrowsNotImplementedException(bool tracking) - { - // GW is not supported, so CanSetTracking is false - ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_30Ee); + //[TestCase(true)] + //[TestCase(false)] + //public void Tracking_Set_WhenCanSetTrackingIsFalse_ThenThrowsNotImplementedException(bool tracking) + //{ + // // GW is not supported, so CanSetTracking is false + // ConnectTelescope(firmwareVersion: TelescopeList.Autostar497_30Ee); - Assert.Throws( () => { _telescope.Tracking = tracking; } ); - } + // Assert.Throws( () => { _telescope.Tracking = tracking; } ); + //} [TestCase(true, "AP")] [TestCase(false, "AL")] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ac62ae2..55d1b0a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1782,17 +1782,10 @@ namespace ASCOM.Meade.net else { LogMessage("Park", $"Parking LX200 Classic"); - //LogMessage("Park", $"Setting Telescope to land targets."); - //try - //{ - // SharedResourcesWrapper.SendBlind("AL"); //todo need to route this to the real commands. - // _utilities.WaitForMilliseconds(1000); //Need to wait 1 second according to old driver. - //} - //catch (Exception ex) - //{ - // LogMessage("Park", $"AL command failed: {ex.Message}"); - //} + + Tracking = false; + LogMessage("Park", $"Calculating Park Altitude"); var parkAlt = AlignmentMode == AlignmentModes.algAltAz ? 0 : 90 - SiteLatitude; LogMessage("Park", $"Slewing to park position az:0 alt:{parkAlt}"); SlewToAltAz(0, parkAlt, false); @@ -2812,10 +2805,10 @@ namespace ASCOM.Meade.net } set { - if (!CanSetTracking) - { - throw new ASCOM.NotImplementedException("Tracking Set"); - } + //if (!CanSetTracking) + //{ + // throw new ASCOM.NotImplementedException("Tracking Set"); + //} LogMessage("Tracking Set", $"{value}"); SharedResourcesWrapper.SendBlind(value ? "AP" : "AL"); //todo need to route this to the real commands. From 35a76fe52cc2a53203b6a5c4abb006c7a3c2c55f Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sun, 8 May 2022 11:52:45 +0000 Subject: [PATCH 25/47] Merged in feature/PortSpeed (pull request #40) Feature/PortSpeed * Added support for changing the speed of the autostar * Added support for changing the speed of the autostar * Merge remote-tracking branch 'origin/feature/PortSpeed' into feature/PortSpeed * Upgraded unit testing to make sure that speed changes are properly tested --- .../Meade.net.Telescope.csproj | 4 + .../SharedResourcesUnitTests.cs | 343 ++++++++++++++++++ Meade.net/SetupDialogForm.cs | 25 +- Meade.net/SharedResources.cs | 83 ++++- 4 files changed, 449 insertions(+), 6 deletions(-) diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index f51673b..e37c209 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -194,6 +194,10 @@ + + + +