Add write() error handling.
This commit is contained in:
@@ -241,7 +241,7 @@ int ecmcSocketCAN::getlastWritesError() {
|
||||
if(!writeBuffer_) {
|
||||
return ECMC_CAN_ERROR_WRITE_BUFFER_NULL;
|
||||
}
|
||||
return writeBuffer_->getlastWritesError();
|
||||
return writeBuffer_->getlastWritesErrorAndReset();
|
||||
}
|
||||
|
||||
int ecmcSocketCAN::addWriteCAN(uint32_t canId,
|
||||
@@ -277,6 +277,12 @@ void ecmcSocketCAN::execute() {
|
||||
for(int i = 0; i < deviceCounter_; i++){
|
||||
devices_[i]->execute();
|
||||
}
|
||||
|
||||
int writeError=getlastWritesError();
|
||||
if (writeError) {
|
||||
errorCode_ = writeError;
|
||||
refreshNeeded_ = 1;
|
||||
}
|
||||
refreshAsynParams();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,8 +128,10 @@ int ecmcSocketCANWriteBuffer::addWriteCAN( uint32_t canId,
|
||||
return addWriteCAN(&frame);
|
||||
}
|
||||
|
||||
int ecmcSocketCANWriteBuffer::getlastWritesError() {
|
||||
return lastWriteSumError_;
|
||||
int ecmcSocketCANWriteBuffer::getlastWritesErrorAndReset() {
|
||||
int tempError = lastWriteSumError_;
|
||||
lastWriteSumError_ = 0;
|
||||
return tempError;
|
||||
}
|
||||
|
||||
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?!
|
||||
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)) {
|
||||
return ECMC_CAN_ERROR_WRITE_INCOMPLETE;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class ecmcSocketCANWriteBuffer {
|
||||
uint8_t data6,
|
||||
uint8_t data7);
|
||||
int addWriteCAN(can_frame *frame);
|
||||
int getlastWritesError();
|
||||
int getlastWritesErrorAndReset();
|
||||
|
||||
private:
|
||||
static std::string to_string(int value);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
REQMOD:mcag-trgt-muts--12400:MODULES
|
||||
REQMOD:mcag-trgt-muts--12400:VERSIONS
|
||||
REQMOD:mcag-trgt-muts--12400:MOD_VER
|
||||
REQMOD:mcag-trgt-muts--12400:exit
|
||||
REQMOD:mcag-trgt-muts--12400:BaseVersion
|
||||
REQMOD:mcag-trgt-muts--12400:require_VER
|
||||
REQMOD:mcag-trgt-muts--12400:ecmccfg_VER
|
||||
REQMOD:mcag-trgt-muts--12400:asyn_VER
|
||||
REQMOD:mcag-trgt-muts--12400:exprtk_VER
|
||||
REQMOD:mcag-trgt-muts--12400:motor_VER
|
||||
REQMOD:mcag-trgt-muts--12400:ecmc_VER
|
||||
REQMOD:mcag-trgt-muts--12400:ecmc_plugin_socketcan_VER
|
||||
REQMOD:mcag-trgt-muts--13868:MODULES
|
||||
REQMOD:mcag-trgt-muts--13868:VERSIONS
|
||||
REQMOD:mcag-trgt-muts--13868:MOD_VER
|
||||
REQMOD:mcag-trgt-muts--13868:exit
|
||||
REQMOD:mcag-trgt-muts--13868:BaseVersion
|
||||
REQMOD:mcag-trgt-muts--13868:require_VER
|
||||
REQMOD:mcag-trgt-muts--13868:ecmccfg_VER
|
||||
REQMOD:mcag-trgt-muts--13868:asyn_VER
|
||||
REQMOD:mcag-trgt-muts--13868:exprtk_VER
|
||||
REQMOD:mcag-trgt-muts--13868:motor_VER
|
||||
REQMOD:mcag-trgt-muts--13868:ecmc_VER
|
||||
REQMOD:mcag-trgt-muts--13868:ecmc_plugin_socketcan_VER
|
||||
|
||||
Reference in New Issue
Block a user