@@ -51,7 +51,7 @@ public class MountVM : ViewModelBase
51
51
bool _isSlewingEast = false ;
52
52
bool _tryConnect = false ;
53
53
bool _driftAlignRunning = false ;
54
- bool _runningOATCommand = false ;
54
+ int _runningOATCommand = 0 ;
55
55
SemaphoreSlim exclusiveAccess = new SemaphoreSlim ( 1 , 1 ) ;
56
56
string _driftAlignStatus = "Drift Alignment" ;
57
57
float _driftPhase = 0 ;
@@ -69,6 +69,7 @@ public class MountVM : ViewModelBase
69
69
DelegateCommand _connectScopeCommand ;
70
70
DelegateCommand _slewToTargetCommand ;
71
71
DelegateCommand _syncToTargetCommand ;
72
+ DelegateCommand _syncToCurrentCommand ;
72
73
DelegateCommand _startSlewingCommand ;
73
74
DelegateCommand _stopSlewingCommand ;
74
75
DelegateCommand _homeCommand ;
@@ -104,6 +105,7 @@ public MountVM()
104
105
_connectScopeCommand = new DelegateCommand ( ( ) => OnConnectToTelescope ( ) , ( ) => _oatMount != null ) ;
105
106
_slewToTargetCommand = new DelegateCommand ( async ( ) => await OnSlewToTarget ( ) , ( ) => MountConnected ) ;
106
107
_syncToTargetCommand = new DelegateCommand ( async ( ) => await OnSyncToTarget ( ) , ( ) => MountConnected ) ;
108
+ _syncToCurrentCommand = new DelegateCommand ( ( ) => OnSyncToCurrent ( ) , ( ) => MountConnected ) ;
107
109
_startSlewingCommand = new DelegateCommand ( async s => await OnStartSlewing ( s . ToString ( ) ) , ( ) => MountConnected ) ;
108
110
_stopSlewingCommand = new DelegateCommand ( async ( ) => await OnStopSlewing ( 'a' ) , ( ) => MountConnected ) ;
109
111
_homeCommand = new DelegateCommand ( async ( ) => await OnHome ( ) , ( ) => MountConnected ) ;
@@ -130,7 +132,7 @@ private void Log(string format, params object[] p)
130
132
{
131
133
var now = DateTime . UtcNow ;
132
134
var elapsed = now - _startTime ;
133
- var timestamp = string . Format ( "[{0:00}:{1:00}:{2:00}.{3:00}] " , elapsed . Hours , elapsed . Minutes , elapsed . Seconds , elapsed . Milliseconds / 10 ) ;
135
+ var timestamp = string . Format ( "[{0:00}:{1:00}:{2:00}.{3:00}] <{4}>: " , elapsed . Hours , elapsed . Minutes , elapsed . Seconds , elapsed . Milliseconds / 10 , Thread . CurrentThread . ManagedThreadId ) ;
134
136
Console . WriteLine ( String . Format ( timestamp + format , p ) ) ;
135
137
}
136
138
@@ -157,11 +159,11 @@ async private Task<string> RunCustomOATCommandAsync(string command)
157
159
string result = string . Empty ;
158
160
try
159
161
{
160
- _runningOATCommand = true ;
162
+ Interlocked . Increment ( ref _runningOATCommand ) ;
161
163
bool needsReturn = false ;
162
- Log ( "OATCustom: StartRunning [{0}]" , command ) ;
164
+ Log ( "OATCustom: StartRunning [{0}], awaiting access " , command ) ;
163
165
await exclusiveAccess . WaitAsync ( ) ;
164
- Log ( "OATCustom: -> {0} " , command ) ;
166
+ Log ( "OATCustom: Acces granted. -> Sending {0} " , command ) ;
165
167
var commandResult = await _oatMount . SendCommand ( command ) ;
166
168
if ( ! string . IsNullOrEmpty ( commandResult . Data ) )
167
169
{
@@ -172,8 +174,8 @@ async private Task<string> RunCustomOATCommandAsync(string command)
172
174
finally
173
175
{
174
176
Log ( "OATCustom: StopRunning [{0}]" , command ) ;
175
- _runningOATCommand = false ;
176
177
exclusiveAccess . Release ( ) ;
178
+ Interlocked . Decrement ( ref _runningOATCommand ) ;
177
179
}
178
180
179
181
return result . TrimEnd ( "#" . ToCharArray ( ) ) ;
@@ -204,14 +206,15 @@ private async Task OnTimer(object s, EventArgs e)
204
206
// }
205
207
//}
206
208
207
- if ( ! _runningOATCommand )
209
+ if ( Interlocked . CompareExchange ( ref _runningOATCommand , 1 , 0 ) == 0 )
208
210
{
209
211
Log ( "OATTimer: Not Running" ) ;
210
212
if ( MountConnected )
211
213
{
212
214
//UpdateCurrentCoordinates();
213
215
await UpdateStatus ( ) ;
214
216
}
217
+ Interlocked . Decrement ( ref _runningOATCommand ) ;
215
218
}
216
219
else
217
220
{
@@ -334,6 +337,13 @@ private async Task OnSyncToTarget()
334
337
await _oatMount . Sync ( new TelescopePosition ( 1.0 * TargetRASecond / 3600.0 + 1.0 * TargetRAMinute / 60.0 + TargetRAHour , 1.0 * TargetDECSecond / 3600.0 + 1.0 * TargetDECMinute / 60.0 + TargetDECDegree , Epoch . JNOW ) ) ;
335
338
}
336
339
340
+ private void OnSyncToCurrent ( )
341
+ {
342
+ TargetRAHour = CurrentRAHour ;
343
+ TargetRAMinute = CurrentRAMinute ;
344
+ TargetRASecond = CurrentRASecond ;
345
+ }
346
+
337
347
private void FloatToHMS ( double val , out int h , out int m , out int s )
338
348
{
339
349
h = ( int ) Math . Floor ( val ) ;
@@ -370,7 +380,8 @@ private async void OnConnectToTelescope()
370
380
//await +.WaitAsync();
371
381
372
382
var result = await _oatMount . SendCommand ( "GVP#,#" ) ;
373
- ScopeName = result . Data ;
383
+ var resultNr = await _oatMount . SendCommand ( "GVN#,#" ) ;
384
+ ScopeName = $ "{ result . Data } { resultNr . Data } ";
374
385
375
386
_transform . SiteElevation = 100 ; // _oatMount.SiteElevation;
376
387
_transform . SiteLatitude = 47.74 ; //_oatMount.SiteLatitude;
@@ -458,6 +469,7 @@ private void RequeryCommands()
458
469
_connectScopeCommand . Requery ( ) ;
459
470
_slewToTargetCommand . Requery ( ) ;
460
471
_syncToTargetCommand . Requery ( ) ;
472
+ _syncToCurrentCommand . Requery ( ) ;
461
473
_startSlewingCommand . Requery ( ) ;
462
474
_stopSlewingCommand . Requery ( ) ;
463
475
_homeCommand . Requery ( ) ;
@@ -542,6 +554,7 @@ private void OnAdjustTarget(string command)
542
554
public ICommand ConnectScopeCommand { get { return _connectScopeCommand ; } }
543
555
public ICommand SlewToTargetCommand { get { return _slewToTargetCommand ; } }
544
556
public ICommand SyncToTargetCommand { get { return _syncToTargetCommand ; } }
557
+ public ICommand SyncToCurrentCommand { get { return _syncToCurrentCommand ; } }
545
558
public ICommand StartSlewingCommand { get { return _startSlewingCommand ; } }
546
559
public ICommand StopSlewingCommand { get { return _stopSlewingCommand ; } }
547
560
public ICommand HomeCommand { get { return _homeCommand ; } }
0 commit comments