EIVE upstream #29

Merged
muellerr merged 693 commits from use-eive-upstream into develop 2023-06-30 15:44:39 +02:00
7 changed files with 34 additions and 34 deletions
Showing only changes of commit b45206ccd6 - Show all commits

View File

@ -6,14 +6,11 @@
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
UnixFileGuard::UnixFileGuard(const std::string& device, int* fileDescriptor, int flags,
UnixFileGuard::UnixFileGuard(const std::string& device, int& fileDescriptor, int flags,
std::string diagnosticPrefix)
: fileDescriptor(fileDescriptor) {
if (fileDescriptor == nullptr) {
return;
}
*fileDescriptor = open(device.c_str(), flags);
if (*fileDescriptor < 0) {
: fdRef(fileDescriptor) {
fileDescriptor = open(device.c_str(), flags);
if (fileDescriptor < 0) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << diagnosticPrefix << ": Opening device failed with error code " << errno << ": "
@ -27,10 +24,6 @@ UnixFileGuard::UnixFileGuard(const std::string& device, int* fileDescriptor, int
}
}
UnixFileGuard::~UnixFileGuard() {
if (fileDescriptor != nullptr) {
close(*fileDescriptor);
}
}
UnixFileGuard::~UnixFileGuard() { close(fdRef); }
ReturnValue_t UnixFileGuard::getOpenResult() const { return openStatus; }

View File

@ -15,7 +15,15 @@ class UnixFileGuard {
static constexpr ReturnValue_t OPEN_FILE_FAILED = 1;
UnixFileGuard(const std::string& device, int* fileDescriptor, int flags,
/**
* Open a device and assign the given file descriptor variable
* @param device [in] Device name.
* @param fileDescriptor [in/out] Will be assigned by file guard and re-used to
* close the guard.
* @param flags
* @param diagnosticPrefix
*/
UnixFileGuard(const std::string& device, int& fileDescriptor, int flags,
std::string diagnosticPrefix = "");
virtual ~UnixFileGuard();
@ -23,7 +31,7 @@ class UnixFileGuard {
ReturnValue_t getOpenResult() const;
private:
int* fileDescriptor = nullptr;
int& fdRef;
ReturnValue_t openStatus = returnvalue::OK;
};

View File

@ -66,8 +66,7 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
ReturnValue_t result;
int fd;
std::string deviceFile;
int fd = 0;
if (sendData == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -98,12 +97,12 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
return returnvalue::FAILED;
}
deviceFile = i2cCookie->getDeviceFile();
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::sendMessage");
const auto& deviceFile = i2cCookie->getDeviceFile();
UnixFileGuard fileHelper(deviceFile, fd, O_RDWR, "I2cComIF::sendMessage");
if (fileHelper.getOpenResult() != returnvalue::OK) {
return fileHelper.getOpenResult();
}
result = openDevice(deviceFile, i2cAddress, &fd);
result = openI2cSlave(deviceFile, i2cAddress, fd);
if (result != returnvalue::OK) {
return result;
}
@ -131,8 +130,7 @@ ReturnValue_t I2cComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::O
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
ReturnValue_t result;
int fd;
std::string deviceFile;
int fd = 0;
if (requestLen == 0) {
return returnvalue::OK;
@ -157,12 +155,12 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
}
i2cDeviceMapIter->second.replyLen = 0;
deviceFile = i2cCookie->getDeviceFile();
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage");
auto& deviceFile = i2cCookie->getDeviceFile();
UnixFileGuard fileHelper(deviceFile, fd, O_RDWR, "I2cComIF::requestReceiveMessage");
if (fileHelper.getOpenResult() != returnvalue::OK) {
return fileHelper.getOpenResult();
}
result = openDevice(deviceFile, i2cAddress, &fd);
result = openI2cSlave(deviceFile, i2cAddress, fd);
if (result != returnvalue::OK) {
return result;
}
@ -220,9 +218,9 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
return returnvalue::OK;
}
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
int* fileDescriptor) {
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
ReturnValue_t I2cComIF::openI2cSlave(const std::string& deviceFile, address_t i2cAddress,
int& fileDescriptor) {
if (ioctl(fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "I2cComIF: Specifying target device failed with error code " << errno << "."

View File

@ -49,7 +49,8 @@ class I2cComIF : public DeviceCommunicationIF, public SystemObject {
* @param fileDescriptor Pointer to device descriptor.
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED.
*/
ReturnValue_t openDevice(std::string deviceFile, address_t i2cAddress, int *fileDescriptor);
ReturnValue_t openI2cSlave(const std::string &deviceFile, address_t i2cAddress,
int &fileDescriptor);
};
#endif /* LINUX_I2C_I2COMIF_H_ */

View File

@ -1,12 +1,12 @@
#include "fsfw_hal/linux/i2c/I2cCookie.h"
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_)
: i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {}
: i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(std::move(deviceFile_)) {}
address_t I2cCookie::getAddress() const { return i2cAddress; }
size_t I2cCookie::getMaxReplyLen() const { return maxReplyLen; }
std::string I2cCookie::getDeviceFile() const { return deviceFile; }
const std::string& I2cCookie::getDeviceFile() const { return deviceFile; }
I2cCookie::~I2cCookie() {}

View File

@ -25,7 +25,7 @@ class I2cCookie : public CookieIF {
address_t getAddress() const;
size_t getMaxReplyLen() const;
std::string getDeviceFile() const;
const std::string& getDeviceFile() const;
uint8_t errorCounter = 0;

View File

@ -75,7 +75,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
spiCookie->getSpiParameters(spiMode, spiSpeed, &params);
int fileDescriptor = 0;
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::initializeInterface");
UnixFileGuard fileHelper(dev, fileDescriptor, O_RDWR, "SpiComIF::initializeInterface");
if (fileHelper.getOpenResult() != returnvalue::OK) {
return fileHelper.getOpenResult();
}
@ -171,7 +171,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
int retval = 0;
/* Prepare transfer */
int fileDescriptor = 0;
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
UnixFileGuard fileHelper(dev, fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
if (fileHelper.getOpenResult() != returnvalue::OK) {
return OPENING_FILE_FAILED;
}
@ -285,7 +285,7 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
ReturnValue_t result = returnvalue::OK;
int fileDescriptor = 0;
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
UnixFileGuard fileHelper(dev, fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
if (fileHelper.getOpenResult() != returnvalue::OK) {
return OPENING_FILE_FAILED;
}