Merge pull request 'RTEMS and DHB update' (#362) from mueller/rtems-update into development

Reviewed-on: fsfw/fsfw#362
This commit is contained in:
Steffen Gaisser 2021-02-09 14:25:49 +01:00
commit b9cb0495a9
14 changed files with 143 additions and 236 deletions

View File

@ -890,7 +890,7 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
<< std::dec << std::setfill(' ') << std::endl;
#else
sif::printWarning("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
owner->getObjectId(), errorPrint);
functionName, owner->getObjectId(), errorPrint);
#endif
}
else if(outputType == sif::OutputTypes::OUT_ERROR) {
@ -901,7 +901,7 @@ void LocalDataPoolManager::printWarningOrError(sif::OutputTypes outputType,
<< std::dec << std::setfill(' ') << std::endl;
#else
sif::printError("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
owner->getObjectId(), errorPrint);
functionName, owner->getObjectId(), errorPrint);
#endif
}
}

View File

@ -399,14 +399,14 @@ ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
PoolEntry<T> **poolEntry) {
auto poolIter = localPoolMap.find(localPoolId);
if (poolIter == localPoolMap.end()) {
printWarningOrError(sif::OutputTypes::OUT_ERROR, "fetchPoolEntry",
printWarningOrError(sif::OutputTypes::OUT_WARNING, "fetchPoolEntry",
localpool::POOL_ENTRY_NOT_FOUND);
return localpool::POOL_ENTRY_NOT_FOUND;
}
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
if(*poolEntry == nullptr) {
printWarningOrError(sif::OutputTypes::OUT_ERROR, "fetchPoolEntry",
printWarningOrError(sif::OutputTypes::OUT_WARNING, "fetchPoolEntry",
localpool::POOL_ENTRY_TYPE_CONFLICT);
return localpool::POOL_ENTRY_TYPE_CONFLICT;
}

View File

@ -2,6 +2,9 @@
#define FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_
#include "LocalPoolDataSetBase.h"
#include "LocalPoolVariable.h"
#include "LocalPoolVector.h"
#include "../objectmanager/SystemObjectIF.h"
#include <array>

View File

@ -1202,61 +1202,62 @@ ReturnValue_t DeviceHandlerBase::letChildHandleMessage(
return RETURN_FAILED;
}
void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
DeviceCommandId_t replyId, bool neverInDataPool, bool forceDirectTm) {
void DeviceHandlerBase::handleDeviceTM(SerializeIF *dataSet, DeviceCommandId_t replyId,
bool forceDirectTm) {
if(dataSet == nullptr) {
return;
}
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
if (iter == deviceReplyMap.end()) {
triggerEvent(DEVICE_UNKNOWN_REPLY, replyId);
return;
}
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, data);
//replies to a command
/* Regular replies to a command */
if (iter->second.command != deviceCommandMap.end())
{
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
if (queueId != NO_COMMANDER) {
//This may fail, but we'll ignore the fault.
actionHelper.reportData(queueId, replyId, data);
/* This may fail, but we'll ignore the fault. */
actionHelper.reportData(queueId, replyId, dataSet);
}
//This check should make sure we get any TM but don't get anything doubled.
/* This check should make sure we get any TM but don't get anything doubled. */
if (wiretappingMode == TM && (requestedRawTraffic != queueId)) {
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, dataSet);
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
}
else if (forceDirectTm and (defaultRawReceiver != queueId) and
(defaultRawReceiver != MessageQueueIF::NO_QUEUE))
(defaultRawReceiver != MessageQueueIF::NO_QUEUE))
{
// hiding of sender needed so the service will handle it as
// unexpected Data, no matter what state (progress or completed)
// it is in
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
true);
actionHelper.reportData(defaultRawReceiver, replyId, dataSet, true);
}
}
//unrequested/aperiodic replies
/* Unrequested or aperiodic replies */
else
{
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, dataSet);
if (wiretappingMode == TM) {
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
}
else if (forceDirectTm and defaultRawReceiver !=
MessageQueueIF::NO_QUEUE)
if (forceDirectTm and defaultRawReceiver != MessageQueueIF::NO_QUEUE)
{
// sid_t setSid = sid_t(this->getObjectId(), replyId);
// LocalPoolDataSetBase* dataset = getDataSetHandle(setSid);
// if(dataset != nullptr) {
// poolManager.generateHousekeepingPacket(setSid, dataset, true);
// }
// hiding of sender needed so the service will handle it as
// unexpected Data, no matter what state (progress or completed)
// it is in
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
true);
}
}
//Try to cast to GlobDataSet and commit data.
if (not neverInDataPool) {
LocalPoolDataSetBase* dataSet =
dynamic_cast<LocalPoolDataSetBase*>(data);
if (dataSet != nullptr) {
dataSet->setValidity(true, true);
dataSet->commit();
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper, true);
}
}
}
@ -1531,3 +1532,11 @@ void DeviceHandlerBase::printWarningOrError(sif::OutputTypes errorType,
LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() {
return &poolManager;
}
MessageQueueId_t DeviceHandlerBase::getCommanderId(DeviceCommandId_t replyId) const {
auto commandIter = deviceCommandMap.find(replyId);
if(commandIter == deviceCommandMap.end()) {
return MessageQueueIF::NO_QUEUE;
}
return commandIter->second.sendReplyTo;
}

View File

@ -189,6 +189,38 @@ public:
/** Destructor. */
virtual ~DeviceHandlerBase();
/**
* Implementation of ExecutableObjectIF function
* Used to setup the reference of the task, that executes this component
* @param task_ Pointer to the taskIF of this task
*/
virtual void setTaskIF(PeriodicTaskIF* task_) override;
virtual MessageQueueId_t getCommandQueue(void) const override;
/** Explicit interface implementation of getObjectId */
virtual object_id_t getObjectId() const override;
/**
* @param parentQueueId
*/
virtual void setParentQueue(MessageQueueId_t parentQueueId);
/** @brief Implementation required for HasActionIF */
ReturnValue_t executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t* data,
size_t size) override;
Mode_t getTransitionSourceMode() const;
Submode_t getTransitionSourceSubMode() const;
virtual void getMode(Mode_t *mode, Submode_t *submode);
HealthState getHealth();
ReturnValue_t setHealth(HealthState health);
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex) override;
protected:
/**
* @brief This is used to let the child class handle the transition from
@ -288,23 +320,29 @@ protected:
virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) = 0;
/**
* @brief Build a device command packet from data supplied by a
* direct command.
*
* @brief Build a device command packet from data supplied by a direct
* command (PUS Service 8)
* @details
* #rawPacket and #rawPacketLen should be set by this method to the packet
* to be sent. The existence of the command in the command map and the
* command size check against 0 are done by the base class.
* This will be called if an functional command via PUS Service 8 is received and is
* the primary interface for functional command instead of #executeAction for users. The
* supplied ActionId_t action ID will be converted to a DeviceCommandId_t command ID after
* an internal check whether the action ID is a key in the device command map.
*
* @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
* #rawPacket and #rawPacketLen should be set by this method to the packet to be sent.
* The existence of the command in the command map and the command size check against 0 are
* done by the base class.
*
* @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.
* - Anything else triggers an event with the
* returnvalue as a parameter
* - @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
*/
virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t * commandData, size_t commandDataLen) = 0;
@ -529,37 +567,6 @@ protected:
*/
virtual void performOperationHook();
public:
/** Explicit interface implementation of getObjectId */
virtual object_id_t getObjectId() const override;
/**
* @param parentQueueId
*/
virtual void setParentQueue(MessageQueueId_t parentQueueId);
/** @brief Implementation required for HasActionIF */
ReturnValue_t executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t* data,
size_t size) override;
Mode_t getTransitionSourceMode() const;
Submode_t getTransitionSourceSubMode() const;
virtual void getMode(Mode_t *mode, Submode_t *submode);
HealthState getHealth();
ReturnValue_t setHealth(HealthState health);
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex) override;
/**
* Implementation of ExecutableObjectIF function
*
* Used to setup the reference of the task, that executes this component
* @param task_ Pointer to the taskIF of this task
*/
virtual void setTaskIF(PeriodicTaskIF* task_);
virtual MessageQueueId_t getCommandQueue(void) const;
protected:
/**
* The Returnvalues id of this class, required by HasReturnvaluesIF
@ -567,16 +574,16 @@ protected:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE;
static const ReturnValue_t INVALID_CHANNEL = MAKE_RETURN_CODE(0xA0);
// Returnvalues for scanForReply()
/* Return codes for scanForReply */
static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(0xB0); //!< This is used to specify for replies from a device which are not replies to requests
static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(0xB1); //!< Ignore parts of the received packet
static const ReturnValue_t IGNORE_FULL_PACKET = MAKE_RETURN_CODE(0xB2); //!< Ignore full received packet
// Returnvalues for command building
/* Return codes for command building */
static const ReturnValue_t NOTHING_TO_SEND = MAKE_RETURN_CODE(0xC0); //!< Return this if no command sending in required
static const ReturnValue_t COMMAND_MAP_ERROR = MAKE_RETURN_CODE(0xC2);
// Returnvalues for getSwitches()
// Return codes for getSwitches */
static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(0xD0);
// Mode handling error Codes
/* Mode handling error Codes */
static const ReturnValue_t CHILD_TIMEOUT = MAKE_RETURN_CODE(0xE0);
static const ReturnValue_t SWITCH_FAILED = MAKE_RETURN_CODE(0xE1);
@ -763,6 +770,8 @@ protected:
*/
virtual void setNormalDatapoolEntriesInvalid();
MessageQueueId_t getCommanderId(DeviceCommandId_t replyId) const;
/**
* Helper function to get pending command. This is useful for devices
* like SPI sensors to identify the last sent command.
@ -995,8 +1004,10 @@ protected:
bool isAwaitingReply();
void handleDeviceTM(SerializeIF *dataSet, DeviceCommandId_t commandId,
bool neverInDataPool = false, bool forceDirectTm = false);
void handleDeviceTM(SerializeIF *dataSet, DeviceCommandId_t replyId,
bool forceDirectTm = false);
// void handleDeviceTM(uint8_t* data, size_t dataSize, DeviceCommandId_t replyId,
// bool forceDirectTm);
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode);
@ -1062,6 +1073,7 @@ protected:
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
*/
void commandSwitch(ReturnValue_t onOff);
private:
/**

View File

@ -10,7 +10,7 @@
#include "../serialize/SerialFixedArrayListAdapter.h"
#include "../serialize/SerializeElement.h"
#include "../serialize/SerialLinkedListAdapter.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../serviceinterface/ServiceInterface.h"
#include "../timemanager/TimeStamperIF.h"
namespace Factory{

View File

@ -1,5 +1,5 @@
#include "ObjectManager.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../serviceinterface/ServiceInterface.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iomanip>
@ -75,6 +75,8 @@ void ObjectManager::initialize() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::initialize: Passed produceObjects "
"functions is nullptr!" << std::endl;
#else
sif::printError("ObjectManager::initialize: Passed produceObjects functions is nullptr!\n");
#endif
return;
}

View File

@ -5,13 +5,17 @@
SystemObject::SystemObject(object_id_t setObjectId, bool doRegister) :
objectId(setObjectId), registered(doRegister) {
if (registered) {
objectManager->insert(objectId, this);
if(objectManager != nullptr) {
objectManager->insert(objectId, this);
}
}
}
SystemObject::~SystemObject() {
if (registered) {
objectManager->remove(objectId);
if(objectManager != nullptr) {
objectManager->remove(objectId);
}
}
}

View File

@ -1,30 +1,34 @@
#ifndef FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
#define FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
#include <fsfw/objectmanager/SystemObjectIF.h>
namespace objects {
enum framework_objects {
// Default verification reporter.
PUS_SERVICE_1_VERIFICATION = 0x53000001,
PUS_SERVICE_2_DEVICE_ACCESS = 0x53000002,
PUS_SERVICE_3_HOUSEKEEPING = 0x53000003,
PUS_SERVICE_5_EVENT_REPORTING = 0x53000005,
PUS_SERVICE_8_FUNCTION_MGMT = 0x53000008,
PUS_SERVICE_9_TIME_MGMT = 0x53000009,
PUS_SERVICE_17_TEST = 0x53000017,
PUS_SERVICE_200_MODE_MGMT = 0x53000200,
enum framework_objects: object_id_t {
FSFW_OBJECTS_START = 0x53000000,
// Default verification reporter.
PUS_SERVICE_1_VERIFICATION = 0x53000001,
PUS_SERVICE_2_DEVICE_ACCESS = 0x53000002,
PUS_SERVICE_3_HOUSEKEEPING = 0x53000003,
PUS_SERVICE_5_EVENT_REPORTING = 0x53000005,
PUS_SERVICE_8_FUNCTION_MGMT = 0x53000008,
PUS_SERVICE_9_TIME_MGMT = 0x53000009,
PUS_SERVICE_17_TEST = 0x53000017,
PUS_SERVICE_200_MODE_MGMT = 0x53000200,
//Generic IDs for IPC, modes, health, events
HEALTH_TABLE = 0x53010000,
// MODE_STORE = 0x53010100,
EVENT_MANAGER = 0x53030000,
INTERNAL_ERROR_REPORTER = 0x53040000,
IPC_STORE = 0x534f0300,
//IDs for PUS Packet Communication
TC_STORE = 0x534f0100,
TM_STORE = 0x534f0200,
TIME_STAMPER = 0x53500010,
//Generic IDs for IPC, modes, health, events
HEALTH_TABLE = 0x53010000,
// MODE_STORE = 0x53010100,
EVENT_MANAGER = 0x53030000,
INTERNAL_ERROR_REPORTER = 0x53040000,
IPC_STORE = 0x534f0300,
//IDs for PUS Packet Communication
TC_STORE = 0x534f0100,
TM_STORE = 0x534f0200,
TIME_STAMPER = 0x53500010,
NO_OBJECT = 0xFFFFFFFF
FSFW_OBJECTS_END = 0x53ffffff,
NO_OBJECT = 0xFFFFFFFF
};
}

View File

@ -1,84 +0,0 @@
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "TaskBase.h"
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE=RTEMS_MINIMUM_STACK_SIZE;
TaskBase::TaskBase(rtems_task_priority set_priority, size_t stack_size,
const char *name) {
rtems_name osalName = 0;
for (uint8_t i = 0; i < 4; i++) {
if (name[i] == 0) {
break;
}
osalName += name[i] << (8 * (3 - i));
}
//The task is created with the operating system's system call.
rtems_status_code status = RTEMS_UNSATISFIED;
if (set_priority >= 0 && set_priority <= 99) {
status = rtems_task_create(osalName,
(0xFF - 2 * set_priority), stack_size,
RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
RTEMS_FLOATING_POINT, &id);
}
ReturnValue_t result = convertReturnCode(status);
if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TaskBase::TaskBase: createTask with name " << std::hex
<< osalName << std::dec << " failed with return code "
<< (uint32_t) status << std::endl;
#endif
this->id = 0;
}
}
TaskBase::~TaskBase() {
rtems_task_delete(id);
}
rtems_id TaskBase::getId() {
return this->id;
}
ReturnValue_t TaskBase::sleepFor(uint32_t ms) {
rtems_status_code status = rtems_task_wake_after(RtemsBasic::convertMsToTicks(ms));
return convertReturnCode(status);
}
ReturnValue_t TaskBase::convertReturnCode(rtems_status_code inValue) {
switch (inValue) {
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_MP_NOT_CONFIGURED:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_NAME:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_TOO_MANY:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_UNSATISFIED:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_PRIORITY:
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t TaskBase::setAndStartPeriod(rtems_interval period, rtems_id *periodId) {
rtems_name periodName = (('P' << 24) + ('e' << 16) + ('r' << 8) + 'd');
rtems_status_code status = rtems_rate_monotonic_create(periodName, periodId);
if (status == RTEMS_SUCCESSFUL) {
status = restartPeriod(period,*periodId);
}
return convertReturnCode(status);
}
rtems_status_code TaskBase::restartPeriod(rtems_interval period, rtems_id periodId){
//This is necessary to avoid a call with period = 0, which does not start the period.
rtems_status_code status = rtems_rate_monotonic_period(periodId, period + 1);
return status;
}

View File

@ -1,47 +0,0 @@
#ifndef FSFW_OSAL_RTEMS_TASKBASE_H_
#define FSFW_OSAL_RTEMS_TASKBASE_H_
#include "RtemsBasic.h"
#include "../../tasks/PeriodicTaskIF.h"
/**
* @brief This is the basic task handling class for rtems.
*
* @details Task creation base class for rtems.
*/
class TaskBase {
protected:
/**
* @brief The class stores the task id it got assigned from the operating system in this attribute.
* If initialization fails, the id is set to zero.
*/
rtems_id id;
public:
/**
* @brief The constructor creates and initializes a task.
* @details This is accomplished by using the operating system call to create a task. The name is
* created automatically with the help od taskCounter. Priority and stack size are
* adjustable, all other attributes are set with default values.
* @param priority Sets the priority of a task. Values range from a low 0 to a high 99.
* @param stack_size The stack size reserved by the operating system for the task.
* @param nam The name of the Task, as a null-terminated String. Currently max 4 chars supported (excluding Null-terminator), rest will be truncated
*/
TaskBase( rtems_task_priority priority, size_t stack_size, const char *name);
/**
* @brief In the destructor, the created task is deleted.
*/
virtual ~TaskBase();
/**
* @brief This method returns the task id of this class.
*/
rtems_id getId();
ReturnValue_t sleepFor(uint32_t ms);
static ReturnValue_t setAndStartPeriod(rtems_interval period, rtems_id *periodId);
static rtems_status_code restartPeriod(rtems_interval period, rtems_id periodId);
private:
static ReturnValue_t convertReturnCode(rtems_status_code inValue);
};
#endif /* FSFW_OSAL_RTEMS_TASKBASE_H_ */

View File

@ -104,12 +104,14 @@ ReturnValue_t Service8FunctionManagement::handleReply(
break;
}
case ActionMessage::DATA_REPLY: {
/* Multiple data replies are possible, so declare data reply as step */
*isStep = true;
result = handleDataReply(reply, objectId, actionId);
break;
}
case ActionMessage::STEP_FAILED:
*isStep = true;
/*No break, falls through*/
/* No break, falls through */
case ActionMessage::COMPLETION_FAILED:
result = ActionMessage::getReturnCode(reply);
break;

View File

@ -1,6 +1,9 @@
#include "Stopwatch.h"
#include "../serviceinterface/ServiceInterface.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iomanip>
#endif
Stopwatch::Stopwatch(bool displayOnDestruction,
StopwatchDisplayMode displayMode): displayOnDestruction(

View File

@ -187,8 +187,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
CHECK(messageSent.getCommand() == static_cast<int>(
HousekeepingMessage::HK_REPORT));
CommandMessageCleaner::clearCommandMessage(&messageSent);
REQUIRE(mqMock->receiveMessage(&messageSent) ==
static_cast<int>(MessageQueueIF::EMPTY));
REQUIRE(mqMock->receiveMessage(&messageSent) == static_cast<int>(MessageQueueIF::EMPTY));
}
/* we need to reset the subscription list because the pool owner