Adding Code for Linux

This commit is contained in:
Steffen Gaisser 2018-07-13 18:28:26 +02:00
parent db1f93a155
commit fd782b20c0
90 changed files with 2411 additions and 1497 deletions

View File

@ -20,11 +20,13 @@ ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) {
}
}
ReturnValue_t ActionHelper::initialize() {
ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) {
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
setQueueToUse(queueToUse_);
return HasReturnvaluesIF::RETURN_OK;
}
@ -100,3 +102,6 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t rep
}
return result;
}
void ActionHelper::resetHelper() {
}

View File

@ -4,26 +4,90 @@
#include <framework/action/ActionMessage.h>
#include <framework/serialize/SerializeIF.h>
#include <framework/ipc/MessageQueueIF.h>
/**
* \brief Action Helper is a helper class which handles action messages
*
* Components which use the HasActionIF this helper can be used to handle the action messages.
* It does handle step messages as well as other answers to action calls. It uses the executeAction function
* of its owner as callback. The call of the initialize function is mandatory and it needs a valid messageQueueIF pointer!
*/
class HasActionsIF;
class ActionHelper {
public:
/**
* Constructor of the action helper
* @param setOwner Pointer to the owner of the interface
* @param useThisQueue messageQueue to be used, can be set during initialize function as well.
*/
ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue);
virtual ~ActionHelper();
/**
* Function to be called from the owner with a new command message
*
* If the message is a valid action message the helper will use the executeAction function from HasActionsIF.
* If the message is invalid or the callback fails a message reply will be send to the sender of the message automatically.
*
* @param command Pointer to a command message received by the owner
* @return HasReturnvaluesIF::RETURN_OK if the message is a action message, CommandMessage::UNKNOW_COMMAND if this message ID is unkown
*/
ReturnValue_t handleActionMessage(CommandMessage* command);
ReturnValue_t initialize();
/**
* Helper initialize function. Must be called before use of any other helper function
* @param queueToUse_ Pointer to the messageQueue to be used
* @return Returns RETURN_OK if successful
*/
ReturnValue_t initialize(MessageQueueIF* queueToUse_);
/**
* Function to be called from the owner to send a step message. Success or failure will be determined by the result value.
*
* @param step Number of steps already done
* @param reportTo The messageQueueId to report the step message to
* @param commandId ID of the executed command
* @param result Result of the execution
*/
void step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
/**
* Function to be called by the owner to send a action completion message
*
* @param reportTo MessageQueueId_t to report the action completion message to
* @param commandId ID of the executed command
* @param result Result of the execution
*/
void finish(MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
/**
* Function to be called by the owner if an action does report data
*
* @param reportTo MessageQueueId_t to report the action completion message to
* @param replyId ID of the executed command
* @param data Pointer to the data
* @return Returns RETURN_OK if successful, otherwise failure code
*/
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, SerializeIF* data, bool hideSender = false);
/**
* Function to setup the MessageQueueIF* of the helper. Can be used to set the messageQueueIF* if
* message queue is unavailable at construction and initialize but must be setup before first call of other functions.
* @param queue Queue to be used by the helper
*/
void setQueueToUse(MessageQueueIF *queue);
protected:
static const uint8_t STEP_OFFSET = 1;
HasActionsIF* owner;
MessageQueueIF* queueToUse;
StorageManagerIF* ipcStore;
static const uint8_t STEP_OFFSET = 1;//!< Increase of value of this per step
HasActionsIF* owner;//!< Pointer to the owner
MessageQueueIF* queueToUse;//!< Queue to be used as response sender, has to be set with
StorageManagerIF* ipcStore;//!< Pointer to an IPC Store, initialized during construction or initialize(MessageQueueIF* queueToUse_) or with setQueueToUse(MessageQueueIF *queue)
/**
*Internal function called by handleActionMessage(CommandMessage* command)
*
* @param commandedBy MessageQueueID of Commander
* @param actionId ID of action to be done
* @param dataAddress Address of additional data in IPC Store
*/
virtual void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, store_address_t dataAddress);
void resetHelper();
/**
*
*/
virtual void resetHelper();
};
#endif /* ACTIONHELPER_H_ */

View File

@ -5,7 +5,7 @@
#include <framework/objectmanager/ObjectManagerIF.h>
CommandActionHelper::CommandActionHelper(CommandsActionsIF* setOwner) :
owner(setOwner), queueToUse(setOwner->getCommandQueuePtr()), ipcStore(
owner(setOwner), queueToUse(NULL), ipcStore(
NULL), commandCount(0), lastTarget(0) {
}
@ -66,11 +66,15 @@ ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId,
ReturnValue_t CommandActionHelper::initialize() {
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore != NULL) {
return HasReturnvaluesIF::RETURN_OK;
} else {
if (ipcStore == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
queueToUse = owner->getCommandQueuePtr();
if(queueToUse == NULL){
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CommandActionHelper::handleReply(CommandMessage* reply) {

View File

@ -6,14 +6,36 @@
#include <framework/action/SimpleActionHelper.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/ipc/MessageQueueIF.h>
/**
* \brief Interface for component which uses actions
*
* This interface is used to execute actions in the component. Actions, in the sense of this interface, are activities with a well-defined beginning and
* end in time. They may adjust sub-states of components, but are not supposed to change
* the main mode of operation, which is handled with the HasModesIF described below.
*
* The HasActionsIF allows components to define such actions and make them available
* for other components to use. Implementing the interface is straightforward: Theres a
* single executeAction call, which provides an identifier for the action to execute, as well
* as arbitrary parameters for input. Aside from direct, software-based
* actions, it is used in device handler components as an interface to forward commands to
* devices.
* Implementing components of the interface are supposed to check identifier (ID) and
* parameters and immediately start execution of the action. It is, however, not required to
* immediately finish execution. Instead, this may be deferred to a later point in time, at
* which the component needs to inform the caller about finished or failed execution.
*/
class HasActionsIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_ACTIONS_IF;
static const ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1);
static const ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1);//!<
static const ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2);
static const ReturnValue_t EXECUTION_FINISHED = MAKE_RETURN_CODE(3);
static const ReturnValue_t INVALID_ACTION_ID = MAKE_RETURN_CODE(4);
virtual ~HasActionsIF() { }
/**
* Function to get the MessageQueueId_t of the implementing object
* @return MessageQueueId_t of the object
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
/**
* Execute or initialize the execution of a certain function.

View File

@ -10,9 +10,10 @@ public:
void step(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
void finish(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
ReturnValue_t reportData(SerializeIF* data);
void resetHelper();
protected:
void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, store_address_t dataAddress);
virtual void resetHelper();
private:
bool isExecuting;
MessageQueueId_t lastCommander;

View File

@ -8,7 +8,7 @@ ControllerBase::ControllerBase(uint32_t setObjectId, uint32_t parentId,
size_t commandQueueDepth) :
SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF), submode(
SUBMODE_NONE), commandQueue(NULL), modeHelper(
this), healthHelper(this, setObjectId),hkSwitcher(this) {
this), healthHelper(this, setObjectId),hkSwitcher(this),executingTask(NULL) {
commandQueue = QueueFactory::instance()->createMessageQueue(commandQueueDepth);
}
@ -129,6 +129,9 @@ ReturnValue_t ControllerBase::setHealth(HealthState health) {
HasHealthIF::HealthState ControllerBase::getHealth() {
return healthHelper.getHealth();
}
void ControllerBase::setTaskIF(PeriodicTaskIF* task_){
executingTask = task_;
}
void ControllerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
}

View File

@ -32,6 +32,16 @@ public:
virtual ReturnValue_t setHealth(HealthState health);
virtual HasHealthIF::HealthState getHealth();
/**
* 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_);
protected:
const uint32_t parentId;
@ -47,6 +57,11 @@ protected:
HkSwitchHelper hkSwitcher;
/**
* Pointer to the task which executes this component, is invalid before setTaskIF was called.
*/
PeriodicTaskIF* executingTask;
void handleQueue();
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;

View File

@ -2,6 +2,7 @@
#define COORDINATETRANSFORMATIONS_H_
#include <framework/timemanager/Clock.h>
#include <cstring>
class CoordinateTransformations {
public:

View File

@ -8,7 +8,7 @@
DataPoolAdmin::DataPoolAdmin(object_id_t objectId) :
SystemObject(objectId), storage(NULL), commandQueue(NULL), memoryHelper(
this, commandQueue), actionHelper(this, commandQueue) {
this, NULL), actionHelper(this, NULL) {
commandQueue = QueueFactory::instance()->createMessageQueue();
}
@ -171,7 +171,7 @@ ReturnValue_t DataPoolAdmin::initialize() {
return result;
}
result = memoryHelper.initialize();
result = memoryHelper.initialize(commandQueue);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
@ -181,7 +181,7 @@ ReturnValue_t DataPoolAdmin::initialize() {
return HasReturnvaluesIF::RETURN_FAILED;
}
result = actionHelper.initialize();
result = actionHelper.initialize(commandQueue);
return result;
}

View File

@ -24,6 +24,8 @@ public:
ReturnValue_t switchHK(SerializeIF *sids, bool enable);
virtual void setTaskIF(PeriodicTaskIF* task_){};
protected:
virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step);
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step,

View File

@ -76,13 +76,13 @@ ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
return DATA_POOL_ACCESS_FAILED;
if (typeSize > max_size)
return INCORRECT_SIZE;
#ifndef BYTE_ORDER
#error BYTE_ORDER not defined
#elif BYTE_ORDER == LITTLE_ENDIAN
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) {
buffer[count] = data_ptr[typeSize - count - 1];
}
#elif BYTE_ORDER == BIG_ENDIAN
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(buffer, data_ptr, typeSize);
#endif
*writtenBytes = typeSize;
@ -112,13 +112,13 @@ PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t* buffer,
uint32_t setSize) {
if (typeSize == setSize) {
#ifndef BYTE_ORDER
#error BYTE_ORDER not defined
#elif BYTE_ORDER == LITTLE_ENDIAN
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) {
value[count] = buffer[typeSize - count - 1];
}
#elif BYTE_ORDER == BIG_ENDIAN
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(value, buffer, typeSize);
#endif
return HasReturnvaluesIF::RETURN_OK;
@ -149,13 +149,13 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size,
const uint32_t max_size, bool bigEndian) const {
if (typeSize + *size <= max_size) {
if (bigEndian) {
#ifndef BYTE_ORDER
#error BYTE_ORDER not defined
#elif BYTE_ORDER == LITTLE_ENDIAN
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) {
(*buffer)[count] = value[typeSize - count - 1];
}
#elif BYTE_ORDER == BIG_ENDIAN
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(*buffer, value, typeSize);
#endif
} else {
@ -179,13 +179,13 @@ ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, int32_t* size,
if (*size >= 0) {
if (bigEndian) {
#ifndef BYTE_ORDER
#error BYTE_ORDER not defined
#elif BYTE_ORDER == LITTLE_ENDIAN
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) {
value[count] = (*buffer)[typeSize - count - 1];
}
#elif BYTE_ORDER == BIG_ENDIAN
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(value, *buffer, typeSize);
#endif
} else {

View File

@ -30,19 +30,7 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress,
thermalRequestPoolId), healthHelper(this, setObjectId), modeHelper(
this), parameterHelper(this), childTransitionFailure(RETURN_OK), ignoreMissedRepliesCount(
0), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(
fdirInstance == NULL), switchOffWasReported(false), executingTask(
NULL), actionHelper(this, commandQueue), cookieInfo(), ioBoardAddress(
//=======
// NULL), IPCStore(NULL), deviceCommunicationId(deviceCommunication), communicationInterface(
// NULL), cookie(
// NULL), commandQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE), deviceThermalStatePoolId(
// thermalStatePoolId), deviceThermalRequestPoolId(
// thermalRequestPoolId), healthHelper(this, setObjectId), modeHelper(
// this), parameterHelper(this), childTransitionFailure(RETURN_OK), ignoreMissedRepliesCount(
// 0), fdirInstance(fdirInstance), defaultFDIRUsed(
// fdirInstance == NULL), switchOffWasReported(false), actionHelper(
// this, &commandQueue), cookieInfo(), ioBoardAddress(
//>>>>>>> makefile
fdirInstance == NULL), switchOffWasReported(false),executingTask(NULL), actionHelper(this, NULL), cookieInfo(), ioBoardAddress(
ioBoardAddress), timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(
_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(
setDeviceSwitch) {
@ -636,7 +624,7 @@ ReturnValue_t DeviceHandlerBase::initialize() {
if (result != RETURN_OK) {
return result;
}
result = actionHelper.initialize();
result = actionHelper.initialize(commandQueue);
if (result != RETURN_OK) {
return result;
}
@ -1021,10 +1009,6 @@ ReturnValue_t DeviceHandlerBase::acceptExternalDeviceCommands() {
return RETURN_OK;
}
void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* interface) {
executingTask = interface;
}
void DeviceHandlerBase::replyRawReplyIfnotWiretapped(const uint8_t* data,
size_t len) {
if ((wiretappingMode == RAW)
@ -1281,3 +1265,7 @@ bool DeviceHandlerBase::commandIsExecuting(DeviceCommandId_t commandId) {
void DeviceHandlerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
}
void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){
executingTask = task_;
}

View File

@ -92,8 +92,13 @@ public:
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex);
void setTaskIF(PeriodicTaskIF* interface);
/**
* 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_);
protected:
/**
* The Returnvalues id of this class, required by HasReturnvaluesIF
@ -248,13 +253,13 @@ protected:
bool switchOffWasReported; //!< Indicates if SWITCH_WENT_OFF was already thrown.
PeriodicTaskIF* executingTask;//!< Pointer to the task which executes this component, is invalid before setTaskIF was called.
static object_id_t powerSwitcherId; //!< Object which switches power on and off.
static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default.
static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault.
PeriodicTaskIF* executingTask;
/**
* Helper function to report a missed reply
*
@ -787,7 +792,6 @@ protected:
DeviceCommandMap deviceCommandMap;
ActionHelper actionHelper;
private:
/**

View File

@ -17,7 +17,6 @@ FixedSlotSequence::~FixedSlotSequence() {
}
void FixedSlotSequence::executeAndAdvance() {
// (*this->current)->print();
(*this->current)->handler->performOperation((*this->current)->opcode);
// if (returnValue != RETURN_OK) {
// this->sendErrorMessage( returnValue );

View File

@ -34,7 +34,6 @@ public:
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
bool reporterInverted = false);
ReturnValue_t performOperation(uint8_t opCode);
protected:
MessageQueueIF* eventReportQueue;

View File

@ -39,10 +39,7 @@ endif
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/parameters/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/power/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/returnvalues/*.cpp)
# easier without it for now
#CXXSRC += $(wildcard $(FRAMEWORK_PATH)/rmap/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/rmap/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/serialize/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/serviceinterface/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/storagemanager/*.cpp)
@ -56,4 +53,4 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmstorage/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/packetmatcher/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/pus/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp)

View File

@ -1,5 +1,4 @@
#include <framework/globalfunctions/conversion.h>
//TODO REMOVE. Needed because of BYTE_ORDER
#include <framework/osal/Endiness.h>
#include <cstring>
@ -59,9 +58,9 @@ void convertToByteStream( int32_t value, uint8_t* buffer, uint32_t* size ) {
//}
void convertToByteStream( float in_value, uint8_t* buffer, uint32_t* size ) {
#ifndef BYTE_ORDER
#error BYTE_ORDER not defined
#elif BYTE_ORDER == LITTLE_ENDIAN
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
union float_union {
float value;
uint8_t chars[4];
@ -73,16 +72,16 @@ void convertToByteStream( float in_value, uint8_t* buffer, uint32_t* size ) {
buffer[2] = temp.chars[1];
buffer[3] = temp.chars[0];
*size += 4;
#elif BYTE_ORDER == BIG_ENDIAN
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(buffer, &in_value, sizeof(in_value));
*size += sizeof(in_value);
#endif
}
void convertToByteStream( double in_value, uint8_t* buffer, uint32_t* size ) {
#ifndef BYTE_ORDER
#error Endianess not defined
#elif BYTE_ORDER == LITTLE_ENDIAN
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
union double_union {
double value;
uint8_t chars[8];
@ -98,7 +97,7 @@ void convertToByteStream( double in_value, uint8_t* buffer, uint32_t* size ) {
buffer[6] = temp.chars[1];
buffer[7] = temp.chars[0];
*size += 8;
#elif BYTE_ORDER == BIG_ENDIAN
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(buffer, &in_value, sizeof(in_value));
*size += sizeof(in_value);
#endif

View File

@ -22,7 +22,6 @@ public:
virtual void lostTm();
virtual void storeFull();
protected:
MutexIF* mutex;

View File

@ -5,11 +5,22 @@
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/ipc/MessageQueueSenderIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
class MessageQueueIF {
public:
static const MessageQueueId_t NO_QUEUE = MessageQueueSenderIF::NO_QUEUE; //!< Ugly hack.
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
/**
* No new messages on the queue
*/
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(1);
/**
* No space left for more messages
*/
static const ReturnValue_t FULL = MAKE_RETURN_CODE(2);
virtual ~MessageQueueIF() {}
/**
* @brief This operation sends a message to the last communication partner.
@ -65,16 +76,32 @@ public:
* This variable is set to zero by default.
* \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full (if implemented).
*/
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ) = 0;
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0;
/**
* @brief This operation sends a message to the given destination.
* @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its
* queue id as "sentFrom" parameter.
* @param sendTo This parameter specifies the message queue id of the destination message queue.
* @param message A pointer to a previously created message, which is sent.
* @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message, bool ignoreFault = false ) = 0;
/**
* \brief The sendToDefault method sends a queue message to the default destination.
* \brief The sendToDefaultFrom method sends a queue message to the default destination.
* \details In all other aspects, it works identical to the sendMessage method.
* \param message This is a pointer to a previously created message, which is sent.
* \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message.
* This variable is set to zero by default.
*/
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ) = 0;
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0;
/**
* @brief This operation sends a message to the default destination.
* @details As in the sendMessage method, this function uses the sendToDefault call of the
* Implementation class and adds its queue id as "sentFrom" information.
* @param message A pointer to a previously created message, which is sent.
*/
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ) = 0;
/**
* \brief This method is a simple setter for the default destination.
*/

24
ipc/MutexHelper.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef FRAMEWORK_IPC_MUTEXHELPER_H_
#define FRAMEWORK_IPC_MUTEXHELPER_H_
#include <framework/ipc/MutexFactory.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
class MutexHelper {
public:
MutexHelper(MutexIF* mutex, uint32_t timeoutMs) :
internalMutex(mutex) {
ReturnValue_t status = mutex->lockMutex(timeoutMs);
if(status != HasReturnvaluesIF::RETURN_OK){
error << "MutexHelper: Lock of Mutex failed " << status << std::endl;
}
}
~MutexHelper() {
internalMutex->unlockMutex();
}
private:
MutexIF* internalMutex;
};
#endif /* FRAMEWORK_IPC_MUTEXHELPER_H_ */

View File

@ -6,6 +6,57 @@
class MutexIF {
public:
static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation.
static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF;
/**
* The system lacked the necessary resources (other than memory) to initialize another mutex.
*/
static const ReturnValue_t NOT_ENOUGH_RESOURCES = MAKE_RETURN_CODE(1);
/**
* Insufficient memory to create or init Mutex
*/
static const ReturnValue_t INSUFFICIENT_MEMORY = MAKE_RETURN_CODE(2);
/**
* Caller does not have enough or right privilege
*/
static const ReturnValue_t NO_PRIVILEGE = MAKE_RETURN_CODE(3);
/**
* Wrong Attribute Setting
*/
static const ReturnValue_t WRONG_ATTRIBUTE_SETTING = MAKE_RETURN_CODE(4);
/**
* The mutex is already locked
*/
static const ReturnValue_t MUTEX_ALREADY_LOCKED = MAKE_RETURN_CODE(5);
/**
* Mutex object not found
*/
static const ReturnValue_t MUTEX_NOT_FOUND = MAKE_RETURN_CODE(6);
/**
* Mutex could not be locked because max amount of recursive locks
*/
static const ReturnValue_t MUTEX_MAX_LOCKS = MAKE_RETURN_CODE(7);
/**
* The current thread already owns this mutex
*/
static const ReturnValue_t CURR_THREAD_ALREADY_OWNS_MUTEX = MAKE_RETURN_CODE(8);
/**
* Current thread does not own this mutex
*/
static const ReturnValue_t CURR_THREAD_DOES_NOT_OWN_MUTEX = MAKE_RETURN_CODE(9);
/**
* The Mutex could not be blocked before timeout
*/
static const ReturnValue_t MUTEX_TIMEOUT = MAKE_RETURN_CODE(10);
/**
* Invalid Mutex ID
*/
static const ReturnValue_t MUTEX_INVALID_ID = MAKE_RETURN_CODE(11);
/**
* Mutex destroyed while waiting
*/
static const ReturnValue_t MUTEX_DESTROYED_WHILE_WAITING = MAKE_RETURN_CODE(12);
virtual ~MutexIF() {}
virtual ReturnValue_t lockMutex(uint32_t timeoutMs) = 0;
virtual ReturnValue_t unlockMutex() = 0;

View File

@ -8,7 +8,7 @@
LocalMemory::LocalMemory(object_id_t setObjectId) :
SystemObject(setObjectId), commandQueue(NULL), memoryHelper(this,
commandQueue) {
NULL) {
commandQueue = QueueFactory::instance()->createMessageQueue();
}
@ -52,7 +52,7 @@ ReturnValue_t LocalMemory::handleMemoryDump(uint32_t address, uint32_t size,
}
ReturnValue_t LocalMemory::initialize() {
return memoryHelper.initialize();
return memoryHelper.initialize(commandQueue);
}
MessageQueueId_t LocalMemory::getCommandQueue() const {

View File

@ -183,3 +183,13 @@ void MemoryHelper::handleMemoryCheckOrDump(CommandMessage* message) {
queueToUse->sendMessage(lastSender, &reply);
}
}
ReturnValue_t MemoryHelper::initialize(MessageQueueIF* queueToUse_) {
if(queueToUse_!=NULL){
this->queueToUse = queueToUse_;
}else{
return MessageQueueIF::NO_QUEUE;
}
return initialize();
}

View File

@ -24,12 +24,13 @@ private:
bool busy;
void handleMemoryLoad(CommandMessage* message);
void handleMemoryCheckOrDump(CommandMessage* message);
ReturnValue_t initialize();
public:
ReturnValue_t handleMemoryCommand(CommandMessage* message);
void completeLoad( ReturnValue_t errorCode, const uint8_t* dataToCopy = NULL, const uint32_t size = 0, uint8_t* copyHere = NULL );
void completeDump( ReturnValue_t errorCode, const uint8_t* dataToCopy = NULL, const uint32_t size = 0);
void swapMatrixCopy( uint8_t *out, const uint8_t *in, uint32_t totalSize, uint8_t datatypeSize);
ReturnValue_t initialize();
ReturnValue_t initialize(MessageQueueIF* queueToUse_);
MemoryHelper( HasMemoryIF* workOnThis, MessageQueueIF* useThisQueue );
~MemoryHelper();
};

View File

@ -19,11 +19,11 @@ public:
}
ReturnValue_t doCheck(T lowSample, T highSample) {
T crossedLimit;
ReturnValue_t currentState = checkSample(lowSample, &crossedLimit);
ReturnValue_t currentState = this->checkSample(lowSample, &crossedLimit);
if (currentState != HasReturnvaluesIF::RETURN_OK) {
return this->monitorStateIs(currentState, lowSample, crossedLimit);
}
currentState = checkSample(highSample, &crossedLimit);
currentState = this->checkSample(highSample, &crossedLimit);
return this->monitorStateIs(currentState, highSample, crossedLimit);
}
protected:

View File

@ -12,16 +12,19 @@
#define LITTLE_ENDIAN 1234
#endif
// This is a GCC C extension
#ifndef BYTE_ORDER
#ifndef BYTE_ORDER_SYSTEM
#ifdef __BYTE_ORDER__
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define BYTE_ORDER BIG_ENDIAN
#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define BYTE_ORDER LITTLE_ENDIAN
#define BYTE_ORDER_SYSTEM BIG_ENDIAN
#else
#error "Can't decide which end is which!"
#endif
#else
#error __BYTE_ORDER__ not defined
#endif
#endif

View File

@ -21,16 +21,16 @@ MessageQueue::~MessageQueue() {
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault) {
return sendMessage(sendTo, message, this->getId(), ignoreFault);
return sendMessageFrom(sendTo, message, this->getId(), ignoreFault);
}
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) {
return sendToDefault(message, this->getId());
return sendToDefaultFrom(message, this->getId());
}
ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) {
if (this->lastPartner != 0) {
return sendMessage(this->lastPartner, message, this->getId());
return sendMessageFrom(this->lastPartner, message, this->getId());
} else {
//TODO: Good returnCode
return HasReturnvaluesIF::RETURN_FAILED;
@ -49,8 +49,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
if (result == pdPASS){
return HasReturnvaluesIF::RETURN_OK;
} else {
//TODO Queue Empty
return HasReturnvaluesIF::RETURN_FAILED;
return MessageQueueIF::EMPTY;
}
}
@ -73,7 +72,7 @@ void MessageQueue::setDefaultDestination(MessageQueueId_t defaultDestination) {
this->defaultDestination = defaultDestination;
}
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom,
bool ignoreFault) {
message->setSender(sentFrom);
@ -83,15 +82,14 @@ ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
if (!ignoreFault) {
//TODO errr reporter
}
//TODO queue is full
return HasReturnvaluesIF::RETURN_FAILED;
return MessageQueueIF::FULL;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message,
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message,
MessageQueueId_t sentFrom, bool ignoreFault) {
return 0;
return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault);
}
MessageQueueId_t MessageQueue::getDefaultDestination() const {

View File

@ -117,7 +117,7 @@ public:
* This variable is set to zero by default.
* \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
/**
* \brief The sendToDefault method sends a queue message to the default destination.
* \details In all other aspects, it works identical to the sendMessage method.
@ -125,7 +125,7 @@ public:
* \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message.
* This variable is set to zero by default.
*/
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
/**
* \brief This method is a simple setter for the default destination.
*/

View File

@ -1,31 +1,32 @@
//entry point into "bsp"
void init(void);
#include <FreeRTOS.h>
#include <FreeRTOSConfig.h>
#include "task.h"
void initTask(void *parameters) {
init();
}
int main(void) {
if ( pdPASS
!= xTaskCreate(initTask, "init", 512, NULL,
configMAX_PRIORITIES - 1, NULL)) {
//print_uart0("Could not create task1\r\n");
}
vTaskStartScheduler();
//Scheduler should never return
//print_uart0("This is bad\n");
for (;;)
;
return 0;
}
//TODO This can be done mission dependent and some low level calls before vTaskStartScheduler might be important
//void init(void);
//
//#include <FreeRTOS.h>
//#include <FreeRTOSConfig.h>
//#include "task.h"
//
//
//void initTask(void *parameters) {
// init();
//}
//
//int main(void) {
//
// if ( pdPASS
// != xTaskCreate(initTask, "init", 512, NULL,
// configMAX_PRIORITIES - 1, NULL)) {
// //print_uart0("Could not create task1\r\n");
// }
//
// vTaskStartScheduler();
//
// //Scheduler should never return
//
// //print_uart0("This is bad\n");
//
// for (;;)
// ;
//
// return 0;
//}

View File

@ -1,144 +0,0 @@
#ifndef FRAMEWORK_OSAL_OPERATINGSYSTEMIF_H_
#define FRAMEWORK_OSAL_OPERATINGSYSTEMIF_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
class OperatingSystemIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::OPERATING_SYSTEM_ABSTRACTION;
//API Status codes, must be implemented by the Operating System (TODO comments based on rtems status.h):
/**
* This is the status to indicate successful completion.
*/
static const ReturnValue_t SUCCESSFUL = MAKE_RETURN_CODE(0);
/**
* This is the status to indicate that a thread exited.
*/
static const ReturnValue_t TASK_EXITTED = MAKE_RETURN_CODE(1);
/**
* This is the status to indicate multiprocessing is not configured.
*/
static const ReturnValue_t MP_NOT_CONFIGURED = MAKE_RETURN_CODE(2);
/**
* This is the status to indicate that the object name was invalid.
*/
static const ReturnValue_t INVALID_NAME = MAKE_RETURN_CODE(3);
/**
* This is the status to indicate that the object Id was invalid.
*/
static const ReturnValue_t INVALID_ID = MAKE_RETURN_CODE(4);
/**
* This is the status to indicate you have attempted to create too many
* instances of a particular object class.
*
* Used for full messages Queues as well
*/
static const ReturnValue_t TOO_MANY = MAKE_RETURN_CODE(5);
/**
* This is the status to indicate that a blocking directive timed out.
*/
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(6);
/**
* This is the status to indicate the the object was deleted
* while the task was blocked waiting.
*/
static const ReturnValue_t OBJECT_WAS_DELETED = MAKE_RETURN_CODE(7);
/**
* This is the status to indicate that the specified size was invalid.
*/
static const ReturnValue_t INVALID_SIZE = MAKE_RETURN_CODE(8);
/**
* This is the status to indicate that the specified address is invalid.
*/
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(9);
/**
* This is the status to indicate that the specified number was invalid.
*/
static const ReturnValue_t INVALID_NUMBER = MAKE_RETURN_CODE(10);
/**
* This is the status to indicate that the item has not been initialized.
*/
static const ReturnValue_t NOT_DEFINED =MAKE_RETURN_CODE(11);
/**
* This is the status to indicate that the object still has
* resources in use.
*/
static const ReturnValue_t RESOURCE_IN_USE =MAKE_RETURN_CODE(12);
/**
* This is the status to indicate that the request was not satisfied.
*/
static const ReturnValue_t UNSATISFIED =MAKE_RETURN_CODE(13);
/**
* Indicates that a Message Queue is empty (unable to allocate it)
*/
static const ReturnValue_t QUEUE_EMPTY =MAKE_RETURN_CODE(14);
/**
* This is the status to indicate that a thread is in wrong state
* was in the wrong execution state for the requested operation.
*/
static const ReturnValue_t INCORRECT_STATE =MAKE_RETURN_CODE(15);
/**
* This is the status to indicate thread was already suspended.
*/
static const ReturnValue_t ALREADY_SUSPENDED = MAKE_RETURN_CODE(16);
/**
* This is the status to indicate that the operation is illegal
* on calling thread.
*/
static const ReturnValue_t ILLEGAL_ON_SELF =MAKE_RETURN_CODE(17);
/**
* This is the status to indicate illegal for remote object.
*/
static const ReturnValue_t ILLEGAL_ON_REMOTE_OBJECT=MAKE_RETURN_CODE(18);
/**
* This is the status to indicate that the operation should not be
* called from from this excecution environment.
*/
static const ReturnValue_t CALLED_FROM_ISR=MAKE_RETURN_CODE(19);
/**
* This is the status to indicate that an invalid thread priority
* was provided.
*/
static const ReturnValue_t INVALID_PRIORITY=MAKE_RETURN_CODE(20);
/**
* This is the status to indicate that the specified date/time was invalid.
*/
static const ReturnValue_t INVALID_CLOCK=MAKE_RETURN_CODE(21);
/**
* This is the status to indicate that the specified node Id was invalid.
*/
static const ReturnValue_t INVALID_NODE=MAKE_RETURN_CODE(22);
/**
* This is the status to indicate that the directive was not configured.
*/
static const ReturnValue_t NOT_CONFIGURED=MAKE_RETURN_CODE(23);
/**
* This is the status to indicate that the caller is not the
* owner of the resource.
*/
static const ReturnValue_t NOT_OWNER_OF_RESOURCE=MAKE_RETURN_CODE(24);
/**
* This is the status to indicate the the directive or requested
* portion of the directive is not implemented.
*/
static const ReturnValue_t NOT_IMPLEMENTED=MAKE_RETURN_CODE(25);
/**
* This is the status to indicate that an internal RTEMS inconsistency
* was detected.
*/
static const ReturnValue_t INTERNAL_ERROR=MAKE_RETURN_CODE(26);
/**
* This is the status to indicate that the directive attempted to allocate
* memory but was unable to do so.
*/
static const ReturnValue_t NO_MEMORY=MAKE_RETURN_CODE(27);
/**
* This is the status to indicate an driver IO error.
*/
static const ReturnValue_t IO_ERROR=MAKE_RETURN_CODE(28);
virtual ~OperatingSystemIF() {};
};
#endif /* FRAMEWORK_OSAL_OPERATINGSYSTEMIF_H_ */

View File

@ -8,25 +8,21 @@
#include <unistd.h>
//#include <fstream>
uint16_t Clock::leapSeconds = 0;
MutexIF* Clock::timeMutex = NULL;
uint32_t Clock::getTicksPerSecond(void){
//TODO This function returns the ticks per second for thread ticks not clock ticks
// timespec ticks;
// int status = clock_getres(CLOCK_REALTIME,&ticks);
//
// if(status!=0){
// //TODO errno
// return 0xFFFFFFFF;
// }
// uint32_t resolution = 1e9 / ticks.tv_nsec;
uint32_t resolution = sysconf(_SC_CLK_TCK);
return resolution;
uint32_t ticks = sysconf(_SC_CLK_TCK);
return ticks;
}
ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
//TODO timeOfDay conversion
timespec timeUnix;
timeval timeTimeval;
convertTimeOfDayToTimeval(time,&timeTimeval);
timeUnix.tv_sec = timeTimeval.tv_sec;
timeUnix.tv_nsec = (__syscall_slong_t) timeTimeval.tv_usec * 1000;
int status = clock_settime(CLOCK_REALTIME,&timeUnix);
if(status!=0){
//TODO errno
@ -109,14 +105,6 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
//TODO errno
return HasReturnvaluesIF::RETURN_FAILED;
}
timespec ticks;
status = clock_getres(CLOCK_REALTIME,&ticks);
if(status!=0){
//TODO errno
return HasReturnvaluesIF::RETURN_FAILED;
}
uint32_t resolution = 1e9 / ticks.tv_nsec;
struct tm* timeInfo;
timeInfo = gmtime(&timeUnix.tv_sec);
@ -126,7 +114,7 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
time->hour = timeInfo->tm_hour;
time->minute = timeInfo->tm_min;
time->second = timeInfo->tm_sec;
time->ticks = (timeUnix.tv_nsec / (double) 1e9) * resolution;
time->usecond = timeUnix.tv_nsec / 1000.0;
return HasReturnvaluesIF::RETURN_OK;
}
@ -143,34 +131,81 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from,
fromTm.tm_min = from->minute;
fromTm.tm_sec = from->second;
timespec ticks;
uint32_t status = clock_getres(CLOCK_REALTIME,&ticks);
if(status!=0){
//TODO errno
return HasReturnvaluesIF::RETURN_FAILED;
}
uint32_t resolution = 1e9 / ticks.tv_nsec;
to->tv_sec = mktime(&fromTm);
to->tv_usec = (from->ticks /(double) resolution) * 1e6;
to->tv_usec = from->usecond;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) {
return HasReturnvaluesIF::RETURN_FAILED;
*JD2000 = (time.tv_sec - 946728000. + time.tv_usec / 1000000.) / 24.
/ 3600.;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval* tt) {
return HasReturnvaluesIF::RETURN_FAILED;
//SHOULDDO: works not for dates in the past (might have less leap seconds)
if (timeMutex == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
uint16_t leapSeconds;
ReturnValue_t result = getLeapSeconds(&leapSeconds);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
timeval leapSeconds_timeval = { 0, 0 };
leapSeconds_timeval.tv_sec = leapSeconds;
//initial offset between UTC and TAI
timeval UTCtoTAI1972 = { 10, 0 };
timeval TAItoTT = { 32, 184000 };
*tt = utc + leapSeconds_timeval + UTCtoTAI1972 + TAItoTT;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) {
return HasReturnvaluesIF::RETURN_FAILED;
if(checkOrCreateClockMutex()!=HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
leapSeconds = leapSeconds_;
result = timeMutex->unlockMutex();
return result;
}
ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) {
return HasReturnvaluesIF::RETURN_FAILED;
if(timeMutex==NULL){
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
*leapSeconds_ = leapSeconds;
result = timeMutex->unlockMutex();
return result;
}
ReturnValue_t Clock::checkOrCreateClockMutex(){
if(timeMutex==NULL){
MutexFactory* mutexFactory = MutexFactory::instance();
if (mutexFactory == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}