#pragma once #include #include #include #include #include "SerialConfig.h" #include "fsfw/returnvalues/returnvalue.h" /** * @brief This is the communication interface to access serial ports on linux based operating * systems. * * @details The implementation follows the instructions from https://blog.mbedded.ninja/programming/ * operating-systems/linux/linux-serial-ports-using-c-cpp/#disabling-canonical-mode * * @author J. Meier */ class SerialCommunicationHelper { public: SerialCommunicationHelper(SerialConfig serialCfg); ReturnValue_t send(const uint8_t* data, size_t dataLen); int rawFd() const; ReturnValue_t initialize(); /** * @brief This function discards all data received but not read in the UART buffer. */ ReturnValue_t flushUartRxBuffer(); /** * @brief This function discards all data in the transmit buffer of the UART driver. */ ReturnValue_t flushUartTxBuffer(); /** * @brief This function discards both data in the transmit and receive buffer of the UART. */ ReturnValue_t flushUartTxAndRxBuf(); private: SerialConfig cfg; int fd = 0; /** * @brief This function opens and configures a uart device by using the information stored * in the uart cookie. * @param uartCookie Pointer to uart cookie with information about the uart. Contains the * uart device file, baudrate, parity, stopbits etc. * @return The file descriptor of the configured uart. */ int configureUartPort(); void setStopBitOptions(struct termios* options); /** * @brief This function sets options which are not configurable by the uartCookie. */ void setFixedOptions(struct termios* options); /** * @brief With this function the datasize settings are added to the termios options struct. */ void setDatasizeOptions(struct termios* options); };