Compare commits
87 Commits
v1.3.0
...
a8167f5431
Author | SHA1 | Date | |
---|---|---|---|
a8167f5431 | |||
41f3d7cf9a | |||
e6e1936293 | |||
15f35f200a | |||
6b20bb197a | |||
215d01b3ca | |||
dfe49cc1e5 | |||
73eb11f4f1 | |||
0a56441510 | |||
e226f19ca8 | |||
7bf66dc401 | |||
a6d744c9c8 | |||
924c150af2 | |||
469eba3ce2 | |||
fd2916af11 | |||
afd375a7f8 | |||
5454169e20 | |||
7d0377845b | |||
882da68a2f | |||
b6aebb3061 | |||
04a1fe7f10 | |||
845c00044e | |||
5f79f987ae | |||
1183e5739d | |||
e3697d6d8c | |||
406b77ea81 | |||
92d3f0743b | |||
a18706ec53 | |||
8a9eb27458 | |||
1ac372cb89 | |||
fb36dc4501 | |||
ba5e2ad8bb | |||
5a6c81130d | |||
d92a796705 | |||
1fa59c5cae | |||
83b5ade6b7 | |||
62873c3118 | |||
1301988892 | |||
1c3770ce96 | |||
22e29144b6 | |||
52bff3985f | |||
133820f463 | |||
8d3fceea8f | |||
90a1571707 | |||
2706b8fa24 | |||
3704d2b829 | |||
6073abb12d | |||
47bec654a0 | |||
b2c102b2c1 | |||
4202205182 | |||
c8472beb5f | |||
8b39248a33 | |||
ec00a84b29 | |||
1a4a85ceb2 | |||
7922bf76da | |||
bb88490cc6 | |||
296c587e3d | |||
4d9c07a1ec | |||
c3fbe04fc6 | |||
466f1e000f | |||
f1f167c2d1 | |||
6f816b2592 | |||
0e5cfcf28f | |||
dee063e259 | |||
aabc729e77 | |||
c0591c3d24 | |||
0ff81294e7 | |||
b6e243b8b3 | |||
5bbe16081f | |||
490ab440e5 | |||
0b207b2b1a | |||
e1f92b3da4 | |||
b75c815361 | |||
a94725c423 | |||
2d667cfb95 | |||
3d80d5d036 | |||
ebc9d99022 | |||
2489276350 | |||
3895806a2b | |||
3bbcc42d39 | |||
fc4324a2fa | |||
7b500eb0ed | |||
54c028f913 | |||
1f6a5e635f | |||
a918c672a5 | |||
1515d59432 | |||
5e960f118f |
@ -10,6 +10,8 @@ endif()
|
||||
option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
|
||||
# Options to exclude parts of the FSFW from compilation.
|
||||
option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON)
|
||||
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
|
||||
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
|
||||
|
||||
# Optional sources
|
||||
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
|
||||
@ -21,7 +23,7 @@ option(FSFW_ADD_COORDINATES "Compile with coordinate components" OFF)
|
||||
option(FSFW_ADD_TMSTORAGE "Compile with tm storage components" OFF)
|
||||
|
||||
# Contrib sources
|
||||
option(FSFW_ADD_SPG4_PROPAGATOR "Add SPG4 propagator code" OFF)
|
||||
option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
|
||||
|
||||
set(LIB_FSFW_NAME fsfw)
|
||||
add_library(${LIB_FSFW_NAME})
|
||||
@ -94,7 +96,9 @@ message(STATUS "Compiling FSFW for the ${OS_FSFW_NAME} operating system.")
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(hal)
|
||||
if(FSFW_ADD_HAL)
|
||||
add_subdirectory(hal)
|
||||
endif()
|
||||
add_subdirectory(contrib)
|
||||
|
||||
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
||||
|
@ -1,4 +1,4 @@
|
||||

|
||||

|
||||
|
||||
# Flight Software Framework (FSFW)
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
if(FSFW_ADD_SPG4_PROPAGATOR)
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
sgp4/sgp4unit.cpp
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgp4
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgp4
|
||||
)
|
||||
endif()
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_subdirectory(fsfw_contrib)
|
||||
|
11
contrib/fsfw_contrib/CMakeLists.txt
Normal file
11
contrib/fsfw_contrib/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
if(FSFW_ADD_SGP4_PROPAGATOR)
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
sgp4/sgp4unit.cpp
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgp4
|
||||
)
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgp4
|
||||
)
|
||||
endif()
|
@ -6,4 +6,4 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_subdirectory(fsfw)
|
||||
add_subdirectory(fsfw_hal)
|
||||
|
@ -1 +0,0 @@
|
||||
add_subdirectory(hal)
|
@ -1,4 +1,4 @@
|
||||
#include "fsfw/hal/common/gpio/GpioCookie.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
GpioCookie::GpioCookie() {
|
@ -1,4 +1,4 @@
|
||||
#include "fsfw/hal/devicehandlers/GyroL3GD20Handler.h"
|
||||
#include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
@ -1,14 +1,14 @@
|
||||
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "devicedefinitions/GyroL3GD20Definitions.h"
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
||||
|
||||
#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG
|
||||
#define FSFW_HAL_L3GD20_GYRO_DEBUG 1
|
||||
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
|
||||
#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */
|
||||
|
||||
/**
|
@ -1,4 +1,9 @@
|
||||
#include "fsfw/hal/linux/UnixFileGuard.h"
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
||||
std::string diagnosticPrefix):
|
||||
@ -10,12 +15,11 @@ UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
||||
if (*fileDescriptor < 0) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << diagnosticPrefix <<"Opening device failed with error code " << errno <<
|
||||
"." << std::endl;
|
||||
sif::warning << "Error description: " << strerror(errno) << std::endl;
|
||||
sif::warning << diagnosticPrefix << ": Opening device failed with error code " <<
|
||||
errno << ": " << strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printError("%sOpening device failed with error code %d.\n", diagnosticPrefix);
|
||||
sif::printWarning("Error description: %s\n", strerror(errno));
|
||||
sif::printWarning("%s: Opening device failed with error code %d: %s\n",
|
||||
diagnosticPrefix, errno, strerror(errno));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
openStatus = OPEN_FILE_FAILED;
|
@ -1,6 +1,6 @@
|
||||
#include "fsfw/hal/linux/gpio/LinuxLibgpioIF.h"
|
||||
#include "fsfw/hal/common/gpio/gpioDefinitions.h"
|
||||
#include "fsfw/hal/common/gpio/GpioCookie.h"
|
||||
#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h"
|
||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fsfw/hal/linux/i2c/I2cComIF.h"
|
||||
#include "fsfw/hal/linux/utility.h"
|
||||
#include "fsfw/hal/linux/UnixFileGuard.h"
|
||||
#include "fsfw_hal/linux/i2c/I2cComIF.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#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_) :
|
@ -1,7 +1,7 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
|
||||
#include "fsfw/hal/linux/rpi/GpioRPi.h"
|
||||
#include "fsfw/hal/common/gpio/GpioCookie.h"
|
||||
#include "fsfw_hal/linux/rpi/GpioRPi.h"
|
||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/hal/linux/spi/SpiComIF.h"
|
||||
#include "fsfw/hal/linux/spi/SpiCookie.h"
|
||||
#include "fsfw/hal/linux/utility.h"
|
||||
#include "fsfw/hal/linux/UnixFileGuard.h"
|
||||
#include "fsfw_hal/linux/spi/SpiComIF.h"
|
||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
#include "fsfw_hal/linux/UnixFileGuard.h"
|
||||
|
||||
#include <fsfw/ipc/MutexFactory.h>
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
@ -15,11 +15,6 @@
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
/* Can be used for low-level debugging of the SPI bus */
|
||||
#ifndef FSFW_HAL_LINUX_SPI_WIRETAPPING
|
||||
#define FSFW_HAL_LINUX_SPI_WIRETAPPING 0
|
||||
#endif
|
||||
|
||||
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
|
||||
SystemObject(objectId), gpioComIF(gpioComIF) {
|
||||
if(gpioComIF == nullptr) {
|
||||
@ -82,7 +77,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
gpioComIF->pullHigh(gpioId);
|
||||
}
|
||||
|
||||
size_t spiSpeed = 0;
|
||||
uint32_t spiSpeed = 0;
|
||||
spi::SpiModes spiMode = spi::SpiModes::MODE_0;
|
||||
|
||||
SpiCookie::UncommonParameters params;
|
||||
@ -90,7 +85,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
|
||||
int fileDescriptor = 0;
|
||||
UnixFileGuard fileHelper(spiCookie->getSpiDevice(), &fileDescriptor, O_RDWR,
|
||||
"SpiComIF::initializeInterface: ");
|
||||
"SpiComIF::initializeInterface");
|
||||
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return fileHelper.getOpenResult();
|
||||
}
|
||||
@ -184,7 +179,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
||||
/* Prepare transfer */
|
||||
int fileDescriptor = 0;
|
||||
std::string device = spiCookie->getSpiDevice();
|
||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage: ");
|
||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
||||
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return OPENING_FILE_FAILED;
|
||||
}
|
||||
@ -273,7 +268,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
|
||||
std::string device = spiCookie->getSpiDevice();
|
||||
int fileDescriptor = 0;
|
||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
|
||||
"SpiComIF::requestReceiveMessage: ");
|
||||
"SpiComIF::requestReceiveMessage");
|
||||
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return OPENING_FILE_FAILED;
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
#ifndef LINUX_SPI_SPICOMIF_H_
|
||||
#define LINUX_SPI_SPICOMIF_H_
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "spiDefinitions.h"
|
||||
#include "returnvalues/classIds.h"
|
||||
#include "fsfw/hal/common/gpio/GpioIF.h"
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
@ -1,4 +1,4 @@
|
||||
#include "fsfw/hal/linux/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||
|
||||
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
|
||||
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed):
|
@ -1,6 +1,7 @@
|
||||
#include "fsfw/hal/linux/uart/UartComIF.h"
|
||||
#include "UartComIF.h"
|
||||
#include "OBSWConfig.h"
|
||||
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
@ -60,7 +61,13 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
|
||||
struct termios options = {};
|
||||
|
||||
std::string deviceFile = uartCookie->getDeviceFile();
|
||||
int fd = open(deviceFile.c_str(), O_RDWR);
|
||||
int flags = O_RDWR;
|
||||
if(uartCookie->getUartMode() == UartModes::CANONICAL) {
|
||||
// In non-canonical mode, don't specify O_NONBLOCK because these properties will be
|
||||
// controlled by the VTIME and VMIN parameters and O_NONBLOCK would override this
|
||||
flags |= O_NONBLOCK;
|
||||
}
|
||||
int fd = open(deviceFile.c_str(), flags);
|
||||
|
||||
if (fd < 0) {
|
||||
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile <<
|
||||
@ -259,23 +266,22 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki
|
||||
|
||||
ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
|
||||
const uint8_t *sendData, size_t sendLen) {
|
||||
|
||||
int fd = 0;
|
||||
std::string deviceFile;
|
||||
UartDeviceMapIter uartDeviceMapIter;
|
||||
|
||||
if(sendData == nullptr) {
|
||||
sif::debug << "UartComIF::sendMessage: Send Data is nullptr" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(sendLen == 0) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
if(sendData == nullptr) {
|
||||
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
|
||||
if(uartCookie == nullptr) {
|
||||
sif::debug << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
|
||||
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
@ -347,12 +353,13 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
||||
size_t maxReplySize = uartCookie.getMaxReplyLen();
|
||||
int fd = iter->second.fileDescriptor;
|
||||
auto bufferPtr = iter->second.replyBuffer.data();
|
||||
iter->second.replyLen = 0;
|
||||
do {
|
||||
size_t allowedReadSize = 0;
|
||||
if(currentBytesRead >= maxReplySize) {
|
||||
// Overflow risk. Emit warning, trigger event and break. If this happens,
|
||||
// the reception buffer is not large enough or data is not polled often enough.
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
|
||||
<< std::endl;
|
||||
@ -370,7 +377,20 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
|
||||
|
||||
bytesRead = read(fd, bufferPtr, allowedReadSize);
|
||||
if (bytesRead < 0) {
|
||||
return RETURN_FAILED;
|
||||
// EAGAIN: No data available in non-blocking mode
|
||||
if(errno != EAGAIN) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" <<
|
||||
errno << ": " << strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n",
|
||||
errno, strerror(errno));
|
||||
#endif
|
||||
#endif
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
else if(bytesRead > 0) {
|
||||
iter->second.replyLen += bytesRead;
|
||||
@ -453,9 +473,12 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCIFLUSH);
|
||||
return RETURN_OK;
|
||||
if(uartDeviceMapIter != uartDeviceMap.end()) {
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCIFLUSH);
|
||||
return RETURN_OK;
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
|
||||
@ -468,9 +491,12 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCOFLUSH);
|
||||
return RETURN_OK;
|
||||
if(uartDeviceMapIter != uartDeviceMap.end()) {
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCOFLUSH);
|
||||
return RETURN_OK;
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
|
||||
@ -483,9 +509,12 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
|
||||
}
|
||||
deviceFile = uartCookie->getDeviceFile();
|
||||
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
return RETURN_OK;
|
||||
if(uartDeviceMapIter != uartDeviceMap.end()) {
|
||||
int fd = uartDeviceMapIter->second.fileDescriptor;
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
return RETURN_OK;
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {
|
@ -1,11 +1,11 @@
|
||||
#include "fsfw/hal/linux/uart/UartCookie.h"
|
||||
#include "fsfw_hal/linux/uart/UartCookie.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
|
||||
uint32_t baudrate, size_t maxReplyLen):
|
||||
handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), baudrate(baudrate),
|
||||
maxReplyLen(maxReplyLen) {
|
||||
handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode),
|
||||
baudrate(baudrate), maxReplyLen(maxReplyLen) {
|
||||
}
|
||||
|
||||
UartCookie::~UartCookie() {}
|
@ -1,6 +1,6 @@
|
||||
#include "fsfw/FSFW.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw/hal/linux/utility.h"
|
||||
#include "fsfw_hal/linux/utility.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
@ -1,10 +1,10 @@
|
||||
#include "fsfw/hal/stm32h7/devicetest/GyroL3GD20H.h"
|
||||
#include "fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h"
|
||||
|
||||
#include "fsfw/hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw/hal/stm32h7/spi/stm32h743ziSpi.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h"
|
||||
|
||||
#include "fsfw/tasks/TaskFactory.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
@ -1,4 +1,4 @@
|
||||
#include <fsfw/hal/stm32h7/dma.h>
|
||||
#include <fsfw_hal/stm32h7/dma.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
@ -1,4 +1,4 @@
|
||||
#include "fsfw/hal/stm32h7/gpio/gpio.h"
|
||||
#include "fsfw_hal/stm32h7/gpio/gpio.h"
|
||||
|
||||
#include "stm32h7xx_hal_rcc.h"
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include "fsfw/hal/stm32h7/spi/SpiComIF.h"
|
||||
#include "fsfw/hal/stm32h7/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/stm32h7/spi/SpiComIF.h"
|
||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||
|
||||
#include "fsfw/tasks/SemaphoreFactory.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw/hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw/hal/stm32h7/gpio/gpio.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/gpio/gpio.h"
|
||||
|
||||
// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete
|
||||
// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently
|
@ -5,7 +5,7 @@
|
||||
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
|
||||
#include "fsfw/hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
#include "stm32h743xx.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "fsfw/hal/stm32h7/spi/SpiCookie.h"
|
||||
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
|
||||
|
||||
|
||||
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
@ -1,7 +1,7 @@
|
||||
#include "fsfw/hal/stm32h7/dma.h"
|
||||
#include "fsfw/hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/dma.h"
|
||||
#include "fsfw_hal/stm32h7/spi/mspInit.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
|
||||
#include "stm32h743xx.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
@ -1,5 +1,5 @@
|
||||
#include "fsfw/hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FSFW_HAL_STM32H7_SPI_SPICORE_H_
|
||||
#define FSFW_HAL_STM32H7_SPI_SPICORE_H_
|
||||
|
||||
#include "fsfw/hal/stm32h7/dma.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/dma.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
@ -1,4 +1,4 @@
|
||||
#include "fsfw/hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
|
||||
void spi::assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle) {
|
||||
switch(spiMode) {
|
@ -1,5 +1,5 @@
|
||||
#include "fsfw/hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
@ -1,6 +1,6 @@
|
||||
#include "fsfw/hal/stm32h7/spi/stm32h743ziSpi.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw/hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_rcc.h"
|
@ -4,7 +4,7 @@
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <fsfw/events/EventManager.h>
|
||||
#include <fsfw/health/HealthTable.h>
|
||||
#include <fsfw/tmtcpacket/pus/TmPacketStored.h>
|
||||
#include <fsfw/tmtcpacket/pus/tm/TmPacketStored.h>
|
||||
#include <fsfw/tmtcservices/CommandingServiceBase.h>
|
||||
#include <fsfw/tmtcservices/PusServiceBase.h>
|
||||
#include <fsfw/internalError/InternalErrorReporter.h>
|
||||
|
@ -9,5 +9,19 @@
|
||||
#cmakedefine FSFW_ADD_COORDINATES
|
||||
#cmakedefine FSFW_ADD_PUS
|
||||
#cmakedefine FSFW_ADD_MONITORING
|
||||
#cmakedefine FSFW_ADD_SGP4_PROPAGATOR
|
||||
|
||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
/* Can be used for low-level debugging of the SPI bus */
|
||||
#ifndef FSFW_HAL_LINUX_SPI_WIRETAPPING
|
||||
#define FSFW_HAL_LINUX_SPI_WIRETAPPING 0
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG
|
||||
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
|
||||
#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */
|
||||
|
||||
#endif /* FSFW_FSFW_H_ */
|
||||
|
@ -7,7 +7,7 @@
|
||||
#ifndef PLATFORM_WIN
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "fsfw/contrib/sgp4/sgp4unit.h"
|
||||
#include "fsfw_contrib/sgp4/sgp4unit.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class Sgp4Propagator {
|
||||
|
@ -8,4 +8,9 @@
|
||||
not enabled with FSFW_ADD_COORDINATES
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_ADD_SGP4_PROPAGATOR
|
||||
#warning Coordinates files were included but SGP4 contributed code compilation was \
|
||||
not enabled with FSFW_ADD_SGP4_PROPAGATOR
|
||||
#endif
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_COORDINATES_COORDINATESCONF_H_ */
|
||||
|
@ -85,9 +85,10 @@ public:
|
||||
* Called by DHB in the GET_WRITE doGetWrite().
|
||||
* Get send confirmation that the data in sendMessage() was sent successfully.
|
||||
* @param cookie
|
||||
* @return - @c RETURN_OK if data was sent successfull
|
||||
* - Everything else triggers falure event with
|
||||
* returnvalue as parameter 1
|
||||
* @return
|
||||
* - @c RETURN_OK if data was sent successfully but a reply is expected
|
||||
* - NO_REPLY_EXPECTED if data was sent successfully and no reply is expected
|
||||
* - Everything else to indicate failure
|
||||
*/
|
||||
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
|
||||
|
||||
|
@ -430,7 +430,12 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
|
||||
DeviceReplyInfo info;
|
||||
info.maxDelayCycles = maxDelayCycles;
|
||||
info.periodic = periodic;
|
||||
info.delayCycles = 0;
|
||||
if(info.periodic) {
|
||||
info.delayCycles = info.maxDelayCycles;
|
||||
}
|
||||
else {
|
||||
info.delayCycles = 0;
|
||||
}
|
||||
info.replyLen = replyLen;
|
||||
info.dataSet = dataSet;
|
||||
info.command = deviceCommandMap.end();
|
||||
@ -648,11 +653,12 @@ void DeviceHandlerBase::doGetWrite() {
|
||||
replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true);
|
||||
}
|
||||
|
||||
//We need to distinguish here, because a raw command never expects a reply.
|
||||
//(Could be done in eRIRM, but then child implementations need to be careful.
|
||||
// We need to distinguish here, because a raw command never expects a reply.
|
||||
// This could be done in the #enableReplyInReplyMap call,
|
||||
// but then child implementations would need to be careful.
|
||||
result = enableReplyInReplyMap(cookieInfo.pendingCommand);
|
||||
} else {
|
||||
//always generate a failure event, so that FDIR knows what's up
|
||||
} else if (result != NO_REPLY_EXPECTED) {
|
||||
// always generate a failure event, so that FDIR knows what's up
|
||||
triggerEvent(DEVICE_SENDING_COMMAND_FAILED, result,
|
||||
cookieInfo.pendingCommand->first);
|
||||
}
|
||||
@ -1336,10 +1342,20 @@ void DeviceHandlerBase::buildInternalCommand(void) {
|
||||
DeviceCommandMap::iterator iter = deviceCommandMap.find(
|
||||
deviceCommandId);
|
||||
if (iter == deviceCommandMap.end()) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
char output[36];
|
||||
sprintf(output, "Command 0x%08x unknown",
|
||||
static_cast<unsigned int>(deviceCommandId));
|
||||
// so we can track misconfigurations
|
||||
printWarningOrError(sif::OutputTypes::OUT_WARNING,
|
||||
"buildInternalCommand",
|
||||
COMMAND_NOT_SUPPORTED,
|
||||
output);
|
||||
#endif
|
||||
result = COMMAND_NOT_SUPPORTED;
|
||||
}
|
||||
else if (iter->second.isExecuting) {
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
char output[36];
|
||||
sprintf(output, "Command 0x%08x is executing",
|
||||
static_cast<unsigned int>(deviceCommandId));
|
||||
@ -1550,10 +1566,18 @@ LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() {
|
||||
return &poolManager;
|
||||
}
|
||||
|
||||
MessageQueueId_t DeviceHandlerBase::getCommanderId(DeviceCommandId_t replyId) const {
|
||||
MessageQueueId_t DeviceHandlerBase::getCommanderQueueId(DeviceCommandId_t replyId) const {
|
||||
auto commandIter = deviceCommandMap.find(replyId);
|
||||
if(commandIter == deviceCommandMap.end()) {
|
||||
return MessageQueueIF::NO_QUEUE;
|
||||
}
|
||||
return commandIter->second.sendReplyTo;
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::finishCommandExecution(DeviceCommandId_t replyId) {
|
||||
auto commandIter = deviceCommandMap.find(replyId);
|
||||
if(commandIter == deviceCommandMap.end()) {
|
||||
return;
|
||||
}
|
||||
commandIter->second.isExecuting = false;
|
||||
}
|
||||
|
@ -327,15 +327,20 @@ protected:
|
||||
* The existence of the command in the command map and the command size check against 0 are
|
||||
* done by the base class.
|
||||
*
|
||||
* The base class will generate a finish reply or a step automatically as long as the
|
||||
* send success is confirmed in the #getSendSuccess function call of the communication
|
||||
* interface. NO_REPLY_EXPECTED should be returned for a finish reply, RETURN_OK should be
|
||||
* returned for a step reply and everything else will trigger a step failure.
|
||||
*
|
||||
* If the commander ID is required for generating a finish reply immediately, it can be
|
||||
* retrieved using the #getCommanderQueueId function.
|
||||
*
|
||||
* @param deviceCommand The command to build, already checked against deviceCommandMap
|
||||
* @param commandData Pointer to the data from the direct command
|
||||
* @param commandDataLen Length of commandData
|
||||
* @return
|
||||
* - @c RETURN_OK to send command after #rawPacket and #rawPacketLen
|
||||
* have been set.
|
||||
* - @c HasActionsIF::EXECUTION_COMPLETE to generate a finish reply immediately. This can
|
||||
* be used if no reply is expected. Otherwise, the developer can call #actionHelper.finish
|
||||
* to finish the command handling.
|
||||
* - Anything else triggers an event with the return code as a parameter as well as a
|
||||
* step reply failed with the return code
|
||||
*/
|
||||
@ -399,7 +404,9 @@ protected:
|
||||
*/
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) = 0;
|
||||
MessageQueueId_t getCommanderId(DeviceCommandId_t replyId) const;
|
||||
MessageQueueId_t getCommanderQueueId(DeviceCommandId_t replyId) const;
|
||||
void finishCommandExecution(DeviceCommandId_t replyId);
|
||||
|
||||
/**
|
||||
* Helper function to get pending command. This is useful for devices
|
||||
* like SPI sensors to identify the last sent command.
|
||||
|
@ -120,7 +120,8 @@ public:
|
||||
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
|
||||
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6);
|
||||
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7);
|
||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command.
|
||||
//!< Used to indicate that this is a command-only command.
|
||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8);
|
||||
static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9);
|
||||
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA);
|
||||
|
||||
|
@ -12,119 +12,119 @@ MessageQueueId_t EventManagerIF::eventmanagerQueue = MessageQueueIF::NO_QUEUE;
|
||||
// So a good guess is 75 to a max of 100 pools required for each, which fits well.
|
||||
const LocalPool::LocalPoolConfig EventManager::poolConfig = {
|
||||
{fsfwconfig::FSFW_EVENTMGMR_MATCHTREE_NODES,
|
||||
sizeof(EventMatchTree::Node)},
|
||||
sizeof(EventMatchTree::Node)},
|
||||
{fsfwconfig::FSFW_EVENTMGMT_EVENTIDMATCHERS,
|
||||
sizeof(EventIdRangeMatcher)},
|
||||
sizeof(EventIdRangeMatcher)},
|
||||
{fsfwconfig::FSFW_EVENTMGMR_RANGEMATCHERS,
|
||||
sizeof(ReporterRangeMatcher)}
|
||||
sizeof(ReporterRangeMatcher)}
|
||||
};
|
||||
|
||||
EventManager::EventManager(object_id_t setObjectId) :
|
||||
SystemObject(setObjectId),
|
||||
factoryBackend(0, poolConfig, false, true) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
||||
SystemObject(setObjectId),
|
||||
factoryBackend(0, poolConfig, false, true) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
EventManager::~EventManager() {
|
||||
QueueFactory::instance()->deleteMessageQueue(eventReportQueue);
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
QueueFactory::instance()->deleteMessageQueue(eventReportQueue);
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
}
|
||||
|
||||
MessageQueueId_t EventManager::getEventReportQueue() {
|
||||
return eventReportQueue->getId();
|
||||
return eventReportQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::performOperation(uint8_t opCode) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
EventMessage message;
|
||||
result = eventReportQueue->receiveMessage(&message);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
EventMessage message;
|
||||
result = eventReportQueue->receiveMessage(&message);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_OBJ_EVENT_TRANSLATION == 1
|
||||
printEvent(&message);
|
||||
printEvent(&message);
|
||||
#endif
|
||||
notifyListeners(&message);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
notifyListeners(&message);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void EventManager::notifyListeners(EventMessage* message) {
|
||||
lockMutex();
|
||||
for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) {
|
||||
if (iter->second.match(message)) {
|
||||
MessageQueueSenderIF::sendMessage(iter->first, message,
|
||||
message->getSender());
|
||||
}
|
||||
}
|
||||
unlockMutex();
|
||||
lockMutex();
|
||||
for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) {
|
||||
if (iter->second.match(message)) {
|
||||
MessageQueueSenderIF::sendMessage(iter->first, message,
|
||||
message->getSender());
|
||||
}
|
||||
}
|
||||
unlockMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::registerListener(MessageQueueId_t listener,
|
||||
bool forwardAllButSelected) {
|
||||
auto result = listenerList.insert(
|
||||
std::pair<MessageQueueId_t, EventMatchTree>(listener,
|
||||
EventMatchTree(&factoryBackend, forwardAllButSelected)));
|
||||
if (!result.second) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
auto result = listenerList.insert(
|
||||
std::pair<MessageQueueId_t, EventMatchTree>(listener,
|
||||
EventMatchTree(&factoryBackend, forwardAllButSelected)));
|
||||
if (!result.second) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::subscribeToEvent(MessageQueueId_t listener,
|
||||
EventId_t event) {
|
||||
return subscribeToEventRange(listener, event);
|
||||
EventId_t event) {
|
||||
return subscribeToEventRange(listener, event);
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::subscribeToAllEventsFrom(MessageQueueId_t listener,
|
||||
object_id_t object) {
|
||||
return subscribeToEventRange(listener, 0, 0, true, object);
|
||||
object_id_t object) {
|
||||
return subscribeToEventRange(listener, 0, 0, true, object);
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::subscribeToEventRange(MessageQueueId_t listener,
|
||||
EventId_t idFrom, EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
auto iter = listenerList.find(listener);
|
||||
if (iter == listenerList.end()) {
|
||||
return LISTENER_NOT_FOUND;
|
||||
}
|
||||
lockMutex();
|
||||
ReturnValue_t result = iter->second.addMatch(idFrom, idTo, idInverted,
|
||||
reporterFrom, reporterTo, reporterInverted);
|
||||
unlockMutex();
|
||||
return result;
|
||||
EventId_t idFrom, EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
auto iter = listenerList.find(listener);
|
||||
if (iter == listenerList.end()) {
|
||||
return LISTENER_NOT_FOUND;
|
||||
}
|
||||
lockMutex();
|
||||
ReturnValue_t result = iter->second.addMatch(idFrom, idTo, idInverted,
|
||||
reporterFrom, reporterTo, reporterInverted);
|
||||
unlockMutex();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
|
||||
EventId_t idFrom, EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
auto iter = listenerList.find(listener);
|
||||
if (iter == listenerList.end()) {
|
||||
return LISTENER_NOT_FOUND;
|
||||
}
|
||||
lockMutex();
|
||||
ReturnValue_t result = iter->second.removeMatch(idFrom, idTo, idInverted,
|
||||
reporterFrom, reporterTo, reporterInverted);
|
||||
unlockMutex();
|
||||
return result;
|
||||
EventId_t idFrom, EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
auto iter = listenerList.find(listener);
|
||||
if (iter == listenerList.end()) {
|
||||
return LISTENER_NOT_FOUND;
|
||||
}
|
||||
lockMutex();
|
||||
ReturnValue_t result = iter->second.removeMatch(idFrom, idTo, idInverted,
|
||||
reporterFrom, reporterTo, reporterInverted);
|
||||
unlockMutex();
|
||||
return result;
|
||||
}
|
||||
|
||||
void EventManager::lockMutex() {
|
||||
mutex->lockMutex(timeoutType, timeoutMs);
|
||||
mutex->lockMutex(timeoutType, timeoutMs);
|
||||
}
|
||||
|
||||
void EventManager::unlockMutex() {
|
||||
mutex->unlockMutex();
|
||||
mutex->unlockMutex();
|
||||
}
|
||||
|
||||
void EventManager::setMutexTimeout(MutexIF::TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
this->timeoutType = timeoutType;
|
||||
this->timeoutMs = timeoutMs;
|
||||
uint32_t timeoutMs) {
|
||||
this->timeoutType = timeoutType;
|
||||
this->timeoutMs = timeoutMs;
|
||||
}
|
||||
|
||||
#if FSFW_OBJ_EVENT_TRANSLATION == 1
|
||||
@ -157,7 +157,7 @@ void EventManager::printUtility(sif::OutputTypes printType, EventMessage *messag
|
||||
message->getReporter() << std::setfill(' ') << std::dec;
|
||||
}
|
||||
sif::info << " reported event with ID " << message->getEventId() << std::endl;
|
||||
sif::debug << translateEvents(message->getEvent()) << " | " <<std::hex << "P1 Hex: 0x" <<
|
||||
sif::info << translateEvents(message->getEvent()) << " | " <<std::hex << "P1 Hex: 0x" <<
|
||||
message->getParameter1() << " | P1 Dec: " << std::dec << message->getParameter1() <<
|
||||
std::hex << " | P2 Hex: 0x" << message->getParameter2() << " | P2 Dec: " <<
|
||||
std::dec << message->getParameter2() << std::endl;
|
||||
@ -170,9 +170,10 @@ void EventManager::printUtility(sif::OutputTypes printType, EventMessage *messag
|
||||
sif::printInfo("Event Manager: Reporter ID 0x%08x reported event with ID %d\n",
|
||||
message->getReporter(), message->getEventId());
|
||||
}
|
||||
sif::printInfo("P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n",
|
||||
message->getParameter1(), message->getParameter1(),
|
||||
message->getParameter2(), message->getParameter2());
|
||||
|
||||
sif::printInfo("%s | P1 Hex: 0x%x | P1 Dec: %d | P2 Hex: 0x%x | P2 Dec: %d\n",
|
||||
translateEvents(message->getEvent()), message->getParameter1(),
|
||||
message->getParameter1(), message->getParameter2(), message->getParameter2());
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
|
||||
}
|
||||
else {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "fsfw/platform.h"
|
||||
#include "fsfw/osal/common/TcpTmTcBridge.h"
|
||||
#include "fsfw/osal/common/tcpipHelpers.h"
|
||||
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw/ipc/MutexGuard.h"
|
||||
@ -17,8 +16,6 @@
|
||||
|
||||
#endif
|
||||
|
||||
const std::string TcpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
|
||||
TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId):
|
||||
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define FSFW_OSAL_COMMON_TCPTMTCBRIDGE_H_
|
||||
|
||||
#include "TcpIpBase.h"
|
||||
#include "../../tmtcservices/TmTcBridge.h"
|
||||
#include "fsfw/tmtcservices/TmTcBridge.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@ -29,8 +29,6 @@ class TcpTmTcBridge:
|
||||
public TmTcBridge {
|
||||
friend class TcpTmTcServer;
|
||||
public:
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_UDP_SERVER_PORT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include "fsfw/osal/common/TcpTmTcServer.h"
|
||||
#include "fsfw/osal/common/TcpTmTcBridge.h"
|
||||
#include "fsfw/osal/common/tcpipHelpers.h"
|
||||
|
||||
#include "fsfw/platform.h"
|
||||
#include "fsfw/FSFW.h"
|
||||
|
||||
#include "TcpTmTcServer.h"
|
||||
#include "TcpTmTcBridge.h"
|
||||
#include "tcpipHelpers.h"
|
||||
|
||||
#include "fsfw/container/SharedRingBuffer.h"
|
||||
#include "fsfw/ipc/MessageQueueSenderIF.h"
|
||||
#include "fsfw/ipc/MutexGuard.h"
|
||||
@ -18,18 +20,14 @@
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7303";
|
||||
const std::string TcpTmTcServer::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
|
||||
TcpTmTcServer::TcpTmTcServer(object_id_t objectId, object_id_t tmtcTcpBridge,
|
||||
size_t receptionBufferSize, std::string customTcpServerPort):
|
||||
SystemObject(objectId), tmtcBridgeId(tmtcTcpBridge),
|
||||
tcpPort(customTcpServerPort), receptionBuffer(receptionBufferSize) {
|
||||
if(tcpPort == "") {
|
||||
tcpPort = DEFAULT_TCP_SERVER_PORT;
|
||||
tcpPort = DEFAULT_SERVER_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,6 +198,10 @@ void TcpTmTcServer::setTcpBacklog(uint8_t tcpBacklog) {
|
||||
this->tcpBacklog = tcpBacklog;
|
||||
}
|
||||
|
||||
std::string TcpTmTcServer::getTcpPort() const {
|
||||
return tcpPort;
|
||||
}
|
||||
|
||||
ReturnValue_t TcpTmTcServer::handleTmSending(socket_t connSocket) {
|
||||
// Access to the FIFO is mutex protected because it is filled by the bridge
|
||||
MutexGuard(tmtcBridge->mutex, tmtcBridge->timeoutType, tmtcBridge->mutexTimeoutMs);
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#include "TcpIpBase.h"
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../ipc/messageQueueDefinitions.h"
|
||||
#include "../../ipc/MessageQueueIF.h"
|
||||
#include "../../objectmanager/frameworkObjects.h"
|
||||
#include "../../objectmanager/SystemObject.h"
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw/platform.h"
|
||||
#include "fsfw/osal/common/tcpipHelpers.h"
|
||||
#include "fsfw/ipc/messageQueueDefinitions.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/objectmanager/frameworkObjects.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
|
||||
#ifdef PLATFORM_UNIX
|
||||
#include <sys/socket.h>
|
||||
@ -41,10 +42,9 @@ class TcpTmTcServer:
|
||||
public TcpIpBase,
|
||||
public ExecutableObjectIF {
|
||||
public:
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_TCP_SERVER_PORT;
|
||||
static const std::string DEFAULT_SERVER_PORT;
|
||||
|
||||
static constexpr size_t ETHERNET_MTU_SIZE = 1500;
|
||||
static constexpr size_t ETHERNET_MTU_SIZE = 1500;
|
||||
|
||||
/**
|
||||
* TCP Server Constructor
|
||||
@ -65,6 +65,8 @@ public:
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
std::string getTcpPort() const;
|
||||
|
||||
protected:
|
||||
StorageManagerIF* tcStore = nullptr;
|
||||
StorageManagerIF* tmStore = nullptr;
|
||||
|
@ -17,13 +17,13 @@
|
||||
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
const std::string UdpTmTcBridge::DEFAULT_UDP_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
const std::string UdpTmTcBridge::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_PORT;
|
||||
|
||||
UdpTmTcBridge::UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
std::string udpServerPort, object_id_t tmStoreId, object_id_t tcStoreId):
|
||||
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||
if(udpServerPort == "") {
|
||||
this->udpServerPort = DEFAULT_UDP_SERVER_PORT;
|
||||
this->udpServerPort = DEFAULT_SERVER_PORT;
|
||||
}
|
||||
else {
|
||||
this->udpServerPort = udpServerPort;
|
||||
@ -108,6 +108,10 @@ UdpTmTcBridge::~UdpTmTcBridge() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string UdpTmTcBridge::getUdpPort() const {
|
||||
return udpServerPort;
|
||||
}
|
||||
|
||||
ReturnValue_t UdpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
int flags = 0;
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define FSFW_OSAL_COMMON_TMTCUDPBRIDGE_H_
|
||||
|
||||
#include "TcpIpBase.h"
|
||||
#include "../../platform.h"
|
||||
#include "../../tmtcservices/TmTcBridge.h"
|
||||
#include "fsfw/platform.h"
|
||||
#include "fsfw/tmtcservices/TmTcBridge.h"
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <ws2tcpip.h>
|
||||
@ -28,7 +28,7 @@ class UdpTmTcBridge:
|
||||
friend class UdpTcPollingTask;
|
||||
public:
|
||||
/* The ports chosen here should not be used by any other process. */
|
||||
static const std::string DEFAULT_UDP_SERVER_PORT;
|
||||
static const std::string DEFAULT_SERVER_PORT;
|
||||
|
||||
UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
std::string udpServerPort = "", object_id_t tmStoreId = objects::TM_STORE,
|
||||
@ -44,6 +44,8 @@ public:
|
||||
|
||||
void checkAndSetClientAddress(sockaddr& clientAddress);
|
||||
|
||||
std::string getUdpPort() const;
|
||||
|
||||
protected:
|
||||
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FSFW_OSAL_COMMON_TCPIPCOMMON_H_
|
||||
#define FSFW_OSAL_COMMON_TCPIPCOMMON_H_
|
||||
|
||||
#include "../../timemanager/clockDefinitions.h"
|
||||
#include "fsfw/timemanager/clockDefinitions.h"
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
namespace tcpip {
|
||||
|
||||
const char* const DEFAULT_SERVER_PORT = "7301";
|
||||
static constexpr char DEFAULT_SERVER_PORT[] = "7301";
|
||||
|
||||
enum class Protocol {
|
||||
UDP,
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief This class manages sending and receiving of
|
||||
* message queue messages.
|
||||
|
@ -16,6 +16,7 @@ target_sources(${LIB_FSFW_NAME}
|
||||
Timer.cpp
|
||||
tcpipHelpers.cpp
|
||||
unixUtility.cpp
|
||||
CommandExecutor.cpp
|
||||
)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
185
src/fsfw/osal/linux/CommandExecutor.cpp
Normal file
185
src/fsfw/osal/linux/CommandExecutor.cpp
Normal file
@ -0,0 +1,185 @@
|
||||
#include "CommandExecutor.h"
|
||||
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw/container/SimpleRingBuffer.h"
|
||||
#include "fsfw/container/DynamicFIFO.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
CommandExecutor::CommandExecutor(const size_t maxSize):
|
||||
readVec(maxSize) {
|
||||
waiter.events = POLLIN;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
|
||||
if(state == States::PENDING) {
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
|
||||
currentCmd = command;
|
||||
this->blocking = blocking;
|
||||
this->printOutput = printOutput;
|
||||
if(state == States::IDLE) {
|
||||
state = States::COMMAND_LOADED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::execute() {
|
||||
if(state == States::IDLE) {
|
||||
return NO_COMMAND_LOADED_OR_PENDING;
|
||||
}
|
||||
else if(state == States::PENDING) {
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
currentCmdFile = popen(currentCmd.c_str(), "r");
|
||||
if(currentCmdFile == nullptr) {
|
||||
lastError = errno;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if(blocking) {
|
||||
return executeBlocking();
|
||||
}
|
||||
else {
|
||||
currentFd = fileno(currentCmdFile);
|
||||
waiter.fd = currentFd;
|
||||
}
|
||||
state = States::PENDING;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::close() {
|
||||
if(state == States::PENDING) {
|
||||
// Attempt to close process, irrespective of if it is running or not
|
||||
if(currentCmdFile != nullptr) {
|
||||
pclose(currentCmdFile);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CommandExecutor::printLastError(std::string funcName) const {
|
||||
if(lastError != 0) {
|
||||
sif::error << funcName << " pclose failed with code " <<
|
||||
lastError << ": " << strerror(lastError) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CommandExecutor::setRingBuffer(SimpleRingBuffer *ringBuffer,
|
||||
DynamicFIFO<uint16_t>* sizesFifo) {
|
||||
this->ringBuffer = ringBuffer;
|
||||
this->sizesFifo = sizesFifo;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::check(bool& bytesRead) {
|
||||
if(blocking) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
switch(state) {
|
||||
case(States::IDLE):
|
||||
case(States::COMMAND_LOADED): {
|
||||
return NO_COMMAND_LOADED_OR_PENDING;
|
||||
}
|
||||
case(States::PENDING): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int result = poll(&waiter, 1, 0);
|
||||
switch(result) {
|
||||
case(0): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
break;
|
||||
}
|
||||
case(1): {
|
||||
if (waiter.revents & POLLIN) {
|
||||
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
||||
if(readBytes == 0) {
|
||||
// Should not happen
|
||||
sif::warning << "CommandExecutor::check: "
|
||||
"No bytes read after poll event.." << std::endl;
|
||||
break;
|
||||
}
|
||||
else if(readBytes > 0) {
|
||||
bytesRead = true;
|
||||
if(printOutput) {
|
||||
// It is assumed the command output is line terminated
|
||||
sif::info << currentCmd << " | " << readVec.data();
|
||||
}
|
||||
if(ringBuffer != nullptr) {
|
||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
|
||||
readVec.data()), readBytes);
|
||||
}
|
||||
if(sizesFifo != nullptr) {
|
||||
if(not sizesFifo->full()) {
|
||||
sizesFifo->insert(readBytes);
|
||||
}
|
||||
}
|
||||
return BYTES_READ;
|
||||
}
|
||||
else {
|
||||
// Should also not happen
|
||||
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
|
||||
strerror(errno) << std::endl;
|
||||
}
|
||||
}
|
||||
else if(waiter.revents & POLLERR) {
|
||||
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
||||
return COMMAND_ERROR;
|
||||
}
|
||||
else if(waiter.revents & POLLHUP) {
|
||||
int result = pclose(currentCmdFile);
|
||||
if(result != 0) {
|
||||
lastError = result;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
state = States::IDLE;
|
||||
currentCmdFile = nullptr;
|
||||
currentFd = 0;
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CommandExecutor::reset() {
|
||||
CommandExecutor::close();
|
||||
currentCmdFile = nullptr;
|
||||
currentFd = 0;
|
||||
state = States::IDLE;
|
||||
}
|
||||
|
||||
int CommandExecutor::getLastError() const {
|
||||
return this->lastError;
|
||||
}
|
||||
|
||||
CommandExecutor::States CommandExecutor::getCurrentState() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::executeBlocking() {
|
||||
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
||||
std::string output(readVec.data());
|
||||
if(printOutput) {
|
||||
sif::info << currentCmd << " | " << output;
|
||||
}
|
||||
if(ringBuffer != nullptr) {
|
||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
||||
}
|
||||
if(sizesFifo != nullptr) {
|
||||
if(not sizesFifo->full()) {
|
||||
sizesFifo->insert(output.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
int result = pclose(currentCmdFile);
|
||||
if(result != 0) {
|
||||
lastError = result;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
134
src/fsfw/osal/linux/CommandExecutor.h
Normal file
134
src/fsfw/osal/linux/CommandExecutor.h
Normal file
@ -0,0 +1,134 @@
|
||||
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
|
||||
#include <poll.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SimpleRingBuffer;
|
||||
template <typename T> class DynamicFIFO;
|
||||
|
||||
/**
|
||||
* @brief Helper class to execute shell commands in blocking and non-blocking mode
|
||||
* @details
|
||||
* This class is able to execute processes by using the Linux popen call. It also has the
|
||||
* capability of writing the read output of a process into a provided ring buffer.
|
||||
*
|
||||
* The executor works by first loading the command which should be executed and specifying
|
||||
* whether it should be executed blocking or non-blocking. After that, execution can be started
|
||||
* with the execute command. In blocking mode, the execute command will block until the command
|
||||
* has finished
|
||||
*/
|
||||
class CommandExecutor {
|
||||
public:
|
||||
enum class States {
|
||||
IDLE,
|
||||
COMMAND_LOADED,
|
||||
PENDING
|
||||
};
|
||||
|
||||
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
||||
static constexpr ReturnValue_t EXECUTION_FINISHED =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
|
||||
|
||||
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
|
||||
//! to load another command but a command is still pending
|
||||
static constexpr ReturnValue_t COMMAND_PENDING =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
||||
static constexpr ReturnValue_t BYTES_READ =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||
//! [EXPORT] : [COMMENT] Command execution failed
|
||||
static constexpr ReturnValue_t COMMAND_ERROR =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
|
||||
//! [EXPORT] : [COMMENT]
|
||||
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
|
||||
static constexpr ReturnValue_t PCLOSE_CALL_ERROR =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
|
||||
|
||||
/**
|
||||
* Constructor. Is initialized with maximum size of internal buffer to read data from the
|
||||
* executed process.
|
||||
* @param maxSize
|
||||
*/
|
||||
CommandExecutor(const size_t maxSize);
|
||||
|
||||
/**
|
||||
* Load a new command which should be executed
|
||||
* @param command
|
||||
* @param blocking
|
||||
* @param printOutput
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t load(std::string command, bool blocking, bool printOutput = true);
|
||||
/**
|
||||
* Execute the loaded command.
|
||||
* @return
|
||||
* - In blocking mode, it will return RETURN_FAILED if
|
||||
* the result of the system call was not 0. The error value can be accessed using
|
||||
* getLastError
|
||||
* - In non-blocking mode, this call will start
|
||||
* the execution and then return RETURN_OK
|
||||
*/
|
||||
ReturnValue_t execute();
|
||||
/**
|
||||
* Only used in non-blocking mode. Checks the currently running command.
|
||||
* @param bytesRead Will be set to the number of bytes read, if bytes have been read
|
||||
* @return
|
||||
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
||||
* check again after this
|
||||
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
|
||||
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
|
||||
* - EXECUTION_FINISHED if the process was executed successfully
|
||||
* - COMMAND_ERROR internal poll error
|
||||
*/
|
||||
ReturnValue_t check(bool& bytesRead);
|
||||
/**
|
||||
* Abort the current command. Should normally not be necessary, check can be used to find
|
||||
* out whether command execution was successful
|
||||
* @return RETURN_OK
|
||||
*/
|
||||
ReturnValue_t close();
|
||||
|
||||
States getCurrentState() const;
|
||||
int getLastError() const;
|
||||
void printLastError(std::string funcName) const;
|
||||
|
||||
/**
|
||||
* Assign a ring buffer and a FIFO which will be filled by the executor with the output
|
||||
* read from the started process
|
||||
* @param ringBuffer
|
||||
* @param sizesFifo
|
||||
*/
|
||||
void setRingBuffer(SimpleRingBuffer* ringBuffer, DynamicFIFO<uint16_t>* sizesFifo);
|
||||
|
||||
/**
|
||||
* Reset the executor. This calls close internally and then reset the state machine so new
|
||||
* commands can be loaded and executed
|
||||
*/
|
||||
void reset();
|
||||
private:
|
||||
std::string currentCmd;
|
||||
bool blocking = true;
|
||||
FILE* currentCmdFile = nullptr;
|
||||
int currentFd = 0;
|
||||
bool printOutput = true;
|
||||
std::vector<char> readVec;
|
||||
struct pollfd waiter {};
|
||||
SimpleRingBuffer* ringBuffer = nullptr;
|
||||
DynamicFIFO<uint16_t>* sizesFifo = nullptr;
|
||||
|
||||
States state = States::IDLE;
|
||||
int lastError = 0;
|
||||
|
||||
ReturnValue_t executeBlocking();
|
||||
};
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_ */
|
@ -27,6 +27,7 @@ int Timer::setTimer(uint32_t intervalMs) {
|
||||
timer.it_value.tv_nsec = (intervalMs * 1000000) % (1000000000);
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_nsec = 0;
|
||||
set = true;
|
||||
return timer_settime(timerId, 0, &timer, NULL);
|
||||
}
|
||||
|
||||
@ -43,3 +44,14 @@ int Timer::getTimer(uint32_t* remainingTimeMs){
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool Timer::isSet() const {
|
||||
return this->set;
|
||||
}
|
||||
|
||||
void Timer::resetTimer() {
|
||||
if(not this->set) {
|
||||
set = false;
|
||||
}
|
||||
setTimer(0);
|
||||
}
|
||||
|
@ -38,7 +38,11 @@ public:
|
||||
*/
|
||||
int getTimer(uint32_t* remainingTimeMs);
|
||||
|
||||
bool isSet() const;
|
||||
void resetTimer();
|
||||
|
||||
private:
|
||||
bool set = true;
|
||||
timer_t timerId;
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,7 @@ void utility::printUnixErrorGeneric(const char* const className,
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
if(outputType == sif::OutputTypes::OUT_ERROR) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << className << "::" << function << ":" << failString << " error: "
|
||||
sif::error << className << "::" << function << ": " << failString << " error: "
|
||||
<< strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printError("%s::%s: %s error: %s\n", className, function, failString, strerror(errno));
|
||||
@ -22,7 +22,7 @@ void utility::printUnixErrorGeneric(const char* const className,
|
||||
}
|
||||
else {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << className << "::" << function << ":" << failString << " error: "
|
||||
sif::warning << className << "::" << function << ": " << failString << " error: "
|
||||
<< strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printWarning("%s::%s: %s error: %s\n", className, function, failString, strerror(errno));
|
||||
|
@ -33,8 +33,8 @@ ReturnValue_t Service8FunctionManagement::getMessageQueueAndObject(
|
||||
if(tcDataLen < sizeof(object_id_t)) {
|
||||
return CommandingServiceBase::INVALID_TC;
|
||||
}
|
||||
SerializeAdapter::deSerialize(objectId, &tcData,
|
||||
&tcDataLen, SerializeIF::Endianness::BIG);
|
||||
// Can't fail, size was checked before
|
||||
SerializeAdapter::deSerialize(objectId, &tcData, &tcDataLen, SerializeIF::Endianness::BIG);
|
||||
|
||||
return checkInterfaceAndAcquireMessageQueue(id,objectId);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user