Add write() error handling.

This commit is contained in:
Anders Sandstrom
2021-03-10 15:35:10 +01:00
parent 8ab585652e
commit 6e84d4bf0c
4 changed files with 29 additions and 16 deletions
@@ -241,7 +241,7 @@ int ecmcSocketCAN::getlastWritesError() {
if(!writeBuffer_) { if(!writeBuffer_) {
return ECMC_CAN_ERROR_WRITE_BUFFER_NULL; return ECMC_CAN_ERROR_WRITE_BUFFER_NULL;
} }
return writeBuffer_->getlastWritesError(); return writeBuffer_->getlastWritesErrorAndReset();
} }
int ecmcSocketCAN::addWriteCAN(uint32_t canId, int ecmcSocketCAN::addWriteCAN(uint32_t canId,
@@ -277,6 +277,12 @@ void ecmcSocketCAN::execute() {
for(int i = 0; i < deviceCounter_; i++){ for(int i = 0; i < deviceCounter_; i++){
devices_[i]->execute(); devices_[i]->execute();
} }
int writeError=getlastWritesError();
if (writeError) {
errorCode_ = writeError;
refreshNeeded_ = 1;
}
refreshAsynParams(); refreshAsynParams();
return; return;
} }
@@ -128,8 +128,10 @@ int ecmcSocketCANWriteBuffer::addWriteCAN( uint32_t canId,
return addWriteCAN(&frame); return addWriteCAN(&frame);
} }
int ecmcSocketCANWriteBuffer::getlastWritesError() { int ecmcSocketCANWriteBuffer::getlastWritesErrorAndReset() {
return lastWriteSumError_; int tempError = lastWriteSumError_;
lastWriteSumError_ = 0;
return tempError;
} }
int ecmcSocketCANWriteBuffer::addToBuffer(can_frame *frame) { int ecmcSocketCANWriteBuffer::addToBuffer(can_frame *frame) {
@@ -180,6 +182,11 @@ int ecmcSocketCANWriteBuffer::writeCAN(can_frame *frame){
// Maybe need to add the size to write here.. if struct is not full, hmm?! // Maybe need to add the size to write here.. if struct is not full, hmm?!
int nbytes = write(socketId_, frame, sizeof(struct can_frame)); 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;
}
if (nbytes!= sizeof(struct can_frame)) { if (nbytes!= sizeof(struct can_frame)) {
return ECMC_CAN_ERROR_WRITE_INCOMPLETE; return ECMC_CAN_ERROR_WRITE_INCOMPLETE;
} }
@@ -71,7 +71,7 @@ class ecmcSocketCANWriteBuffer {
uint8_t data6, uint8_t data6,
uint8_t data7); uint8_t data7);
int addWriteCAN(can_frame *frame); int addWriteCAN(can_frame *frame);
int getlastWritesError(); int getlastWritesErrorAndReset();
private: private:
static std::string to_string(int value); static std::string to_string(int value);
+12 -12
View File
@@ -1,12 +1,12 @@
REQMOD:mcag-trgt-muts--12400:MODULES REQMOD:mcag-trgt-muts--13868:MODULES
REQMOD:mcag-trgt-muts--12400:VERSIONS REQMOD:mcag-trgt-muts--13868:VERSIONS
REQMOD:mcag-trgt-muts--12400:MOD_VER REQMOD:mcag-trgt-muts--13868:MOD_VER
REQMOD:mcag-trgt-muts--12400:exit REQMOD:mcag-trgt-muts--13868:exit
REQMOD:mcag-trgt-muts--12400:BaseVersion REQMOD:mcag-trgt-muts--13868:BaseVersion
REQMOD:mcag-trgt-muts--12400:require_VER REQMOD:mcag-trgt-muts--13868:require_VER
REQMOD:mcag-trgt-muts--12400:ecmccfg_VER REQMOD:mcag-trgt-muts--13868:ecmccfg_VER
REQMOD:mcag-trgt-muts--12400:asyn_VER REQMOD:mcag-trgt-muts--13868:asyn_VER
REQMOD:mcag-trgt-muts--12400:exprtk_VER REQMOD:mcag-trgt-muts--13868:exprtk_VER
REQMOD:mcag-trgt-muts--12400:motor_VER REQMOD:mcag-trgt-muts--13868:motor_VER
REQMOD:mcag-trgt-muts--12400:ecmc_VER REQMOD:mcag-trgt-muts--13868:ecmc_VER
REQMOD:mcag-trgt-muts--12400:ecmc_plugin_socketcan_VER REQMOD:mcag-trgt-muts--13868:ecmc_plugin_socketcan_VER