From 683a58286828615dfcb1669ac21682d969ad0478 Mon Sep 17 00:00:00 2001 From: Rick Burke Date: Sat, 25 Jun 2022 07:44:18 -0700 Subject: [PATCH] Simplify Dome Manager command logic. Ensure that short slews are handled correctly so that the client can get the downstream driver's Slewing state immediately after the command is issued. --- DeviceHub/DeviceManagers/DomeManager.cs | 218 ++++-------------------- Inno Setup/ASCOM Device Hub Setup.iss | 2 +- ProductAssemblyInfo.cs | 2 +- 3 files changed, 32 insertions(+), 190 deletions(-) diff --git a/DeviceHub/DeviceManagers/DomeManager.cs b/DeviceHub/DeviceManagers/DomeManager.cs index d246ffc..0d1a4e0 100644 --- a/DeviceHub/DeviceManagers/DomeManager.cs +++ b/DeviceHub/DeviceManagers/DomeManager.cs @@ -304,10 +304,10 @@ public void OpenDomeShutter() if ( Connected && Capabilities != null && Status != null && Capabilities.CanSetShutter && Status.ShutterStatus != ShutterState.shutterOpen ) { - // Issue the open shutter command and wait for a status update before continuing. + OpenShutter(); + Status = new DevHubDomeStatus( this ); - var task = OpenShutterAsync(); - var result = task.Result; + SetFastPolling(); } } @@ -318,10 +318,10 @@ public void CloseDomeShutter() if ( Connected && Capabilities != null && Status != null && Capabilities.CanSetShutter && Status.ShutterStatus != ShutterState.shutterClosed ) { - // Issue the close shutter command and wait for a status update before returning. + CloseShutter(); + Status = new DevHubDomeStatus( this ); - var task = CloseShutterAsync(); - var result = task.Result; + SetFastPolling(); } } @@ -331,10 +331,10 @@ public void ParkTheDome() { ParkingState = ParkingStateEnum.ParkInProgress; - // Issue the park command and wait for a status update before returning; + Park(); + Status = new DevHubDomeStatus( this ); - var task = ParkDomeAsync(); - var result = task.Result; + SetFastPolling(); } } @@ -342,8 +342,10 @@ public void FindHomePosition() { if ( Connected && Capabilities != null && Capabilities.CanFindHome && !Slewing ) { - var task = FindHomeAsync(); - var result = task.Result; + FindHome(); + Status = new DevHubDomeStatus( this ); + + SetFastPolling(); } } @@ -354,17 +356,10 @@ public void SlewDomeShutter( double targetAltitude ) if ( Connected && !Slewing && Capabilities.CanSetAltitude && ( status != ShutterState.shutterClosed && status != ShutterState.shutterError ) ) { - Task task; + SlewToAltitude( targetAltitude ); + Status = new DevHubDomeStatus( this ); - try - { - task = SlewShutterAsync( targetAltitude ); - task.Wait(); - } - catch ( AggregateException xcp ) - { - throw xcp.InnerException; - } + SetFastPolling(); } } @@ -378,21 +373,14 @@ public void SetSlavedState( bool state ) public void SlewDomeToAzimuth( double targetAzimuth ) { - if ( Connected && !Slewing && Capabilities.CanSetAzimuth ) + if ( Connected && !Status.Slewing && Capabilities.CanSetAzimuth ) { - // We don't actually need the result, but it allows us to wait for the async slew to start - // and for a status update to occur. + SlewToAzimuth( targetAzimuth ); + Status = new DevHubDomeStatus( this ); - try - { - var task = SlewDomeAsync( targetAzimuth ); - var result = task.Result; - } - catch (AggregateException xcp ) - { - Exception ex = xcp.InnerException; - throw ex; - } + // Put the polling task into high gear. + + SetFastPolling(); } } @@ -400,16 +388,8 @@ public void StopDomeMotion() { if ( Connected ) { - Task task = Task.Run( () => - { - AbortSlew(); - - WaitForStatusUpdate(); - - return true; - } ); - - bool result = task.Result; + AbortSlew(); + Status = new DevHubDomeStatus( this ); } } @@ -542,10 +522,12 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime ) LogActivityLine( msgType, "Dome position recalculation due to telescope slew-in-progress." ); - Transform xform = new Transform(); - xform.SiteElevation = TelescopeParameters.SiteElevation; - xform.SiteLatitude = TelescopeParameters.SiteLatitude; - xform.SiteLongitude = TelescopeParameters.SiteLongitude; + Transform xform = new Transform + { + SiteElevation = TelescopeParameters.SiteElevation, + SiteLongitude = TelescopeParameters.SiteLongitude, + SiteLatitude = TelescopeParameters.SiteLatitude + }; EquatorialCoordinateType coordinateType = TelescopeParameters.EquatorialSystem; @@ -857,146 +839,6 @@ private void ReadInitialDomeDataTask() Messenger.Default.Send( new DomeStatusUpdatedMessage( Status ) ); } - private Task OpenShutterAsync() - { - // This method creates a task to run on a worker thread. It issues the open shutter command, - // speeds up the polling cycle, and waits until the next status update before completing. - // This allows the caller to wait for completion before continuing. - - Task task = Task.Run( () => - { - OpenShutter(); - - SetFastPolling(); - - WaitForStatusUpdate(); - - return Status.ShutterStatus == ShutterState.shutterOpening; - } ); - - return task; - } - - private Task CloseShutterAsync() - { - // This method creates a task to run on a worker thread. It issues the close shutter command, - // speeds up the polling cycle, and waits until the next status update before completing. - // This allows the caller to wait for completion before continuing. - - Task task = Task.Run( () => - { - CloseShutter(); - - // Put the polling task into high gear. - - SetFastPolling(); - - WaitForStatusUpdate(); - - return Status.ShutterStatus == ShutterState.shutterClosing; - } ); - - return task; - } - - private Task SlewShutterAsync( double altitude ) - { - // This method creates a task to run on a worker thread. It issues the slew shutter command, - // speeds up the polling cycle, and waits until the next status update before completing. - // This allows the caller to wait for completion before continuing. - - Task task = Task.Run( () => - { - SlewToAltitude( altitude ); - - // Put the polling task into high gear. - - SetFastPolling(); - - WaitForStatusUpdate(); - } ); - - return task; - } - - private Task ParkDomeAsync() - { - // This method creates a task to run on a worker thread. It issues the park command, - // speeds up the polling cycle, and waits until the next status update before completing. - // This allows the caller to wait for completion before continuing. - - Task task = Task.Run( () => - { - Park(); - - // Put the polling task into high gear. - - SetFastPolling(); - - WaitForStatusUpdate(); - - return Status.AtPark; - } ); - - return task; - } - - private void WaitForStatusUpdate() - { - DateTime lastUpdate = Status.LastUpdateTime; - - // Wait for a status update before ending the task. - - while ( lastUpdate == Status.LastUpdateTime ) - { - Thread.Sleep( 400 ); - } - } - - private Task FindHomeAsync() - { - // This method creates a task to run on a worker thread. It issues the FindHome command, - // speeds up the polling cycle, and waits until the next status update before completing. - // This allows the caller to wait for completion before continuing. - - Task task = Task.Run( () => - { - FindHome(); - - // Put the polling task into high gear. - - SetFastPolling(); - - WaitForStatusUpdate(); - - return Status.AtHome; - } ); - - return task; - } - - private Task SlewDomeAsync( double toAzimuth ) - { - // This method creates a task to run on a worker thread. It issues the slew command, - // speeds up the polling cycle, and waits until the next status update before completing. - // This allows the caller to wait for completion before continuing. - - Task task = Task.Run( () => - { - SlewToAzimuth( toAzimuth ); - - // Put the polling task into high gear. - - SetFastPolling(); - - WaitForStatusUpdate(); - - return Status.Slewing; - } ); - - return task; - } - /// /// Calculate the pointing position of the dome given the pointing position of the telescope, /// the hour angle in hours, and the side-of-pier diff --git a/Inno Setup/ASCOM Device Hub Setup.iss b/Inno Setup/ASCOM Device Hub Setup.iss index 9c259da..b104904 100644 --- a/Inno Setup/ASCOM Device Hub Setup.iss +++ b/Inno Setup/ASCOM Device Hub Setup.iss @@ -4,7 +4,7 @@ ; #define MyAppName "ASCOM.DeviceHub" -#define MyAppVersion "6.6.0.11" +#define MyAppVersion "6.6.0.12" #define MyDestSubdirName "DeviceHub" ; #define MyPlatformRoot "D:\Github Repos\ASCOMPlatform\" #define MyPlatformRoot "D:\My Projects\Visual Studio 2022\Ascom\" diff --git a/ProductAssemblyInfo.cs b/ProductAssemblyInfo.cs index 6ef447b..9fe47db 100644 --- a/ProductAssemblyInfo.cs +++ b/ProductAssemblyInfo.cs @@ -20,4 +20,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion( "6.6.0.11" )] \ No newline at end of file +[assembly: AssemblyVersion( "6.6.0.12" )] \ No newline at end of file