some renaming and tweaks for linux serial driver

This commit is contained in:
Robin Müller 2022-11-10 17:31:11 +01:00
parent 2a203ae13d
commit 39946bff58
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
11 changed files with 40 additions and 41 deletions

View File

@ -122,6 +122,7 @@ if(UNIX)
option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add Linux peripheral drivers"
OFF)
option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Attempt to add Linux GPIOD drivers" OFF)
option(FSFW_HAL_LINUX_ADD_SERIAL_DRIVERS "Add serial drivers" ON)
endif()
# Optional sources

View File

@ -5,11 +5,14 @@ endif()
target_sources(${LIB_FSFW_NAME} PRIVATE UnixFileGuard.cpp CommandExecutor.cpp
utility.cpp)
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
add_subdirectory(gpio)
endif()
if(FSFW_HAL_LINUX_ADD_SERIAL_DRIVERS)
add_subdirectory(serial)
endif()
if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS)
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
add_subdirectory(gpio)
endif()
add_subdirectory(uart)
# Adding those does not really make sense on Apple systems which are generally
# host systems. It won't even compile as the headers are missing
if(NOT APPLE)

View File

@ -0,0 +1,2 @@
target_sources(${LIB_FSFW_NAME} PUBLIC SerialComIF.cpp SerialCookie.cpp
helper.cpp)

View File

@ -1,7 +1,6 @@
#include "UartComIF.h"
#include <errno.h>
#include <fcntl.h>
#include <fsfw_hal/linux/serial/SerialComIF.h>
#include <termios.h>
#include <unistd.h>
@ -11,11 +10,11 @@
#include "fsfw/serviceinterface.h"
#include "fsfw_hal/linux/utility.h"
UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {}
SerialComIF::SerialComIF(object_id_t objectId) : SystemObject(objectId) {}
UartComIF::~UartComIF() {}
SerialComIF::~SerialComIF() {}
ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
ReturnValue_t SerialComIF::initializeInterface(CookieIF* cookie) {
std::string deviceFile;
if (cookie == nullptr) {
@ -59,7 +58,7 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
return returnvalue::OK;
}
int UartComIF::configureUartPort(UartCookie* uartCookie) {
int SerialComIF::configureUartPort(UartCookie* uartCookie) {
struct termios options = {};
std::string deviceFile = uartCookie->getDeviceFile();
@ -114,7 +113,7 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
return fd;
}
void UartComIF::setStopBitOptions(struct termios* options, UartCookie* uartCookie) {
void SerialComIF::setStopBitOptions(struct termios* options, UartCookie* uartCookie) {
/* Clear stop field. Sets stop bit to one bit */
options->c_cflag &= ~CSTOPB;
switch (uartCookie->getStopBits()) {
@ -126,7 +125,7 @@ void UartComIF::setStopBitOptions(struct termios* options, UartCookie* uartCooki
}
}
void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCookie) {
void SerialComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCookie) {
/* Clear size bits */
options->c_cflag &= ~CSIZE;
switch (uartCookie->getBitsPerWord()) {
@ -150,7 +149,7 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook
}
}
void UartComIF::setFixedOptions(struct termios* options) {
void SerialComIF::setFixedOptions(struct termios* options) {
/* Disable RTS/CTS hardware flow control */
options->c_cflag &= ~CRTSCTS;
/* Turn on READ & ignore ctrl lines (CLOCAL = 1) */
@ -173,7 +172,7 @@ void UartComIF::setFixedOptions(struct termios* options) {
options->c_oflag &= ~ONLCR;
}
ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
ReturnValue_t SerialComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
int fd = 0;
std::string deviceFile;
@ -219,9 +218,9 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData,
return returnvalue::OK;
}
ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; }
ReturnValue_t SerialComIF::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; }
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
ReturnValue_t SerialComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
std::string deviceFile;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
@ -257,8 +256,8 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
}
}
ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceMap::iterator& iter,
size_t requestLen) {
ReturnValue_t SerialComIF::handleCanonicalRead(UartCookie& uartCookie,
UartDeviceMap::iterator& iter, size_t requestLen) {
ReturnValue_t result = returnvalue::OK;
uint8_t maxReadCycles = uartCookie.getReadCycles();
uint8_t currentReadCycles = 0;
@ -315,8 +314,9 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
return result;
}
ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie,
UartDeviceMap::iterator& iter, size_t requestLen) {
ReturnValue_t SerialComIF::handleNoncanonicalRead(UartCookie& uartCookie,
UartDeviceMap::iterator& iter,
size_t requestLen) {
int fd = iter->second.fileDescriptor;
auto bufferPtr = iter->second.replyBuffer.data();
// Size check to prevent buffer overflow
@ -349,7 +349,7 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie,
return returnvalue::OK;
}
ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
ReturnValue_t SerialComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
std::string deviceFile;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
@ -379,7 +379,7 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
return returnvalue::OK;
}
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
ReturnValue_t SerialComIF::flushUartRxBuffer(CookieIF* cookie) {
std::string deviceFile;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) {
@ -398,7 +398,7 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
return returnvalue::FAILED;
}
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
ReturnValue_t SerialComIF::flushUartTxBuffer(CookieIF* cookie) {
std::string deviceFile;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) {
@ -417,7 +417,7 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
return returnvalue::FAILED;
}
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
ReturnValue_t SerialComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
std::string deviceFile;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) {

View File

@ -3,13 +3,12 @@
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw_hal/linux/serial/SerialCookie.h>
#include <fsfw_hal/linux/serial/helper.h>
#include <unordered_map>
#include <vector>
#include "UartCookie.h"
#include "helper.h"
/**
* @brief This is the communication interface to access serial ports on linux based operating
* systems.
@ -19,7 +18,7 @@
*
* @author J. Meier
*/
class UartComIF : public DeviceCommunicationIF, public SystemObject {
class SerialComIF : public DeviceCommunicationIF, public SystemObject {
public:
static constexpr uint8_t uartRetvalId = CLASS_ID::HAL_UART;
@ -27,9 +26,9 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject {
static constexpr ReturnValue_t UART_READ_SIZE_MISSMATCH = returnvalue::makeCode(uartRetvalId, 2);
static constexpr ReturnValue_t UART_RX_BUFFER_TOO_SMALL = returnvalue::makeCode(uartRetvalId, 3);
UartComIF(object_id_t objectId);
SerialComIF(object_id_t objectId);
virtual ~UartComIF();
virtual ~SerialComIF();
ReturnValue_t initializeInterface(CookieIF* cookie) override;
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;

View File

@ -1,6 +1,5 @@
#include "UartCookie.h"
#include <fsfw/serviceinterface.h>
#include <fsfw_hal/linux/serial/SerialCookie.h>
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
size_t maxReplyLen, UartModes uartMode)

View File

@ -3,11 +3,10 @@
#include <fsfw/devicehandlers/CookieIF.h>
#include <fsfw/objectmanager/SystemObjectIF.h>
#include <fsfw_hal/linux/serial/helper.h>
#include <string>
#include "helper.h"
/**
* @brief Cookie for the UartComIF. There are many options available to configure the UART driver.
* The constructor only requests for common options like the baudrate. Other options can

View File

@ -1,5 +1,4 @@
#include "helper.h"
#include <fsfw_hal/linux/serial/helper.h>
#include <sys/ioctl.h>
#include "fsfw/serviceinterface.h"

View File

@ -1 +0,0 @@
target_sources(${LIB_FSFW_NAME} PUBLIC UartComIF.cpp UartCookie.cpp helper.cpp)

View File

@ -36,8 +36,7 @@ TEST_CASE("FixedMap Tests", "[containers]") {
REQUIRE(map.find(5, &ptr) == static_cast<int>(returnvalue::OK));
REQUIRE(*ptr == 6);
REQUIRE(*(map.findValue(6)) == 7);
REQUIRE(map.find(31, &ptr) ==
static_cast<int>(containers::KEY_DOES_NOT_EXIST));
REQUIRE(map.find(31, &ptr) == static_cast<int>(containers::KEY_DOES_NOT_EXIST));
}
REQUIRE(map.getSerializedSize() ==
@ -81,8 +80,7 @@ TEST_CASE("FixedMap Tests", "[containers]") {
REQUIRE(map.insert(37, 38, nullptr) == static_cast<int>(returnvalue::OK));
REQUIRE(map.find(37)->second == 38);
REQUIRE(map.size() == 2);
REQUIRE(map.insert(37, 24, nullptr) ==
static_cast<int>(containers::KEY_ALREADY_EXISTS));
REQUIRE(map.insert(37, 24, nullptr) == static_cast<int>(containers::KEY_ALREADY_EXISTS));
REQUIRE(map.find(37)->second != 24);
REQUIRE(map.size() == 2);
};