Merge pull request 'Update EIVE FSFW' (#8) from mueller/master into eive/develop

Reviewed-on: eive/fsfw#8
This commit is contained in:
Jakob Meier 2021-08-05 16:35:23 +02:00
commit 47bec654a0
162 changed files with 638 additions and 667 deletions

View File

@ -10,6 +10,7 @@ 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_HAL "Add Hardware Abstraction Layer" ON)
# Optional sources
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
@ -21,7 +22,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 +95,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.

View File

@ -1,4 +1,4 @@
![FSFW Logo](logo/FSFW_Logo_V3_bw.png)
![FSFW Logo](misc/logo/FSFW_Logo_V3_bw.png)
# Flight Software Framework (FSFW)

View File

@ -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)

View 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()

View File

@ -6,4 +6,4 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(fsfw)
add_subdirectory(fsfw_hal)

View File

@ -1 +0,0 @@
add_subdirectory(hal)

View File

@ -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() {

View File

@ -1,4 +1,4 @@
#include "fsfw/hal/devicehandlers/GyroL3GD20Handler.h"
#include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h"
#include "fsfw/datapool/PoolReadGuard.h"

View File

@ -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 */
/**

View File

@ -1,4 +1,4 @@
#include "fsfw/hal/linux/UnixFileGuard.h"
#include "fsfw_hal/linux/UnixFileGuard.h"
UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
std::string diagnosticPrefix):

View File

@ -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>

View File

@ -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"

View File

@ -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_) :

View File

@ -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>

View File

@ -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>

View File

@ -3,7 +3,7 @@
#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"

View File

@ -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):

View File

@ -1,4 +1,4 @@
#include "fsfw/hal/linux/uart/UartComIF.h"
#include "fsfw_hal/linux/uart/UartComIF.h"
#include "OBSWConfig.h"
#include "fsfw/serviceinterface/ServiceInterface.h"

View File

@ -1,4 +1,4 @@
#include "fsfw/hal/linux/uart/UartCookie.h"
#include "fsfw_hal/linux/uart/UartCookie.h"
#include <fsfw/serviceinterface/ServiceInterface.h>

View File

@ -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>

View File

@ -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"

View File

@ -1,4 +1,4 @@
#include <fsfw/hal/stm32h7/dma.h>
#include <fsfw_hal/stm32h7/dma.h>
#include <cstdint>
#include <cstddef>

View File

@ -1,4 +1,4 @@
#include "fsfw/hal/stm32h7/gpio/gpio.h"
#include "fsfw_hal/stm32h7/gpio/gpio.h"
#include "stm32h7xx_hal_rcc.h"

View File

@ -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

View File

@ -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"

View File

@ -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,

View File

@ -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"

View File

@ -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>

View File

@ -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"

View File

@ -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) {

View File

@ -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"

View File

@ -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"

View File

@ -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>

View File

@ -9,5 +9,10 @@
#cmakedefine FSFW_ADD_COORDINATES
#cmakedefine FSFW_ADD_PUS
#cmakedefine FSFW_ADD_MONITORING
#cmakedefine FSFW_ADD_SGP4_PROPAGATOR
#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */
#endif /* FSFW_FSFW_H_ */

View File

@ -55,7 +55,19 @@ void ActionHelper::setQueueToUse(MessageQueueIF* queue) {
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
ActionId_t actionId, store_address_t dataAddress) {
const uint8_t* dataPtr = NULL;
if(ipcStore == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "ActionHelper::prepareExecution: IPC Store not set. Call initialize first"
<< std::endl;
#else
sif::printWarning("ActionHelper::prepareExecution: "
"IPC Store not set. Call initialize first\n");
#endif
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return;
}
const uint8_t* dataPtr = nullptr;
size_t size = 0;
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -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 {

View File

@ -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_ */

View File

@ -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 {

View File

@ -11,7 +11,6 @@
#include "FreeRTOS.h"
#include "queue.h"
/**
* @brief This class manages sending and receiving of
* message queue messages.

View File

@ -16,6 +16,7 @@ target_sources(${LIB_FSFW_NAME}
Timer.cpp
tcpipHelpers.cpp
unixUtility.cpp
CommandExecutor.cpp
)
find_package(Threads REQUIRED)

View File

@ -0,0 +1,184 @@
#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;
}
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;
}

View 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_ */

View File

@ -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));

View File

@ -72,6 +72,7 @@ enum: uint8_t {
PUS_SERVICE_3, //PUS3
PUS_SERVICE_9, //PUS9
FILE_SYSTEM, //FILS
LINUX_OSAL, //UXOS
HAL_SPI, //HSPI
HAL_UART, //HURT
HAL_I2C, //HI2C

View File

@ -1,7 +1,7 @@
#ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_
#define FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_
#include <FSFWConfig.h>
#include "fsfw/FSFW.h"
#include "serviceInterfaceDefintions.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1

View File

@ -146,8 +146,8 @@ std::string* ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) {
#endif
int32_t charCount = sprintf(parsePosition,
"%s: | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ",
this->logMessage.c_str(), loggerTime.hour,
"%s%s | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ",
this->logMessage.c_str(), sif::ANSI_COLOR_RESET, loggerTime.hour,
loggerTime.minute,
loggerTime.second,
loggerTime.usecond /1000);
@ -171,9 +171,11 @@ bool ServiceInterfaceBuffer::crAdditionEnabled() const {
return addCrToPreamble;
}
#if FSFW_COLORED_OUTPUT == 1
void ServiceInterfaceBuffer::setAsciiColorPrefix(std::string colorPrefix) {
this->colorPrefix = colorPrefix;
this->colorPrefix = colorPrefix;
}
#endif
#ifdef UT699
#include "../osal/rtems/Interrupt.h"

View File

@ -69,6 +69,10 @@ void fsfwPrint(sif::PrintLevel printType, const char* fmt, va_list arg) {
len += sprintf(bufferPosition + len, "ERROR: ");
}
#if FSFW_COLORED_OUTPUT == 1
len += sprintf(bufferPosition, sif::ANSI_COLOR_RESET);
#endif
Clock::TimeOfDay_t now;
Clock::getDateAndTime(&now);
/*

View File

@ -19,9 +19,11 @@ bool ServiceInterfaceStream::crAdditionEnabled() const {
return streambuf.crAdditionEnabled();
}
#if FSFW_COLORED_OUTPUT == 1
void ServiceInterfaceStream::setAsciiColorPrefix(std::string asciiColorCode) {
streambuf.setAsciiColorPrefix(asciiColorCode);
}
#endif
#endif

View File

@ -46,7 +46,9 @@ public:
*/
bool crAdditionEnabled() const;
#if FSFW_COLORED_OUTPUT == 1
void setAsciiColorPrefix(std::string asciiColorCode);
#endif
protected:
ServiceInterfaceBuffer streambuf;

View File

@ -6,4 +6,4 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(fsfw)
add_subdirectory(fsfw_tests)

View File

@ -1 +0,0 @@
add_subdirectory(tests)

View File

@ -1,11 +1,11 @@
#include "fsfw/tests/internal/InternalUnitTester.h"
#include "fsfw/tests/internal/UnittDefinitions.h"
#include "fsfw_tests/internal/InternalUnitTester.h"
#include "fsfw_tests/internal/UnittDefinitions.h"
#include "fsfw/tests/internal/osal/IntTestMq.h"
#include "fsfw/tests/internal/osal/IntTestSemaphore.h"
#include "fsfw/tests/internal/osal/IntTestMutex.h"
#include "fsfw/tests/internal/serialize/IntTestSerialization.h"
#include "fsfw/tests/internal/globalfunctions/TestArrayPrinter.h"
#include "fsfw_tests/internal/osal/IntTestMq.h"
#include "fsfw_tests/internal/osal/IntTestSemaphore.h"
#include "fsfw_tests/internal/osal/IntTestMutex.h"
#include "fsfw_tests/internal/serialize/IntTestSerialization.h"
#include "fsfw_tests/internal/globalfunctions/TestArrayPrinter.h"
#include <cstdlib>

View File

@ -1,4 +1,4 @@
#include "fsfw/tests/internal/UnittDefinitions.h"
#include "fsfw_tests/internal/UnittDefinitions.h"
ReturnValue_t unitt::put_error(std::string errorId) {
#if FSFW_CPP_OSTREAM_ENABLED == 1

Some files were not shown because too many files have changed in this diff Show More