Improve error printouts for read and write
This commit is contained in:
@@ -203,9 +203,19 @@ void ecmcSocketCAN::doReadWorker() {
|
||||
}
|
||||
// Wait for new CAN frame
|
||||
int bytes = read(socketId_, &rxmsg_, sizeof(rxmsg_));
|
||||
|
||||
// error in read()
|
||||
if(bytes == -1) {
|
||||
errorCode_ = errno;
|
||||
printf("ecmcSocketCAN: read() fail with error %s.\n", strerror(errno));
|
||||
errorCode_ = errno;
|
||||
printf("ecmcSocketCAN: read() fail with error: %s, (0x%x).\n", strerror(errno),errno);
|
||||
refreshNeeded_ = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// incomplete read()
|
||||
if(bytes != sizeof(rxmsg_)) {
|
||||
printf("ecmcSocketCAN: read() fail with error: Incomplete read, not a full can frame (0x%x).\n",ECMC_CAN_ERROR_READ_INCOMPLETE);
|
||||
errorCode_ = ECMC_CAN_ERROR_READ_INCOMPLETE;
|
||||
refreshNeeded_ = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#define ECMC_CAN_ERROR_WRITE_NO_DATA 12
|
||||
#define ECMC_CAN_ERROR_WRITE_INCOMPLETE 13
|
||||
#define ECMC_CAN_ERROR_WRITE_BUFFER_NULL 14
|
||||
#define ECMC_CAN_ERROR_READ_INCOMPLETE 15
|
||||
|
||||
class ecmcSocketCAN {
|
||||
public:
|
||||
|
||||
@@ -185,12 +185,14 @@ int ecmcSocketCANWriteBuffer::writeCAN(can_frame *frame){
|
||||
|
||||
// Maybe need to add the size to write here.. if struct is not full, hmm?!
|
||||
int nbytes = write(socketId_, frame, sizeof(struct can_frame));
|
||||
|
||||
if(nbytes == -1) {
|
||||
printf("ecmcSocketCAN: write() fail with error %s.\n", strerror(errno));
|
||||
return ECMC_CAN_ERROR_WRITE_INCOMPLETE;
|
||||
printf("ecmcSocketCAN: write() fail with error: %s (0x%x).\n", strerror(errno),errno);
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (nbytes!= sizeof(struct can_frame)) {
|
||||
printf("ecmcSocketCAN: write() fail with error: Incomplete write(), not a full can frame (0x%x).\n",ECMC_CAN_ERROR_WRITE_INCOMPLETE);
|
||||
return ECMC_CAN_ERROR_WRITE_INCOMPLETE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user