adapt to develop

This commit is contained in:
Jakob Meier 2022-02-05 17:12:42 +01:00
parent c0648a789b
commit 018d814f29

View File

@ -7,8 +7,8 @@
#include <cstring> #include <cstring>
#include "OBSWConfig.h" #include "fsfw/FSFW.h"
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface.h"
#include "fsfw_hal/linux/utility.h" #include "fsfw_hal/linux/utility.h"
UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {} UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {}
@ -25,7 +25,9 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl; sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
@ -41,13 +43,17 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0}; UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
auto status = uartDeviceMap.emplace(deviceFile, uartElements); auto status = uartDeviceMap.emplace(deviceFile, uartElements);
if (status.second == false) { if (status.second == false) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
<< "to UART device map" << std::endl; << "to UART device map" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
} else { } else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile
<< " already in use" << std::endl; << " already in use" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -67,15 +73,19 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
int fd = open(deviceFile.c_str(), flags); int fd = open(deviceFile.c_str(), flags);
if (fd < 0) { if (fd < 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile
<< "with error code " << errno << strerror(errno) << std::endl; << "with error code " << errno << strerror(errno) << std::endl;
#endif
return fd; return fd;
} }
/* Read in existing settings */ /* Read in existing settings */
if (tcgetattr(fd, &options) != 0) { if (tcgetattr(fd, &options) != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureUartPort: Error " << errno sif::warning << "UartComIF::configureUartPort: Error " << errno
<< "from tcgetattr: " << strerror(errno) << std::endl; << "from tcgetattr: " << strerror(errno) << std::endl;
#endif
return fd; return fd;
} }
@ -96,8 +106,10 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
/* Save option settings */ /* Save option settings */
if (tcsetattr(fd, TCSANOW, &options) != 0) { if (tcsetattr(fd, TCSANOW, &options) != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << errno sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << errno
<< ": " << strerror(errno); << ": " << strerror(errno);
#endif
return fd; return fd;
} }
return fd; return fd;
@ -149,7 +161,9 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook
options->c_cflag |= CS8; options->c_cflag |= CS8;
break; break;
default: default:
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl; sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl;
#endif
break; break;
} }
} }
@ -300,7 +314,9 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki
cfsetospeed(options, B4000000); cfsetospeed(options, B4000000);
break; break;
default: default:
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl; sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl;
#endif
break; break;
} }
} }
@ -315,29 +331,37 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData,
} }
if (sendData == nullptr) { if (sendData == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl; sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl; sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile); uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if (uartDeviceMapIter == uartDeviceMap.end()) { if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map" sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
<< std::endl; << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
fd = uartDeviceMapIter->second.fileDescriptor; fd = uartDeviceMapIter->second.fileDescriptor;
if (write(fd, sendData, sendLen) != (int)sendLen) { if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
<< ": Error description: " << strerror(errno) << std::endl; << ": Error description: " << strerror(errno) << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -352,7 +376,9 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl; sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
@ -365,8 +391,10 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
} }
if (uartDeviceMapIter == uartDeviceMap.end()) { if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile
<< " not in uart map" << std::endl; << " not in uart map" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -460,8 +488,10 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDevi
return RETURN_FAILED; return RETURN_FAILED;
} else if (bytesRead != static_cast<int>(requestLen)) { } else if (bytesRead != static_cast<int>(requestLen)) {
if (uartCookie.isReplySizeFixed()) { if (uartCookie.isReplySizeFixed()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of " sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of "
<< requestLen << " bytes" << std::endl; << requestLen << " bytes" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
} }
@ -475,15 +505,19 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl; sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile); uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if (uartDeviceMapIter == uartDeviceMap.end()) { if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map" sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
<< std::endl; << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -501,7 +535,9 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl; sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
@ -519,7 +555,9 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl; sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
@ -537,7 +575,9 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl; sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();