init commit
This commit is contained in:
parent
b3d08cd40b
commit
e9b86e51df
@ -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
|
||||