UART ComIF update #11

Merged
meierj merged 10 commits from mueller/master into master 2021-06-21 16:58:32 +02:00
2 changed files with 63 additions and 67 deletions
Showing only changes of commit ab01c22b60 - Show all commits

View File

@ -302,7 +302,6 @@ ReturnValue_t UartComIF::getSendSuccess(CookieIF *cookie) {
} }
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) { ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
int fd = 0;
std::string deviceFile; std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
@ -394,11 +393,11 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
if(requestLen > uartCookie.getMaxReplyLen()) { if(requestLen > uartCookie.getMaxReplyLen()) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!" sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
<< std::endl; << std::endl;
#else #else
sif::printWarning("UartComIF::requestReceiveMessage: " sif::printWarning("UartComIF::requestReceiveMessage: "
"Next read would cause overflow!"); "Next read would cause overflow!");
#endif #endif
#endif #endif
return UART_RX_BUFFER_TOO_SMALL; return UART_RX_BUFFER_TOO_SMALL;

View File

@ -1,14 +1,13 @@
#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_ #ifndef BSP_Q7S_COMIF_UARTCOMIF_H_
#define BSP_Q7S_COMIF_UARTCOMIF_H_ #define BSP_Q7S_COMIF_UARTCOMIF_H_
#include "UartCookie.h"
#include <fsfw/objectmanager/SystemObject.h> #include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/devicehandlers/DeviceCommunicationIF.h> #include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "UartCookie.h"
/** /**
* @brief This is the communication interface to access serial ports on linux based operating * @brief This is the communication interface to access serial ports on linux based operating
* systems. * systems.
@ -29,82 +28,80 @@ public:
static constexpr ReturnValue_t UART_RX_BUFFER_TOO_SMALL = static constexpr ReturnValue_t UART_RX_BUFFER_TOO_SMALL =
HasReturnvaluesIF::makeReturnCode(uartRetvalId, 3); HasReturnvaluesIF::makeReturnCode(uartRetvalId, 3);
static constexpr uint8_t uartSubsystemId = SUBSYSTEM_ID::HAL_UART; UartComIF(object_id_t objectId);
UartComIF(object_id_t objectId); virtual ~UartComIF();
virtual ~UartComIF(); ReturnValue_t initializeInterface(CookieIF * cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
ReturnValue_t initializeInterface(CookieIF * cookie) override; size_t sendLen) override;
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData, ReturnValue_t getSendSuccess(CookieIF *cookie) override;
size_t sendLen) override; ReturnValue_t requestReceiveMessage(CookieIF *cookie,
ReturnValue_t getSendSuccess(CookieIF *cookie) override; size_t requestLen) override;
ReturnValue_t requestReceiveMessage(CookieIF *cookie, ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t requestLen) override; size_t *size) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override;
private: private:
using UartDeviceFile_t = std::string; using UartDeviceFile_t = std::string;
struct UartElements { struct UartElements {
int fileDescriptor; int fileDescriptor;
std::vector<uint8_t> replyBuffer; std::vector<uint8_t> replyBuffer;
/** Number of bytes read will be written to this variable */ /** Number of bytes read will be written to this variable */
size_t replyLen; size_t replyLen;
}; };
using UartDeviceMap = std::unordered_map<UartDeviceFile_t, UartElements>; using UartDeviceMap = std::unordered_map<UartDeviceFile_t, UartElements>;
using UartDeviceMapIter = UartDeviceMap::iterator; using UartDeviceMapIter = UartDeviceMap::iterator;
/** /**
* The uart devie map stores informations of initialized uart ports. * The uart devie map stores informations of initialized uart ports.
*/ */
UartDeviceMap uartDeviceMap; UartDeviceMap uartDeviceMap;
/** /**
* @brief This function opens and configures a uart device by using the information stored * @brief This function opens and configures a uart device by using the information stored
* in the uart cookie. * in the uart cookie.
* @param uartCookie Pointer to uart cookie with information about the uart. Contains the * @param uartCookie Pointer to uart cookie with information about the uart. Contains the
* uart device file, baudrate, parity, stopbits etc. * uart device file, baudrate, parity, stopbits etc.
* @return The file descriptor of the configured uart. * @return The file descriptor of the configured uart.
*/ */
int configureUartPort(UartCookie* uartCookie); int configureUartPort(UartCookie* uartCookie);
/** /**
* @brief This function adds the parity settings to the termios options struct. * @brief This function adds the parity settings to the termios options struct.
* *
* @param options Pointer to termios options struct which will be modified to enable or disable * @param options Pointer to termios options struct which will be modified to enable or disable
* parity checking. * parity checking.
* @param uartCookie Pointer to uart cookie containing the information about the desired * @param uartCookie Pointer to uart cookie containing the information about the desired
* parity settings. * parity settings.
* *
*/ */
void setParityOptions(struct termios* options, UartCookie* uartCookie); void setParityOptions(struct termios* options, UartCookie* uartCookie);
void setStopBitOptions(struct termios* options, UartCookie* uartCookie); void setStopBitOptions(struct termios* options, UartCookie* uartCookie);
/** /**
* @brief This function sets options which are not configurable by the uartCookie. * @brief This function sets options which are not configurable by the uartCookie.
*/ */
void setFixedOptions(struct termios* options); void setFixedOptions(struct termios* options);
/** /**
* @brief With this function the datasize settings are added to the termios options struct. * @brief With this function the datasize settings are added to the termios options struct.
*/ */
void setDatasizeOptions(struct termios* options, UartCookie* uartCookie); void setDatasizeOptions(struct termios* options, UartCookie* uartCookie);
/** /**
* @brief This functions adds the baudrate specified in the uartCookie to the termios options * @brief This functions adds the baudrate specified in the uartCookie to the termios options
* struct. * struct.
*/ */
void configureBaudrate(struct termios* options, UartCookie* uartCookie); void configureBaudrate(struct termios* options, UartCookie* uartCookie);
void setUartMode(struct termios* options, UartCookie& uartCookie); void setUartMode(struct termios* options, UartCookie& uartCookie);
ReturnValue_t handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, ReturnValue_t handleCanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
size_t requestLen); size_t requestLen);
ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter, ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
size_t requestLen); size_t requestLen);