Skip to content

Commit 131bae3

Browse files
committed
Print human-readable error messages for binary command errors
1 parent 0ab65ca commit 131bae3

2 files changed

Lines changed: 32 additions & 20 deletions

File tree

acsMotionApp/src/SPiiPlusCommDriver.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ asynStatus SPiiPlusComm::writeReadBinary(char *output, int outBytes, char *input
342342
char* packetBuffer;
343343
size_t nwrite, nread;
344344
int eomReason;
345-
asynStatus status, errCheckStatus;
345+
int errNo = 0;
346+
asynStatus status;
346347
static const char *functionName = "writeReadBinary";
347348

348349
asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: start\n", driverName, functionName);
@@ -374,11 +375,12 @@ asynStatus SPiiPlusComm::writeReadBinary(char *output, int outBytes, char *input
374375
if (status == asynSuccess)
375376
{
376377
// Check for an error reply
377-
status = binaryErrorCheck(packetBuffer, nread);
378-
if (status == asynError)
378+
errNo = binaryErrorCheck(packetBuffer, nread);
379+
if (errNo != 0)
379380
{
380381
*sliceAvailable = false;
381382
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Binary read failed (controller)\n", driverName, functionName);
383+
status = asynError;
382384
}
383385
else
384386
{
@@ -410,10 +412,10 @@ asynStatus SPiiPlusComm::writeReadBinary(char *output, int outBytes, char *input
410412
// If fewer bytes were read and there was an asyn timeout, there might still be an error message
411413
if (nread > 0)
412414
{
413-
errCheckStatus = binaryErrorCheck(packetBuffer, nread);
414-
if (errCheckStatus == asynError)
415+
errNo = binaryErrorCheck(packetBuffer, nread);
416+
if (errNo != 0)
415417
{
416-
status = errCheckStatus;
418+
status = asynError;
417419
}
418420
}
419421
}
@@ -427,16 +429,23 @@ asynStatus SPiiPlusComm::writeReadBinary(char *output, int outBytes, char *input
427429

428430
unlock();
429431

432+
if (errNo != 0)
433+
{
434+
// Print the human-readable error string; humans don't like searching pdfs for error descriptions
435+
writeReadBinaryErrorMessage(errNo);
436+
}
437+
430438
asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: end\n", driverName, functionName);
431439

432440
return status;
433441
}
434442

435-
asynStatus SPiiPlusComm::binaryErrorCheck(char *buffer, int readBytes)
443+
// Return value is 0 if there is no error and the error number if an error is detected
444+
int SPiiPlusComm::binaryErrorCheck(char *buffer, int readBytes)
436445
{
437-
asynStatus status=asynSuccess;
438446
std::stringstream val_convert;
439-
int errNo, idx;
447+
int errNo = 0;
448+
int idx;
440449
uint8_t replyStart, replyEnd, cmdId, bodyLenLsb, bodyLenMsb, bodyStart, bodyEnd;
441450
int bodyLength;
442451
uint8_t errorStr[5] = {0, 0, 0, 0, 0};
@@ -493,12 +502,6 @@ asynStatus SPiiPlusComm::binaryErrorCheck(char *buffer, int readBytes)
493502
val_convert >> errNo;
494503

495504
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Binary command error %i for command id %x\n", driverName, functionName, errNo, cmdId);
496-
497-
// TODO: Print the human-readable error string; humans don't like searching pdfs for error descriptions
498-
// The following call causes a deadlock, even though it doesn't take any locks
499-
//writeReadBinaryErrorMessage(errNo);
500-
501-
status = asynError;
502505
}
503506
}
504507
else
@@ -512,7 +515,7 @@ asynStatus SPiiPlusComm::binaryErrorCheck(char *buffer, int readBytes)
512515
}
513516
}
514517

515-
return status;
518+
return errNo;
516519
}
517520

518521
asynStatus SPiiPlusComm::isVariableDefined(bool *isDefined, const char *var)
@@ -553,6 +556,7 @@ asynStatus SPiiPlusComm::writeReadAckBinary(char *output, int outBytes, char *in
553556
size_t nwrite, nread, extraRead;
554557
int eomReason;
555558
int commandID;
559+
int errNo = 0;
556560
asynStatus status;
557561
static const char *functionName = "writeReadAckBinary";
558562

@@ -592,11 +596,12 @@ asynStatus SPiiPlusComm::writeReadAckBinary(char *output, int outBytes, char *in
592596

593597
asynPrint(pasynUserSelf, ASYN_TRACEIO_DRIVER, "%s:%s: status = %i; extraRead = %li, eomReason = %i\n", driverName, functionName, status, extraRead, eomReason);
594598

595-
// Check for an error reply -- this overwrites the buffer if an error occurs
596-
status = binaryErrorCheck(input, nread+extraRead);
597-
if (status == asynError)
599+
// Check for an error reply
600+
errNo = binaryErrorCheck(input, nread+extraRead);
601+
if (errNo != 0)
598602
{
599603
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Binary read failed (controller)\n", driverName, functionName);
604+
status = asynError;
600605
}
601606

602607
}
@@ -609,6 +614,7 @@ asynStatus SPiiPlusComm::writeReadAckBinary(char *output, int outBytes, char *in
609614
else
610615
{
611616
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Command ID mismatch: write ID = %i, read ID = %i\n", driverName, functionName, commandID, input[1]);
617+
// Should status be set to asynError here?
612618
}
613619
}
614620
}
@@ -623,6 +629,12 @@ asynStatus SPiiPlusComm::writeReadAckBinary(char *output, int outBytes, char *in
623629

624630
unlock();
625631

632+
if (errNo > 0)
633+
{
634+
// Print the human-readable error string; humans don't like searching pdfs for error descriptions
635+
writeReadBinaryErrorMessage(errNo);
636+
}
637+
626638
asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: end\n", driverName, functionName);
627639

628640
return status;

acsMotionApp/src/SPiiPlusCommDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class epicsShareClass SPiiPlusComm : public asynPortDriver {
2727
asynStatus putDoubleArray(double *data, const char *var, int idx1start, int idx1end, int idx2start, int idx2end);
2828
asynStatus writeReadBinary(char *output, int outBytes, char *input, int inBytes, size_t *dataBytes, bool* sliceAvailable);
2929
asynStatus writeReadAckBinary(char *output, int outBytes, char *input, int inBytes);
30-
asynStatus binaryErrorCheck(char *buffer, int readBytes);
30+
int binaryErrorCheck(char *buffer, int readBytes);
3131
asynStatus isVariableDefined(bool *isDefined, const char *var);
3232
asynStatus globalVarCheck(const char *var, int idx1start, int idx1end, int idx2start, int idx2end, int *dimensions, int *numElements, int *errNo);
3333
asynStatus createGlobalRealVar(const char *var, int idx1start, int idx1end, int idx2start, int idx2end);

0 commit comments

Comments
 (0)