From 77b1a85b47c3bd2cb9f36d92ea31689dc4caa674 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 20 Oct 2022 14:24:03 +0200 Subject: [PATCH 1/3] important bugfix for i2c device com IF --- src/fsfw_hal/linux/i2c/I2cComIF.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw_hal/linux/i2c/I2cComIF.cpp b/src/fsfw_hal/linux/i2c/I2cComIF.cpp index 8edeb8ab..11b826ce 100644 --- a/src/fsfw_hal/linux/i2c/I2cComIF.cpp +++ b/src/fsfw_hal/linux/i2c/I2cComIF.cpp @@ -214,7 +214,7 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, } *buffer = i2cDeviceMapIter->second.replyBuffer.data(); *size = i2cDeviceMapIter->second.replyLen; - + i2cDeviceMapIter->second.replyLen = 0; return returnvalue::OK; } From 1164c21dddc2fb84126a45f7531116423d5a4753 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 14:23:43 +0200 Subject: [PATCH 2/3] iter not a member anymore, more bugfixes --- src/fsfw_hal/linux/i2c/I2cComIF.cpp | 13 +++++-------- src/fsfw_hal/linux/i2c/I2cComIF.h | 2 -- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/fsfw_hal/linux/i2c/I2cComIF.cpp b/src/fsfw_hal/linux/i2c/I2cComIF.cpp index 11b826ce..4e57852b 100644 --- a/src/fsfw_hal/linux/i2c/I2cComIF.cpp +++ b/src/fsfw_hal/linux/i2c/I2cComIF.cpp @@ -41,7 +41,7 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) { i2cAddress = i2cCookie->getAddress(); - i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + auto i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); if (i2cDeviceMapIter == i2cDeviceMap.end()) { size_t maxReplyLen = i2cCookie->getMaxReplyLen(); I2cInstance i2cInstance = {std::vector(maxReplyLen), 0}; @@ -89,7 +89,7 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s } address_t i2cAddress = i2cCookie->getAddress(); - i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + auto i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); if (i2cDeviceMapIter == i2cDeviceMap.end()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not " @@ -140,20 +140,19 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl; #endif - i2cDeviceMapIter->second.replyLen = 0; return NULLPOINTER; } address_t i2cAddress = i2cCookie->getAddress(); - i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + auto i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); if (i2cDeviceMapIter == i2cDeviceMap.end()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not " << "registered in i2cDeviceMap" << std::endl; #endif - i2cDeviceMapIter->second.replyLen = 0; return returnvalue::FAILED; } + i2cDeviceMapIter->second.replyLen = 0; deviceFile = i2cCookie->getDeviceFile(); UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage"); @@ -162,7 +161,6 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe } result = openDevice(deviceFile, i2cAddress, &fd); if (result != returnvalue::OK) { - i2cDeviceMapIter->second.replyLen = 0; return result; } @@ -177,7 +175,6 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " << requestLen << " bytes" << std::endl; #endif - i2cDeviceMapIter->second.replyLen = 0; #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen << " bytes" << std::endl; @@ -204,7 +201,7 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, } address_t i2cAddress = i2cCookie->getAddress(); - i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); + auto i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); if (i2cDeviceMapIter == i2cDeviceMap.end()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not " diff --git a/src/fsfw_hal/linux/i2c/I2cComIF.h b/src/fsfw_hal/linux/i2c/I2cComIF.h index 0a15c3a4..8c44cee0 100644 --- a/src/fsfw_hal/linux/i2c/I2cComIF.h +++ b/src/fsfw_hal/linux/i2c/I2cComIF.h @@ -36,12 +36,10 @@ class I2cComIF : public DeviceCommunicationIF, public SystemObject { }; using I2cDeviceMap = std::unordered_map; - using I2cDeviceMapIter = I2cDeviceMap::iterator; /* In this map all i2c devices will be registered with their address and * the appropriate file descriptor will be stored */ I2cDeviceMap i2cDeviceMap; - I2cDeviceMapIter i2cDeviceMapIter; /** * @brief This function opens an I2C device and binds the opened file From d8a4675842c2d913218b2c3c341eb6ba346e05ad Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 14:30:14 +0200 Subject: [PATCH 3/3] bump changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e2262b..1419c4d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixes +- I2C Bugfixes: Do not keep iterator as member and fix some incorrect handling with the iterator. + Also properly reset the reply size for successfull transfers and erroneous transfers. + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/700 - Bugfix for Serial Buffer Stream: Setting `doActive` to false now actually fully disables printing. PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/680