@@ -84,6 +84,10 @@ HamlibRotDrv::HamlibRotDrv(const RotProfile &profile,
84
84
}
85
85
86
86
rig_set_debug (RIG_DEBUG_BUG);
87
+
88
+ connect (&errorTimer, &QTimer::timeout,
89
+ this , &HamlibRotDrv::checkErrorCounter);
90
+
87
91
}
88
92
89
93
HamlibRotDrv::~HamlibRotDrv ()
@@ -147,16 +151,10 @@ bool HamlibRotDrv::open()
147
151
148
152
int status = rot_open (rot);
149
153
150
- if ( status != RIG_OK )
151
- {
152
- lastErrorText = hamlibErrorString (status);
153
- qCDebug (runtime) << " Rot Open Error" << lastErrorText;
154
+ if ( !isRotRespOK (status, tr (" Rot Open Error" ), false ) )
154
155
return false ;
155
- }
156
- else
157
- {
158
- qCDebug (runtime) << " Rot Open - OK" ;
159
- }
156
+
157
+ qCDebug (runtime) << " Rot Open - OK" ;
160
158
161
159
opened = true ;
162
160
@@ -243,13 +241,7 @@ void HamlibRotDrv::setPosition(double in_azimuth, double in_elevation)
243
241
static_cast <azimuth_t >(newAzimuth),
244
242
static_cast <elevation_t >(newElevation));
245
243
246
- if ( status != RIG_OK )
247
- {
248
- lastErrorText = hamlibErrorString (status);
249
- qCWarning (runtime) << " Set Az/El error" << lastErrorText;
250
- emit errorOccured (tr (" Set Possition Error" ),
251
- lastErrorText);
252
- }
244
+ isRotRespOK (status, tr (" Set Possition Error" ), false );
253
245
254
246
// wait a moment because Rotators are slow and they are not possible to set and get
255
247
// mode so quickly (get mode is called in the main thread's update() function
@@ -261,6 +253,7 @@ void HamlibRotDrv::stopTimers()
261
253
FCT_IDENTIFICATION;
262
254
263
255
timer.stop ();
256
+ errorTimer.stop ();
264
257
}
265
258
266
259
void HamlibRotDrv::checkRotStateChange ()
@@ -284,6 +277,21 @@ void HamlibRotDrv::checkRotStateChange()
284
277
drvLock.unlock ();
285
278
}
286
279
280
+ void HamlibRotDrv::checkErrorCounter ()
281
+ {
282
+ FCT_IDENTIFICATION;
283
+
284
+ if ( postponedErrors.isEmpty () )
285
+ return ;
286
+
287
+ qCDebug (runtime) << postponedErrors;
288
+
289
+ // emit only one error
290
+ auto it = postponedErrors.constBegin ();
291
+ emit errorOccured (it.key (), it.value ());
292
+ postponedErrors.clear ();
293
+ }
294
+
287
295
void HamlibRotDrv::checkChanges ()
288
296
{
289
297
FCT_IDENTIFICATION;
@@ -307,7 +315,7 @@ void HamlibRotDrv::checkAzEl()
307
315
elevation_t el;
308
316
309
317
int status = rot_get_position (rot, &az, &el);
310
- if ( status == RIG_OK )
318
+ if ( isRotRespOK ( status, tr ( " Get Possition Error " )) )
311
319
{
312
320
double newAzimuth = az;
313
321
double newElevation = el;
@@ -328,18 +336,49 @@ void HamlibRotDrv::checkAzEl()
328
336
emit positioningChanged (azimuth, elevation);
329
337
}
330
338
}
331
- else
332
- {
333
- lastErrorText = hamlibErrorString (status);
334
- qCWarning (runtime) << " Get AZ/EL error" << lastErrorText;
335
- emit errorOccured (tr (" Get Possition Error" ),
336
- lastErrorText);
337
- }
338
339
}
339
340
else
340
- {
341
341
qCDebug (runtime) << " Get POSITION is disabled" ;
342
+ }
343
+
344
+ bool HamlibRotDrv::isRotRespOK (int errorStatus, const QString errorName, bool emitError)
345
+ {
346
+ FCT_IDENTIFICATION;
347
+
348
+ qCDebug (function_parameters) << errorStatus << errorName << emitError;
349
+
350
+ if ( errorStatus == RIG_OK ) // there are no special codes for ROT, use RIG codes
351
+ {
352
+ if ( emitError )
353
+ postponedErrors.remove (errorName);
354
+ return true ;
342
355
}
356
+
357
+ lastErrorText = hamlibErrorString (errorStatus);
358
+
359
+ if ( emitError )
360
+ {
361
+ qCDebug (runtime) << " Emit Error detected" ;
362
+
363
+ if ( !RIG_IS_SOFT_ERRCODE (-errorStatus) )
364
+ {
365
+ // hard error, emit error now
366
+ qCDebug (runtime) << " Hard Error" ;
367
+ emit errorOccured (errorName, lastErrorText);
368
+ }
369
+ else
370
+ {
371
+ // soft error
372
+ postponedErrors[errorName] = lastErrorText;
373
+
374
+ if ( !errorTimer.isActive () )
375
+ {
376
+ qCDebug (runtime) << " Starting Error Timer" ;
377
+ errorTimer.start (15 * 1000 ); // 15s
378
+ }
379
+ }
380
+ }
381
+ return false ;
343
382
}
344
383
345
384
serial_handshake_e HamlibRotDrv::stringToHamlibFlowControl (const QString &in_flowcontrol)
@@ -384,17 +423,22 @@ QString HamlibRotDrv::hamlibErrorString(int errorCode)
384
423
385
424
qCDebug (function_parameters) << errorCode;
386
425
387
- static QRegularExpression re (" [\r\n ]" );
388
-
389
- const QStringList &errorList = QString (rigerror (errorCode)).split (re);
390
426
QString ret;
427
+ QString detail (rigerror (errorCode));
428
+
429
+ #if ( HAMLIBVERSION_MAJOR >= 4 && HAMLIBVERSION_MINOR >= 5 )
430
+ // The rigerror has different behavior since 4.5. It contains the stack trace in the first part
431
+ // Need to use rigerror2
432
+ ret = QString (rigerror2 (errorCode));
433
+ #else
434
+ static QRegularExpression re (" [\r\n ]" );
435
+ QStringList errorList = detail.split (re);
391
436
392
437
if ( errorList.size () >= 1 )
393
- {
394
438
ret = errorList.at (0 );
395
- }
396
-
397
- qCDebug (runtime) << ret;
439
+ # endif
440
+ qWarning () << " Detail " << detail;
441
+ qCWarning (runtime) << ret;
398
442
399
443
return ret;
400
444
}
0 commit comments