diff --git a/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.cpp b/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.cpp index 76cf121..5ce9f53 100644 --- a/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.cpp +++ b/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.cpp @@ -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; } diff --git a/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.h b/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.h index 38a607a..8d57102 100644 --- a/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.h +++ b/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCAN.h @@ -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: diff --git a/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCANWriteBuffer.cpp b/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCANWriteBuffer.cpp index e843c71..3e7285c 100644 --- a/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCANWriteBuffer.cpp +++ b/ecmc_plugin_socketcan/ecmc_plugin_socketcanApp/src/ecmcSocketCANWriteBuffer.cpp @@ -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; }