Merge remote-tracking branch 'origin/develop' into mueller/pus-15-tm-storage
This commit is contained in:
commit
b45206ccd6
@ -6,14 +6,11 @@
|
|||||||
#include "fsfw/FSFW.h"
|
#include "fsfw/FSFW.h"
|
||||||
#include "fsfw/serviceinterface.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)
|
std::string diagnosticPrefix)
|
||||||
: fileDescriptor(fileDescriptor) {
|
: fdRef(fileDescriptor) {
|
||||||
if (fileDescriptor == nullptr) {
|
fileDescriptor = open(device.c_str(), flags);
|
||||||
return;
|
if (fileDescriptor < 0) {
|
||||||
}
|
|
||||||
*fileDescriptor = open(device.c_str(), flags);
|
|
||||||
if (*fileDescriptor < 0) {
|
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << diagnosticPrefix << ": Opening device failed with error code " << errno << ": "
|
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() {
|
UnixFileGuard::~UnixFileGuard() { close(fdRef); }
|
||||||
if (fileDescriptor != nullptr) {
|
|
||||||
close(*fileDescriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t UnixFileGuard::getOpenResult() const { return openStatus; }
|
ReturnValue_t UnixFileGuard::getOpenResult() const { return openStatus; }
|
||||||
|
@ -15,7 +15,15 @@ class UnixFileGuard {
|
|||||||
|
|
||||||
static constexpr ReturnValue_t OPEN_FILE_FAILED = 1;
|
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 = "");
|
std::string diagnosticPrefix = "");
|
||||||
|
|
||||||
virtual ~UnixFileGuard();
|
virtual ~UnixFileGuard();
|
||||||
@ -23,7 +31,7 @@ class UnixFileGuard {
|
|||||||
ReturnValue_t getOpenResult() const;
|
ReturnValue_t getOpenResult() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int* fileDescriptor = nullptr;
|
int& fdRef;
|
||||||
ReturnValue_t openStatus = returnvalue::OK;
|
ReturnValue_t openStatus = returnvalue::OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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 I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
int fd;
|
int fd = 0;
|
||||||
std::string deviceFile;
|
|
||||||
|
|
||||||
if (sendData == nullptr) {
|
if (sendData == nullptr) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
@ -98,12 +97,12 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
|
|||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFile = i2cCookie->getDeviceFile();
|
const auto& deviceFile = i2cCookie->getDeviceFile();
|
||||||
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::sendMessage");
|
UnixFileGuard fileHelper(deviceFile, fd, O_RDWR, "I2cComIF::sendMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
result = openDevice(deviceFile, i2cAddress, &fd);
|
result = openI2cSlave(deviceFile, i2cAddress, fd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
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 I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
int fd;
|
int fd = 0;
|
||||||
std::string deviceFile;
|
|
||||||
|
|
||||||
if (requestLen == 0) {
|
if (requestLen == 0) {
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
@ -157,12 +155,12 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
|
|||||||
}
|
}
|
||||||
i2cDeviceMapIter->second.replyLen = 0;
|
i2cDeviceMapIter->second.replyLen = 0;
|
||||||
|
|
||||||
deviceFile = i2cCookie->getDeviceFile();
|
auto& deviceFile = i2cCookie->getDeviceFile();
|
||||||
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage");
|
UnixFileGuard fileHelper(deviceFile, fd, O_RDWR, "I2cComIF::requestReceiveMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
result = openDevice(deviceFile, i2cAddress, &fd);
|
result = openI2cSlave(deviceFile, i2cAddress, fd);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -220,9 +218,9 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
|
ReturnValue_t I2cComIF::openI2cSlave(const std::string& deviceFile, address_t i2cAddress,
|
||||||
int* fileDescriptor) {
|
int& fileDescriptor) {
|
||||||
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
|
if (ioctl(fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "I2cComIF: Specifying target device failed with error code " << errno << "."
|
sif::warning << "I2cComIF: Specifying target device failed with error code " << errno << "."
|
||||||
|
@ -49,7 +49,8 @@ class I2cComIF : public DeviceCommunicationIF, public SystemObject {
|
|||||||
* @param fileDescriptor Pointer to device descriptor.
|
* @param fileDescriptor Pointer to device descriptor.
|
||||||
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED.
|
* @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_ */
|
#endif /* LINUX_I2C_I2COMIF_H_ */
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
||||||
|
|
||||||
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_)
|
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; }
|
address_t I2cCookie::getAddress() const { return i2cAddress; }
|
||||||
|
|
||||||
size_t I2cCookie::getMaxReplyLen() const { return maxReplyLen; }
|
size_t I2cCookie::getMaxReplyLen() const { return maxReplyLen; }
|
||||||
|
|
||||||
std::string I2cCookie::getDeviceFile() const { return deviceFile; }
|
const std::string& I2cCookie::getDeviceFile() const { return deviceFile; }
|
||||||
|
|
||||||
I2cCookie::~I2cCookie() {}
|
I2cCookie::~I2cCookie() {}
|
||||||
|
@ -25,7 +25,7 @@ class I2cCookie : public CookieIF {
|
|||||||
|
|
||||||
address_t getAddress() const;
|
address_t getAddress() const;
|
||||||
size_t getMaxReplyLen() const;
|
size_t getMaxReplyLen() const;
|
||||||
std::string getDeviceFile() const;
|
const std::string& getDeviceFile() const;
|
||||||
|
|
||||||
uint8_t errorCounter = 0;
|
uint8_t errorCounter = 0;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
|
|||||||
spiCookie->getSpiParameters(spiMode, spiSpeed, ¶ms);
|
spiCookie->getSpiParameters(spiMode, spiSpeed, ¶ms);
|
||||||
|
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::initializeInterface");
|
UnixFileGuard fileHelper(dev, fileDescriptor, O_RDWR, "SpiComIF::initializeInterface");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
||||||
return fileHelper.getOpenResult();
|
return fileHelper.getOpenResult();
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
/* Prepare transfer */
|
/* Prepare transfer */
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
UnixFileGuard fileHelper(dev, fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
||||||
return OPENING_FILE_FAILED;
|
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 SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = returnvalue::OK;
|
||||||
int fileDescriptor = 0;
|
int fileDescriptor = 0;
|
||||||
UnixFileGuard fileHelper(dev, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
|
UnixFileGuard fileHelper(dev, fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
|
||||||
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
if (fileHelper.getOpenResult() != returnvalue::OK) {
|
||||||
return OPENING_FILE_FAILED;
|
return OPENING_FILE_FAILED;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user