Renaming of global data pool files #186
@ -1,15 +0,0 @@
|
||||
#ifndef CONTROLLERSET_H_
|
||||
#define CONTROLLERSET_H_
|
||||
|
||||
#include "DataSet.h"
|
||||
|
||||
class ControllerSet :public DataSet {
|
||||
public:
|
||||
ControllerSet();
|
||||
virtual ~ControllerSet();
|
||||
|
||||
virtual void setToDefault() = 0;
|
||||
void setInvalid();
|
||||
};
|
||||
|
||||
#endif /* CONTROLLERSET_H_ */
|
@ -1,131 +0,0 @@
|
||||
#include "DataPool.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
|
||||
DataPool::DataPool( void ( *initFunction )( std::map<uint32_t, PoolEntryIF*>* pool_map ) ) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
if (initFunction != NULL ) {
|
||||
initFunction( &this->data_pool );
|
||||
}
|
||||
}
|
||||
|
||||
DataPool::~DataPool() {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
for ( std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.begin(); it != this->data_pool.end(); ++it ) {
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
//The function checks PID, type and array length before returning a copy of the PoolEntry. In failure case, it returns a temp-Entry with size 0 and NULL-ptr.
|
||||
template <typename T> PoolEntry<T>* DataPool::getData( uint32_t data_pool_id, uint8_t sizeOrPosition ) {
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
if ( it != this->data_pool.end() ) {
|
||||
PoolEntry<T>* entry = dynamic_cast< PoolEntry<T>* >( it->second );
|
||||
if (entry != NULL ) {
|
||||
if ( sizeOrPosition <= entry->length ) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PoolEntryIF* DataPool::getRawData( uint32_t data_pool_id ) {
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
if ( it != this->data_pool.end() ) {
|
||||
return it->second;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//uint8_t DataPool::getRawData( uint32_t data_pool_id, uint8_t* address, uint16_t* size, uint32_t maxSize ) {
|
||||
// std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
// if ( it != this->data_pool.end() ) {
|
||||
// if ( it->second->getByteSize() <= maxSize ) {
|
||||
// *size = it->second->getByteSize();
|
||||
// memcpy( address, it->second->getRawData(), *size );
|
||||
// return DP_SUCCESSFUL;
|
||||
// }
|
||||
// }
|
||||
// *size = 0;
|
||||
// return DP_FAILURE;
|
||||
//}
|
||||
|
||||
ReturnValue_t DataPool::freeDataPoolLock() {
|
||||
ReturnValue_t status = mutex->unlockMutex();
|
||||
if ( status != RETURN_OK ) {
|
||||
sif::error << "DataPool::DataPool: unlock of mutex failed with error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t DataPool::lockDataPool() {
|
||||
ReturnValue_t status = mutex->lockMutex(MutexIF::BLOCKING);
|
||||
if ( status != RETURN_OK ) {
|
||||
sif::error << "DataPool::DataPool: lock of mutex failed with error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void DataPool::print() {
|
||||
sif::debug << "DataPool contains: " << std::endl;
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator dataPoolIt;
|
||||
dataPoolIt = this->data_pool.begin();
|
||||
while( dataPoolIt != this->data_pool.end() ) {
|
||||
sif::debug << std::hex << dataPoolIt->first << std::dec << " |";
|
||||
dataPoolIt->second->print();
|
||||
dataPoolIt++;
|
||||
}
|
||||
}
|
||||
|
||||
template PoolEntry<uint8_t>* DataPool::getData<uint8_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint16_t>* DataPool::getData<uint16_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint32_t>* DataPool::getData<uint32_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint64_t>* DataPool::getData<uint64_t>(uint32_t data_pool_id,
|
||||
uint8_t size);
|
||||
template PoolEntry<int8_t>* DataPool::getData<int8_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int16_t>* DataPool::getData<int16_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int32_t>* DataPool::getData<int32_t>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<float>* DataPool::getData<float>( uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<double>* DataPool::getData<double>(uint32_t data_pool_id,
|
||||
uint8_t size);
|
||||
|
||||
|
||||
uint32_t DataPool::PIDToDataPoolId(uint32_t parameter_id) {
|
||||
return (parameter_id >> 8) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
uint8_t DataPool::PIDToArrayIndex(uint32_t parameter_id) {
|
||||
return (parameter_id & 0x000000FF);
|
||||
}
|
||||
|
||||
uint32_t DataPool::poolIdAndPositionToPid(uint32_t poolId, uint8_t index) {
|
||||
return (poolId << 8) + index;
|
||||
}
|
||||
|
||||
|
||||
//SHOULDDO: Do we need a mutex lock here... I don't think so, as we only check static const values of elements in a list that do not change.
|
||||
//there is no guarantee in the standard, but it seems to me that the implementation is safe -UM
|
||||
ReturnValue_t DataPool::getType(uint32_t parameter_id, Type* type) {
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( PIDToDataPoolId(parameter_id));
|
||||
if ( it != this->data_pool.end() ) {
|
||||
*type = it->second->getType();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
*type = Type::UNKNOWN_TYPE;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
bool DataPool::exists(uint32_t parameterId) {
|
||||
uint32_t poolId = PIDToDataPoolId(parameterId);
|
||||
uint32_t index = PIDToArrayIndex(parameterId);
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( poolId );
|
||||
if (it != data_pool.end()) {
|
||||
if (it->second->getSize() >= index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
/**
|
||||
* \file DataPool.h
|
||||
*
|
||||
* \date 10/17/2012
|
||||
* \author Bastian Baetz
|
||||
*
|
||||
* \brief This file contains the definition of the DataPool class and (temporarily)
|
||||
* the "extern" definition of the global dataPool instance.
|
||||
*/
|
||||
|
||||
#ifndef DATAPOOL_H_
|
||||
#define DATAPOOL_H_
|
||||
|
||||
#include "PoolEntry.h"
|
||||
#include "../globalfunctions/Type.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* \defgroup data_pool Data Pool
|
||||
* This is the group, where all classes associated with Data Pool Handling belong to.
|
||||
* This includes classes to access Data Pool variables.
|
||||
*/
|
||||
|
||||
#define DP_SUCCESSFUL 0
|
||||
#define DP_FAILURE 1
|
||||
|
||||
/**
|
||||
* \brief This class represents the OBSW global data-pool.
|
||||
*
|
||||
* \details All variables are registered and space is allocated in an initialization
|
||||
* function, which is passed do the constructor.
|
||||
* Space for the variables is allocated on the heap (with a new call).
|
||||
* The data is found by a data pool id, which uniquely represents a variable.
|
||||
* Data pool variables should be used with a blackboard logic in mind,
|
||||
* which means read data is valid (if flagged so), but not necessarily up-to-date.
|
||||
* Variables are either single values or arrays.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class DataPool : public HasReturnvaluesIF {
|
||||
private:
|
||||
/**
|
||||
* \brief This is the actual data pool itself.
|
||||
* \details It is represented by a map
|
||||
* with the data pool id as index and a pointer to a single PoolEntry as value.
|
||||
*/
|
||||
std::map<uint32_t, PoolEntryIF*> data_pool;
|
||||
public:
|
||||
/**
|
||||
* \brief The mutex is created in the constructor and makes access mutual exclusive.
|
||||
* \details Locking and unlocking the pool is only done by the DataSet class.
|
||||
*/
|
||||
MutexIF* mutex;
|
||||
/**
|
||||
* \brief In the classes constructor, the passed initialization function is called.
|
||||
* \details To enable filling the pool,
|
||||
* a pointer to the map is passed, allowing direct access to the pool's content.
|
||||
* On runtime, adding or removing variables is forbidden.
|
||||
*/
|
||||
DataPool( void ( *initFunction )( std::map<uint32_t, PoolEntryIF*>* pool_map ) );
|
||||
/**
|
||||
* \brief The destructor iterates through the data_pool map and calls all Entries destructors to clean up the heap.
|
||||
*/
|
||||
~DataPool();
|
||||
/**
|
||||
* \brief This is the default call to access the pool.
|
||||
* \details A pointer to the PoolEntry object is returned.
|
||||
* The call checks data pool id, type and array size. Returns NULL in case of failure.
|
||||
* \param data_pool_id The data pool id to search.
|
||||
* \param sizeOrPosition The array size (not byte size!) of the pool entry, or the position the user wants to read.
|
||||
* If smaller than the entry size, everything's ok.
|
||||
*/
|
||||
template <typename T> PoolEntry<T>* getData( uint32_t data_pool_id, uint8_t sizeOrPosition );
|
||||
/**
|
||||
* \brief An alternative call to get a data pool entry in case the type is not implicitly known
|
||||
* (i.e. in Housekeeping Telemetry).
|
||||
* \details It returns a basic interface and does NOT perform
|
||||
* a size check. The caller has to assure he does not copy too much data.
|
||||
* Returns NULL in case the entry is not found.
|
||||
* \param data_pool_id The data pool id to search.
|
||||
*/
|
||||
PoolEntryIF* getRawData( uint32_t data_pool_id );
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate locking the global data pool.
|
||||
* \details It fetches the pool's mutex id and tries to acquire the mutex.
|
||||
*/
|
||||
ReturnValue_t lockDataPool();
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate unlocking the global data pool.
|
||||
* \details It fetches the pool's mutex id and tries to free the mutex.
|
||||
*/
|
||||
ReturnValue_t freeDataPoolLock();
|
||||
/**
|
||||
* \brief The print call is a simple debug method.
|
||||
* \details It prints the current content of the data pool.
|
||||
* It iterates through the data_pool map and calls each entry's print() method.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Extracts the data pool id from a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The data pool id as used within the OBSW.
|
||||
*/
|
||||
static uint32_t PIDToDataPoolId( uint32_t parameter_id );
|
||||
/**
|
||||
* Extracts an array index out of a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The index of the corresponding data pool entry.
|
||||
*/
|
||||
static uint8_t PIDToArrayIndex( uint32_t parameter_id );
|
||||
/**
|
||||
* Retransforms a data pool id and an array index to a SCOS 2000 PID.
|
||||
*/
|
||||
static uint32_t poolIdAndPositionToPid( uint32_t poolId, uint8_t index );
|
||||
|
||||
/**
|
||||
* Method to return the type of a pool variable.
|
||||
* @param parameter_id A parameterID (not pool id) of a DP member.
|
||||
* @param type Returns the type or TYPE::UNKNOWN_TYPE
|
||||
* @return RETURN_OK if parameter exists, RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getType( uint32_t parameter_id, Type* type );
|
||||
|
||||
/**
|
||||
* Method to check if a PID exists.
|
||||
* Does not lock, as there's no possibility to alter the list that is checked during run-time.
|
||||
* @param parameterId The PID (not pool id!) of a parameter.
|
||||
* @return true if exists, false else.
|
||||
*/
|
||||
bool exists(uint32_t parameterId);
|
||||
};
|
||||
|
||||
//We assume someone globally instantiates a DataPool.
|
||||
extern DataPool dataPool;
|
||||
#endif /* DATAPOOL_H_ */
|
@ -1,150 +0,0 @@
|
||||
#include "DataSet.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
DataSet::DataSet() :
|
||||
fill_count(0), state(DATA_SET_UNINITIALISED) {
|
||||
for (unsigned count = 0; count < DATA_SET_MAX_SIZE; count++) {
|
||||
registeredVariables[count] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DataSet::~DataSet() {
|
||||
//Don't do anything with your variables, they are dead already! (Destructor is already called)
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::read() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
if (state == DATA_SET_UNINITIALISED) {
|
||||
lockDataPool();
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_WRITE
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
ReturnValue_t status = registeredVariables[count]->read();
|
||||
if (status != RETURN_OK) {
|
||||
result = INVALID_PARAMETER_DEFINITION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = DATA_SET_WAS_READ;
|
||||
freeDataPoolLock();
|
||||
} else {
|
||||
sif::error << "DataSet::read(): Call made in wrong position." << std::endl;
|
||||
result = SET_WAS_ALREADY_READ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::commit(uint8_t valid) {
|
||||
setValid(valid);
|
||||
return commit();
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::commit() {
|
||||
if (state == DATA_SET_WAS_READ) {
|
||||
lockDataPool();
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commit();
|
||||
}
|
||||
}
|
||||
state = DATA_SET_UNINITIALISED;
|
||||
freeDataPoolLock();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
lockDataPool();
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
== PoolVariableIF::VAR_WRITE
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commit();
|
||||
} else if (registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
if (result != COMMITING_WITHOUT_READING) {
|
||||
sif::error <<
|
||||
"DataSet::commit(): commit-without-read "
|
||||
"call made with non write-only variable." << std::endl;
|
||||
result = COMMITING_WITHOUT_READING;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = DATA_SET_UNINITIALISED;
|
||||
freeDataPoolLock();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DataSet::registerVariable(PoolVariableIF* variable) {
|
||||
if (state == DATA_SET_UNINITIALISED) {
|
||||
if (variable != NULL) {
|
||||
if (fill_count < DATA_SET_MAX_SIZE) {
|
||||
registeredVariables[fill_count] = variable;
|
||||
fill_count++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sif::error
|
||||
<< "DataSet::registerVariable: failed. Either NULL, or set is full, or call made in wrong position."
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t DataSet::freeDataPoolLock() {
|
||||
return ::dataPool.freeDataPoolLock();
|
||||
}
|
||||
|
||||
uint8_t DataSet::lockDataPool() {
|
||||
return ::dataPool.lockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t DataSet::getSerializedSize() const {
|
||||
size_t size = 0;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
size += registeredVariables[count]->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void DataSet::setValid(uint8_t valid) {
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ) {
|
||||
registeredVariables[count]->setValid(valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||
streamEndianness);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
/*
|
||||
* \file DataSet.h
|
||||
*
|
||||
* \brief This file contains the DataSet class and a small structure called DataSetContent.
|
||||
*
|
||||
* \date 10/17/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DATASET_H_
|
||||
#define DATASET_H_
|
||||
|
||||
#include "DataPool.h"
|
||||
#include "DataSetIF.h"
|
||||
#include "PoolRawAccess.h"
|
||||
#include "PoolVariable.h"
|
||||
#include "PoolVarList.h"
|
||||
#include "PoolVector.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
/**
|
||||
* \brief The DataSet class manages a set of locally checked out variables.
|
||||
*
|
||||
* \details This class manages a list, where a set of local variables (or pool variables) are
|
||||
* registered. They are checked-out (i.e. their values are looked up and copied)
|
||||
* with the read call. After the user finishes working with the pool variables,
|
||||
* he can write back all variable values to the pool with the commit call.
|
||||
* The data set manages locking and freeing the data pool, to ensure that all values
|
||||
* are read and written back at once.
|
||||
* An internal state manages usage of this class. Variables may only be registered before
|
||||
* the read call is made, and the commit call only after the read call.
|
||||
* If pool variables are writable and not committed until destruction of the set, the
|
||||
* DataSet class automatically sets the valid flag in the data pool to invalid (without)
|
||||
* changing the variable's value.
|
||||
*
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class DataSet: public DataSetIF, public HasReturnvaluesIF, public SerializeIF {
|
||||
private:
|
||||
//SHOULDDO we could use a linked list of datapool variables
|
||||
static const uint8_t DATA_SET_MAX_SIZE = 63; //!< This definition sets the maximum number of variables to register in one DataSet.
|
||||
|
||||
/**
|
||||
* \brief This array represents all pool variables registered in this set.
|
||||
* \details It has a maximum size of DATA_SET_MAX_SIZE.
|
||||
*/
|
||||
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
|
||||
/**
|
||||
* \brief The fill_count attribute ensures that the variables register in the correct array
|
||||
* position and that the maximum number of variables is not exceeded.
|
||||
*/
|
||||
uint16_t fill_count;
|
||||
/**
|
||||
* States of the seet.
|
||||
*/
|
||||
enum States {
|
||||
DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||
DATA_SET_WAS_READ //!< DATA_SET_WAS_READ
|
||||
};
|
||||
/**
|
||||
* \brief state manages the internal state of the data set, which is important e.g. for the
|
||||
* behavior on destruction.
|
||||
*/
|
||||
States state;
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate locking the global data pool.
|
||||
* \details It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
uint8_t lockDataPool();
|
||||
/**
|
||||
* \brief This is a small helper function to facilitate unlocking the global data pool.
|
||||
* \details It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
uint8_t freeDataPoolLock();
|
||||
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS;
|
||||
static const ReturnValue_t INVALID_PARAMETER_DEFINITION =
|
||||
MAKE_RETURN_CODE( 0x01 );
|
||||
static const ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE( 0x02 );
|
||||
static const ReturnValue_t COMMITING_WITHOUT_READING =
|
||||
MAKE_RETURN_CODE(0x03);
|
||||
|
||||
/**
|
||||
* \brief The constructor simply sets the fill_count to zero and sets the state to "uninitialized".
|
||||
*/
|
||||
DataSet();
|
||||
/**
|
||||
* \brief The destructor automatically manages writing the valid information of variables.
|
||||
* \details In case the data set was read out, but not committed (indicated by state),
|
||||
* the destructor parses all variables that are still registered to the set.
|
||||
* For each, the valid flag in the data pool is set to "invalid".
|
||||
*/
|
||||
~DataSet();
|
||||
/**
|
||||
* \brief The read call initializes reading out all registered variables.
|
||||
* \details It iterates through the list of registered variables and calls all read()
|
||||
* functions of the registered pool variables (which read out their values from the
|
||||
* data pool) which are not write-only. In case of an error (e.g. a wrong data type,
|
||||
* or an invalid data pool id), the operation is aborted and
|
||||
* \c INVALID_PARAMETER_DEFINITION returned.
|
||||
* The data pool is locked during the whole read operation and freed afterwards.
|
||||
* The state changes to "was written" after this operation.
|
||||
* \return - \c RETURN_OK if all variables were read successfully.
|
||||
* - \c INVALID_PARAMETER_DEFINITION if PID, size or type of the
|
||||
* requested variable is invalid.
|
||||
* - \c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||
* commit() in between
|
||||
*/
|
||||
ReturnValue_t read();
|
||||
/**
|
||||
* \brief The commit call initializes writing back the registered variables.
|
||||
* \details It iterates through the list of registered variables and calls
|
||||
* the commit() method of the remaining registered variables (which write back
|
||||
* their values to the pool).
|
||||
* The data pool is locked during the whole commit operation and freed afterwards.
|
||||
* The state changes to "was committed" after this operation.
|
||||
* If the set does contain at least one variable which is not write-only commit()
|
||||
* can only be called after read(). If the set only contains variables which are
|
||||
* write only, commit() can be called without a preceding read() call.
|
||||
* \return - \c RETURN_OK if all variables were read successfully.
|
||||
* - \c COMMITING_WITHOUT_READING if set was not read yet and contains non write-only
|
||||
* variables
|
||||
*/
|
||||
ReturnValue_t commit(void);
|
||||
/**
|
||||
* Variant of method above which sets validity of all elements of the set.
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
* \return - \c RETURN_OK if all variables were read successfully.
|
||||
* - \c COMMITING_WITHOUT_READING if set was not read yet and contains non write-only
|
||||
* variables
|
||||
*/
|
||||
ReturnValue_t commit(uint8_t valid);
|
||||
/**
|
||||
* \brief This operation is used to register the local variables in the set.
|
||||
* \details It copies all required information to the currently
|
||||
* free space in the registeredVariables list.
|
||||
*/
|
||||
void registerVariable(PoolVariableIF* variable);
|
||||
|
||||
/**
|
||||
* Set the valid information of all variables contained in the set which are not readonly
|
||||
*
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
*/
|
||||
void setValid(uint8_t valid);
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
};
|
||||
|
||||
#endif /* DATASET_H_ */
|
@ -1,39 +1,47 @@
|
||||
/**
|
||||
* \file DataSetIF.h
|
||||
*
|
||||
* \brief This file contains the small interface to access the DataSet class.
|
||||
*
|
||||
* \date 10/23/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DATASETIF_H_
|
||||
#define DATASETIF_H_
|
||||
#ifndef FSFW_DATAPOOL_DATASETIF_H_
|
||||
#define FSFW_DATAPOOL_DATASETIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
class PoolVariableIF;
|
||||
|
||||
/**
|
||||
* \brief This class defines a small interface to register on a DataSet.
|
||||
* @brief This class defines a small interface to register on a DataSet.
|
||||
*
|
||||
* \details Currently, the only purpose of this interface is to provide a method for locally
|
||||
* checked-out variables to register on a data set. Still, it may become useful for
|
||||
* other purposes as well.
|
||||
*
|
||||
* \ingroup data_pool
|
||||
* @details
|
||||
* Currently, the only purpose of this interface is to provide a
|
||||
* method for locally checked-out variables to register on a data set.
|
||||
* Still, it may become useful for other purposes as well.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class DataSetIF {
|
||||
public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS;
|
||||
static constexpr ReturnValue_t INVALID_PARAMETER_DEFINITION =
|
||||
MAKE_RETURN_CODE( 0x01 );
|
||||
static constexpr ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE( 0x02 );
|
||||
static constexpr ReturnValue_t COMMITING_WITHOUT_READING =
|
||||
MAKE_RETURN_CODE(0x03);
|
||||
|
||||
static constexpr ReturnValue_t DATA_SET_UNINITIALISED = MAKE_RETURN_CODE( 0x04 );
|
||||
static constexpr ReturnValue_t DATA_SET_FULL = MAKE_RETURN_CODE( 0x05 );
|
||||
static constexpr ReturnValue_t POOL_VAR_NULL = MAKE_RETURN_CODE( 0x06 );
|
||||
|
||||
/**
|
||||
* \brief This is an empty virtual destructor, as it is proposed for C++ interfaces.
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is proposed for C++ interfaces.
|
||||
*/
|
||||
virtual ~DataSetIF() {}
|
||||
|
||||
/**
|
||||
* \brief This operation provides a method to register local data pool variables
|
||||
* to register in a data set by passing itself to this DataSet operation.
|
||||
* @brief This operation provides a method to register local data pool
|
||||
* variables to register in a data set by passing itself
|
||||
* to this DataSet operation.
|
||||
*/
|
||||
virtual void registerVariable( PoolVariableIF* variable ) = 0;
|
||||
virtual ReturnValue_t registerVariable(PoolVariableIF* variable) = 0;
|
||||
|
||||
virtual uint16_t getFillCount() const = 0;
|
||||
};
|
||||
|
||||
#endif /* DATASETIF_H_ */
|
||||
#endif /* FSFW_DATAPOOL_DATASETIF_H_ */
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "HkSwitchHelper.h"
|
||||
//#include <mission/tmtcservices/HKService_03.h>
|
||||
#include "../datapool/HkSwitchHelper.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) :
|
||||
@ -22,14 +21,14 @@ ReturnValue_t HkSwitchHelper::initialize() {
|
||||
}
|
||||
|
||||
ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) {
|
||||
CommandMessage message;
|
||||
while (actionQueue->receiveMessage(&message) == HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = commandActionHelper.handleReply(&message);
|
||||
CommandMessage command;
|
||||
while (actionQueue->receiveMessage(&command) == HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = commandActionHelper.handleReply(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
message.setToUnknownCommand();
|
||||
actionQueue->reply(&message);
|
||||
command.setToUnknownCommand();
|
||||
actionQueue->reply(&command);
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
169
datapool/PoolDataSetBase.cpp
Normal file
169
datapool/PoolDataSetBase.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
#include "PoolDataSetBase.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxFillCount):
|
||||
registeredVariables(registeredVariablesArray),
|
||||
maxFillCount(maxFillCount) {
|
||||
}
|
||||
|
||||
PoolDataSetBase::~PoolDataSetBase() {}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::registerVariable(
|
||||
PoolVariableIF *variable) {
|
||||
if (state != States::DATA_SET_UNINITIALISED) {
|
||||
sif::error << "DataSet::registerVariable: "
|
||||
"Call made in wrong position." << std::endl;
|
||||
return DataSetIF::DATA_SET_UNINITIALISED;
|
||||
}
|
||||
if (variable == nullptr) {
|
||||
sif::error << "DataSet::registerVariable: "
|
||||
"Pool variable is nullptr." << std::endl;
|
||||
return DataSetIF::POOL_VAR_NULL;
|
||||
}
|
||||
if (fillCount >= maxFillCount) {
|
||||
sif::error << "DataSet::registerVariable: "
|
||||
"DataSet is full." << std::endl;
|
||||
return DataSetIF::DATA_SET_FULL;
|
||||
}
|
||||
registeredVariables[fillCount] = variable;
|
||||
fillCount++;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if (state == States::DATA_SET_UNINITIALISED) {
|
||||
lockDataPool(lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = readVariable(count);
|
||||
if(result != RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = States::DATA_SET_WAS_READ;
|
||||
unlockDataPool();
|
||||
}
|
||||
else {
|
||||
sif::error << "DataSet::read(): "
|
||||
"Call made in wrong position. Don't forget to commit"
|
||||
" member datasets!" << std::endl;
|
||||
result = SET_WAS_ALREADY_READ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t PoolDataSetBase::getFillCount() const {
|
||||
return fillCount;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::readVariable(uint16_t count) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
// These checks are often performed by the respective
|
||||
// variable implementation too, but I guess a double check does not hurt.
|
||||
if (registeredVariables[count]->getReadWriteMode() !=
|
||||
PoolVariableIF::VAR_WRITE and
|
||||
registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER)
|
||||
{
|
||||
result = registeredVariables[count]->readWithoutLock();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
result = INVALID_PARAMETER_DEFINITION;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::commit(uint32_t lockTimeout) {
|
||||
if (state == States::DATA_SET_WAS_READ) {
|
||||
handleAlreadyReadDatasetCommit(lockTimeout);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return handleUnreadDatasetCommit(lockTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
void PoolDataSetBase::handleAlreadyReadDatasetCommit(uint32_t lockTimeout) {
|
||||
lockDataPool(lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commitWithoutLock();
|
||||
}
|
||||
}
|
||||
state = States::DATA_SET_UNINITIALISED;
|
||||
unlockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::handleUnreadDatasetCommit(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
lockDataPool(lockTimeout);
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
== PoolVariableIF::VAR_WRITE
|
||||
&& registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
registeredVariables[count]->commitWithoutLock();
|
||||
} else if (registeredVariables[count]->getDataPoolId()
|
||||
!= PoolVariableIF::NO_PARAMETER) {
|
||||
if (result != COMMITING_WITHOUT_READING) {
|
||||
sif::error << "DataSet::commit(): commit-without-read call made "
|
||||
"with non write-only variable." << std::endl;
|
||||
result = COMMITING_WITHOUT_READING;
|
||||
}
|
||||
}
|
||||
}
|
||||
state = States::DATA_SET_UNINITIALISED;
|
||||
unlockDataPool();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PoolDataSetBase::lockDataPool(uint32_t timeoutMs) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::unlockDataPool() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolDataSetBase::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t PoolDataSetBase::getSerializedSize() const {
|
||||
uint32_t size = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
size += registeredVariables[count]->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void PoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
|
||||
this->registeredVariables = variablesContainer;
|
||||
}
|
152
datapool/PoolDataSetBase.h
Normal file
152
datapool/PoolDataSetBase.h
Normal file
@ -0,0 +1,152 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLDATASETBASE_H_
|
||||
#define FSFW_DATAPOOL_POOLDATASETBASE_H_
|
||||
|
||||
#include "PoolDataSetIF.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
|
||||
/**
|
||||
* @brief The DataSetBase class manages a set of locally checked out variables.
|
||||
* @details
|
||||
* This class manages a list, where a set of local variables (or pool variables)
|
||||
* are registered. They are checked-out (i.e. their values are looked
|
||||
* up and copied) with the read call. After the user finishes working with the
|
||||
* pool variables, he can write back all variable values to the pool with
|
||||
* the commit call. The data set manages locking and freeing the data pool,
|
||||
* to ensure that all values are read and written back at once.
|
||||
*
|
||||
* An internal state manages usage of this class. Variables may only be
|
||||
* registered before the read call is made, and the commit call only
|
||||
* after the read call.
|
||||
*
|
||||
* If pool variables are writable and not committed until destruction
|
||||
* of the set, the DataSet class automatically sets the valid flag in the
|
||||
* data pool to invalid (without) changing the variable's value.
|
||||
*
|
||||
* The base class lockDataPool und unlockDataPool implementation are empty
|
||||
* and should be implemented to protect the underlying pool type.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolDataSetBase: public PoolDataSetIF,
|
||||
public SerializeIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Creates an empty dataset. Use registerVariable or
|
||||
* supply a pointer to this dataset to PoolVariable
|
||||
* initializations to register pool variables.
|
||||
*/
|
||||
PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxFillCount);
|
||||
virtual~ PoolDataSetBase();
|
||||
|
||||
/**
|
||||
* @brief The read call initializes reading out all registered variables.
|
||||
* @details
|
||||
* It iterates through the list of registered variables and calls all read()
|
||||
* functions of the registered pool variables (which read out their values
|
||||
* from the data pool) which are not write-only.
|
||||
* In case of an error (e.g. a wrong data type, or an invalid data pool id),
|
||||
* the operation is aborted and @c INVALID_PARAMETER_DEFINITION returned.
|
||||
*
|
||||
* The data pool is locked during the whole read operation and
|
||||
* freed afterwards.The state changes to "was written" after this operation.
|
||||
* @return
|
||||
* - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c INVALID_PARAMETER_DEFINITION if PID, size or type of the
|
||||
* requested variable is invalid.
|
||||
* - @c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||
* commit() in between
|
||||
*/
|
||||
virtual ReturnValue_t read(uint32_t lockTimeout =
|
||||
MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call initializes writing back the registered variables.
|
||||
* @details
|
||||
* It iterates through the list of registered variables and calls the
|
||||
* commit() method of the remaining registered variables (which write back
|
||||
* their values to the pool).
|
||||
*
|
||||
* The data pool is locked during the whole commit operation and
|
||||
* freed afterwards. The state changes to "was committed" after this operation.
|
||||
*
|
||||
* If the set does contain at least one variable which is not write-only
|
||||
* commit() can only be called after read(). If the set only contains
|
||||
* variables which are write only, commit() can be called without a
|
||||
* preceding read() call.
|
||||
* @return - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||
* contains non write-only variables
|
||||
*/
|
||||
virtual ReturnValue_t commit(uint32_t lockTimeout =
|
||||
MutexIF::BLOCKING) override;
|
||||
|
||||
/**
|
||||
* Register the passed pool variable instance into the data set.
|
||||
* @param variable
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t registerVariable( PoolVariableIF* variable) override;
|
||||
/**
|
||||
* Provides the means to lock the underlying data structure to ensure
|
||||
* thread-safety. Default implementation is empty
|
||||
* @return Always returns -@c RETURN_OK
|
||||
*/
|
||||
virtual ReturnValue_t lockDataPool(uint32_t timeoutMs =
|
||||
MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* Provides the means to unlock the underlying data structure to ensure
|
||||
* thread-safety. Default implementation is empty
|
||||
* @return Always returns -@c RETURN_OK
|
||||
*/
|
||||
virtual ReturnValue_t unlockDataPool() override;
|
||||
|
||||
virtual uint16_t getFillCount() const;
|
||||
|
||||
/* SerializeIF implementations */
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief The fill_count attribute ensures that the variables
|
||||
* register in the correct array position and that the maximum
|
||||
* number of variables is not exceeded.
|
||||
*/
|
||||
uint16_t fillCount = 0;
|
||||
/**
|
||||
* States of the seet.
|
||||
*/
|
||||
enum class States {
|
||||
DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||
DATA_SET_WAS_READ //!< DATA_SET_WAS_READ
|
||||
};
|
||||
/**
|
||||
* @brief state manages the internal state of the data set,
|
||||
* which is important e.g. for the behavior on destruction.
|
||||
*/
|
||||
States state = States::DATA_SET_UNINITIALISED;
|
||||
|
||||
/**
|
||||
* @brief This array represents all pool variables registered in this set.
|
||||
* Child classes can use a static or dynamic container to create
|
||||
* an array of registered variables and assign the first entry here.
|
||||
*/
|
||||
PoolVariableIF** registeredVariables = nullptr;
|
||||
const size_t maxFillCount = 0;
|
||||
|
||||
void setContainer(PoolVariableIF** variablesContainer);
|
||||
|
||||
private:
|
||||
ReturnValue_t readVariable(uint16_t count);
|
||||
void handleAlreadyReadDatasetCommit(uint32_t lockTimeout);
|
||||
ReturnValue_t handleUnreadDatasetCommit(uint32_t lockTimeout);
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLDATASETBASE_H_ */
|
33
datapool/PoolDataSetIF.h
Normal file
33
datapool/PoolDataSetIF.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef FSFW_DATAPOOL_POOLDATASETIF_H_
|
||||
#define FSFW_DATAPOOL_POOLDATASETIF_H_
|
||||
|
||||
#include "DataSetIF.h"
|
||||
|
||||
/**
|
||||
* @brief Extendes the DataSetIF by adding abstract functions to lock
|
||||
* and unlock a data pool and read/commit semantics.
|
||||
*/
|
||||
class PoolDataSetIF: public DataSetIF {
|
||||
public:
|
||||
virtual~ PoolDataSetIF() {};
|
||||
|
||||
virtual ReturnValue_t read(dur_millis_t lockTimeout) = 0;
|
||||
virtual ReturnValue_t commit(dur_millis_t lockTimeout) = 0;
|
||||
|
||||
/**
|
||||
* @brief Most underlying data structures will have a pool like structure
|
||||
* and will require a lock and unlock mechanism to ensure
|
||||
* thread-safety
|
||||
* @return Lock operation result
|
||||
*/
|
||||
virtual ReturnValue_t lockDataPool(dur_millis_t timeoutMs) = 0;
|
||||
/**
|
||||
* @brief Unlock call corresponding to the lock call.
|
||||
* @return Unlock operation result
|
||||
*/
|
||||
virtual ReturnValue_t unlockDataPool() = 0;
|
||||
|
||||
virtual bool isValid() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLDATASETIF_H_ */
|
@ -1,4 +1,5 @@
|
||||
#include "PoolEntry.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../globalfunctions/arrayprinter.h"
|
||||
#include <cstring>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_POOLENTRY_H_
|
||||
#define FRAMEWORK_DATAPOOL_POOLENTRY_H_
|
||||
#ifndef FSFW_DATAPOOL_POOLENTRY_H_
|
||||
#define FSFW_DATAPOOL_POOLENTRY_H_
|
||||
|
||||
#include "PoolEntryIF.h"
|
||||
|
||||
@ -127,4 +127,4 @@ public:
|
||||
Type getType();
|
||||
};
|
||||
|
||||
#endif /* POOLENTRY_H_ */
|
||||
#endif /* FSFW_DATAPOOL_POOLENTRY_H_ */
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_POOLENTRYIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_POOLENTRYIF_H_
|
||||
#ifndef FSFW_DATAPOOL_POOLENTRYIF_H_
|
||||
#define FSFW_DATAPOOL_POOLENTRYIF_H_
|
||||
|
||||
#include "../globalfunctions/Type.h"
|
||||
#include <cstdint>
|
||||
@ -60,4 +60,4 @@ public:
|
||||
virtual Type getType() = 0;
|
||||
};
|
||||
|
||||
#endif /* POOLENTRYIF_H_ */
|
||||
#endif /* FSFW_DATAPOOL_POOLENTRYIF_H_ */
|
||||
|
@ -1,187 +0,0 @@
|
||||
#include "DataPool.h"
|
||||
#include "PoolEntryIF.h"
|
||||
#include "PoolRawAccess.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../serialize/EndianConverter.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(
|
||||
Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0), readWriteMode(
|
||||
setReadWriteMode) {
|
||||
memset(value, 0, sizeof(value));
|
||||
if (data_set != NULL) {
|
||||
data_set->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
PoolRawAccess::~PoolRawAccess() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::read() {
|
||||
PoolEntryIF *read_out = ::dataPool.getRawData(dataPoolId);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->getValid();
|
||||
if (read_out->getSize() > arrayEntry) {
|
||||
arraySize = read_out->getSize();
|
||||
typeSize = read_out->getByteSize() / read_out->getSize();
|
||||
type = read_out->getType();
|
||||
if (typeSize <= sizeof(value)) {
|
||||
uint16_t arrayPosition = arrayEntry * typeSize;
|
||||
sizeTillEnd = read_out->getByteSize() - arrayPosition;
|
||||
uint8_t *ptr =
|
||||
&((uint8_t*) read_out->getRawData())[arrayPosition];
|
||||
memcpy(value, ptr, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
//Error value type too large.
|
||||
}
|
||||
} else {
|
||||
//Error index requested too large
|
||||
}
|
||||
} else {
|
||||
//Error entry does not exist.
|
||||
}
|
||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
valid = INVALID;
|
||||
typeSize = 0;
|
||||
sizeTillEnd = 0;
|
||||
memset(value, 0, sizeof(value));
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commit() {
|
||||
PoolEntryIF *write_back = ::dataPool.getRawData(dataPoolId);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->setValid(valid);
|
||||
uint8_t array_position = arrayEntry * typeSize;
|
||||
uint8_t *ptr = &((uint8_t*) write_back->getRawData())[array_position];
|
||||
memcpy(ptr, value, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* PoolRawAccess::getEntry() {
|
||||
return value;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t *buffer,
|
||||
size_t *writtenBytes, size_t maxSize) {
|
||||
uint8_t *data_ptr = getEntry();
|
||||
// debug << "PoolRawAccess::getEntry: Array position: " << index * size_of_type << " Size of T: " << (int)size_of_type << " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
||||
if (typeSize == 0) {
|
||||
return DATA_POOL_ACCESS_FAILED;
|
||||
}
|
||||
if (typeSize > maxSize) {
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
||||
*writtenBytes = typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
Type PoolRawAccess::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeOfType() {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getArraySize() {
|
||||
return arraySize;
|
||||
}
|
||||
|
||||
uint32_t PoolRawAccess::getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
|
||||
PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
||||
size_t setSize) {
|
||||
if (typeSize == setSize) {
|
||||
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
sif::error
|
||||
<< "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: Internal"
|
||||
<< (uint32_t) typeSize << ", Requested: " << setSize
|
||||
<< std::endl;
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
bool PoolRawAccess::isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void PoolRawAccess::setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeTillEnd() const {
|
||||
return sizeTillEnd;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
if (typeSize + *size <= maxSize) {
|
||||
switch (streamEndianness) {
|
||||
case (Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case (Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
default:
|
||||
case (Endianness::MACHINE):
|
||||
memcpy(*buffer, value, typeSize);
|
||||
break;
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSerializedSize() const {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) {
|
||||
|
||||
if (*size >= typeSize) {
|
||||
switch (streamEndianness) {
|
||||
case (Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case (Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
default:
|
||||
case (Endianness::MACHINE):
|
||||
memcpy(value, *buffer, typeSize);
|
||||
break;
|
||||
}
|
||||
*size -= typeSize;
|
||||
*buffer += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
#ifndef POOLRAWACCESS_H_
|
||||
#define POOLRAWACCESS_H_
|
||||
|
||||
#include "DataSetIF.h"
|
||||
#include "PoolVariableIF.h"
|
||||
|
||||
/**
|
||||
* This class allows accessing Data Pool variables as raw bytes.
|
||||
* This is necessary to have an access method for HK data, as the PID's alone do not
|
||||
* provide a type information.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class PoolRawAccess: public PoolVariableIF {
|
||||
private:
|
||||
/**
|
||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* \brief The array entry that is fetched from the data pool.
|
||||
*/
|
||||
uint8_t arrayEntry;
|
||||
/**
|
||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* \brief This value contains the type of the data pool entry.
|
||||
*/
|
||||
Type type;
|
||||
/**
|
||||
* \brief This value contains the size of the data pool entry in bytes.
|
||||
*/
|
||||
size_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
size_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
size_t sizeTillEnd;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
static const uint8_t RAW_MAX_SIZE = sizeof(double);
|
||||
protected:
|
||||
/**
|
||||
* \brief This is a call to read the value from the global data pool.
|
||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*/
|
||||
ReturnValue_t read();
|
||||
/**
|
||||
* \brief The commit call writes back the variable's value to the data pool.
|
||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit();
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS;
|
||||
static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02);
|
||||
uint8_t value[RAW_MAX_SIZE];
|
||||
PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry,
|
||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode =
|
||||
PoolVariableIF::VAR_READ);
|
||||
/**
|
||||
* \brief The classes destructor is empty. If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolRawAccess();
|
||||
/**
|
||||
* \brief This operation returns a pointer to the entry fetched.
|
||||
* \details This means, it does not return a pointer to byte "index", but to the start byte of
|
||||
* array entry "index". Example: If the original data pool array consists of an double
|
||||
* array of size four, getEntry(1) returns &(this->value[8]).
|
||||
*/
|
||||
uint8_t* getEntry();
|
||||
/**
|
||||
* \brief This operation returns the fetched entry from the data pool and
|
||||
* flips the bytes, if necessary.
|
||||
* \details It makes use of the getEntry call of this function, but additionally flips the
|
||||
* bytes to big endian, which is the default for external communication (as House-
|
||||
* keeping telemetry). To achieve this, the data is copied directly to the passed
|
||||
* buffer, if it fits in the given maxSize.
|
||||
* \param buffer A pointer to a buffer to write to
|
||||
* \param writtenBytes The number of bytes written is returned with this value.
|
||||
* \param maxSize The maximum size that the function may write to buffer.
|
||||
* \return - \c RETURN_OK if entry could be acquired
|
||||
* - \c RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
||||
size_t maxSize);
|
||||
/**
|
||||
* With this method, the content can be set from a big endian buffer safely.
|
||||
* @param buffer Pointer to the data to set
|
||||
* @param size Size of the data to write. Must fit this->size.
|
||||
* @return - \c RETURN_OK on success
|
||||
* - \c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t setEntryFromBigEndian(const uint8_t *buffer,
|
||||
size_t setSize);
|
||||
/**
|
||||
* \brief This operation returns the type of the entry currently stored.
|
||||
*/
|
||||
Type getType();
|
||||
/**
|
||||
* \brief This operation returns the size of the entry currently stored.
|
||||
*/
|
||||
size_t getSizeOfType();
|
||||
/**
|
||||
*
|
||||
* @return the size of the datapool array
|
||||
*/
|
||||
size_t getArraySize();
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const;
|
||||
/**
|
||||
* This method returns if the variable is read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
void setValid(uint8_t valid);
|
||||
/**
|
||||
* Getter for the remaining size.
|
||||
*/
|
||||
size_t getSizeTillEnd() const;
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override;
|
||||
};
|
||||
|
||||
#endif /* POOLRAWACCESS_H_ */
|
@ -1,14 +1,15 @@
|
||||
#ifndef POOLVARLIST_H_
|
||||
#define POOLVARLIST_H_
|
||||
#ifndef FSFW_DATAPOOL_POOLVARLIST_H_
|
||||
#define FSFW_DATAPOOL_POOLVARLIST_H_
|
||||
|
||||
#include "PoolVariable.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
template <class T, uint8_t n_var>
|
||||
class PoolVarList {
|
||||
private:
|
||||
PoolVariable<T> variables[n_var];
|
||||
GlobPoolVar<T> variables[n_var];
|
||||
public:
|
||||
PoolVarList( const uint32_t set_id[n_var], DataSetIF* dataSet, PoolVariableIF::ReadWriteMode_t setReadWriteMode ) {
|
||||
PoolVarList( const uint32_t set_id[n_var], DataSetIF* dataSet,
|
||||
PoolVariableIF::ReadWriteMode_t setReadWriteMode ) {
|
||||
//I really should have a look at the new init list c++ syntax.
|
||||
if (dataSet == NULL) {
|
||||
return;
|
||||
@ -20,9 +21,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
PoolVariable<T> &operator [](int i) { return variables[i]; }
|
||||
GlobPoolVar<T> &operator [](int i) { return variables[i]; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* POOLVARLIST_H_ */
|
||||
#endif /* FSFW_DATAPOOL_POOLVARLIST_H_ */
|
||||
|
@ -1,295 +0,0 @@
|
||||
/*
|
||||
* \file PoolVariable.h
|
||||
*
|
||||
* \brief This file contains the PoolVariable class, which locally represents a non-array data pool variable.
|
||||
*
|
||||
* \date 10/17/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLVARIABLE_H_
|
||||
#define POOLVARIABLE_H_
|
||||
|
||||
#include "DataSetIF.h"
|
||||
#include "PoolEntry.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
template<typename T, uint8_t n_var> class PoolVarList;
|
||||
|
||||
/**
|
||||
* \brief This is the access class for non-array data pool entries.
|
||||
*
|
||||
* \details To ensure safe usage of the data pool, operation is not done directly on the data pool
|
||||
* entries, but on local copies. This class provides simple type-safe access to single
|
||||
* data pool entries (i.e. entries with length = 1).
|
||||
* The class can be instantiated as read-write and read only.
|
||||
* It provides a commit-and-roll-back semantic, which means that the variable's value in
|
||||
* the data pool is not changed until the commit call is executed.
|
||||
* \tparam T The template parameter sets the type of the variable. Currently, all plain data types
|
||||
* are supported, but in principle any type is possible.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
template<typename T>
|
||||
class PoolVariable: public PoolVariableIF {
|
||||
template<typename U, uint8_t n_var> friend class PoolVarList;
|
||||
protected:
|
||||
/**
|
||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
/**
|
||||
* \brief This is a call to read the value from the global data pool.
|
||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*/
|
||||
ReturnValue_t read() {
|
||||
PoolEntry<T> *read_out = ::dataPool.getData < T > (dataPoolId, 1);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = *(read_out->address);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
value = 0;
|
||||
valid = false;
|
||||
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* \brief The commit call writes back the variable's value to the data pool.
|
||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit() {
|
||||
PoolEntry<T> *write_back = ::dataPool.getData < T > (dataPoolId, 1);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->valid = valid;
|
||||
*(write_back->address) = value;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Empty ctor for List initialization
|
||||
*/
|
||||
PoolVariable() :
|
||||
dataPoolId(PoolVariableIF::NO_PARAMETER), valid(
|
||||
PoolVariableIF::INVALID), readWriteMode(VAR_READ), value(0) {
|
||||
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* \brief This is the local copy of the data pool entry.
|
||||
* \details The user can work on this attribute
|
||||
* just like he would on a simple local variable.
|
||||
*/
|
||||
T value;
|
||||
/**
|
||||
* \brief In the constructor, the variable can register itself in a DataSet (if not NULL is
|
||||
* passed).
|
||||
* \details It DOES NOT fetch the current value from the data pool, but sets the value
|
||||
* attribute to default (0). The value is fetched within the read() operation.
|
||||
* \param set_id This is the id in the global data pool this instance of the access class
|
||||
* corresponds to.
|
||||
* \param dataSet The data set in which the variable shall register itself. If NULL,
|
||||
* the variable is not registered.
|
||||
* \param setWritable If this flag is set to true, changes in the value attribute can be
|
||||
* written back to the data pool, otherwise not.
|
||||
*/
|
||||
PoolVariable(uint32_t set_id, DataSetIF *dataSet,
|
||||
ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), valid(PoolVariableIF::INVALID), readWriteMode(
|
||||
setReadWriteMode), value(0) {
|
||||
if (dataSet != NULL) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy ctor to copy classes containing Pool Variables.
|
||||
*/
|
||||
PoolVariable(const PoolVariable &rhs) :
|
||||
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
||||
rhs.readWriteMode), value(rhs.value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The classes destructor is empty.
|
||||
* \details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolVariable() {
|
||||
|
||||
}
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
/**
|
||||
* This operation sets the data pool id of the variable.
|
||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const {
|
||||
if (valid)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
void setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
operator T() {
|
||||
return value;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
PoolVariable<T>& operator=(T newValue) {
|
||||
value = newValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PoolVariable<T>& operator=(PoolVariable<T> newPoolVariable) {
|
||||
value = newPoolVariable.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize<T>(&value, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const override {
|
||||
return SerializeAdapter::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
|
||||
typedef PoolVariable<uint8_t> db_uint8_t;
|
||||
typedef PoolVariable<uint16_t> db_uint16_t;
|
||||
typedef PoolVariable<uint32_t> db_uint32_t;
|
||||
typedef PoolVariable<int8_t> db_int8_t;
|
||||
typedef PoolVariable<int16_t> db_int16_t;
|
||||
typedef PoolVariable<int32_t> db_int32_t;
|
||||
typedef PoolVariable<uint8_t> db_bool_t;
|
||||
typedef PoolVariable<float> db_float_t;
|
||||
typedef PoolVariable<double> db_double_t;
|
||||
//Alternative (but I thing this is not as useful: code duplication, differences too small):
|
||||
|
||||
//template <typename T>
|
||||
//class PoolReader : public PoolVariableIF {
|
||||
//private:
|
||||
// uint32_t parameter_id;
|
||||
// uint8_t valid;
|
||||
//public:
|
||||
// T value;
|
||||
// PoolReader( uint32_t set_id, DataSetIF* set ) : parameter_id(set_id), valid(false), value(0) {
|
||||
// set->registerVariable( this );
|
||||
// }
|
||||
//
|
||||
// ~PoolReader() {};
|
||||
//
|
||||
// uint8_t commit() {
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// }
|
||||
//
|
||||
// uint8_t read() {
|
||||
// PoolEntry<T>* read_out = ::dataPool.getData<T>( parameter_id, 1 );
|
||||
// if ( read_out != NULL ) {
|
||||
// valid = read_out->valid;
|
||||
// value = *(read_out->address);
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// } else {
|
||||
// value = 0;
|
||||
// valid = false;
|
||||
// return CHECKOUT_FAILED;
|
||||
// }
|
||||
// }
|
||||
// uint32_t getParameterId() { return parameter_id; }
|
||||
// bool isWritable() { return false; };
|
||||
// bool isValid() { if (valid) return true; else return false; }
|
||||
//};
|
||||
//
|
||||
//template <typename T>
|
||||
//class PoolWriter : public PoolVariableIF {
|
||||
//private:
|
||||
// uint32_t parameter_id;
|
||||
//public:
|
||||
// T value;
|
||||
// PoolWriter( uint32_t set_id, DataSetIF* set ) : parameter_id(set_id), value(0) {
|
||||
// set->registerVariable( this );
|
||||
// }
|
||||
//
|
||||
// ~PoolWriter() {};
|
||||
//
|
||||
// uint8_t commit() {
|
||||
// PoolEntry<T>* write_back = ::dataPool.getData<T>( parameter_id, 1 );
|
||||
// if ( write_back != NULL ) {
|
||||
// write_back->valid = true;
|
||||
// *(write_back->address) = value;
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// } else {
|
||||
// return CHECKOUT_FAILED;
|
||||
// }
|
||||
// }
|
||||
// uint8_t read() {
|
||||
// PoolEntry<T>* read_out = ::dataPool.getData<T>( parameter_id, 1 );
|
||||
// if ( read_out != NULL ) {
|
||||
// value = *(read_out->address);
|
||||
// return HasReturnvaluesIF::RETURN_OK;
|
||||
// } else {
|
||||
// value = 0;
|
||||
// return CHECKOUT_FAILED;
|
||||
// }
|
||||
// }
|
||||
// uint32_t getParameterId() { return parameter_id; }
|
||||
// bool isWritable() { return true; };
|
||||
// bool isValid() { return false; }
|
||||
//};
|
||||
|
||||
#endif /* POOLVARIABLE_H_ */
|
@ -1,71 +1,99 @@
|
||||
/*
|
||||
* \file PoolVariableIF.h
|
||||
*
|
||||
* \brief This file contains the interface definition for pool variables.
|
||||
*
|
||||
* \date 10/17/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLVARIABLEIF_H_
|
||||
#define POOLVARIABLEIF_H_
|
||||
#ifndef FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||
#define FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
|
||||
/**
|
||||
* \brief This interface is used to control local data pool variable representations.
|
||||
*
|
||||
* \details To securely handle data pool variables, all pool entries are locally managed by
|
||||
* data pool variable access classes, which are called pool variables. To ensure a
|
||||
* common state of a set of variables needed in a function, these local pool variables
|
||||
* again are managed by other classes, e.g. the DataSet. This interface provides unified
|
||||
* access to local pool variables for such manager classes.
|
||||
* \ingroup data_pool
|
||||
* @brief This interface is used to control data pool
|
||||
* variable representations.
|
||||
* @details
|
||||
* To securely handle data pool variables, all pool entries are locally
|
||||
* managed by data pool variable access classes, which are called pool
|
||||
* variables. To ensure a common state of a set of variables needed in a
|
||||
* function, these local pool variables again are managed by other classes,
|
||||
* like the DataSet classes. This interface provides unified access to
|
||||
* local pool variables for such manager classes.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolVariableIF : public SerializeIF {
|
||||
friend class DataSet;
|
||||
protected:
|
||||
/**
|
||||
* \brief The commit call shall write back a newly calculated local value to the data pool.
|
||||
*/
|
||||
virtual ReturnValue_t commit() = 0;
|
||||
/**
|
||||
* \brief The read call shall read the value of this parameter from the data pool and store
|
||||
* the content locally.
|
||||
*/
|
||||
virtual ReturnValue_t read() = 0;
|
||||
friend class PoolDataSetBase;
|
||||
friend class GlobDataSet;
|
||||
friend class LocalPoolDataSetBase;
|
||||
public:
|
||||
static const uint8_t VALID = 1;
|
||||
static const uint8_t INVALID = 0;
|
||||
static const uint32_t NO_PARAMETER = 0;
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::POOL_VARIABLE_IF;
|
||||
static constexpr ReturnValue_t INVALID_READ_WRITE_MODE = MAKE_RETURN_CODE(0xA0);
|
||||
|
||||
static constexpr bool VALID = 1;
|
||||
static constexpr bool INVALID = 0;
|
||||
static constexpr uint32_t NO_PARAMETER = 0xffffffff;
|
||||
|
||||
enum ReadWriteMode_t {
|
||||
VAR_READ, VAR_WRITE, VAR_READ_WRITE
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief This is an empty virtual destructor, as it is proposed for C++ interfaces.
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is proposed for C++ interfaces.
|
||||
*/
|
||||
virtual ~PoolVariableIF() {
|
||||
}
|
||||
virtual ~PoolVariableIF() {}
|
||||
/**
|
||||
* \brief This method returns if the variable is write-only, read-write or read-only.
|
||||
* @brief This method returns if the variable is write-only,
|
||||
* read-write or read-only.
|
||||
*/
|
||||
virtual ReadWriteMode_t getReadWriteMode() const = 0;
|
||||
/**
|
||||
* \brief This operation shall return the data pool id of the variable.
|
||||
* @brief This operation shall return the data pool id of the variable.
|
||||
*/
|
||||
virtual uint32_t getDataPoolId() const = 0;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
* @brief With this call, the valid information of the
|
||||
* variable is returned.
|
||||
*/
|
||||
virtual bool isValid() const = 0;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is set.
|
||||
* @brief With this call, the valid information of the variable is set.
|
||||
*/
|
||||
virtual void setValid(uint8_t validity) = 0;
|
||||
virtual void setValid(bool validity) = 0;
|
||||
|
||||
/**
|
||||
* @brief The commit call shall write back a newly calculated local
|
||||
* value to the data pool.
|
||||
* @details
|
||||
* It is assumed that these calls are implemented in a thread-safe manner!
|
||||
*/
|
||||
virtual ReturnValue_t commit(uint32_t lockTimeout) = 0;
|
||||
/**
|
||||
* @brief The read call shall read the value of this parameter from
|
||||
* the data pool and store the content locally.
|
||||
* @details
|
||||
* It is assumbed that these calls are implemented in a thread-safe manner!
|
||||
*/
|
||||
virtual ReturnValue_t read(uint32_t lockTimeout) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Same as commit with the difference that comitting will be
|
||||
* performed without a lock
|
||||
* @return
|
||||
* This can be used if the lock protection is handled externally
|
||||
* to avoid the overhead of locking and unlocking consecutively.
|
||||
* Declared protected to avoid free public usage.
|
||||
*/
|
||||
virtual ReturnValue_t readWithoutLock() = 0;
|
||||
/**
|
||||
* @brief Same as commit with the difference that comitting will be
|
||||
* performed without a lock
|
||||
* @return
|
||||
* This can be used if the lock protection is handled externally
|
||||
* to avoid the overhead of locking and unlocking consecutively.
|
||||
* Declared protected to avoid free public usage.
|
||||
*/
|
||||
virtual ReturnValue_t commitWithoutLock() = 0;
|
||||
};
|
||||
|
||||
#endif /* POOLVARIABLEIF_H_ */
|
||||
using pool_rwm_t = PoolVariableIF::ReadWriteMode_t;
|
||||
|
||||
#endif /* FSFW_DATAPOOL_POOLVARIABLEIF_H_ */
|
||||
|
@ -1,233 +0,0 @@
|
||||
/*
|
||||
* \file PoolVector.h
|
||||
*
|
||||
* \brief This file contains the PoolVector class, the header only class to handle data pool vectors.
|
||||
*
|
||||
* \date 10/23/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLVECTOR_H_
|
||||
#define POOLVECTOR_H_
|
||||
|
||||
#include "DataSetIF.h"
|
||||
#include "PoolEntry.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
/**
|
||||
* \brief This is the access class for array-type data pool entries.
|
||||
*
|
||||
* \details To ensure safe usage of the data pool, operation is not done directly on the data pool
|
||||
* entries, but on local copies. This class provides simple type- and length-safe access
|
||||
* to vector-style data pool entries (i.e. entries with length > 1).
|
||||
* The class can be instantiated as read-write and read only.
|
||||
* It provides a commit-and-roll-back semantic, which means that no array entry in
|
||||
* the data pool is changed until the commit call is executed.
|
||||
* There are two template parameters:
|
||||
* \tparam T This template parameter specifies the data type of an array entry. Currently, all
|
||||
* plain data types are supported, but in principle any type is possible.
|
||||
* \tparam vector_size This template parameter specifies the vector size of this entry.
|
||||
* Using a template parameter for this is not perfect, but avoids dynamic memory allocation.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
template<typename T, uint16_t vector_size>
|
||||
class PoolVector: public PoolVariableIF {
|
||||
private:
|
||||
/**
|
||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* \brief This is a call to read the array's values from the global data pool.
|
||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies all array values and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type, size or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*/
|
||||
ReturnValue_t read() {
|
||||
PoolEntry<T>* read_out = ::dataPool.getData<T>(this->dataPoolId,
|
||||
vector_size);
|
||||
if (read_out != NULL) {
|
||||
this->valid = read_out->valid;
|
||||
memcpy(this->value, read_out->address, read_out->getByteSize());
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
} else {
|
||||
memset(this->value, 0, vector_size * sizeof(T));
|
||||
sif::error << "PoolVector: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
this->valid = INVALID;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* \brief The commit call copies the array values back to the data pool.
|
||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit() {
|
||||
PoolEntry<T>* write_back = ::dataPool.getData<T>(this->dataPoolId,
|
||||
vector_size);
|
||||
if ((write_back != NULL) && (this->readWriteMode != VAR_READ)) {
|
||||
write_back->valid = valid;
|
||||
memcpy(write_back->address, this->value, write_back->getByteSize());
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* \brief This is the local copy of the data pool entry.
|
||||
* \detials The user can work on this attribute
|
||||
* just like he would on a local array of this type.
|
||||
*/
|
||||
T value[vector_size];
|
||||
/**
|
||||
* \brief In the constructor, the variable can register itself in a DataSet (if not NULL is
|
||||
* passed).
|
||||
* \details It DOES NOT fetch the current value from the data pool, but sets the value
|
||||
* attribute to default (0). The value is fetched within the read() operation.
|
||||
* \param set_id This is the id in the global data pool this instance of the access class
|
||||
* corresponds to.
|
||||
* \param dataSet The data set in which the variable shall register itself. If NULL,
|
||||
* the variable is not registered.
|
||||
* \param setWritable If this flag is set to true, changes in the value attribute can be
|
||||
* written back to the data pool, otherwise not.
|
||||
*/
|
||||
PoolVector(uint32_t set_id, DataSetIF* set,
|
||||
ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
||||
memset(this->value, 0, vector_size * sizeof(T));
|
||||
if (set != NULL) {
|
||||
set->registerVariable(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy ctor to copy classes containing Pool Variables.
|
||||
*/
|
||||
// PoolVector(const PoolVector& rhs) {
|
||||
// PoolVector<T, vector_size> temp(rhs.dataPoolId, rhs.)
|
||||
// memcpy(value, rhs.value, sizeof(T)*vector_size);
|
||||
// }
|
||||
/**
|
||||
* \brief The classes destructor is empty.
|
||||
* \details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolVector() {
|
||||
}
|
||||
;
|
||||
/**
|
||||
* \brief The operation returns the number of array entries in this variable.
|
||||
*/
|
||||
uint8_t getSize() {
|
||||
return vector_size;
|
||||
}
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
/**
|
||||
* This operation sets the data pool id of the variable.
|
||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void setValid(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
uint8_t getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
T &operator [](int i) {
|
||||
return value[i];
|
||||
}
|
||||
|
||||
const T &operator [](int i) const {
|
||||
return value[i];
|
||||
}
|
||||
|
||||
PoolVector<T, vector_size> &operator=(
|
||||
PoolVector<T, vector_size> newPoolVector) {
|
||||
|
||||
for (uint16_t i = 0; i < vector_size; i++) {
|
||||
this->value[i] = newPoolVector.value[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vector_size; i++) {
|
||||
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return vector_size * SerializeAdapter::getSerializedSize(value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vector_size; i++) {
|
||||
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* POOLVECTOR_H_ */
|
14
datapool/SharedDataSetIF.h
Normal file
14
datapool/SharedDataSetIF.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||
#include "PoolDataSetIF.h"
|
||||
|
||||
class SharedDataSetIF: public PoolDataSetIF {
|
||||
public:
|
||||
virtual ~SharedDataSetIF() {};
|
||||
|
||||
private:
|
||||
virtual ReturnValue_t lockDataset(dur_millis_t mutexTimeout) = 0;
|
||||
virtual ReturnValue_t unlockDataset() = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_ */
|
@ -1,4 +1,4 @@
|
||||
#include "ControllerSet.h"
|
||||
#include <fsfw/datapoolglob/ControllerSet.h>
|
||||
|
||||
ControllerSet::ControllerSet() {
|
||||
|
15
datapoolglob/ControllerSet.h
Normal file
15
datapoolglob/ControllerSet.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef FSFW_DATAPOOLGLOB_CONTROLLERSET_H_
|
||||
#define FSFW_DATAPOOLGLOB_CONTROLLERSET_H_
|
||||
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
|
||||
class ControllerSet :public GlobDataSet {
|
||||
public:
|
||||
ControllerSet();
|
||||
virtual ~ControllerSet();
|
||||
|
||||
virtual void setToDefault() = 0;
|
||||
void setInvalid();
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOLGLOB_CONTROLLERSET_H_ */
|
@ -1,7 +1,8 @@
|
||||
#include "DataPool.h"
|
||||
#include "DataPoolAdmin.h"
|
||||
#include "DataSet.h"
|
||||
#include "GlobalDataSet.h"
|
||||
#include "GlobalDataPool.h"
|
||||
#include "PoolRawAccess.h"
|
||||
|
||||
#include "../ipc/CommandMessage.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
#include "../parameters/ParameterMessage.h"
|
||||
@ -40,9 +41,9 @@ ReturnValue_t DataPoolAdmin::executeAction(ActionId_t actionId,
|
||||
|
||||
uint8_t valid = data[4];
|
||||
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess variable(poolId, 0, &mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
ReturnValue_t status = mySet.read();
|
||||
if (status != RETURN_OK) {
|
||||
@ -92,9 +93,9 @@ void DataPoolAdmin::handleCommand() {
|
||||
|
||||
ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
const uint8_t* data, size_t size, uint8_t** dataPointer) {
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
||||
DataSet testSet;
|
||||
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = glob::dataPool.PIDToArrayIndex(address);
|
||||
GlobDataSet testSet;
|
||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = testSet.read();
|
||||
@ -113,7 +114,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
const uint8_t* readPosition = data;
|
||||
|
||||
for (; size > 0; size -= typeSize) {
|
||||
DataSet rawSet;
|
||||
GlobDataSet rawSet;
|
||||
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
status = rawSet.read();
|
||||
@ -131,9 +132,9 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
|
||||
ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
||||
uint8_t** dataPointer, uint8_t* copyHere) {
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
||||
DataSet testSet;
|
||||
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = glob::dataPool.PIDToArrayIndex(address);
|
||||
GlobDataSet testSet;
|
||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = testSet.read();
|
||||
@ -146,7 +147,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
||||
}
|
||||
uint8_t* ptrToCopy = copyHere;
|
||||
for (; size > 0; size -= typeSize) {
|
||||
DataSet rawSet;
|
||||
GlobDataSet rawSet;
|
||||
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
status = rawSet.read();
|
@ -1,15 +1,17 @@
|
||||
#ifndef DATAPOOLADMIN_H_
|
||||
#define DATAPOOLADMIN_H_
|
||||
#ifndef FSFW_DATAPOOLGLOB_DATAPOOLADMIN_H_
|
||||
#define FSFW_DATAPOOLGLOB_DATAPOOLADMIN_H_
|
||||
|
||||
#include "DataPoolParameterWrapper.h"
|
||||
|
||||
#include "../memory/MemoryHelper.h"
|
||||
#include "../action/HasActionsIF.h"
|
||||
#include "../action/SimpleActionHelper.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
#include "../parameters/ReceivesParameterMessagesIF.h"
|
||||
#include "DataPoolParameterWrapper.h"
|
||||
#include "../action/HasActionsIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../parameters/ReceivesParameterMessagesIF.h"
|
||||
#include "../action/SimpleActionHelper.h"
|
||||
#include "../memory/MemoryHelper.h"
|
||||
|
||||
|
||||
class DataPoolAdmin: public HasActionsIF,
|
||||
public ExecutableObjectIF,
|
||||
@ -55,4 +57,4 @@ private:
|
||||
Command_t initialCommand);
|
||||
};
|
||||
|
||||
#endif /* DATAPOOLADMIN_H_ */
|
||||
#endif /* FSFW_DATAPOOLGLOB_DATAPOOLADMIN_H_ */
|
@ -1,10 +1,8 @@
|
||||
#include "DataPoolParameterWrapper.h"
|
||||
|
||||
//for returncodes
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/DataPoolParameterWrapper.h"
|
||||
#include "../datapoolglob/PoolRawAccess.h"
|
||||
#include "../parameters/HasParametersIF.h"
|
||||
|
||||
#include "DataSet.h"
|
||||
#include "PoolRawAccess.h"
|
||||
|
||||
DataPoolParameterWrapper::DataPoolParameterWrapper() :
|
||||
type(Type::UNKNOWN_TYPE), rows(0), columns(0), poolId(
|
||||
@ -20,7 +18,7 @@ ReturnValue_t DataPoolParameterWrapper::set(uint8_t domainId,
|
||||
uint16_t parameterId) {
|
||||
poolId = (domainId << 16) + parameterId;
|
||||
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess raw(poolId, 0, &mySet, PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = mySet.read();
|
||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -57,7 +55,7 @@ ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer,
|
||||
}
|
||||
|
||||
for (uint8_t index = 0; index < rows; index++){
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess raw(poolId, index, &mySet,PoolVariableIF::VAR_READ);
|
||||
mySet.read();
|
||||
result = raw.serialize(buffer,size,maxSize,streamEndianness);
|
||||
@ -94,7 +92,7 @@ ReturnValue_t DataPoolParameterWrapper::deSerializeData(uint8_t startingRow,
|
||||
|
||||
for (uint8_t fromRow = 0; fromRow < fromRows; fromRow++) {
|
||||
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PoolRawAccess raw(poolId, startingRow + fromRow, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
133
datapoolglob/GlobalDataPool.cpp
Normal file
133
datapoolglob/GlobalDataPool.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
#include "../datapoolglob/GlobalDataPool.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
|
||||
GlobalDataPool::GlobalDataPool(
|
||||
void(*initFunction)(GlobPoolMap* pool_map)) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
if (initFunction != NULL ) {
|
||||
initFunction( &this->globDataPool );
|
||||
}
|
||||
}
|
||||
|
||||
GlobalDataPool::~GlobalDataPool() {
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
for(GlobPoolMapIter it = this->globDataPool.begin();
|
||||
it != this->globDataPool.end(); ++it )
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
|
||||
// The function checks PID, type and array length before returning a copy of
|
||||
// the PoolEntry. In failure case, it returns a temp-Entry with size 0 and NULL-ptr.
|
||||
template <typename T> PoolEntry<T>* GlobalDataPool::getData( uint32_t data_pool_id,
|
||||
uint8_t sizeOrPosition ) {
|
||||
GlobPoolMapIter it = this->globDataPool.find( data_pool_id );
|
||||
if ( it != this->globDataPool.end() ) {
|
||||
PoolEntry<T>* entry = dynamic_cast< PoolEntry<T>* >( it->second );
|
||||
if (entry != nullptr ) {
|
||||
if ( sizeOrPosition <= entry->length ) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PoolEntryIF* GlobalDataPool::getRawData( uint32_t data_pool_id ) {
|
||||
GlobPoolMapIter it = this->globDataPool.find( data_pool_id );
|
||||
if ( it != this->globDataPool.end() ) {
|
||||
return it->second;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t GlobalDataPool::unlockDataPool() {
|
||||
ReturnValue_t status = mutex->unlockMutex();
|
||||
if(status != RETURN_OK) {
|
||||
sif::error << "DataPool::DataPool: unlock of mutex failed with"
|
||||
" error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobalDataPool::lockDataPool(uint32_t timeoutMs) {
|
||||
ReturnValue_t status = mutex->lockMutex(MutexIF::TimeoutType::WAITING,
|
||||
timeoutMs);
|
||||
if(status != RETURN_OK) {
|
||||
sif::error << "DataPool::DataPool: lock of mutex failed "
|
||||
"with error code: " << status << std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void GlobalDataPool::print() {
|
||||
sif::debug << "DataPool contains: " << std::endl;
|
||||
std::map<uint32_t, PoolEntryIF*>::iterator dataPoolIt;
|
||||
dataPoolIt = this->globDataPool.begin();
|
||||
while( dataPoolIt != this->globDataPool.end() ) {
|
||||
sif::debug << std::hex << dataPoolIt->first << std::dec << " |";
|
||||
dataPoolIt->second->print();
|
||||
dataPoolIt++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GlobalDataPool::PIDToDataPoolId(uint32_t parameter_id) {
|
||||
return (parameter_id >> 8) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
uint8_t GlobalDataPool::PIDToArrayIndex(uint32_t parameter_id) {
|
||||
return (parameter_id & 0x000000FF);
|
||||
}
|
||||
|
||||
uint32_t GlobalDataPool::poolIdAndPositionToPid(uint32_t poolId, uint8_t index) {
|
||||
return (poolId << 8) + index;
|
||||
}
|
||||
|
||||
|
||||
//SHOULDDO: Do we need a mutex lock here... I don't think so,
|
||||
//as we only check static const values of elements in a list that do not change.
|
||||
//there is no guarantee in the standard, but it seems to me that the implementation is safe -UM
|
||||
ReturnValue_t GlobalDataPool::getType(uint32_t parameter_id, Type* type) {
|
||||
GlobPoolMapIter it = this->globDataPool.find( PIDToDataPoolId(parameter_id));
|
||||
if ( it != this->globDataPool.end() ) {
|
||||
*type = it->second->getType();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
*type = Type::UNKNOWN_TYPE;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalDataPool::exists(uint32_t parameterId) {
|
||||
uint32_t poolId = PIDToDataPoolId(parameterId);
|
||||
uint32_t index = PIDToArrayIndex(parameterId);
|
||||
GlobPoolMapIter it = this->globDataPool.find( poolId );
|
||||
if (it != globDataPool.end()) {
|
||||
if (it->second->getSize() >= index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template PoolEntry<uint8_t>* GlobalDataPool::getData<uint8_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint16_t>* GlobalDataPool::getData<uint16_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint32_t>* GlobalDataPool::getData<uint32_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<uint64_t>* GlobalDataPool::getData<uint64_t>(
|
||||
uint32_t data_pool_id, uint8_t size);
|
||||
template PoolEntry<int8_t>* GlobalDataPool::getData<int8_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int16_t>* GlobalDataPool::getData<int16_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<int32_t>* GlobalDataPool::getData<int32_t>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<float>* GlobalDataPool::getData<float>(
|
||||
uint32_t data_pool_id, uint8_t size );
|
||||
template PoolEntry<double>* GlobalDataPool::getData<double>(
|
||||
uint32_t data_pool_id, uint8_t size);
|
149
datapoolglob/GlobalDataPool.h
Normal file
149
datapoolglob/GlobalDataPool.h
Normal file
@ -0,0 +1,149 @@
|
||||
#ifndef GLOBALDATAPOOL_H_
|
||||
#define GLOBALDATAPOOL_H_
|
||||
|
||||
#include "../datapool/PoolEntry.h"
|
||||
#include "../globalfunctions/Type.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* @defgroup data_pool Global data pool
|
||||
* This is the group, where all classes associated with global
|
||||
* data pool handling belong to.
|
||||
* This includes classes to access Data Pool variables.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Typedefs for the global pool representations
|
||||
*/
|
||||
using GlobPoolMap = std::map<uint32_t, PoolEntryIF*>;
|
||||
using GlobPoolMapIter = GlobPoolMap::iterator;
|
||||
|
||||
/**
|
||||
* @brief This class represents the OBSW global data-pool.
|
||||
*
|
||||
* @details
|
||||
* All variables are registered and space is allocated in an initialization
|
||||
* function, which is passed do the constructor. Space for the variables is
|
||||
* allocated on the heap (with a new call).
|
||||
*
|
||||
* The data is found by a data pool id, which uniquely represents a variable.
|
||||
* Data pool variables should be used with a blackboard logic in mind,
|
||||
* which means read data is valid (if flagged so),
|
||||
* but not necessarily up-to-date.
|
||||
*
|
||||
* Variables are either single values or arrays.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class GlobalDataPool : public HasReturnvaluesIF {
|
||||
private:
|
||||
/**
|
||||
* @brief This is the actual data pool itself.
|
||||
* @details It is represented by a map with the data pool id as index
|
||||
* and a pointer to a single PoolEntry as value.
|
||||
*/
|
||||
GlobPoolMap globDataPool;
|
||||
|
||||
/**
|
||||
* @brief The mutex is created in the constructor and makes
|
||||
* access mutual exclusive.
|
||||
* @details Locking and unlocking the pool is only done by the DataSet class.
|
||||
*/
|
||||
MutexIF* mutex;
|
||||
public:
|
||||
/**
|
||||
* @brief In the classes constructor,
|
||||
* the passed initialization function is called.
|
||||
* @details
|
||||
* To enable filling the pool, a pointer to the map is passed,
|
||||
* allowing direct access to the pool's content.
|
||||
* On runtime, adding or removing variables is forbidden.
|
||||
*/
|
||||
GlobalDataPool( void ( *initFunction )( GlobPoolMap* pool_map ) );
|
||||
|
||||
/**
|
||||
* @brief The destructor iterates through the data_pool map and
|
||||
* calls all entries destructors to clean up the heap.
|
||||
*/
|
||||
~GlobalDataPool();
|
||||
|
||||
/**
|
||||
* @brief This is the default call to access the pool.
|
||||
* @details
|
||||
* A pointer to the PoolEntry object is returned.
|
||||
* The call checks data pool id, type and array size.
|
||||
* Returns NULL in case of failure.
|
||||
* @param data_pool_id The data pool id to search.
|
||||
* @param sizeOrPosition The array size (not byte size!) of the pool entry,
|
||||
* or the position the user wants to read.
|
||||
* If smaller than the entry size, everything's ok.
|
||||
*/
|
||||
template <typename T> PoolEntry<T>* getData( uint32_t data_pool_id,
|
||||
uint8_t sizeOrPosition );
|
||||
|
||||
/**
|
||||
* @brief An alternative call to get a data pool entry in case the type is not implicitly known
|
||||
* (i.e. in Housekeeping Telemetry).
|
||||
* @details It returns a basic interface and does NOT perform
|
||||
* a size check. The caller has to assure he does not copy too much data.
|
||||
* Returns NULL in case the entry is not found.
|
||||
* @param data_pool_id The data pool id to search.
|
||||
*/
|
||||
PoolEntryIF* getRawData( uint32_t data_pool_id );
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate locking the global data pool.
|
||||
* @details It fetches the pool's mutex id and tries to acquire the mutex.
|
||||
*/
|
||||
ReturnValue_t lockDataPool(uint32_t timeoutMs = MutexIF::BLOCKING);
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate unlocking the global data pool.
|
||||
* @details It fetches the pool's mutex id and tries to free the mutex.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool();
|
||||
/**
|
||||
* @brief The print call is a simple debug method.
|
||||
* @details It prints the current content of the data pool.
|
||||
* It iterates through the data_pool map and calls each entry's print() method.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Extracts the data pool id from a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The data pool id as used within the OBSW.
|
||||
*/
|
||||
static uint32_t PIDToDataPoolId( uint32_t parameter_id );
|
||||
/**
|
||||
* Extracts an array index out of a SCOS 2000 PID.
|
||||
* @param parameter_id The passed Parameter ID.
|
||||
* @return The index of the corresponding data pool entry.
|
||||
*/
|
||||
static uint8_t PIDToArrayIndex( uint32_t parameter_id );
|
||||
/**
|
||||
* Retransforms a data pool id and an array index to a SCOS 2000 PID.
|
||||
*/
|
||||
static uint32_t poolIdAndPositionToPid( uint32_t poolId, uint8_t index );
|
||||
|
||||
/**
|
||||
* Method to return the type of a pool variable.
|
||||
* @param parameter_id A parameterID (not pool id) of a DP member.
|
||||
* @param type Returns the type or TYPE::UNKNOWN_TYPE
|
||||
* @return RETURN_OK if parameter exists, RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getType( uint32_t parameter_id, Type* type );
|
||||
|
||||
/**
|
||||
* Method to check if a PID exists. Does not lock, as there's no
|
||||
* possibility to alter the list that is checked during run-time.
|
||||
* @param parameterId The PID (not pool id!) of a parameter.
|
||||
* @return true if exists, false else.
|
||||
*/
|
||||
bool exists(uint32_t parameterId);
|
||||
};
|
||||
|
||||
//We assume someone globally instantiates a DataPool.
|
||||
namespace glob {
|
||||
extern GlobalDataPool dataPool;
|
||||
}
|
||||
|
||||
#endif /* DATAPOOL_H_ */
|
48
datapoolglob/GlobalDataSet.cpp
Normal file
48
datapoolglob/GlobalDataSet.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "../datapoolglob/GlobalDataPool.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
GlobDataSet::GlobDataSet(): PoolDataSetBase(
|
||||
reinterpret_cast<PoolVariableIF**>(®isteredVariables),
|
||||
DATA_SET_MAX_SIZE) {}
|
||||
|
||||
// Don't do anything with your variables, they are dead already!
|
||||
// (Destructor is already called)
|
||||
GlobDataSet::~GlobDataSet() {}
|
||||
|
||||
ReturnValue_t GlobDataSet::commit(bool valid, uint32_t lockTimeout) {
|
||||
setEntriesValid(valid);
|
||||
setSetValid(valid);
|
||||
return commit(lockTimeout);
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::commit(uint32_t lockTimeout) {
|
||||
return PoolDataSetBase::commit(lockTimeout);
|
||||
}
|
||||
|
||||
bool GlobDataSet::isValid() const {
|
||||
return this->valid;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::unlockDataPool() {
|
||||
return glob::dataPool.unlockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::lockDataPool(uint32_t timeoutMs) {
|
||||
return glob::dataPool.lockDataPool(timeoutMs);
|
||||
}
|
||||
|
||||
void GlobDataSet::setEntriesValid(bool valid) {
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ) {
|
||||
registeredVariables[count]->setValid(valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlobDataSet::setSetValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
|
98
datapoolglob/GlobalDataSet.h
Normal file
98
datapoolglob/GlobalDataSet.h
Normal file
@ -0,0 +1,98 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLGLOB_DATASET_H_
|
||||
#define FRAMEWORK_DATAPOOLGLOB_DATASET_H_
|
||||
|
||||
#include "../datapool/PoolDataSetBase.h"
|
||||
|
||||
/**
|
||||
* @brief The DataSet class manages a set of locally checked out variables
|
||||
* for the global data pool.
|
||||
* @details
|
||||
* This class uses the read-commit() semantic provided by the DataSetBase class.
|
||||
* It extends the base class by using the global data pool,
|
||||
* having a valid state and implementing lock und unlock calls for the global
|
||||
* datapool.
|
||||
*
|
||||
* For more information on how this class works, see the DataSetBase
|
||||
* documentation.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class GlobDataSet: public PoolDataSetBase {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Creates an empty GlobDataSet. Use registerVariable or
|
||||
* supply a pointer to this dataset to PoolVariable
|
||||
* initializations to register pool variables.
|
||||
*/
|
||||
GlobDataSet();
|
||||
|
||||
/**
|
||||
* @brief The destructor automatically manages writing the valid
|
||||
* information of variables.
|
||||
* @details
|
||||
* In case the data set was read out, but not committed(indicated by state),
|
||||
* the destructor parses all variables that are still registered to the set.
|
||||
* For each, the valid flag in the data pool is set to "invalid".
|
||||
*/
|
||||
~GlobDataSet();
|
||||
|
||||
/**
|
||||
* Variant of method above which sets validity of all elements of the set.
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
* @return - @c RETURN_OK if all variables were read successfully.
|
||||
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||
* contains non write-only variables
|
||||
*/
|
||||
ReturnValue_t commit(bool valid, uint32_t lockTimeout = MutexIF::BLOCKING);
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
/**
|
||||
* Set all entries
|
||||
* @param valid
|
||||
*/
|
||||
void setSetValid(bool valid);
|
||||
|
||||
bool isValid() const override;
|
||||
|
||||
/**
|
||||
* Set the valid information of all variables contained in the set which
|
||||
* are not read-only
|
||||
*
|
||||
* @param valid Validity information from PoolVariableIF.
|
||||
*/
|
||||
void setEntriesValid(bool valid);
|
||||
|
||||
//!< This definition sets the maximum number of variables to
|
||||
//! register in one DataSet.
|
||||
static const uint8_t DATA_SET_MAX_SIZE = 63;
|
||||
|
||||
private:
|
||||
/**
|
||||
* If the valid state of a dataset is always relevant to the whole
|
||||
* data set we can use this flag.
|
||||
*/
|
||||
bool valid = false;
|
||||
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate locking
|
||||
* the global data pool.
|
||||
* @details
|
||||
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t lockDataPool(uint32_t timeoutMs) override;
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate
|
||||
* unlocking the global data pool
|
||||
* @details
|
||||
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool() override;
|
||||
|
||||
void handleAlreadyReadDatasetCommit();
|
||||
ReturnValue_t handleUnreadDatasetCommit();
|
||||
|
||||
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLGLOB_DATASET_H_ */
|
213
datapoolglob/GlobalPoolVariable.h
Normal file
213
datapoolglob/GlobalPoolVariable.h
Normal file
@ -0,0 +1,213 @@
|
||||
#ifndef GLOBALPOOLVARIABLE_H_
|
||||
#define GLOBALPOOLVARIABLE_H_
|
||||
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapoolglob/GlobalDataPool.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../datapool/PoolEntry.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
template<typename T, uint8_t n_var> class PoolVarList;
|
||||
|
||||
|
||||
/**
|
||||
* @brief This is the access class for non-array data pool entries.
|
||||
*
|
||||
* @details
|
||||
* To ensure safe usage of the data pool, operation is not done directly
|
||||
* on the data pool entries, but on local copies. This class provides simple
|
||||
* type-safe access to single data pool entries (i.e. entries with length = 1).
|
||||
* The class can be instantiated as read-write and read only.
|
||||
* It provides a commit-and-roll-back semantic, which means that the
|
||||
* variable's value in the data pool is not changed until the
|
||||
* commit call is executed.
|
||||
* @tparam T The template parameter sets the type of the variable.
|
||||
* Currently, all plain data types are supported, but in principle
|
||||
* any type is possible.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T>
|
||||
class GlobPoolVar: public PoolVariableIF {
|
||||
template<typename U, uint8_t n_var> friend class PoolVarList;
|
||||
static_assert(not std::is_same<T, bool>::value,
|
||||
"Do not use boolean for the PoolEntry type, use uint8_t instead!"
|
||||
"There is no boolean type in CCSDS.");
|
||||
public:
|
||||
/**
|
||||
* @brief In the constructor, the variable can register itself in a
|
||||
* DataSet (if nullptr is not passed).
|
||||
* @details
|
||||
* It DOES NOT fetch the current value from the data pool, but
|
||||
* sets the value attribute to default (0).
|
||||
* The value is fetched within the read() operation.
|
||||
* @param set_id This is the id in the global data pool
|
||||
* this instance of the access class corresponds to.
|
||||
* @param dataSet The data set in which the variable shall register
|
||||
* itself. If NULL, the variable is not registered.
|
||||
* @param setWritable If this flag is set to true, changes in the value
|
||||
* attribute can be written back to the data pool, otherwise not.
|
||||
*/
|
||||
GlobPoolVar(uint32_t set_id, DataSetIF* dataSet,
|
||||
ReadWriteMode_t setReadWriteMode);
|
||||
|
||||
/**
|
||||
* @brief This is the local copy of the data pool entry.
|
||||
* @details The user can work on this attribute
|
||||
* just like he would on a simple local variable.
|
||||
*/
|
||||
T value = 0;
|
||||
|
||||
/**
|
||||
* @brief Copy ctor to copy classes containing Pool Variables.
|
||||
* (Robin): This only copies member variables, which is done
|
||||
* by the default copy ctor. maybe we can ommit this ctor?
|
||||
*/
|
||||
GlobPoolVar(const GlobPoolVar& rhs);
|
||||
|
||||
/**
|
||||
* @brief The classes destructor is empty.
|
||||
* @details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~GlobPoolVar() {}
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the value from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout) override;
|
||||
/**
|
||||
* @brief The commit call writes back the variable's value to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* The commit call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls,
|
||||
* the data pool is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool is
|
||||
* copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
|
||||
/**
|
||||
* @brief The information whether the class is read-write or read-only
|
||||
* is stored here.
|
||||
*/
|
||||
pool_rwm_t readWriteMode;
|
||||
|
||||
/**
|
||||
* Empty ctor for List initialization
|
||||
*/
|
||||
GlobPoolVar();
|
||||
public:
|
||||
/**
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const override;
|
||||
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const override;
|
||||
/**
|
||||
* This operation sets the data pool id of the variable.
|
||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId);
|
||||
|
||||
/**
|
||||
* \brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const override;
|
||||
|
||||
uint8_t getValid();
|
||||
|
||||
void setValid(bool valid) override;
|
||||
|
||||
operator T() {
|
||||
return value;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
GlobPoolVar<T> &operator=(T newValue) {
|
||||
value = newValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GlobPoolVar<T> &operator=(GlobPoolVar<T> newPoolVariable) {
|
||||
value = newPoolVariable.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize(&value, buffer, size, max_size,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return SerializeAdapter::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
return SerializeAdapter::deSerialize(&value, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
};
|
||||
|
||||
#include "../datapoolglob/GlobalPoolVariable.tpp"
|
||||
|
||||
typedef GlobPoolVar<uint8_t> gp_bool_t;
|
||||
typedef GlobPoolVar<uint8_t> gp_uint8_t;
|
||||
typedef GlobPoolVar<uint16_t> gp_uint16_t;
|
||||
typedef GlobPoolVar<uint32_t> gp_uint32_t;
|
||||
typedef GlobPoolVar<int8_t> gp_int8_t;
|
||||
typedef GlobPoolVar<int16_t> gp_int16_t;
|
||||
typedef GlobPoolVar<int32_t> gp_int32_t;
|
||||
typedef GlobPoolVar<float> gp_float_t;
|
||||
typedef GlobPoolVar<double> gp_double_t;
|
||||
|
||||
#endif /* POOLVARIABLE_H_ */
|
117
datapoolglob/GlobalPoolVariable.tpp
Normal file
117
datapoolglob/GlobalPoolVariable.tpp
Normal file
@ -0,0 +1,117 @@
|
||||
#ifndef GLOBALPOOLVARIABLE_TPP_
|
||||
#define GLOBALPOOLVARIABLE_TPP_
|
||||
|
||||
template <class T>
|
||||
inline GlobPoolVar<T>::GlobPoolVar(uint32_t set_id,
|
||||
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode):
|
||||
dataPoolId(set_id), valid(PoolVariableIF::INVALID),
|
||||
readWriteMode(setReadWriteMode)
|
||||
{
|
||||
if (dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::commit(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = commitWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::readWithoutLock() {
|
||||
PoolEntry<T>* read_out = glob::dataPool.getData<T>(dataPoolId, 1);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = *(read_out->address);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
value = 0;
|
||||
valid = false;
|
||||
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline ReturnValue_t GlobPoolVar<T>::commitWithoutLock() {
|
||||
PoolEntry<T>* write_back = glob::dataPool.getData<T>(dataPoolId, 1);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->valid = valid;
|
||||
*(write_back->address) = value;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline GlobPoolVar<T>::GlobPoolVar():
|
||||
dataPoolId(PoolVariableIF::NO_PARAMETER),
|
||||
valid(PoolVariableIF::INVALID),
|
||||
readWriteMode(VAR_READ), value(0) {}
|
||||
|
||||
template <class T>
|
||||
inline GlobPoolVar<T>::GlobPoolVar(const GlobPoolVar& rhs) :
|
||||
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
||||
rhs.readWriteMode), value(rhs.value) {}
|
||||
|
||||
template <class T>
|
||||
inline pool_rwm_t GlobPoolVar<T>::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline uint32_t GlobPoolVar<T>::getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void GlobPoolVar<T>::setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool GlobPoolVar<T>::isValid() const {
|
||||
if (valid)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline uint8_t GlobPoolVar<T>::getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void GlobPoolVar<T>::setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
#endif
|
185
datapoolglob/GlobalPoolVector.h
Normal file
185
datapoolglob/GlobalPoolVector.h
Normal file
@ -0,0 +1,185 @@
|
||||
#ifndef FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_H_
|
||||
#define FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_H_
|
||||
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapool/PoolEntry.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
/**
|
||||
* @brief This is the access class for array-type data pool entries.
|
||||
*
|
||||
* @details
|
||||
* To ensure safe usage of the data pool, operation is not done directly on the
|
||||
* data pool entries, but on local copies. This class provides simple type-
|
||||
* and length-safe access to vector-style data pool entries (i.e. entries with
|
||||
* length > 1). The class can be instantiated as read-write and read only.
|
||||
*
|
||||
* It provides a commit-and-roll-back semantic, which means that no array
|
||||
* entry in the data pool is changed until the commit call is executed.
|
||||
* There are two template parameters:
|
||||
* @tparam T
|
||||
* This template parameter specifies the data type of an array entry. Currently,
|
||||
* all plain data types are supported, but in principle any type is possible.
|
||||
* @tparam vector_size
|
||||
* This template parameter specifies the vector size of this entry. Using a
|
||||
* template parameter for this is not perfect, but avoids
|
||||
* dynamic memory allocation.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T, uint16_t vectorSize>
|
||||
class GlobPoolVector: public PoolVariableIF {
|
||||
public:
|
||||
/**
|
||||
* @brief In the constructor, the variable can register itself in a
|
||||
* DataSet (if no nullptr is passed).
|
||||
* @details
|
||||
* It DOES NOT fetch the current value from the data pool, but sets the
|
||||
* value attribute to default (0). The value is fetched within the
|
||||
* read() operation.
|
||||
* @param set_id
|
||||
* This is the id in the global data pool this instance of the access
|
||||
* class corresponds to.
|
||||
* @param dataSet
|
||||
* The data set in which the variable shall register itself. If nullptr,
|
||||
* the variable is not registered.
|
||||
* @param setWritable
|
||||
* If this flag is set to true, changes in the value attribute can be
|
||||
* written back to the data pool, otherwise not.
|
||||
*/
|
||||
GlobPoolVector(uint32_t set_id, DataSetIF* set,
|
||||
ReadWriteMode_t setReadWriteMode);
|
||||
|
||||
/**
|
||||
* @brief This is the local copy of the data pool entry.
|
||||
* @details The user can work on this attribute
|
||||
* just like he would on a local array of this type.
|
||||
*/
|
||||
T value[vectorSize];
|
||||
/**
|
||||
* @brief The classes destructor is empty.
|
||||
* @details If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~GlobPoolVector() {};
|
||||
/**
|
||||
* @brief The operation returns the number of array entries
|
||||
* in this variable.
|
||||
*/
|
||||
uint8_t getSize() {
|
||||
return vectorSize;
|
||||
}
|
||||
/**
|
||||
* @brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
/**
|
||||
* @brief This operation sets the data pool id of the variable.
|
||||
* @details
|
||||
* The method is necessary to set id's of data pool member variables
|
||||
* with bad initialization.
|
||||
*/
|
||||
void setDataPoolId(uint32_t poolId) {
|
||||
dataPoolId = poolId;
|
||||
}
|
||||
/**
|
||||
* This method returns if the variable is write-only, read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
void setValid(bool valid) {this->valid = valid;}
|
||||
uint8_t getValid() {return valid;}
|
||||
|
||||
T &operator [](int i) {return value[i];}
|
||||
const T &operator [](int i) const {return value[i];}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t max_size, Endianness streamEndianness) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the array's values
|
||||
* from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies all array values
|
||||
* and the valid information to its local attributes.
|
||||
* In case of a failure (wrong type, size or pool id not found), the
|
||||
* variable is set to zero and invalid.
|
||||
* The read call is protected by a lock of the global data pool.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call copies the array values back to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The commit call is protected by a lock of the global data pool.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls,
|
||||
* the data pool id is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool
|
||||
* is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* @brief The information whether the class is read-write or
|
||||
* read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
};
|
||||
|
||||
#include "../datapoolglob/GlobalPoolVector.tpp"
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
using gp_vec_t = GlobPoolVector<T, vectorSize>;
|
||||
|
||||
#endif /* FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_H_ */
|
117
datapoolglob/GlobalPoolVector.tpp
Normal file
117
datapoolglob/GlobalPoolVector.tpp
Normal file
@ -0,0 +1,117 @@
|
||||
#ifndef FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_TPP_
|
||||
#define FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_TPP_
|
||||
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline GlobPoolVector<T, vectorSize>::GlobPoolVector(uint32_t set_id,
|
||||
DataSetIF* set, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
||||
memset(this->value, 0, vectorSize * sizeof(T));
|
||||
if (set != nullptr) {
|
||||
set->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commit(
|
||||
uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = commitWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::readWithoutLock() {
|
||||
PoolEntry<T>* read_out = glob::dataPool.getData<T>(this->dataPoolId,
|
||||
vectorSize);
|
||||
if (read_out != nullptr) {
|
||||
this->valid = read_out->valid;
|
||||
memcpy(this->value, read_out->address, read_out->getByteSize());
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
} else {
|
||||
memset(this->value, 0, vectorSize * sizeof(T));
|
||||
sif::error << "PoolVector: Read of DP Variable 0x" << std::hex
|
||||
<< std::setw(8) << std::setfill('0') << dataPoolId <<
|
||||
std::dec << " failed." << std::endl;
|
||||
this->valid = INVALID;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commitWithoutLock() {
|
||||
PoolEntry<T>* writeBack = glob::dataPool.getData<T>(this->dataPoolId,
|
||||
vectorSize);
|
||||
if ((writeBack != nullptr) && (this->readWriteMode != VAR_READ)) {
|
||||
writeBack->valid = valid;
|
||||
memcpy(writeBack->address, this->value, writeBack->getByteSize());
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
|
||||
size_t* size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vectorSize; i++) {
|
||||
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||
max_size, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline size_t GlobPoolVector<T, vectorSize>::getSerializedSize() const {
|
||||
return vectorSize * SerializeAdapter::getSerializedSize(value);
|
||||
}
|
||||
|
||||
template<typename T, uint16_t vectorSize>
|
||||
inline ReturnValue_t GlobPoolVector<T, vectorSize>::deSerialize(
|
||||
const uint8_t** buffer, size_t* size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vectorSize; i++) {
|
||||
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||
streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#ifndef PIDREADER_H_
|
||||
#define PIDREADER_H_
|
||||
#include "DataPool.h"
|
||||
#include "DataSetIF.h"
|
||||
#include "PoolEntry.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapoolglob/GlobalDataPool.h"
|
||||
#include "../datapool/PoolEntry.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
@ -15,10 +15,10 @@ class PIDReader: public PoolVariableIF {
|
||||
protected:
|
||||
uint32_t parameterId;
|
||||
uint8_t valid;
|
||||
ReturnValue_t read() {
|
||||
uint8_t arrayIndex = DataPool::PIDToArrayIndex(parameterId);
|
||||
PoolEntry<T> *read_out = ::dataPool.getData<T>(
|
||||
DataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||
ReturnValue_t readWithoutLock() {
|
||||
uint8_t arrayIndex = GlobalDataPool::PIDToArrayIndex(parameterId);
|
||||
PoolEntry<T> *read_out = glob::dataPool.getData<T>(
|
||||
GlobalDataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = read_out->address[arrayIndex];
|
||||
@ -36,9 +36,13 @@ protected:
|
||||
* Reason is the possibility to access a single DP vector element, but if we commit,
|
||||
* we set validity of the whole vector.
|
||||
*/
|
||||
ReturnValue_t commit() {
|
||||
ReturnValue_t commit(uint32_t lockTimeout) override {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
ReturnValue_t commitWithoutLock() override {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty ctor for List initialization
|
||||
*/
|
||||
@ -72,6 +76,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t read(uint32_t lockTimeout) override {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "PIDReader::read: Could not unlock data pool!"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Copy ctor to copy classes containing Pool Variables.
|
||||
*/
|
||||
@ -89,7 +106,7 @@ public:
|
||||
* \brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const {
|
||||
return DataPool::PIDToDataPoolId(parameterId);
|
||||
return GlobalDataPool::PIDToDataPoolId(parameterId);
|
||||
}
|
||||
uint32_t getParameterId() const {
|
||||
return parameterId;
|
||||
@ -114,7 +131,7 @@ public:
|
||||
return valid;
|
||||
}
|
||||
|
||||
void setValid(uint8_t valid) {
|
||||
void setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_PIDREADERLIST_H_
|
||||
#define FRAMEWORK_DATAPOOL_PIDREADERLIST_H_
|
||||
#ifndef FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_
|
||||
#define FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_
|
||||
|
||||
#include "PIDReader.h"
|
||||
#include "PoolVariableIF.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../datapoolglob/PIDReader.h"
|
||||
template <class T, uint8_t n_var>
|
||||
class PIDReaderList {
|
||||
private:
|
||||
@ -24,4 +24,4 @@ public:
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_PIDREADERLIST_H_ */
|
||||
#endif /* FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_ */
|
239
datapoolglob/PoolRawAccess.cpp
Normal file
239
datapoolglob/PoolRawAccess.cpp
Normal file
@ -0,0 +1,239 @@
|
||||
#include "../datapoolglob/GlobalDataPool.h"
|
||||
#include "../datapoolglob/PoolRawAccess.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../serialize/EndianConverter.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode) :
|
||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false),
|
||||
type(Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0),
|
||||
readWriteMode(setReadWriteMode) {
|
||||
memset(value, 0, sizeof(value));
|
||||
if (dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
PoolRawAccess::~PoolRawAccess() {}
|
||||
|
||||
ReturnValue_t PoolRawAccess::read(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = readWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::readWithoutLock() {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
PoolEntryIF* readOut = glob::dataPool.getRawData(dataPoolId);
|
||||
if (readOut != nullptr) {
|
||||
result = handleReadOut(readOut);
|
||||
if(result == RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
result = READ_ENTRY_NON_EXISTENT;
|
||||
}
|
||||
handleReadError(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* readOut) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
valid = readOut->getValid();
|
||||
if (readOut->getSize() > arrayEntry) {
|
||||
arraySize = readOut->getSize();
|
||||
typeSize = readOut->getByteSize() / readOut->getSize();
|
||||
type = readOut->getType();
|
||||
if (typeSize <= sizeof(value)) {
|
||||
uint16_t arrayPosition = arrayEntry * typeSize;
|
||||
sizeTillEnd = readOut->getByteSize() - arrayPosition;
|
||||
uint8_t* ptr = &((uint8_t*) readOut->getRawData())[arrayPosition];
|
||||
memcpy(value, ptr, typeSize);
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
result = READ_TYPE_TOO_LARGE;
|
||||
}
|
||||
} else {
|
||||
//debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl;
|
||||
result = READ_INDEX_TOO_LARGE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PoolRawAccess::handleReadError(ReturnValue_t result) {
|
||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId
|
||||
<< std::dec << " failed, ";
|
||||
if(result == READ_TYPE_TOO_LARGE) {
|
||||
sif::error << "type too large." << std::endl;
|
||||
}
|
||||
else if(result == READ_INDEX_TOO_LARGE) {
|
||||
sif::error << "index too large." << std::endl;
|
||||
}
|
||||
else if(result == READ_ENTRY_NON_EXISTENT) {
|
||||
sif::error << "entry does not exist." << std::endl;
|
||||
}
|
||||
|
||||
valid = INVALID;
|
||||
typeSize = 0;
|
||||
sizeTillEnd = 0;
|
||||
memset(value, 0, sizeof(value));
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commit(uint32_t lockTimeout) {
|
||||
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = commitWithoutLock();
|
||||
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||
<< std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commitWithoutLock() {
|
||||
PoolEntryIF* write_back = glob::dataPool.getRawData(dataPoolId);
|
||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||
write_back->setValid(valid);
|
||||
uint8_t array_position = arrayEntry * typeSize;
|
||||
uint8_t* ptr = &((uint8_t*) write_back->getRawData())[array_position];
|
||||
memcpy(ptr, value, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* PoolRawAccess::getEntry() {
|
||||
return value;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
|
||||
size_t* writtenBytes, size_t max_size) {
|
||||
uint8_t* data_ptr = getEntry();
|
||||
// debug << "PoolRawAccess::getEntry: Array position: " <<
|
||||
// index * size_of_type << " Size of T: " << (int)size_of_type <<
|
||||
// " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
||||
if (typeSize == 0)
|
||||
return DATA_POOL_ACCESS_FAILED;
|
||||
if (typeSize > max_size)
|
||||
return INCORRECT_SIZE;
|
||||
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
||||
*writtenBytes = typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
if (typeSize + *size <= maxSize) {
|
||||
switch(streamEndianness) {
|
||||
case(Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case(Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
||||
break;
|
||||
case(Endianness::MACHINE):
|
||||
default:
|
||||
memcpy(*buffer, value, typeSize);
|
||||
break;
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Type PoolRawAccess::getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeOfType() {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getArraySize(){
|
||||
return arraySize;
|
||||
}
|
||||
|
||||
uint32_t PoolRawAccess::getDataPoolId() const {
|
||||
return dataPoolId;
|
||||
}
|
||||
|
||||
PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
||||
size_t setSize) {
|
||||
if (typeSize == setSize) {
|
||||
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
sif::error << "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: "
|
||||
"Internal" << (uint32_t) typeSize << ", Requested: " << setSize
|
||||
<< std::endl;
|
||||
return INCORRECT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
bool PoolRawAccess::isValid() const {
|
||||
if (valid != INVALID)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void PoolRawAccess::setValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSizeTillEnd() const {
|
||||
return sizeTillEnd;
|
||||
}
|
||||
|
||||
|
||||
size_t PoolRawAccess::getSerializedSize() const {
|
||||
return typeSize;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) {
|
||||
|
||||
if (*size >= typeSize) {
|
||||
switch(streamEndianness) {
|
||||
case(Endianness::BIG):
|
||||
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case(Endianness::LITTLE):
|
||||
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
||||
break;
|
||||
case(Endianness::MACHINE):
|
||||
default:
|
||||
memcpy(value, *buffer, typeSize);
|
||||
break;
|
||||
}
|
||||
*size -= typeSize;
|
||||
*buffer += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
220
datapoolglob/PoolRawAccess.h
Normal file
220
datapoolglob/PoolRawAccess.h
Normal file
@ -0,0 +1,220 @@
|
||||
#ifndef POOLRAWACCESS_H_
|
||||
#define POOLRAWACCESS_H_
|
||||
|
||||
#include "../datapool/DataSetIF.h"
|
||||
#include "../datapool/PoolEntryIF.h"
|
||||
#include "../datapool/PoolVariableIF.h"
|
||||
#include "../globalfunctions/Type.h"
|
||||
|
||||
/**
|
||||
* @brief This class allows accessing Data Pool variables as raw bytes.
|
||||
* @details
|
||||
* This is necessary to have an access method for HK data, as the PID's alone
|
||||
* do not provide type information. Please note that the the raw pool access
|
||||
* read() and commit() calls are not thread-safe.
|
||||
*
|
||||
* Please supply a data set and use the data set read(), commit() calls for
|
||||
* thread-safe data pool access.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolRawAccess: public PoolVariableIF, HasReturnvaluesIF {
|
||||
public:
|
||||
/**
|
||||
* This constructor is used to access a data pool entry with a
|
||||
* given ID if the target type is not known. A DataSet object is supplied
|
||||
* and the data pool entry with the given ID is registered to that data set.
|
||||
* Please note that a pool raw access buffer only has a buffer
|
||||
* with a size of double. As such, for vector entries which have
|
||||
* @param data_pool_id Target data pool entry ID
|
||||
* @param arrayEntry
|
||||
* @param data_set Dataset to register data pool entry to
|
||||
* @param setReadWriteMode
|
||||
* @param registerVectors If set to true, the constructor checks if
|
||||
* there are multiple vector entries to registers
|
||||
* and registers all of them recursively into the data_set
|
||||
*
|
||||
*/
|
||||
PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry,
|
||||
DataSetIF* data_set, ReadWriteMode_t setReadWriteMode =
|
||||
PoolVariableIF::VAR_READ);
|
||||
|
||||
/**
|
||||
* @brief This operation returns a pointer to the entry fetched.
|
||||
* @details Return pointer to the buffer containing the raw data
|
||||
* Size and number of data can be retrieved by other means.
|
||||
*/
|
||||
uint8_t* getEntry();
|
||||
/**
|
||||
* @brief This operation returns the fetched entry from the data pool and
|
||||
* flips the bytes, if necessary.
|
||||
* @details It makes use of the getEntry call of this function, but additionally flips the
|
||||
* bytes to big endian, which is the default for external communication (as House-
|
||||
* keeping telemetry). To achieve this, the data is copied directly to the passed
|
||||
* buffer, if it fits in the given max_size.
|
||||
* @param buffer A pointer to a buffer to write to
|
||||
* @param writtenBytes The number of bytes written is returned with this value.
|
||||
* @param max_size The maximum size that the function may write to buffer.
|
||||
* @return - @c RETURN_OK if entry could be acquired
|
||||
* - @c RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
||||
size_t maxSize);
|
||||
|
||||
/**
|
||||
* @brief Serialize raw pool entry into provided buffer directly
|
||||
* @param buffer Provided buffer. Raw pool data will be copied here
|
||||
* @param size [out] Increment provided size value by serialized size
|
||||
* @param max_size Maximum allowed serialization size
|
||||
* @param bigEndian Specify endianess
|
||||
* @return - @c RETURN_OK if serialization was successfull
|
||||
* - @c SerializeIF::BUFFER_TOO_SHORT if range check failed
|
||||
*/
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* With this method, the content can be set from a big endian buffer safely.
|
||||
* @param buffer Pointer to the data to set
|
||||
* @param size Size of the data to write. Must fit this->size.
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t setEntryFromBigEndian(const uint8_t* buffer,
|
||||
size_t setSize);
|
||||
/**
|
||||
* @brief This operation returns the type of the entry currently stored.
|
||||
*/
|
||||
Type getType();
|
||||
/**
|
||||
* @brief This operation returns the size of the entry currently stored.
|
||||
*/
|
||||
size_t getSizeOfType();
|
||||
/**
|
||||
*
|
||||
* @return the size of the datapool array
|
||||
*/
|
||||
size_t getArraySize();
|
||||
/**
|
||||
* @brief This operation returns the data pool id of the variable.
|
||||
*/
|
||||
uint32_t getDataPoolId() const;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS;
|
||||
static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t READ_TYPE_TOO_LARGE = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t READ_INDEX_TOO_LARGE = MAKE_RETURN_CODE(0x04);
|
||||
static const ReturnValue_t READ_ENTRY_NON_EXISTENT = MAKE_RETURN_CODE(0x05);
|
||||
static const uint8_t RAW_MAX_SIZE = sizeof(double);
|
||||
uint8_t value[RAW_MAX_SIZE];
|
||||
|
||||
|
||||
/**
|
||||
* @brief The classes destructor is empty. If commit() was not called, the local value is
|
||||
* discarded and not written back to the data pool.
|
||||
*/
|
||||
~PoolRawAccess();
|
||||
|
||||
/**
|
||||
* This method returns if the variable is read-write or read-only.
|
||||
*/
|
||||
ReadWriteMode_t getReadWriteMode() const;
|
||||
/**
|
||||
* @brief With this call, the valid information of the variable is returned.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
void setValid(bool valid);
|
||||
/**
|
||||
* Getter for the remaining size.
|
||||
*/
|
||||
size_t getSizeTillEnd() const;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the value from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the global data pool and copies the value and the valid
|
||||
* information to its local attributes. In case of a failure (wrong type or
|
||||
* pool id not found), the variable is set to zero and invalid.
|
||||
* The call is protected by a lock of the global data pool.
|
||||
* @return -@c RETURN_OK Read successfull
|
||||
* -@c READ_TYPE_TOO_LARGE
|
||||
* -@c READ_INDEX_TOO_LARGE
|
||||
* -@c READ_ENTRY_NON_EXISTENT
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call writes back the variable's value to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the valid flag is automatically set to "valid".
|
||||
* The call is protected by a lock of the global data pool.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
ReturnValue_t handleReadOut(PoolEntryIF* read_out);
|
||||
void handleReadError(ReturnValue_t result);
|
||||
private:
|
||||
/**
|
||||
* @brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||
* is stored.
|
||||
*/
|
||||
uint32_t dataPoolId;
|
||||
/**
|
||||
* @brief The array entry that is fetched from the data pool.
|
||||
*/
|
||||
uint8_t arrayEntry;
|
||||
/**
|
||||
* @brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||
*/
|
||||
uint8_t valid;
|
||||
/**
|
||||
* @brief This value contains the type of the data pool entry.
|
||||
*/
|
||||
Type type;
|
||||
/**
|
||||
* @brief This value contains the size of the data pool entry type in bytes.
|
||||
*/
|
||||
size_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
size_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
size_t sizeTillEnd;
|
||||
/**
|
||||
* @brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
};
|
||||
|
||||
#endif /* POOLRAWACCESS_H_ */
|
@ -5,8 +5,8 @@
|
||||
#include "../objectmanager/ObjectManager.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PoolVariable.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../subsystem/SubsystemBase.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
@ -186,8 +186,8 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
||||
fillCommandAndReplyMap();
|
||||
|
||||
//Set temperature target state to NON_OP.
|
||||
DataSet mySet;
|
||||
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_WRITE);
|
||||
mySet.read();
|
||||
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
||||
@ -469,8 +469,8 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
||||
Clock::getUptime(&timeoutStart);
|
||||
|
||||
if (mode == MODE_OFF) {
|
||||
DataSet mySet;
|
||||
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -926,10 +926,10 @@ ReturnValue_t DeviceHandlerBase::checkModeCommand(Mode_t commandedMode,
|
||||
|
||||
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
||||
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
||||
DataSet mySet;
|
||||
db_int8_t thermalState(deviceThermalStatePoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t thermalState(deviceThermalStatePoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
gp_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -956,8 +956,8 @@ void DeviceHandlerBase::startTransition(Mode_t commandedMode,
|
||||
childTransitionDelay = getTransitionDelayMs(_MODE_START_UP,
|
||||
MODE_ON);
|
||||
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
||||
DataSet mySet;
|
||||
db_int8_t thermalRequest(deviceThermalRequestPoolId,
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t thermalRequest(deviceThermalRequestPoolId,
|
||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -1185,7 +1185,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
||||
}
|
||||
//Try to cast to GlobDataSet and commit data.
|
||||
if (!neverInDataPool) {
|
||||
DataSet* dataSet = dynamic_cast<DataSet*>(data);
|
||||
GlobDataSet* dataSet = dynamic_cast<GlobDataSet*>(data);
|
||||
if (dataSet != NULL) {
|
||||
dataSet->commit(PoolVariableIF::VALID);
|
||||
}
|
||||
|
3
fsfw.mk
3
fsfw.mk
@ -9,6 +9,9 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/controller/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/coordinates/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datalinklayer/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapool/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoolglob/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoollocal/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/housekeeping/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/devicehandlers/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/*.cpp)
|
||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/eventmatching/*.cpp)
|
||||
|
@ -1,17 +1,16 @@
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "InternalErrorReporter.h"
|
||||
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PoolVariable.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId,
|
||||
uint32_t queuePoolId, uint32_t tmPoolId, uint32_t storePoolId) :
|
||||
SystemObject(setObjectId), mutex(NULL), queuePoolId(queuePoolId), tmPoolId(
|
||||
tmPoolId), storePoolId(
|
||||
storePoolId), queueHits(0), tmHits(0), storeHits(
|
||||
0) {
|
||||
SystemObject(setObjectId), mutex(NULL), queuePoolId(queuePoolId),
|
||||
tmPoolId(tmPoolId),storePoolId(storePoolId), queueHits(0), tmHits(0),
|
||||
storeHits(0) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
@ -21,13 +20,13 @@ InternalErrorReporter::~InternalErrorReporter() {
|
||||
|
||||
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
|
||||
|
||||
DataSet mySet;
|
||||
PoolVariable<uint32_t> queueHitsInPool(queuePoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint32_t queueHitsInPool(queuePoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
PoolVariable<uint32_t> tmHitsInPool(tmPoolId, &mySet,
|
||||
gp_uint32_t tmHitsInPool(tmPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
|
||||
PoolVariable<uint32_t> storeHitsInPool(storePoolId, &mySet,
|
||||
gp_uint32_t storeHitsInPool(storePoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
#ifndef MONITORBASE_H_
|
||||
#define MONITORBASE_H_
|
||||
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PIDReader.h"
|
||||
#include "LimitViolationReporter.h"
|
||||
#include "MonitoringIF.h"
|
||||
#include "MonitoringMessageContent.h"
|
||||
#include "MonitorReporter.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/PIDReader.h"
|
||||
#include "../monitoring/LimitViolationReporter.h"
|
||||
#include "../monitoring/MonitoringIF.h"
|
||||
#include "../monitoring/MonitoringMessageContent.h"
|
||||
#include "../monitoring/MonitorReporter.h"
|
||||
|
||||
/**
|
||||
* Base class for monitoring of parameters.
|
||||
@ -48,7 +48,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual ReturnValue_t fetchSample(T* sample) {
|
||||
DataSet mySet;
|
||||
GlobDataSet mySet;
|
||||
PIDReader<T> parameter(this->parameterId, &mySet);
|
||||
mySet.read();
|
||||
if (!parameter.isValid()) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "../monitoring/LimitViolationReporter.h"
|
||||
#include "../monitoring/MonitoringMessageContent.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "Fuse.h"
|
||||
#include "../power/Fuse.h"
|
||||
#include "../serialize/SerialFixedArrayListAdapter.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
@ -12,7 +12,7 @@ Fuse::Fuse(object_id_t fuseObjectId, uint8_t fuseId, VariableIds ids,
|
||||
SystemObject(fuseObjectId), oldFuseState(0), fuseId(fuseId), powerIF(
|
||||
NULL), currentLimit(fuseObjectId, 1, ids.pidCurrent, confirmationCount,
|
||||
maxCurrent, FUSE_CURRENT_HIGH), powerMonitor(fuseObjectId, 2,
|
||||
DataPool::poolIdAndPositionToPid(ids.poolIdPower, 0),
|
||||
GlobalDataPool::poolIdAndPositionToPid(ids.poolIdPower, 0),
|
||||
confirmationCount), set(), voltage(ids.pidVoltage, &set), current(
|
||||
ids.pidCurrent, &set), state(ids.pidState, &set), power(
|
||||
ids.poolIdPower, &set, PoolVariableIF::VAR_READ_WRITE), commandQueue(
|
||||
@ -109,7 +109,7 @@ size_t Fuse::getSerializedSize() const {
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (DeviceList::iterator iter = devices.begin(); iter != devices.end();
|
||||
iter++) {
|
||||
|
15
power/Fuse.h
15
power/Fuse.h
@ -1,12 +1,13 @@
|
||||
#ifndef FUSE_H_
|
||||
#define FUSE_H_
|
||||
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PIDReader.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../datapoolglob/PIDReader.h"
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../monitoring/AbsLimitMonitor.h"
|
||||
#include "PowerComponentIF.h"
|
||||
#include "PowerSwitchIF.h"
|
||||
#include "../power/PowerComponentIF.h"
|
||||
#include "../power/PowerSwitchIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../parameters/ParameterHelper.h"
|
||||
#include <list>
|
||||
@ -84,12 +85,12 @@ private:
|
||||
|
||||
};
|
||||
PowerMonitor powerMonitor;
|
||||
DataSet set;
|
||||
GlobDataSet set;
|
||||
PIDReader<float> voltage;
|
||||
PIDReader<float> current;
|
||||
PIDReader<uint8_t> state;
|
||||
db_float_t power;
|
||||
MessageQueueIF *commandQueue;
|
||||
gp_float_t power;
|
||||
MessageQueueIF* commandQueue;
|
||||
ParameterHelper parameterHelper;
|
||||
HealthHelper healthHelper;
|
||||
static object_id_t powerSwitchId;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef POWERSENSOR_H_
|
||||
#define POWERSENSOR_H_
|
||||
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PIDReader.h"
|
||||
#include "../datapool/PoolVariable.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../datapoolglob/PIDReader.h"
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../monitoring/LimitMonitor.h"
|
||||
#include "../parameters/ParameterHelper.h"
|
||||
@ -53,12 +53,12 @@ private:
|
||||
MessageQueueIF* commandQueue;
|
||||
ParameterHelper parameterHelper;
|
||||
HealthHelper healthHelper;
|
||||
DataSet set;
|
||||
GlobDataSet set;
|
||||
//Variables in
|
||||
PIDReader<float> current;
|
||||
PIDReader<float> voltage;
|
||||
//Variables out
|
||||
db_float_t power;
|
||||
gp_float_t power;
|
||||
|
||||
static const uint8_t MODULE_ID_CURRENT = 1;
|
||||
static const uint8_t MODULE_ID_VOLTAGE = 2;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
CoreComponent::CoreComponent(object_id_t reportingObjectId, uint8_t domainId,
|
||||
uint32_t temperaturePoolId, uint32_t targetStatePoolId,
|
||||
uint32_t currentStatePoolId, uint32_t requestPoolId, DataSet* dataSet,
|
||||
uint32_t currentStatePoolId, uint32_t requestPoolId, GlobDataSet* dataSet,
|
||||
AbstractTemperatureSensor* sensor,
|
||||
AbstractTemperatureSensor* firstRedundantSensor,
|
||||
AbstractTemperatureSensor* secondRedundantSensor,
|
||||
@ -18,14 +18,14 @@ CoreComponent::CoreComponent(object_id_t reportingObjectId, uint8_t domainId,
|
||||
AbstractTemperatureSensor::ZERO_KELVIN_C), parameters(
|
||||
parameters), temperatureMonitor(reportingObjectId,
|
||||
domainId + 1,
|
||||
DataPool::poolIdAndPositionToPid(temperaturePoolId, 0),
|
||||
GlobalDataPool::poolIdAndPositionToPid(temperaturePoolId, 0),
|
||||
COMPONENT_TEMP_CONFIRMATION), domainId(domainId) {
|
||||
if (thermalModule != NULL) {
|
||||
thermalModule->registerComponent(this, priority);
|
||||
}
|
||||
//Set thermal state once, then leave to operator.
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> writableTargetState(targetStatePoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t writableTargetState(targetStatePoolId, &mySet,
|
||||
PoolVariableIF::VAR_WRITE);
|
||||
writableTargetState = initialTargetState;
|
||||
mySet.commit(PoolVariableIF::VALID);
|
||||
@ -70,8 +70,8 @@ float CoreComponent::getLowerOpLimit() {
|
||||
}
|
||||
|
||||
ReturnValue_t CoreComponent::setTargetState(int8_t newState) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> writableTargetState(targetState.getDataPoolId(),
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t writableTargetState(targetState.getDataPoolId(),
|
||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if ((writableTargetState == STATE_REQUEST_OPERATIONAL)
|
||||
|
@ -1,13 +1,14 @@
|
||||
#ifndef MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
#define MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PoolVariable.h"
|
||||
#include "ThermalComponentIF.h"
|
||||
#include "AbstractTemperatureSensor.h"
|
||||
#include "ThermalModule.h"
|
||||
#include "ThermalMonitor.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
#include "../thermal/AbstractTemperatureSensor.h"
|
||||
#include "../thermal/ThermalModule.h"
|
||||
#include "../thermal/ThermalMonitor.h"
|
||||
|
||||
// TODO: Documentaiton, how to use this? only use Thermal Component, which inherits core component?
|
||||
class CoreComponent: public ThermalComponentIF {
|
||||
public:
|
||||
struct Parameters {
|
||||
@ -22,7 +23,7 @@ public:
|
||||
|
||||
CoreComponent(object_id_t reportingObjectId, uint8_t domainId, uint32_t temperaturePoolId,
|
||||
uint32_t targetStatePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t requestPoolId, DataSet *dataSet,
|
||||
uint32_t requestPoolId, GlobDataSet *dataSet,
|
||||
AbstractTemperatureSensor *sensor,
|
||||
AbstractTemperatureSensor *firstRedundantSensor,
|
||||
AbstractTemperatureSensor *secondRedundantSensor,
|
||||
@ -57,10 +58,10 @@ protected:
|
||||
AbstractTemperatureSensor *secondRedundantSensor;
|
||||
ThermalModuleIF *thermalModule;
|
||||
|
||||
db_float_t temperature;
|
||||
db_int8_t targetState;
|
||||
db_int8_t currentState;
|
||||
db_uint8_t heaterRequest;
|
||||
gp_float_t temperature;
|
||||
gp_int8_t targetState;
|
||||
gp_int8_t currentState;
|
||||
gp_uint8_t heaterRequest;
|
||||
|
||||
bool isHeating;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
ThermalComponent::ThermalComponent(object_id_t reportingObjectId,
|
||||
uint8_t domainId, uint32_t temperaturePoolId,
|
||||
uint32_t targetStatePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t requestPoolId, DataSet* dataSet,
|
||||
uint32_t requestPoolId, GlobDataSet* dataSet,
|
||||
AbstractTemperatureSensor* sensor,
|
||||
AbstractTemperatureSensor* firstRedundantSensor,
|
||||
AbstractTemperatureSensor* secondRedundantSensor,
|
||||
@ -12,20 +12,18 @@ ThermalComponent::ThermalComponent(object_id_t reportingObjectId,
|
||||
CoreComponent(reportingObjectId, domainId, temperaturePoolId,
|
||||
targetStatePoolId, currentStatePoolId, requestPoolId, dataSet,
|
||||
sensor, firstRedundantSensor, secondRedundantSensor,
|
||||
thermalModule,
|
||||
{ parameters.lowerOpLimit, parameters.upperOpLimit,
|
||||
parameters.heaterOn, parameters.hysteresis,
|
||||
parameters.heaterSwitchoff }, priority,
|
||||
ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL), nopParameters(
|
||||
{ parameters.lowerNopLimit, parameters.upperNopLimit }) {
|
||||
thermalModule,{ parameters.lowerOpLimit, parameters.upperOpLimit,
|
||||
parameters.heaterOn, parameters.hysteresis, parameters.heaterSwitchoff },
|
||||
priority, ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL),
|
||||
nopParameters({ parameters.lowerNopLimit, parameters.upperNopLimit }) {
|
||||
}
|
||||
|
||||
ThermalComponent::~ThermalComponent() {
|
||||
}
|
||||
|
||||
ReturnValue_t ThermalComponent::setTargetState(int8_t newState) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> writableTargetState(targetState.getDataPoolId(),
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t writableTargetState(targetState.getDataPoolId(),
|
||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if ((writableTargetState == STATE_REQUEST_OPERATIONAL)
|
||||
@ -42,7 +40,7 @@ ReturnValue_t ThermalComponent::setTargetState(int8_t newState) {
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, uint32_t size) {
|
||||
ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, size_t size) {
|
||||
if (size != 4 * sizeof(parameters.lowerOpLimit)) {
|
||||
return MonitoringIF::INVALID_SIZE;
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include "CoreComponent.h"
|
||||
|
||||
/**
|
||||
* What is it. How to use
|
||||
*/
|
||||
class ThermalComponent: public CoreComponent {
|
||||
public:
|
||||
struct Parameters {
|
||||
@ -14,13 +17,34 @@ public:
|
||||
float hysteresis;
|
||||
float heaterSwitchoff;
|
||||
};
|
||||
|
||||
/**
|
||||
* Non-Operational Temperatures
|
||||
*/
|
||||
struct NopParameters {
|
||||
float lowerNopLimit;
|
||||
float upperNopLimit;
|
||||
};
|
||||
|
||||
/**
|
||||
* How to use.
|
||||
* @param reportingObjectId
|
||||
* @param domainId
|
||||
* @param temperaturePoolId
|
||||
* @param targetStatePoolId
|
||||
* @param currentStatePoolId
|
||||
* @param requestPoolId
|
||||
* @param dataSet
|
||||
* @param sensor
|
||||
* @param firstRedundantSensor
|
||||
* @param secondRedundantSensor
|
||||
* @param thermalModule
|
||||
* @param parameters
|
||||
* @param priority
|
||||
*/
|
||||
ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, uint32_t temperaturePoolId,
|
||||
uint32_t targetStatePoolId, uint32_t currentStatePoolId, uint32_t requestPoolId,
|
||||
DataSet *dataSet, AbstractTemperatureSensor *sensor,
|
||||
GlobDataSet *dataSet, AbstractTemperatureSensor *sensor,
|
||||
AbstractTemperatureSensor *firstRedundantSensor,
|
||||
AbstractTemperatureSensor *secondRedundantSensor,
|
||||
ThermalModuleIF *thermalModule, Parameters parameters,
|
||||
@ -29,7 +53,7 @@ public:
|
||||
|
||||
ReturnValue_t setTargetState(int8_t newState);
|
||||
|
||||
virtual ReturnValue_t setLimits( const uint8_t* data, uint32_t size);
|
||||
virtual ReturnValue_t setLimits( const uint8_t* data, size_t size);
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId,
|
||||
uint32_t currentStatePoolId, uint32_t targetStatePoolId,
|
||||
DataSet *dataSet, Parameters parameters,
|
||||
GlobDataSet *dataSet, Parameters parameters,
|
||||
RedundantHeater::Parameters heaterParameters) :
|
||||
oldStrategy(ACTIVE_SINGLE), survivalTargetTemp(0), targetTemp(0), heating(
|
||||
false), parameters(parameters), moduleTemperature(
|
||||
@ -16,7 +16,7 @@ ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId,
|
||||
heater = new RedundantHeater(heaterParameters);
|
||||
}
|
||||
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId, DataSet* dataSet) :
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId, GlobDataSet* dataSet) :
|
||||
oldStrategy(ACTIVE_SINGLE), survivalTargetTemp(0), targetTemp(0), heating(
|
||||
false), parameters( { 0, 0 }), moduleTemperature(
|
||||
moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), heater(
|
||||
@ -250,8 +250,8 @@ bool ThermalModule::calculateModuleHeaterRequestAndSetModuleStatus(
|
||||
}
|
||||
|
||||
void ThermalModule::setHeating(bool on) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> writableTargetState(targetState.getDataPoolId(),
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t writableTargetState(targetState.getDataPoolId(),
|
||||
&mySet, PoolVariableIF::VAR_WRITE);
|
||||
if (on) {
|
||||
writableTargetState = STATE_REQUEST_HEATING;
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef THERMALMODULE_H_
|
||||
#define THERMALMODULE_H_
|
||||
|
||||
#include "../datapool/DataSet.h"
|
||||
#include "../datapool/PoolVariable.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "ThermalModuleIF.h"
|
||||
@ -11,6 +11,9 @@
|
||||
#include "RedundantHeater.h"
|
||||
class PowerSwitchIF;
|
||||
|
||||
/**
|
||||
* @brief Allows creation of different thermal control domains within a system.
|
||||
*/
|
||||
class ThermalModule: public ThermalModuleIF {
|
||||
friend class ThermalController;
|
||||
public:
|
||||
@ -20,10 +23,10 @@ public:
|
||||
};
|
||||
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t targetStatePoolId, DataSet *dataSet, Parameters parameters,
|
||||
uint32_t targetStatePoolId, GlobDataSet *dataSet, Parameters parameters,
|
||||
RedundantHeater::Parameters heaterParameters);
|
||||
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, DataSet *dataSet);
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, GlobDataSet *dataSet);
|
||||
|
||||
virtual ~ThermalModule();
|
||||
|
||||
@ -67,12 +70,12 @@ protected:
|
||||
|
||||
Parameters parameters;
|
||||
|
||||
db_float_t moduleTemperature;
|
||||
gp_float_t moduleTemperature;
|
||||
|
||||
RedundantHeater *heater;
|
||||
|
||||
db_int8_t currentState;
|
||||
db_int8_t targetState;
|
||||
gp_int8_t currentState;
|
||||
gp_int8_t targetState;
|
||||
|
||||
std::list<AbstractTemperatureSensor *> sensors;
|
||||
std::list<ComponentData> components;
|
||||
|
Loading…
Reference in New Issue
Block a user