simplified i2c code

This commit is contained in:
Robin Müller 2021-02-14 18:45:31 +01:00
parent 101a7696c3
commit 0045cd2062
2 changed files with 140 additions and 146 deletions

View File

@ -6,6 +6,7 @@
#include <fsfw/objectmanager/SystemObject.h>
class GpioCookie;
/**
* @brief This class implements the GpioIF for a linux based system. The
* implementation is based on the libgpiod lib which requires linux 4.8

View File

@ -14,18 +14,18 @@ I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){
I2cComIF::~I2cComIF() {}
ReturnValue_t I2cComIF::initializeInterface(CookieIF * cookie) {
ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
address_t i2cAddress;
std::string deviceFile;
if(cookie == nullptr) {
sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl;
return NULLPOINTER;
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
sif::error << "I2cComIF: Invalid I2C Cookie!"
<< std::endl;
sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl;
return NULLPOINTER;
}
@ -35,25 +35,18 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF * cookie) {
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
I2cInstance_t i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
std::pair status = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
if (status.second == false) {
sif::error << "I2cComIF::initializeInterface: Failed to insert "
<< "device with address " << i2cAddress << "to I2C device "
<< "map" << std::endl;
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
if (not statusPair.second) {
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
i2cAddress << "to I2C device " << "map" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
}
else {
sif::error << "I2cComIF: Device with address " << i2cAddress
<< "already in use" << std::endl;
}
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "Failure" << std::endl;
}
return HasReturnvaluesIF::RETURN_OK;
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress <<
"already in use" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,