From 05cad893a2b713827cf4cdc9afe49675f18afcc7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Dec 2022 10:05:23 +0100 Subject: [PATCH] introduce error counter to avoid spam --- src/fsfw_hal/linux/i2c/I2cComIF.cpp | 11 +++++++---- src/fsfw_hal/linux/i2c/I2cCookie.h | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/fsfw_hal/linux/i2c/I2cComIF.cpp b/src/fsfw_hal/linux/i2c/I2cComIF.cpp index 1ad19e82..08151c03 100644 --- a/src/fsfw_hal/linux/i2c/I2cComIF.cpp +++ b/src/fsfw_hal/linux/i2c/I2cComIF.cpp @@ -109,14 +109,17 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s } if (write(fd, sendData, sendLen) != static_cast(sendLen)) { + i2cCookie->errorCounter++; + if (i2cCookie->errorCounter < 3) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "I2cComIF::sendMessage: Failed to send data to I2C " - "device with error code " - << errno << ". Error description: " << strerror(errno) << std::endl; + sif::error << "I2cComIF::sendMessage: Failed to send data to I2C " + "device with error code " + << errno << ". Error description: " << strerror(errno) << std::endl; #endif + } return returnvalue::FAILED; } - + i2cCookie->errorCounter = 0; #if FSFW_HAL_I2C_WIRETAPPING == 1 sif::info << "Sent I2C data to bus " << deviceFile << ":" << std::endl; arrayprinter::print(sendData, sendLen); diff --git a/src/fsfw_hal/linux/i2c/I2cCookie.h b/src/fsfw_hal/linux/i2c/I2cCookie.h index 84a1873c..8be71205 100644 --- a/src/fsfw_hal/linux/i2c/I2cCookie.h +++ b/src/fsfw_hal/linux/i2c/I2cCookie.h @@ -27,6 +27,8 @@ class I2cCookie : public CookieIF { size_t getMaxReplyLen() const; std::string getDeviceFile() const; + uint8_t errorCounter = 0; + private: address_t i2cAddress = 0; size_t maxReplyLen = 0;