Skip to content

Commit 6949330

Browse files
committed
HamlibDrv: Added a postponed handling for Rot soft errors
the same change as in the case of the commit 30a1f97
1 parent 61790e9 commit 6949330

File tree

2 files changed

+82
-32
lines changed

2 files changed

+82
-32
lines changed

rotator/drivers/HamlibRotDrv.cpp

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ HamlibRotDrv::HamlibRotDrv(const RotProfile &profile,
8484
}
8585

8686
rig_set_debug(RIG_DEBUG_BUG);
87+
88+
connect(&errorTimer, &QTimer::timeout,
89+
this, &HamlibRotDrv::checkErrorCounter);
90+
8791
}
8892

8993
HamlibRotDrv::~HamlibRotDrv()
@@ -147,16 +151,10 @@ bool HamlibRotDrv::open()
147151

148152
int status = rot_open(rot);
149153

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) )
154155
return false;
155-
}
156-
else
157-
{
158-
qCDebug(runtime) << "Rot Open - OK";
159-
}
156+
157+
qCDebug(runtime) << "Rot Open - OK";
160158

161159
opened = true;
162160

@@ -243,13 +241,7 @@ void HamlibRotDrv::setPosition(double in_azimuth, double in_elevation)
243241
static_cast<azimuth_t>(newAzimuth),
244242
static_cast<elevation_t>(newElevation));
245243

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);
253245

254246
// wait a moment because Rotators are slow and they are not possible to set and get
255247
// mode so quickly (get mode is called in the main thread's update() function
@@ -261,6 +253,7 @@ void HamlibRotDrv::stopTimers()
261253
FCT_IDENTIFICATION;
262254

263255
timer.stop();
256+
errorTimer.stop();
264257
}
265258

266259
void HamlibRotDrv::checkRotStateChange()
@@ -284,6 +277,21 @@ void HamlibRotDrv::checkRotStateChange()
284277
drvLock.unlock();
285278
}
286279

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+
287295
void HamlibRotDrv::checkChanges()
288296
{
289297
FCT_IDENTIFICATION;
@@ -307,7 +315,7 @@ void HamlibRotDrv::checkAzEl()
307315
elevation_t el;
308316

309317
int status = rot_get_position(rot, &az, &el);
310-
if ( status == RIG_OK )
318+
if ( isRotRespOK(status, tr("Get Possition Error")) )
311319
{
312320
double newAzimuth = az;
313321
double newElevation = el;
@@ -328,18 +336,49 @@ void HamlibRotDrv::checkAzEl()
328336
emit positioningChanged(azimuth, elevation);
329337
}
330338
}
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-
}
338339
}
339340
else
340-
{
341341
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;
342355
}
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;
343382
}
344383

345384
serial_handshake_e HamlibRotDrv::stringToHamlibFlowControl(const QString &in_flowcontrol)
@@ -384,17 +423,22 @@ QString HamlibRotDrv::hamlibErrorString(int errorCode)
384423

385424
qCDebug(function_parameters) << errorCode;
386425

387-
static QRegularExpression re("[\r\n]");
388-
389-
const QStringList &errorList = QString(rigerror(errorCode)).split(re);
390426
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);
391436

392437
if ( errorList.size() >= 1 )
393-
{
394438
ret = errorList.at(0);
395-
}
396-
397-
qCDebug(runtime) << ret;
439+
#endif
440+
qWarning() << "Detail" << detail;
441+
qCWarning(runtime) << ret;
398442

399443
return ret;
400444
}

rotator/drivers/HamlibRotDrv.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ class HamlibRotDrv : public GenericRotDrv
2424

2525
private slots:
2626
void checkRotStateChange();
27+
void checkErrorCounter();
2728

2829
private:
2930
static int addRig(const struct rot_caps* caps, void* data);
3031

3132
void checkChanges();
3233
void checkAzEl();
34+
bool isRotRespOK(int errorStatus,
35+
const QString errorName,
36+
bool emitError = true);
3337

3438
serial_handshake_e stringToHamlibFlowControl(const QString &in_flowcontrol);
3539
serial_parity_e stringToHamlibParity(const QString &in_parity);
@@ -38,9 +42,11 @@ private slots:
3842

3943
ROT* rot;
4044
QTimer timer;
45+
QTimer errorTimer;
4146
QMutex drvLock;
4247

4348
bool forceSendState;
49+
QHash<QString, QString>postponedErrors;
4450
};
4551

4652
#endif // QLOG_ROTATOR_DRIVERS_HAMLIBROTDRV_H

0 commit comments

Comments
 (0)