merging renaming into main branch
This commit is contained in:
parent
b673e13892
commit
cbfa21d45a
@ -1,9 +1,9 @@
|
||||
#ifndef CONTROLLERSET_H_
|
||||
#define CONTROLLERSET_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
|
||||
class ControllerSet :public DataSet {
|
||||
class ControllerSet :public GlobDataSet {
|
||||
public:
|
||||
ControllerSet();
|
||||
virtual ~ControllerSet();
|
||||
|
@ -1,132 +0,0 @@
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/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 max_size ) {
|
||||
// std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
||||
// if ( it != this->data_pool.end() ) {
|
||||
// if ( it->second->getByteSize() <= max_size ) {
|
||||
// *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::NO_TIMEOUT);
|
||||
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<bool>* DataPool::getData<bool>( uint32_t data_pool_id, uint8_t size );
|
||||
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,136 +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 <framework/datapool/PoolEntry.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
#include <framework/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 to 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 <framework/datapool/DataSet.h>
|
||||
#include <framework/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,
|
||||
const size_t max_size, bool bigEndian) const {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->serialize(buffer, size, max_size,
|
||||
bigEndian);
|
||||
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,
|
||||
bool bigEndian) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||
bigEndian);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
@ -1,168 +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 <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/datapool/PoolVarList.h>
|
||||
#include <framework/datapool/PoolVector.h>
|
||||
#include <framework/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 {
|
||||
|
||||
public:
|
||||
//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.
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
* Serialize all registered pool variables into the provided buffer
|
||||
* @param buffer
|
||||
* @param size Is incremented by serialized size
|
||||
* @param max_size
|
||||
* @param bigEndian
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const;
|
||||
|
||||
virtual size_t getSerializedSize() const;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian);
|
||||
|
||||
private:
|
||||
/**
|
||||
* \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();
|
||||
|
||||
};
|
||||
|
||||
#endif /* DATASET_H_ */
|
@ -1,39 +1,36 @@
|
||||
/**
|
||||
* \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_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.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:
|
||||
/**
|
||||
* \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 ReturnValue_t lockDataPool() = 0;
|
||||
virtual ReturnValue_t unlockDataPool() = 0;
|
||||
};
|
||||
|
||||
#endif /* DATASETIF_H_ */
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <framework/datapool/HkSwitchHelper.h>
|
||||
//#include <mission/tmtcservices/HKService_03.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
|
||||
HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) :
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef PIDREADER_H_
|
||||
#define PIDREADER_H_
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
@ -16,9 +16,9 @@ protected:
|
||||
uint32_t parameterId;
|
||||
uint8_t valid;
|
||||
ReturnValue_t read() {
|
||||
uint8_t arrayIndex = DataPool::PIDToArrayIndex(parameterId);
|
||||
uint8_t arrayIndex = GlobalDataPool::PIDToArrayIndex(parameterId);
|
||||
PoolEntry<T>* read_out = ::dataPool.getData<T>(
|
||||
DataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||
GlobalDataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||
if (read_out != NULL) {
|
||||
valid = read_out->valid;
|
||||
value = read_out->address[arrayIndex];
|
||||
@ -88,7 +88,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;
|
||||
|
@ -71,7 +71,6 @@ Type PoolEntry<T>::getType() {
|
||||
return PodTypeConversion<T>::type;
|
||||
}
|
||||
|
||||
template class PoolEntry<bool>;
|
||||
template class PoolEntry<uint8_t>;
|
||||
template class PoolEntry<uint16_t>;
|
||||
template class PoolEntry<uint32_t>;
|
||||
|
@ -6,34 +6,46 @@
|
||||
#include <stddef.h>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
/**
|
||||
* \brief This is a small helper class that defines a single data pool entry.
|
||||
*
|
||||
* \details The helper is used to store all information together with the data as a single data pool entry.
|
||||
* The content's type is defined by the template argument.
|
||||
* It is prepared for use with plain old data types,
|
||||
* but may be extended to complex types if necessary.
|
||||
* It can be initialized with a certain value, size and validity flag.
|
||||
* It holds a pointer to the real data and offers methods to access this data and to acquire
|
||||
* additional information (such as validity and array/byte size).
|
||||
* It is NOT intended to be used outside the DataPool class.
|
||||
*
|
||||
* \ingroup data_pool
|
||||
* @brief This is a small helper class that defines a single data pool entry.
|
||||
* @details
|
||||
* The helper is used to store all information together with the data as a
|
||||
* single data pool entry.The content's type is defined by the template argument.
|
||||
* It is prepared for use with plain old data types, but may be extended to
|
||||
* complex types if necessary. It can be initialized with a certain value,
|
||||
* size and validity flag. It holds a pointer to the real data and offers
|
||||
* methods to access this data and to acquire additional information
|
||||
* (such as validity and array/byte size). It is NOT intended to be used
|
||||
* outside the DataPool class.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*
|
||||
*/
|
||||
template <typename T>
|
||||
class PoolEntry : public PoolEntryIF {
|
||||
public:
|
||||
static_assert(not std::is_same<T, bool>::value,
|
||||
"Do not use boolean for the PoolEntry type, use uint8_t instead!"
|
||||
"Warum? Darum :-)");
|
||||
/**
|
||||
* \brief In the classe's constructor, space is allocated on the heap and
|
||||
* @brief In the classe's constructor, space is allocated on the heap and
|
||||
* potential init values are copied to that space.
|
||||
* \param initValue A pointer to the single value or array that holds the init value.
|
||||
* With the default value (NULL), the entry is initalized with all 0.
|
||||
* \param set_length Defines the array length of this entry.
|
||||
* \param set_valid Sets the initialization flag. It is invalid (0) by default.
|
||||
* @param initValue Initializer list with values to initialize with
|
||||
* @param set_length Defines the array length of this entry.
|
||||
* @param set_valid Sets the initialization flag. It is invalid (0) by default.
|
||||
*/
|
||||
PoolEntry( std::initializer_list<T> initValue = {}, uint8_t set_length = 1, uint8_t set_valid = 0 );
|
||||
/**
|
||||
* @brief In the classe's constructor, space is allocated on the heap and
|
||||
* potential init values are copied to that space.
|
||||
* @param initValue A pointer to the single value or array that holds the init value.
|
||||
* With the default value (NULL), the entry is initalized with all 0.
|
||||
* @param set_length Defines the array length of this entry.
|
||||
* @param set_valid Sets the initialization flag. It is invalid (0) by default.
|
||||
*/
|
||||
PoolEntry( T* initValue = NULL, uint8_t set_length = 1, uint8_t set_valid = 0 );
|
||||
|
||||
/**
|
||||
* \brief The allocated memory for the variable is freed in the destructor.
|
||||
* \details As the data pool is global, this dtor is only called on program exit.
|
||||
|
@ -1,66 +1,63 @@
|
||||
/**
|
||||
* \file PoolEntryIF.h
|
||||
*
|
||||
* \brief This file holds the class that defines the Interface for Pool Entry elements.
|
||||
*
|
||||
* \date 10/18/2012
|
||||
*
|
||||
* \author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef POOLENTRYIF_H_
|
||||
#define POOLENTRYIF_H_
|
||||
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* \brief This interface defines the access possibilities to a single data pool entry.
|
||||
*
|
||||
* \details The interface provides methods to determine the size and the validity information of a value.
|
||||
* It also defines a method to receive a pointer to the raw data content.
|
||||
* It is mainly used by DataPool itself, but also as a return pointer.
|
||||
*
|
||||
* \ingroup data_pool
|
||||
*
|
||||
* @brief This interface defines the access possibilities to a
|
||||
* single data pool entry.
|
||||
* @details
|
||||
* The interface provides methods to determine the size and the validity
|
||||
* information of a value. It also defines a method to receive a pointer to
|
||||
* the raw data content. It is mainly used by DataPool itself, but also as a
|
||||
* return pointer.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class PoolEntryIF {
|
||||
public:
|
||||
/**
|
||||
* \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 ~PoolEntryIF() {
|
||||
}
|
||||
virtual ~PoolEntryIF() {}
|
||||
|
||||
/**
|
||||
* \brief getSize returns the array size of the entry. A single variable parameter has size 1.
|
||||
* @brief getSize returns the array size of the entry.
|
||||
* A single variable parameter has size 1.
|
||||
*/
|
||||
virtual uint8_t getSize() = 0;
|
||||
|
||||
/**
|
||||
* \brief This operation returns the size in bytes, which is calculated by
|
||||
* @brief This operation returns the size in bytes, which is calculated by
|
||||
* sizeof(type) * array_size.
|
||||
*/
|
||||
virtual uint16_t getByteSize() = 0;
|
||||
|
||||
/**
|
||||
* \brief This operation returns a the address pointer casted to void*.
|
||||
* @brief This operation returns a the address pointer casted to void*.
|
||||
*/
|
||||
virtual void* getRawData() = 0;
|
||||
|
||||
/**
|
||||
* \brief This method allows to set the valid information of the pool entry.
|
||||
* @brief This method allows to set the valid information of the pool entry.
|
||||
*/
|
||||
virtual void setValid(uint8_t isValid) = 0;
|
||||
|
||||
/**
|
||||
* \brief This method allows to set the valid information of the pool entry.
|
||||
* @brief This method allows to set the valid information of the pool entry.
|
||||
*/
|
||||
virtual uint8_t getValid() = 0;
|
||||
|
||||
/**
|
||||
* \brief This is a debug method that prints all values and the valid information to the screen.
|
||||
* It prints all array entries in a row.
|
||||
* @brief This is a debug method that prints all values and the valid
|
||||
* information to the screen. It prints all array entries in a row.
|
||||
*/
|
||||
virtual void print() = 0;
|
||||
|
||||
/**
|
||||
* Returns the type of the entry.
|
||||
* @brief Returns the type of the entry.
|
||||
*/
|
||||
virtual Type getType() = 0;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/PoolEntryIF.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/osal/Endiness.h>
|
||||
|
||||
@ -14,63 +14,41 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||
}
|
||||
}
|
||||
|
||||
PoolRawAccess::~PoolRawAccess() {}
|
||||
PoolRawAccess::~PoolRawAccess() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::read() {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
PoolEntryIF* read_out = ::dataPool.getRawData(dataPoolId);
|
||||
if (read_out != NULL) {
|
||||
result = handleReadOut(read_out);
|
||||
if(result == RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
result = READ_ENTRY_NON_EXISTENT;
|
||||
}
|
||||
handleReadError(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* read_out) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
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 RETURN_OK;
|
||||
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 {
|
||||
result = READ_TYPE_TOO_LARGE;
|
||||
//Error index requested too large
|
||||
}
|
||||
} else {
|
||||
//debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl;
|
||||
result = READ_INDEX_TOO_LARGE;
|
||||
//Error entry does not exist.
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
<< std::dec << " failed." << std::endl;
|
||||
valid = INVALID;
|
||||
typeSize = 0;
|
||||
sizeTillEnd = 0;
|
||||
memset(value, 0, sizeof(value));
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::commit() {
|
||||
@ -111,32 +89,6 @@ ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const {
|
||||
if (typeSize + *size <= max_size) {
|
||||
if (bigEndian) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (uint8_t count = 0; count < typeSize; count++) {
|
||||
(*buffer)[count] = value[typeSize - count - 1];
|
||||
}
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(*buffer, value, typeSize);
|
||||
#endif
|
||||
} else {
|
||||
memcpy(*buffer, value, typeSize);
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Type PoolRawAccess::getType() {
|
||||
return type;
|
||||
}
|
||||
@ -193,6 +145,29 @@ uint16_t PoolRawAccess::getSizeTillEnd() const {
|
||||
return sizeTillEnd;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const {
|
||||
if (typeSize + *size <= max_size) {
|
||||
if (bigEndian) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (uint8_t count = 0; count < typeSize; count++) {
|
||||
(*buffer)[count] = value[typeSize - count - 1];
|
||||
}
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(*buffer, value, typeSize);
|
||||
#endif
|
||||
} else {
|
||||
memcpy(*buffer, value, typeSize);
|
||||
}
|
||||
*size += typeSize;
|
||||
(*buffer) += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
size_t PoolRawAccess::getSerializedSize() const {
|
||||
return typeSize;
|
||||
@ -200,9 +175,8 @@ size_t PoolRawAccess::getSerializedSize() const {
|
||||
|
||||
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) {
|
||||
// TODO: Needs to be tested!!!
|
||||
if (*size >= typeSize) {
|
||||
*size -= typeSize;
|
||||
|
||||
if (bigEndian) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
@ -213,14 +187,12 @@ ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(value, *buffer, typeSize);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
memcpy(value, *buffer, typeSize);
|
||||
}
|
||||
*buffer += typeSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
@ -6,54 +6,83 @@
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
|
||||
/**
|
||||
* @brief This class allows accessing Data Pool variables as raw bytes.
|
||||
* @details
|
||||
* 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. 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
|
||||
* provide a type information.
|
||||
* \ingroup data_pool
|
||||
*/
|
||||
class PoolRawAccess: public PoolVariableIF, HasReturnvaluesIF {
|
||||
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.
|
||||
*/
|
||||
uint8_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
uint8_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
uint16_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);
|
||||
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];
|
||||
|
||||
/**
|
||||
* 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);
|
||||
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 Return pointer to the buffer containing the raw data
|
||||
* Size and number of data can be retrieved by other means.
|
||||
* \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();
|
||||
/**
|
||||
@ -71,19 +100,6 @@ public:
|
||||
*/
|
||||
ReturnValue_t getEntryEndianSafe(uint8_t* buffer, uint32_t* size,
|
||||
uint32_t max_size);
|
||||
|
||||
/**
|
||||
* @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,
|
||||
const size_t max_size, bool bigEndian) const;
|
||||
|
||||
/**
|
||||
* With this method, the content can be set from a big endian buffer safely.
|
||||
* @param buffer Pointer to the data to set
|
||||
@ -125,73 +141,13 @@ public:
|
||||
*/
|
||||
uint16_t getSizeTillEnd() const;
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const;
|
||||
|
||||
size_t getSerializedSize() const;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian);
|
||||
|
||||
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 !
|
||||
* If reading from the data pool without information about the type is desired,
|
||||
* initialize the raw pool access by supplying a data set and using the data set
|
||||
* read function, which calls this read function.
|
||||
* @return -@c RETURN_OK Read successfull
|
||||
* -@c READ_TYPE_TOO_LARGE
|
||||
* -@c READ_INDEX_TOO_LARGE
|
||||
* -@c READ_ENTRY_NON_EXISTENT
|
||||
*/
|
||||
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();
|
||||
|
||||
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.
|
||||
*/
|
||||
uint8_t typeSize;
|
||||
/**
|
||||
* The size of the DP array (single values return 1)
|
||||
*/
|
||||
uint8_t arraySize;
|
||||
/**
|
||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||
*/
|
||||
uint16_t sizeTillEnd;
|
||||
/**
|
||||
* \brief The information whether the class is read-write or read-only is stored here.
|
||||
*/
|
||||
ReadWriteMode_t readWriteMode;
|
||||
};
|
||||
|
||||
#endif /* POOLRAWACCESS_H_ */
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
|
||||
PoolRawAccessHelper::PoolRawAccessHelper(uint32_t * poolIdBuffer_,
|
||||
uint8_t numberOfParameters_):
|
||||
@ -97,7 +97,7 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(
|
||||
// << std::hex << currentPoolId << std::endl;
|
||||
while(not poolEntrySerialized) {
|
||||
|
||||
if(counter > DataSet::DATA_SET_MAX_SIZE) {
|
||||
if(counter > GlobDataSet::DATA_SET_MAX_SIZE) {
|
||||
sif::error << "PoolRawAccessHelper: Config error, "
|
||||
"max. number of possible data set variables exceeded"
|
||||
<< std::endl;
|
||||
@ -105,7 +105,7 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(
|
||||
}
|
||||
counter ++;
|
||||
|
||||
DataSet currentDataSet = DataSet();
|
||||
GlobDataSet currentDataSet;
|
||||
//debug << "Current array position: " << (int)arrayPosition << std::endl;
|
||||
PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,
|
||||
¤tDataSet,PoolVariableIF::VAR_READ);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#define FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
|
||||
/**
|
||||
* @brief This helper function simplifies accessing data pool entries
|
||||
|
@ -1,12 +1,12 @@
|
||||
#ifndef POOLVARLIST_H_
|
||||
#define POOLVARLIST_H_
|
||||
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/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 ) {
|
||||
//I really should have a look at the new init list c++ syntax.
|
||||
@ -20,7 +20,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
PoolVariable<T> &operator [](int i) { return variables[i]; }
|
||||
GlobPoolVar<T> &operator [](int i) { return variables[i]; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,71 +1,70 @@
|
||||
/*
|
||||
* \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_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/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;
|
||||
friend class GlobDataSet;
|
||||
friend class LocalDataSet;
|
||||
protected:
|
||||
/**
|
||||
* \brief The commit call shall write back a newly calculated local value to the data pool.
|
||||
* @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.
|
||||
* @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;
|
||||
public:
|
||||
static const uint8_t VALID = 1;
|
||||
static const uint8_t INVALID = 0;
|
||||
static const uint32_t NO_PARAMETER = 0;
|
||||
static constexpr bool VALID = 1;
|
||||
static constexpr bool INVALID = 0;
|
||||
static constexpr uint32_t NO_PARAMETER = 0;
|
||||
|
||||
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.
|
||||
*/
|
||||
// why not just use a boolean here?
|
||||
virtual void setValid(uint8_t validity) = 0;
|
||||
|
||||
};
|
||||
|
||||
using pool_rwm_t = PoolVariableIF::ReadWriteMode_t;
|
||||
|
||||
#endif /* POOLVARIABLEIF_H_ */
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include <framework/datapool/DataPool.h>
|
||||
#include <framework/datapool/DataPoolAdmin.h>
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/DataPoolAdmin.h>
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
#include <framework/parameters/ParameterMessage.h>
|
||||
@ -26,7 +24,7 @@ MessageQueueId_t DataPoolAdmin::getCommandQueue() const {
|
||||
}
|
||||
|
||||
ReturnValue_t DataPoolAdmin::executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size) {
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size) {
|
||||
if (actionId != SET_VALIDITY) {
|
||||
return INVALID_ACTION_ID;
|
||||
}
|
||||
@ -42,7 +40,7 @@ ReturnValue_t DataPoolAdmin::executeAction(ActionId_t actionId,
|
||||
|
||||
uint32_t poolId = ::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) {
|
||||
@ -94,7 +92,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||
const uint8_t* data, uint32_t size, uint8_t** dataPointer) {
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
||||
DataSet testSet;
|
||||
GlobDataSet testSet;
|
||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = testSet.read();
|
||||
@ -113,7 +111,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();
|
||||
@ -133,7 +131,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, uint32_t size,
|
||||
uint8_t** dataPointer, uint8_t* copyHere) {
|
||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
||||
DataSet testSet;
|
||||
GlobDataSet testSet;
|
||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
ReturnValue_t status = testSet.read();
|
||||
@ -146,7 +144,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, uint32_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,16 @@
|
||||
#ifndef DATAPOOLADMIN_H_
|
||||
#define DATAPOOLADMIN_H_
|
||||
|
||||
#include <framework/memory/MemoryHelper.h>
|
||||
#include <framework/action/HasActionsIF.h>
|
||||
#include <framework/action/SimpleActionHelper.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/parameters/ReceivesParameterMessagesIF.h>
|
||||
#include <framework/datapool/DataPoolParameterWrapper.h>
|
||||
#include <framework/action/HasActionsIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/parameters/ReceivesParameterMessagesIF.h>
|
||||
|
||||
#include <framework/memory/MemoryHelper.h>
|
||||
#include <framework/action/SimpleActionHelper.h>
|
||||
#include <framework/datapoolglob/DataPoolParameterWrapper.h>
|
||||
|
||||
class DataPoolAdmin: public HasActionsIF,
|
||||
public ExecutableObjectIF,
|
||||
@ -33,8 +34,8 @@ public:
|
||||
ReturnValue_t handleMemoryDump(uint32_t address, uint32_t size,
|
||||
uint8_t** dataPointer, uint8_t* copyHere);
|
||||
|
||||
virtual ReturnValue_t executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size);
|
||||
ReturnValue_t executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size);
|
||||
|
||||
//not implemented as ParameterHelper is no used
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
@ -1,10 +1,8 @@
|
||||
#include "DataPoolParameterWrapper.h"
|
||||
|
||||
//for returncodes
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/DataPoolParameterWrapper.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/parameters/HasParametersIF.h>
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/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,max_size,bigEndian);
|
||||
@ -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();
|
132
datapoolglob/GlobalDataPool.cpp
Normal file
132
datapoolglob/GlobalDataPool.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/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::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 GlobalDataPool::lockDataPool() {
|
||||
ReturnValue_t status = mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
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);
|
146
datapoolglob/GlobalDataPool.h
Normal file
146
datapoolglob/GlobalDataPool.h
Normal file
@ -0,0 +1,146 @@
|
||||
#ifndef GLOBALDATAPOOL_H_
|
||||
#define GLOBALDATAPOOL_H_
|
||||
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
#include <framework/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();
|
||||
/**
|
||||
* @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 GlobalDataPool dataPool;
|
||||
#endif /* DATAPOOL_H_ */
|
166
datapoolglob/GlobalDataSet.cpp
Normal file
166
datapoolglob/GlobalDataSet.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
GlobDataSet::GlobDataSet() :
|
||||
fill_count(0), state(DATA_SET_UNINITIALISED) {
|
||||
for (unsigned count = 0; count < DATA_SET_MAX_SIZE; count++) {
|
||||
registeredVariables[count] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
GlobDataSet::~GlobDataSet() {
|
||||
//Don't do anything with your variables, they are dead already!
|
||||
// (Destructor is already called)
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::registerVariable(PoolVariableIF* variable) {
|
||||
if (state != DATA_SET_UNINITIALISED) {
|
||||
sif::error << "DataSet::registerVariable: Call made in wrong position." << std::endl;
|
||||
return DATA_SET_UNINITIALISED;
|
||||
}
|
||||
if (variable == nullptr) {
|
||||
sif::error << "DataSet::registerVariable: Pool variable is nullptr." << std::endl;
|
||||
return POOL_VAR_NULL;
|
||||
}
|
||||
if (fill_count >= DATA_SET_MAX_SIZE) {
|
||||
sif::error << "DataSet::registerVariable: DataSet is full." << std::endl;
|
||||
return DATA_SET_FULL;
|
||||
}
|
||||
registeredVariables[fill_count] = variable;
|
||||
fill_count++;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::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;
|
||||
unlockDataPool();
|
||||
} else {
|
||||
sif::error << "DataSet::read(): Call made in wrong position." << std::endl;
|
||||
result = SET_WAS_ALREADY_READ;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::commit(bool valid) {
|
||||
setEntriesValid(valid);
|
||||
setSetValid(valid);
|
||||
return commit();
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::commit() {
|
||||
if (state == DATA_SET_WAS_READ) {
|
||||
handleAlreadyReadDatasetCommit();
|
||||
return RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return handleUnreadDatasetCommit();
|
||||
}
|
||||
}
|
||||
|
||||
void GlobDataSet::handleAlreadyReadDatasetCommit() {
|
||||
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;
|
||||
unlockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::handleUnreadDatasetCommit() {
|
||||
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;
|
||||
unlockDataPool();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::unlockDataPool() {
|
||||
return ::dataPool.freeDataPoolLock();
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::lockDataPool() {
|
||||
return ::dataPool.lockDataPool();
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->serialize(buffer, size, max_size,
|
||||
bigEndian);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t GlobDataSet::getSerializedSize() const {
|
||||
uint32_t size = 0;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
size += registeredVariables[count]->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void GlobDataSet::setEntriesValid(bool valid) {
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
if (registeredVariables[count]->getReadWriteMode()
|
||||
!= PoolVariableIF::VAR_READ) {
|
||||
registeredVariables[count]->setValid(valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlobDataSet::setSetValid(bool valid) {
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobDataSet::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (uint16_t count = 0; count < fill_count; count++) {
|
||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||
bigEndian);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
185
datapoolglob/GlobalDataSet.h
Normal file
185
datapoolglob/GlobalDataSet.h
Normal file
@ -0,0 +1,185 @@
|
||||
#ifndef DATASET_H_
|
||||
#define DATASET_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolRawAccess.h>
|
||||
#include <framework/datapool/PoolVarList.h>
|
||||
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
/**
|
||||
* @brief The DataSet class manages a set of locally checked out variables
|
||||
* for the global data pool.
|
||||
*
|
||||
* @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.
|
||||
* @author Bastian Baetz
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
class GlobDataSet: public DataSetIF, public HasReturnvaluesIF, public SerializeIF {
|
||||
public:
|
||||
//SHOULDDO we could use a linked list of datapool variables
|
||||
//!< This definition sets the maximum number of variables to
|
||||
//! register in one DataSet.
|
||||
static const uint8_t DATA_SET_MAX_SIZE = 63;
|
||||
|
||||
|
||||
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_UNINITIALIZED = 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 The constructor simply sets the fill_count to zero and sets
|
||||
* the state to "uninitialized".
|
||||
*/
|
||||
GlobDataSet();
|
||||
|
||||
/**
|
||||
* @brief This operation is used to register the local variables in the set.
|
||||
* @details It stores the pool variable pointer in a variable list.
|
||||
*/
|
||||
ReturnValue_t registerVariable(PoolVariableIF* variable) override;
|
||||
|
||||
/**
|
||||
* @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();
|
||||
/**
|
||||
* @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(bool valid);
|
||||
|
||||
/**
|
||||
* Set all entries
|
||||
* @param valid
|
||||
*/
|
||||
void setSetValid(bool valid);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) override;
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief This array represents all pool variables registered in this set.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 underlying data data pool structure
|
||||
* @details
|
||||
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t lockDataPool() override;
|
||||
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate
|
||||
* unlocking the underlying data data pool structure
|
||||
* @details
|
||||
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool() override;
|
||||
|
||||
void handleAlreadyReadDatasetCommit();
|
||||
ReturnValue_t handleUnreadDatasetCommit();
|
||||
};
|
||||
|
||||
#endif /* DATASET_H_ */
|
189
datapoolglob/GlobalPoolVariable.h
Normal file
189
datapoolglob/GlobalPoolVariable.h
Normal file
@ -0,0 +1,189 @@
|
||||
#ifndef POOLVARIABLE_H_
|
||||
#define POOLVARIABLE_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapoolglob/GlobalDataPool.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/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!"
|
||||
"Warum? Darum :-)");
|
||||
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() {}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @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() 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.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t commit() override;
|
||||
|
||||
/**
|
||||
* 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(uint8_t valid);
|
||||
|
||||
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, bool bigEndian) const override {
|
||||
return SerializeAdapter<T>::serialize(&value, buffer, size, max_size,
|
||||
bigEndian);
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return SerializeAdapter<T>::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) {
|
||||
return SerializeAdapter<T>::deSerialize(&value, buffer, size, bigEndian);
|
||||
}
|
||||
};
|
||||
|
||||
#include <framework/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_ */
|
84
datapoolglob/GlobalPoolVariable.tpp
Normal file
84
datapoolglob/GlobalPoolVariable.tpp
Normal file
@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
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 <class T>
|
||||
inline ReturnValue_t GlobPoolVar<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;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline ReturnValue_t GlobPoolVar<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;
|
||||
}
|
||||
}
|
||||
|
||||
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(uint8_t valid) {
|
||||
this->valid = valid;
|
||||
}
|
223
datapoolglob/GlobalPoolVector.h
Normal file
223
datapoolglob/GlobalPoolVector.h
Normal file
@ -0,0 +1,223 @@
|
||||
#ifndef POOLVECTOR_H_
|
||||
#define POOLVECTOR_H_
|
||||
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/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 GlobPoolVector: 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.
|
||||
*/
|
||||
GlobPoolVector(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.
|
||||
*/
|
||||
~GlobPoolVector() {
|
||||
}
|
||||
;
|
||||
/**
|
||||
* \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];
|
||||
}
|
||||
|
||||
GlobPoolVector<T, vector_size> &operator=(
|
||||
GlobPoolVector<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,
|
||||
const size_t max_size, bool bigEndian) const override {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vector_size; i++) {
|
||||
result = SerializeAdapter<T>::serialize(&(value[i]), buffer, size,
|
||||
max_size, bigEndian);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const override {
|
||||
return vector_size * SerializeAdapter<T>::getSerializedSize(value);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) override {
|
||||
uint16_t i;
|
||||
ReturnValue_t result;
|
||||
for (i = 0; i < vector_size; i++) {
|
||||
result = SerializeAdapter<T>::deSerialize(&(value[i]), buffer, size,
|
||||
bigEndian);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* POOLVECTOR_H_ */
|
66
datapoollocal/LocalDataSet.cpp
Normal file
66
datapoollocal/LocalDataSet.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <framework/datapoollocal/LocalDataSet.h>
|
||||
|
||||
LocalDataSet::LocalDataSet():
|
||||
fill_count(0), state(DATA_SET_UNINITIALISED)
|
||||
{
|
||||
for (unsigned count = 0; count < DATA_SET_MAX_SIZE; count++) {
|
||||
registeredVariables[count] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// who has the responsibility to lock the mutex? the local pool variable
|
||||
// has access to the HK manager and could call its mutex lock function.
|
||||
ReturnValue_t LocalDataSet::registerVariable(
|
||||
PoolVariableIF *variable) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
LocalDataSet::~LocalDataSet() {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::read() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::commit(void) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::commit(bool valid) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void LocalDataSet::setSetValid(bool valid) {
|
||||
}
|
||||
|
||||
void LocalDataSet::setEntriesValid(bool valid) {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::serialize(uint8_t **buffer,
|
||||
size_t *size, const size_t max_size, bool bigEndian) const {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
size_t LocalDataSet::getSerializedSize() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::deSerialize(const uint8_t **buffer,
|
||||
size_t *size, bool bigEndian) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::lockDataPool() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::unlockDataPool() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void LocalDataSet::handleAlreadyReadDatasetCommit() {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalDataSet::handleUnreadDatasetCommit() {
|
||||
return RETURN_OK;
|
||||
}
|
187
datapoollocal/LocalDataSet.h
Normal file
187
datapoollocal/LocalDataSet.h
Normal file
@ -0,0 +1,187 @@
|
||||
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
|
||||
#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
|
||||
/**
|
||||
* @brief The LocalDataSet class manages a set of locally checked out variables
|
||||
* for local data pools
|
||||
* @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 local data pools,
|
||||
* to ensure thread-safety.
|
||||
*
|
||||
* 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 LocalDataSet:
|
||||
public DataSetIF,
|
||||
public HasReturnvaluesIF,
|
||||
public SerializeIF {
|
||||
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_UNINITIALIZED = 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 The constructor simply sets the fill_count to zero and sets
|
||||
* the state to "uninitialized".
|
||||
*/
|
||||
LocalDataSet();
|
||||
|
||||
/**
|
||||
* @brief This operation is used to register the local variables in the set.
|
||||
* @details It stores the pool variable pointer in a variable list.
|
||||
*/
|
||||
ReturnValue_t registerVariable(PoolVariableIF* variable) override;
|
||||
|
||||
/**
|
||||
* @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".
|
||||
*/
|
||||
~LocalDataSet();
|
||||
|
||||
/**
|
||||
* @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(bool valid);
|
||||
|
||||
/**
|
||||
* Set all entries
|
||||
* @param valid
|
||||
*/
|
||||
void setSetValid(bool valid);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) override;
|
||||
private:
|
||||
// SHOULDDO we could use a linked list of datapool variables
|
||||
//! This definition sets the maximum number of variables
|
||||
//! to register in one DataSet.
|
||||
static const uint8_t DATA_SET_MAX_SIZE = 63;
|
||||
/**
|
||||
* @brief This array represents all pool variables registered in this set.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 underlying data data pool structure
|
||||
* @details
|
||||
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t lockDataPool() override;
|
||||
|
||||
/**
|
||||
* @brief This is a small helper function to facilitate
|
||||
* unlocking the underlying data data pool structure
|
||||
* @details
|
||||
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||
*/
|
||||
ReturnValue_t unlockDataPool() override;
|
||||
|
||||
void handleAlreadyReadDatasetCommit();
|
||||
ReturnValue_t handleUnreadDatasetCommit();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */
|
103
datapoollocal/LocalPoolVariable.h
Normal file
103
datapoollocal/LocalPoolVariable.h
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
|
||||
#include <framework/housekeeping/HousekeepingManager.h>
|
||||
|
||||
#include <map>
|
||||
/**
|
||||
* @brief This is the access class for non-array local data pool entries.
|
||||
*
|
||||
* @details
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Local Pool Variable class which is used to access the local pools.
|
||||
* @details This class is not stored in the map. Instead, it is used to access
|
||||
* the pool entries by using a pointer to the map storing the pool
|
||||
* entries. It can also be used to organize these pool entries
|
||||
* into data sets.
|
||||
* @tparam T
|
||||
*/
|
||||
template<typename T>
|
||||
class LocalPoolVar: public PoolVariableIF, HasReturnvaluesIF {
|
||||
public:
|
||||
static constexpr lp_id_t INVALID_POOL_ID = 0xFFFFFFFF;
|
||||
|
||||
/**
|
||||
* This constructor is used by the data creators to have pool variable
|
||||
* instances which can also be stored in datasets.
|
||||
* @param set_id
|
||||
* @param setReadWriteMode
|
||||
* @param localPoolMap
|
||||
* @param dataSet
|
||||
*/
|
||||
LocalPoolVar(lp_id_t poolId, HasHkPoolParametersIF* hkOwner,
|
||||
pool_rwm_t setReadWriteMode, DataSetIF* dataSet = nullptr);
|
||||
|
||||
/**
|
||||
* This constructor is used by data users like controllers to have
|
||||
* access to the local pool variables of data creators by supplying
|
||||
* the respective creator object ID.
|
||||
* @param poolId
|
||||
* @param poolOwner
|
||||
* @param setReadWriteMode
|
||||
* @param dataSet
|
||||
*/
|
||||
LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
|
||||
pool_rwm_t setReadWriteMode, DataSetIF* dataSet = nullptr);
|
||||
|
||||
virtual~ LocalPoolVar() {};
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
ReturnValue_t commit() override;
|
||||
ReturnValue_t read() override;
|
||||
pool_rwm_t getReadWriteMode() const override;
|
||||
uint32_t getDataPoolId() const override;
|
||||
bool isValid() const override;
|
||||
void setValid(uint8_t validity) override;
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) override;
|
||||
private:
|
||||
lp_id_t localPoolId = INVALID_POOL_ID;
|
||||
pool_rwm_t readWriteMode = pool_rwm_t::VAR_READ_WRITE;
|
||||
bool valid = false;
|
||||
|
||||
bool objectValid = true;
|
||||
//! Pointer to the class which manages the HK pool.
|
||||
HousekeepingManager* hkManager;
|
||||
};
|
||||
|
||||
#include <framework/datapoollocal/LocalPoolVariable.tpp>
|
||||
template<class T>
|
||||
using lp_variable = LocalPoolVar<T>;
|
||||
|
||||
using lp_bool_t = LocalPoolVar<bool>;
|
||||
using lp_uint8_t = LocalPoolVar<uint8_t>;
|
||||
using lp_uint16_t = LocalPoolVar<uint16_t>;
|
||||
using lp_uint32_t = LocalPoolVar<uint32_t>;
|
||||
using lp_uint64_t = LocalPoolVar<uint64_t>;
|
||||
using lp_int8_t = LocalPoolVar<int8_t>;
|
||||
using lp_int16_t = LocalPoolVar<int16_t>;
|
||||
using lp_int32_t = LocalPoolVar<int32_t>;
|
||||
using lp_int64_t = LocalPoolVar<int64_t>;
|
||||
using lp_float_t = LocalPoolVar<float>;
|
||||
using lp_double_t = LocalPoolVar<double>;
|
||||
|
||||
|
109
datapoollocal/LocalPoolVariable.tpp
Normal file
109
datapoollocal/LocalPoolVariable.tpp
Normal file
@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include <framework/housekeeping/HasHkPoolParametersIF.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
template<typename T>
|
||||
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId,
|
||||
HasHkPoolParametersIF* hkOwner, pool_rwm_t setReadWriteMode,
|
||||
DataSetIF* dataSet):
|
||||
localPoolId(poolId),readWriteMode(setReadWriteMode) {
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
if(dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
|
||||
pool_rwm_t setReadWriteMode, DataSetIF *dataSet):
|
||||
readWriteMode(readWriteMode) {
|
||||
HasHkPoolParametersIF* hkOwner =
|
||||
objectManager->get<HasHkPoolParametersIF>(poolOwner);
|
||||
if(hkOwner == nullptr) {
|
||||
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
|
||||
"the correct interface HasHkPoolParametersIF!" << std::endl;
|
||||
objectValid = false;
|
||||
return;
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
if(dataSet != nullptr) {
|
||||
dataSet->registerVariable(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::read() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
"mode for read() call." << std::endl;
|
||||
// TODO: special return value
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
MutexHelper(hkManager->getMutexHandle(), MutexIF::NO_TIMEOUT);
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, poolEntry);
|
||||
if(result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->value = *(poolEntry->address);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::commit() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_READ) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
"mode for commit() call." << std::endl;
|
||||
// TODO: special return value
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
MutexHelper(hkManager->getMutexHandle(), MutexIF::NO_TIMEOUT);
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, poolEntry);
|
||||
if(result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
*(poolEntry->address) = this->value;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline pool_rwm_t LocalPoolVar<T>::getReadWriteMode() const {
|
||||
return readWriteMode;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline lp_id_t LocalPoolVar<T>::getDataPoolId() const {
|
||||
return localPoolId;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool LocalPoolVar<T>::isValid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void LocalPoolVar<T>::setValid(uint8_t validity) {
|
||||
this->valid = validity;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const {
|
||||
return AutoSerializeAdapter::serialize(&value,
|
||||
buffer, size ,max_size, bigEndian);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline size_t LocalPoolVar<T>::getSerializedSize() const {
|
||||
return AutoSerializeAdapter::getSerializedSize(&value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVar<T>::deSerialize(const uint8_t** buffer,
|
||||
size_t* size, bool bigEndian) {
|
||||
return AutoSerializeAdapter::deSerialize(&value, buffer, size, bigEndian);
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/datapool/PoolVector.h>
|
||||
#include <framework/devicehandlers/AcceptsDeviceResponsesIF.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <framework/devicehandlers/DeviceTmReportingWrapper.h>
|
||||
#include <framework/globalfunctions/CRC.h>
|
||||
#include <framework/objectmanager/ObjectManager.h>
|
||||
#include <framework/storagemanager/StorageManagerIF.h>
|
||||
#include <framework/subsystem/SubsystemBase.h>
|
||||
#include <framework/thermal/ThermalComponentIF.h>
|
||||
#include <framework/devicehandlers/AcceptsDeviceResponsesIF.h>
|
||||
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/devicehandlers/DeviceTmReportingWrapper.h>
|
||||
#include <framework/globalfunctions/CRC.h>
|
||||
#include <framework/subsystem/SubsystemBase.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
@ -17,34 +17,33 @@ object_id_t DeviceHandlerBase::rawDataReceiverId = 0;
|
||||
object_id_t DeviceHandlerBase::defaultFDIRParentId = 0;
|
||||
|
||||
DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
|
||||
object_id_t deviceCommunication, CookieIF * comCookie_,
|
||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
||||
uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance,
|
||||
size_t cmdQueueSize) :
|
||||
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
|
||||
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
|
||||
deviceCommunicationId(deviceCommunication), comCookie(comCookie_),
|
||||
deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId(thermalRequestPoolId),
|
||||
healthHelper(this, setObjectId), modeHelper(this), parameterHelper(this),
|
||||
fdirInstance(fdirInstance), hkSwitcher(this),
|
||||
defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false),
|
||||
executingTask(nullptr), actionHelper(this, nullptr), cookieInfo(),
|
||||
childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN),
|
||||
transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch)
|
||||
{
|
||||
commandQueue = QueueFactory::instance()->
|
||||
createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE);
|
||||
deviceCommunicationId(deviceCommunication), deviceThermalStatePoolId(
|
||||
thermalStatePoolId),deviceThermalRequestPoolId(thermalRequestPoolId),
|
||||
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
||||
childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
|
||||
hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
|
||||
switchOffWasReported(false), actionHelper(this, nullptr), cookieInfo(),
|
||||
childTransitionDelay(5000),
|
||||
transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(
|
||||
SUBMODE_NONE), deviceSwitch(setDeviceSwitch) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
||||
CommandMessage::MAX_MESSAGE_SIZE);
|
||||
cookieInfo.state = COOKIE_UNUSED;
|
||||
insertInCommandMap(RAW_COMMAND_ID);
|
||||
if (this->fdirInstance == nullptr) {
|
||||
this->fdirInstance =
|
||||
new DeviceHandlerFailureIsolation(setObjectId,
|
||||
defaultFDIRParentId);
|
||||
this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId,
|
||||
defaultFDIRParentId);
|
||||
}
|
||||
}
|
||||
|
||||
DeviceHandlerBase::~DeviceHandlerBase() {
|
||||
delete comCookie;
|
||||
//communicationInterface->close(cookie);
|
||||
if (defaultFDIRUsed) {
|
||||
delete fdirInstance;
|
||||
}
|
||||
@ -53,7 +52,8 @@ DeviceHandlerBase::~DeviceHandlerBase() {
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
|
||||
this->pstStep = counter;
|
||||
if (counter == 0) {
|
||||
|
||||
if (getComAction() == SEND_WRITE) {
|
||||
cookieInfo.state = COOKIE_UNUSED;
|
||||
readCommandQueue();
|
||||
doStateMachine();
|
||||
@ -66,7 +66,6 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
|
||||
if (mode == MODE_OFF) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
switch (getComAction()) {
|
||||
case SEND_WRITE:
|
||||
if ((cookieInfo.state == COOKIE_UNUSED)) {
|
||||
@ -87,7 +86,6 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
@ -116,7 +114,7 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
||||
AcceptsDeviceResponsesIF *rawReceiver = objectManager->get<
|
||||
AcceptsDeviceResponsesIF>(rawDataReceiverId);
|
||||
|
||||
if (rawReceiver == nullptr) {
|
||||
if (rawReceiver == NULL) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -158,14 +156,15 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
||||
fillCommandAndReplyMap();
|
||||
|
||||
//Set temperature target state to NON_OP.
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_WRITE);
|
||||
mySet.read();
|
||||
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
||||
mySet.commit(PoolVariableIF::VALID);
|
||||
|
||||
return RETURN_OK;
|
||||
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::decrementDeviceReplyMap() {
|
||||
@ -366,8 +365,11 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceComm
|
||||
info.expectedReplies = 0;
|
||||
info.isExecuting = false;
|
||||
info.sendReplyTo = NO_COMMANDER;
|
||||
std::pair<DeviceCommandIter, bool> result = deviceCommandMap.emplace(deviceCommand,info);
|
||||
if (result.second) {
|
||||
std::pair<std::map<DeviceCommandId_t, DeviceCommandInfo>::iterator, bool> returnValue;
|
||||
returnValue = deviceCommandMap.insert(
|
||||
std::pair<DeviceCommandId_t, DeviceCommandInfo>(deviceCommand,
|
||||
info));
|
||||
if (returnValue.second) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
@ -426,8 +428,8 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
||||
Clock::getUptime(&timeoutStart);
|
||||
|
||||
if (mode == MODE_OFF) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -487,7 +489,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter,
|
||||
return;
|
||||
}
|
||||
//Check if more replies are expected. If so, do nothing.
|
||||
DeviceCommandInfo * info = &(iter->second.command->second);
|
||||
DeviceCommandInfo* info = &(iter->second.command->second);
|
||||
if (--info->expectedReplies == 0) {
|
||||
//Check if it was transition or internal command. Don't send any replies in that case.
|
||||
if (info->sendReplyTo != NO_COMMANDER) {
|
||||
@ -526,6 +528,7 @@ void DeviceHandlerBase::doGetWrite() {
|
||||
if (wiretappingMode == RAW) {
|
||||
replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true);
|
||||
}
|
||||
|
||||
//We need to distinguish here, because a raw command never expects a reply.
|
||||
//(Could be done in eRIRM, but then child implementations need to be careful.
|
||||
result = enableReplyInReplyMap(cookieInfo.pendingCommand);
|
||||
@ -541,25 +544,22 @@ void DeviceHandlerBase::doGetWrite() {
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::doSendRead() {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
ReturnValue_t result;
|
||||
|
||||
size_t requestLen = 0;
|
||||
// If the device handler can only request replies after a command
|
||||
// has been sent, there should be only one reply enabled and the
|
||||
// correct reply length will be mapped.
|
||||
for(DeviceReplyIter iter = deviceReplyMap.begin();
|
||||
iter != deviceReplyMap.end();iter++)
|
||||
{
|
||||
if(iter->second.delayCycles != 0) {
|
||||
requestLen = iter->second.replyLen;
|
||||
break;
|
||||
}
|
||||
DeviceReplyIter iter = deviceReplyMap.find(cookieInfo.pendingCommand->first);
|
||||
if(iter != deviceReplyMap.end()) {
|
||||
requestLen = iter->second.replyLen;
|
||||
}
|
||||
else {
|
||||
requestLen = 0;
|
||||
}
|
||||
|
||||
result = communicationInterface->requestReceiveMessage(comCookie, requestLen);
|
||||
|
||||
if (result == RETURN_OK) {
|
||||
cookieInfo.state = COOKIE_READ_SENT;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
|
||||
//We can't inform anyone, because we don't know which command was sent last.
|
||||
//So, we need to wait for a timeout.
|
||||
@ -583,8 +583,8 @@ void DeviceHandlerBase::doGetRead() {
|
||||
|
||||
cookieInfo.state = COOKIE_UNUSED;
|
||||
|
||||
result = communicationInterface->readReceivedMessage(comCookie, &receivedData,
|
||||
&receivedDataLen);
|
||||
result = communicationInterface->readReceivedMessage(comCookie,
|
||||
&receivedData, &receivedDataLen);
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
|
||||
@ -644,7 +644,7 @@ void DeviceHandlerBase::doGetRead() {
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress,
|
||||
uint8_t ** data, size_t * len) {
|
||||
uint8_t * *data, uint32_t * len) {
|
||||
size_t lenTmp;
|
||||
|
||||
if (IPCStore == NULL) {
|
||||
@ -663,10 +663,8 @@ ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress,
|
||||
*len = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
||||
MessageQueueId_t sendTo, bool isCommand) {
|
||||
if (IPCStore == NULL || len == 0) {
|
||||
@ -681,6 +679,7 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
||||
}
|
||||
|
||||
CommandMessage message;
|
||||
|
||||
DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&message,
|
||||
getObjectId(), address, isCommand);
|
||||
|
||||
@ -690,14 +689,12 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
IPCStore->deleteData(address);
|
||||
// Silently discard data, this indicates heavy TM traffic which should
|
||||
// not be increased by additional events.
|
||||
//Silently discard data, this indicates heavy TM traffic which should not be increased by additional events.
|
||||
}
|
||||
}
|
||||
|
||||
//Default child implementations
|
||||
|
||||
DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getComAction() {
|
||||
DeviceHandlerIF::CommunicationAction_t DeviceHandlerBase::getComAction() {
|
||||
switch (pstStep) {
|
||||
case 0:
|
||||
return SEND_WRITE;
|
||||
@ -762,8 +759,8 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
|
||||
// DeviceCommunicationIF>(newChannelId);
|
||||
//
|
||||
// if (newCommunication != NULL) {
|
||||
// ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress,
|
||||
// maxDeviceReplyLen, comParameter1, comParameter2);
|
||||
// ReturnValue_t result = newCommunication->reOpen(cookie, ioBoardAddress,
|
||||
// maxDeviceReplyLen);
|
||||
// if (result != RETURN_OK) {
|
||||
// return result;
|
||||
// }
|
||||
@ -780,8 +777,8 @@ void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
|
||||
replyReturnvalueToCommand(result, RAW_COMMAND_ID);
|
||||
storedRawData.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
} else {
|
||||
cookieInfo.pendingCommand = deviceCommandMap.
|
||||
find((DeviceCommandId_t) RAW_COMMAND_ID);
|
||||
cookieInfo.pendingCommand = deviceCommandMap.find(
|
||||
(DeviceCommandId_t) RAW_COMMAND_ID);
|
||||
cookieInfo.pendingCommand->second.isExecuting = true;
|
||||
cookieInfo.state = COOKIE_WRITE_READY;
|
||||
}
|
||||
@ -820,7 +817,7 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap(
|
||||
iter = deviceReplyMap.find(command->first);
|
||||
}
|
||||
if (iter != deviceReplyMap.end()) {
|
||||
DeviceReplyInfo * info = &(iter->second);
|
||||
DeviceReplyInfo *info = &(iter->second);
|
||||
info->delayCycles = info->maxDelayCycles;
|
||||
info->command = command;
|
||||
command->second.expectedReplies = expectedReplies;
|
||||
@ -846,9 +843,8 @@ ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) {
|
||||
ReturnValue_t result = getSwitches(&switches, &numberOfSwitches);
|
||||
if ((result == RETURN_OK) && (numberOfSwitches != 0)) {
|
||||
while (numberOfSwitches > 0) {
|
||||
if (powerSwitcher-> getSwitchState(switches[numberOfSwitches - 1])
|
||||
== PowerSwitchIF::SWITCH_OFF)
|
||||
{
|
||||
if (powerSwitcher->getSwitchState(switches[numberOfSwitches - 1])
|
||||
== PowerSwitchIF::SWITCH_OFF) {
|
||||
return PowerSwitchIF::SWITCH_OFF;
|
||||
}
|
||||
numberOfSwitches--;
|
||||
@ -890,10 +886,10 @@ ReturnValue_t DeviceHandlerBase::checkModeCommand(Mode_t commandedMode,
|
||||
|
||||
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
||||
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalState(deviceThermalStatePoolId, &mySet,
|
||||
GlobDataSet mySet;
|
||||
gp_uint8_t thermalState(deviceThermalStatePoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||
PoolVariableIF::VAR_READ);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -920,8 +916,8 @@ void DeviceHandlerBase::startTransition(Mode_t commandedMode,
|
||||
childTransitionDelay = getTransitionDelayMs(_MODE_START_UP,
|
||||
MODE_ON);
|
||||
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
||||
DataSet mySet;
|
||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId,
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t thermalRequest(deviceThermalRequestPoolId,
|
||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||
mySet.read();
|
||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||
@ -1032,7 +1028,6 @@ void DeviceHandlerBase::replyRawReplyIfnotWiretapped(const uint8_t* data,
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage(
|
||||
CommandMessage * message) {
|
||||
ReturnValue_t result;
|
||||
switch (message->getCommand()) {
|
||||
case DeviceHandlerMessage::CMD_WIRETAPPING:
|
||||
switch (DeviceHandlerMessage::getWiretappingMode(message)) {
|
||||
@ -1054,21 +1049,19 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage(
|
||||
}
|
||||
replyReturnvalueToCommand(RETURN_OK);
|
||||
return RETURN_OK;
|
||||
case DeviceHandlerMessage::CMD_SWITCH_ADDRESS:
|
||||
if (mode != MODE_OFF) {
|
||||
replyReturnvalueToCommand(WRONG_MODE_FOR_COMMAND);
|
||||
} else {
|
||||
// rework in progress
|
||||
result = RETURN_OK;
|
||||
//result = switchCookieChannel(
|
||||
// DeviceHandlerMessage::getIoBoardObjectId(message));
|
||||
if (result == RETURN_OK) {
|
||||
replyReturnvalueToCommand(RETURN_OK);
|
||||
} else {
|
||||
replyReturnvalueToCommand(CANT_SWITCH_ADDRESS);
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
// case DeviceHandlerMessage::CMD_SWITCH_IOBOARD:
|
||||
// if (mode != MODE_OFF) {
|
||||
// replyReturnvalueToCommand(WRONG_MODE_FOR_COMMAND);
|
||||
// } else {
|
||||
//// result = switchCookieChannel(
|
||||
//// DeviceHandlerMessage::getIoBoardObjectId(message));
|
||||
// if (result == RETURN_OK) {
|
||||
// replyReturnvalueToCommand(RETURN_OK);
|
||||
// } else {
|
||||
// replyReturnvalueToCommand(CANT_SWITCH_IO_ADDRESS);
|
||||
// }
|
||||
// }
|
||||
// return RETURN_OK;
|
||||
case DeviceHandlerMessage::CMD_RAW:
|
||||
if ((mode != MODE_RAW)) {
|
||||
DeviceHandlerMessage::clear(message);
|
||||
@ -1124,7 +1117,8 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
||||
|
||||
// hiding of sender needed so the service will handle it as unexpected Data, no matter what state
|
||||
//(progress or completed) it is in
|
||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper, true);
|
||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
||||
true);
|
||||
|
||||
}
|
||||
} else { //unrequested/aperiodic replies
|
||||
@ -1137,9 +1131,9 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
||||
true);
|
||||
}
|
||||
}
|
||||
//Try to cast to DataSet and commit 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);
|
||||
}
|
||||
@ -1147,12 +1141,11 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size) {
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size) {
|
||||
ReturnValue_t result = acceptExternalDeviceCommands();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
DeviceCommandMap::iterator iter = deviceCommandMap.find(actionId);
|
||||
if (iter == deviceCommandMap.end()) {
|
||||
result = COMMAND_NOT_SUPPORTED;
|
||||
@ -1171,7 +1164,7 @@ ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId,
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::buildInternalCommand(void) {
|
||||
// Neither Raw nor Direct could build a command
|
||||
//Neither Raw nor Direct could build a command
|
||||
ReturnValue_t result = NOTHING_TO_SEND;
|
||||
DeviceCommandId_t deviceCommandId = NO_COMMAND_ID;
|
||||
if (mode == MODE_NORMAL) {
|
||||
@ -1189,13 +1182,12 @@ void DeviceHandlerBase::buildInternalCommand(void) {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == NOTHING_TO_SEND) {
|
||||
return;
|
||||
}
|
||||
if (result == RETURN_OK) {
|
||||
DeviceCommandMap::iterator iter =
|
||||
deviceCommandMap.find(deviceCommandId);
|
||||
DeviceCommandMap::iterator iter = deviceCommandMap.find(
|
||||
deviceCommandId);
|
||||
if (iter == deviceCommandMap.end()) {
|
||||
result = COMMAND_NOT_SUPPORTED;
|
||||
} else if (iter->second.isExecuting) {
|
||||
@ -1210,7 +1202,6 @@ void DeviceHandlerBase::buildInternalCommand(void) {
|
||||
cookieInfo.state = COOKIE_WRITE_READY;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
triggerEvent(DEVICE_BUILDING_COMMAND_FAILED, result, deviceCommandId);
|
||||
}
|
||||
@ -1285,8 +1276,8 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){
|
||||
executingTask = task_;
|
||||
}
|
||||
|
||||
void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t objectId, uint32_t parameter) {
|
||||
}
|
||||
// Default implementations empty.
|
||||
void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
|
||||
object_id_t objectId, uint32_t parameter) {}
|
||||
|
||||
void DeviceHandlerBase::performOperationHook() {
|
||||
}
|
||||
void DeviceHandlerBase::performOperationHook() {}
|
||||
|
@ -1,26 +1,23 @@
|
||||
#ifndef DEVICEHANDLERBASE_H_
|
||||
#define DEVICEHANDLERBASE_H_
|
||||
|
||||
#include <framework/action/ActionHelper.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/action/HasActionsIF.h>
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <framework/health/HealthHelper.h>
|
||||
#include <framework/modes/HasModesIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/parameters/ParameterHelper.h>
|
||||
#include <framework/power/PowerSwitchIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
|
||||
#include <framework/datapool/HkSwitchHelper.h>
|
||||
#include <framework/devicehandlers/CookieIF.h>
|
||||
#include <framework/serialize/SerialFixedArrayListAdapter.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/tasks/PeriodicTaskIF.h>
|
||||
|
||||
#include <framework/action/ActionHelper.h>
|
||||
#include <framework/health/HealthHelper.h>
|
||||
#include <framework/parameters/ParameterHelper.h>
|
||||
#include <framework/datapool/HkSwitchHelper.h>
|
||||
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace Factory{
|
||||
@ -92,21 +89,22 @@ public:
|
||||
* The constructor passes the objectId to the SystemObject().
|
||||
*
|
||||
* @param setObjectId the ObjectId to pass to the SystemObject() Constructor
|
||||
* @param maxDeviceReplyLen the largest allowed reply size
|
||||
* @param maxDeviceReplyLen the length the RMAP getRead call will be sent with
|
||||
* @param setDeviceSwitch the switch the device is connected to,
|
||||
* for devices using two switches, overwrite getSwitches()
|
||||
* @param deviceCommuncation Communcation Interface object which is
|
||||
* used to implement communication functions
|
||||
* for devices using two switches, overwrite getSwitches()
|
||||
* @param deviceCommuncation Communcation Interface object which is used
|
||||
* to implement communication functions
|
||||
* @param thermalStatePoolId
|
||||
* @param thermalRequestPoolId
|
||||
* @param fdirInstance
|
||||
* @param cmdQueueSize
|
||||
*/
|
||||
DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
||||
CookieIF * comCookie_, uint8_t setDeviceSwitch,
|
||||
CookieIF * comCookie, uint8_t setDeviceSwitch,
|
||||
uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER,
|
||||
uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER,
|
||||
FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20);
|
||||
FailureIsolationBase* fdirInstance = nullptr,
|
||||
size_t cmdQueueSize = 20);
|
||||
|
||||
/**
|
||||
* @brief This function is the device handler base core component and is
|
||||
@ -213,12 +211,13 @@ protected:
|
||||
/**
|
||||
* Build the device command to send for normal mode.
|
||||
*
|
||||
* This is only called in @c MODE_NORMAL. If multiple submodes for @c MODE_NORMAL are supported,
|
||||
* different commands can built returned depending on the submode.
|
||||
* This is only called in @c MODE_NORMAL. If multiple submodes for
|
||||
* @c MODE_NORMAL are supported, different commands can built,
|
||||
* depending on the submode.
|
||||
*
|
||||
* #rawPacket and #rawPacketLen must be set by this method to the packet to be sent.
|
||||
* If variable command frequence is required, a counter can be used and
|
||||
* the frequency in the reply map has to be set manually
|
||||
* #rawPacket and #rawPacketLen must be set by this method to the
|
||||
* packet to be sent. If variable command frequence is required, a counter
|
||||
* can be used and the frequency in the reply map has to be set manually
|
||||
* by calling updateReplyMap().
|
||||
*
|
||||
* @param[out] id the device command id that has been built
|
||||
@ -233,10 +232,13 @@ protected:
|
||||
* Build the device command to send for a transitional mode.
|
||||
*
|
||||
* This is only called in @c _MODE_TO_NORMAL, @c _MODE_TO_ON, @c _MODE_TO_RAW,
|
||||
* @c _MODE_START_UP and @c _MODE_TO_POWER_DOWN. So it is used by doStartUp() and doShutDown() as well as doTransition()
|
||||
* @c _MODE_START_UP and @c _MODE_TO_POWER_DOWN. So it is used by doStartUp()
|
||||
* and doShutDown() as well as doTransition()
|
||||
*
|
||||
* A good idea is to implement a flag indicating a command has to be built and a variable containing the command number to be built
|
||||
* and filling them in doStartUp(), doShutDown() and doTransition() so no modes have to be checked here.
|
||||
* A good idea is to implement a flag indicating a command has to be built
|
||||
* and a variable containing the command number to be built
|
||||
* and filling them in doStartUp(), doShutDown() and doTransition() so no
|
||||
* modes have to be checked here.
|
||||
*
|
||||
* #rawPacket and #rawPacketLen must be set by this method to the packet to be sent.
|
||||
*
|
||||
@ -266,6 +268,63 @@ protected:
|
||||
virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t * commandData, size_t commandDataLen) = 0;
|
||||
|
||||
/**
|
||||
* @brief Scans a buffer for a valid reply.
|
||||
* @details
|
||||
* This is used by the base class to check the data received for valid packets.
|
||||
* It only checks if a valid packet starts at @c start.
|
||||
* It also only checks the structural validy of the packet,
|
||||
* e.g. checksums lengths and protocol data. No information check is done,
|
||||
* e.g. range checks etc.
|
||||
*
|
||||
* Errors should be reported directly, the base class does NOT report any
|
||||
* errors based on the return value of this function.
|
||||
*
|
||||
* @param start start of remaining buffer to be scanned
|
||||
* @param len length of remaining buffer to be scanned
|
||||
* @param[out] foundId the id of the data found in the buffer.
|
||||
* @param[out] foundLen length of the data found. Is to be set in function,
|
||||
* buffer is scanned at previous position + foundLen.
|
||||
* @return
|
||||
* - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid
|
||||
* - @c RETURN_FAILED no reply could be found starting at @c start,
|
||||
* implies @c foundLen is not valid, base class will call scanForReply()
|
||||
* again with ++start
|
||||
* - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid,
|
||||
* e.g. checksum error, implies @c foundLen is valid, can be used to
|
||||
* skip some bytes
|
||||
* - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid
|
||||
* - @c DeviceHandlerIF::IGNORE_REPLY_DATA Ignore this specific part of
|
||||
* the packet
|
||||
* - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet
|
||||
* - @c APERIODIC_REPLY if a valid reply is received that has not been
|
||||
* requested by a command, but should be handled anyway
|
||||
* (@see also fillCommandAndCookieMap() )
|
||||
*/
|
||||
virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) = 0;
|
||||
|
||||
/**
|
||||
* @brief Interpret a reply from the device.
|
||||
* @details
|
||||
* This is called after scanForReply() found a valid packet, it can be
|
||||
* assumed that the length and structure is valid.
|
||||
* This routine extracts the data from the packet into a DataSet and then
|
||||
* calls handleDeviceTM(), which either sends a TM packet or stores the
|
||||
* data in the DataPool depending on whether it was an external command.
|
||||
* No packet length is given, as it should be defined implicitly by the id.
|
||||
*
|
||||
* @param id the id found by scanForReply()
|
||||
* @param packet
|
||||
* @return
|
||||
* - @c RETURN_OK when the reply was interpreted.
|
||||
* - @c RETURN_FAILED when the reply could not be interpreted,
|
||||
* e.g. logical errors or range violations occurred
|
||||
*/
|
||||
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) = 0;
|
||||
|
||||
/**
|
||||
* @brief fill the #deviceCommandMap
|
||||
* called by the initialize() of the base class
|
||||
@ -312,85 +371,83 @@ protected:
|
||||
virtual void fillCommandAndReplyMap() = 0;
|
||||
|
||||
/**
|
||||
* @brief Scans a buffer for a valid reply.
|
||||
* @details
|
||||
* This is used by the base class to check the data received for valid packets.
|
||||
* It only checks if a valid packet starts at @c start.
|
||||
* It also only checks the structural validy of the packet,
|
||||
* e.g. checksums lengths and protocol data.
|
||||
* No information check is done, e.g. range checks etc.
|
||||
*
|
||||
* Errors should be reported directly, the base class does NOT report
|
||||
* any errors based on the returnvalue of this function.
|
||||
*
|
||||
* @param start start of remaining buffer to be scanned
|
||||
* @param len length of remaining buffer to be scanned
|
||||
* @param[out] foundId the id of the data found in the buffer.
|
||||
* @param[out] foundLen length of the data found. Is to be set in function,
|
||||
* buffer is scanned at previous position + foundLen.
|
||||
* @return
|
||||
* - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid
|
||||
* - @c RETURN_FAILED no reply could be found starting at @c start,
|
||||
* implies @c foundLen is not valid,
|
||||
* base class will call scanForReply() again with ++start
|
||||
* - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid,
|
||||
* e.g. checksum error, implies @c foundLen is valid, can be used to skip some bytes
|
||||
* - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid
|
||||
* - @c DeviceHandlerIF::IGNORE_REPLY_DATA Ignore this specific part of the packet
|
||||
* - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet
|
||||
* - @c APERIODIC_REPLY if a valid reply is received that has not been
|
||||
* requested by a command, but should be handled anyway
|
||||
* (@see also fillCommandAndCookieMap() )
|
||||
* This is a helper method to facilitate inserting entries in the command map.
|
||||
* @param deviceCommand Identifier of the command to add.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the command
|
||||
* waits until it times out.
|
||||
* @param periodic Indicates if the command is periodic (i.e. it is sent
|
||||
* by the device repeatedly without request) or not. Default is aperiodic (0)
|
||||
* @return - @c RETURN_OK when the command was successfully inserted,
|
||||
* - @c RETURN_FAILED else.
|
||||
*/
|
||||
virtual ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) = 0;
|
||||
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
|
||||
uint16_t maxDelayCycles, size_t replyLen = 0, uint8_t periodic = 0,
|
||||
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
|
||||
|
||||
/**
|
||||
* @brief Interpret a reply from the device.
|
||||
* @details
|
||||
* This is called after scanForReply() found a valid packet, it can be assumed that the length and structure is valid.
|
||||
* This routine extracts the data from the packet into a DataSet and then calls handleDeviceTM(), which either sends
|
||||
* a TM packet or stores the data in the DataPool depending on whether the it was an external command.
|
||||
* No packet length is given, as it should be defined implicitly by the id.
|
||||
*
|
||||
* @param id the id found by scanForReply()
|
||||
* @param packet
|
||||
* @return
|
||||
* - @c RETURN_OK when the reply was interpreted.
|
||||
* - @c RETURN_FAILED when the reply could not be interpreted, eg. logical errors or range violations occurred
|
||||
* @brief This is a helper method to insert replies in the reply map.
|
||||
* @param deviceCommand Identifier of the reply to add.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the reply waits
|
||||
* until it times out.
|
||||
* @param periodic Indicates if the command is periodic (i.e. it is sent
|
||||
* by the device repeatedly without request) or not. Default is aperiodic (0)
|
||||
* @return - @c RETURN_OK when the command was successfully inserted,
|
||||
* - @c RETURN_FAILED else.
|
||||
*/
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) = 0;
|
||||
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand,
|
||||
uint16_t maxDelayCycles, size_t replyLen = 0, uint8_t periodic = 0);
|
||||
|
||||
/**
|
||||
* set all datapool variables that are update periodically in normal mode invalid
|
||||
*
|
||||
* Child classes should provide an implementation which sets all those variables invalid
|
||||
* which are set periodically during any normal mode.
|
||||
* @brief A simple command to add a command to the commandList.
|
||||
* @param deviceCommand The command to add
|
||||
* @return - @c RETURN_OK when the command was successfully inserted,
|
||||
* - @c RETURN_FAILED else.
|
||||
*/
|
||||
virtual void setNormalDatapoolEntriesInvalid() = 0;
|
||||
ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand);
|
||||
/**
|
||||
* @brief This is a helper method to facilitate updating entries
|
||||
* in the reply map.
|
||||
* @param deviceCommand Identifier of the reply to update.
|
||||
* @param delayCycles The current number of delay cycles to wait.
|
||||
* As stated in #fillCommandAndCookieMap, to disable periodic commands,
|
||||
* this is set to zero.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the reply waits
|
||||
* until it times out. By passing 0 the entry remains untouched.
|
||||
* @param periodic Indicates if the command is periodic (i.e. it is sent
|
||||
* by the device repeatedly without request) or not.Default is aperiodic (0).
|
||||
* Warning: The setting always overrides the value that was entered in the map.
|
||||
* @return - @c RETURN_OK when the command was successfully inserted,
|
||||
* - @c RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t updateReplyMapEntry(DeviceCommandId_t deviceReply,
|
||||
uint16_t delayCycles, uint16_t maxDelayCycles,
|
||||
uint8_t periodic = 0);
|
||||
|
||||
/**
|
||||
* @brief Can be implemented by child handler to
|
||||
* perform debugging
|
||||
* @details Example: Calling this in performOperation
|
||||
* to track values like mode.
|
||||
* @param positionTracker Provide the child handler a way to know where the debugInterface was called
|
||||
* @param objectId Provide the child handler object Id to specify actions for spefic devices
|
||||
* @param parameter Supply a parameter of interest
|
||||
* @param positionTracker Provide the child handler a way to know
|
||||
* where the debugInterface was called
|
||||
* @param objectId Provide the child handler object Id to
|
||||
* specify actions for spefic devices
|
||||
* @param parameter Supply a parameter of interest
|
||||
* Please delete all debugInterface calls in DHB after debugging is finished !
|
||||
*/
|
||||
virtual void debugInterface(uint8_t positionTracker = 0, object_id_t objectId = 0, uint32_t parameter = 0);
|
||||
virtual void debugInterface(uint8_t positionTracker = 0,
|
||||
object_id_t objectId = 0, uint32_t parameter = 0);
|
||||
|
||||
/**
|
||||
* Get the time needed to transit from modeFrom to modeTo.
|
||||
*
|
||||
* Used for the following transitions:
|
||||
* modeFrom -> modeTo:
|
||||
* - MODE_ON -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN]
|
||||
* - MODE_NORMAL -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN]
|
||||
* - MODE_RAW -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN]
|
||||
* - _MODE_START_UP -> MODE_ON (do not include time to set the switches, the base class got you covered)
|
||||
* MODE_ON -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN]
|
||||
* MODE_NORMAL -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN]
|
||||
* MODE_RAW -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN]
|
||||
* _MODE_START_UP -> MODE_ON (do not include time to set the switches,
|
||||
* the base class got you covered)
|
||||
*
|
||||
* The default implementation returns 0 !
|
||||
* @param modeFrom
|
||||
@ -408,40 +465,24 @@ protected:
|
||||
* @param[out] numberOfSwitches length of returned array
|
||||
* @return
|
||||
* - @c RETURN_OK if the parameters were set
|
||||
* - @c NO_SWITCH or any other returnvalue if no switches exist
|
||||
* - @c RETURN_FAILED if no switches exist
|
||||
*/
|
||||
virtual ReturnValue_t getSwitches(const uint8_t **switches,
|
||||
uint8_t *numberOfSwitches);
|
||||
|
||||
/**
|
||||
* Can be used to perform device specific periodic operations.
|
||||
* This is called on the SEND_READ step of the performOperation() call
|
||||
* @brief Hook function for child handlers which is called once per
|
||||
* performOperation(). Default implementation is empty.
|
||||
*/
|
||||
virtual void performOperationHook();
|
||||
|
||||
/**
|
||||
* The Returnvalues id of this class, required by HasReturnvaluesIF
|
||||
*/
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @param parentQueueId
|
||||
*/
|
||||
virtual void setParentQueue(MessageQueueId_t parentQueueId);
|
||||
|
||||
/**
|
||||
* This function call handles the execution of external commands as required
|
||||
* by the HasActionIF.
|
||||
* @param actionId
|
||||
* @param commandedBy
|
||||
* @param data
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size);
|
||||
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size);
|
||||
Mode_t getTransitionSourceMode() const;
|
||||
Submode_t getTransitionSourceSubMode() const;
|
||||
virtual void getMode(Mode_t *mode, Submode_t *submode);
|
||||
@ -460,6 +501,28 @@ public:
|
||||
virtual MessageQueueId_t getCommandQueue(void) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The Returnvalues id of this class, required by HasReturnvaluesIF
|
||||
*/
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE;
|
||||
|
||||
/**
|
||||
* These returnvalues can be returned from abstract functions
|
||||
* to alter the behaviour of DHB.For error values, refer to
|
||||
* DeviceHandlerIF.h returnvalues.
|
||||
*/
|
||||
static const ReturnValue_t INVALID_CHANNEL = MAKE_RETURN_CODE(4);
|
||||
// Returnvalues for scanForReply()
|
||||
static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(5); //!< This is used to specify for replies from a device which are not replies to requests
|
||||
static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(6); //!< Ignore parts of the received packet
|
||||
static const ReturnValue_t IGNORE_FULL_PACKET = MAKE_RETURN_CODE(7); //!< Ignore full received packet
|
||||
|
||||
// static const ReturnValue_t ONE_SWITCH = MAKE_RETURN_CODE(8);
|
||||
// static const ReturnValue_t TWO_SWITCHES = MAKE_RETURN_CODE(9);
|
||||
static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(10);
|
||||
static const ReturnValue_t COMMAND_MAP_ERROR = MAKE_RETURN_CODE(11);
|
||||
static const ReturnValue_t NOTHING_TO_SEND = MAKE_RETURN_CODE(12);
|
||||
|
||||
//Mode handling error Codes
|
||||
static const ReturnValue_t CHILD_TIMEOUT = MAKE_RETURN_CODE(0xE1);
|
||||
static const ReturnValue_t SWITCH_FAILED = MAKE_RETURN_CODE(0xE2);
|
||||
@ -475,7 +538,7 @@ protected:
|
||||
/**
|
||||
* Size of the #rawPacket.
|
||||
*/
|
||||
size_t rawPacketLen = 0;
|
||||
uint32_t rawPacketLen = 0;
|
||||
|
||||
/**
|
||||
* The mode the device handler is currently in.
|
||||
@ -502,7 +565,7 @@ protected:
|
||||
* indicates either that all raw messages to and from the device should be sent to #theOneWhoWantsToReadRawTraffic
|
||||
* or that all device TM should be downlinked to #theOneWhoWantsToReadRawTraffic
|
||||
*/
|
||||
enum WiretappingMode: uint8_t {
|
||||
enum WiretappingMode {
|
||||
OFF = 0, RAW = 1, TM = 2
|
||||
} wiretappingMode;
|
||||
|
||||
@ -546,18 +609,16 @@ protected:
|
||||
DeviceCommunicationIF *communicationInterface = nullptr;
|
||||
|
||||
/**
|
||||
* Cookie used for communication. This is passed to the communication
|
||||
* interface.
|
||||
* Cookie used for communication
|
||||
*/
|
||||
CookieIF *comCookie;
|
||||
CookieIF * comCookie = nullptr;
|
||||
|
||||
struct DeviceCommandInfo {
|
||||
bool isExecuting; //!< Indicates if the command is already executing.
|
||||
uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0.
|
||||
MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander.
|
||||
};
|
||||
typedef std::map<DeviceCommandId_t, DeviceCommandInfo> DeviceCommandMap;
|
||||
typedef DeviceCommandMap::iterator DeviceCommandIter;
|
||||
using DeviceCommandMap = std::map<DeviceCommandId_t, DeviceCommandInfo> ;
|
||||
|
||||
/**
|
||||
* @brief Information about expected replies
|
||||
@ -568,15 +629,12 @@ protected:
|
||||
uint16_t maxDelayCycles; //!< The maximum number of cycles the handler should wait for a reply to this command.
|
||||
uint16_t delayCycles; //!< The currently remaining cycles the handler should wait for a reply, 0 means there is no reply expected
|
||||
size_t replyLen = 0; //!< Expected size of the reply.
|
||||
//(Robin): This is a flag, isnt it? could we declare it bool? uint8_t always
|
||||
// gives away the impression that this variable is more than a simple flag
|
||||
// and true/false are also more explicit.
|
||||
uint8_t periodic; //!< if this is !=0, the delayCycles will not be reset to 0 but to maxDelayCycles
|
||||
DeviceCommandMap::iterator command; //!< The command that expects this reply.
|
||||
};
|
||||
|
||||
typedef std::map<DeviceCommandId_t, DeviceReplyInfo> DeviceReplyMap;
|
||||
typedef DeviceReplyMap::iterator DeviceReplyIter;
|
||||
using DeviceReplyMap = std::map<DeviceCommandId_t, DeviceReplyInfo> ;
|
||||
using DeviceReplyIter = DeviceReplyMap::iterator;
|
||||
|
||||
/**
|
||||
* The MessageQueue used to receive device handler commands and to send replies.
|
||||
@ -610,7 +668,7 @@ protected:
|
||||
* Optional Error code
|
||||
* Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure.
|
||||
*/
|
||||
ReturnValue_t childTransitionFailure = RETURN_OK;
|
||||
ReturnValue_t childTransitionFailure;
|
||||
|
||||
uint32_t ignoreMissedRepliesCount = 0; //!< Counts if communication channel lost a reply, so some missed replys can be ignored.
|
||||
|
||||
@ -622,35 +680,13 @@ protected:
|
||||
|
||||
bool switchOffWasReported; //!< Indicates if SWITCH_WENT_OFF was already thrown.
|
||||
|
||||
PeriodicTaskIF* executingTask;//!< Pointer to the task which executes this component, is invalid before setTaskIF was called.
|
||||
PeriodicTaskIF* executingTask = nullptr;//!< Pointer to the task which executes this component, is invalid before setTaskIF was called.
|
||||
|
||||
static object_id_t powerSwitcherId; //!< Object which switches power on and off.
|
||||
|
||||
static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default.
|
||||
|
||||
static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault.
|
||||
|
||||
/**
|
||||
* Set the device handler mode
|
||||
*
|
||||
* Sets #timeoutStart with every call.
|
||||
*
|
||||
* Sets #transitionTargetMode if necessary so transitional states can be entered from everywhere without breaking the state machine
|
||||
* (which relies on a correct #transitionTargetMode).
|
||||
*
|
||||
* The submode is left unchanged.
|
||||
*
|
||||
*
|
||||
* @param newMode
|
||||
*/
|
||||
void setMode(Mode_t newMode);
|
||||
|
||||
/**
|
||||
* @overload
|
||||
* @param submode
|
||||
*/
|
||||
void setMode(Mode_t newMode, Submode_t submode);
|
||||
|
||||
/**
|
||||
* Helper function to report a missed reply
|
||||
*
|
||||
@ -671,14 +707,30 @@ protected:
|
||||
void replyReturnvalueToCommand(ReturnValue_t status,
|
||||
uint32_t parameter = 0);
|
||||
|
||||
/**
|
||||
* Send reply to a command, differentiate between raw command
|
||||
* and normal command.
|
||||
* @param status
|
||||
* @param parameter
|
||||
*/
|
||||
void replyToCommand(ReturnValue_t status, uint32_t parameter = 0);
|
||||
|
||||
/**
|
||||
* Set the device handler mode
|
||||
*
|
||||
* Sets #timeoutStart with every call.
|
||||
*
|
||||
* Sets #transitionTargetMode if necessary so transitional states can be
|
||||
* entered from everywhere without breaking the state machine
|
||||
* (which relies on a correct #transitionTargetMode).
|
||||
*
|
||||
* The submode is left unchanged.
|
||||
*
|
||||
*
|
||||
* @param newMode
|
||||
*/
|
||||
void setMode(Mode_t newMode);
|
||||
|
||||
/**
|
||||
* @overload
|
||||
* @param submode
|
||||
*/
|
||||
void setMode(Mode_t newMode, Submode_t submode);
|
||||
|
||||
/**
|
||||
* Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW).
|
||||
*
|
||||
@ -708,55 +760,6 @@ protected:
|
||||
*/
|
||||
virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom);
|
||||
|
||||
/**
|
||||
* This is a helper method to facilitate inserting entries in the command map.
|
||||
* @param deviceCommand Identifier of the command to add.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the command waits until it times out.
|
||||
* @param periodic Indicates if the reply is periodic (i.e. it is sent by the device repeatedly without request) or not.
|
||||
* Default is aperiodic (0)
|
||||
* @param hasDifferentReplyId
|
||||
* @param replyId
|
||||
* @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else.
|
||||
*/
|
||||
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
|
||||
uint16_t maxDelayCycles, size_t replyLen = 0, uint8_t periodic = 0,
|
||||
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
|
||||
/**
|
||||
* This is a helper method to insert replies in the reply map.
|
||||
* @param deviceCommand Identifier of the reply to add.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the reply waits until it times out.
|
||||
* @param periodic Indicates if the command is periodic (i.e. it is sent by the device repeatedly without request) or not.
|
||||
* Default is aperiodic (0)
|
||||
* @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else.
|
||||
*/
|
||||
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand,
|
||||
uint16_t maxDelayCycles, size_t replyLen = 0, uint8_t periodic = 0);
|
||||
/**
|
||||
* A simple command to add a command to the commandList.
|
||||
* @param deviceCommand The command to add
|
||||
* @return RETURN_OK if the command was successfully inserted, RETURN_FAILED else.
|
||||
*/
|
||||
ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand);
|
||||
/**
|
||||
* This is a helper method to facilitate updating entries in the reply map.
|
||||
* @param deviceCommand Identifier of the reply to update.
|
||||
* @param delayCycles The current number of delay cycles to wait. As stated in #fillCommandAndCookieMap, to disable periodic commands, this is set to zero.
|
||||
* @param maxDelayCycles The maximum number of delay cycles the reply waits until it times out. By passing 0 the entry remains untouched.
|
||||
* @param periodic Indicates if the command is periodic (i.e. it is sent by the device repeatedly without request) or not.
|
||||
* Default is aperiodic (0). Warning: The setting always overrides the value that was entered in the map.
|
||||
* @return RETURN_OK when the reply was successfully updated, COMMAND_MAP_ERROR else.
|
||||
*/
|
||||
ReturnValue_t updateReplyMapEntry(DeviceCommandId_t deviceReply,
|
||||
uint16_t delayCycles, uint16_t maxDelayCycles,
|
||||
uint8_t periodic = 0);
|
||||
/**
|
||||
* Returns the delay cycle count of a reply.
|
||||
* A count != 0 indicates that the command is already executed.
|
||||
* @param deviceCommand The command to look for
|
||||
* @return The current delay count. If the command does not exist (should never happen) it returns 0.
|
||||
*/
|
||||
uint8_t getReplyDelayCycles(DeviceCommandId_t deviceCommand);
|
||||
|
||||
/**
|
||||
* Is the combination of mode and submode valid?
|
||||
*
|
||||
@ -776,6 +779,7 @@ protected:
|
||||
*
|
||||
* @return The Rmap action to execute in this step
|
||||
*/
|
||||
|
||||
virtual CommunicationAction_t getComAction();
|
||||
|
||||
/**
|
||||
@ -798,6 +802,14 @@ protected:
|
||||
*/
|
||||
virtual ReturnValue_t buildChildRawCommand();
|
||||
|
||||
/**
|
||||
* Returns the delay cycle count of a reply.
|
||||
* A count != 0 indicates that the command is already executed.
|
||||
* @param deviceCommand The command to look for
|
||||
* @return The current delay count. If the command does not exist (should never happen) it returns 0.
|
||||
*/
|
||||
uint8_t getReplyDelayCycles(DeviceCommandId_t deviceCommand);
|
||||
|
||||
/**
|
||||
* Construct a command reply containing a raw reply.
|
||||
*
|
||||
@ -861,6 +873,14 @@ protected:
|
||||
*/
|
||||
ReturnValue_t getStateOfSwitches(void);
|
||||
|
||||
/**
|
||||
* set all datapool variables that are update periodically in normal mode invalid
|
||||
*
|
||||
* Child classes should provide an implementation which sets all those variables invalid
|
||||
* which are set periodically during any normal mode.
|
||||
*/
|
||||
virtual void setNormalDatapoolEntriesInvalid() = 0;
|
||||
|
||||
/**
|
||||
* build a list of sids and pass it to the #hkSwitcher
|
||||
*/
|
||||
@ -889,6 +909,7 @@ protected:
|
||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
||||
virtual void setToExternalControl();
|
||||
virtual void announceMode(bool recursive);
|
||||
|
||||
virtual ReturnValue_t letChildHandleMessage(CommandMessage *message);
|
||||
|
||||
/**
|
||||
@ -954,13 +975,12 @@ protected:
|
||||
DeviceCommandMap deviceCommandMap;
|
||||
|
||||
ActionHelper actionHelper;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* State a cookie is in.
|
||||
*
|
||||
* Used to keep track of the state of the communication.
|
||||
* Used to keep track of the state of the RMAP communication.
|
||||
*/
|
||||
enum CookieState_t {
|
||||
COOKIE_UNUSED, //!< The Cookie is unused
|
||||
@ -1034,20 +1054,22 @@ private:
|
||||
* - checks whether commanded mode transitions are required and calls handleCommandedModeTransition()
|
||||
* - does the necessary action for the current mode or calls doChildStateMachine in modes @c MODE_TO_ON and @c MODE_TO_OFF
|
||||
* - actions that happen in transitions (eg setting a timeout) are handled in setMode()
|
||||
* - Maybe export this into own class to increase modularity of software
|
||||
* and reduce the massive class size ?
|
||||
*/
|
||||
void doStateMachine(void);
|
||||
|
||||
void buildRawDeviceCommand(CommandMessage* message);
|
||||
void buildInternalCommand(void);
|
||||
|
||||
// /**
|
||||
// * Send a reply with the current mode and submode.
|
||||
// */
|
||||
// void announceMode(void);
|
||||
|
||||
/**
|
||||
* Decrement the counter for the timout of replies.
|
||||
*
|
||||
* This is called at the beginning of each cycle. It checks whether a reply has timed out (that means a reply was expected
|
||||
* but not received).
|
||||
* In case the reply is periodic, the counter is simply set back to a specified value.
|
||||
*/
|
||||
void decrementDeviceReplyMap(void);
|
||||
|
||||
@ -1114,8 +1136,8 @@ private:
|
||||
* - @c RETURN_FAILED IPCStore is NULL
|
||||
* - the return value from the IPCStore if it was not @c RETURN_OK
|
||||
*/
|
||||
ReturnValue_t getStorageData(store_address_t storageAddress,
|
||||
uint8_t ** data, size_t * len);
|
||||
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
|
||||
uint32_t *len);
|
||||
|
||||
/**
|
||||
* set all switches returned by getSwitches()
|
||||
@ -1144,16 +1166,9 @@ private:
|
||||
* - @c RETURN_FAILED when cookies could not be changed, eg because the newChannel is not enabled
|
||||
* - @c returnvalues of RMAPChannelIF::isActive()
|
||||
*/
|
||||
//ReturnValue_t switchCookieChannel(object_id_t newChannelId);
|
||||
ReturnValue_t switchCookieChannel(object_id_t newChannelId);
|
||||
|
||||
/**
|
||||
* Handle device handler messages (e.g. commands sent by PUS Service 2)
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* DEVICEHANDLERBASE_H_ */
|
||||
|
32
housekeeping/HasHkPoolParametersIF.h
Normal file
32
housekeeping/HasHkPoolParametersIF.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_
|
||||
#define FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_
|
||||
#include <framework/datapool/PoolEntryIF.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
#include <map>
|
||||
|
||||
class HousekeepingManager;
|
||||
/**
|
||||
* @brief Type definition for local pool entries.
|
||||
*/
|
||||
using lp_id_t = uint32_t;
|
||||
using LocalDataPoolMap = std::map<lp_id_t, PoolEntryIF*>;
|
||||
using LocalDataPoolMapIter = LocalDataPoolMap::iterator;
|
||||
|
||||
/**
|
||||
* @brief Interface for the local housekeeping managers used by the device
|
||||
* handler.
|
||||
*/
|
||||
class HasHkPoolParametersIF {
|
||||
public:
|
||||
virtual~ HasHkPoolParametersIF() {};
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
virtual ReturnValue_t initializeHousekeepingPoolEntries(
|
||||
LocalDataPoolMap& localDataPoolMap) = 0;
|
||||
virtual float setMinimalHkSamplingFrequency() = 0;
|
||||
virtual HousekeepingManager* getHkManagerHandle() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_ */
|
50
housekeeping/HousekeepingManager.cpp
Normal file
50
housekeeping/HousekeepingManager.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <framework/housekeeping/HousekeepingManager.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
#include <framework/ipc/MutexHelper.h>
|
||||
|
||||
HousekeepingManager::HousekeepingManager(HasHkPoolParametersIF* owner) {
|
||||
//todo :: nullptr check owner.
|
||||
if(owner == nullptr) {
|
||||
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
|
||||
std::exit(0);
|
||||
}
|
||||
this->owner = owner;
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
owner->setMinimalHkSamplingFrequency();
|
||||
}
|
||||
|
||||
HousekeepingManager::~HousekeepingManager() {}
|
||||
|
||||
ReturnValue_t HousekeepingManager::initializeHousekeepingPoolEntriesOnce() {
|
||||
if(not mapInitialized) {
|
||||
ReturnValue_t result = owner->initializeHousekeepingPoolEntries(localDpMap);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
mapInitialized = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
sif::warning << "hk manager says no" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t HousekeepingManager::handleHousekeepingMessage(
|
||||
CommandMessage *message) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MutexIF* HousekeepingManager::getMutexHandle() {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
void HousekeepingManager::setMinimalSamplingFrequency(float frequencySeconds) {
|
||||
this->samplingFrequency = frequencySeconds;
|
||||
|
||||
}
|
||||
|
||||
void HousekeepingManager::generateHousekeepingPacket(DataSetIF *dataSet) {
|
||||
}
|
||||
|
||||
void HousekeepingManager::setHkPacketQueue(MessageQueueIF *msgQueue) {
|
||||
this->hkPacketQueue = msgQueue;
|
||||
}
|
95
housekeeping/HousekeepingManager.h
Normal file
95
housekeeping/HousekeepingManager.h
Normal file
@ -0,0 +1,95 @@
|
||||
#ifndef FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_
|
||||
#define FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/housekeeping/HasHkPoolParametersIF.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
|
||||
#include <framework/datapool/PoolEntry.h>
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/ipc/MutexHelper.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
class HousekeepingManager {
|
||||
public:
|
||||
static constexpr float MINIMAL_SAMPLING_FREQUENCY = 0.2;
|
||||
|
||||
HousekeepingManager(HasHkPoolParametersIF* owner);
|
||||
virtual~ HousekeepingManager();
|
||||
|
||||
MutexIF* getMutexHandle();
|
||||
|
||||
// propably will just call respective local data set functions.
|
||||
void generateHousekeepingPacket(DataSetIF* dataSet);
|
||||
ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
|
||||
|
||||
/**
|
||||
* Read a variable by supplying its local pool ID and assign the pool
|
||||
* entry to the supplied PoolEntry pointer. The type of the pool entry
|
||||
* is deduced automatically. This call is not thread-safe!
|
||||
* @tparam T Type of the pool entry
|
||||
* @param localPoolId Pool ID of the variable to read
|
||||
* @param poolVar [out] Corresponding pool entry will be assigned to the
|
||||
* supplied pointer.
|
||||
* @return
|
||||
*/
|
||||
template <class T>
|
||||
ReturnValue_t fetchPoolEntry(lp_id_t localPoolId, PoolEntry<T> *poolEntry);
|
||||
void setMinimalSamplingFrequency(float frequencySeconds);
|
||||
|
||||
/**
|
||||
* This function is used to fill the local data pool map with pool
|
||||
* entries. The default implementation is empty.
|
||||
* @param localDataPoolMap
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t initializeHousekeepingPoolEntriesOnce();
|
||||
|
||||
void setHkPacketQueue(MessageQueueIF* msgQueue);
|
||||
private:
|
||||
//! this depends on the PST frequency.. maybe it would be better to just
|
||||
//! set this manually with a global configuration value which is also
|
||||
//! passed to the PST. Or force setting this in device handler.
|
||||
float samplingFrequency = MINIMAL_SAMPLING_FREQUENCY;
|
||||
|
||||
//! This is the map holding the actual data. Should only be initialized
|
||||
//! once !
|
||||
bool mapInitialized = false;
|
||||
LocalDataPoolMap localDpMap;
|
||||
|
||||
//! Every housekeeping data manager has a mutex to protect access
|
||||
//! to it's data pool.
|
||||
MutexIF * mutex = nullptr;
|
||||
|
||||
//! The class which actually owns the manager (and its datapool).
|
||||
HasHkPoolParametersIF* owner = nullptr;
|
||||
|
||||
//! Used for replies.
|
||||
//! (maybe we dont need this, the sender can be retrieved from command
|
||||
//! message..)
|
||||
MessageQueueIF* hkReplyQueue = nullptr;
|
||||
//! Used for HK packets, which are generated without requests.
|
||||
MessageQueueIF* hkPacketQueue = nullptr;
|
||||
};
|
||||
|
||||
template<class T> inline
|
||||
ReturnValue_t HousekeepingManager::fetchPoolEntry(lp_id_t localPoolId,
|
||||
PoolEntry<T> *poolEntry) {
|
||||
auto poolIter = localDpMap.find(localPoolId);
|
||||
if (poolIter == localDpMap.end()) {
|
||||
// todo: special returnvalue.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
|
||||
if(poolEntry == nullptr) {
|
||||
// todo: special returnvalue.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
#endif /* FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ */
|
10
housekeeping/HousekeepingMessage.cpp
Normal file
10
housekeeping/HousekeepingMessage.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <framework/housekeeping/HousekeepingMessage.h>
|
||||
|
||||
void HousekeepingMessage::setAddHkReportStructMessage(CommandMessage *message,
|
||||
set_t setId, store_address_t packet) {
|
||||
message->setCommand(ADD_HK_REPORT_STRUCT);
|
||||
message->setParameter(setId);
|
||||
message->setParameter2(packet.raw);
|
||||
}
|
||||
|
||||
//void Housekeeping
|
87
housekeeping/HousekeepingMessage.h
Normal file
87
housekeeping/HousekeepingMessage.h
Normal file
@ -0,0 +1,87 @@
|
||||
#ifndef FRAMEWORK_HK_HOUSEKEEPINGMESSAGE_H_
|
||||
#define FRAMEWORK_HK_HOUSEKEEPINGMESSAGE_H_
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/storagemanager/StorageManagerIF.h>
|
||||
#include <limits>
|
||||
|
||||
/**
|
||||
* the sid consists of the target object ID and... something else I forgot.
|
||||
* Propably a special HK id to distinguish multiple hk pool packages
|
||||
* inside a handler or controller
|
||||
*/
|
||||
typedef uint32_t set_t;
|
||||
|
||||
union sid_t {
|
||||
static constexpr uint64_t INVALID_ADDRESS = std::numeric_limits<uint64_t>::max();
|
||||
sid_t(): raw(INVALID_ADDRESS) {}
|
||||
|
||||
struct {
|
||||
object_id_t objectId ;
|
||||
set_t hkId;
|
||||
};
|
||||
/**
|
||||
* Alternative access to the raw value.
|
||||
*/
|
||||
uint64_t raw;
|
||||
};
|
||||
class HousekeepingMessage {
|
||||
public:
|
||||
/**
|
||||
* No instances of a message shall be created, instead
|
||||
* a CommandMessage instance is manipulated.
|
||||
*/
|
||||
HousekeepingMessage() = delete;
|
||||
HousekeepingMessage(const HousekeepingMessage&) = delete;
|
||||
HousekeepingMessage operator=(const HousekeepingMessage &) = delete;
|
||||
|
||||
static constexpr uint8_t MESSAGE_ID = MESSAGE_TYPE::HOUSEKEEPING;
|
||||
static constexpr Command_t ADD_HK_REPORT_STRUCT =
|
||||
MAKE_COMMAND_ID(1);
|
||||
static constexpr Command_t ADD_DIAGNOSTICS_REPORT_STRUCT =
|
||||
MAKE_COMMAND_ID(2);
|
||||
|
||||
static constexpr Command_t DELETE_HK_REPORT_STRUCT = MAKE_COMMAND_ID(3);
|
||||
static constexpr Command_t DELETE_DIAGNOSTICS_REPORT_STRUCT =
|
||||
MAKE_COMMAND_ID(4);
|
||||
|
||||
static constexpr Command_t ENABLE_PERIODIC_HK_GENERATION =
|
||||
MAKE_COMMAND_ID(5);
|
||||
static constexpr Command_t DISABLE_PERIODIC_HK_REPORT_GENERATION =
|
||||
MAKE_COMMAND_ID(6);
|
||||
|
||||
static constexpr Command_t ENABLE_PERIODIC_DIAGNOSTICS_GENERATION =
|
||||
MAKE_COMMAND_ID(7);
|
||||
static constexpr Command_t DISABLE_PERIODIC_DIAGNOSTICS_GENERATION =
|
||||
MAKE_COMMAND_ID(8);
|
||||
|
||||
static constexpr Command_t REPORT_HK_REPORT_STRUCTURES = MAKE_COMMAND_ID(9);
|
||||
static constexpr Command_t REPORT_DIAGNOSTICS_REPORT_STRUCTURES =
|
||||
MAKE_COMMAND_ID(11);
|
||||
|
||||
static constexpr Command_t HK_DEFINITIONS_REPORT = MAKE_COMMAND_ID(10);
|
||||
static constexpr Command_t DIAGNOSTICS_DEFINITION_REPORT = MAKE_COMMAND_ID(12);
|
||||
|
||||
static constexpr Command_t HK_REPORT = MAKE_COMMAND_ID(25);
|
||||
static constexpr Command_t DIAGNOSTICS_REPORT = MAKE_COMMAND_ID(26);
|
||||
|
||||
static constexpr Command_t GENERATE_ONE_PARAMETER_REPORT =
|
||||
MAKE_COMMAND_ID(27);
|
||||
static constexpr Command_t GENERATE_ONE_DIAGNOSTICS_REPORT =
|
||||
MAKE_COMMAND_ID(28);
|
||||
|
||||
static constexpr Command_t APPEND_PARAMETERS_TO_PARAMETER_REPORT_STRUCTURE =
|
||||
MAKE_COMMAND_ID(29);
|
||||
static constexpr Command_t APPEND_PARAMETERS_TO_DIAGNOSTICS_REPORT_STRUCTURE =
|
||||
MAKE_COMMAND_ID(30);
|
||||
|
||||
static constexpr Command_t MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL =
|
||||
MAKE_COMMAND_ID(31);
|
||||
static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL =
|
||||
MAKE_COMMAND_ID(32);
|
||||
|
||||
static void setAddHkReportStructMessage(CommandMessage* message,
|
||||
set_t setId, store_address_t packet);
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_HK_HOUSEKEEPINGMESSAGE_H_ */
|
@ -1,6 +1,6 @@
|
||||
#include "InternalErrorReporter.h"
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
|
||||
@ -20,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,7 +1,7 @@
|
||||
#ifndef MONITORBASE_H_
|
||||
#define MONITORBASE_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
@ -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()) {
|
||||
|
@ -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(
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FUSE_H_
|
||||
#define FUSE_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/devicehandlers/HealthDevice.h>
|
||||
#include <framework/monitoring/AbsLimitMonitor.h>
|
||||
@ -83,11 +83,11 @@ private:
|
||||
|
||||
};
|
||||
PowerMonitor powerMonitor;
|
||||
DataSet set;
|
||||
GlobDataSet set;
|
||||
PIDReader<float> voltage;
|
||||
PIDReader<float> current;
|
||||
PIDReader<uint8_t> state;
|
||||
db_float_t power;
|
||||
gp_float_t power;
|
||||
MessageQueueIF* commandQueue;
|
||||
ParameterHelper parameterHelper;
|
||||
HealthHelper healthHelper;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef POWERSENSOR_H_
|
||||
#define POWERSENSOR_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/devicehandlers/HealthDevice.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,7 +1,7 @@
|
||||
#ifndef MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
#define MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/thermal/ThermalComponentIF.h>
|
||||
#include <framework/thermal/AbstractTemperatureSensor.h>
|
||||
@ -23,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,
|
||||
@ -58,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;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef THERMALMODULE_H_
|
||||
#define THERMALMODULE_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapoolglob/GlobalDataSet.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/devicehandlers/HealthDevice.h>
|
||||
#include <framework/events/EventReportingProxyIF.h>
|
||||
@ -23,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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user