Skip to content

Commit 683a582

Browse files
committed
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.
1 parent 336d8f0 commit 683a582

3 files changed

Lines changed: 32 additions & 190 deletions

File tree

DeviceHub/DeviceManagers/DomeManager.cs

Lines changed: 30 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ public void OpenDomeShutter()
304304
if ( Connected && Capabilities != null && Status != null
305305
&& Capabilities.CanSetShutter && Status.ShutterStatus != ShutterState.shutterOpen )
306306
{
307-
// Issue the open shutter command and wait for a status update before continuing.
307+
OpenShutter();
308+
Status = new DevHubDomeStatus( this );
308309

309-
var task = OpenShutterAsync();
310-
var result = task.Result;
310+
SetFastPolling();
311311
}
312312
}
313313

@@ -318,10 +318,10 @@ public void CloseDomeShutter()
318318
if ( Connected && Capabilities != null && Status != null
319319
&& Capabilities.CanSetShutter && Status.ShutterStatus != ShutterState.shutterClosed )
320320
{
321-
// Issue the close shutter command and wait for a status update before returning.
321+
CloseShutter();
322+
Status = new DevHubDomeStatus( this );
322323

323-
var task = CloseShutterAsync();
324-
var result = task.Result;
324+
SetFastPolling();
325325
}
326326
}
327327

@@ -331,19 +331,21 @@ public void ParkTheDome()
331331
{
332332
ParkingState = ParkingStateEnum.ParkInProgress;
333333

334-
// Issue the park command and wait for a status update before returning;
334+
Park();
335+
Status = new DevHubDomeStatus( this );
335336

336-
var task = ParkDomeAsync();
337-
var result = task.Result;
337+
SetFastPolling();
338338
}
339339
}
340340

341341
public void FindHomePosition()
342342
{
343343
if ( Connected && Capabilities != null && Capabilities.CanFindHome && !Slewing )
344344
{
345-
var task = FindHomeAsync();
346-
var result = task.Result;
345+
FindHome();
346+
Status = new DevHubDomeStatus( this );
347+
348+
SetFastPolling();
347349
}
348350
}
349351

@@ -354,17 +356,10 @@ public void SlewDomeShutter( double targetAltitude )
354356
if ( Connected && !Slewing && Capabilities.CanSetAltitude
355357
&& ( status != ShutterState.shutterClosed && status != ShutterState.shutterError ) )
356358
{
357-
Task task;
359+
SlewToAltitude( targetAltitude );
360+
Status = new DevHubDomeStatus( this );
358361

359-
try
360-
{
361-
task = SlewShutterAsync( targetAltitude );
362-
task.Wait();
363-
}
364-
catch ( AggregateException xcp )
365-
{
366-
throw xcp.InnerException;
367-
}
362+
SetFastPolling();
368363
}
369364
}
370365

@@ -378,38 +373,23 @@ public void SetSlavedState( bool state )
378373

379374
public void SlewDomeToAzimuth( double targetAzimuth )
380375
{
381-
if ( Connected && !Slewing && Capabilities.CanSetAzimuth )
376+
if ( Connected && !Status.Slewing && Capabilities.CanSetAzimuth )
382377
{
383-
// We don't actually need the result, but it allows us to wait for the async slew to start
384-
// and for a status update to occur.
378+
SlewToAzimuth( targetAzimuth );
379+
Status = new DevHubDomeStatus( this );
385380

386-
try
387-
{
388-
var task = SlewDomeAsync( targetAzimuth );
389-
var result = task.Result;
390-
}
391-
catch (AggregateException xcp )
392-
{
393-
Exception ex = xcp.InnerException;
394-
throw ex;
395-
}
381+
// Put the polling task into high gear.
382+
383+
SetFastPolling();
396384
}
397385
}
398386

399387
public void StopDomeMotion()
400388
{
401389
if ( Connected )
402390
{
403-
Task<bool> task = Task<bool>.Run( () =>
404-
{
405-
AbortSlew();
406-
407-
WaitForStatusUpdate();
408-
409-
return true;
410-
} );
411-
412-
bool result = task.Result;
391+
AbortSlew();
392+
Status = new DevHubDomeStatus( this );
413393
}
414394
}
415395

@@ -542,10 +522,12 @@ private void SlewTheSlavedDome( ref DateTime nextAdjustmentTime )
542522

543523
LogActivityLine( msgType, "Dome position recalculation due to telescope slew-in-progress." );
544524

545-
Transform xform = new Transform();
546-
xform.SiteElevation = TelescopeParameters.SiteElevation;
547-
xform.SiteLatitude = TelescopeParameters.SiteLatitude;
548-
xform.SiteLongitude = TelescopeParameters.SiteLongitude;
525+
Transform xform = new Transform
526+
{
527+
SiteElevation = TelescopeParameters.SiteElevation,
528+
SiteLongitude = TelescopeParameters.SiteLongitude,
529+
SiteLatitude = TelescopeParameters.SiteLatitude
530+
};
549531

550532
EquatorialCoordinateType coordinateType = TelescopeParameters.EquatorialSystem;
551533

@@ -857,146 +839,6 @@ private void ReadInitialDomeDataTask()
857839
Messenger.Default.Send( new DomeStatusUpdatedMessage( Status ) );
858840
}
859841

860-
private Task<bool> OpenShutterAsync()
861-
{
862-
// This method creates a task to run on a worker thread. It issues the open shutter command,
863-
// speeds up the polling cycle, and waits until the next status update before completing.
864-
// This allows the caller to wait for completion before continuing.
865-
866-
Task<bool> task = Task<bool>.Run( () =>
867-
{
868-
OpenShutter();
869-
870-
SetFastPolling();
871-
872-
WaitForStatusUpdate();
873-
874-
return Status.ShutterStatus == ShutterState.shutterOpening;
875-
} );
876-
877-
return task;
878-
}
879-
880-
private Task<bool> CloseShutterAsync()
881-
{
882-
// This method creates a task to run on a worker thread. It issues the close shutter command,
883-
// speeds up the polling cycle, and waits until the next status update before completing.
884-
// This allows the caller to wait for completion before continuing.
885-
886-
Task<bool> task = Task<bool>.Run( () =>
887-
{
888-
CloseShutter();
889-
890-
// Put the polling task into high gear.
891-
892-
SetFastPolling();
893-
894-
WaitForStatusUpdate();
895-
896-
return Status.ShutterStatus == ShutterState.shutterClosing;
897-
} );
898-
899-
return task;
900-
}
901-
902-
private Task SlewShutterAsync( double altitude )
903-
{
904-
// This method creates a task to run on a worker thread. It issues the slew shutter command,
905-
// speeds up the polling cycle, and waits until the next status update before completing.
906-
// This allows the caller to wait for completion before continuing.
907-
908-
Task task = Task.Run( () =>
909-
{
910-
SlewToAltitude( altitude );
911-
912-
// Put the polling task into high gear.
913-
914-
SetFastPolling();
915-
916-
WaitForStatusUpdate();
917-
} );
918-
919-
return task;
920-
}
921-
922-
private Task<bool> ParkDomeAsync()
923-
{
924-
// This method creates a task to run on a worker thread. It issues the park command,
925-
// speeds up the polling cycle, and waits until the next status update before completing.
926-
// This allows the caller to wait for completion before continuing.
927-
928-
Task<bool> task = Task<bool>.Run( () =>
929-
{
930-
Park();
931-
932-
// Put the polling task into high gear.
933-
934-
SetFastPolling();
935-
936-
WaitForStatusUpdate();
937-
938-
return Status.AtPark;
939-
} );
940-
941-
return task;
942-
}
943-
944-
private void WaitForStatusUpdate()
945-
{
946-
DateTime lastUpdate = Status.LastUpdateTime;
947-
948-
// Wait for a status update before ending the task.
949-
950-
while ( lastUpdate == Status.LastUpdateTime )
951-
{
952-
Thread.Sleep( 400 );
953-
}
954-
}
955-
956-
private Task<bool> FindHomeAsync()
957-
{
958-
// This method creates a task to run on a worker thread. It issues the FindHome command,
959-
// speeds up the polling cycle, and waits until the next status update before completing.
960-
// This allows the caller to wait for completion before continuing.
961-
962-
Task<bool> task = Task<bool>.Run( () =>
963-
{
964-
FindHome();
965-
966-
// Put the polling task into high gear.
967-
968-
SetFastPolling();
969-
970-
WaitForStatusUpdate();
971-
972-
return Status.AtHome;
973-
} );
974-
975-
return task;
976-
}
977-
978-
private Task<bool> SlewDomeAsync( double toAzimuth )
979-
{
980-
// This method creates a task to run on a worker thread. It issues the slew command,
981-
// speeds up the polling cycle, and waits until the next status update before completing.
982-
// This allows the caller to wait for completion before continuing.
983-
984-
Task<bool> task = Task<bool>.Run( () =>
985-
{
986-
SlewToAzimuth( toAzimuth );
987-
988-
// Put the polling task into high gear.
989-
990-
SetFastPolling();
991-
992-
WaitForStatusUpdate();
993-
994-
return Status.Slewing;
995-
} );
996-
997-
return task;
998-
}
999-
1000842
/// <summary>
1001843
/// Calculate the pointing position of the dome given the pointing position of the telescope,
1002844
/// the hour angle in hours, and the side-of-pier

Inno Setup/ASCOM Device Hub Setup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
;
55

66
#define MyAppName "ASCOM.DeviceHub"
7-
#define MyAppVersion "6.6.0.11"
7+
#define MyAppVersion "6.6.0.12"
88
#define MyDestSubdirName "DeviceHub"
99
; #define MyPlatformRoot "D:\Github Repos\ASCOMPlatform\"
1010
#define MyPlatformRoot "D:\My Projects\Visual Studio 2022\Ascom\"

ProductAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
// You can specify all the values or you can default the Build and Revision Numbers
2121
// by using the '*' as shown below:
2222
// [assembly: AssemblyVersion("1.0.*")]
23-
[assembly: AssemblyVersion( "6.6.0.11" )]
23+
[assembly: AssemblyVersion( "6.6.0.12" )]

0 commit comments

Comments
 (0)