Merge remote-tracking branch 'upstream/development' into mueller/LocalPoolRefactoring
This commit is contained in:
commit
67a8b031d0
15
CHANGELOG
15
CHANGELOG
@ -1,5 +1,8 @@
|
|||||||
## Changes from ASTP 0.0.1 to 1.0.0
|
## Changes from ASTP 0.0.1 to 1.0.0
|
||||||
|
|
||||||
|
### Host OSAL
|
||||||
|
|
||||||
|
- Bugfix in MessageQueue, which caused the sender not to be set properly
|
||||||
|
|
||||||
### FreeRTOS OSAL
|
### FreeRTOS OSAL
|
||||||
|
|
||||||
@ -15,3 +18,15 @@ a C file without issues
|
|||||||
### Local Pool
|
### Local Pool
|
||||||
|
|
||||||
- Interface of LocalPools has changed. LocalPool is not a template anymore. Instead the size and bucket number of the pools per page and the number of pages are passed to the ctor instead of two ctor arguments and a template parameter
|
- Interface of LocalPools has changed. LocalPool is not a template anymore. Instead the size and bucket number of the pools per page and the number of pages are passed to the ctor instead of two ctor arguments and a template parameter
|
||||||
|
|
||||||
|
### Device Handler Base
|
||||||
|
|
||||||
|
- There is an additional `PERFORM_OPERATION` step for the device handler base. It is important
|
||||||
|
that DHB users adapt their polling sequence tables to perform this step. This steps allows for aclear distinction between operation and communication steps
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
- makeEvent function: Now takes three input parameters instead of two and
|
||||||
|
allows setting a unique ID. Event.cpp source file removed, functions now
|
||||||
|
defined in header directly. Namespaces renamed. Functions declared `constexpr`
|
||||||
|
now
|
||||||
|
@ -19,12 +19,12 @@ class VirtualChannelReception;
|
|||||||
class DataLinkLayer : public CCSDSReturnValuesIF {
|
class DataLinkLayer : public CCSDSReturnValuesIF {
|
||||||
public:
|
public:
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_1;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_1;
|
||||||
static const Event RF_AVAILABLE = MAKE_EVENT(0, SEVERITY::INFO); //!< A RF available signal was detected. P1: raw RFA state, P2: 0
|
static const Event RF_AVAILABLE = MAKE_EVENT(0, severity::INFO); //!< A RF available signal was detected. P1: raw RFA state, P2: 0
|
||||||
static const Event RF_LOST = MAKE_EVENT(1, SEVERITY::INFO); //!< A previously found RF available signal was lost. P1: raw RFA state, P2: 0
|
static const Event RF_LOST = MAKE_EVENT(1, severity::INFO); //!< A previously found RF available signal was lost. P1: raw RFA state, P2: 0
|
||||||
static const Event BIT_LOCK = MAKE_EVENT(2, SEVERITY::INFO); //!< A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0
|
static const Event BIT_LOCK = MAKE_EVENT(2, severity::INFO); //!< A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0
|
||||||
static const Event BIT_LOCK_LOST = MAKE_EVENT(3, SEVERITY::INFO); //!< A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0
|
static const Event BIT_LOCK_LOST = MAKE_EVENT(3, severity::INFO); //!< A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0
|
||||||
// static const Event RF_CHAIN_LOST = MAKE_EVENT(4, SEVERITY::INFO); //!< The CCSDS Board detected that either bit lock or RF available or both are lost. No parameters.
|
// static const Event RF_CHAIN_LOST = MAKE_EVENT(4, severity::INFO); //!< The CCSDS Board detected that either bit lock or RF available or both are lost. No parameters.
|
||||||
static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, SEVERITY::LOW); //!< The CCSDS Board could not interpret a TC
|
static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, severity::LOW); //!< The CCSDS Board could not interpret a TC
|
||||||
/**
|
/**
|
||||||
* The Constructor sets the passed parameters and nothing else.
|
* The Constructor sets the passed parameters and nothing else.
|
||||||
* @param set_frame_buffer The buffer in which incoming frame candidates are stored.
|
* @param set_frame_buffer The buffer in which incoming frame candidates are stored.
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef CONTROLLERSET_H_
|
|
||||||
#define CONTROLLERSET_H_
|
|
||||||
|
|
||||||
#include "DataSet.h"
|
|
||||||
|
|
||||||
class ControllerSet :public DataSet {
|
|
||||||
public:
|
|
||||||
ControllerSet();
|
|
||||||
virtual ~ControllerSet();
|
|
||||||
|
|
||||||
virtual void setToDefault() = 0;
|
|
||||||
void setInvalid();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* CONTROLLERSET_H_ */
|
|
@ -1,131 +0,0 @@
|
|||||||
#include "DataPool.h"
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
#include "../ipc/MutexFactory.h"
|
|
||||||
|
|
||||||
DataPool::DataPool( void ( *initFunction )( std::map<uint32_t, PoolEntryIF*>* pool_map ) ) {
|
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
|
||||||
if (initFunction != NULL ) {
|
|
||||||
initFunction( &this->data_pool );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataPool::~DataPool() {
|
|
||||||
MutexFactory::instance()->deleteMutex(mutex);
|
|
||||||
for ( std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.begin(); it != this->data_pool.end(); ++it ) {
|
|
||||||
delete it->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//The function checks PID, type and array length before returning a copy of the PoolEntry. In failure case, it returns a temp-Entry with size 0 and NULL-ptr.
|
|
||||||
template <typename T> PoolEntry<T>* DataPool::getData( uint32_t data_pool_id, uint8_t sizeOrPosition ) {
|
|
||||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
|
||||||
if ( it != this->data_pool.end() ) {
|
|
||||||
PoolEntry<T>* entry = dynamic_cast< PoolEntry<T>* >( it->second );
|
|
||||||
if (entry != NULL ) {
|
|
||||||
if ( sizeOrPosition <= entry->length ) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
PoolEntryIF* DataPool::getRawData( uint32_t data_pool_id ) {
|
|
||||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
|
||||||
if ( it != this->data_pool.end() ) {
|
|
||||||
return it->second;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//uint8_t DataPool::getRawData( uint32_t data_pool_id, uint8_t* address, uint16_t* size, uint32_t maxSize ) {
|
|
||||||
// std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( data_pool_id );
|
|
||||||
// if ( it != this->data_pool.end() ) {
|
|
||||||
// if ( it->second->getByteSize() <= maxSize ) {
|
|
||||||
// *size = it->second->getByteSize();
|
|
||||||
// memcpy( address, it->second->getRawData(), *size );
|
|
||||||
// return DP_SUCCESSFUL;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// *size = 0;
|
|
||||||
// return DP_FAILURE;
|
|
||||||
//}
|
|
||||||
|
|
||||||
ReturnValue_t DataPool::freeDataPoolLock() {
|
|
||||||
ReturnValue_t status = mutex->unlockMutex();
|
|
||||||
if ( status != RETURN_OK ) {
|
|
||||||
sif::error << "DataPool::DataPool: unlock of mutex failed with error code: " << status << std::endl;
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t DataPool::lockDataPool() {
|
|
||||||
ReturnValue_t status = mutex->lockMutex(MutexIF::BLOCKING);
|
|
||||||
if ( status != RETURN_OK ) {
|
|
||||||
sif::error << "DataPool::DataPool: lock of mutex failed with error code: " << status << std::endl;
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataPool::print() {
|
|
||||||
sif::debug << "DataPool contains: " << std::endl;
|
|
||||||
std::map<uint32_t, PoolEntryIF*>::iterator dataPoolIt;
|
|
||||||
dataPoolIt = this->data_pool.begin();
|
|
||||||
while( dataPoolIt != this->data_pool.end() ) {
|
|
||||||
sif::debug << std::hex << dataPoolIt->first << std::dec << " |";
|
|
||||||
dataPoolIt->second->print();
|
|
||||||
dataPoolIt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template PoolEntry<uint8_t>* DataPool::getData<uint8_t>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<uint16_t>* DataPool::getData<uint16_t>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<uint32_t>* DataPool::getData<uint32_t>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<uint64_t>* DataPool::getData<uint64_t>(uint32_t data_pool_id,
|
|
||||||
uint8_t size);
|
|
||||||
template PoolEntry<int8_t>* DataPool::getData<int8_t>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<int16_t>* DataPool::getData<int16_t>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<int32_t>* DataPool::getData<int32_t>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<float>* DataPool::getData<float>( uint32_t data_pool_id, uint8_t size );
|
|
||||||
template PoolEntry<double>* DataPool::getData<double>(uint32_t data_pool_id,
|
|
||||||
uint8_t size);
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t DataPool::PIDToDataPoolId(uint32_t parameter_id) {
|
|
||||||
return (parameter_id >> 8) & 0x00FFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t DataPool::PIDToArrayIndex(uint32_t parameter_id) {
|
|
||||||
return (parameter_id & 0x000000FF);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t DataPool::poolIdAndPositionToPid(uint32_t poolId, uint8_t index) {
|
|
||||||
return (poolId << 8) + index;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//SHOULDDO: Do we need a mutex lock here... I don't think so, as we only check static const values of elements in a list that do not change.
|
|
||||||
//there is no guarantee in the standard, but it seems to me that the implementation is safe -UM
|
|
||||||
ReturnValue_t DataPool::getType(uint32_t parameter_id, Type* type) {
|
|
||||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( PIDToDataPoolId(parameter_id));
|
|
||||||
if ( it != this->data_pool.end() ) {
|
|
||||||
*type = it->second->getType();
|
|
||||||
return RETURN_OK;
|
|
||||||
} else {
|
|
||||||
*type = Type::UNKNOWN_TYPE;
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataPool::exists(uint32_t parameterId) {
|
|
||||||
uint32_t poolId = PIDToDataPoolId(parameterId);
|
|
||||||
uint32_t index = PIDToArrayIndex(parameterId);
|
|
||||||
std::map<uint32_t, PoolEntryIF*>::iterator it = this->data_pool.find( poolId );
|
|
||||||
if (it != data_pool.end()) {
|
|
||||||
if (it->second->getSize() >= index) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
@ -1,135 +0,0 @@
|
|||||||
/**
|
|
||||||
* \file DataPool.h
|
|
||||||
*
|
|
||||||
* \date 10/17/2012
|
|
||||||
* \author Bastian Baetz
|
|
||||||
*
|
|
||||||
* \brief This file contains the definition of the DataPool class and (temporarily)
|
|
||||||
* the "extern" definition of the global dataPool instance.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DATAPOOL_H_
|
|
||||||
#define DATAPOOL_H_
|
|
||||||
|
|
||||||
#include "PoolEntry.h"
|
|
||||||
#include "../globalfunctions/Type.h"
|
|
||||||
#include "../ipc/MutexIF.h"
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup data_pool Data Pool
|
|
||||||
* This is the group, where all classes associated with Data Pool Handling belong to.
|
|
||||||
* This includes classes to access Data Pool variables.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define DP_SUCCESSFUL 0
|
|
||||||
#define DP_FAILURE 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This class represents the OBSW global data-pool.
|
|
||||||
*
|
|
||||||
* \details All variables are registered and space is allocated in an initialization
|
|
||||||
* function, which is passed do the constructor.
|
|
||||||
* Space for the variables is allocated on the heap (with a new call).
|
|
||||||
* The data is found by a data pool id, which uniquely represents a variable.
|
|
||||||
* Data pool variables should be used with a blackboard logic in mind,
|
|
||||||
* which means read data is valid (if flagged so), but not necessarily up-to-date.
|
|
||||||
* Variables are either single values or arrays.
|
|
||||||
* \ingroup data_pool
|
|
||||||
*/
|
|
||||||
class DataPool : public HasReturnvaluesIF {
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* \brief This is the actual data pool itself.
|
|
||||||
* \details It is represented by a map
|
|
||||||
* with the data pool id as index and a pointer to a single PoolEntry as value.
|
|
||||||
*/
|
|
||||||
std::map<uint32_t, PoolEntryIF*> data_pool;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* \brief The mutex is created in the constructor and makes access mutual exclusive.
|
|
||||||
* \details Locking and unlocking the pool is only done by the DataSet class.
|
|
||||||
*/
|
|
||||||
MutexIF* mutex;
|
|
||||||
/**
|
|
||||||
* \brief In the classes constructor, the passed initialization function is called.
|
|
||||||
* \details To enable filling the pool,
|
|
||||||
* a pointer to the map is passed, allowing direct access to the pool's content.
|
|
||||||
* On runtime, adding or removing variables is forbidden.
|
|
||||||
*/
|
|
||||||
DataPool( void ( *initFunction )( std::map<uint32_t, PoolEntryIF*>* pool_map ) );
|
|
||||||
/**
|
|
||||||
* \brief The destructor iterates through the data_pool map and calls all Entries destructors to clean up the heap.
|
|
||||||
*/
|
|
||||||
~DataPool();
|
|
||||||
/**
|
|
||||||
* \brief This is the default call to access the pool.
|
|
||||||
* \details A pointer to the PoolEntry object is returned.
|
|
||||||
* The call checks data pool id, type and array size. Returns NULL in case of failure.
|
|
||||||
* \param data_pool_id The data pool id to search.
|
|
||||||
* \param sizeOrPosition The array size (not byte size!) of the pool entry, or the position the user wants to read.
|
|
||||||
* If smaller than the entry size, everything's ok.
|
|
||||||
*/
|
|
||||||
template <typename T> PoolEntry<T>* getData( uint32_t data_pool_id, uint8_t sizeOrPosition );
|
|
||||||
/**
|
|
||||||
* \brief An alternative call to get a data pool entry in case the type is not implicitly known
|
|
||||||
* (i.e. in Housekeeping Telemetry).
|
|
||||||
* \details It returns a basic interface and does NOT perform
|
|
||||||
* a size check. The caller has to assure he does not copy too much data.
|
|
||||||
* Returns NULL in case the entry is not found.
|
|
||||||
* \param data_pool_id The data pool id to search.
|
|
||||||
*/
|
|
||||||
PoolEntryIF* getRawData( uint32_t data_pool_id );
|
|
||||||
/**
|
|
||||||
* \brief This is a small helper function to facilitate locking the global data pool.
|
|
||||||
* \details It fetches the pool's mutex id and tries to acquire the mutex.
|
|
||||||
*/
|
|
||||||
ReturnValue_t lockDataPool();
|
|
||||||
/**
|
|
||||||
* \brief This is a small helper function to facilitate unlocking the global data pool.
|
|
||||||
* \details It fetches the pool's mutex id and tries to free the mutex.
|
|
||||||
*/
|
|
||||||
ReturnValue_t freeDataPoolLock();
|
|
||||||
/**
|
|
||||||
* \brief The print call is a simple debug method.
|
|
||||||
* \details It prints the current content of the data pool.
|
|
||||||
* It iterates through the data_pool map and calls each entry's print() method.
|
|
||||||
*/
|
|
||||||
void print();
|
|
||||||
/**
|
|
||||||
* Extracts the data pool id from a SCOS 2000 PID.
|
|
||||||
* @param parameter_id The passed Parameter ID.
|
|
||||||
* @return The data pool id as used within the OBSW.
|
|
||||||
*/
|
|
||||||
static uint32_t PIDToDataPoolId( uint32_t parameter_id );
|
|
||||||
/**
|
|
||||||
* Extracts an array index out of a SCOS 2000 PID.
|
|
||||||
* @param parameter_id The passed Parameter ID.
|
|
||||||
* @return The index of the corresponding data pool entry.
|
|
||||||
*/
|
|
||||||
static uint8_t PIDToArrayIndex( uint32_t parameter_id );
|
|
||||||
/**
|
|
||||||
* Retransforms a data pool id and an array index to a SCOS 2000 PID.
|
|
||||||
*/
|
|
||||||
static uint32_t poolIdAndPositionToPid( uint32_t poolId, uint8_t index );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to return the type of a pool variable.
|
|
||||||
* @param parameter_id A parameterID (not pool id) of a DP member.
|
|
||||||
* @param type Returns the type or TYPE::UNKNOWN_TYPE
|
|
||||||
* @return RETURN_OK if parameter exists, RETURN_FAILED else.
|
|
||||||
*/
|
|
||||||
ReturnValue_t getType( uint32_t parameter_id, Type* type );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to check if a PID exists.
|
|
||||||
* Does not lock, as there's no possibility to alter the list that is checked during run-time.
|
|
||||||
* @param parameterId The PID (not pool id!) of a parameter.
|
|
||||||
* @return true if exists, false else.
|
|
||||||
*/
|
|
||||||
bool exists(uint32_t parameterId);
|
|
||||||
};
|
|
||||||
|
|
||||||
//We assume someone globally instantiates a DataPool.
|
|
||||||
extern DataPool dataPool;
|
|
||||||
#endif /* DATAPOOL_H_ */
|
|
@ -1,150 +0,0 @@
|
|||||||
#include "DataSet.h"
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
|
|
||||||
DataSet::DataSet() :
|
|
||||||
fill_count(0), state(DATA_SET_UNINITIALISED) {
|
|
||||||
for (unsigned count = 0; count < DATA_SET_MAX_SIZE; count++) {
|
|
||||||
registeredVariables[count] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataSet::~DataSet() {
|
|
||||||
//Don't do anything with your variables, they are dead already! (Destructor is already called)
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t DataSet::read() {
|
|
||||||
ReturnValue_t result = RETURN_OK;
|
|
||||||
if (state == DATA_SET_UNINITIALISED) {
|
|
||||||
lockDataPool();
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
if (registeredVariables[count]->getReadWriteMode()
|
|
||||||
!= PoolVariableIF::VAR_WRITE
|
|
||||||
&& registeredVariables[count]->getDataPoolId()
|
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
|
||||||
ReturnValue_t status = registeredVariables[count]->read();
|
|
||||||
if (status != RETURN_OK) {
|
|
||||||
result = INVALID_PARAMETER_DEFINITION;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state = DATA_SET_WAS_READ;
|
|
||||||
freeDataPoolLock();
|
|
||||||
} else {
|
|
||||||
sif::error << "DataSet::read(): Call made in wrong position." << std::endl;
|
|
||||||
result = SET_WAS_ALREADY_READ;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t DataSet::commit(uint8_t valid) {
|
|
||||||
setValid(valid);
|
|
||||||
return commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t DataSet::commit() {
|
|
||||||
if (state == DATA_SET_WAS_READ) {
|
|
||||||
lockDataPool();
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
if (registeredVariables[count]->getReadWriteMode()
|
|
||||||
!= PoolVariableIF::VAR_READ
|
|
||||||
&& registeredVariables[count]->getDataPoolId()
|
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
|
||||||
registeredVariables[count]->commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state = DATA_SET_UNINITIALISED;
|
|
||||||
freeDataPoolLock();
|
|
||||||
return RETURN_OK;
|
|
||||||
} else {
|
|
||||||
ReturnValue_t result = RETURN_OK;
|
|
||||||
lockDataPool();
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
if (registeredVariables[count]->getReadWriteMode()
|
|
||||||
== PoolVariableIF::VAR_WRITE
|
|
||||||
&& registeredVariables[count]->getDataPoolId()
|
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
|
||||||
registeredVariables[count]->commit();
|
|
||||||
} else if (registeredVariables[count]->getDataPoolId()
|
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
|
||||||
if (result != COMMITING_WITHOUT_READING) {
|
|
||||||
sif::error <<
|
|
||||||
"DataSet::commit(): commit-without-read "
|
|
||||||
"call made with non write-only variable." << std::endl;
|
|
||||||
result = COMMITING_WITHOUT_READING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state = DATA_SET_UNINITIALISED;
|
|
||||||
freeDataPoolLock();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataSet::registerVariable(PoolVariableIF* variable) {
|
|
||||||
if (state == DATA_SET_UNINITIALISED) {
|
|
||||||
if (variable != NULL) {
|
|
||||||
if (fill_count < DATA_SET_MAX_SIZE) {
|
|
||||||
registeredVariables[fill_count] = variable;
|
|
||||||
fill_count++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sif::error
|
|
||||||
<< "DataSet::registerVariable: failed. Either NULL, or set is full, or call made in wrong position."
|
|
||||||
<< std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t DataSet::freeDataPoolLock() {
|
|
||||||
return ::dataPool.freeDataPoolLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t DataSet::lockDataPool() {
|
|
||||||
return ::dataPool.lockDataPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t DataSet::serialize(uint8_t** buffer, size_t* size,
|
|
||||||
size_t maxSize, Endianness streamEndianness) const {
|
|
||||||
ReturnValue_t result = RETURN_FAILED;
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
|
||||||
streamEndianness);
|
|
||||||
if (result != RETURN_OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t DataSet::getSerializedSize() const {
|
|
||||||
size_t size = 0;
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
size += registeredVariables[count]->getSerializedSize();
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataSet::setValid(uint8_t valid) {
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
if (registeredVariables[count]->getReadWriteMode()
|
|
||||||
!= PoolVariableIF::VAR_READ) {
|
|
||||||
registeredVariables[count]->setValid(valid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, size_t* size,
|
|
||||||
Endianness streamEndianness) {
|
|
||||||
ReturnValue_t result = RETURN_FAILED;
|
|
||||||
for (uint16_t count = 0; count < fill_count; count++) {
|
|
||||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
|
||||||
streamEndianness);
|
|
||||||
if (result != RETURN_OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* \file DataSet.h
|
|
||||||
*
|
|
||||||
* \brief This file contains the DataSet class and a small structure called DataSetContent.
|
|
||||||
*
|
|
||||||
* \date 10/17/2012
|
|
||||||
*
|
|
||||||
* \author Bastian Baetz
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DATASET_H_
|
|
||||||
#define DATASET_H_
|
|
||||||
|
|
||||||
#include "DataPool.h"
|
|
||||||
#include "DataSetIF.h"
|
|
||||||
#include "PoolRawAccess.h"
|
|
||||||
#include "PoolVariable.h"
|
|
||||||
#include "PoolVarList.h"
|
|
||||||
#include "PoolVector.h"
|
|
||||||
#include "../serialize/SerializeAdapter.h"
|
|
||||||
/**
|
|
||||||
* \brief The DataSet class manages a set of locally checked out variables.
|
|
||||||
*
|
|
||||||
* \details This class manages a list, where a set of local variables (or pool variables) are
|
|
||||||
* registered. They are checked-out (i.e. their values are looked up and copied)
|
|
||||||
* with the read call. After the user finishes working with the pool variables,
|
|
||||||
* he can write back all variable values to the pool with the commit call.
|
|
||||||
* The data set manages locking and freeing the data pool, to ensure that all values
|
|
||||||
* are read and written back at once.
|
|
||||||
* An internal state manages usage of this class. Variables may only be registered before
|
|
||||||
* the read call is made, and the commit call only after the read call.
|
|
||||||
* If pool variables are writable and not committed until destruction of the set, the
|
|
||||||
* DataSet class automatically sets the valid flag in the data pool to invalid (without)
|
|
||||||
* changing the variable's value.
|
|
||||||
*
|
|
||||||
* \ingroup data_pool
|
|
||||||
*/
|
|
||||||
class DataSet: public DataSetIF, public HasReturnvaluesIF, public SerializeIF {
|
|
||||||
private:
|
|
||||||
//SHOULDDO we could use a linked list of datapool variables
|
|
||||||
static const uint8_t DATA_SET_MAX_SIZE = 63; //!< This definition sets the maximum number of variables to register in one DataSet.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This array represents all pool variables registered in this set.
|
|
||||||
* \details It has a maximum size of DATA_SET_MAX_SIZE.
|
|
||||||
*/
|
|
||||||
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
|
|
||||||
/**
|
|
||||||
* \brief The fill_count attribute ensures that the variables register in the correct array
|
|
||||||
* position and that the maximum number of variables is not exceeded.
|
|
||||||
*/
|
|
||||||
uint16_t fill_count;
|
|
||||||
/**
|
|
||||||
* States of the seet.
|
|
||||||
*/
|
|
||||||
enum States {
|
|
||||||
DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
|
||||||
DATA_SET_WAS_READ //!< DATA_SET_WAS_READ
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* \brief state manages the internal state of the data set, which is important e.g. for the
|
|
||||||
* behavior on destruction.
|
|
||||||
*/
|
|
||||||
States state;
|
|
||||||
/**
|
|
||||||
* \brief This is a small helper function to facilitate locking the global data pool.
|
|
||||||
* \details It makes use of the lockDataPool method offered by the DataPool class.
|
|
||||||
*/
|
|
||||||
uint8_t lockDataPool();
|
|
||||||
/**
|
|
||||||
* \brief This is a small helper function to facilitate unlocking the global data pool.
|
|
||||||
* \details It makes use of the freeDataPoolLock method offered by the DataPool class.
|
|
||||||
*/
|
|
||||||
uint8_t freeDataPoolLock();
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS;
|
|
||||||
static const ReturnValue_t INVALID_PARAMETER_DEFINITION =
|
|
||||||
MAKE_RETURN_CODE( 0x01 );
|
|
||||||
static const ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE( 0x02 );
|
|
||||||
static const ReturnValue_t COMMITING_WITHOUT_READING =
|
|
||||||
MAKE_RETURN_CODE(0x03);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The constructor simply sets the fill_count to zero and sets the state to "uninitialized".
|
|
||||||
*/
|
|
||||||
DataSet();
|
|
||||||
/**
|
|
||||||
* \brief The destructor automatically manages writing the valid information of variables.
|
|
||||||
* \details In case the data set was read out, but not committed (indicated by state),
|
|
||||||
* the destructor parses all variables that are still registered to the set.
|
|
||||||
* For each, the valid flag in the data pool is set to "invalid".
|
|
||||||
*/
|
|
||||||
~DataSet();
|
|
||||||
/**
|
|
||||||
* \brief The read call initializes reading out all registered variables.
|
|
||||||
* \details It iterates through the list of registered variables and calls all read()
|
|
||||||
* functions of the registered pool variables (which read out their values from the
|
|
||||||
* data pool) which are not write-only. In case of an error (e.g. a wrong data type,
|
|
||||||
* or an invalid data pool id), the operation is aborted and
|
|
||||||
* \c INVALID_PARAMETER_DEFINITION returned.
|
|
||||||
* The data pool is locked during the whole read operation and freed afterwards.
|
|
||||||
* The state changes to "was written" after this operation.
|
|
||||||
* \return - \c RETURN_OK if all variables were read successfully.
|
|
||||||
* - \c INVALID_PARAMETER_DEFINITION if PID, size or type of the
|
|
||||||
* requested variable is invalid.
|
|
||||||
* - \c SET_WAS_ALREADY_READ if read() is called twice without calling
|
|
||||||
* commit() in between
|
|
||||||
*/
|
|
||||||
ReturnValue_t read();
|
|
||||||
/**
|
|
||||||
* \brief The commit call initializes writing back the registered variables.
|
|
||||||
* \details It iterates through the list of registered variables and calls
|
|
||||||
* the commit() method of the remaining registered variables (which write back
|
|
||||||
* their values to the pool).
|
|
||||||
* The data pool is locked during the whole commit operation and freed afterwards.
|
|
||||||
* The state changes to "was committed" after this operation.
|
|
||||||
* If the set does contain at least one variable which is not write-only commit()
|
|
||||||
* can only be called after read(). If the set only contains variables which are
|
|
||||||
* write only, commit() can be called without a preceding read() call.
|
|
||||||
* \return - \c RETURN_OK if all variables were read successfully.
|
|
||||||
* - \c COMMITING_WITHOUT_READING if set was not read yet and contains non write-only
|
|
||||||
* variables
|
|
||||||
*/
|
|
||||||
ReturnValue_t commit(void);
|
|
||||||
/**
|
|
||||||
* Variant of method above which sets validity of all elements of the set.
|
|
||||||
* @param valid Validity information from PoolVariableIF.
|
|
||||||
* \return - \c RETURN_OK if all variables were read successfully.
|
|
||||||
* - \c COMMITING_WITHOUT_READING if set was not read yet and contains non write-only
|
|
||||||
* variables
|
|
||||||
*/
|
|
||||||
ReturnValue_t commit(uint8_t valid);
|
|
||||||
/**
|
|
||||||
* \brief This operation is used to register the local variables in the set.
|
|
||||||
* \details It copies all required information to the currently
|
|
||||||
* free space in the registeredVariables list.
|
|
||||||
*/
|
|
||||||
void registerVariable(PoolVariableIF* variable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the valid information of all variables contained in the set which are not readonly
|
|
||||||
*
|
|
||||||
* @param valid Validity information from PoolVariableIF.
|
|
||||||
*/
|
|
||||||
void setValid(uint8_t valid);
|
|
||||||
|
|
||||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
||||||
size_t maxSize, Endianness streamEndianness) const override;
|
|
||||||
|
|
||||||
size_t getSerializedSize() const override;
|
|
||||||
|
|
||||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
||||||
Endianness streamEndianness) override;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* DATASET_H_ */
|
|
@ -1,39 +1,47 @@
|
|||||||
/**
|
#ifndef FSFW_DATAPOOL_DATASETIF_H_
|
||||||
* \file DataSetIF.h
|
#define FSFW_DATAPOOL_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 "../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "../timemanager/Clock.h"
|
||||||
class PoolVariableIF;
|
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
|
* @details
|
||||||
* checked-out variables to register on a data set. Still, it may become useful for
|
* Currently, the only purpose of this interface is to provide a
|
||||||
* other purposes as well.
|
* 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
|
* @author Bastian Baetz
|
||||||
|
* @ingroup data_pool
|
||||||
*/
|
*/
|
||||||
class DataSetIF {
|
class DataSetIF {
|
||||||
public:
|
public:
|
||||||
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS;
|
||||||
|
static constexpr ReturnValue_t INVALID_PARAMETER_DEFINITION =
|
||||||
|
MAKE_RETURN_CODE( 0x01 );
|
||||||
|
static constexpr ReturnValue_t SET_WAS_ALREADY_READ = MAKE_RETURN_CODE( 0x02 );
|
||||||
|
static constexpr ReturnValue_t COMMITING_WITHOUT_READING =
|
||||||
|
MAKE_RETURN_CODE(0x03);
|
||||||
|
|
||||||
|
static constexpr ReturnValue_t DATA_SET_UNINITIALISED = MAKE_RETURN_CODE( 0x04 );
|
||||||
|
static constexpr ReturnValue_t DATA_SET_FULL = MAKE_RETURN_CODE( 0x05 );
|
||||||
|
static constexpr ReturnValue_t POOL_VAR_NULL = MAKE_RETURN_CODE( 0x06 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This is an empty virtual destructor, as it is proposed for C++ interfaces.
|
* @brief This is an empty virtual destructor,
|
||||||
|
* as it is proposed for C++ interfaces.
|
||||||
*/
|
*/
|
||||||
virtual ~DataSetIF() {}
|
virtual ~DataSetIF() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This operation provides a method to register local data pool variables
|
* @brief This operation provides a method to register local data pool
|
||||||
* to register in a data set by passing itself to this DataSet operation.
|
* variables to register in a data set by passing itself
|
||||||
|
* to this DataSet operation.
|
||||||
*/
|
*/
|
||||||
virtual void registerVariable( PoolVariableIF* variable ) = 0;
|
virtual ReturnValue_t registerVariable(PoolVariableIF* variable) = 0;
|
||||||
|
|
||||||
|
virtual uint16_t getFillCount() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DATASETIF_H_ */
|
#endif /* FSFW_DATAPOOL_DATASETIF_H_ */
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "HkSwitchHelper.h"
|
#include "../datapool/HkSwitchHelper.h"
|
||||||
//#include <mission/tmtcservices/HKService_03.h>
|
|
||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
|
|
||||||
HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) :
|
HkSwitchHelper::HkSwitchHelper(EventReportingProxyIF* eventProxy) :
|
||||||
@ -22,14 +21,14 @@ ReturnValue_t HkSwitchHelper::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) {
|
ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) {
|
||||||
CommandMessage message;
|
CommandMessage command;
|
||||||
while (actionQueue->receiveMessage(&message) == HasReturnvaluesIF::RETURN_OK) {
|
while (actionQueue->receiveMessage(&command) == HasReturnvaluesIF::RETURN_OK) {
|
||||||
ReturnValue_t result = commandActionHelper.handleReply(&message);
|
ReturnValue_t result = commandActionHelper.handleReply(&command);
|
||||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
message.setToUnknownCommand();
|
command.setToUnknownCommand();
|
||||||
actionQueue->reply(&message);
|
actionQueue->reply(&command);
|
||||||
}
|
}
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
@ -13,7 +13,7 @@ class HkSwitchHelper: public ExecutableObjectIF, public CommandsActionsIF {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HK;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HK;
|
||||||
static const Event SWITCHING_TM_FAILED = MAKE_EVENT(1, SEVERITY::LOW); //!< Commanding the HK Service failed, p1: error code, p2 action: 0 disable / 1 enable
|
static const Event SWITCHING_TM_FAILED = MAKE_EVENT(1, severity::LOW); //!< Commanding the HK Service failed, p1: error code, p2 action: 0 disable / 1 enable
|
||||||
|
|
||||||
HkSwitchHelper(EventReportingProxyIF *eventProxy);
|
HkSwitchHelper(EventReportingProxyIF *eventProxy);
|
||||||
virtual ~HkSwitchHelper();
|
virtual ~HkSwitchHelper();
|
||||||
|
169
datapool/PoolDataSetBase.cpp
Normal file
169
datapool/PoolDataSetBase.cpp
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
#include "PoolDataSetBase.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||||
|
const size_t maxFillCount):
|
||||||
|
registeredVariables(registeredVariablesArray),
|
||||||
|
maxFillCount(maxFillCount) {
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolDataSetBase::~PoolDataSetBase() {}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::registerVariable(
|
||||||
|
PoolVariableIF *variable) {
|
||||||
|
if (state != States::DATA_SET_UNINITIALISED) {
|
||||||
|
sif::error << "DataSet::registerVariable: "
|
||||||
|
"Call made in wrong position." << std::endl;
|
||||||
|
return DataSetIF::DATA_SET_UNINITIALISED;
|
||||||
|
}
|
||||||
|
if (variable == nullptr) {
|
||||||
|
sif::error << "DataSet::registerVariable: "
|
||||||
|
"Pool variable is nullptr." << std::endl;
|
||||||
|
return DataSetIF::POOL_VAR_NULL;
|
||||||
|
}
|
||||||
|
if (fillCount >= maxFillCount) {
|
||||||
|
sif::error << "DataSet::registerVariable: "
|
||||||
|
"DataSet is full." << std::endl;
|
||||||
|
return DataSetIF::DATA_SET_FULL;
|
||||||
|
}
|
||||||
|
registeredVariables[fillCount] = variable;
|
||||||
|
fillCount++;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::read(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
if (state == States::DATA_SET_UNINITIALISED) {
|
||||||
|
lockDataPool(lockTimeout);
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
result = readVariable(count);
|
||||||
|
if(result != RETURN_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = States::DATA_SET_WAS_READ;
|
||||||
|
unlockDataPool();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::error << "DataSet::read(): "
|
||||||
|
"Call made in wrong position. Don't forget to commit"
|
||||||
|
" member datasets!" << std::endl;
|
||||||
|
result = SET_WAS_ALREADY_READ;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t PoolDataSetBase::getFillCount() const {
|
||||||
|
return fillCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::readVariable(uint16_t count) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
// These checks are often performed by the respective
|
||||||
|
// variable implementation too, but I guess a double check does not hurt.
|
||||||
|
if (registeredVariables[count]->getReadWriteMode() !=
|
||||||
|
PoolVariableIF::VAR_WRITE and
|
||||||
|
registeredVariables[count]->getDataPoolId()
|
||||||
|
!= PoolVariableIF::NO_PARAMETER)
|
||||||
|
{
|
||||||
|
result = registeredVariables[count]->readWithoutLock();
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
result = INVALID_PARAMETER_DEFINITION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::commit(uint32_t lockTimeout) {
|
||||||
|
if (state == States::DATA_SET_WAS_READ) {
|
||||||
|
handleAlreadyReadDatasetCommit(lockTimeout);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return handleUnreadDatasetCommit(lockTimeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoolDataSetBase::handleAlreadyReadDatasetCommit(uint32_t lockTimeout) {
|
||||||
|
lockDataPool(lockTimeout);
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
if (registeredVariables[count]->getReadWriteMode()
|
||||||
|
!= PoolVariableIF::VAR_READ
|
||||||
|
&& registeredVariables[count]->getDataPoolId()
|
||||||
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
|
registeredVariables[count]->commitWithoutLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = States::DATA_SET_UNINITIALISED;
|
||||||
|
unlockDataPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::handleUnreadDatasetCommit(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
lockDataPool(lockTimeout);
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
if (registeredVariables[count]->getReadWriteMode()
|
||||||
|
== PoolVariableIF::VAR_WRITE
|
||||||
|
&& registeredVariables[count]->getDataPoolId()
|
||||||
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
|
registeredVariables[count]->commitWithoutLock();
|
||||||
|
} else if (registeredVariables[count]->getDataPoolId()
|
||||||
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
|
if (result != COMMITING_WITHOUT_READING) {
|
||||||
|
sif::error << "DataSet::commit(): commit-without-read call made "
|
||||||
|
"with non write-only variable." << std::endl;
|
||||||
|
result = COMMITING_WITHOUT_READING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = States::DATA_SET_UNINITIALISED;
|
||||||
|
unlockDataPool();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::lockDataPool(uint32_t timeoutMs) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::unlockDataPool() {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::serialize(uint8_t** buffer, size_t* size,
|
||||||
|
const size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||||
|
streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolDataSetBase::deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||||
|
streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PoolDataSetBase::getSerializedSize() const {
|
||||||
|
uint32_t size = 0;
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
size += registeredVariables[count]->getSerializedSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
|
||||||
|
this->registeredVariables = variablesContainer;
|
||||||
|
}
|
152
datapool/PoolDataSetBase.h
Normal file
152
datapool/PoolDataSetBase.h
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
#ifndef FSFW_DATAPOOL_POOLDATASETBASE_H_
|
||||||
|
#define FSFW_DATAPOOL_POOLDATASETBASE_H_
|
||||||
|
|
||||||
|
#include "PoolDataSetIF.h"
|
||||||
|
#include "PoolVariableIF.h"
|
||||||
|
#include "../ipc/MutexIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The DataSetBase class manages a set of locally checked out variables.
|
||||||
|
* @details
|
||||||
|
* This class manages a list, where a set of local variables (or pool variables)
|
||||||
|
* are registered. They are checked-out (i.e. their values are looked
|
||||||
|
* up and copied) with the read call. After the user finishes working with the
|
||||||
|
* pool variables, he can write back all variable values to the pool with
|
||||||
|
* the commit call. The data set manages locking and freeing the data pool,
|
||||||
|
* to ensure that all values are read and written back at once.
|
||||||
|
*
|
||||||
|
* An internal state manages usage of this class. Variables may only be
|
||||||
|
* registered before the read call is made, and the commit call only
|
||||||
|
* after the read call.
|
||||||
|
*
|
||||||
|
* If pool variables are writable and not committed until destruction
|
||||||
|
* of the set, the DataSet class automatically sets the valid flag in the
|
||||||
|
* data pool to invalid (without) changing the variable's value.
|
||||||
|
*
|
||||||
|
* The base class lockDataPool und unlockDataPool implementation are empty
|
||||||
|
* and should be implemented to protect the underlying pool type.
|
||||||
|
* @author Bastian Baetz
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
class PoolDataSetBase: public PoolDataSetIF,
|
||||||
|
public SerializeIF,
|
||||||
|
public HasReturnvaluesIF {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates an empty dataset. Use registerVariable or
|
||||||
|
* supply a pointer to this dataset to PoolVariable
|
||||||
|
* initializations to register pool variables.
|
||||||
|
*/
|
||||||
|
PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||||
|
const size_t maxFillCount);
|
||||||
|
virtual~ PoolDataSetBase();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The read call initializes reading out all registered variables.
|
||||||
|
* @details
|
||||||
|
* It iterates through the list of registered variables and calls all read()
|
||||||
|
* functions of the registered pool variables (which read out their values
|
||||||
|
* from the data pool) which are not write-only.
|
||||||
|
* In case of an error (e.g. a wrong data type, or an invalid data pool id),
|
||||||
|
* the operation is aborted and @c INVALID_PARAMETER_DEFINITION returned.
|
||||||
|
*
|
||||||
|
* The data pool is locked during the whole read operation and
|
||||||
|
* freed afterwards.The state changes to "was written" after this operation.
|
||||||
|
* @return
|
||||||
|
* - @c RETURN_OK if all variables were read successfully.
|
||||||
|
* - @c INVALID_PARAMETER_DEFINITION if PID, size or type of the
|
||||||
|
* requested variable is invalid.
|
||||||
|
* - @c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||||
|
* commit() in between
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t read(uint32_t lockTimeout =
|
||||||
|
MutexIF::BLOCKING) override;
|
||||||
|
/**
|
||||||
|
* @brief The commit call initializes writing back the registered variables.
|
||||||
|
* @details
|
||||||
|
* It iterates through the list of registered variables and calls the
|
||||||
|
* commit() method of the remaining registered variables (which write back
|
||||||
|
* their values to the pool).
|
||||||
|
*
|
||||||
|
* The data pool is locked during the whole commit operation and
|
||||||
|
* freed afterwards. The state changes to "was committed" after this operation.
|
||||||
|
*
|
||||||
|
* If the set does contain at least one variable which is not write-only
|
||||||
|
* commit() can only be called after read(). If the set only contains
|
||||||
|
* variables which are write only, commit() can be called without a
|
||||||
|
* preceding read() call.
|
||||||
|
* @return - @c RETURN_OK if all variables were read successfully.
|
||||||
|
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||||
|
* contains non write-only variables
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t commit(uint32_t lockTimeout =
|
||||||
|
MutexIF::BLOCKING) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the passed pool variable instance into the data set.
|
||||||
|
* @param variable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t registerVariable( PoolVariableIF* variable) override;
|
||||||
|
/**
|
||||||
|
* Provides the means to lock the underlying data structure to ensure
|
||||||
|
* thread-safety. Default implementation is empty
|
||||||
|
* @return Always returns -@c RETURN_OK
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t lockDataPool(uint32_t timeoutMs =
|
||||||
|
MutexIF::BLOCKING) override;
|
||||||
|
/**
|
||||||
|
* Provides the means to unlock the underlying data structure to ensure
|
||||||
|
* thread-safety. Default implementation is empty
|
||||||
|
* @return Always returns -@c RETURN_OK
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t unlockDataPool() override;
|
||||||
|
|
||||||
|
virtual uint16_t getFillCount() const;
|
||||||
|
|
||||||
|
/* SerializeIF implementations */
|
||||||
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
|
const size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness) const override;
|
||||||
|
virtual size_t getSerializedSize() const override;
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief The fill_count attribute ensures that the variables
|
||||||
|
* register in the correct array position and that the maximum
|
||||||
|
* number of variables is not exceeded.
|
||||||
|
*/
|
||||||
|
uint16_t fillCount = 0;
|
||||||
|
/**
|
||||||
|
* States of the seet.
|
||||||
|
*/
|
||||||
|
enum class States {
|
||||||
|
DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||||
|
DATA_SET_WAS_READ //!< DATA_SET_WAS_READ
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief state manages the internal state of the data set,
|
||||||
|
* which is important e.g. for the behavior on destruction.
|
||||||
|
*/
|
||||||
|
States state = States::DATA_SET_UNINITIALISED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This array represents all pool variables registered in this set.
|
||||||
|
* Child classes can use a static or dynamic container to create
|
||||||
|
* an array of registered variables and assign the first entry here.
|
||||||
|
*/
|
||||||
|
PoolVariableIF** registeredVariables = nullptr;
|
||||||
|
const size_t maxFillCount = 0;
|
||||||
|
|
||||||
|
void setContainer(PoolVariableIF** variablesContainer);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ReturnValue_t readVariable(uint16_t count);
|
||||||
|
void handleAlreadyReadDatasetCommit(uint32_t lockTimeout);
|
||||||
|
ReturnValue_t handleUnreadDatasetCommit(uint32_t lockTimeout);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOL_POOLDATASETBASE_H_ */
|
33
datapool/PoolDataSetIF.h
Normal file
33
datapool/PoolDataSetIF.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef FSFW_DATAPOOL_POOLDATASETIF_H_
|
||||||
|
#define FSFW_DATAPOOL_POOLDATASETIF_H_
|
||||||
|
|
||||||
|
#include "DataSetIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Extendes the DataSetIF by adding abstract functions to lock
|
||||||
|
* and unlock a data pool and read/commit semantics.
|
||||||
|
*/
|
||||||
|
class PoolDataSetIF: public DataSetIF {
|
||||||
|
public:
|
||||||
|
virtual~ PoolDataSetIF() {};
|
||||||
|
|
||||||
|
virtual ReturnValue_t read(dur_millis_t lockTimeout) = 0;
|
||||||
|
virtual ReturnValue_t commit(dur_millis_t lockTimeout) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Most underlying data structures will have a pool like structure
|
||||||
|
* and will require a lock and unlock mechanism to ensure
|
||||||
|
* thread-safety
|
||||||
|
* @return Lock operation result
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t lockDataPool(dur_millis_t timeoutMs) = 0;
|
||||||
|
/**
|
||||||
|
* @brief Unlock call corresponding to the lock call.
|
||||||
|
* @return Unlock operation result
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t unlockDataPool() = 0;
|
||||||
|
|
||||||
|
virtual bool isValid() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOL_POOLDATASETIF_H_ */
|
@ -1,4 +1,5 @@
|
|||||||
#include "PoolEntry.h"
|
#include "PoolEntry.h"
|
||||||
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
#include "../globalfunctions/arrayprinter.h"
|
#include "../globalfunctions/arrayprinter.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FRAMEWORK_DATAPOOL_POOLENTRY_H_
|
#ifndef FSFW_DATAPOOL_POOLENTRY_H_
|
||||||
#define FRAMEWORK_DATAPOOL_POOLENTRY_H_
|
#define FSFW_DATAPOOL_POOLENTRY_H_
|
||||||
|
|
||||||
#include "PoolEntryIF.h"
|
#include "PoolEntryIF.h"
|
||||||
|
|
||||||
@ -127,4 +127,4 @@ public:
|
|||||||
Type getType();
|
Type getType();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* POOLENTRY_H_ */
|
#endif /* FSFW_DATAPOOL_POOLENTRY_H_ */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FRAMEWORK_DATAPOOL_POOLENTRYIF_H_
|
#ifndef FSFW_DATAPOOL_POOLENTRYIF_H_
|
||||||
#define FRAMEWORK_DATAPOOL_POOLENTRYIF_H_
|
#define FSFW_DATAPOOL_POOLENTRYIF_H_
|
||||||
|
|
||||||
#include "../globalfunctions/Type.h"
|
#include "../globalfunctions/Type.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -60,4 +60,4 @@ public:
|
|||||||
virtual Type getType() = 0;
|
virtual Type getType() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* POOLENTRYIF_H_ */
|
#endif /* FSFW_DATAPOOL_POOLENTRYIF_H_ */
|
||||||
|
@ -1,187 +0,0 @@
|
|||||||
#include "DataPool.h"
|
|
||||||
#include "PoolEntryIF.h"
|
|
||||||
#include "PoolRawAccess.h"
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
#include "../serialize/EndianConverter.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
|
||||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode) :
|
|
||||||
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(
|
|
||||||
Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0), readWriteMode(
|
|
||||||
setReadWriteMode) {
|
|
||||||
memset(value, 0, sizeof(value));
|
|
||||||
if (data_set != NULL) {
|
|
||||||
data_set->registerVariable(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PoolRawAccess::~PoolRawAccess() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t PoolRawAccess::read() {
|
|
||||||
PoolEntryIF *read_out = ::dataPool.getRawData(dataPoolId);
|
|
||||||
if (read_out != NULL) {
|
|
||||||
valid = read_out->getValid();
|
|
||||||
if (read_out->getSize() > arrayEntry) {
|
|
||||||
arraySize = read_out->getSize();
|
|
||||||
typeSize = read_out->getByteSize() / read_out->getSize();
|
|
||||||
type = read_out->getType();
|
|
||||||
if (typeSize <= sizeof(value)) {
|
|
||||||
uint16_t arrayPosition = arrayEntry * typeSize;
|
|
||||||
sizeTillEnd = read_out->getByteSize() - arrayPosition;
|
|
||||||
uint8_t *ptr =
|
|
||||||
&((uint8_t*) read_out->getRawData())[arrayPosition];
|
|
||||||
memcpy(value, ptr, typeSize);
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
//Error value type too large.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//Error index requested too large
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//Error entry does not exist.
|
|
||||||
}
|
|
||||||
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex
|
|
||||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
|
||||||
valid = INVALID;
|
|
||||||
typeSize = 0;
|
|
||||||
sizeTillEnd = 0;
|
|
||||||
memset(value, 0, sizeof(value));
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t PoolRawAccess::commit() {
|
|
||||||
PoolEntryIF *write_back = ::dataPool.getRawData(dataPoolId);
|
|
||||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
|
||||||
write_back->setValid(valid);
|
|
||||||
uint8_t array_position = arrayEntry * typeSize;
|
|
||||||
uint8_t *ptr = &((uint8_t*) write_back->getRawData())[array_position];
|
|
||||||
memcpy(ptr, value, typeSize);
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t* PoolRawAccess::getEntry() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t *buffer,
|
|
||||||
size_t *writtenBytes, size_t maxSize) {
|
|
||||||
uint8_t *data_ptr = getEntry();
|
|
||||||
// debug << "PoolRawAccess::getEntry: Array position: " << index * size_of_type << " Size of T: " << (int)size_of_type << " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
|
||||||
if (typeSize == 0) {
|
|
||||||
return DATA_POOL_ACCESS_FAILED;
|
|
||||||
}
|
|
||||||
if (typeSize > maxSize) {
|
|
||||||
return INCORRECT_SIZE;
|
|
||||||
}
|
|
||||||
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
|
||||||
*writtenBytes = typeSize;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type PoolRawAccess::getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t PoolRawAccess::getSizeOfType() {
|
|
||||||
return typeSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t PoolRawAccess::getArraySize() {
|
|
||||||
return arraySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t PoolRawAccess::getDataPoolId() const {
|
|
||||||
return dataPoolId;
|
|
||||||
}
|
|
||||||
|
|
||||||
PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
|
||||||
return readWriteMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
|
||||||
size_t setSize) {
|
|
||||||
if (typeSize == setSize) {
|
|
||||||
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
sif::error
|
|
||||||
<< "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: Internal"
|
|
||||||
<< (uint32_t) typeSize << ", Requested: " << setSize
|
|
||||||
<< std::endl;
|
|
||||||
return INCORRECT_SIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PoolRawAccess::isValid() const {
|
|
||||||
if (valid != INVALID)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PoolRawAccess::setValid(uint8_t valid) {
|
|
||||||
this->valid = valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t PoolRawAccess::getSizeTillEnd() const {
|
|
||||||
return sizeTillEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t PoolRawAccess::serialize(uint8_t **buffer, size_t *size,
|
|
||||||
size_t maxSize, Endianness streamEndianness) const {
|
|
||||||
if (typeSize + *size <= maxSize) {
|
|
||||||
switch (streamEndianness) {
|
|
||||||
case (Endianness::BIG):
|
|
||||||
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
|
||||||
break;
|
|
||||||
case (Endianness::LITTLE):
|
|
||||||
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case (Endianness::MACHINE):
|
|
||||||
memcpy(*buffer, value, typeSize);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*size += typeSize;
|
|
||||||
(*buffer) += typeSize;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
return SerializeIF::BUFFER_TOO_SHORT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t PoolRawAccess::getSerializedSize() const {
|
|
||||||
return typeSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
|
|
||||||
Endianness streamEndianness) {
|
|
||||||
|
|
||||||
if (*size >= typeSize) {
|
|
||||||
switch (streamEndianness) {
|
|
||||||
case (Endianness::BIG):
|
|
||||||
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
|
||||||
break;
|
|
||||||
case (Endianness::LITTLE):
|
|
||||||
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case (Endianness::MACHINE):
|
|
||||||
memcpy(value, *buffer, typeSize);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*size -= typeSize;
|
|
||||||
*buffer += typeSize;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
return SerializeIF::STREAM_TOO_SHORT;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,152 +0,0 @@
|
|||||||
#ifndef POOLRAWACCESS_H_
|
|
||||||
#define POOLRAWACCESS_H_
|
|
||||||
|
|
||||||
#include "DataSetIF.h"
|
|
||||||
#include "PoolVariableIF.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class allows accessing Data Pool variables as raw bytes.
|
|
||||||
* This is necessary to have an access method for HK data, as the PID's alone do not
|
|
||||||
* provide a type information.
|
|
||||||
* \ingroup data_pool
|
|
||||||
*/
|
|
||||||
class PoolRawAccess: public PoolVariableIF {
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
|
||||||
* is stored.
|
|
||||||
*/
|
|
||||||
uint32_t dataPoolId;
|
|
||||||
/**
|
|
||||||
* \brief The array entry that is fetched from the data pool.
|
|
||||||
*/
|
|
||||||
uint8_t arrayEntry;
|
|
||||||
/**
|
|
||||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
|
||||||
*/
|
|
||||||
uint8_t valid;
|
|
||||||
/**
|
|
||||||
* \brief This value contains the type of the data pool entry.
|
|
||||||
*/
|
|
||||||
Type type;
|
|
||||||
/**
|
|
||||||
* \brief This value contains the size of the data pool entry in bytes.
|
|
||||||
*/
|
|
||||||
size_t typeSize;
|
|
||||||
/**
|
|
||||||
* The size of the DP array (single values return 1)
|
|
||||||
*/
|
|
||||||
size_t arraySize;
|
|
||||||
/**
|
|
||||||
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
|
||||||
*/
|
|
||||||
size_t sizeTillEnd;
|
|
||||||
/**
|
|
||||||
* \brief The information whether the class is read-write or read-only is stored here.
|
|
||||||
*/
|
|
||||||
ReadWriteMode_t readWriteMode;
|
|
||||||
static const uint8_t RAW_MAX_SIZE = sizeof(double);
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* \brief This is a call to read the value from the global data pool.
|
|
||||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
|
||||||
* data pool id from the global data pool and copies the value and the valid
|
|
||||||
* information to its local attributes. In case of a failure (wrong type or
|
|
||||||
* pool id not found), the variable is set to zero and invalid.
|
|
||||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
||||||
*/
|
|
||||||
ReturnValue_t read();
|
|
||||||
/**
|
|
||||||
* \brief The commit call writes back the variable's value to the data pool.
|
|
||||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
|
||||||
* the value is copied and the valid flag is automatically set to "valid".
|
|
||||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ReturnValue_t commit();
|
|
||||||
public:
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS;
|
|
||||||
static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01);
|
|
||||||
static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02);
|
|
||||||
uint8_t value[RAW_MAX_SIZE];
|
|
||||||
PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry,
|
|
||||||
DataSetIF *data_set, ReadWriteMode_t setReadWriteMode =
|
|
||||||
PoolVariableIF::VAR_READ);
|
|
||||||
/**
|
|
||||||
* \brief The classes destructor is empty. If commit() was not called, the local value is
|
|
||||||
* discarded and not written back to the data pool.
|
|
||||||
*/
|
|
||||||
~PoolRawAccess();
|
|
||||||
/**
|
|
||||||
* \brief This operation returns a pointer to the entry fetched.
|
|
||||||
* \details This means, it does not return a pointer to byte "index", but to the start byte of
|
|
||||||
* array entry "index". Example: If the original data pool array consists of an double
|
|
||||||
* array of size four, getEntry(1) returns &(this->value[8]).
|
|
||||||
*/
|
|
||||||
uint8_t* getEntry();
|
|
||||||
/**
|
|
||||||
* \brief This operation returns the fetched entry from the data pool and
|
|
||||||
* flips the bytes, if necessary.
|
|
||||||
* \details It makes use of the getEntry call of this function, but additionally flips the
|
|
||||||
* bytes to big endian, which is the default for external communication (as House-
|
|
||||||
* keeping telemetry). To achieve this, the data is copied directly to the passed
|
|
||||||
* buffer, if it fits in the given maxSize.
|
|
||||||
* \param buffer A pointer to a buffer to write to
|
|
||||||
* \param writtenBytes The number of bytes written is returned with this value.
|
|
||||||
* \param maxSize The maximum size that the function may write to buffer.
|
|
||||||
* \return - \c RETURN_OK if entry could be acquired
|
|
||||||
* - \c RETURN_FAILED else.
|
|
||||||
*/
|
|
||||||
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
|
||||||
size_t maxSize);
|
|
||||||
/**
|
|
||||||
* With this method, the content can be set from a big endian buffer safely.
|
|
||||||
* @param buffer Pointer to the data to set
|
|
||||||
* @param size Size of the data to write. Must fit this->size.
|
|
||||||
* @return - \c RETURN_OK on success
|
|
||||||
* - \c RETURN_FAILED on failure
|
|
||||||
*/
|
|
||||||
ReturnValue_t setEntryFromBigEndian(const uint8_t *buffer,
|
|
||||||
size_t setSize);
|
|
||||||
/**
|
|
||||||
* \brief This operation returns the type of the entry currently stored.
|
|
||||||
*/
|
|
||||||
Type getType();
|
|
||||||
/**
|
|
||||||
* \brief This operation returns the size of the entry currently stored.
|
|
||||||
*/
|
|
||||||
size_t getSizeOfType();
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return the size of the datapool array
|
|
||||||
*/
|
|
||||||
size_t getArraySize();
|
|
||||||
/**
|
|
||||||
* \brief This operation returns the data pool id of the variable.
|
|
||||||
*/
|
|
||||||
uint32_t getDataPoolId() const;
|
|
||||||
/**
|
|
||||||
* This method returns if the variable is read-write or read-only.
|
|
||||||
*/
|
|
||||||
ReadWriteMode_t getReadWriteMode() const;
|
|
||||||
/**
|
|
||||||
* \brief With this call, the valid information of the variable is returned.
|
|
||||||
*/
|
|
||||||
bool isValid() const;
|
|
||||||
|
|
||||||
void setValid(uint8_t valid);
|
|
||||||
/**
|
|
||||||
* Getter for the remaining size.
|
|
||||||
*/
|
|
||||||
size_t getSizeTillEnd() const;
|
|
||||||
|
|
||||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
|
||||||
Endianness streamEndianness) const override;
|
|
||||||
|
|
||||||
size_t getSerializedSize() const override;
|
|
||||||
|
|
||||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
|
||||||
Endianness streamEndianness) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* POOLRAWACCESS_H_ */
|
|
@ -1,14 +1,15 @@
|
|||||||
#ifndef POOLVARLIST_H_
|
#ifndef FSFW_DATAPOOL_POOLVARLIST_H_
|
||||||
#define POOLVARLIST_H_
|
#define FSFW_DATAPOOL_POOLVARLIST_H_
|
||||||
|
|
||||||
#include "PoolVariable.h"
|
#include "../datapool/PoolVariableIF.h"
|
||||||
#include "PoolVariableIF.h"
|
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||||
template <class T, uint8_t n_var>
|
template <class T, uint8_t n_var>
|
||||||
class PoolVarList {
|
class PoolVarList {
|
||||||
private:
|
private:
|
||||||
PoolVariable<T> variables[n_var];
|
GlobPoolVar<T> variables[n_var];
|
||||||
public:
|
public:
|
||||||
PoolVarList( const uint32_t set_id[n_var], DataSetIF* dataSet, PoolVariableIF::ReadWriteMode_t setReadWriteMode ) {
|
PoolVarList( const uint32_t set_id[n_var], DataSetIF* dataSet,
|
||||||
|
PoolVariableIF::ReadWriteMode_t setReadWriteMode ) {
|
||||||
//I really should have a look at the new init list c++ syntax.
|
//I really should have a look at the new init list c++ syntax.
|
||||||
if (dataSet == NULL) {
|
if (dataSet == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -20,9 +21,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVariable<T> &operator [](int i) { return variables[i]; }
|
GlobPoolVar<T> &operator [](int i) { return variables[i]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* POOLVARLIST_H_ */
|
#endif /* FSFW_DATAPOOL_POOLVARLIST_H_ */
|
||||||
|
@ -1,295 +0,0 @@
|
|||||||
/*
|
|
||||||
* \file PoolVariable.h
|
|
||||||
*
|
|
||||||
* \brief This file contains the PoolVariable class, which locally represents a non-array data pool variable.
|
|
||||||
*
|
|
||||||
* \date 10/17/2012
|
|
||||||
*
|
|
||||||
* \author Bastian Baetz
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef POOLVARIABLE_H_
|
|
||||||
#define POOLVARIABLE_H_
|
|
||||||
|
|
||||||
#include "DataSetIF.h"
|
|
||||||
#include "PoolEntry.h"
|
|
||||||
#include "PoolVariableIF.h"
|
|
||||||
#include "../serialize/SerializeAdapter.h"
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
|
|
||||||
template<typename T, uint8_t n_var> class PoolVarList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This is the access class for non-array data pool entries.
|
|
||||||
*
|
|
||||||
* \details To ensure safe usage of the data pool, operation is not done directly on the data pool
|
|
||||||
* entries, but on local copies. This class provides simple type-safe access to single
|
|
||||||
* data pool entries (i.e. entries with length = 1).
|
|
||||||
* The class can be instantiated as read-write and read only.
|
|
||||||
* It provides a commit-and-roll-back semantic, which means that the variable's value in
|
|
||||||
* the data pool is not changed until the commit call is executed.
|
|
||||||
* \tparam T The template parameter sets the type of the variable. Currently, all plain data types
|
|
||||||
* are supported, but in principle any type is possible.
|
|
||||||
* \ingroup data_pool
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
class PoolVariable: public PoolVariableIF {
|
|
||||||
template<typename U, uint8_t n_var> friend class PoolVarList;
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
|
||||||
* is stored.
|
|
||||||
*/
|
|
||||||
uint32_t dataPoolId;
|
|
||||||
/**
|
|
||||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
|
||||||
*/
|
|
||||||
uint8_t valid;
|
|
||||||
/**
|
|
||||||
* \brief The information whether the class is read-write or read-only is stored here.
|
|
||||||
*/
|
|
||||||
ReadWriteMode_t readWriteMode;
|
|
||||||
/**
|
|
||||||
* \brief This is a call to read the value from the global data pool.
|
|
||||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
|
||||||
* data pool id from the global data pool and copies the value and the valid
|
|
||||||
* information to its local attributes. In case of a failure (wrong type or
|
|
||||||
* pool id not found), the variable is set to zero and invalid.
|
|
||||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
||||||
*/
|
|
||||||
ReturnValue_t read() {
|
|
||||||
PoolEntry<T> *read_out = ::dataPool.getData < T > (dataPoolId, 1);
|
|
||||||
if (read_out != NULL) {
|
|
||||||
valid = read_out->valid;
|
|
||||||
value = *(read_out->address);
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
value = 0;
|
|
||||||
valid = false;
|
|
||||||
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
|
||||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief The commit call writes back the variable's value to the data pool.
|
|
||||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
|
||||||
* the value is copied and the valid flag is automatically set to "valid".
|
|
||||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ReturnValue_t commit() {
|
|
||||||
PoolEntry<T> *write_back = ::dataPool.getData < T > (dataPoolId, 1);
|
|
||||||
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
|
||||||
write_back->valid = valid;
|
|
||||||
*(write_back->address) = value;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Empty ctor for List initialization
|
|
||||||
*/
|
|
||||||
PoolVariable() :
|
|
||||||
dataPoolId(PoolVariableIF::NO_PARAMETER), valid(
|
|
||||||
PoolVariableIF::INVALID), readWriteMode(VAR_READ), value(0) {
|
|
||||||
|
|
||||||
}
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* \brief This is the local copy of the data pool entry.
|
|
||||||
* \details The user can work on this attribute
|
|
||||||
* just like he would on a simple local variable.
|
|
||||||
*/
|
|
||||||
T value;
|
|
||||||
/**
|
|
||||||
* \brief In the constructor, the variable can register itself in a DataSet (if not NULL is
|
|
||||||
* passed).
|
|
||||||
* \details It DOES NOT fetch the current value from the data pool, but sets the value
|
|
||||||
* attribute to default (0). The value is fetched within the read() operation.
|
|
||||||
* \param set_id This is the id in the global data pool this instance of the access class
|
|
||||||
* corresponds to.
|
|
||||||
* \param dataSet The data set in which the variable shall register itself. If NULL,
|
|
||||||
* the variable is not registered.
|
|
||||||
* \param setWritable If this flag is set to true, changes in the value attribute can be
|
|
||||||
* written back to the data pool, otherwise not.
|
|
||||||
*/
|
|
||||||
PoolVariable(uint32_t set_id, DataSetIF *dataSet,
|
|
||||||
ReadWriteMode_t setReadWriteMode) :
|
|
||||||
dataPoolId(set_id), valid(PoolVariableIF::INVALID), readWriteMode(
|
|
||||||
setReadWriteMode), value(0) {
|
|
||||||
if (dataSet != NULL) {
|
|
||||||
dataSet->registerVariable(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Copy ctor to copy classes containing Pool Variables.
|
|
||||||
*/
|
|
||||||
PoolVariable(const PoolVariable &rhs) :
|
|
||||||
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
|
||||||
rhs.readWriteMode), value(rhs.value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The classes destructor is empty.
|
|
||||||
* \details If commit() was not called, the local value is
|
|
||||||
* discarded and not written back to the data pool.
|
|
||||||
*/
|
|
||||||
~PoolVariable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief This operation returns the data pool id of the variable.
|
|
||||||
*/
|
|
||||||
uint32_t getDataPoolId() const {
|
|
||||||
return dataPoolId;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* This operation sets the data pool id of the variable.
|
|
||||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
|
||||||
*/
|
|
||||||
void setDataPoolId(uint32_t poolId) {
|
|
||||||
dataPoolId = poolId;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* This method returns if the variable is write-only, read-write or read-only.
|
|
||||||
*/
|
|
||||||
ReadWriteMode_t getReadWriteMode() const {
|
|
||||||
return readWriteMode;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief With this call, the valid information of the variable is returned.
|
|
||||||
*/
|
|
||||||
bool isValid() const {
|
|
||||||
if (valid)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t getValid() {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setValid(uint8_t valid) {
|
|
||||||
this->valid = valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T() const {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
PoolVariable<T>& operator=(T newValue) {
|
|
||||||
value = newValue;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
PoolVariable<T>& operator=(PoolVariable<T> newPoolVariable) {
|
|
||||||
value = newPoolVariable.value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
|
||||||
size_t maxSize, Endianness streamEndianness) const override {
|
|
||||||
return SerializeAdapter::serialize<T>(&value, buffer, size, maxSize,
|
|
||||||
streamEndianness);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual size_t getSerializedSize() const override {
|
|
||||||
return SerializeAdapter::getSerializedSize(&value);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
|
||||||
Endianness streamEndianness) override {
|
|
||||||
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef PoolVariable<uint8_t> db_uint8_t;
|
|
||||||
typedef PoolVariable<uint16_t> db_uint16_t;
|
|
||||||
typedef PoolVariable<uint32_t> db_uint32_t;
|
|
||||||
typedef PoolVariable<int8_t> db_int8_t;
|
|
||||||
typedef PoolVariable<int16_t> db_int16_t;
|
|
||||||
typedef PoolVariable<int32_t> db_int32_t;
|
|
||||||
typedef PoolVariable<uint8_t> db_bool_t;
|
|
||||||
typedef PoolVariable<float> db_float_t;
|
|
||||||
typedef PoolVariable<double> db_double_t;
|
|
||||||
//Alternative (but I thing this is not as useful: code duplication, differences too small):
|
|
||||||
|
|
||||||
//template <typename T>
|
|
||||||
//class PoolReader : public PoolVariableIF {
|
|
||||||
//private:
|
|
||||||
// uint32_t parameter_id;
|
|
||||||
// uint8_t valid;
|
|
||||||
//public:
|
|
||||||
// T value;
|
|
||||||
// PoolReader( uint32_t set_id, DataSetIF* set ) : parameter_id(set_id), valid(false), value(0) {
|
|
||||||
// set->registerVariable( this );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ~PoolReader() {};
|
|
||||||
//
|
|
||||||
// uint8_t commit() {
|
|
||||||
// return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// uint8_t read() {
|
|
||||||
// PoolEntry<T>* read_out = ::dataPool.getData<T>( parameter_id, 1 );
|
|
||||||
// if ( read_out != NULL ) {
|
|
||||||
// valid = read_out->valid;
|
|
||||||
// value = *(read_out->address);
|
|
||||||
// return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
// } else {
|
|
||||||
// value = 0;
|
|
||||||
// valid = false;
|
|
||||||
// return CHECKOUT_FAILED;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// uint32_t getParameterId() { return parameter_id; }
|
|
||||||
// bool isWritable() { return false; };
|
|
||||||
// bool isValid() { if (valid) return true; else return false; }
|
|
||||||
//};
|
|
||||||
//
|
|
||||||
//template <typename T>
|
|
||||||
//class PoolWriter : public PoolVariableIF {
|
|
||||||
//private:
|
|
||||||
// uint32_t parameter_id;
|
|
||||||
//public:
|
|
||||||
// T value;
|
|
||||||
// PoolWriter( uint32_t set_id, DataSetIF* set ) : parameter_id(set_id), value(0) {
|
|
||||||
// set->registerVariable( this );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ~PoolWriter() {};
|
|
||||||
//
|
|
||||||
// uint8_t commit() {
|
|
||||||
// PoolEntry<T>* write_back = ::dataPool.getData<T>( parameter_id, 1 );
|
|
||||||
// if ( write_back != NULL ) {
|
|
||||||
// write_back->valid = true;
|
|
||||||
// *(write_back->address) = value;
|
|
||||||
// return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
// } else {
|
|
||||||
// return CHECKOUT_FAILED;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// uint8_t read() {
|
|
||||||
// PoolEntry<T>* read_out = ::dataPool.getData<T>( parameter_id, 1 );
|
|
||||||
// if ( read_out != NULL ) {
|
|
||||||
// value = *(read_out->address);
|
|
||||||
// return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
// } else {
|
|
||||||
// value = 0;
|
|
||||||
// return CHECKOUT_FAILED;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// uint32_t getParameterId() { return parameter_id; }
|
|
||||||
// bool isWritable() { return true; };
|
|
||||||
// bool isValid() { return false; }
|
|
||||||
//};
|
|
||||||
|
|
||||||
#endif /* POOLVARIABLE_H_ */
|
|
@ -1,71 +1,99 @@
|
|||||||
/*
|
#ifndef FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||||
* \file PoolVariableIF.h
|
#define FSFW_DATAPOOL_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 "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../serialize/SerializeIF.h"
|
#include "../serialize/SerializeIF.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This interface is used to control local data pool variable representations.
|
* @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
|
* @details
|
||||||
* data pool variable access classes, which are called pool variables. To ensure a
|
* To securely handle data pool variables, all pool entries are locally
|
||||||
* common state of a set of variables needed in a function, these local pool variables
|
* managed by data pool variable access classes, which are called pool
|
||||||
* again are managed by other classes, e.g. the DataSet. This interface provides unified
|
* variables. To ensure a common state of a set of variables needed in a
|
||||||
* access to local pool variables for such manager classes.
|
* function, these local pool variables again are managed by other classes,
|
||||||
* \ingroup data_pool
|
* 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 {
|
class PoolVariableIF : public SerializeIF {
|
||||||
friend class DataSet;
|
friend class PoolDataSetBase;
|
||||||
protected:
|
friend class GlobDataSet;
|
||||||
/**
|
friend class LocalPoolDataSetBase;
|
||||||
* \brief The commit call shall write back a newly calculated local value to the data pool.
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t commit() = 0;
|
|
||||||
/**
|
|
||||||
* \brief The read call shall read the value of this parameter from the data pool and store
|
|
||||||
* the content locally.
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t read() = 0;
|
|
||||||
public:
|
public:
|
||||||
static const uint8_t VALID = 1;
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::POOL_VARIABLE_IF;
|
||||||
static const uint8_t INVALID = 0;
|
static constexpr ReturnValue_t INVALID_READ_WRITE_MODE = MAKE_RETURN_CODE(0xA0);
|
||||||
static const uint32_t NO_PARAMETER = 0;
|
|
||||||
|
static constexpr bool VALID = 1;
|
||||||
|
static constexpr bool INVALID = 0;
|
||||||
|
static constexpr uint32_t NO_PARAMETER = 0xffffffff;
|
||||||
|
|
||||||
enum ReadWriteMode_t {
|
enum ReadWriteMode_t {
|
||||||
VAR_READ, VAR_WRITE, VAR_READ_WRITE
|
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;
|
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;
|
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;
|
virtual bool isValid() const = 0;
|
||||||
/**
|
/**
|
||||||
* \brief With this call, the valid information of the variable is set.
|
* @brief With this call, the valid information of the variable is set.
|
||||||
*/
|
*/
|
||||||
virtual void setValid(uint8_t validity) = 0;
|
virtual void setValid(bool validity) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The commit call shall write back a newly calculated local
|
||||||
|
* value to the data pool.
|
||||||
|
* @details
|
||||||
|
* It is assumed that these calls are implemented in a thread-safe manner!
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t commit(uint32_t lockTimeout) = 0;
|
||||||
|
/**
|
||||||
|
* @brief The read call shall read the value of this parameter from
|
||||||
|
* the data pool and store the content locally.
|
||||||
|
* @details
|
||||||
|
* It is assumbed that these calls are implemented in a thread-safe manner!
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t read(uint32_t lockTimeout) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Same as commit with the difference that comitting will be
|
||||||
|
* performed without a lock
|
||||||
|
* @return
|
||||||
|
* This can be used if the lock protection is handled externally
|
||||||
|
* to avoid the overhead of locking and unlocking consecutively.
|
||||||
|
* Declared protected to avoid free public usage.
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t readWithoutLock() = 0;
|
||||||
|
/**
|
||||||
|
* @brief Same as commit with the difference that comitting will be
|
||||||
|
* performed without a lock
|
||||||
|
* @return
|
||||||
|
* This can be used if the lock protection is handled externally
|
||||||
|
* to avoid the overhead of locking and unlocking consecutively.
|
||||||
|
* Declared protected to avoid free public usage.
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t commitWithoutLock() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* POOLVARIABLEIF_H_ */
|
using pool_rwm_t = PoolVariableIF::ReadWriteMode_t;
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOL_POOLVARIABLEIF_H_ */
|
||||||
|
@ -1,233 +0,0 @@
|
|||||||
/*
|
|
||||||
* \file PoolVector.h
|
|
||||||
*
|
|
||||||
* \brief This file contains the PoolVector class, the header only class to handle data pool vectors.
|
|
||||||
*
|
|
||||||
* \date 10/23/2012
|
|
||||||
*
|
|
||||||
* \author Bastian Baetz
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef POOLVECTOR_H_
|
|
||||||
#define POOLVECTOR_H_
|
|
||||||
|
|
||||||
#include "DataSetIF.h"
|
|
||||||
#include "PoolEntry.h"
|
|
||||||
#include "PoolVariableIF.h"
|
|
||||||
#include "../serialize/SerializeAdapter.h"
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This is the access class for array-type data pool entries.
|
|
||||||
*
|
|
||||||
* \details To ensure safe usage of the data pool, operation is not done directly on the data pool
|
|
||||||
* entries, but on local copies. This class provides simple type- and length-safe access
|
|
||||||
* to vector-style data pool entries (i.e. entries with length > 1).
|
|
||||||
* The class can be instantiated as read-write and read only.
|
|
||||||
* It provides a commit-and-roll-back semantic, which means that no array entry in
|
|
||||||
* the data pool is changed until the commit call is executed.
|
|
||||||
* There are two template parameters:
|
|
||||||
* \tparam T This template parameter specifies the data type of an array entry. Currently, all
|
|
||||||
* plain data types are supported, but in principle any type is possible.
|
|
||||||
* \tparam vector_size This template parameter specifies the vector size of this entry.
|
|
||||||
* Using a template parameter for this is not perfect, but avoids dynamic memory allocation.
|
|
||||||
* \ingroup data_pool
|
|
||||||
*/
|
|
||||||
template<typename T, uint16_t vector_size>
|
|
||||||
class PoolVector: public PoolVariableIF {
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* \brief To access the correct data pool entry on read and commit calls, the data pool id
|
|
||||||
* is stored.
|
|
||||||
*/
|
|
||||||
uint32_t dataPoolId;
|
|
||||||
/**
|
|
||||||
* \brief The valid information as it was stored in the data pool is copied to this attribute.
|
|
||||||
*/
|
|
||||||
uint8_t valid;
|
|
||||||
/**
|
|
||||||
* \brief The information whether the class is read-write or read-only is stored here.
|
|
||||||
*/
|
|
||||||
ReadWriteMode_t readWriteMode;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* \brief This is a call to read the array's values from the global data pool.
|
|
||||||
* \details When executed, this operation tries to fetch the pool entry with matching
|
|
||||||
* data pool id from the global data pool and copies all array values and the valid
|
|
||||||
* information to its local attributes. In case of a failure (wrong type, size or
|
|
||||||
* pool id not found), the variable is set to zero and invalid.
|
|
||||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
||||||
*/
|
|
||||||
ReturnValue_t read() {
|
|
||||||
PoolEntry<T>* read_out = ::dataPool.getData<T>(this->dataPoolId,
|
|
||||||
vector_size);
|
|
||||||
if (read_out != NULL) {
|
|
||||||
this->valid = read_out->valid;
|
|
||||||
memcpy(this->value, read_out->address, read_out->getByteSize());
|
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
memset(this->value, 0, vector_size * sizeof(T));
|
|
||||||
sif::error << "PoolVector: read of DP Variable 0x" << std::hex
|
|
||||||
<< dataPoolId << std::dec << " failed." << std::endl;
|
|
||||||
this->valid = INVALID;
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief The commit call copies the array values back to the data pool.
|
|
||||||
* \details It checks type and size, as well as if the variable is writable. If so,
|
|
||||||
* the value is copied and the valid flag is automatically set to "valid".
|
|
||||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ReturnValue_t commit() {
|
|
||||||
PoolEntry<T>* write_back = ::dataPool.getData<T>(this->dataPoolId,
|
|
||||||
vector_size);
|
|
||||||
if ((write_back != NULL) && (this->readWriteMode != VAR_READ)) {
|
|
||||||
write_back->valid = valid;
|
|
||||||
memcpy(write_back->address, this->value, write_back->getByteSize());
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
} else {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* \brief This is the local copy of the data pool entry.
|
|
||||||
* \detials The user can work on this attribute
|
|
||||||
* just like he would on a local array of this type.
|
|
||||||
*/
|
|
||||||
T value[vector_size];
|
|
||||||
/**
|
|
||||||
* \brief In the constructor, the variable can register itself in a DataSet (if not NULL is
|
|
||||||
* passed).
|
|
||||||
* \details It DOES NOT fetch the current value from the data pool, but sets the value
|
|
||||||
* attribute to default (0). The value is fetched within the read() operation.
|
|
||||||
* \param set_id This is the id in the global data pool this instance of the access class
|
|
||||||
* corresponds to.
|
|
||||||
* \param dataSet The data set in which the variable shall register itself. If NULL,
|
|
||||||
* the variable is not registered.
|
|
||||||
* \param setWritable If this flag is set to true, changes in the value attribute can be
|
|
||||||
* written back to the data pool, otherwise not.
|
|
||||||
*/
|
|
||||||
PoolVector(uint32_t set_id, DataSetIF* set,
|
|
||||||
ReadWriteMode_t setReadWriteMode) :
|
|
||||||
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
|
||||||
memset(this->value, 0, vector_size * sizeof(T));
|
|
||||||
if (set != NULL) {
|
|
||||||
set->registerVariable(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Copy ctor to copy classes containing Pool Variables.
|
|
||||||
*/
|
|
||||||
// PoolVector(const PoolVector& rhs) {
|
|
||||||
// PoolVector<T, vector_size> temp(rhs.dataPoolId, rhs.)
|
|
||||||
// memcpy(value, rhs.value, sizeof(T)*vector_size);
|
|
||||||
// }
|
|
||||||
/**
|
|
||||||
* \brief The classes destructor is empty.
|
|
||||||
* \details If commit() was not called, the local value is
|
|
||||||
* discarded and not written back to the data pool.
|
|
||||||
*/
|
|
||||||
~PoolVector() {
|
|
||||||
}
|
|
||||||
;
|
|
||||||
/**
|
|
||||||
* \brief The operation returns the number of array entries in this variable.
|
|
||||||
*/
|
|
||||||
uint8_t getSize() {
|
|
||||||
return vector_size;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief This operation returns the data pool id of the variable.
|
|
||||||
*/
|
|
||||||
uint32_t getDataPoolId() const {
|
|
||||||
return dataPoolId;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* This operation sets the data pool id of the variable.
|
|
||||||
* The method is necessary to set id's of data pool member variables with bad initialization.
|
|
||||||
*/
|
|
||||||
void setDataPoolId(uint32_t poolId) {
|
|
||||||
dataPoolId = poolId;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* This method returns if the variable is write-only, read-write or read-only.
|
|
||||||
*/
|
|
||||||
ReadWriteMode_t getReadWriteMode() const {
|
|
||||||
return readWriteMode;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
/**
|
|
||||||
* \brief With this call, the valid information of the variable is returned.
|
|
||||||
*/
|
|
||||||
bool isValid() const {
|
|
||||||
if (valid != INVALID)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setValid(uint8_t valid) {
|
|
||||||
this->valid = valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t getValid() {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
T &operator [](int i) {
|
|
||||||
return value[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const T &operator [](int i) const {
|
|
||||||
return value[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
PoolVector<T, vector_size> &operator=(
|
|
||||||
PoolVector<T, vector_size> newPoolVector) {
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < vector_size; i++) {
|
|
||||||
this->value[i] = newPoolVector.value[i];
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
||||||
size_t maxSize, Endianness streamEndianness) const {
|
|
||||||
uint16_t i;
|
|
||||||
ReturnValue_t result;
|
|
||||||
for (i = 0; i < vector_size; i++) {
|
|
||||||
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
|
||||||
maxSize, streamEndianness);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual size_t getSerializedSize() const {
|
|
||||||
return vector_size * SerializeAdapter::getSerializedSize(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
||||||
Endianness streamEndianness) {
|
|
||||||
uint16_t i;
|
|
||||||
ReturnValue_t result;
|
|
||||||
for (i = 0; i < vector_size; i++) {
|
|
||||||
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
|
||||||
streamEndianness);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* POOLVECTOR_H_ */
|
|
14
datapool/SharedDataSetIF.h
Normal file
14
datapool/SharedDataSetIF.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||||
|
#define FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_
|
||||||
|
#include "PoolDataSetIF.h"
|
||||||
|
|
||||||
|
class SharedDataSetIF: public PoolDataSetIF {
|
||||||
|
public:
|
||||||
|
virtual ~SharedDataSetIF() {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual ReturnValue_t lockDataset(dur_millis_t mutexTimeout) = 0;
|
||||||
|
virtual ReturnValue_t unlockDataset() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_DATAPOOL_SHAREDDATASETIF_H_ */
|
@ -1,4 +1,4 @@
|
|||||||
#include "ControllerSet.h"
|
#include <fsfw/datapoolglob/ControllerSet.h>
|
||||||
|
|
||||||
ControllerSet::ControllerSet() {
|
ControllerSet::ControllerSet() {
|
||||||
|
|
15
datapoolglob/ControllerSet.h
Normal file
15
datapoolglob/ControllerSet.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLGLOB_CONTROLLERSET_H_
|
||||||
|
#define FSFW_DATAPOOLGLOB_CONTROLLERSET_H_
|
||||||
|
|
||||||
|
#include "../datapoolglob/GlobalDataSet.h"
|
||||||
|
|
||||||
|
class ControllerSet :public GlobDataSet {
|
||||||
|
public:
|
||||||
|
ControllerSet();
|
||||||
|
virtual ~ControllerSet();
|
||||||
|
|
||||||
|
virtual void setToDefault() = 0;
|
||||||
|
void setInvalid();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLGLOB_CONTROLLERSET_H_ */
|
@ -1,7 +1,8 @@
|
|||||||
#include "DataPool.h"
|
|
||||||
#include "DataPoolAdmin.h"
|
#include "DataPoolAdmin.h"
|
||||||
#include "DataSet.h"
|
#include "GlobalDataSet.h"
|
||||||
|
#include "GlobalDataPool.h"
|
||||||
#include "PoolRawAccess.h"
|
#include "PoolRawAccess.h"
|
||||||
|
|
||||||
#include "../ipc/CommandMessage.h"
|
#include "../ipc/CommandMessage.h"
|
||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
#include "../parameters/ParameterMessage.h"
|
#include "../parameters/ParameterMessage.h"
|
||||||
@ -40,9 +41,9 @@ ReturnValue_t DataPoolAdmin::executeAction(ActionId_t actionId,
|
|||||||
|
|
||||||
uint8_t valid = data[4];
|
uint8_t valid = data[4];
|
||||||
|
|
||||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||||
|
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
PoolRawAccess variable(poolId, 0, &mySet, PoolVariableIF::VAR_READ_WRITE);
|
PoolRawAccess variable(poolId, 0, &mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||||
ReturnValue_t status = mySet.read();
|
ReturnValue_t status = mySet.read();
|
||||||
if (status != RETURN_OK) {
|
if (status != RETURN_OK) {
|
||||||
@ -92,9 +93,9 @@ void DataPoolAdmin::handleCommand() {
|
|||||||
|
|
||||||
ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
||||||
const uint8_t* data, size_t size, uint8_t** dataPointer) {
|
const uint8_t* data, size_t size, uint8_t** dataPointer) {
|
||||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
uint8_t arrayIndex = glob::dataPool.PIDToArrayIndex(address);
|
||||||
DataSet testSet;
|
GlobDataSet testSet;
|
||||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
ReturnValue_t status = testSet.read();
|
ReturnValue_t status = testSet.read();
|
||||||
@ -113,7 +114,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
|||||||
const uint8_t* readPosition = data;
|
const uint8_t* readPosition = data;
|
||||||
|
|
||||||
for (; size > 0; size -= typeSize) {
|
for (; size > 0; size -= typeSize) {
|
||||||
DataSet rawSet;
|
GlobDataSet rawSet;
|
||||||
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
status = rawSet.read();
|
status = rawSet.read();
|
||||||
@ -131,9 +132,9 @@ ReturnValue_t DataPoolAdmin::handleMemoryLoad(uint32_t address,
|
|||||||
|
|
||||||
ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
||||||
uint8_t** dataPointer, uint8_t* copyHere) {
|
uint8_t** dataPointer, uint8_t* copyHere) {
|
||||||
uint32_t poolId = ::dataPool.PIDToDataPoolId(address);
|
uint32_t poolId = glob::dataPool.PIDToDataPoolId(address);
|
||||||
uint8_t arrayIndex = ::dataPool.PIDToArrayIndex(address);
|
uint8_t arrayIndex = glob::dataPool.PIDToArrayIndex(address);
|
||||||
DataSet testSet;
|
GlobDataSet testSet;
|
||||||
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
PoolRawAccess varToGetSize(poolId, arrayIndex, &testSet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
ReturnValue_t status = testSet.read();
|
ReturnValue_t status = testSet.read();
|
||||||
@ -146,7 +147,7 @@ ReturnValue_t DataPoolAdmin::handleMemoryDump(uint32_t address, size_t size,
|
|||||||
}
|
}
|
||||||
uint8_t* ptrToCopy = copyHere;
|
uint8_t* ptrToCopy = copyHere;
|
||||||
for (; size > 0; size -= typeSize) {
|
for (; size > 0; size -= typeSize) {
|
||||||
DataSet rawSet;
|
GlobDataSet rawSet;
|
||||||
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
PoolRawAccess variable(poolId, arrayIndex, &rawSet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
status = rawSet.read();
|
status = rawSet.read();
|
@ -1,15 +1,17 @@
|
|||||||
#ifndef DATAPOOLADMIN_H_
|
#ifndef FSFW_DATAPOOLGLOB_DATAPOOLADMIN_H_
|
||||||
#define DATAPOOLADMIN_H_
|
#define FSFW_DATAPOOLGLOB_DATAPOOLADMIN_H_
|
||||||
|
|
||||||
|
#include "DataPoolParameterWrapper.h"
|
||||||
|
|
||||||
#include "../memory/MemoryHelper.h"
|
|
||||||
#include "../action/HasActionsIF.h"
|
|
||||||
#include "../action/SimpleActionHelper.h"
|
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../tasks/ExecutableObjectIF.h"
|
#include "../tasks/ExecutableObjectIF.h"
|
||||||
#include "../parameters/ReceivesParameterMessagesIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
#include "DataPoolParameterWrapper.h"
|
|
||||||
#include "../ipc/MessageQueueIF.h"
|
#include "../ipc/MessageQueueIF.h"
|
||||||
|
#include "../parameters/ReceivesParameterMessagesIF.h"
|
||||||
|
#include "../action/SimpleActionHelper.h"
|
||||||
|
#include "../memory/MemoryHelper.h"
|
||||||
|
|
||||||
|
|
||||||
class DataPoolAdmin: public HasActionsIF,
|
class DataPoolAdmin: public HasActionsIF,
|
||||||
public ExecutableObjectIF,
|
public ExecutableObjectIF,
|
||||||
@ -55,4 +57,4 @@ private:
|
|||||||
Command_t initialCommand);
|
Command_t initialCommand);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DATAPOOLADMIN_H_ */
|
#endif /* FSFW_DATAPOOLGLOB_DATAPOOLADMIN_H_ */
|
@ -1,10 +1,8 @@
|
|||||||
#include "DataPoolParameterWrapper.h"
|
#include "../datapoolglob/GlobalDataSet.h"
|
||||||
|
#include "../datapoolglob/DataPoolParameterWrapper.h"
|
||||||
//for returncodes
|
#include "../datapoolglob/PoolRawAccess.h"
|
||||||
#include "../parameters/HasParametersIF.h"
|
#include "../parameters/HasParametersIF.h"
|
||||||
|
|
||||||
#include "DataSet.h"
|
|
||||||
#include "PoolRawAccess.h"
|
|
||||||
|
|
||||||
DataPoolParameterWrapper::DataPoolParameterWrapper() :
|
DataPoolParameterWrapper::DataPoolParameterWrapper() :
|
||||||
type(Type::UNKNOWN_TYPE), rows(0), columns(0), poolId(
|
type(Type::UNKNOWN_TYPE), rows(0), columns(0), poolId(
|
||||||
@ -20,7 +18,7 @@ ReturnValue_t DataPoolParameterWrapper::set(uint8_t domainId,
|
|||||||
uint16_t parameterId) {
|
uint16_t parameterId) {
|
||||||
poolId = (domainId << 16) + parameterId;
|
poolId = (domainId << 16) + parameterId;
|
||||||
|
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
PoolRawAccess raw(poolId, 0, &mySet, PoolVariableIF::VAR_READ);
|
PoolRawAccess raw(poolId, 0, &mySet, PoolVariableIF::VAR_READ);
|
||||||
ReturnValue_t status = mySet.read();
|
ReturnValue_t status = mySet.read();
|
||||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||||
@ -57,7 +55,7 @@ ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t index = 0; index < rows; index++){
|
for (uint8_t index = 0; index < rows; index++){
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
PoolRawAccess raw(poolId, index, &mySet,PoolVariableIF::VAR_READ);
|
PoolRawAccess raw(poolId, index, &mySet,PoolVariableIF::VAR_READ);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
result = raw.serialize(buffer,size,maxSize,streamEndianness);
|
result = raw.serialize(buffer,size,maxSize,streamEndianness);
|
||||||
@ -94,7 +92,7 @@ ReturnValue_t DataPoolParameterWrapper::deSerializeData(uint8_t startingRow,
|
|||||||
|
|
||||||
for (uint8_t fromRow = 0; fromRow < fromRows; fromRow++) {
|
for (uint8_t fromRow = 0; fromRow < fromRows; fromRow++) {
|
||||||
|
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
PoolRawAccess raw(poolId, startingRow + fromRow, &mySet,
|
PoolRawAccess raw(poolId, startingRow + fromRow, &mySet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
133
datapoolglob/GlobalDataPool.cpp
Normal file
133
datapoolglob/GlobalDataPool.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#include "../datapoolglob/GlobalDataPool.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
#include "../ipc/MutexFactory.h"
|
||||||
|
|
||||||
|
GlobalDataPool::GlobalDataPool(
|
||||||
|
void(*initFunction)(GlobPoolMap* pool_map)) {
|
||||||
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
|
if (initFunction != NULL ) {
|
||||||
|
initFunction( &this->globDataPool );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalDataPool::~GlobalDataPool() {
|
||||||
|
MutexFactory::instance()->deleteMutex(mutex);
|
||||||
|
for(GlobPoolMapIter it = this->globDataPool.begin();
|
||||||
|
it != this->globDataPool.end(); ++it )
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The function checks PID, type and array length before returning a copy of
|
||||||
|
// the PoolEntry. In failure case, it returns a temp-Entry with size 0 and NULL-ptr.
|
||||||
|
template <typename T> PoolEntry<T>* GlobalDataPool::getData( uint32_t data_pool_id,
|
||||||
|
uint8_t sizeOrPosition ) {
|
||||||
|
GlobPoolMapIter it = this->globDataPool.find( data_pool_id );
|
||||||
|
if ( it != this->globDataPool.end() ) {
|
||||||
|
PoolEntry<T>* entry = dynamic_cast< PoolEntry<T>* >( it->second );
|
||||||
|
if (entry != nullptr ) {
|
||||||
|
if ( sizeOrPosition <= entry->length ) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolEntryIF* GlobalDataPool::getRawData( uint32_t data_pool_id ) {
|
||||||
|
GlobPoolMapIter it = this->globDataPool.find( data_pool_id );
|
||||||
|
if ( it != this->globDataPool.end() ) {
|
||||||
|
return it->second;
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t GlobalDataPool::unlockDataPool() {
|
||||||
|
ReturnValue_t status = mutex->unlockMutex();
|
||||||
|
if(status != RETURN_OK) {
|
||||||
|
sif::error << "DataPool::DataPool: unlock of mutex failed with"
|
||||||
|
" error code: " << status << std::endl;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t GlobalDataPool::lockDataPool(uint32_t timeoutMs) {
|
||||||
|
ReturnValue_t status = mutex->lockMutex(MutexIF::TimeoutType::WAITING,
|
||||||
|
timeoutMs);
|
||||||
|
if(status != RETURN_OK) {
|
||||||
|
sif::error << "DataPool::DataPool: lock of mutex failed "
|
||||||
|
"with error code: " << status << std::endl;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalDataPool::print() {
|
||||||
|
sif::debug << "DataPool contains: " << std::endl;
|
||||||
|
std::map<uint32_t, PoolEntryIF*>::iterator dataPoolIt;
|
||||||
|
dataPoolIt = this->globDataPool.begin();
|
||||||
|
while( dataPoolIt != this->globDataPool.end() ) {
|
||||||
|
sif::debug << std::hex << dataPoolIt->first << std::dec << " |";
|
||||||
|
dataPoolIt->second->print();
|
||||||
|
dataPoolIt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GlobalDataPool::PIDToDataPoolId(uint32_t parameter_id) {
|
||||||
|
return (parameter_id >> 8) & 0x00FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t GlobalDataPool::PIDToArrayIndex(uint32_t parameter_id) {
|
||||||
|
return (parameter_id & 0x000000FF);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GlobalDataPool::poolIdAndPositionToPid(uint32_t poolId, uint8_t index) {
|
||||||
|
return (poolId << 8) + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//SHOULDDO: Do we need a mutex lock here... I don't think so,
|
||||||
|
//as we only check static const values of elements in a list that do not change.
|
||||||
|
//there is no guarantee in the standard, but it seems to me that the implementation is safe -UM
|
||||||
|
ReturnValue_t GlobalDataPool::getType(uint32_t parameter_id, Type* type) {
|
||||||
|
GlobPoolMapIter it = this->globDataPool.find( PIDToDataPoolId(parameter_id));
|
||||||
|
if ( it != this->globDataPool.end() ) {
|
||||||
|
*type = it->second->getType();
|
||||||
|
return RETURN_OK;
|
||||||
|
} else {
|
||||||
|
*type = Type::UNKNOWN_TYPE;
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GlobalDataPool::exists(uint32_t parameterId) {
|
||||||
|
uint32_t poolId = PIDToDataPoolId(parameterId);
|
||||||
|
uint32_t index = PIDToArrayIndex(parameterId);
|
||||||
|
GlobPoolMapIter it = this->globDataPool.find( poolId );
|
||||||
|
if (it != globDataPool.end()) {
|
||||||
|
if (it->second->getSize() >= index) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template PoolEntry<uint8_t>* GlobalDataPool::getData<uint8_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<uint16_t>* GlobalDataPool::getData<uint16_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<uint32_t>* GlobalDataPool::getData<uint32_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<uint64_t>* GlobalDataPool::getData<uint64_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size);
|
||||||
|
template PoolEntry<int8_t>* GlobalDataPool::getData<int8_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<int16_t>* GlobalDataPool::getData<int16_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<int32_t>* GlobalDataPool::getData<int32_t>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<float>* GlobalDataPool::getData<float>(
|
||||||
|
uint32_t data_pool_id, uint8_t size );
|
||||||
|
template PoolEntry<double>* GlobalDataPool::getData<double>(
|
||||||
|
uint32_t data_pool_id, uint8_t size);
|
149
datapoolglob/GlobalDataPool.h
Normal file
149
datapoolglob/GlobalDataPool.h
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
#ifndef GLOBALDATAPOOL_H_
|
||||||
|
#define GLOBALDATAPOOL_H_
|
||||||
|
|
||||||
|
#include "../datapool/PoolEntry.h"
|
||||||
|
#include "../globalfunctions/Type.h"
|
||||||
|
#include "../ipc/MutexIF.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup data_pool Global data pool
|
||||||
|
* This is the group, where all classes associated with global
|
||||||
|
* data pool handling belong to.
|
||||||
|
* This includes classes to access Data Pool variables.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Typedefs for the global pool representations
|
||||||
|
*/
|
||||||
|
using GlobPoolMap = std::map<uint32_t, PoolEntryIF*>;
|
||||||
|
using GlobPoolMapIter = GlobPoolMap::iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class represents the OBSW global data-pool.
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
* All variables are registered and space is allocated in an initialization
|
||||||
|
* function, which is passed do the constructor. Space for the variables is
|
||||||
|
* allocated on the heap (with a new call).
|
||||||
|
*
|
||||||
|
* The data is found by a data pool id, which uniquely represents a variable.
|
||||||
|
* Data pool variables should be used with a blackboard logic in mind,
|
||||||
|
* which means read data is valid (if flagged so),
|
||||||
|
* but not necessarily up-to-date.
|
||||||
|
*
|
||||||
|
* Variables are either single values or arrays.
|
||||||
|
* @author Bastian Baetz
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
class GlobalDataPool : public HasReturnvaluesIF {
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief This is the actual data pool itself.
|
||||||
|
* @details It is represented by a map with the data pool id as index
|
||||||
|
* and a pointer to a single PoolEntry as value.
|
||||||
|
*/
|
||||||
|
GlobPoolMap globDataPool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The mutex is created in the constructor and makes
|
||||||
|
* access mutual exclusive.
|
||||||
|
* @details Locking and unlocking the pool is only done by the DataSet class.
|
||||||
|
*/
|
||||||
|
MutexIF* mutex;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief In the classes constructor,
|
||||||
|
* the passed initialization function is called.
|
||||||
|
* @details
|
||||||
|
* To enable filling the pool, a pointer to the map is passed,
|
||||||
|
* allowing direct access to the pool's content.
|
||||||
|
* On runtime, adding or removing variables is forbidden.
|
||||||
|
*/
|
||||||
|
GlobalDataPool( void ( *initFunction )( GlobPoolMap* pool_map ) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The destructor iterates through the data_pool map and
|
||||||
|
* calls all entries destructors to clean up the heap.
|
||||||
|
*/
|
||||||
|
~GlobalDataPool();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the default call to access the pool.
|
||||||
|
* @details
|
||||||
|
* A pointer to the PoolEntry object is returned.
|
||||||
|
* The call checks data pool id, type and array size.
|
||||||
|
* Returns NULL in case of failure.
|
||||||
|
* @param data_pool_id The data pool id to search.
|
||||||
|
* @param sizeOrPosition The array size (not byte size!) of the pool entry,
|
||||||
|
* or the position the user wants to read.
|
||||||
|
* If smaller than the entry size, everything's ok.
|
||||||
|
*/
|
||||||
|
template <typename T> PoolEntry<T>* getData( uint32_t data_pool_id,
|
||||||
|
uint8_t sizeOrPosition );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief An alternative call to get a data pool entry in case the type is not implicitly known
|
||||||
|
* (i.e. in Housekeeping Telemetry).
|
||||||
|
* @details It returns a basic interface and does NOT perform
|
||||||
|
* a size check. The caller has to assure he does not copy too much data.
|
||||||
|
* Returns NULL in case the entry is not found.
|
||||||
|
* @param data_pool_id The data pool id to search.
|
||||||
|
*/
|
||||||
|
PoolEntryIF* getRawData( uint32_t data_pool_id );
|
||||||
|
/**
|
||||||
|
* @brief This is a small helper function to facilitate locking the global data pool.
|
||||||
|
* @details It fetches the pool's mutex id and tries to acquire the mutex.
|
||||||
|
*/
|
||||||
|
ReturnValue_t lockDataPool(uint32_t timeoutMs = MutexIF::BLOCKING);
|
||||||
|
/**
|
||||||
|
* @brief This is a small helper function to facilitate unlocking the global data pool.
|
||||||
|
* @details It fetches the pool's mutex id and tries to free the mutex.
|
||||||
|
*/
|
||||||
|
ReturnValue_t unlockDataPool();
|
||||||
|
/**
|
||||||
|
* @brief The print call is a simple debug method.
|
||||||
|
* @details It prints the current content of the data pool.
|
||||||
|
* It iterates through the data_pool map and calls each entry's print() method.
|
||||||
|
*/
|
||||||
|
void print();
|
||||||
|
/**
|
||||||
|
* Extracts the data pool id from a SCOS 2000 PID.
|
||||||
|
* @param parameter_id The passed Parameter ID.
|
||||||
|
* @return The data pool id as used within the OBSW.
|
||||||
|
*/
|
||||||
|
static uint32_t PIDToDataPoolId( uint32_t parameter_id );
|
||||||
|
/**
|
||||||
|
* Extracts an array index out of a SCOS 2000 PID.
|
||||||
|
* @param parameter_id The passed Parameter ID.
|
||||||
|
* @return The index of the corresponding data pool entry.
|
||||||
|
*/
|
||||||
|
static uint8_t PIDToArrayIndex( uint32_t parameter_id );
|
||||||
|
/**
|
||||||
|
* Retransforms a data pool id and an array index to a SCOS 2000 PID.
|
||||||
|
*/
|
||||||
|
static uint32_t poolIdAndPositionToPid( uint32_t poolId, uint8_t index );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to return the type of a pool variable.
|
||||||
|
* @param parameter_id A parameterID (not pool id) of a DP member.
|
||||||
|
* @param type Returns the type or TYPE::UNKNOWN_TYPE
|
||||||
|
* @return RETURN_OK if parameter exists, RETURN_FAILED else.
|
||||||
|
*/
|
||||||
|
ReturnValue_t getType( uint32_t parameter_id, Type* type );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to check if a PID exists. Does not lock, as there's no
|
||||||
|
* possibility to alter the list that is checked during run-time.
|
||||||
|
* @param parameterId The PID (not pool id!) of a parameter.
|
||||||
|
* @return true if exists, false else.
|
||||||
|
*/
|
||||||
|
bool exists(uint32_t parameterId);
|
||||||
|
};
|
||||||
|
|
||||||
|
//We assume someone globally instantiates a DataPool.
|
||||||
|
namespace glob {
|
||||||
|
extern GlobalDataPool dataPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DATAPOOL_H_ */
|
48
datapoolglob/GlobalDataSet.cpp
Normal file
48
datapoolglob/GlobalDataSet.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "../datapoolglob/GlobalDataPool.h"
|
||||||
|
#include "../datapoolglob/GlobalDataSet.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
GlobDataSet::GlobDataSet(): PoolDataSetBase(
|
||||||
|
reinterpret_cast<PoolVariableIF**>(®isteredVariables),
|
||||||
|
DATA_SET_MAX_SIZE) {}
|
||||||
|
|
||||||
|
// Don't do anything with your variables, they are dead already!
|
||||||
|
// (Destructor is already called)
|
||||||
|
GlobDataSet::~GlobDataSet() {}
|
||||||
|
|
||||||
|
ReturnValue_t GlobDataSet::commit(bool valid, uint32_t lockTimeout) {
|
||||||
|
setEntriesValid(valid);
|
||||||
|
setSetValid(valid);
|
||||||
|
return commit(lockTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t GlobDataSet::commit(uint32_t lockTimeout) {
|
||||||
|
return PoolDataSetBase::commit(lockTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GlobDataSet::isValid() const {
|
||||||
|
return this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t GlobDataSet::unlockDataPool() {
|
||||||
|
return glob::dataPool.unlockDataPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t GlobDataSet::lockDataPool(uint32_t timeoutMs) {
|
||||||
|
return glob::dataPool.lockDataPool(timeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobDataSet::setEntriesValid(bool valid) {
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
if (registeredVariables[count]->getReadWriteMode()
|
||||||
|
!= PoolVariableIF::VAR_READ) {
|
||||||
|
registeredVariables[count]->setValid(valid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobDataSet::setSetValid(bool valid) {
|
||||||
|
this->valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
98
datapoolglob/GlobalDataSet.h
Normal file
98
datapoolglob/GlobalDataSet.h
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#ifndef FRAMEWORK_DATAPOOLGLOB_DATASET_H_
|
||||||
|
#define FRAMEWORK_DATAPOOLGLOB_DATASET_H_
|
||||||
|
|
||||||
|
#include "../datapool/PoolDataSetBase.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The DataSet class manages a set of locally checked out variables
|
||||||
|
* for the global data pool.
|
||||||
|
* @details
|
||||||
|
* This class uses the read-commit() semantic provided by the DataSetBase class.
|
||||||
|
* It extends the base class by using the global data pool,
|
||||||
|
* having a valid state and implementing lock und unlock calls for the global
|
||||||
|
* datapool.
|
||||||
|
*
|
||||||
|
* For more information on how this class works, see the DataSetBase
|
||||||
|
* documentation.
|
||||||
|
* @author Bastian Baetz
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
class GlobDataSet: public PoolDataSetBase {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates an empty GlobDataSet. Use registerVariable or
|
||||||
|
* supply a pointer to this dataset to PoolVariable
|
||||||
|
* initializations to register pool variables.
|
||||||
|
*/
|
||||||
|
GlobDataSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The destructor automatically manages writing the valid
|
||||||
|
* information of variables.
|
||||||
|
* @details
|
||||||
|
* In case the data set was read out, but not committed(indicated by state),
|
||||||
|
* the destructor parses all variables that are still registered to the set.
|
||||||
|
* For each, the valid flag in the data pool is set to "invalid".
|
||||||
|
*/
|
||||||
|
~GlobDataSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variant of method above which sets validity of all elements of the set.
|
||||||
|
* @param valid Validity information from PoolVariableIF.
|
||||||
|
* @return - @c RETURN_OK if all variables were read successfully.
|
||||||
|
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||||
|
* contains non write-only variables
|
||||||
|
*/
|
||||||
|
ReturnValue_t commit(bool valid, uint32_t lockTimeout = MutexIF::BLOCKING);
|
||||||
|
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set all entries
|
||||||
|
* @param valid
|
||||||
|
*/
|
||||||
|
void setSetValid(bool valid);
|
||||||
|
|
||||||
|
bool isValid() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the valid information of all variables contained in the set which
|
||||||
|
* are not read-only
|
||||||
|
*
|
||||||
|
* @param valid Validity information from PoolVariableIF.
|
||||||
|
*/
|
||||||
|
void setEntriesValid(bool valid);
|
||||||
|
|
||||||
|
//!< This definition sets the maximum number of variables to
|
||||||
|
//! register in one DataSet.
|
||||||
|
static const uint8_t DATA_SET_MAX_SIZE = 63;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* If the valid state of a dataset is always relevant to the whole
|
||||||
|
* data set we can use this flag.
|
||||||
|
*/
|
||||||
|
bool valid = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a small helper function to facilitate locking
|
||||||
|
* the global data pool.
|
||||||
|
* @details
|
||||||
|
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||||
|
*/
|
||||||
|
ReturnValue_t lockDataPool(uint32_t timeoutMs) override;
|
||||||
|
/**
|
||||||
|
* @brief This is a small helper function to facilitate
|
||||||
|
* unlocking the global data pool
|
||||||
|
* @details
|
||||||
|
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||||
|
*/
|
||||||
|
ReturnValue_t unlockDataPool() override;
|
||||||
|
|
||||||
|
void handleAlreadyReadDatasetCommit();
|
||||||
|
ReturnValue_t handleUnreadDatasetCommit();
|
||||||
|
|
||||||
|
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_DATAPOOLGLOB_DATASET_H_ */
|
213
datapoolglob/GlobalPoolVariable.h
Normal file
213
datapoolglob/GlobalPoolVariable.h
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
#ifndef GLOBALPOOLVARIABLE_H_
|
||||||
|
#define GLOBALPOOLVARIABLE_H_
|
||||||
|
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../datapoolglob/GlobalDataPool.h"
|
||||||
|
#include "../datapool/PoolVariableIF.h"
|
||||||
|
#include "../datapool/PoolEntry.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
template<typename T, uint8_t n_var> class PoolVarList;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the access class for non-array data pool entries.
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
* To ensure safe usage of the data pool, operation is not done directly
|
||||||
|
* on the data pool entries, but on local copies. This class provides simple
|
||||||
|
* type-safe access to single data pool entries (i.e. entries with length = 1).
|
||||||
|
* The class can be instantiated as read-write and read only.
|
||||||
|
* It provides a commit-and-roll-back semantic, which means that the
|
||||||
|
* variable's value in the data pool is not changed until the
|
||||||
|
* commit call is executed.
|
||||||
|
* @tparam T The template parameter sets the type of the variable.
|
||||||
|
* Currently, all plain data types are supported, but in principle
|
||||||
|
* any type is possible.
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
class GlobPoolVar: public PoolVariableIF {
|
||||||
|
template<typename U, uint8_t n_var> friend class PoolVarList;
|
||||||
|
static_assert(not std::is_same<T, bool>::value,
|
||||||
|
"Do not use boolean for the PoolEntry type, use uint8_t instead!"
|
||||||
|
"There is no boolean type in CCSDS.");
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief In the constructor, the variable can register itself in a
|
||||||
|
* DataSet (if nullptr is not passed).
|
||||||
|
* @details
|
||||||
|
* It DOES NOT fetch the current value from the data pool, but
|
||||||
|
* sets the value attribute to default (0).
|
||||||
|
* The value is fetched within the read() operation.
|
||||||
|
* @param set_id This is the id in the global data pool
|
||||||
|
* this instance of the access class corresponds to.
|
||||||
|
* @param dataSet The data set in which the variable shall register
|
||||||
|
* itself. If NULL, the variable is not registered.
|
||||||
|
* @param setWritable If this flag is set to true, changes in the value
|
||||||
|
* attribute can be written back to the data pool, otherwise not.
|
||||||
|
*/
|
||||||
|
GlobPoolVar(uint32_t set_id, DataSetIF* dataSet,
|
||||||
|
ReadWriteMode_t setReadWriteMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the local copy of the data pool entry.
|
||||||
|
* @details The user can work on this attribute
|
||||||
|
* just like he would on a simple local variable.
|
||||||
|
*/
|
||||||
|
T value = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy ctor to copy classes containing Pool Variables.
|
||||||
|
* (Robin): This only copies member variables, which is done
|
||||||
|
* by the default copy ctor. maybe we can ommit this ctor?
|
||||||
|
*/
|
||||||
|
GlobPoolVar(const GlobPoolVar& rhs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The classes destructor is empty.
|
||||||
|
* @details If commit() was not called, the local value is
|
||||||
|
* discarded and not written back to the data pool.
|
||||||
|
*/
|
||||||
|
~GlobPoolVar() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a call to read the value from the global data pool.
|
||||||
|
* @details
|
||||||
|
* When executed, this operation tries to fetch the pool entry with matching
|
||||||
|
* data pool id from the global data pool and copies the value and the valid
|
||||||
|
* information to its local attributes. In case of a failure (wrong type or
|
||||||
|
* pool id not found), the variable is set to zero and invalid.
|
||||||
|
* The read call is protected with a lock.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t read(uint32_t lockTimeout) override;
|
||||||
|
/**
|
||||||
|
* @brief The commit call writes back the variable's value to the data pool.
|
||||||
|
* @details
|
||||||
|
* It checks type and size, as well as if the variable is writable. If so,
|
||||||
|
* the value is copied and the valid flag is automatically set to "valid".
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* The commit call is protected with a lock.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commit(uint32_t lockTimeout) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Like #read, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t readWithoutLock() override;
|
||||||
|
/**
|
||||||
|
* @brief Like #commit, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commitWithoutLock() override;
|
||||||
|
/**
|
||||||
|
* @brief To access the correct data pool entry on read and commit calls,
|
||||||
|
* the data pool is stored.
|
||||||
|
*/
|
||||||
|
uint32_t dataPoolId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The valid information as it was stored in the data pool is
|
||||||
|
* copied to this attribute.
|
||||||
|
*/
|
||||||
|
uint8_t valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The information whether the class is read-write or read-only
|
||||||
|
* is stored here.
|
||||||
|
*/
|
||||||
|
pool_rwm_t readWriteMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty ctor for List initialization
|
||||||
|
*/
|
||||||
|
GlobPoolVar();
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* \brief This operation returns the data pool id of the variable.
|
||||||
|
*/
|
||||||
|
uint32_t getDataPoolId() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns if the variable is write-only, read-write or read-only.
|
||||||
|
*/
|
||||||
|
ReadWriteMode_t getReadWriteMode() const override;
|
||||||
|
/**
|
||||||
|
* This operation sets the data pool id of the variable.
|
||||||
|
* The method is necessary to set id's of data pool member variables with bad initialization.
|
||||||
|
*/
|
||||||
|
void setDataPoolId(uint32_t poolId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief With this call, the valid information of the variable is returned.
|
||||||
|
*/
|
||||||
|
bool isValid() const override;
|
||||||
|
|
||||||
|
uint8_t getValid();
|
||||||
|
|
||||||
|
void setValid(bool valid) override;
|
||||||
|
|
||||||
|
operator T() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T() const {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobPoolVar<T> &operator=(T newValue) {
|
||||||
|
value = newValue;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobPoolVar<T> &operator=(GlobPoolVar<T> newPoolVariable) {
|
||||||
|
value = newPoolVariable.value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
|
const size_t max_size,
|
||||||
|
SerializeIF::Endianness streamEndianness) const override {
|
||||||
|
return SerializeAdapter::serialize(&value, buffer, size, max_size,
|
||||||
|
streamEndianness);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual size_t getSerializedSize() const {
|
||||||
|
return SerializeAdapter::getSerializedSize(&value);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) {
|
||||||
|
return SerializeAdapter::deSerialize(&value, buffer, size,
|
||||||
|
streamEndianness);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "../datapoolglob/GlobalPoolVariable.tpp"
|
||||||
|
|
||||||
|
typedef GlobPoolVar<uint8_t> gp_bool_t;
|
||||||
|
typedef GlobPoolVar<uint8_t> gp_uint8_t;
|
||||||
|
typedef GlobPoolVar<uint16_t> gp_uint16_t;
|
||||||
|
typedef GlobPoolVar<uint32_t> gp_uint32_t;
|
||||||
|
typedef GlobPoolVar<int8_t> gp_int8_t;
|
||||||
|
typedef GlobPoolVar<int16_t> gp_int16_t;
|
||||||
|
typedef GlobPoolVar<int32_t> gp_int32_t;
|
||||||
|
typedef GlobPoolVar<float> gp_float_t;
|
||||||
|
typedef GlobPoolVar<double> gp_double_t;
|
||||||
|
|
||||||
|
#endif /* POOLVARIABLE_H_ */
|
117
datapoolglob/GlobalPoolVariable.tpp
Normal file
117
datapoolglob/GlobalPoolVariable.tpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#ifndef GLOBALPOOLVARIABLE_TPP_
|
||||||
|
#define GLOBALPOOLVARIABLE_TPP_
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline GlobPoolVar<T>::GlobPoolVar(uint32_t set_id,
|
||||||
|
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode):
|
||||||
|
dataPoolId(set_id), valid(PoolVariableIF::INVALID),
|
||||||
|
readWriteMode(setReadWriteMode)
|
||||||
|
{
|
||||||
|
if (dataSet != nullptr) {
|
||||||
|
dataSet->registerVariable(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t GlobPoolVar<T>::read(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = readWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t GlobPoolVar<T>::commit(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = commitWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline ReturnValue_t GlobPoolVar<T>::readWithoutLock() {
|
||||||
|
PoolEntry<T>* read_out = glob::dataPool.getData<T>(dataPoolId, 1);
|
||||||
|
if (read_out != NULL) {
|
||||||
|
valid = read_out->valid;
|
||||||
|
value = *(read_out->address);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
value = 0;
|
||||||
|
valid = false;
|
||||||
|
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
||||||
|
<< dataPoolId << std::dec << " failed." << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline ReturnValue_t GlobPoolVar<T>::commitWithoutLock() {
|
||||||
|
PoolEntry<T>* write_back = glob::dataPool.getData<T>(dataPoolId, 1);
|
||||||
|
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||||
|
write_back->valid = valid;
|
||||||
|
*(write_back->address) = value;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline GlobPoolVar<T>::GlobPoolVar():
|
||||||
|
dataPoolId(PoolVariableIF::NO_PARAMETER),
|
||||||
|
valid(PoolVariableIF::INVALID),
|
||||||
|
readWriteMode(VAR_READ), value(0) {}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline GlobPoolVar<T>::GlobPoolVar(const GlobPoolVar& rhs) :
|
||||||
|
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
||||||
|
rhs.readWriteMode), value(rhs.value) {}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline pool_rwm_t GlobPoolVar<T>::getReadWriteMode() const {
|
||||||
|
return readWriteMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline uint32_t GlobPoolVar<T>::getDataPoolId() const {
|
||||||
|
return dataPoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void GlobPoolVar<T>::setDataPoolId(uint32_t poolId) {
|
||||||
|
dataPoolId = poolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline bool GlobPoolVar<T>::isValid() const {
|
||||||
|
if (valid)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline uint8_t GlobPoolVar<T>::getValid() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void GlobPoolVar<T>::setValid(bool valid) {
|
||||||
|
this->valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
185
datapoolglob/GlobalPoolVector.h
Normal file
185
datapoolglob/GlobalPoolVector.h
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_H_
|
||||||
|
#define FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_H_
|
||||||
|
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../datapool/PoolEntry.h"
|
||||||
|
#include "../datapool/PoolVariableIF.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the access class for array-type data pool entries.
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
* To ensure safe usage of the data pool, operation is not done directly on the
|
||||||
|
* data pool entries, but on local copies. This class provides simple type-
|
||||||
|
* and length-safe access to vector-style data pool entries (i.e. entries with
|
||||||
|
* length > 1). The class can be instantiated as read-write and read only.
|
||||||
|
*
|
||||||
|
* It provides a commit-and-roll-back semantic, which means that no array
|
||||||
|
* entry in the data pool is changed until the commit call is executed.
|
||||||
|
* There are two template parameters:
|
||||||
|
* @tparam T
|
||||||
|
* This template parameter specifies the data type of an array entry. Currently,
|
||||||
|
* all plain data types are supported, but in principle any type is possible.
|
||||||
|
* @tparam vector_size
|
||||||
|
* This template parameter specifies the vector size of this entry. Using a
|
||||||
|
* template parameter for this is not perfect, but avoids
|
||||||
|
* dynamic memory allocation.
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
class GlobPoolVector: public PoolVariableIF {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief In the constructor, the variable can register itself in a
|
||||||
|
* DataSet (if no nullptr is passed).
|
||||||
|
* @details
|
||||||
|
* It DOES NOT fetch the current value from the data pool, but sets the
|
||||||
|
* value attribute to default (0). The value is fetched within the
|
||||||
|
* read() operation.
|
||||||
|
* @param set_id
|
||||||
|
* This is the id in the global data pool this instance of the access
|
||||||
|
* class corresponds to.
|
||||||
|
* @param dataSet
|
||||||
|
* The data set in which the variable shall register itself. If nullptr,
|
||||||
|
* the variable is not registered.
|
||||||
|
* @param setWritable
|
||||||
|
* If this flag is set to true, changes in the value attribute can be
|
||||||
|
* written back to the data pool, otherwise not.
|
||||||
|
*/
|
||||||
|
GlobPoolVector(uint32_t set_id, DataSetIF* set,
|
||||||
|
ReadWriteMode_t setReadWriteMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the local copy of the data pool entry.
|
||||||
|
* @details The user can work on this attribute
|
||||||
|
* just like he would on a local array of this type.
|
||||||
|
*/
|
||||||
|
T value[vectorSize];
|
||||||
|
/**
|
||||||
|
* @brief The classes destructor is empty.
|
||||||
|
* @details If commit() was not called, the local value is
|
||||||
|
* discarded and not written back to the data pool.
|
||||||
|
*/
|
||||||
|
~GlobPoolVector() {};
|
||||||
|
/**
|
||||||
|
* @brief The operation returns the number of array entries
|
||||||
|
* in this variable.
|
||||||
|
*/
|
||||||
|
uint8_t getSize() {
|
||||||
|
return vectorSize;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief This operation returns the data pool id of the variable.
|
||||||
|
*/
|
||||||
|
uint32_t getDataPoolId() const {
|
||||||
|
return dataPoolId;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief This operation sets the data pool id of the variable.
|
||||||
|
* @details
|
||||||
|
* The method is necessary to set id's of data pool member variables
|
||||||
|
* with bad initialization.
|
||||||
|
*/
|
||||||
|
void setDataPoolId(uint32_t poolId) {
|
||||||
|
dataPoolId = poolId;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* This method returns if the variable is write-only, read-write or read-only.
|
||||||
|
*/
|
||||||
|
ReadWriteMode_t getReadWriteMode() const {
|
||||||
|
return readWriteMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief With this call, the valid information of the variable is returned.
|
||||||
|
*/
|
||||||
|
bool isValid() const {
|
||||||
|
if (valid != INVALID)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void setValid(bool valid) {this->valid = valid;}
|
||||||
|
uint8_t getValid() {return valid;}
|
||||||
|
|
||||||
|
T &operator [](int i) {return value[i];}
|
||||||
|
const T &operator [](int i) const {return value[i];}
|
||||||
|
|
||||||
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
|
size_t max_size, Endianness streamEndianness) const override;
|
||||||
|
virtual size_t getSerializedSize() const override;
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a call to read the array's values
|
||||||
|
* from the global data pool.
|
||||||
|
* @details
|
||||||
|
* When executed, this operation tries to fetch the pool entry with matching
|
||||||
|
* data pool id from the global data pool and copies all array values
|
||||||
|
* and the valid information to its local attributes.
|
||||||
|
* In case of a failure (wrong type, size or pool id not found), the
|
||||||
|
* variable is set to zero and invalid.
|
||||||
|
* The read call is protected by a lock of the global data pool.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
/**
|
||||||
|
* @brief The commit call copies the array values back to the data pool.
|
||||||
|
* @details
|
||||||
|
* It checks type and size, as well as if the variable is writable. If so,
|
||||||
|
* the value is copied and the valid flag is automatically set to "valid".
|
||||||
|
* The commit call is protected by a lock of the global data pool.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Like #read, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t readWithoutLock() override;
|
||||||
|
/**
|
||||||
|
* @brief Like #commit, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commitWithoutLock() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief To access the correct data pool entry on read and commit calls,
|
||||||
|
* the data pool id is stored.
|
||||||
|
*/
|
||||||
|
uint32_t dataPoolId;
|
||||||
|
/**
|
||||||
|
* @brief The valid information as it was stored in the data pool
|
||||||
|
* is copied to this attribute.
|
||||||
|
*/
|
||||||
|
uint8_t valid;
|
||||||
|
/**
|
||||||
|
* @brief The information whether the class is read-write or
|
||||||
|
* read-only is stored here.
|
||||||
|
*/
|
||||||
|
ReadWriteMode_t readWriteMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "../datapoolglob/GlobalPoolVector.tpp"
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
using gp_vec_t = GlobPoolVector<T, vectorSize>;
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_H_ */
|
117
datapoolglob/GlobalPoolVector.tpp
Normal file
117
datapoolglob/GlobalPoolVector.tpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_TPP_
|
||||||
|
#define FSFW_DATAPOOLGLOB_GLOBALPOOLVECTOR_TPP_
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline GlobPoolVector<T, vectorSize>::GlobPoolVector(uint32_t set_id,
|
||||||
|
DataSetIF* set, ReadWriteMode_t setReadWriteMode) :
|
||||||
|
dataPoolId(set_id), valid(false), readWriteMode(setReadWriteMode) {
|
||||||
|
memset(this->value, 0, vectorSize * sizeof(T));
|
||||||
|
if (set != nullptr) {
|
||||||
|
set->registerVariable(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = readWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commit(
|
||||||
|
uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = commitWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::readWithoutLock() {
|
||||||
|
PoolEntry<T>* read_out = glob::dataPool.getData<T>(this->dataPoolId,
|
||||||
|
vectorSize);
|
||||||
|
if (read_out != nullptr) {
|
||||||
|
this->valid = read_out->valid;
|
||||||
|
memcpy(this->value, read_out->address, read_out->getByteSize());
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
memset(this->value, 0, vectorSize * sizeof(T));
|
||||||
|
sif::error << "PoolVector: Read of DP Variable 0x" << std::hex
|
||||||
|
<< std::setw(8) << std::setfill('0') << dataPoolId <<
|
||||||
|
std::dec << " failed." << std::endl;
|
||||||
|
this->valid = INVALID;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::commitWithoutLock() {
|
||||||
|
PoolEntry<T>* writeBack = glob::dataPool.getData<T>(this->dataPoolId,
|
||||||
|
vectorSize);
|
||||||
|
if ((writeBack != nullptr) && (this->readWriteMode != VAR_READ)) {
|
||||||
|
writeBack->valid = valid;
|
||||||
|
memcpy(writeBack->address, this->value, writeBack->getByteSize());
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
|
||||||
|
size_t* size, size_t max_size,
|
||||||
|
SerializeIF::Endianness streamEndianness) const {
|
||||||
|
uint16_t i;
|
||||||
|
ReturnValue_t result;
|
||||||
|
for (i = 0; i < vectorSize; i++) {
|
||||||
|
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||||
|
max_size, streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline size_t GlobPoolVector<T, vectorSize>::getSerializedSize() const {
|
||||||
|
return vectorSize * SerializeAdapter::getSerializedSize(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t GlobPoolVector<T, vectorSize>::deSerialize(
|
||||||
|
const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) {
|
||||||
|
uint16_t i;
|
||||||
|
ReturnValue_t result;
|
||||||
|
for (i = 0; i < vectorSize; i++) {
|
||||||
|
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||||
|
streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,9 +1,9 @@
|
|||||||
#ifndef PIDREADER_H_
|
#ifndef PIDREADER_H_
|
||||||
#define PIDREADER_H_
|
#define PIDREADER_H_
|
||||||
#include "DataPool.h"
|
#include "../datapool/DataSetIF.h"
|
||||||
#include "DataSetIF.h"
|
#include "../datapoolglob/GlobalDataPool.h"
|
||||||
#include "PoolEntry.h"
|
#include "../datapool/PoolEntry.h"
|
||||||
#include "PoolVariableIF.h"
|
#include "../datapool/PoolVariableIF.h"
|
||||||
#include "../serialize/SerializeAdapter.h"
|
#include "../serialize/SerializeAdapter.h"
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
@ -15,10 +15,10 @@ class PIDReader: public PoolVariableIF {
|
|||||||
protected:
|
protected:
|
||||||
uint32_t parameterId;
|
uint32_t parameterId;
|
||||||
uint8_t valid;
|
uint8_t valid;
|
||||||
ReturnValue_t read() {
|
ReturnValue_t readWithoutLock() {
|
||||||
uint8_t arrayIndex = DataPool::PIDToArrayIndex(parameterId);
|
uint8_t arrayIndex = GlobalDataPool::PIDToArrayIndex(parameterId);
|
||||||
PoolEntry<T> *read_out = ::dataPool.getData<T>(
|
PoolEntry<T> *read_out = glob::dataPool.getData<T>(
|
||||||
DataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
GlobalDataPool::PIDToDataPoolId(parameterId), arrayIndex);
|
||||||
if (read_out != NULL) {
|
if (read_out != NULL) {
|
||||||
valid = read_out->valid;
|
valid = read_out->valid;
|
||||||
value = read_out->address[arrayIndex];
|
value = read_out->address[arrayIndex];
|
||||||
@ -36,9 +36,13 @@ protected:
|
|||||||
* Reason is the possibility to access a single DP vector element, but if we commit,
|
* Reason is the possibility to access a single DP vector element, but if we commit,
|
||||||
* we set validity of the whole vector.
|
* we set validity of the whole vector.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t commit() {
|
ReturnValue_t commit(uint32_t lockTimeout) override {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
ReturnValue_t commitWithoutLock() override {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty ctor for List initialization
|
* Empty ctor for List initialization
|
||||||
*/
|
*/
|
||||||
@ -72,6 +76,19 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t read(uint32_t lockTimeout) override {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool();
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = readWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "PIDReader::read: Could not unlock data pool!"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Copy ctor to copy classes containing Pool Variables.
|
* Copy ctor to copy classes containing Pool Variables.
|
||||||
*/
|
*/
|
||||||
@ -89,7 +106,7 @@ public:
|
|||||||
* \brief This operation returns the data pool id of the variable.
|
* \brief This operation returns the data pool id of the variable.
|
||||||
*/
|
*/
|
||||||
uint32_t getDataPoolId() const {
|
uint32_t getDataPoolId() const {
|
||||||
return DataPool::PIDToDataPoolId(parameterId);
|
return GlobalDataPool::PIDToDataPoolId(parameterId);
|
||||||
}
|
}
|
||||||
uint32_t getParameterId() const {
|
uint32_t getParameterId() const {
|
||||||
return parameterId;
|
return parameterId;
|
||||||
@ -114,7 +131,7 @@ public:
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValid(uint8_t valid) {
|
void setValid(bool valid) {
|
||||||
this->valid = valid;
|
this->valid = valid;
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef FRAMEWORK_DATAPOOL_PIDREADERLIST_H_
|
#ifndef FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_
|
||||||
#define FRAMEWORK_DATAPOOL_PIDREADERLIST_H_
|
#define FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_
|
||||||
|
|
||||||
#include "PIDReader.h"
|
#include "../datapool/PoolVariableIF.h"
|
||||||
#include "PoolVariableIF.h"
|
#include "../datapoolglob/PIDReader.h"
|
||||||
template <class T, uint8_t n_var>
|
template <class T, uint8_t n_var>
|
||||||
class PIDReaderList {
|
class PIDReaderList {
|
||||||
private:
|
private:
|
||||||
@ -24,4 +24,4 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FRAMEWORK_DATAPOOL_PIDREADERLIST_H_ */
|
#endif /* FRAMEWORK_DATAPOOLGLOB_PIDREADERLIST_H_ */
|
239
datapoolglob/PoolRawAccess.cpp
Normal file
239
datapoolglob/PoolRawAccess.cpp
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
#include "../datapoolglob/GlobalDataPool.h"
|
||||||
|
#include "../datapoolglob/PoolRawAccess.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
#include "../serialize/EndianConverter.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry,
|
||||||
|
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode) :
|
||||||
|
dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false),
|
||||||
|
type(Type::UNKNOWN_TYPE), typeSize(0), arraySize(0), sizeTillEnd(0),
|
||||||
|
readWriteMode(setReadWriteMode) {
|
||||||
|
memset(value, 0, sizeof(value));
|
||||||
|
if (dataSet != nullptr) {
|
||||||
|
dataSet->registerVariable(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolRawAccess::~PoolRawAccess() {}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::read(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = readWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::readWithoutLock() {
|
||||||
|
ReturnValue_t result = RETURN_FAILED;
|
||||||
|
PoolEntryIF* readOut = glob::dataPool.getRawData(dataPoolId);
|
||||||
|
if (readOut != nullptr) {
|
||||||
|
result = handleReadOut(readOut);
|
||||||
|
if(result == RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = READ_ENTRY_NON_EXISTENT;
|
||||||
|
}
|
||||||
|
handleReadError(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* readOut) {
|
||||||
|
ReturnValue_t result = RETURN_FAILED;
|
||||||
|
valid = readOut->getValid();
|
||||||
|
if (readOut->getSize() > arrayEntry) {
|
||||||
|
arraySize = readOut->getSize();
|
||||||
|
typeSize = readOut->getByteSize() / readOut->getSize();
|
||||||
|
type = readOut->getType();
|
||||||
|
if (typeSize <= sizeof(value)) {
|
||||||
|
uint16_t arrayPosition = arrayEntry * typeSize;
|
||||||
|
sizeTillEnd = readOut->getByteSize() - arrayPosition;
|
||||||
|
uint8_t* ptr = &((uint8_t*) readOut->getRawData())[arrayPosition];
|
||||||
|
memcpy(value, ptr, typeSize);
|
||||||
|
return RETURN_OK;
|
||||||
|
} else {
|
||||||
|
result = READ_TYPE_TOO_LARGE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl;
|
||||||
|
result = READ_INDEX_TOO_LARGE;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoolRawAccess::handleReadError(ReturnValue_t result) {
|
||||||
|
sif::error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId
|
||||||
|
<< std::dec << " failed, ";
|
||||||
|
if(result == READ_TYPE_TOO_LARGE) {
|
||||||
|
sif::error << "type too large." << std::endl;
|
||||||
|
}
|
||||||
|
else if(result == READ_INDEX_TOO_LARGE) {
|
||||||
|
sif::error << "index too large." << std::endl;
|
||||||
|
}
|
||||||
|
else if(result == READ_ENTRY_NON_EXISTENT) {
|
||||||
|
sif::error << "entry does not exist." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
valid = INVALID;
|
||||||
|
typeSize = 0;
|
||||||
|
sizeTillEnd = 0;
|
||||||
|
memset(value, 0, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::commit(uint32_t lockTimeout) {
|
||||||
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = commitWithoutLock();
|
||||||
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
||||||
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::commitWithoutLock() {
|
||||||
|
PoolEntryIF* write_back = glob::dataPool.getRawData(dataPoolId);
|
||||||
|
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
||||||
|
write_back->setValid(valid);
|
||||||
|
uint8_t array_position = arrayEntry * typeSize;
|
||||||
|
uint8_t* ptr = &((uint8_t*) write_back->getRawData())[array_position];
|
||||||
|
memcpy(ptr, value, typeSize);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t* PoolRawAccess::getEntry() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
|
||||||
|
size_t* writtenBytes, size_t max_size) {
|
||||||
|
uint8_t* data_ptr = getEntry();
|
||||||
|
// debug << "PoolRawAccess::getEntry: Array position: " <<
|
||||||
|
// index * size_of_type << " Size of T: " << (int)size_of_type <<
|
||||||
|
// " ByteSize: " << byte_size << " Position: " << *size << std::endl;
|
||||||
|
if (typeSize == 0)
|
||||||
|
return DATA_POOL_ACCESS_FAILED;
|
||||||
|
if (typeSize > max_size)
|
||||||
|
return INCORRECT_SIZE;
|
||||||
|
EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
|
||||||
|
*writtenBytes = typeSize;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size,
|
||||||
|
size_t maxSize, Endianness streamEndianness) const {
|
||||||
|
if (typeSize + *size <= maxSize) {
|
||||||
|
switch(streamEndianness) {
|
||||||
|
case(Endianness::BIG):
|
||||||
|
EndianConverter::convertBigEndian(*buffer, value, typeSize);
|
||||||
|
break;
|
||||||
|
case(Endianness::LITTLE):
|
||||||
|
EndianConverter::convertLittleEndian(*buffer, value, typeSize);
|
||||||
|
break;
|
||||||
|
case(Endianness::MACHINE):
|
||||||
|
default:
|
||||||
|
memcpy(*buffer, value, typeSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*size += typeSize;
|
||||||
|
(*buffer) += typeSize;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
return SerializeIF::BUFFER_TOO_SHORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Type PoolRawAccess::getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PoolRawAccess::getSizeOfType() {
|
||||||
|
return typeSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PoolRawAccess::getArraySize(){
|
||||||
|
return arraySize;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t PoolRawAccess::getDataPoolId() const {
|
||||||
|
return dataPoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
|
||||||
|
return readWriteMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
|
||||||
|
size_t setSize) {
|
||||||
|
if (typeSize == setSize) {
|
||||||
|
EndianConverter::convertBigEndian(value, buffer, typeSize);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
sif::error << "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: "
|
||||||
|
"Internal" << (uint32_t) typeSize << ", Requested: " << setSize
|
||||||
|
<< std::endl;
|
||||||
|
return INCORRECT_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PoolRawAccess::isValid() const {
|
||||||
|
if (valid != INVALID)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PoolRawAccess::setValid(bool valid) {
|
||||||
|
this->valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t PoolRawAccess::getSizeTillEnd() const {
|
||||||
|
return sizeTillEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t PoolRawAccess::getSerializedSize() const {
|
||||||
|
return typeSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
|
||||||
|
Endianness streamEndianness) {
|
||||||
|
|
||||||
|
if (*size >= typeSize) {
|
||||||
|
switch(streamEndianness) {
|
||||||
|
case(Endianness::BIG):
|
||||||
|
EndianConverter::convertBigEndian(value, *buffer, typeSize);
|
||||||
|
break;
|
||||||
|
case(Endianness::LITTLE):
|
||||||
|
EndianConverter::convertLittleEndian(value, *buffer, typeSize);
|
||||||
|
break;
|
||||||
|
case(Endianness::MACHINE):
|
||||||
|
default:
|
||||||
|
memcpy(value, *buffer, typeSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*size -= typeSize;
|
||||||
|
*buffer += typeSize;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
|
}
|
||||||
|
}
|
220
datapoolglob/PoolRawAccess.h
Normal file
220
datapoolglob/PoolRawAccess.h
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
#ifndef POOLRAWACCESS_H_
|
||||||
|
#define POOLRAWACCESS_H_
|
||||||
|
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../datapool/PoolEntryIF.h"
|
||||||
|
#include "../datapool/PoolVariableIF.h"
|
||||||
|
#include "../globalfunctions/Type.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class allows accessing Data Pool variables as raw bytes.
|
||||||
|
* @details
|
||||||
|
* This is necessary to have an access method for HK data, as the PID's alone
|
||||||
|
* do not provide type information. Please note that the the raw pool access
|
||||||
|
* read() and commit() calls are not thread-safe.
|
||||||
|
*
|
||||||
|
* Please supply a data set and use the data set read(), commit() calls for
|
||||||
|
* thread-safe data pool access.
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
class PoolRawAccess: public PoolVariableIF, HasReturnvaluesIF {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* This constructor is used to access a data pool entry with a
|
||||||
|
* given ID if the target type is not known. A DataSet object is supplied
|
||||||
|
* and the data pool entry with the given ID is registered to that data set.
|
||||||
|
* Please note that a pool raw access buffer only has a buffer
|
||||||
|
* with a size of double. As such, for vector entries which have
|
||||||
|
* @param data_pool_id Target data pool entry ID
|
||||||
|
* @param arrayEntry
|
||||||
|
* @param data_set Dataset to register data pool entry to
|
||||||
|
* @param setReadWriteMode
|
||||||
|
* @param registerVectors If set to true, the constructor checks if
|
||||||
|
* there are multiple vector entries to registers
|
||||||
|
* and registers all of them recursively into the data_set
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry,
|
||||||
|
DataSetIF* data_set, ReadWriteMode_t setReadWriteMode =
|
||||||
|
PoolVariableIF::VAR_READ);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This operation returns a pointer to the entry fetched.
|
||||||
|
* @details Return pointer to the buffer containing the raw data
|
||||||
|
* Size and number of data can be retrieved by other means.
|
||||||
|
*/
|
||||||
|
uint8_t* getEntry();
|
||||||
|
/**
|
||||||
|
* @brief This operation returns the fetched entry from the data pool and
|
||||||
|
* flips the bytes, if necessary.
|
||||||
|
* @details It makes use of the getEntry call of this function, but additionally flips the
|
||||||
|
* bytes to big endian, which is the default for external communication (as House-
|
||||||
|
* keeping telemetry). To achieve this, the data is copied directly to the passed
|
||||||
|
* buffer, if it fits in the given max_size.
|
||||||
|
* @param buffer A pointer to a buffer to write to
|
||||||
|
* @param writtenBytes The number of bytes written is returned with this value.
|
||||||
|
* @param max_size The maximum size that the function may write to buffer.
|
||||||
|
* @return - @c RETURN_OK if entry could be acquired
|
||||||
|
* - @c RETURN_FAILED else.
|
||||||
|
*/
|
||||||
|
ReturnValue_t getEntryEndianSafe(uint8_t *buffer, size_t *size,
|
||||||
|
size_t maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Serialize raw pool entry into provided buffer directly
|
||||||
|
* @param buffer Provided buffer. Raw pool data will be copied here
|
||||||
|
* @param size [out] Increment provided size value by serialized size
|
||||||
|
* @param max_size Maximum allowed serialization size
|
||||||
|
* @param bigEndian Specify endianess
|
||||||
|
* @return - @c RETURN_OK if serialization was successfull
|
||||||
|
* - @c SerializeIF::BUFFER_TOO_SHORT if range check failed
|
||||||
|
*/
|
||||||
|
ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||||
|
size_t maxSize, Endianness streamEndianness) const override;
|
||||||
|
|
||||||
|
size_t getSerializedSize() const override;
|
||||||
|
|
||||||
|
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||||
|
Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With this method, the content can be set from a big endian buffer safely.
|
||||||
|
* @param buffer Pointer to the data to set
|
||||||
|
* @param size Size of the data to write. Must fit this->size.
|
||||||
|
* @return - @c RETURN_OK on success
|
||||||
|
* - @c RETURN_FAILED on failure
|
||||||
|
*/
|
||||||
|
ReturnValue_t setEntryFromBigEndian(const uint8_t* buffer,
|
||||||
|
size_t setSize);
|
||||||
|
/**
|
||||||
|
* @brief This operation returns the type of the entry currently stored.
|
||||||
|
*/
|
||||||
|
Type getType();
|
||||||
|
/**
|
||||||
|
* @brief This operation returns the size of the entry currently stored.
|
||||||
|
*/
|
||||||
|
size_t getSizeOfType();
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the size of the datapool array
|
||||||
|
*/
|
||||||
|
size_t getArraySize();
|
||||||
|
/**
|
||||||
|
* @brief This operation returns the data pool id of the variable.
|
||||||
|
*/
|
||||||
|
uint32_t getDataPoolId() const;
|
||||||
|
|
||||||
|
static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS;
|
||||||
|
static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01);
|
||||||
|
static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02);
|
||||||
|
static const ReturnValue_t READ_TYPE_TOO_LARGE = MAKE_RETURN_CODE(0x03);
|
||||||
|
static const ReturnValue_t READ_INDEX_TOO_LARGE = MAKE_RETURN_CODE(0x04);
|
||||||
|
static const ReturnValue_t READ_ENTRY_NON_EXISTENT = MAKE_RETURN_CODE(0x05);
|
||||||
|
static const uint8_t RAW_MAX_SIZE = sizeof(double);
|
||||||
|
uint8_t value[RAW_MAX_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The classes destructor is empty. If commit() was not called, the local value is
|
||||||
|
* discarded and not written back to the data pool.
|
||||||
|
*/
|
||||||
|
~PoolRawAccess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns if the variable is read-write or read-only.
|
||||||
|
*/
|
||||||
|
ReadWriteMode_t getReadWriteMode() const;
|
||||||
|
/**
|
||||||
|
* @brief With this call, the valid information of the variable is returned.
|
||||||
|
*/
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
|
void setValid(bool valid);
|
||||||
|
/**
|
||||||
|
* Getter for the remaining size.
|
||||||
|
*/
|
||||||
|
size_t getSizeTillEnd() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a call to read the value from the global data pool.
|
||||||
|
* @details
|
||||||
|
* When executed, this operation tries to fetch the pool entry with matching
|
||||||
|
* data pool id from the global data pool and copies the value and the valid
|
||||||
|
* information to its local attributes. In case of a failure (wrong type or
|
||||||
|
* pool id not found), the variable is set to zero and invalid.
|
||||||
|
* The call is protected by a lock of the global data pool.
|
||||||
|
* @return -@c RETURN_OK Read successfull
|
||||||
|
* -@c READ_TYPE_TOO_LARGE
|
||||||
|
* -@c READ_INDEX_TOO_LARGE
|
||||||
|
* -@c READ_ENTRY_NON_EXISTENT
|
||||||
|
*/
|
||||||
|
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
/**
|
||||||
|
* @brief The commit call writes back the variable's value to the data pool.
|
||||||
|
* @details
|
||||||
|
* It checks type and size, as well as if the variable is writable. If so,
|
||||||
|
* the value is copied and the valid flag is automatically set to "valid".
|
||||||
|
* The call is protected by a lock of the global data pool.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Like #read, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t readWithoutLock() override;
|
||||||
|
/**
|
||||||
|
* @brief Like #commit, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commitWithoutLock() override;
|
||||||
|
|
||||||
|
ReturnValue_t handleReadOut(PoolEntryIF* read_out);
|
||||||
|
void handleReadError(ReturnValue_t result);
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief To access the correct data pool entry on read and commit calls, the data pool id
|
||||||
|
* is stored.
|
||||||
|
*/
|
||||||
|
uint32_t dataPoolId;
|
||||||
|
/**
|
||||||
|
* @brief The array entry that is fetched from the data pool.
|
||||||
|
*/
|
||||||
|
uint8_t arrayEntry;
|
||||||
|
/**
|
||||||
|
* @brief The valid information as it was stored in the data pool is copied to this attribute.
|
||||||
|
*/
|
||||||
|
uint8_t valid;
|
||||||
|
/**
|
||||||
|
* @brief This value contains the type of the data pool entry.
|
||||||
|
*/
|
||||||
|
Type type;
|
||||||
|
/**
|
||||||
|
* @brief This value contains the size of the data pool entry type in bytes.
|
||||||
|
*/
|
||||||
|
size_t typeSize;
|
||||||
|
/**
|
||||||
|
* The size of the DP array (single values return 1)
|
||||||
|
*/
|
||||||
|
size_t arraySize;
|
||||||
|
/**
|
||||||
|
* The size (in bytes) from the selected entry till the end of this DataPool variable.
|
||||||
|
*/
|
||||||
|
size_t sizeTillEnd;
|
||||||
|
/**
|
||||||
|
* @brief The information whether the class is read-write or read-only is stored here.
|
||||||
|
*/
|
||||||
|
ReadWriteMode_t readWriteMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* POOLRAWACCESS_H_ */
|
136
datapoollocal/HasLocalDataPoolIF.h
Normal file
136
datapoollocal/HasLocalDataPoolIF.h
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_
|
||||||
|
|
||||||
|
#include "locPoolDefinitions.h"
|
||||||
|
|
||||||
|
#include "../datapool/PoolEntryIF.h"
|
||||||
|
#include "../ipc/MessageQueueSenderIF.h"
|
||||||
|
#include "../housekeeping/HousekeepingMessage.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class LocalDataPoolManager;
|
||||||
|
class LocalPoolDataSetBase;
|
||||||
|
class LocalPoolObjectBase;
|
||||||
|
|
||||||
|
using LocalDataPool = std::map<lp_id_t, PoolEntryIF*>;
|
||||||
|
using LocalDataPoolMapIter = LocalDataPool::iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This interface is implemented by classes which posses a local
|
||||||
|
* data pool (not the managing class). It defines the relationship
|
||||||
|
* between the local data pool owner and the LocalDataPoolManager.
|
||||||
|
* @details
|
||||||
|
* Any class implementing this interface shall also have a LocalDataPoolManager
|
||||||
|
* member class which contains the actual pool data structure
|
||||||
|
* and exposes the public interface for it.
|
||||||
|
* This is required because the pool entries are templates, which makes
|
||||||
|
* specifying an interface rather difficult. The local data pool can be
|
||||||
|
* accessed by using the LocalPoolVariable, LocalPoolVector or LocalDataSet
|
||||||
|
* classes.
|
||||||
|
*
|
||||||
|
* Architectural Note:
|
||||||
|
* This could be circumvented by using a wrapper/accessor function or
|
||||||
|
* implementing the templated function in this interface..
|
||||||
|
* The first solution sounds better than the second but
|
||||||
|
* the LocalPoolVariable classes are templates as well, so this just shifts
|
||||||
|
* the problem somewhere else. Interfaces are nice, but the most
|
||||||
|
* pragmatic solution I found was to offer the client the full interface
|
||||||
|
* of the LocalDataPoolManager.
|
||||||
|
*/
|
||||||
|
class HasLocalDataPoolIF {
|
||||||
|
public:
|
||||||
|
virtual~ HasLocalDataPoolIF() {};
|
||||||
|
|
||||||
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF;
|
||||||
|
|
||||||
|
static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID;
|
||||||
|
|
||||||
|
virtual object_id_t getObjectId() const = 0;
|
||||||
|
|
||||||
|
/** Command queue for housekeeping messages. */
|
||||||
|
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is used by pool owner to initialize the pool map once
|
||||||
|
* The manager instance shall also be passed to this function.
|
||||||
|
* It can be used to subscribe for periodic packets for for updates.
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t initializeLocalDataPool(
|
||||||
|
LocalDataPool& localDataPoolMap,
|
||||||
|
LocalDataPoolManager& poolManager) = 0;
|
||||||
|
|
||||||
|
/** Can be used to get a handle to the local data pool manager. */
|
||||||
|
virtual LocalDataPoolManager* getHkManagerHandle() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the minimum sampling frequency in milliseconds, which will
|
||||||
|
* usually be the period the pool owner performs its periodic operation.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual uint32_t getPeriodicOperationFrequency() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used by the pool manager to get a valid dataset
|
||||||
|
* from a SID
|
||||||
|
* @param sid Corresponding structure ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to the function above, but used to get a local pool variable
|
||||||
|
* handle. This is only needed for update notifications, so it is not
|
||||||
|
* defined as abstract.
|
||||||
|
* @param localPoolId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) {
|
||||||
|
sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden"
|
||||||
|
<< ". Returning nullptr!" << std::endl;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function will be called by the manager if an update
|
||||||
|
* notification is received.
|
||||||
|
* @details
|
||||||
|
* Can be overriden by the child class to handle changed datasets.
|
||||||
|
* @param sid
|
||||||
|
* @param storeId If a snapshot was requested, data will be located inside
|
||||||
|
* the IPC store with this store ID.
|
||||||
|
*/
|
||||||
|
virtual void handleChangedDataset(sid_t sid,
|
||||||
|
store_address_t storeId = storeId::INVALID_STORE_ADDRESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function will be called by the manager if an update
|
||||||
|
* notification is received.
|
||||||
|
* @details
|
||||||
|
* Can be overriden by the child class to handle changed pool IDs.
|
||||||
|
* @param sid
|
||||||
|
* @param storeId If a snapshot was requested, data will be located inside
|
||||||
|
* the IPC store with this store ID.
|
||||||
|
*/
|
||||||
|
virtual void handleChangedPoolVariable(lp_id_t poolId,
|
||||||
|
store_address_t storeId = storeId::INVALID_STORE_ADDRESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* These function can be implemented by pool owner, as they are required
|
||||||
|
* by the housekeeping message interface */
|
||||||
|
virtual ReturnValue_t addDataSet(sid_t sid) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
};
|
||||||
|
virtual ReturnValue_t removeDataSet(sid_t sid) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
};
|
||||||
|
virtual ReturnValue_t changeCollectionInterval(sid_t sid,
|
||||||
|
float newIntervalSeconds) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ */
|
782
datapoollocal/LocalDataPoolManager.cpp
Normal file
782
datapoollocal/LocalDataPoolManager.cpp
Normal file
@ -0,0 +1,782 @@
|
|||||||
|
#include "LocalDataPoolManager.h"
|
||||||
|
#include "LocalPoolObjectBase.h"
|
||||||
|
#include "LocalPoolDataSetBase.h"
|
||||||
|
|
||||||
|
#include "../housekeeping/HousekeepingPacketUpdate.h"
|
||||||
|
#include "../housekeeping/HousekeepingSetPacket.h"
|
||||||
|
#include "../housekeeping/AcceptsHkPacketsIF.h"
|
||||||
|
|
||||||
|
#include "../timemanager/CCSDSTime.h"
|
||||||
|
#include "../ipc/MutexFactory.h"
|
||||||
|
#include "../ipc/MutexHelper.h"
|
||||||
|
#include "../ipc/QueueFactory.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
object_id_t LocalDataPoolManager::defaultHkDestination =
|
||||||
|
objects::PUS_SERVICE_3_HOUSEKEEPING;
|
||||||
|
|
||||||
|
LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner,
|
||||||
|
MessageQueueIF* queueToUse, bool appendValidityBuffer):
|
||||||
|
appendValidityBuffer(appendValidityBuffer) {
|
||||||
|
if(owner == nullptr) {
|
||||||
|
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
|
||||||
|
<< "Invalid supplied owner!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->owner = owner;
|
||||||
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
|
if(mutex == nullptr) {
|
||||||
|
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
|
||||||
|
<< "Could not create mutex." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
hkQueue = queueToUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDataPoolManager::~LocalDataPoolManager() {}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) {
|
||||||
|
if(queueToUse == nullptr) {
|
||||||
|
sif::error << "LocalDataPoolManager::initialize: "
|
||||||
|
<< std::hex << "0x" << owner->getObjectId() << ". Supplied "
|
||||||
|
<< "queue invalid!" << std::dec << std::endl;
|
||||||
|
}
|
||||||
|
hkQueue = queueToUse;
|
||||||
|
|
||||||
|
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||||
|
if(ipcStore == nullptr) {
|
||||||
|
sif::error << "LocalDataPoolManager::initialize: "
|
||||||
|
<< std::hex << "0x" << owner->getObjectId() << ": Could not "
|
||||||
|
<< "set IPC store." <<std::dec << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(defaultHkDestination != objects::NO_OBJECT) {
|
||||||
|
AcceptsHkPacketsIF* hkPacketReceiver =
|
||||||
|
objectManager->get<AcceptsHkPacketsIF>(defaultHkDestination);
|
||||||
|
if(hkPacketReceiver != nullptr) {
|
||||||
|
hkDestinationId = hkPacketReceiver->getHkQueue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
|
||||||
|
<< "Default HK destination object is invalid!" << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::initializeAfterTaskCreation(
|
||||||
|
uint8_t nonDiagInvlFactor) {
|
||||||
|
setNonDiagnosticIntervalFactor(nonDiagInvlFactor);
|
||||||
|
return initializeHousekeepingPoolEntriesOnce();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
|
||||||
|
if(not mapInitialized) {
|
||||||
|
ReturnValue_t result = owner->initializeLocalDataPool(localPoolMap,
|
||||||
|
*this);
|
||||||
|
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
mapInitialized = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
sif::warning << "HousekeepingManager: The map should only be initialized "
|
||||||
|
<< "once!" << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::performHkOperation() {
|
||||||
|
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
for(auto& receiver: hkReceiversMap) {
|
||||||
|
switch(receiver.reportingType) {
|
||||||
|
case(ReportingType::PERIODIC): {
|
||||||
|
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||||
|
// Periodic packets shall only be generated from datasets.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
performPeriodicHkGeneration(receiver);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(ReportingType::UPDATE_HK): {
|
||||||
|
handleHkUpdate(receiver, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(ReportingType::UPDATE_NOTIFICATION): {
|
||||||
|
handleNotificationUpdate(receiver, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(ReportingType::UPDATE_SNAPSHOT): {
|
||||||
|
handleNotificationSnapshot(receiver, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// This should never happen.
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetHkUpdateResetHelper();
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::handleHkUpdate(HkReceiver& receiver,
|
||||||
|
ReturnValue_t& status) {
|
||||||
|
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||||
|
// Update packets shall only be generated from datasets.
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
|
||||||
|
receiver.dataId.sid);
|
||||||
|
if(dataSet->hasChanged()) {
|
||||||
|
// prepare and send update notification
|
||||||
|
ReturnValue_t result = generateHousekeepingPacket(
|
||||||
|
receiver.dataId.sid, dataSet, true);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
status = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handleChangeResetLogic(receiver.dataType, receiver.dataId,
|
||||||
|
dataSet);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::handleNotificationUpdate(
|
||||||
|
HkReceiver& receiver, ReturnValue_t& status) {
|
||||||
|
MarkChangedIF* toReset = nullptr;
|
||||||
|
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||||
|
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
|
||||||
|
receiver.dataId.localPoolId);
|
||||||
|
if(poolObj == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if(poolObj->hasChanged()) {
|
||||||
|
// prepare and send update notification.
|
||||||
|
CommandMessage notification;
|
||||||
|
HousekeepingMessage::setUpdateNotificationVariableCommand(
|
||||||
|
¬ification, receiver.dataId.localPoolId);
|
||||||
|
ReturnValue_t result = hkQueue->sendMessage(
|
||||||
|
receiver.destinationQueue, ¬ification);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
status = result;
|
||||||
|
}
|
||||||
|
toReset = poolObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
|
||||||
|
receiver.dataId.sid);
|
||||||
|
if(dataSet == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if(dataSet->hasChanged()) {
|
||||||
|
// prepare and send update notification
|
||||||
|
CommandMessage notification;
|
||||||
|
HousekeepingMessage::setUpdateNotificationSetCommand(
|
||||||
|
¬ification, receiver.dataId.sid);
|
||||||
|
ReturnValue_t result = hkQueue->sendMessage(
|
||||||
|
receiver.destinationQueue, ¬ification);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
status = result;
|
||||||
|
}
|
||||||
|
toReset = dataSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(toReset != nullptr) {
|
||||||
|
handleChangeResetLogic(receiver.dataType,
|
||||||
|
receiver.dataId, toReset);
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
|
||||||
|
HkReceiver& receiver, ReturnValue_t& status) {
|
||||||
|
MarkChangedIF* toReset = nullptr;
|
||||||
|
// check whether data has changed and send messages in case it has.
|
||||||
|
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
|
||||||
|
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
|
||||||
|
receiver.dataId.localPoolId);
|
||||||
|
if(poolObj == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not poolObj->hasChanged()) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare and send update snapshot.
|
||||||
|
timeval now;
|
||||||
|
Clock::getClock_timeval(&now);
|
||||||
|
CCSDSTime::CDS_short cds;
|
||||||
|
CCSDSTime::convertToCcsds(&cds, &now);
|
||||||
|
HousekeepingPacketUpdate updatePacket(reinterpret_cast<uint8_t*>(&cds),
|
||||||
|
sizeof(cds), owner->getPoolObjectHandle(
|
||||||
|
receiver.dataId.localPoolId));
|
||||||
|
|
||||||
|
store_address_t storeId;
|
||||||
|
ReturnValue_t result = addUpdateToStore(updatePacket, storeId);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandMessage notification;
|
||||||
|
HousekeepingMessage::setUpdateSnapshotVariableCommand(¬ification,
|
||||||
|
receiver.dataId.localPoolId, storeId);
|
||||||
|
result = hkQueue->sendMessage(receiver.destinationQueue,
|
||||||
|
¬ification);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
status = result;
|
||||||
|
}
|
||||||
|
toReset = poolObj;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
|
||||||
|
receiver.dataId.sid);
|
||||||
|
if(dataSet == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(not dataSet->hasChanged()) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare and send update snapshot.
|
||||||
|
timeval now;
|
||||||
|
Clock::getClock_timeval(&now);
|
||||||
|
CCSDSTime::CDS_short cds;
|
||||||
|
CCSDSTime::convertToCcsds(&cds, &now);
|
||||||
|
HousekeepingPacketUpdate updatePacket(reinterpret_cast<uint8_t*>(&cds),
|
||||||
|
sizeof(cds), owner->getDataSetHandle(receiver.dataId.sid));
|
||||||
|
|
||||||
|
store_address_t storeId;
|
||||||
|
ReturnValue_t result = addUpdateToStore(updatePacket, storeId);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandMessage notification;
|
||||||
|
HousekeepingMessage::setUpdateSnapshotSetCommand(
|
||||||
|
¬ification, receiver.dataId.sid, storeId);
|
||||||
|
result = hkQueue->sendMessage(receiver.destinationQueue, ¬ification);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
status = result;
|
||||||
|
}
|
||||||
|
toReset = dataSet;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(toReset != nullptr) {
|
||||||
|
handleChangeResetLogic(receiver.dataType,
|
||||||
|
receiver.dataId, toReset);
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::addUpdateToStore(
|
||||||
|
HousekeepingPacketUpdate& updatePacket, store_address_t& storeId) {
|
||||||
|
size_t updatePacketSize = updatePacket.getSerializedSize();
|
||||||
|
uint8_t *storePtr = nullptr;
|
||||||
|
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||||
|
updatePacket.getSerializedSize(), &storePtr);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
size_t serializedSize = 0;
|
||||||
|
result = updatePacket.serialize(&storePtr, &serializedSize,
|
||||||
|
updatePacketSize, SerializeIF::Endianness::MACHINE);
|
||||||
|
return result;;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalDataPoolManager::handleChangeResetLogic(
|
||||||
|
DataType type, DataId dataId, MarkChangedIF* toReset) {
|
||||||
|
if(hkUpdateResetList == nullptr) {
|
||||||
|
// config error!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& changeInfo: *hkUpdateResetList) {
|
||||||
|
if(changeInfo.dataType != type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if((changeInfo.dataType == DataType::DATA_SET) and
|
||||||
|
(changeInfo.dataId.sid != dataId.sid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if((changeInfo.dataType == DataType::LOCAL_POOL_VARIABLE) and
|
||||||
|
(changeInfo.dataId.localPoolId != dataId.localPoolId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(changeInfo.updateCounter <= 1) {
|
||||||
|
toReset->setChanged(false);
|
||||||
|
}
|
||||||
|
if(changeInfo.currentUpdateCounter == 0) {
|
||||||
|
toReset->setChanged(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
changeInfo.currentUpdateCounter--;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalDataPoolManager::resetHkUpdateResetHelper() {
|
||||||
|
if(hkUpdateResetList == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& changeInfo: *hkUpdateResetList) {
|
||||||
|
changeInfo.currentUpdateCounter = changeInfo.updateCounter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid,
|
||||||
|
bool enableReporting, float collectionInterval, bool isDiagnostics,
|
||||||
|
object_id_t packetDestination) {
|
||||||
|
AcceptsHkPacketsIF* hkReceiverObject =
|
||||||
|
objectManager->get<AcceptsHkPacketsIF>(packetDestination);
|
||||||
|
if(hkReceiverObject == nullptr) {
|
||||||
|
sif::error << "LocalDataPoolManager::subscribeForPeriodicPacket:"
|
||||||
|
<< " Invalid receiver!"<< std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HkReceiver hkReceiver;
|
||||||
|
hkReceiver.dataId.sid = sid;
|
||||||
|
hkReceiver.reportingType = ReportingType::PERIODIC;
|
||||||
|
hkReceiver.dataType = DataType::DATA_SET;
|
||||||
|
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
|
||||||
|
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
if(dataSet != nullptr) {
|
||||||
|
dataSet->setReportingEnabled(enableReporting);
|
||||||
|
dataSet->setDiagnostic(isDiagnostics);
|
||||||
|
dataSet->initializePeriodicHelper(collectionInterval,
|
||||||
|
owner->getPeriodicOperationFrequency(), isDiagnostics);
|
||||||
|
}
|
||||||
|
|
||||||
|
hkReceiversMap.push_back(hkReceiver);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::subscribeForUpdatePackets(sid_t sid,
|
||||||
|
bool isDiagnostics, bool reportingEnabled,
|
||||||
|
object_id_t packetDestination) {
|
||||||
|
AcceptsHkPacketsIF* hkReceiverObject =
|
||||||
|
objectManager->get<AcceptsHkPacketsIF>(packetDestination);
|
||||||
|
if(hkReceiverObject == nullptr) {
|
||||||
|
sif::error << "LocalDataPoolManager::subscribeForPeriodicPacket:"
|
||||||
|
<< " Invalid receiver!"<< std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HkReceiver hkReceiver;
|
||||||
|
hkReceiver.dataId.sid = sid;
|
||||||
|
hkReceiver.reportingType = ReportingType::UPDATE_HK;
|
||||||
|
hkReceiver.dataType = DataType::DATA_SET;
|
||||||
|
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
|
||||||
|
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
if(dataSet != nullptr) {
|
||||||
|
dataSet->setReportingEnabled(true);
|
||||||
|
dataSet->setDiagnostic(isDiagnostics);
|
||||||
|
}
|
||||||
|
|
||||||
|
hkReceiversMap.push_back(hkReceiver);
|
||||||
|
|
||||||
|
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::subscribeForSetUpdateMessages(
|
||||||
|
const uint32_t setId, object_id_t destinationObject,
|
||||||
|
MessageQueueId_t targetQueueId, bool generateSnapshot) {
|
||||||
|
struct HkReceiver hkReceiver;
|
||||||
|
hkReceiver.dataType = DataType::DATA_SET;
|
||||||
|
hkReceiver.dataId.sid = sid_t(this->getOwner()->getObjectId(), setId);
|
||||||
|
hkReceiver.destinationQueue = targetQueueId;
|
||||||
|
hkReceiver.objectId = destinationObject;
|
||||||
|
if(generateSnapshot) {
|
||||||
|
hkReceiver.reportingType = ReportingType::UPDATE_SNAPSHOT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hkReceiver.reportingType = ReportingType::UPDATE_NOTIFICATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
hkReceiversMap.push_back(hkReceiver);
|
||||||
|
|
||||||
|
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::subscribeForVariableUpdateMessages(
|
||||||
|
const lp_id_t localPoolId, object_id_t destinationObject,
|
||||||
|
MessageQueueId_t targetQueueId, bool generateSnapshot) {
|
||||||
|
struct HkReceiver hkReceiver;
|
||||||
|
hkReceiver.dataType = DataType::LOCAL_POOL_VARIABLE;
|
||||||
|
hkReceiver.dataId.localPoolId = localPoolId;
|
||||||
|
hkReceiver.destinationQueue = targetQueueId;
|
||||||
|
hkReceiver.objectId = destinationObject;
|
||||||
|
if(generateSnapshot) {
|
||||||
|
hkReceiver.reportingType = ReportingType::UPDATE_SNAPSHOT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hkReceiver.reportingType = ReportingType::UPDATE_NOTIFICATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
hkReceiversMap.push_back(hkReceiver);
|
||||||
|
|
||||||
|
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType,
|
||||||
|
DataId dataId) {
|
||||||
|
if(hkUpdateResetList == nullptr) {
|
||||||
|
hkUpdateResetList = new std::vector<struct HkUpdateResetHelper>();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& updateResetStruct: *hkUpdateResetList) {
|
||||||
|
if(dataType == DataType::DATA_SET) {
|
||||||
|
if(updateResetStruct.dataId.sid == dataId.sid) {
|
||||||
|
updateResetStruct.updateCounter++;
|
||||||
|
updateResetStruct.currentUpdateCounter++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(updateResetStruct.dataId.localPoolId == dataId.localPoolId) {
|
||||||
|
updateResetStruct.updateCounter++;
|
||||||
|
updateResetStruct.currentUpdateCounter++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
HkUpdateResetHelper hkUpdateResetHelper;
|
||||||
|
hkUpdateResetHelper.currentUpdateCounter = 1;
|
||||||
|
hkUpdateResetHelper.updateCounter = 1;
|
||||||
|
hkUpdateResetHelper.dataType = dataType;
|
||||||
|
if(dataType == DataType::DATA_SET) {
|
||||||
|
hkUpdateResetHelper.dataId.sid = dataId.sid;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId;
|
||||||
|
}
|
||||||
|
hkUpdateResetList->push_back(hkUpdateResetHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
|
||||||
|
CommandMessage* message) {
|
||||||
|
Command_t command = message->getCommand();
|
||||||
|
sid_t sid = HousekeepingMessage::getSid(message);
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
switch(command) {
|
||||||
|
// Houskeeping interface handling.
|
||||||
|
case(HousekeepingMessage::ENABLE_PERIODIC_DIAGNOSTICS_GENERATION): {
|
||||||
|
result = togglePeriodicGeneration(sid, true, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case(HousekeepingMessage::DISABLE_PERIODIC_DIAGNOSTICS_GENERATION): {
|
||||||
|
result = togglePeriodicGeneration(sid, false, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case(HousekeepingMessage::ENABLE_PERIODIC_HK_REPORT_GENERATION): {
|
||||||
|
result = togglePeriodicGeneration(sid, true, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case(HousekeepingMessage::DISABLE_PERIODIC_HK_REPORT_GENERATION): {
|
||||||
|
result = togglePeriodicGeneration(sid, false, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES):
|
||||||
|
return generateSetStructurePacket(sid, true);
|
||||||
|
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES):
|
||||||
|
return generateSetStructurePacket(sid, false);
|
||||||
|
case(HousekeepingMessage::MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL):
|
||||||
|
case(HousekeepingMessage::MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL): {
|
||||||
|
float newCollIntvl = 0;
|
||||||
|
HousekeepingMessage::getCollectionIntervalModificationCommand(message,
|
||||||
|
&newCollIntvl);
|
||||||
|
if(command == HousekeepingMessage::
|
||||||
|
MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL) {
|
||||||
|
result = changeCollectionInterval(sid, newCollIntvl, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = changeCollectionInterval(sid, newCollIntvl, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
|
||||||
|
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): {
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
if(command == HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT
|
||||||
|
and dataSet->isDiagnostics()) {
|
||||||
|
return WRONG_HK_PACKET_TYPE;
|
||||||
|
}
|
||||||
|
else if(command == HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT
|
||||||
|
and not dataSet->isDiagnostics()) {
|
||||||
|
return WRONG_HK_PACKET_TYPE;
|
||||||
|
}
|
||||||
|
return generateHousekeepingPacket(HousekeepingMessage::getSid(message),
|
||||||
|
dataSet, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notification handling.
|
||||||
|
case(HousekeepingMessage::UPDATE_NOTIFICATION_SET): {
|
||||||
|
owner->handleChangedDataset(sid);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
case(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE): {
|
||||||
|
lp_id_t locPoolId = HousekeepingMessage::
|
||||||
|
getUpdateNotificationVariableCommand(message);
|
||||||
|
owner->handleChangedPoolVariable(locPoolId);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
case(HousekeepingMessage::UPDATE_SNAPSHOT_SET): {
|
||||||
|
store_address_t storeId;
|
||||||
|
HousekeepingMessage::getUpdateSnapshotSetCommand(message, &storeId);
|
||||||
|
owner->handleChangedDataset(sid, storeId);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
case(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE): {
|
||||||
|
store_address_t storeId;
|
||||||
|
lp_id_t localPoolId = HousekeepingMessage::
|
||||||
|
getUpdateSnapshotVariableCommand(message, &storeId);
|
||||||
|
owner->handleChangedPoolVariable(localPoolId, storeId);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return CommandMessageIF::UNKNOWN_COMMAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandMessage reply;
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
HousekeepingMessage::setHkRequestFailureReply(&reply, sid, result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HousekeepingMessage::setHkRequestSuccessReply(&reply, sid);
|
||||||
|
}
|
||||||
|
hkQueue->sendMessage(hkDestinationId, &reply);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::printPoolEntry(
|
||||||
|
lp_id_t localPoolId) {
|
||||||
|
auto poolIter = localPoolMap.find(localPoolId);
|
||||||
|
if (poolIter == localPoolMap.end()) {
|
||||||
|
sif::debug << "HousekeepingManager::fechPoolEntry:"
|
||||||
|
<< " Pool entry not found." << std::endl;
|
||||||
|
return POOL_ENTRY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
poolIter->second->print();
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
MutexIF* LocalDataPoolManager::getMutexHandle() {
|
||||||
|
return mutex;
|
||||||
|
}
|
||||||
|
|
||||||
|
HasLocalDataPoolIF* LocalDataPoolManager::getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
|
||||||
|
LocalPoolDataSetBase* dataSet, bool forDownlink,
|
||||||
|
MessageQueueId_t destination) {
|
||||||
|
if(dataSet == nullptr) {
|
||||||
|
// Configuration error.
|
||||||
|
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
|
||||||
|
<< " Set ID not found or dataset not assigned!" << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
store_address_t storeId;
|
||||||
|
HousekeepingPacketDownlink hkPacket(sid, dataSet);
|
||||||
|
size_t serializedSize = 0;
|
||||||
|
ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, storeId,
|
||||||
|
forDownlink, &serializedSize);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK or serializedSize == 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// and now we set a HK message and send it the HK packet destination.
|
||||||
|
CommandMessage hkMessage;
|
||||||
|
if(dataSet->isDiagnostics()) {
|
||||||
|
HousekeepingMessage::setHkDiagnosticsReply(&hkMessage, sid, storeId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HousekeepingMessage::setHkReportReply(&hkMessage, sid, storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hkQueue == nullptr) {
|
||||||
|
return QUEUE_OR_DESTINATION_NOT_SET;
|
||||||
|
}
|
||||||
|
if(destination == MessageQueueIF::NO_QUEUE) {
|
||||||
|
if(hkDestinationId == MessageQueueIF::NO_QUEUE) {
|
||||||
|
// error, all destinations invalid
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
destination = hkDestinationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hkQueue->sendMessage(destination, &hkMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
|
||||||
|
HousekeepingPacketDownlink& hkPacket,
|
||||||
|
store_address_t& storeId, bool forDownlink,
|
||||||
|
size_t* serializedSize) {
|
||||||
|
uint8_t* dataPtr = nullptr;
|
||||||
|
const size_t maxSize = hkPacket.getSerializedSize();
|
||||||
|
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||||
|
maxSize, &dataPtr);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(forDownlink) {
|
||||||
|
return hkPacket.serialize(&dataPtr, serializedSize, maxSize,
|
||||||
|
SerializeIF::Endianness::BIG);
|
||||||
|
}
|
||||||
|
return hkPacket.serialize(&dataPtr, serializedSize, maxSize,
|
||||||
|
SerializeIF::Endianness::MACHINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalDataPoolManager::setNonDiagnosticIntervalFactor(
|
||||||
|
uint8_t nonDiagInvlFactor) {
|
||||||
|
this->nonDiagnosticIntervalFactor = nonDiagInvlFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) {
|
||||||
|
sid_t sid = receiver.dataId.sid;
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
if(not dataSet->getReportingEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dataSet->periodicHelper == nullptr) {
|
||||||
|
// Configuration error.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(not dataSet->periodicHelper->checkOpNecessary()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t result = generateHousekeepingPacket(
|
||||||
|
sid, dataSet, true);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
// configuration error
|
||||||
|
sif::debug << "LocalDataPoolManager::performHkOperation:"
|
||||||
|
<< "0x" << std::hex << std::setfill('0') << std::setw(8)
|
||||||
|
<< owner->getObjectId() << " Error generating "
|
||||||
|
<< "HK packet" << std::setfill(' ') << std::dec << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid,
|
||||||
|
bool enable, bool isDiagnostics) {
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
if((dataSet->isDiagnostics() and not isDiagnostics) or
|
||||||
|
(not dataSet->isDiagnostics() and isDiagnostics)) {
|
||||||
|
return WRONG_HK_PACKET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((dataSet->getReportingEnabled() and enable) or
|
||||||
|
(not dataSet->getReportingEnabled() and not enable)) {
|
||||||
|
return REPORTING_STATUS_UNCHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataSet->setReportingEnabled(enable);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
|
||||||
|
float newCollectionInterval, bool isDiagnostics) {
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
bool targetIsDiagnostics = dataSet->isDiagnostics();
|
||||||
|
if((targetIsDiagnostics and not isDiagnostics) or
|
||||||
|
(not targetIsDiagnostics and isDiagnostics)) {
|
||||||
|
return WRONG_HK_PACKET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dataSet->periodicHelper == nullptr) {
|
||||||
|
// config error
|
||||||
|
return PERIODIC_HELPER_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataSet->periodicHelper->changeCollectionInterval(newCollectionInterval);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
|
||||||
|
bool isDiagnostics) {
|
||||||
|
// Get and check dataset first.
|
||||||
|
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
|
||||||
|
if(dataSet == nullptr) {
|
||||||
|
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
|
||||||
|
<< " Set ID not found" << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool targetIsDiagnostics = dataSet->isDiagnostics();
|
||||||
|
if((targetIsDiagnostics and not isDiagnostics) or
|
||||||
|
(not targetIsDiagnostics and isDiagnostics)) {
|
||||||
|
return WRONG_HK_PACKET_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid = dataSet->isValid();
|
||||||
|
bool reportingEnabled = dataSet->getReportingEnabled();
|
||||||
|
float collectionInterval =
|
||||||
|
dataSet->periodicHelper->getCollectionIntervalInSeconds();
|
||||||
|
|
||||||
|
// Generate set packet which can be serialized.
|
||||||
|
HousekeepingSetPacket setPacket(sid,
|
||||||
|
reportingEnabled, valid, collectionInterval, dataSet);
|
||||||
|
size_t expectedSize = setPacket.getSerializedSize();
|
||||||
|
uint8_t* storePtr = nullptr;
|
||||||
|
store_address_t storeId;
|
||||||
|
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
|
||||||
|
expectedSize,&storePtr);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
|
||||||
|
<< "Could not get free element from IPC store." << std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize set packet into store.
|
||||||
|
size_t size = 0;
|
||||||
|
result = setPacket.serialize(&storePtr, &size, expectedSize,
|
||||||
|
SerializeIF::Endianness::BIG);
|
||||||
|
if(expectedSize != size) {
|
||||||
|
sif::error << "HousekeepingManager::generateSetStructurePacket: "
|
||||||
|
<< "Expected size is not equal to serialized size" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send structure reporting reply.
|
||||||
|
CommandMessage reply;
|
||||||
|
if(isDiagnostics) {
|
||||||
|
HousekeepingMessage::setDiagnosticsStuctureReportReply(&reply,
|
||||||
|
sid, storeId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HousekeepingMessage::setHkStuctureReportReply(&reply,
|
||||||
|
sid, storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
hkQueue->reply(&reply);
|
||||||
|
return result;
|
||||||
|
}
|
396
datapoollocal/LocalDataPoolManager.h
Normal file
396
datapoollocal/LocalDataPoolManager.h
Normal file
@ -0,0 +1,396 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
|
||||||
|
|
||||||
|
#include "HasLocalDataPoolIF.h"
|
||||||
|
|
||||||
|
#include "../housekeeping/HousekeepingPacketDownlink.h"
|
||||||
|
#include "../housekeeping/HousekeepingMessage.h"
|
||||||
|
#include "../housekeeping/PeriodicHousekeepingHelper.h"
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../datapool/PoolEntry.h"
|
||||||
|
#include "../objectmanager/SystemObjectIF.h"
|
||||||
|
#include "../ipc/MutexIF.h"
|
||||||
|
#include "../ipc/CommandMessage.h"
|
||||||
|
#include "../ipc/MessageQueueIF.h"
|
||||||
|
#include "../ipc/MutexHelper.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace Factory {
|
||||||
|
void setStaticFrameworkObjectIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocalPoolDataSetBase;
|
||||||
|
class HousekeepingPacketUpdate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class is the managing instance for the local data pool.
|
||||||
|
* @details
|
||||||
|
* The actual data pool structure is a member of this class. Any class which
|
||||||
|
* has a local data pool shall have this manager class as a member and implement
|
||||||
|
* the HasLocalDataPoolIF.
|
||||||
|
*
|
||||||
|
* The manager offers some adaption points and functions which can be used
|
||||||
|
* by the owning class to simplify data handling significantly.
|
||||||
|
*
|
||||||
|
* Please ensure that both initialize and initializeAfterTaskCreation are
|
||||||
|
* called at some point by the owning class in the respective functions of the
|
||||||
|
* same name!
|
||||||
|
*
|
||||||
|
* Users of the data pool use the helper classes LocalDataSet,
|
||||||
|
* LocalPoolVariable and LocalPoolVector to access pool entries in
|
||||||
|
* a thread-safe and efficient way.
|
||||||
|
*
|
||||||
|
* The local data pools employ a blackboard logic: Only the most recent
|
||||||
|
* value is stored. The helper classes offer a read() and commit() interface
|
||||||
|
* through the PoolVariableIF which is used to read and update values.
|
||||||
|
* Each pool entry has a valid state too.
|
||||||
|
* @author R. Mueller
|
||||||
|
*/
|
||||||
|
class LocalDataPoolManager {
|
||||||
|
template<typename T> friend class LocalPoolVar;
|
||||||
|
template<typename T, uint16_t vecSize> friend class LocalPoolVector;
|
||||||
|
friend class LocalPoolDataSetBase;
|
||||||
|
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||||
|
public:
|
||||||
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER;
|
||||||
|
|
||||||
|
static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x00);
|
||||||
|
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x01);
|
||||||
|
|
||||||
|
static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x02);
|
||||||
|
|
||||||
|
static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(0x03);
|
||||||
|
static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(0x04);
|
||||||
|
static constexpr ReturnValue_t PERIODIC_HELPER_INVALID = MAKE_RETURN_CODE(0x05);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is used by a class which wants to implement
|
||||||
|
* a personal local data pool. The queueToUse can be supplied if it
|
||||||
|
* is already known.
|
||||||
|
*
|
||||||
|
* initialize() has to be called in any case before using the object!
|
||||||
|
* @param owner
|
||||||
|
* @param queueToUse
|
||||||
|
* @param appendValidityBuffer Specify whether a buffer containing the
|
||||||
|
* validity state is generated when serializing or deserializing packets.
|
||||||
|
*/
|
||||||
|
LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse,
|
||||||
|
bool appendValidityBuffer = true);
|
||||||
|
virtual~ LocalDataPoolManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns the queue to use. Make sure to call this in the #initialize
|
||||||
|
* function of the owner.
|
||||||
|
* @param queueToUse
|
||||||
|
* @param nonDiagInvlFactor See #setNonDiagnosticIntervalFactor doc
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t initialize(MessageQueueIF* queueToUse);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the map by calling the map initialization function and
|
||||||
|
* setting the periodic factor for non-diagnostic packets.
|
||||||
|
* Don't forget to call this in the #initializeAfterTaskCreation call of
|
||||||
|
* the owner, otherwise the map will be invalid!
|
||||||
|
* @param nonDiagInvlFactor
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t initializeAfterTaskCreation(
|
||||||
|
uint8_t nonDiagInvlFactor = 5);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This should be called in the periodic handler of the owner.
|
||||||
|
* @details
|
||||||
|
* This in generally called in the #performOperation function of the owner.
|
||||||
|
* It performs all the periodic functionalities of the data pool manager,
|
||||||
|
* for example generating periodic HK packets.
|
||||||
|
* Marked virtual as an adaption point for custom data pool managers.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t performHkOperation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Subscribe for the generation of periodic packets.
|
||||||
|
* @details
|
||||||
|
* This subscription mechanism will generally be used by the data creator
|
||||||
|
* to generate housekeeping packets which are downlinked directly.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting,
|
||||||
|
float collectionInterval, bool isDiagnostics,
|
||||||
|
object_id_t packetDestination = defaultHkDestination);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Subscribe for the generation of packets if the dataset
|
||||||
|
* is marked as changed.
|
||||||
|
* @details
|
||||||
|
* This subscription mechanism will generally be used by the data creator.
|
||||||
|
* @param sid
|
||||||
|
* @param isDiagnostics
|
||||||
|
* @param packetDestination
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t subscribeForUpdatePackets(sid_t sid, bool reportingEnabled,
|
||||||
|
bool isDiagnostics,
|
||||||
|
object_id_t packetDestination = defaultHkDestination);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Subscribe for a notification message which will be sent
|
||||||
|
* if a dataset has changed.
|
||||||
|
* @details
|
||||||
|
* This subscription mechanism will generally be used internally by
|
||||||
|
* other software components.
|
||||||
|
* @param setId Set ID of the set to receive update messages from.
|
||||||
|
* @param destinationObject
|
||||||
|
* @param targetQueueId
|
||||||
|
* @param generateSnapshot If this is set to true, a copy of the current
|
||||||
|
* data with a timestamp will be generated and sent via message.
|
||||||
|
* Otherwise, only an notification message is sent.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t subscribeForSetUpdateMessages(const uint32_t setId,
|
||||||
|
object_id_t destinationObject,
|
||||||
|
MessageQueueId_t targetQueueId,
|
||||||
|
bool generateSnapshot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Subscribe for an notification message which will be sent if a
|
||||||
|
* pool variable has changed.
|
||||||
|
* @details
|
||||||
|
* This subscription mechanism will generally be used internally by
|
||||||
|
* other software components.
|
||||||
|
* @param localPoolId Pool ID of the pool variable
|
||||||
|
* @param destinationObject
|
||||||
|
* @param targetQueueId
|
||||||
|
* @param generateSnapshot If this is set to true, a copy of the current
|
||||||
|
* data with a timestamp will be generated and sent via message.
|
||||||
|
* Otherwise, only an notification message is sent.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t subscribeForVariableUpdateMessages(const lp_id_t localPoolId,
|
||||||
|
object_id_t destinationObject,
|
||||||
|
MessageQueueId_t targetQueueId,
|
||||||
|
bool generateSnapshot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-Diagnostics packets usually have a lower minimum sampling frequency
|
||||||
|
* than diagnostic packets.
|
||||||
|
* A factor can be specified to determine the minimum sampling frequency
|
||||||
|
* for non-diagnostic packets. The minimum sampling frequency of the
|
||||||
|
* diagnostics packets,which is usually jusst the period of the
|
||||||
|
* performOperation calls, is multiplied with that factor.
|
||||||
|
* @param factor
|
||||||
|
*/
|
||||||
|
void setNonDiagnosticIntervalFactor(uint8_t nonDiagInvlFactor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The manager is also able to handle housekeeping messages.
|
||||||
|
* @details
|
||||||
|
* This most commonly is used to handle messages for the housekeeping
|
||||||
|
* interface, but the manager is also able to handle update notifications
|
||||||
|
* and calls a special function which can be overriden by a child class
|
||||||
|
* to handle data set or pool variable updates. This is relevant
|
||||||
|
* for classes like controllers which have their own local datapool
|
||||||
|
* but pull their data from other local datapools.
|
||||||
|
* @param message
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a housekeeping packet with a given SID.
|
||||||
|
* @param sid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t generateHousekeepingPacket(sid_t sid,
|
||||||
|
LocalPoolDataSetBase* dataSet, bool forDownlink,
|
||||||
|
MessageQueueId_t destination = MessageQueueIF::NO_QUEUE);
|
||||||
|
|
||||||
|
HasLocalDataPoolIF* getOwner();
|
||||||
|
|
||||||
|
ReturnValue_t printPoolEntry(lp_id_t localPoolId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different types of housekeeping reporting are possible.
|
||||||
|
* 1. PERIODIC:
|
||||||
|
* HK packets are generated in fixed intervals and sent to
|
||||||
|
* destination. Fromat will be raw.
|
||||||
|
* 2. UPDATE_NOTIFICATION:
|
||||||
|
* Notification will be sent out if HK data has changed.
|
||||||
|
* 3. UPDATE_SNAPSHOT:
|
||||||
|
* HK packets are only generated if explicitely requested.
|
||||||
|
* Propably not necessary, just use multiple local data sets or
|
||||||
|
* shared datasets.
|
||||||
|
*/
|
||||||
|
enum class ReportingType: uint8_t {
|
||||||
|
//! Periodic generation of HK packets.
|
||||||
|
PERIODIC,
|
||||||
|
//! Housekeeping packet will be generated if values have changed.
|
||||||
|
UPDATE_HK,
|
||||||
|
//! Update notification will be sent out as message.
|
||||||
|
UPDATE_NOTIFICATION,
|
||||||
|
//! Notification will be sent out as message and a snapshot of the
|
||||||
|
//! current data will be generated.
|
||||||
|
UPDATE_SNAPSHOT,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different data types are possible in the HK receiver map.
|
||||||
|
* For example, updates can be requested for full datasets or
|
||||||
|
* for single pool variables. Periodic reporting is only possible for
|
||||||
|
* data sets.
|
||||||
|
*/
|
||||||
|
enum class DataType: uint8_t {
|
||||||
|
LOCAL_POOL_VARIABLE,
|
||||||
|
DATA_SET
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Copying forbidden */
|
||||||
|
LocalDataPoolManager(const LocalDataPoolManager &) = delete;
|
||||||
|
LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
LocalDataPool localPoolMap;
|
||||||
|
//! 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). */
|
||||||
|
HasLocalDataPoolIF* owner = nullptr;
|
||||||
|
|
||||||
|
uint8_t nonDiagnosticIntervalFactor = 0;
|
||||||
|
|
||||||
|
/** Default receiver for periodic HK packets */
|
||||||
|
static object_id_t defaultHkDestination;
|
||||||
|
MessageQueueId_t hkDestinationId = MessageQueueIF::NO_QUEUE;
|
||||||
|
|
||||||
|
union DataId {
|
||||||
|
DataId(): sid() {};
|
||||||
|
sid_t sid;
|
||||||
|
lp_id_t localPoolId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The data pool manager will keep an internal map of HK receivers. */
|
||||||
|
struct HkReceiver {
|
||||||
|
/** Object ID of receiver */
|
||||||
|
object_id_t objectId = objects::NO_OBJECT;
|
||||||
|
|
||||||
|
DataType dataType = DataType::DATA_SET;
|
||||||
|
DataId dataId;
|
||||||
|
|
||||||
|
ReportingType reportingType = ReportingType::PERIODIC;
|
||||||
|
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** This vector will contain the list of HK receivers. */
|
||||||
|
using HkReceivers = std::vector<struct HkReceiver>;
|
||||||
|
|
||||||
|
HkReceivers hkReceiversMap;
|
||||||
|
|
||||||
|
struct HkUpdateResetHelper {
|
||||||
|
DataType dataType = DataType::DATA_SET;
|
||||||
|
DataId dataId;
|
||||||
|
uint8_t updateCounter;
|
||||||
|
uint8_t currentUpdateCounter;
|
||||||
|
};
|
||||||
|
|
||||||
|
using HkUpdateResetList = std::vector<struct HkUpdateResetHelper>;
|
||||||
|
// Will only be created when needed.
|
||||||
|
HkUpdateResetList* hkUpdateResetList = nullptr;
|
||||||
|
|
||||||
|
/** This is the map holding the actual data. Should only be initialized
|
||||||
|
* once ! */
|
||||||
|
bool mapInitialized = false;
|
||||||
|
/** This specifies whether a validity buffer is appended at the end
|
||||||
|
* of generated housekeeping packets. */
|
||||||
|
bool appendValidityBuffer = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Queue used for communication, for example commands.
|
||||||
|
* Is also used to send messages. Can be set either in the constructor
|
||||||
|
* or in the initialize() function.
|
||||||
|
*/
|
||||||
|
MessageQueueIF* hkQueue = nullptr;
|
||||||
|
|
||||||
|
/** Global IPC store is used to store all packets. */
|
||||||
|
StorageManagerIF* ipcStore = nullptr;
|
||||||
|
/**
|
||||||
|
* Get the pointer to the mutex. Can be used to lock the data pool
|
||||||
|
* externally. Use with care and don't forget to unlock locked mutexes!
|
||||||
|
* For now, only friend classes can accss this function.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MutexIF* getMutexHandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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!
|
||||||
|
* For now, only friend classes like LocalPoolVar may access this
|
||||||
|
* function.
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used to fill the local data pool map with pool
|
||||||
|
* entries. It should only be called once by the pool owner.
|
||||||
|
* @param localDataPoolMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t initializeHousekeepingPoolEntriesOnce();
|
||||||
|
|
||||||
|
ReturnValue_t serializeHkPacketIntoStore(
|
||||||
|
HousekeepingPacketDownlink& hkPacket,
|
||||||
|
store_address_t& storeId, bool forDownlink, size_t* serializedSize);
|
||||||
|
|
||||||
|
void performPeriodicHkGeneration(HkReceiver& hkReceiver);
|
||||||
|
ReturnValue_t togglePeriodicGeneration(sid_t sid, bool enable,
|
||||||
|
bool isDiagnostics);
|
||||||
|
ReturnValue_t changeCollectionInterval(sid_t sid,
|
||||||
|
float newCollectionInterval, bool isDiagnostics);
|
||||||
|
ReturnValue_t generateSetStructurePacket(sid_t sid, bool isDiagnostics);
|
||||||
|
|
||||||
|
void handleHkUpdateResetListInsertion(DataType dataType, DataId dataId);
|
||||||
|
void handleChangeResetLogic(DataType type,
|
||||||
|
DataId dataId, MarkChangedIF* toReset);
|
||||||
|
void resetHkUpdateResetHelper();
|
||||||
|
|
||||||
|
ReturnValue_t handleHkUpdate(HkReceiver& hkReceiver,
|
||||||
|
ReturnValue_t& status);
|
||||||
|
ReturnValue_t handleNotificationUpdate(HkReceiver& hkReceiver,
|
||||||
|
ReturnValue_t& status);
|
||||||
|
ReturnValue_t handleNotificationSnapshot(HkReceiver& hkReceiver,
|
||||||
|
ReturnValue_t& status);
|
||||||
|
ReturnValue_t addUpdateToStore(HousekeepingPacketUpdate& updatePacket,
|
||||||
|
store_address_t& storeId);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T> inline
|
||||||
|
ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
|
||||||
|
PoolEntry<T> **poolEntry) {
|
||||||
|
auto poolIter = localPoolMap.find(localPoolId);
|
||||||
|
if (poolIter == localPoolMap.end()) {
|
||||||
|
sif::warning << "HousekeepingManager::fechPoolEntry: Pool entry "
|
||||||
|
"not found." << std::endl;
|
||||||
|
return POOL_ENTRY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
|
||||||
|
if(*poolEntry == nullptr) {
|
||||||
|
sif::debug << "HousekeepingManager::fetchPoolEntry:"
|
||||||
|
" Pool entry not found." << std::endl;
|
||||||
|
return POOL_ENTRY_TYPE_CONFLICT;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ */
|
22
datapoollocal/LocalDataSet.cpp
Normal file
22
datapoollocal/LocalDataSet.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "LocalDataSet.h"
|
||||||
|
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
LocalDataSet::LocalDataSet(HasLocalDataPoolIF *hkOwner, uint32_t setId,
|
||||||
|
const size_t maxNumberOfVariables):
|
||||||
|
LocalPoolDataSetBase(hkOwner, setId, nullptr, maxNumberOfVariables),
|
||||||
|
poolVarList(maxNumberOfVariables) {
|
||||||
|
this->setContainer(poolVarList.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDataSet::LocalDataSet(sid_t sid, const size_t maxNumberOfVariables):
|
||||||
|
LocalPoolDataSetBase(sid, nullptr, maxNumberOfVariables),
|
||||||
|
poolVarList(maxNumberOfVariables) {
|
||||||
|
this->setContainer(poolVarList.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDataSet::~LocalDataSet() {}
|
||||||
|
|
21
datapoollocal/LocalDataSet.h
Normal file
21
datapoollocal/LocalDataSet.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALDATASET_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALDATASET_H_
|
||||||
|
|
||||||
|
#include "LocalPoolDataSetBase.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class LocalDataSet: public LocalPoolDataSetBase {
|
||||||
|
public:
|
||||||
|
LocalDataSet(HasLocalDataPoolIF* hkOwner, uint32_t setId,
|
||||||
|
const size_t maxSize);
|
||||||
|
LocalDataSet(sid_t sid, const size_t maxSize);
|
||||||
|
virtual~ LocalDataSet();
|
||||||
|
|
||||||
|
//! Copying forbidden for now.
|
||||||
|
LocalDataSet(const LocalDataSet&) = delete;
|
||||||
|
LocalDataSet& operator=(const LocalDataSet&) = delete;
|
||||||
|
private:
|
||||||
|
std::vector<PoolVariableIF*> poolVarList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALDATASET_H_ */
|
278
datapoollocal/LocalPoolDataSetBase.cpp
Normal file
278
datapoollocal/LocalPoolDataSetBase.cpp
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
#include "LocalPoolDataSetBase.h"
|
||||||
|
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||||
|
#include "../housekeeping/PeriodicHousekeepingHelper.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||||
|
uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
||||||
|
const size_t maxNumberOfVariables, bool noPeriodicHandling):
|
||||||
|
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||||
|
if(hkOwner == nullptr) {
|
||||||
|
// Configuration error.
|
||||||
|
sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
||||||
|
<< "invalid!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hkManager = hkOwner->getHkManagerHandle();
|
||||||
|
this->sid.objectId = hkOwner->getObjectId();
|
||||||
|
this->sid.ownerSetId = setId;
|
||||||
|
|
||||||
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
|
|
||||||
|
// Data creators get a periodic helper for periodic HK data generation.
|
||||||
|
if(not noPeriodicHandling) {
|
||||||
|
periodicHelper = new PeriodicHousekeepingHelper(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid,
|
||||||
|
PoolVariableIF** registeredVariablesArray,
|
||||||
|
const size_t maxNumberOfVariables):
|
||||||
|
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||||
|
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
||||||
|
sid.objectId);
|
||||||
|
if(hkOwner == nullptr) {
|
||||||
|
// Configuration error.
|
||||||
|
sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
||||||
|
<< "invalid!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hkManager = hkOwner->getHkManagerHandle();
|
||||||
|
this->sid = sid;
|
||||||
|
|
||||||
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalPoolDataSetBase::~LocalPoolDataSetBase() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::lockDataPool(uint32_t timeoutMs) {
|
||||||
|
MutexIF* mutex = hkManager->getMutexHandle();
|
||||||
|
return mutex->lockMutex(MutexIF::TimeoutType::WAITING, timeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer,
|
||||||
|
size_t *size, size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness) const {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||||
|
uint8_t validityMask[validityMaskSize];
|
||||||
|
uint8_t validBufferIndex = 0;
|
||||||
|
uint8_t validBufferIndexBit = 0;
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
if(registeredVariables[count]->isValid()) {
|
||||||
|
// set validity buffer here.
|
||||||
|
this->bitSetter(validityMask + validBufferIndex,
|
||||||
|
validBufferIndexBit);
|
||||||
|
if(validBufferIndexBit == 7) {
|
||||||
|
validBufferIndex ++;
|
||||||
|
validBufferIndexBit = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
validBufferIndexBit ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||||
|
streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*size + validityMaskSize > maxSize) {
|
||||||
|
return SerializeIF::BUFFER_TOO_SHORT;
|
||||||
|
}
|
||||||
|
// copy validity buffer to end
|
||||||
|
std::memcpy(*buffer, validityMask, validityMaskSize);
|
||||||
|
*size += validityMaskSize;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
||||||
|
const uint8_t **buffer, size_t *size,
|
||||||
|
SerializeIF::Endianness streamEndianness) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||||
|
streamEndianness);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*size < std::ceil(static_cast<float>(fillCount) / 8.0)) {
|
||||||
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t validBufferIndex = 0;
|
||||||
|
uint8_t validBufferIndexBit = 0;
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
// set validity buffer here.
|
||||||
|
bool nextVarValid = this->bitGetter(*buffer +
|
||||||
|
validBufferIndex, validBufferIndexBit);
|
||||||
|
registeredVariables[count]->setValid(nextVarValid);
|
||||||
|
|
||||||
|
if(validBufferIndexBit == 7) {
|
||||||
|
validBufferIndex ++;
|
||||||
|
validBufferIndexBit = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
validBufferIndexBit ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
|
||||||
|
MutexIF* mutex = hkManager->getMutexHandle();
|
||||||
|
return mutex->unlockMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer,
|
||||||
|
size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness,
|
||||||
|
bool serializeFillCount) const {
|
||||||
|
// Serialize as uint8_t
|
||||||
|
uint8_t fillCount = this->fillCount;
|
||||||
|
if(serializeFillCount) {
|
||||||
|
SerializeAdapter::serialize(&fillCount, buffer, size, maxSize,
|
||||||
|
streamEndianness);
|
||||||
|
}
|
||||||
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
|
lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId();
|
||||||
|
auto result = SerializeAdapter::serialize(¤tPoolId, buffer,
|
||||||
|
size, maxSize, streamEndianness);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::warning << "LocalDataSet::serializeLocalPoolIds: Serialization"
|
||||||
|
" error!" << std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize(
|
||||||
|
bool serializeFillCount) const {
|
||||||
|
if(serializeFillCount) {
|
||||||
|
return fillCount * sizeof(lp_id_t) + sizeof(uint8_t);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return fillCount * sizeof(lp_id_t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t LocalPoolDataSetBase::getSerializedSize() const {
|
||||||
|
if(withValidityBuffer) {
|
||||||
|
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
||||||
|
return validityMaskSize + PoolDataSetBase::getSerializedSize();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return PoolDataSetBase::getSerializedSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::setValidityBufferGeneration(
|
||||||
|
bool withValidityBuffer) {
|
||||||
|
this->withValidityBuffer = withValidityBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer,
|
||||||
|
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||||
|
if(withValidityBuffer) {
|
||||||
|
return this->deSerializeWithValidityBuffer(buffer, size,
|
||||||
|
streamEndianness);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return PoolDataSetBase::deSerialize(buffer, size, streamEndianness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size,
|
||||||
|
size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
||||||
|
if(withValidityBuffer) {
|
||||||
|
return this->serializeWithValidityBuffer(buffer, size,
|
||||||
|
maxSize, streamEndianness);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return PoolDataSetBase::serialize(buffer, size, maxSize,
|
||||||
|
streamEndianness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const {
|
||||||
|
if(position > 7) {
|
||||||
|
sif::debug << "Pool Raw Access: Bit setting invalid position"
|
||||||
|
<< std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
||||||
|
*byte |= 1 << shiftNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) {
|
||||||
|
this->diagnostic = isDiagnostics;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolDataSetBase::isDiagnostics() const {
|
||||||
|
return diagnostic;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) {
|
||||||
|
this->reportingEnabled = reportingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolDataSetBase::getReportingEnabled() const {
|
||||||
|
return reportingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::initializePeriodicHelper(
|
||||||
|
float collectionInterval, dur_millis_t minimumPeriodicInterval,
|
||||||
|
bool isDiagnostics, uint8_t nonDiagIntervalFactor) {
|
||||||
|
periodicHelper->initialize(collectionInterval, minimumPeriodicInterval,
|
||||||
|
isDiagnostics, nonDiagIntervalFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::setChanged(bool changed) {
|
||||||
|
// TODO: Make this configurable?
|
||||||
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
|
this->changed = changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolDataSetBase::hasChanged() const {
|
||||||
|
// TODO: Make this configurable?
|
||||||
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t LocalPoolDataSetBase::getSid() const {
|
||||||
|
return sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte,
|
||||||
|
uint8_t position) const {
|
||||||
|
if(position > 7) {
|
||||||
|
sif::debug << "Pool Raw Access: Bit setting invalid position"
|
||||||
|
<< std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
||||||
|
return *byte & (1 << shiftNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolDataSetBase::isValid() const {
|
||||||
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 5);
|
||||||
|
return this->valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
|
||||||
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 5);
|
||||||
|
if(setEntriesRecursively) {
|
||||||
|
for(size_t idx = 0; idx < this->getFillCount(); idx++) {
|
||||||
|
registeredVariables[idx] -> setValid(valid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->valid = valid;
|
||||||
|
}
|
198
datapoollocal/LocalPoolDataSetBase.h
Normal file
198
datapoollocal/LocalPoolDataSetBase.h
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
|
||||||
|
|
||||||
|
#include "HasLocalDataPoolIF.h"
|
||||||
|
#include "MarkChangedIF.h"
|
||||||
|
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../datapool/PoolDataSetBase.h"
|
||||||
|
#include "../serialize/SerializeIF.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class LocalDataPoolManager;
|
||||||
|
class PeriodicHousekeepingHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The LocalDataSet class manages a set of locally checked out
|
||||||
|
* variables for local data pools
|
||||||
|
* @details
|
||||||
|
* Extends the PoolDataSetBase class for local data pools by introducing
|
||||||
|
* a validity state, a flag to mark the set as changed, and various other
|
||||||
|
* functions to make it usable by the LocalDataPoolManager class.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Pool variables can be added to the dataset by using the constructor
|
||||||
|
* argument of the pool variable or using the #registerVariable member function.
|
||||||
|
*
|
||||||
|
* An internal state manages usage of this class. Variables may only be
|
||||||
|
* registered before any read call is made, and the commit call can only happen
|
||||||
|
* 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 LocalPoolDataSetBase: public PoolDataSetBase,
|
||||||
|
public MarkChangedIF {
|
||||||
|
friend class LocalDataPoolManager;
|
||||||
|
friend class PeriodicHousekeepingHelper;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor for the creator of local pool data.
|
||||||
|
* @details
|
||||||
|
* This constructor also initializes the components required for
|
||||||
|
* periodic handling.
|
||||||
|
*/
|
||||||
|
LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||||
|
uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
||||||
|
const size_t maxNumberOfVariables, bool noPeriodicHandling = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor for users of local pool data.
|
||||||
|
* @details
|
||||||
|
* @param sid Unique identifier of dataset consisting of object ID and
|
||||||
|
* set ID.
|
||||||
|
* @param registeredVariablesArray
|
||||||
|
* @param maxNumberOfVariables
|
||||||
|
*/
|
||||||
|
LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
|
||||||
|
const size_t maxNumberOfVariables);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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".
|
||||||
|
*/
|
||||||
|
~LocalPoolDataSetBase();
|
||||||
|
|
||||||
|
void setValidityBufferGeneration(bool withValidityBuffer);
|
||||||
|
|
||||||
|
sid_t getSid() const;
|
||||||
|
|
||||||
|
/** SerializeIF overrides */
|
||||||
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness) const override;
|
||||||
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size,
|
||||||
|
SerializeIF::Endianness streamEndianness) override;
|
||||||
|
size_t getSerializedSize() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special version of the serilization function which appends a
|
||||||
|
* validity buffer at the end. Each bit of this validity buffer
|
||||||
|
* denotes whether the container data set entries are valid from left
|
||||||
|
* to right, MSB first. (length = ceil(N/8), N = number of pool variables)
|
||||||
|
* @param buffer
|
||||||
|
* @param size
|
||||||
|
* @param maxSize
|
||||||
|
* @param bigEndian
|
||||||
|
* @param withValidityBuffer
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t serializeWithValidityBuffer(uint8_t** buffer,
|
||||||
|
size_t* size, size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness) const;
|
||||||
|
ReturnValue_t deSerializeWithValidityBuffer(const uint8_t** buffer,
|
||||||
|
size_t *size, SerializeIF::Endianness streamEndianness);
|
||||||
|
ReturnValue_t serializeLocalPoolIds(uint8_t** buffer,
|
||||||
|
size_t* size, size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness,
|
||||||
|
bool serializeFillCount = true) const;
|
||||||
|
uint8_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dataset valid or invalid. These calls are mutex protected.
|
||||||
|
* @param setEntriesRecursively
|
||||||
|
* If this is true, all contained datasets will also be set recursively.
|
||||||
|
*/
|
||||||
|
void setValidity(bool valid, bool setEntriesRecursively);
|
||||||
|
bool isValid() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These calls are mutex protected.
|
||||||
|
* @param changed
|
||||||
|
*/
|
||||||
|
void setChanged(bool changed) override;
|
||||||
|
bool hasChanged() const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
sid_t sid;
|
||||||
|
MutexIF* mutex = nullptr;
|
||||||
|
|
||||||
|
bool diagnostic = false;
|
||||||
|
void setDiagnostic(bool diagnostics);
|
||||||
|
bool isDiagnostics() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for periodic generation.
|
||||||
|
*/
|
||||||
|
bool reportingEnabled = false;
|
||||||
|
void setReportingEnabled(bool enabled);
|
||||||
|
bool getReportingEnabled() const;
|
||||||
|
|
||||||
|
void initializePeriodicHelper(float collectionInterval,
|
||||||
|
dur_millis_t minimumPeriodicInterval,
|
||||||
|
bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the valid state of a dataset is always relevant to the whole
|
||||||
|
* data set we can use this flag.
|
||||||
|
*/
|
||||||
|
bool valid = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used to mark the dataset as changed, which is used
|
||||||
|
* by the LocalDataPoolManager to send out update messages.
|
||||||
|
*/
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify whether the validity buffer is serialized too when serializing
|
||||||
|
* or deserializing the packet. Each bit of the validity buffer will
|
||||||
|
* contain the validity state of the pool variables from left to right.
|
||||||
|
* The size of validity buffer thus will be ceil(N / 8) with N = number of
|
||||||
|
* pool variables.
|
||||||
|
*/
|
||||||
|
bool withValidityBuffer = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a small helper function to facilitate locking
|
||||||
|
* the global data pool.
|
||||||
|
* @details
|
||||||
|
* It makes use of the lockDataPool method offered by the DataPool class.
|
||||||
|
*/
|
||||||
|
ReturnValue_t lockDataPool(uint32_t timeoutMs) override;
|
||||||
|
/**
|
||||||
|
* @brief This is a small helper function to facilitate
|
||||||
|
* unlocking the global data pool
|
||||||
|
* @details
|
||||||
|
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
||||||
|
*/
|
||||||
|
ReturnValue_t unlockDataPool() override;
|
||||||
|
|
||||||
|
LocalDataPoolManager* hkManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set n-th bit of a byte, with n being the position from 0
|
||||||
|
* (most significant bit) to 7 (least significant bit)
|
||||||
|
*/
|
||||||
|
void bitSetter(uint8_t* byte, uint8_t position) const;
|
||||||
|
bool bitGetter(const uint8_t* byte, uint8_t position) const;
|
||||||
|
|
||||||
|
PeriodicHousekeepingHelper* periodicHelper = nullptr;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_ */
|
73
datapoollocal/LocalPoolObjectBase.cpp
Normal file
73
datapoollocal/LocalPoolObjectBase.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#include "LocalPoolObjectBase.h"
|
||||||
|
|
||||||
|
LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId,
|
||||||
|
HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet,
|
||||||
|
pool_rwm_t setReadWriteMode): localPoolId(poolId),
|
||||||
|
readWriteMode(setReadWriteMode) {
|
||||||
|
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||||
|
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
||||||
|
<< "which is the NO_PARAMETER value!" << std::endl;
|
||||||
|
}
|
||||||
|
if(hkOwner == nullptr) {
|
||||||
|
sif::error << "LocalPoolVar<T>::LocalPoolVar: The supplied pool "
|
||||||
|
<< "owner is a invalid!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hkManager = hkOwner->getHkManagerHandle();
|
||||||
|
if (dataSet != nullptr) {
|
||||||
|
dataSet->registerVariable(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId,
|
||||||
|
DataSetIF *dataSet, pool_rwm_t setReadWriteMode): localPoolId(poolId),
|
||||||
|
readWriteMode(setReadWriteMode) {
|
||||||
|
if(poolId == PoolVariableIF::NO_PARAMETER) {
|
||||||
|
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
||||||
|
<< "which is the NO_PARAMETER value!" << std::endl;
|
||||||
|
}
|
||||||
|
HasLocalDataPoolIF* hkOwner =
|
||||||
|
objectManager->get<HasLocalDataPoolIF>(poolOwner);
|
||||||
|
if(hkOwner == nullptr) {
|
||||||
|
sif::error << "LocalPoolVariable: The supplied pool owner did not "
|
||||||
|
<< "implement the correct interface"
|
||||||
|
<< " HasLocalDataPoolIF!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hkManager = hkOwner->getHkManagerHandle();
|
||||||
|
if(dataSet != nullptr) {
|
||||||
|
dataSet->registerVariable(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const {
|
||||||
|
return readWriteMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolObjectBase::isValid() const {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolObjectBase::setValid(bool valid) {
|
||||||
|
this->valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
lp_id_t LocalPoolObjectBase::getDataPoolId() const {
|
||||||
|
return localPoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) {
|
||||||
|
this->localPoolId = poolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolObjectBase::setChanged(bool changed) {
|
||||||
|
this->changed = changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalPoolObjectBase::hasChanged() const {
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) {
|
||||||
|
this->readWriteMode = newReadWriteMode;
|
||||||
|
}
|
63
datapoollocal/LocalPoolObjectBase.h
Normal file
63
datapoollocal/LocalPoolObjectBase.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_
|
||||||
|
|
||||||
|
#include "MarkChangedIF.h"
|
||||||
|
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||||
|
#include "../datapool/PoolVariableIF.h"
|
||||||
|
|
||||||
|
|
||||||
|
class LocalPoolObjectBase: public PoolVariableIF,
|
||||||
|
public HasReturnvaluesIF,
|
||||||
|
public MarkChangedIF {
|
||||||
|
public:
|
||||||
|
LocalPoolObjectBase(lp_id_t poolId,
|
||||||
|
HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet,
|
||||||
|
pool_rwm_t setReadWriteMode);
|
||||||
|
|
||||||
|
LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId,
|
||||||
|
DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
|
||||||
|
void setReadWriteMode(pool_rwm_t newReadWriteMode);
|
||||||
|
pool_rwm_t getReadWriteMode() const;
|
||||||
|
|
||||||
|
bool isValid() const override;
|
||||||
|
void setValid(bool valid) override;
|
||||||
|
|
||||||
|
void setChanged(bool changed) override;
|
||||||
|
bool hasChanged() const override;
|
||||||
|
|
||||||
|
lp_id_t getDataPoolId() const override;
|
||||||
|
void setDataPoolId(lp_id_t poolId);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief To access the correct data pool entry on read and commit calls,
|
||||||
|
* the data pool id is stored.
|
||||||
|
*/
|
||||||
|
uint32_t localPoolId = PoolVariableIF::NO_PARAMETER;
|
||||||
|
/**
|
||||||
|
* @brief The valid information as it was stored in the data pool
|
||||||
|
* is copied to this attribute.
|
||||||
|
*/
|
||||||
|
bool valid = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A local pool variable can be marked as changed.
|
||||||
|
*/
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The information whether the class is read-write or
|
||||||
|
* read-only is stored here.
|
||||||
|
*/
|
||||||
|
ReadWriteMode_t readWriteMode = pool_rwm_t::VAR_READ_WRITE;
|
||||||
|
|
||||||
|
//! @brief Pointer to the class which manages the HK pool.
|
||||||
|
LocalDataPoolManager* hkManager;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ */
|
185
datapoollocal/LocalPoolVariable.h
Normal file
185
datapoollocal/LocalPoolVariable.h
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||||
|
|
||||||
|
#include "LocalPoolObjectBase.h"
|
||||||
|
#include "HasLocalDataPoolIF.h"
|
||||||
|
#include "LocalDataPoolManager.h"
|
||||||
|
|
||||||
|
#include "../datapool/PoolVariableIF.h"
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 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 LocalPoolVar: public LocalPoolObjectBase {
|
||||||
|
public:
|
||||||
|
//! Default ctor is forbidden.
|
||||||
|
LocalPoolVar() = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is used by the data creators to have pool variable
|
||||||
|
* instances which can also be stored in datasets.
|
||||||
|
*
|
||||||
|
* It does not fetch the current value from the data pool, which
|
||||||
|
* has to be done by calling the read() operation.
|
||||||
|
* Datasets can be used to access multiple local pool entries in an
|
||||||
|
* efficient way. A pointer to a dataset can be passed to register
|
||||||
|
* the pool variable in that dataset directly.
|
||||||
|
* @param poolId ID of the local pool entry.
|
||||||
|
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||||
|
* class itself which passes "this".
|
||||||
|
* @param dataSet The data set in which the variable shall register itself.
|
||||||
|
* If nullptr, the variable is not registered.
|
||||||
|
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||||
|
*/
|
||||||
|
LocalPoolVar(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
|
||||||
|
DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* It does not fetch the current value from the data pool, which
|
||||||
|
* has to be done by calling the read() operation.
|
||||||
|
* Datasets can be used to access multiple local pool entries in an
|
||||||
|
* efficient way. A pointer to a dataset can be passed to register
|
||||||
|
* the pool variable in that dataset directly.
|
||||||
|
* @param poolId ID of the local pool entry.
|
||||||
|
* @param hkOwner object ID of the pool owner.
|
||||||
|
* @param dataSet The data set in which the variable shall register itself.
|
||||||
|
* If nullptr, the variable is not registered.
|
||||||
|
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
LocalPoolVar(object_id_t poolOwner, lp_id_t poolId,
|
||||||
|
DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
/**
|
||||||
|
* Variation which takes the global unique identifier of a pool variable.
|
||||||
|
* @param globalPoolId
|
||||||
|
* @param dataSet
|
||||||
|
* @param setReadWriteMode
|
||||||
|
*/
|
||||||
|
LocalPoolVar(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
|
||||||
|
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 serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness) const override;
|
||||||
|
virtual size_t getSerializedSize() const override;
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 data pool and copies all array values and the valid
|
||||||
|
* information to its local attributes.
|
||||||
|
* In case of a failure (wrong type, size or pool id not found), the
|
||||||
|
* variable is set to zero and invalid.
|
||||||
|
* The read call is protected with a lock.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ReturnValue_t read(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
/**
|
||||||
|
* @brief The commit call copies the array values back to the data pool.
|
||||||
|
* @details
|
||||||
|
* It checks type and size, as well as if the variable is writable. If so,
|
||||||
|
* the value is copied and the local valid flag is written back as well.
|
||||||
|
* The read call is protected with a lock.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commit(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
|
||||||
|
|
||||||
|
LocalPoolVar<T> &operator=(const T& newValue);
|
||||||
|
LocalPoolVar<T> &operator=(const LocalPoolVar<T>& newPoolVariable);
|
||||||
|
|
||||||
|
//! Explicit type conversion operator. Allows casting the class to
|
||||||
|
//! its template type to perform operations on value.
|
||||||
|
explicit operator T() const;
|
||||||
|
|
||||||
|
bool operator==(const LocalPoolVar<T>& other) const;
|
||||||
|
bool operator==(const T& other) const;
|
||||||
|
|
||||||
|
bool operator!=(const LocalPoolVar<T>& other) const;
|
||||||
|
bool operator!=(const T& other) const;
|
||||||
|
|
||||||
|
bool operator<(const LocalPoolVar<T>& other) const;
|
||||||
|
bool operator<(const T& other) const;
|
||||||
|
|
||||||
|
bool operator>(const LocalPoolVar<T>& other) const;
|
||||||
|
bool operator>(const T& other) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Like #read, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t readWithoutLock() override;
|
||||||
|
/**
|
||||||
|
* @brief Like #commit, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commitWithoutLock() override;
|
||||||
|
|
||||||
|
// std::ostream is the type for object std::cout
|
||||||
|
template <typename U>
|
||||||
|
friend std::ostream& operator<< (std::ostream &out,
|
||||||
|
const LocalPoolVar<U> &var);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "LocalPoolVariable.tpp"
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
using lp_var_t = LocalPoolVar<T>;
|
||||||
|
|
||||||
|
using lp_bool_t = LocalPoolVar<uint8_t>;
|
||||||
|
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>;
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ */
|
169
datapoollocal/LocalPoolVariable.tpp
Normal file
169
datapoollocal/LocalPoolVariable.tpp
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
|
||||||
|
|
||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
||||||
|
#error Include LocalPoolVariable.h before LocalPoolVariable.tpp!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline LocalPoolVar<T>::LocalPoolVar(HasLocalDataPoolIF* hkOwner,
|
||||||
|
lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
|
||||||
|
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline LocalPoolVar<T>::LocalPoolVar(object_id_t poolOwner, lp_id_t poolId,
|
||||||
|
DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
|
||||||
|
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline LocalPoolVar<T>::LocalPoolVar(gp_id_t globalPoolId, DataSetIF *dataSet,
|
||||||
|
pool_rwm_t setReadWriteMode):
|
||||||
|
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
|
||||||
|
dataSet, setReadWriteMode){}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) {
|
||||||
|
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
|
||||||
|
lockTimeout);
|
||||||
|
return readWithoutLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t LocalPoolVar<T>::readWithoutLock() {
|
||||||
|
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
|
||||||
|
sif::debug << "LocalPoolVar: Invalid read write "
|
||||||
|
"mode for read() call." << std::endl;
|
||||||
|
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolEntry<T>* poolEntry = nullptr;
|
||||||
|
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||||
|
if(result != RETURN_OK and poolEntry != nullptr) {
|
||||||
|
sif::error << "PoolVector: Read of local pool variable of object "
|
||||||
|
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||||
|
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||||
|
std::dec << " failed.\n" << std::flush;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
this->value = *(poolEntry->address);
|
||||||
|
this->valid = poolEntry->valid;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) {
|
||||||
|
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
|
||||||
|
lockTimeout);
|
||||||
|
return commitWithoutLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t LocalPoolVar<T>::commitWithoutLock() {
|
||||||
|
if(readWriteMode == pool_rwm_t::VAR_READ) {
|
||||||
|
sif::debug << "LocalPoolVar: Invalid read write "
|
||||||
|
"mode for commit() call." << std::endl;
|
||||||
|
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||||
|
}
|
||||||
|
PoolEntry<T>* poolEntry = nullptr;
|
||||||
|
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||||
|
if(result != RETURN_OK) {
|
||||||
|
sif::error << "PoolVector: Read of local pool variable of object "
|
||||||
|
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||||
|
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||||
|
std::dec << " failed.\n" << std::flush;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
*(poolEntry->address) = this->value;
|
||||||
|
poolEntry->valid = this->valid;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size,
|
||||||
|
const size_t max_size, SerializeIF::Endianness streamEndianness) const {
|
||||||
|
return SerializeAdapter::serialize(&value,
|
||||||
|
buffer, size ,max_size, streamEndianness);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline size_t LocalPoolVar<T>::getSerializedSize() const {
|
||||||
|
return SerializeAdapter::getSerializedSize(&value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t LocalPoolVar<T>::deSerialize(const uint8_t** buffer,
|
||||||
|
size_t* size, SerializeIF::Endianness streamEndianness) {
|
||||||
|
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline std::ostream& operator<< (std::ostream &out,
|
||||||
|
const LocalPoolVar<T> &var) {
|
||||||
|
out << var.value;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline LocalPoolVar<T>::operator T() const {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline LocalPoolVar<T> & LocalPoolVar<T>::operator=(const T& newValue) {
|
||||||
|
value = newValue;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline LocalPoolVar<T>& LocalPoolVar<T>::operator =(
|
||||||
|
const LocalPoolVar<T>& newPoolVariable) {
|
||||||
|
value = newPoolVariable.value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator ==(const LocalPoolVar<T> &other) const {
|
||||||
|
return this->value == other.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator ==(const T &other) const {
|
||||||
|
return this->value == other;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator !=(const LocalPoolVar<T> &other) const {
|
||||||
|
return not (*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator !=(const T &other) const {
|
||||||
|
return not (*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator <(const LocalPoolVar<T> &other) const {
|
||||||
|
return this->value < other.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator <(const T &other) const {
|
||||||
|
return this->value < other;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator >(const LocalPoolVar<T> &other) const {
|
||||||
|
return not (*this < other);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool LocalPoolVar<T>::operator >(const T &other) const {
|
||||||
|
return not (*this < other);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */
|
174
datapoollocal/LocalPoolVector.h
Normal file
174
datapoollocal/LocalPoolVector.h
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||||
|
|
||||||
|
#include "LocalPoolObjectBase.h"
|
||||||
|
#include "../datapool/DataSetIF.h"
|
||||||
|
#include "../datapool/PoolEntry.h"
|
||||||
|
#include "../datapool/PoolVariableIF.h"
|
||||||
|
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the access class for array-type data pool entries.
|
||||||
|
* @details
|
||||||
|
* To ensure safe usage of the data pool, operation is not done directly on the
|
||||||
|
* data pool entries, but on local copies. This class provides simple type-
|
||||||
|
* and length-safe access to vector-style data pool entries (i.e. entries with
|
||||||
|
* length > 1). The class can be instantiated as read-write and read only.
|
||||||
|
*
|
||||||
|
* It provides a commit-and-roll-back semantic, which means that no array
|
||||||
|
* entry in the data pool is changed until the commit call is executed.
|
||||||
|
* There are two template parameters:
|
||||||
|
* @tparam T
|
||||||
|
* This template parameter specifies the data type of an array entry. Currently,
|
||||||
|
* all plain data types are supported, but in principle any type is possible.
|
||||||
|
* @tparam vector_size
|
||||||
|
* This template parameter specifies the vector size of this entry. Using a
|
||||||
|
* template parameter for this is not perfect, but avoids
|
||||||
|
* dynamic memory allocation.
|
||||||
|
* @ingroup data_pool
|
||||||
|
*/
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
class LocalPoolVector: public LocalPoolObjectBase {
|
||||||
|
public:
|
||||||
|
LocalPoolVector() = delete;
|
||||||
|
/**
|
||||||
|
* This constructor is used by the data creators to have pool variable
|
||||||
|
* instances which can also be stored in datasets.
|
||||||
|
* It does not fetch the current value from the data pool. This is performed
|
||||||
|
* by the read() operation (which is not thread-safe).
|
||||||
|
* Datasets can be used to access local pool entires in a thread-safe way.
|
||||||
|
* @param poolId ID of the local pool entry.
|
||||||
|
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||||
|
* class itself which passes "this".
|
||||||
|
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||||
|
* @param dataSet The data set in which the variable shall register itself.
|
||||||
|
* If nullptr, the variable is not registered.
|
||||||
|
*/
|
||||||
|
LocalPoolVector(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
|
||||||
|
DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* It does not fetch the current value from the data pool. This is performed
|
||||||
|
* by the read() operation (which is not thread-safe).
|
||||||
|
* Datasets can be used to access local pool entires in a thread-safe way.
|
||||||
|
* @param poolId ID of the local pool entry.
|
||||||
|
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||||
|
* class itself which passes "this".
|
||||||
|
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||||
|
* @param dataSet The data set in which the variable shall register itself.
|
||||||
|
* If nullptr, the variable is not registered.
|
||||||
|
*/
|
||||||
|
LocalPoolVector(object_id_t poolOwner, lp_id_t poolId,
|
||||||
|
DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
/**
|
||||||
|
* Variation which takes the unique global identifier of a local pool
|
||||||
|
* vector.
|
||||||
|
* @param globalPoolId
|
||||||
|
* @param dataSet
|
||||||
|
* @param setReadWriteMode
|
||||||
|
*/
|
||||||
|
LocalPoolVector(gp_id_t globalPoolId,
|
||||||
|
DataSetIF* dataSet = nullptr,
|
||||||
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is the local copy of the data pool entry.
|
||||||
|
* @details
|
||||||
|
* The user can work on this attribute just like he would on a local
|
||||||
|
* array of this type.
|
||||||
|
*/
|
||||||
|
T value[vectorSize];
|
||||||
|
/**
|
||||||
|
* @brief The classes destructor is empty.
|
||||||
|
* @details If commit() was not called, the local value is
|
||||||
|
* discarded and not written back to the data pool.
|
||||||
|
*/
|
||||||
|
~LocalPoolVector() {};
|
||||||
|
/**
|
||||||
|
* @brief The operation returns the number of array entries
|
||||||
|
* in this variable.
|
||||||
|
*/
|
||||||
|
uint8_t getSize() {
|
||||||
|
return vectorSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator [](int i);
|
||||||
|
const T &operator [](int i) const;
|
||||||
|
|
||||||
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
|
const size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndiannes) const override;
|
||||||
|
virtual size_t getSerializedSize() const override;
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This is a call to read the array's values
|
||||||
|
* from the global data pool.
|
||||||
|
* @details
|
||||||
|
* When executed, this operation tries to fetch the pool entry with matching
|
||||||
|
* data pool id from the data pool and copies all array values and the valid
|
||||||
|
* information to its local attributes.
|
||||||
|
* In case of a failure (wrong type, size or pool id not found), the
|
||||||
|
* variable is set to zero and invalid.
|
||||||
|
* The read call is protected with a lock.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
/**
|
||||||
|
* @brief The commit call copies the array values back to the data pool.
|
||||||
|
* @details
|
||||||
|
* It checks type and size, as well as if the variable is writable. If so,
|
||||||
|
* the value is copied and the local valid flag is written back as well.
|
||||||
|
* The read call is protected with a lock.
|
||||||
|
* It is recommended to use DataSets to read and commit multiple variables
|
||||||
|
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Like #read, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t readWithoutLock() override;
|
||||||
|
/**
|
||||||
|
* @brief Like #commit, but without a lock protection of the global pool.
|
||||||
|
* @details
|
||||||
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||||
|
* This can be used if the lock is handled externally to avoid the overhead
|
||||||
|
* of consecutive lock und unlock operations.
|
||||||
|
* Declared protected to discourage free public usage.
|
||||||
|
*/
|
||||||
|
ReturnValue_t commitWithoutLock() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
// std::ostream is the type for object std::cout
|
||||||
|
template <typename U, uint16_t otherSize>
|
||||||
|
friend std::ostream& operator<< (std::ostream &out,
|
||||||
|
const LocalPoolVector<U, otherSize> &var);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "LocalPoolVector.tpp"
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
using lp_vec_t = LocalPoolVector<T, vectorSize>;
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ */
|
158
datapoollocal/LocalPoolVector.tpp
Normal file
158
datapoollocal/LocalPoolVector.tpp
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_
|
||||||
|
|
||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_
|
||||||
|
#error Include LocalPoolVector.h before LocalPoolVector.tpp!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(
|
||||||
|
HasLocalDataPoolIF* hkOwner, lp_id_t poolId, DataSetIF* dataSet,
|
||||||
|
pool_rwm_t setReadWriteMode):
|
||||||
|
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(object_id_t poolOwner,
|
||||||
|
lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
|
||||||
|
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(gp_id_t globalPoolId,
|
||||||
|
DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
|
||||||
|
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
|
||||||
|
dataSet, setReadWriteMode) {}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t LocalPoolVector<T, vectorSize>::read(uint32_t lockTimeout) {
|
||||||
|
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
|
||||||
|
lockTimeout);
|
||||||
|
return readWithoutLock();
|
||||||
|
}
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t LocalPoolVector<T, vectorSize>::readWithoutLock() {
|
||||||
|
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
|
||||||
|
sif::debug << "LocalPoolVar: Invalid read write "
|
||||||
|
"mode for read() call." << std::endl;
|
||||||
|
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolEntry<T>* poolEntry = nullptr;
|
||||||
|
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||||
|
memset(this->value, 0, vectorSize * sizeof(T));
|
||||||
|
|
||||||
|
if(result != RETURN_OK) {
|
||||||
|
sif::error << "PoolVector: Read of local pool variable of object "
|
||||||
|
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||||
|
hkManager->getOwner() << "and lp ID 0x" << localPoolId <<
|
||||||
|
std::dec << " failed." << std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
std::memcpy(this->value, poolEntry->address, poolEntry->getByteSize());
|
||||||
|
this->valid = poolEntry->valid;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit(
|
||||||
|
uint32_t lockTimeout) {
|
||||||
|
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
|
||||||
|
lockTimeout);
|
||||||
|
return commitWithoutLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() {
|
||||||
|
if(readWriteMode == pool_rwm_t::VAR_READ) {
|
||||||
|
sif::debug << "LocalPoolVar: Invalid read write "
|
||||||
|
"mode for commit() call." << std::endl;
|
||||||
|
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||||
|
}
|
||||||
|
PoolEntry<T>* poolEntry = nullptr;
|
||||||
|
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||||
|
if(result != RETURN_OK) {
|
||||||
|
sif::error << "PoolVector: Read of local pool variable of object "
|
||||||
|
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||||
|
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||||
|
std::dec << " failed.\n" << std::flush;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
std::memcpy(poolEntry->address, this->value, poolEntry->getByteSize());
|
||||||
|
poolEntry->valid = this->valid;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline T& LocalPoolVector<T, vectorSize>::operator [](int i) {
|
||||||
|
if(i <= vectorSize) {
|
||||||
|
return value[i];
|
||||||
|
}
|
||||||
|
// If this happens, I have to set some value. I consider this
|
||||||
|
// a configuration error, but I wont exit here.
|
||||||
|
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
|
||||||
|
" last value!" << std::endl;
|
||||||
|
return value[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline const T& LocalPoolVector<T, vectorSize>::operator [](int i) const {
|
||||||
|
if(i <= vectorSize) {
|
||||||
|
return value[i];
|
||||||
|
}
|
||||||
|
// If this happens, I have to set some value. I consider this
|
||||||
|
// a configuration error, but I wont exit here.
|
||||||
|
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
|
||||||
|
" last value!" << std::endl;
|
||||||
|
return value[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t LocalPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
|
||||||
|
size_t* size, size_t maxSize,
|
||||||
|
SerializeIF::Endianness streamEndianness) const {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
for (uint16_t i = 0; i < vectorSize; i++) {
|
||||||
|
result = SerializeAdapter::serialize(&(value[i]), buffer, size,
|
||||||
|
maxSize, streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline size_t LocalPoolVector<T, vectorSize>::getSerializedSize() const {
|
||||||
|
return vectorSize * SerializeAdapter::getSerializedSize(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline ReturnValue_t LocalPoolVector<T, vectorSize>::deSerialize(
|
||||||
|
const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
for (uint16_t i = 0; i < vectorSize; i++) {
|
||||||
|
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
|
||||||
|
streamEndianness);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t vectorSize>
|
||||||
|
inline std::ostream& operator<< (std::ostream &out,
|
||||||
|
const LocalPoolVector<T, vectorSize> &var) {
|
||||||
|
out << "Vector: [";
|
||||||
|
for(int i = 0;i < vectorSize; i++) {
|
||||||
|
out << var.value[i];
|
||||||
|
if(i < vectorSize - 1) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out << "]";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ */
|
17
datapoollocal/MarkChangedIF.h
Normal file
17
datapoollocal/MarkChangedIF.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_MARKCHANGEDIF_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_MARKCHANGEDIF_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common interface for local pool entities which can be marked as changed.
|
||||||
|
*/
|
||||||
|
class MarkChangedIF {
|
||||||
|
public:
|
||||||
|
virtual~ MarkChangedIF() {};
|
||||||
|
|
||||||
|
virtual bool hasChanged() const = 0;
|
||||||
|
virtual void setChanged(bool changed) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_MARKCHANGEDIF_H_ */
|
16
datapoollocal/SharedLocalDataSet.cpp
Normal file
16
datapoollocal/SharedLocalDataSet.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "SharedLocalDataSet.h"
|
||||||
|
|
||||||
|
SharedLocalDataSet::SharedLocalDataSet(object_id_t objectId, sid_t sid,
|
||||||
|
const size_t maxSize): SystemObject(objectId),
|
||||||
|
LocalPoolDataSetBase(sid, nullptr, maxSize) {
|
||||||
|
this->setContainer(poolVarVector.data());
|
||||||
|
datasetLock = MutexFactory::instance()->createMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t SharedLocalDataSet::lockDataset(dur_millis_t mutexTimeout) {
|
||||||
|
return datasetLock->lockMutex(MutexIF::TimeoutType::WAITING, mutexTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t SharedLocalDataSet::unlockDataset() {
|
||||||
|
return datasetLock->unlockMutex();
|
||||||
|
}
|
24
datapoollocal/SharedLocalDataSet.h
Normal file
24
datapoollocal/SharedLocalDataSet.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_SHAREDLOCALDATASET_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_SHAREDLOCALDATASET_H_
|
||||||
|
|
||||||
|
#include "LocalPoolDataSetBase.h"
|
||||||
|
#include "../datapool/SharedDataSetIF.h"
|
||||||
|
#include "../objectmanager/SystemObject.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class SharedLocalDataSet: public SystemObject,
|
||||||
|
public LocalPoolDataSetBase,
|
||||||
|
public SharedDataSetIF {
|
||||||
|
public:
|
||||||
|
SharedLocalDataSet(object_id_t objectId, sid_t sid,
|
||||||
|
const size_t maxSize);
|
||||||
|
ReturnValue_t lockDataset(dur_millis_t mutexTimeout) override;
|
||||||
|
ReturnValue_t unlockDataset() override;
|
||||||
|
private:
|
||||||
|
|
||||||
|
MutexIF* datasetLock = nullptr;
|
||||||
|
std::vector<PoolVariableIF*> poolVarVector;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_SHAREDLOCALDATASET_H_ */
|
50
datapoollocal/StaticLocalDataSet.h
Normal file
50
datapoollocal/StaticLocalDataSet.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_
|
||||||
|
|
||||||
|
#include "LocalPoolDataSetBase.h"
|
||||||
|
#include "../objectmanager/SystemObjectIF.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This local dataset type is created on the stack.
|
||||||
|
* @details
|
||||||
|
* This will is the primary data structure to organize pool variables into
|
||||||
|
* sets which can be accessed via the housekeeping service interface or
|
||||||
|
* which can be sent to other software objects.
|
||||||
|
*
|
||||||
|
* It is recommended to read the documentation of the LocalPoolDataSetBase
|
||||||
|
* class for more information on how this class works and how to use it.
|
||||||
|
* @tparam capacity Capacity of the static dataset, which is usually known
|
||||||
|
* beforehand.
|
||||||
|
*/
|
||||||
|
template <uint8_t NUM_VARIABLES>
|
||||||
|
class StaticLocalDataSet: public LocalPoolDataSetBase {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor used by data owner and creator like device handlers.
|
||||||
|
* This constructor also initialized the components required for
|
||||||
|
* periodic handling.
|
||||||
|
* @param hkOwner
|
||||||
|
* @param setId
|
||||||
|
*/
|
||||||
|
StaticLocalDataSet(HasLocalDataPoolIF* hkOwner,
|
||||||
|
uint32_t setId): LocalPoolDataSetBase(hkOwner, setId, nullptr,
|
||||||
|
NUM_VARIABLES) {
|
||||||
|
this->setContainer(poolVarList.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor used by data users like controllers.
|
||||||
|
* @param hkOwner
|
||||||
|
* @param setId
|
||||||
|
*/
|
||||||
|
StaticLocalDataSet(sid_t sid): LocalPoolDataSetBase(sid, nullptr,
|
||||||
|
NUM_VARIABLES) {
|
||||||
|
this->setContainer(poolVarList.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<PoolVariableIF*, NUM_VARIABLES> poolVarList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_ */
|
93
datapoollocal/locPoolDefinitions.h
Normal file
93
datapoollocal/locPoolDefinitions.h
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#ifndef FSFW_DATAPOOLLOCAL_LOCPOOLDEFINITIONS_H_
|
||||||
|
#define FSFW_DATAPOOLLOCAL_LOCPOOLDEFINITIONS_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include "../objectmanager/SystemObjectIF.h"
|
||||||
|
#include "../objectmanager/frameworkObjects.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type definition for local pool entries.
|
||||||
|
*/
|
||||||
|
using lp_id_t = uint32_t;
|
||||||
|
|
||||||
|
namespace localpool {
|
||||||
|
static constexpr uint32_t INVALID_LPID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used as a unique identifier for data sets.
|
||||||
|
*/
|
||||||
|
union sid_t {
|
||||||
|
static constexpr uint64_t INVALID_SID = -1;
|
||||||
|
static constexpr uint32_t INVALID_OBJECT_ID = objects::NO_OBJECT;
|
||||||
|
static constexpr uint32_t INVALID_SET_ID = -1;
|
||||||
|
|
||||||
|
|
||||||
|
sid_t(): raw(INVALID_SID) {}
|
||||||
|
|
||||||
|
sid_t(object_id_t objectId, uint32_t setId):
|
||||||
|
objectId(objectId),
|
||||||
|
ownerSetId(setId) {}
|
||||||
|
|
||||||
|
struct {
|
||||||
|
object_id_t objectId ;
|
||||||
|
/**
|
||||||
|
* A generic 32 bit ID to identify unique HK packets for a single
|
||||||
|
* object. For example, the DeviceCommandId_t is used for
|
||||||
|
* DeviceHandlers
|
||||||
|
*/
|
||||||
|
uint32_t ownerSetId;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Alternative access to the raw value. This is also the size of the type.
|
||||||
|
*/
|
||||||
|
uint64_t raw;
|
||||||
|
|
||||||
|
bool notSet() const {
|
||||||
|
return raw == INVALID_SID;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const sid_t& other) const {
|
||||||
|
return raw == other.raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const sid_t& other) const {
|
||||||
|
return not (raw == other.raw);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used as a global unique identifier for local pool variables.
|
||||||
|
*/
|
||||||
|
union gp_id_t {
|
||||||
|
static constexpr uint64_t INVALID_GPID = -1;
|
||||||
|
static constexpr uint32_t INVALID_OBJECT_ID = objects::NO_OBJECT;
|
||||||
|
static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID;
|
||||||
|
|
||||||
|
gp_id_t(): raw(INVALID_GPID) {}
|
||||||
|
|
||||||
|
gp_id_t(object_id_t objectId, lp_id_t localPoolId):
|
||||||
|
objectId(objectId),
|
||||||
|
localPoolId(localPoolId) {}
|
||||||
|
|
||||||
|
struct {
|
||||||
|
object_id_t objectId;
|
||||||
|
lp_id_t localPoolId;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint64_t raw;
|
||||||
|
|
||||||
|
bool notSet() const {
|
||||||
|
return raw == INVALID_GPID;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const sid_t& other) const {
|
||||||
|
return raw == other.raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const sid_t& other) const {
|
||||||
|
return not (raw == other.raw);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOLLOCAL_LOCPOOLDEFINITIONS_H_ */
|
@ -1,23 +1,19 @@
|
|||||||
/**
|
#ifndef FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
|
||||||
* @file AcceptsDeviceResponsesIF.h
|
#define FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
|
||||||
* @brief This file defines the AcceptsDeviceResponsesIF class.
|
|
||||||
* @date 15.05.2013
|
|
||||||
* @author baetz
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ACCEPTSDEVICERESPONSESIF_H_
|
|
||||||
#define ACCEPTSDEVICERESPONSESIF_H_
|
|
||||||
|
|
||||||
#include "../ipc/MessageQueueSenderIF.h"
|
#include "../ipc/MessageQueueSenderIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface is used by the device handler to send a device response
|
||||||
|
* to the queue ID, which is returned in the implemented abstract method.
|
||||||
|
*/
|
||||||
class AcceptsDeviceResponsesIF {
|
class AcceptsDeviceResponsesIF {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Default empty virtual destructor.
|
* Default empty virtual destructor.
|
||||||
*/
|
*/
|
||||||
virtual ~AcceptsDeviceResponsesIF() {
|
virtual ~AcceptsDeviceResponsesIF() {}
|
||||||
}
|
virtual MessageQueueId_t getDeviceQueue() = 0;
|
||||||
virtual MessageQueueId_t getDeviceQueue() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ACCEPTSDEVICERESPONSESIF_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_ */
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId,
|
AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId,
|
||||||
uint16_t commandQueueDepth) :
|
uint16_t commandQueueDepth) :
|
||||||
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth), internalState(
|
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth),
|
||||||
STATE_NONE), recoveryState(RECOVERY_IDLE), recoveringDevice(
|
internalState(STATE_NONE), recoveryState(RECOVERY_IDLE),
|
||||||
childrenMap.end()), targetMode(MODE_OFF), targetSubmode(
|
recoveringDevice(childrenMap.end()), targetMode(MODE_OFF),
|
||||||
SUBMODE_NONE) {
|
targetSubmode(SUBMODE_NONE) {
|
||||||
recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS);
|
recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,9 +165,8 @@ ReturnValue_t AssemblyBase::checkChildrenState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t AssemblyBase::checkChildrenStateOff() {
|
ReturnValue_t AssemblyBase::checkChildrenStateOff() {
|
||||||
for (std::map<object_id_t, ChildInfo>::iterator iter = childrenMap.begin();
|
for (const auto& childIter: childrenMap) {
|
||||||
iter != childrenMap.end(); iter++) {
|
if (checkChildOff(childIter.first) != RETURN_OK) {
|
||||||
if (checkChildOff(iter->first) != RETURN_OK) {
|
|
||||||
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
|
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,30 @@
|
|||||||
#ifndef ASSEMBLYBASE_H_
|
#ifndef FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_
|
||||||
#define ASSEMBLYBASE_H_
|
#define FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_
|
||||||
|
|
||||||
#include "../container/FixedArrayList.h"
|
|
||||||
#include "DeviceHandlerBase.h"
|
#include "DeviceHandlerBase.h"
|
||||||
|
#include "../container/FixedArrayList.h"
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base class to implement reconfiguration and failure handling for
|
||||||
|
* redundant devices by monitoring their modes health states.
|
||||||
|
* @details
|
||||||
|
* Documentation: Dissertation Baetz p.156, 157.
|
||||||
|
*
|
||||||
|
* This class reduces the complexity of controller components which would
|
||||||
|
* otherwise be needed for the handling of redundant devices.
|
||||||
|
*
|
||||||
|
* The template class monitors mode and health state of its children
|
||||||
|
* and checks availability of devices on every detected change.
|
||||||
|
* AssemblyBase does not implement any redundancy logic by itself, but provides
|
||||||
|
* adaptation points for implementations to do so. Since most monitoring
|
||||||
|
* activities rely on mode and health state only and are therefore
|
||||||
|
* generic, it is sufficient for subclasses to provide:
|
||||||
|
*
|
||||||
|
* 1. check logic when active-> checkChildrenStateOn
|
||||||
|
* 2. transition logic to change the mode -> commandChildren
|
||||||
|
*
|
||||||
|
*/
|
||||||
class AssemblyBase: public SubsystemBase {
|
class AssemblyBase: public SubsystemBase {
|
||||||
public:
|
public:
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::ASSEMBLY_BASE;
|
static const uint8_t INTERFACE_ID = CLASS_ID::ASSEMBLY_BASE;
|
||||||
@ -16,10 +36,41 @@ public:
|
|||||||
static const ReturnValue_t NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE =
|
static const ReturnValue_t NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE =
|
||||||
MAKE_RETURN_CODE(0xa1);
|
MAKE_RETURN_CODE(0xa1);
|
||||||
|
|
||||||
AssemblyBase(object_id_t objectId, object_id_t parentId, uint16_t commandQueueDepth = 8);
|
AssemblyBase(object_id_t objectId, object_id_t parentId,
|
||||||
|
uint16_t commandQueueDepth = 8);
|
||||||
virtual ~AssemblyBase();
|
virtual ~AssemblyBase();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
// SHOULDDO: Change that OVERWRITE_HEALTH may be returned
|
||||||
|
// (or return internalState directly?)
|
||||||
|
/**
|
||||||
|
* Command children to reach [mode,submode] combination
|
||||||
|
* Can be done by setting #commandsOutstanding correctly,
|
||||||
|
* or using executeTable()
|
||||||
|
* @param mode
|
||||||
|
* @param submode
|
||||||
|
* @return
|
||||||
|
* - @c RETURN_OK if ok
|
||||||
|
* - @c NEED_SECOND_STEP if children need to be commanded again
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether desired assembly mode was achieved by checking the modes
|
||||||
|
* or/and health states of child device handlers.
|
||||||
|
* The assembly template class will also call this function if a health
|
||||||
|
* or mode change of a child device handler was detected.
|
||||||
|
* @param wantedMode
|
||||||
|
* @param wantedSubmode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
|
||||||
|
Submode_t wantedSubmode) = 0;
|
||||||
|
|
||||||
|
virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
|
||||||
|
Submode_t submode) = 0;
|
||||||
|
|
||||||
enum InternalState {
|
enum InternalState {
|
||||||
STATE_NONE,
|
STATE_NONE,
|
||||||
STATE_OVERWRITE_HEALTH,
|
STATE_OVERWRITE_HEALTH,
|
||||||
@ -36,6 +87,7 @@ protected:
|
|||||||
RECOVERY_WAIT
|
RECOVERY_WAIT
|
||||||
} recoveryState; //!< Indicates if one of the children requested a recovery.
|
} recoveryState; //!< Indicates if one of the children requested a recovery.
|
||||||
ChildrenMap::iterator recoveringDevice;
|
ChildrenMap::iterator recoveringDevice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the mode the current transition is trying to achieve.
|
* the mode the current transition is trying to achieve.
|
||||||
* Can be different from the modehelper.commandedMode!
|
* Can be different from the modehelper.commandedMode!
|
||||||
@ -61,8 +113,8 @@ protected:
|
|||||||
bool handleChildrenChanged();
|
bool handleChildrenChanged();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called if the children changed its mode in a way that the current
|
* This method is called if the children changed its mode in a way that
|
||||||
* mode can't be kept.
|
* the current mode can't be kept.
|
||||||
* Default behavior is to go to MODE_OFF.
|
* Default behavior is to go to MODE_OFF.
|
||||||
* @param result The failure code which was returned by checkChildrenState.
|
* @param result The failure code which was returned by checkChildrenState.
|
||||||
*/
|
*/
|
||||||
@ -75,9 +127,6 @@ protected:
|
|||||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||||
uint32_t *msToReachTheMode);
|
uint32_t *msToReachTheMode);
|
||||||
|
|
||||||
virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
|
|
||||||
Submode_t submode) = 0;
|
|
||||||
|
|
||||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
virtual void startTransition(Mode_t mode, Submode_t submode);
|
||||||
|
|
||||||
virtual void doStartTransition(Mode_t mode, Submode_t submode);
|
virtual void doStartTransition(Mode_t mode, Submode_t submode);
|
||||||
@ -90,24 +139,6 @@ protected:
|
|||||||
|
|
||||||
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
|
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
|
||||||
|
|
||||||
//SHOULDDO: Change that OVERWRITE_HEALTH may be returned (or return internalState directly?)
|
|
||||||
/**
|
|
||||||
* command children to reach mode,submode
|
|
||||||
*
|
|
||||||
* set #commandsOutstanding correctly, or use executeTable()
|
|
||||||
*
|
|
||||||
* @param mode
|
|
||||||
* @param submode
|
|
||||||
* @return
|
|
||||||
* - @c RETURN_OK if ok
|
|
||||||
* - @c NEED_SECOND_STEP if children need to be commanded again
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) = 0;
|
|
||||||
|
|
||||||
//SHOULDDO: Remove wantedMode, wantedSubmode, as targetMode/submode is available?
|
|
||||||
virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
|
|
||||||
Submode_t wantedSubmode) = 0;
|
|
||||||
|
|
||||||
virtual ReturnValue_t checkChildrenStateOff();
|
virtual ReturnValue_t checkChildrenStateOff();
|
||||||
|
|
||||||
ReturnValue_t checkChildrenState();
|
ReturnValue_t checkChildrenState();
|
||||||
@ -125,8 +156,9 @@ protected:
|
|||||||
* Also sets state to STATE_OVERWRITE_HEATH.
|
* Also sets state to STATE_OVERWRITE_HEATH.
|
||||||
* @param objectId Must be a registered child.
|
* @param objectId Must be a registered child.
|
||||||
*/
|
*/
|
||||||
void overwriteDeviceHealth(object_id_t objectId, HasHealthIF::HealthState oldHealth);
|
void overwriteDeviceHealth(object_id_t objectId,
|
||||||
|
HasHealthIF::HealthState oldHealth);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ASSEMBLYBASE_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_ */
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
|
#include "ChildHandlerBase.h"
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
#include "../devicehandlers/ChildHandlerBase.h"
|
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
|
|
||||||
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
|
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
|
||||||
object_id_t deviceCommunication, CookieIF * cookie,
|
object_id_t deviceCommunication, CookieIF * cookie,
|
||||||
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
|
object_id_t hkDestination, uint32_t thermalStatePoolId,
|
||||||
object_id_t parent, FailureIsolationBase* customFdir,
|
uint32_t thermalRequestPoolId,
|
||||||
size_t cmdQueueSize) :
|
object_id_t parent,
|
||||||
|
FailureIsolationBase* customFdir, size_t cmdQueueSize) :
|
||||||
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
|
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
|
||||||
(customFdir == nullptr? &childHandlerFdir : customFdir),
|
(customFdir == nullptr? &childHandlerFdir : customFdir),
|
||||||
cmdQueueSize),
|
cmdQueueSize),
|
||||||
parentId(parent), childHandlerFdir(setObjectId) {
|
parentId(parent), childHandlerFdir(setObjectId) {
|
||||||
|
this->setHkDestination(hkDestination);
|
||||||
this->setThermalStateRequestPoolIds(thermalStatePoolId,
|
this->setThermalStateRequestPoolIds(thermalStatePoolId,
|
||||||
thermalRequestPoolId);
|
thermalRequestPoolId);
|
||||||
|
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
#ifndef FSFW_DEVICES_CHILDHANDLERBASE_H_
|
#ifndef FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_
|
||||||
#define FSFW_DEVICES_CHILDHANDLERBASE_H_
|
#define FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_
|
||||||
|
|
||||||
#include "ChildHandlerFDIR.h"
|
|
||||||
#include "DeviceHandlerBase.h"
|
#include "DeviceHandlerBase.h"
|
||||||
|
#include "ChildHandlerFDIR.h"
|
||||||
|
|
||||||
class ChildHandlerBase: public DeviceHandlerBase {
|
class ChildHandlerBase: public DeviceHandlerBase {
|
||||||
public:
|
public:
|
||||||
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
||||||
CookieIF * cookie, uint32_t thermalStatePoolId,
|
CookieIF * cookie, object_id_t hkDestination,
|
||||||
uint32_t thermalRequestPoolId,
|
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
|
||||||
object_id_t parent = objects::NO_OBJECT,
|
object_id_t parent = objects::NO_OBJECT,
|
||||||
FailureIsolationBase* customFdir = nullptr,
|
FailureIsolationBase* customFdir = nullptr,
|
||||||
size_t cmdQueueSize = 20);
|
size_t cmdQueueSize = 20);
|
||||||
|
|
||||||
virtual ~ChildHandlerBase();
|
virtual ~ChildHandlerBase();
|
||||||
|
|
||||||
virtual ReturnValue_t initialize();
|
virtual ReturnValue_t initialize();
|
||||||
@ -22,5 +23,4 @@ protected:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_DEVICES_CHILDHANDLERBASE_H_ */
|
#endif /* FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_ */
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "ChildHandlerFDIR.h"
|
#include "ChildHandlerFDIR.h"
|
||||||
|
|
||||||
ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner, object_id_t faultTreeParent, uint32_t recoveryCount) :
|
ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner,
|
||||||
|
object_id_t faultTreeParent, uint32_t recoveryCount) :
|
||||||
DeviceHandlerFailureIsolation(owner, faultTreeParent) {
|
DeviceHandlerFailureIsolation(owner, faultTreeParent) {
|
||||||
recoveryCounter.setFailureThreshold(recoveryCount);
|
recoveryCounter.setFailureThreshold(recoveryCount);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
|
#ifndef FSFW_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
|
||||||
#define FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
|
#define FSFW_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
|
||||||
|
|
||||||
#include "DeviceHandlerFailureIsolation.h"
|
#include "DeviceHandlerFailureIsolation.h"
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
#ifndef COOKIE_H_
|
#ifndef FSFW_DEVICEHANDLER_COOKIE_H_
|
||||||
#define COOKIE_H_
|
#define FSFW_DEVICEHANDLER_COOKIE_H_
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Physical address type
|
* @brief Physical address type
|
||||||
*/
|
*/
|
||||||
typedef std::uint32_t address_t;
|
using address_t = uint32_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This datatype is used to identify different connection over a
|
* @brief This datatype is used to identify different connection over a
|
||||||
@ -16,7 +17,6 @@ typedef std::uint32_t address_t;
|
|||||||
* calling @code{.cpp} CookieIF* childCookie = new ChildCookie(...)
|
* calling @code{.cpp} CookieIF* childCookie = new ChildCookie(...)
|
||||||
* @endcode .
|
* @endcode .
|
||||||
*
|
*
|
||||||
* [not implemented yet]
|
|
||||||
* This cookie is then passed to the child device handlers, which stores the
|
* This cookie is then passed to the child device handlers, which stores the
|
||||||
* pointer and passes it to the communication interface functions.
|
* pointer and passes it to the communication interface functions.
|
||||||
*
|
*
|
||||||
@ -31,4 +31,4 @@ public:
|
|||||||
virtual ~CookieIF() {};
|
virtual ~CookieIF() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* COOKIE_H_ */
|
#endif /* FSFW_DEVICEHANDLER_COOKIE_H_ */
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef DEVICECOMMUNICATIONIF_H_
|
#ifndef FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_
|
||||||
#define DEVICECOMMUNICATIONIF_H_
|
#define FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_
|
||||||
|
|
||||||
#include "CookieIF.h"
|
#include "CookieIF.h"
|
||||||
|
#include "DeviceHandlerIF.h"
|
||||||
|
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include <cstddef>
|
|
||||||
/**
|
/**
|
||||||
* @defgroup interfaces Interfaces
|
* @defgroup interfaces Interfaces
|
||||||
* @brief Interfaces for flight software objects
|
* @brief Interfaces for flight software objects
|
||||||
@ -19,8 +20,8 @@
|
|||||||
* the device handler to allow reuse of these components.
|
* the device handler to allow reuse of these components.
|
||||||
* @details
|
* @details
|
||||||
* Documentation: Dissertation Baetz p.138.
|
* Documentation: Dissertation Baetz p.138.
|
||||||
* It works with the assumption that received data
|
* It works with the assumption that received data is polled by a component.
|
||||||
* is polled by a component. There are four generic steps of device communication:
|
* There are four generic steps of device communication:
|
||||||
*
|
*
|
||||||
* 1. Send data to a device
|
* 1. Send data to a device
|
||||||
* 2. Get acknowledgement for sending
|
* 2. Get acknowledgement for sending
|
||||||
@ -38,24 +39,20 @@ class DeviceCommunicationIF: public HasReturnvaluesIF {
|
|||||||
public:
|
public:
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
|
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
|
||||||
|
|
||||||
//! Standard Error Codes
|
//! This is returned in readReceivedMessage() if no reply was reived.
|
||||||
|
static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0x01);
|
||||||
|
|
||||||
//! General protocol error. Define more concrete errors in child handler
|
//! General protocol error. Define more concrete errors in child handler
|
||||||
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x01);
|
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
|
||||||
//! If cookie is a null pointer
|
//! If cookie is a null pointer
|
||||||
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x02);
|
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x03);
|
||||||
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x03);
|
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x04);
|
||||||
// is this needed if there is no open/close call?
|
// is this needed if there is no open/close call?
|
||||||
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
|
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
|
||||||
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0x06);
|
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
|
||||||
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x07);
|
|
||||||
static const ReturnValue_t CANT_CHANGE_REPLY_LEN = MAKE_RETURN_CODE(0x08);
|
|
||||||
|
|
||||||
//! Can be used in readReceivedMessage() if no reply was received.
|
|
||||||
static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0xA1);
|
|
||||||
|
|
||||||
virtual ~DeviceCommunicationIF() {}
|
virtual ~DeviceCommunicationIF() {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Device specific initialization, using the cookie.
|
* @brief Device specific initialization, using the cookie.
|
||||||
* @details
|
* @details
|
||||||
@ -76,13 +73,13 @@ public:
|
|||||||
* by implementing and calling related drivers or wrapper functions.
|
* by implementing and calling related drivers or wrapper functions.
|
||||||
* @param cookie
|
* @param cookie
|
||||||
* @param data
|
* @param data
|
||||||
* @param len
|
* @param len If this is 0, nothing shall be sent.
|
||||||
* @return
|
* @return
|
||||||
* - @c RETURN_OK for successfull send
|
* - @c RETURN_OK for successfull send
|
||||||
* - Everything else triggers failure event with returnvalue as parameter 1
|
* - Everything else triggers failure event with returnvalue as parameter 1
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
|
virtual ReturnValue_t sendMessage(CookieIF *cookie,
|
||||||
size_t sendLen) = 0;
|
const uint8_t * sendData, size_t sendLen) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by DHB in the GET_WRITE doGetWrite().
|
* Called by DHB in the GET_WRITE doGetWrite().
|
||||||
@ -108,7 +105,7 @@ public:
|
|||||||
* returnvalue as parameter 1
|
* returnvalue as parameter 1
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
||||||
size_t requestLen) = 0;
|
size_t requestLen) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by DHB in the GET_WRITE doGetRead().
|
* Called by DHB in the GET_WRITE doGetRead().
|
||||||
@ -124,8 +121,8 @@ public:
|
|||||||
* - Everything else triggers failure event with
|
* - Everything else triggers failure event with
|
||||||
* returnvalue as parameter 1
|
* returnvalue as parameter 1
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
||||||
size_t *size) = 0;
|
uint8_t **buffer, size_t *size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DEVICECOMMUNICATIONIF_H_ */
|
#endif /* FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_ */
|
||||||
|
@ -2,15 +2,17 @@
|
|||||||
#include "AcceptsDeviceResponsesIF.h"
|
#include "AcceptsDeviceResponsesIF.h"
|
||||||
#include "DeviceTmReportingWrapper.h"
|
#include "DeviceTmReportingWrapper.h"
|
||||||
|
|
||||||
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
#include "../datapoolglob/GlobalDataSet.h"
|
||||||
|
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||||
#include "../objectmanager/ObjectManager.h"
|
#include "../objectmanager/ObjectManager.h"
|
||||||
#include "../storagemanager/StorageManagerIF.h"
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
#include "../thermal/ThermalComponentIF.h"
|
#include "../thermal/ThermalComponentIF.h"
|
||||||
#include "../datapool/DataSet.h"
|
|
||||||
#include "../datapool/PoolVariable.h"
|
|
||||||
#include "../globalfunctions/CRC.h"
|
#include "../globalfunctions/CRC.h"
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../housekeeping/HousekeepingMessage.h"
|
||||||
|
#include "../ipc/MessageQueueMessage.h"
|
||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
@ -25,10 +27,11 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
|
|||||||
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
|
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
|
||||||
deviceCommunicationId(deviceCommunication), comCookie(comCookie),
|
deviceCommunicationId(deviceCommunication), comCookie(comCookie),
|
||||||
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
||||||
actionHelper(this, nullptr), childTransitionFailure(RETURN_OK),
|
actionHelper(this, nullptr), hkManager(this, nullptr),
|
||||||
fdirInstance(fdirInstance), hkSwitcher(this),
|
childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
|
||||||
defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false),
|
hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
|
||||||
childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN),
|
switchOffWasReported(false), childTransitionDelay(5000),
|
||||||
|
transitionSourceMode(_MODE_POWER_DOWN),
|
||||||
transitionSourceSubMode(SUBMODE_NONE) {
|
transitionSourceSubMode(SUBMODE_NONE) {
|
||||||
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
||||||
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||||
@ -48,6 +51,10 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceHandlerBase::setHkDestination(object_id_t hkDestination) {
|
||||||
|
this->hkDestination = hkDestination;
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceHandlerBase::setThermalStateRequestPoolIds(
|
void DeviceHandlerBase::setThermalStateRequestPoolIds(
|
||||||
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId) {
|
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId) {
|
||||||
this->deviceThermalRequestPoolId = thermalStatePoolId;
|
this->deviceThermalRequestPoolId = thermalStatePoolId;
|
||||||
@ -65,8 +72,13 @@ DeviceHandlerBase::~DeviceHandlerBase() {
|
|||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
|
ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
|
||||||
this->pstStep = counter;
|
this->pstStep = counter;
|
||||||
|
this->lastStep = this->pstStep;
|
||||||
|
|
||||||
if (getComAction() == SEND_WRITE) {
|
if (getComAction() == CommunicationAction::NOTHING) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getComAction() == CommunicationAction::PERFORM_OPERATION) {
|
||||||
cookieInfo.state = COOKIE_UNUSED;
|
cookieInfo.state = COOKIE_UNUSED;
|
||||||
readCommandQueue();
|
readCommandQueue();
|
||||||
doStateMachine();
|
doStateMachine();
|
||||||
@ -74,27 +86,31 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
|
|||||||
decrementDeviceReplyMap();
|
decrementDeviceReplyMap();
|
||||||
fdirInstance->checkForFailures();
|
fdirInstance->checkForFailures();
|
||||||
hkSwitcher.performOperation();
|
hkSwitcher.performOperation();
|
||||||
|
hkManager.performHkOperation();
|
||||||
performOperationHook();
|
performOperationHook();
|
||||||
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == MODE_OFF) {
|
if (mode == MODE_OFF) {
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (getComAction()) {
|
switch (getComAction()) {
|
||||||
case SEND_WRITE:
|
case CommunicationAction::SEND_WRITE:
|
||||||
if ((cookieInfo.state == COOKIE_UNUSED)) {
|
if (cookieInfo.state == COOKIE_UNUSED) {
|
||||||
|
// if no external command was specified, build internal command.
|
||||||
buildInternalCommand();
|
buildInternalCommand();
|
||||||
}
|
}
|
||||||
doSendWrite();
|
doSendWrite();
|
||||||
break;
|
break;
|
||||||
case GET_WRITE:
|
case CommunicationAction::GET_WRITE:
|
||||||
doGetWrite();
|
doGetWrite();
|
||||||
break;
|
break;
|
||||||
case SEND_READ:
|
case CommunicationAction::SEND_READ:
|
||||||
doSendRead();
|
doSendRead();
|
||||||
break;
|
break;
|
||||||
case GET_READ:
|
case CommunicationAction::GET_READ:
|
||||||
doGetRead();
|
doGetRead();
|
||||||
cookieInfo.state = COOKIE_UNUSED;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -120,7 +136,9 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
|||||||
|
|
||||||
result = communicationInterface->initializeInterface(comCookie);
|
result = communicationInterface->initializeInterface(comCookie);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
sif::error << "DeviceHandlerBase::initialize: Initializing "
|
||||||
|
"communication interface failed!" << std::endl;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||||
@ -183,11 +201,16 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = hkManager.initialize(commandQueue);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
fillCommandAndReplyMap();
|
fillCommandAndReplyMap();
|
||||||
|
|
||||||
//Set temperature target state to NON_OP.
|
//Set temperature target state to NON_OP.
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_WRITE);
|
PoolVariableIF::VAR_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
||||||
@ -245,10 +268,10 @@ void DeviceHandlerBase::readCommandQueue() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// result = hkManager.handleHousekeepingMessage(&command);
|
result = hkManager.handleHousekeepingMessage(&command);
|
||||||
// if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
result = handleDeviceHandlerMessage(&command);
|
result = handleDeviceHandlerMessage(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
@ -376,24 +399,28 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode,
|
|||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
|
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
|
||||||
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
|
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
|
||||||
size_t replyLen, bool periodic, bool hasDifferentReplyId,
|
LocalPoolDataSetBase* replyDataSet, size_t replyLen, bool periodic,
|
||||||
DeviceCommandId_t replyId) {
|
bool hasDifferentReplyId, DeviceCommandId_t replyId) {
|
||||||
//No need to check, as we may try to insert multiple times.
|
//No need to check, as we may try to insert multiple times.
|
||||||
insertInCommandMap(deviceCommand);
|
insertInCommandMap(deviceCommand);
|
||||||
if (hasDifferentReplyId) {
|
if (hasDifferentReplyId) {
|
||||||
return insertInReplyMap(replyId, maxDelayCycles, replyLen, periodic);
|
return insertInReplyMap(replyId, maxDelayCycles,
|
||||||
|
replyDataSet, replyLen, periodic);
|
||||||
} else {
|
} else {
|
||||||
return insertInReplyMap(deviceCommand, maxDelayCycles, replyLen, periodic);
|
return insertInReplyMap(deviceCommand, maxDelayCycles,
|
||||||
|
replyDataSet, replyLen, periodic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
|
ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
|
||||||
uint16_t maxDelayCycles, size_t replyLen, bool periodic) {
|
uint16_t maxDelayCycles, LocalPoolDataSetBase* dataSet,
|
||||||
|
size_t replyLen, bool periodic) {
|
||||||
DeviceReplyInfo info;
|
DeviceReplyInfo info;
|
||||||
info.maxDelayCycles = maxDelayCycles;
|
info.maxDelayCycles = maxDelayCycles;
|
||||||
info.periodic = periodic;
|
info.periodic = periodic;
|
||||||
info.delayCycles = 0;
|
info.delayCycles = 0;
|
||||||
info.replyLen = replyLen;
|
info.replyLen = replyLen;
|
||||||
|
info.dataSet = dataSet;
|
||||||
info.command = deviceCommandMap.end();
|
info.command = deviceCommandMap.end();
|
||||||
auto resultPair = deviceReplyMap.emplace(replyId, info);
|
auto resultPair = deviceReplyMap.emplace(replyId, info);
|
||||||
if (resultPair.second) {
|
if (resultPair.second) {
|
||||||
@ -419,13 +446,12 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(
|
|||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply,
|
ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply,
|
||||||
uint16_t delayCycles, uint16_t maxDelayCycles, bool periodic) {
|
uint16_t delayCycles, uint16_t maxDelayCycles, bool periodic) {
|
||||||
std::map<DeviceCommandId_t, DeviceReplyInfo>::iterator iter =
|
auto replyIter = deviceReplyMap.find(deviceReply);
|
||||||
deviceReplyMap.find(deviceReply);
|
if (replyIter == deviceReplyMap.end()) {
|
||||||
if (iter == deviceReplyMap.end()) {
|
|
||||||
triggerEvent(INVALID_DEVICE_COMMAND, deviceReply);
|
triggerEvent(INVALID_DEVICE_COMMAND, deviceReply);
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
} else {
|
} else {
|
||||||
DeviceReplyInfo *info = &(iter->second);
|
DeviceReplyInfo *info = &(replyIter->second);
|
||||||
if (maxDelayCycles != 0) {
|
if (maxDelayCycles != 0) {
|
||||||
info->maxDelayCycles = maxDelayCycles;
|
info->maxDelayCycles = maxDelayCycles;
|
||||||
}
|
}
|
||||||
@ -435,6 +461,17 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t DeviceHandlerBase::setReplyDataset(DeviceCommandId_t replyId,
|
||||||
|
LocalPoolDataSetBase *dataSet) {
|
||||||
|
auto replyIter = deviceReplyMap.find(replyId);
|
||||||
|
if(replyIter == deviceReplyMap.end()) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
replyIter->second.dataSet = dataSet;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceHandlerBase::callChildStatemachine() {
|
void DeviceHandlerBase::callChildStatemachine() {
|
||||||
if (mode == _MODE_START_UP) {
|
if (mode == _MODE_START_UP) {
|
||||||
doStartUp();
|
doStartUp();
|
||||||
@ -469,8 +506,8 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
|||||||
Clock::getUptime(&timeoutStart);
|
Clock::getUptime(&timeoutStart);
|
||||||
|
|
||||||
if (mode == MODE_OFF) {
|
if (mode == MODE_OFF) {
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||||
@ -649,7 +686,7 @@ void DeviceHandlerBase::doGetRead() {
|
|||||||
void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
|
void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
|
||||||
size_t receivedDataLen) {
|
size_t receivedDataLen) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
DeviceCommandId_t foundId = 0xFFFFFFFF;
|
DeviceCommandId_t foundId = DeviceHandlerIF::NO_COMMAND;
|
||||||
size_t foundLen = 0;
|
size_t foundLen = 0;
|
||||||
// The loop may not execute more often than the number of received bytes
|
// The loop may not execute more often than the number of received bytes
|
||||||
// (worst case). This approach avoids infinite loops due to buggy
|
// (worst case). This approach avoids infinite loops due to buggy
|
||||||
@ -661,18 +698,26 @@ void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case RETURN_OK:
|
case RETURN_OK:
|
||||||
handleReply(receivedData, foundId, foundLen);
|
handleReply(receivedData, foundId, foundLen);
|
||||||
|
if(foundLen == 0) {
|
||||||
|
sif::warning << "DeviceHandlerBase::parseReply: foundLen is 0!"
|
||||||
|
" Packet parsing will be stuck." << std::endl;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case APERIODIC_REPLY: {
|
case APERIODIC_REPLY: {
|
||||||
result = interpretDeviceReply(foundId, receivedData);
|
result = interpretDeviceReply(foundId, receivedData);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||||
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result,
|
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result,
|
||||||
foundId);
|
foundId);
|
||||||
|
}
|
||||||
|
if(foundLen == 0) {
|
||||||
|
sif::warning << "DeviceHandlerBase::parseReply: foundLen is 0!"
|
||||||
|
" Packet parsing will be stuck." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
case IGNORE_REPLY_DATA:
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case IGNORE_REPLY_DATA:
|
||||||
|
continue;
|
||||||
case IGNORE_FULL_PACKET:
|
case IGNORE_FULL_PACKET:
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
@ -704,16 +749,19 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
|
|||||||
DeviceReplyInfo *info = &(iter->second);
|
DeviceReplyInfo *info = &(iter->second);
|
||||||
|
|
||||||
if (info->delayCycles != 0) {
|
if (info->delayCycles != 0) {
|
||||||
|
result = interpretDeviceReply(foundId, receivedData);
|
||||||
|
|
||||||
if (info->periodic != false) {
|
if(result == IGNORE_REPLY_DATA) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info->periodic) {
|
||||||
info->delayCycles = info->maxDelayCycles;
|
info->delayCycles = info->maxDelayCycles;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info->delayCycles = 0;
|
info->delayCycles = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = interpretDeviceReply(foundId, receivedData);
|
|
||||||
|
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
// Report failed interpretation to FDIR.
|
// Report failed interpretation to FDIR.
|
||||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||||
@ -781,24 +829,27 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Default child implementations
|
//Default child implementations
|
||||||
DeviceHandlerIF::CommunicationAction_t DeviceHandlerBase::getComAction() {
|
DeviceHandlerIF::CommunicationAction DeviceHandlerBase::getComAction() {
|
||||||
switch (pstStep) {
|
switch (pstStep) {
|
||||||
case 0:
|
case 0:
|
||||||
return SEND_WRITE;
|
return CommunicationAction::PERFORM_OPERATION;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
return GET_WRITE;
|
return CommunicationAction::SEND_WRITE;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
return SEND_READ;
|
return CommunicationAction::GET_WRITE;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
return GET_READ;
|
return CommunicationAction::SEND_READ;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
return CommunicationAction::GET_READ;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return NOTHING;
|
return CommunicationAction::NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageQueueId_t DeviceHandlerBase::getCommandQueue() const {
|
MessageQueueId_t DeviceHandlerBase::getCommandQueue() const {
|
||||||
@ -926,10 +977,10 @@ ReturnValue_t DeviceHandlerBase::checkModeCommand(Mode_t commandedMode,
|
|||||||
|
|
||||||
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
||||||
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
db_int8_t thermalState(deviceThermalStatePoolId, &mySet,
|
gp_uint8_t thermalState(deviceThermalStatePoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||||
@ -956,8 +1007,8 @@ void DeviceHandlerBase::startTransition(Mode_t commandedMode,
|
|||||||
childTransitionDelay = getTransitionDelayMs(_MODE_START_UP,
|
childTransitionDelay = getTransitionDelayMs(_MODE_START_UP,
|
||||||
MODE_ON);
|
MODE_ON);
|
||||||
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
db_int8_t thermalRequest(deviceThermalRequestPoolId,
|
gp_int8_t thermalRequest(deviceThermalRequestPoolId,
|
||||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||||
@ -1089,19 +1140,6 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage(
|
|||||||
}
|
}
|
||||||
replyReturnvalueToCommand(RETURN_OK);
|
replyReturnvalueToCommand(RETURN_OK);
|
||||||
return RETURN_OK;
|
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:
|
case DeviceHandlerMessage::CMD_RAW:
|
||||||
if ((mode != MODE_RAW)) {
|
if ((mode != MODE_RAW)) {
|
||||||
DeviceHandlerMessage::clear(message);
|
DeviceHandlerMessage::clear(message);
|
||||||
@ -1185,7 +1223,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
|||||||
}
|
}
|
||||||
//Try to cast to GlobDataSet and commit data.
|
//Try to cast to GlobDataSet and commit data.
|
||||||
if (!neverInDataPool) {
|
if (!neverInDataPool) {
|
||||||
DataSet* dataSet = dynamic_cast<DataSet*>(data);
|
GlobDataSet* dataSet = dynamic_cast<GlobDataSet*>(data);
|
||||||
if (dataSet != NULL) {
|
if (dataSet != NULL) {
|
||||||
dataSet->commit(PoolVariableIF::VALID);
|
dataSet->commit(PoolVariableIF::VALID);
|
||||||
}
|
}
|
||||||
@ -1248,10 +1286,14 @@ void DeviceHandlerBase::buildInternalCommand(void) {
|
|||||||
if (iter == deviceCommandMap.end()) {
|
if (iter == deviceCommandMap.end()) {
|
||||||
result = COMMAND_NOT_SUPPORTED;
|
result = COMMAND_NOT_SUPPORTED;
|
||||||
} else if (iter->second.isExecuting) {
|
} else if (iter->second.isExecuting) {
|
||||||
|
//so we can track misconfigurations
|
||||||
sif::debug << std::hex << getObjectId()
|
sif::debug << std::hex << getObjectId()
|
||||||
<< ": DHB::buildInternalCommand: Command "
|
<< ": DHB::buildInternalCommand: Command "
|
||||||
<< deviceCommandId << " isExecuting" << std::endl; //so we can track misconfigurations
|
<< deviceCommandId << " isExecuting" << std::dec
|
||||||
return; //this is an internal command, no need to report a failure here, missed reply will track if a reply is too late, otherwise, it's ok
|
<< std::endl;
|
||||||
|
// this is an internal command, no need to report a failure here,
|
||||||
|
// missed reply will track if a reply is too late, otherwise, it's ok
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
iter->second.sendReplyTo = NO_COMMANDER;
|
iter->second.sendReplyTo = NO_COMMANDER;
|
||||||
iter->second.isExecuting = true;
|
iter->second.isExecuting = true;
|
||||||
@ -1340,12 +1382,50 @@ void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
|
|||||||
void DeviceHandlerBase::performOperationHook() {
|
void DeviceHandlerBase::performOperationHook() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t DeviceHandlerBase::initializeLocalDataPool(
|
||||||
|
LocalDataPool &localDataPoolMap,
|
||||||
|
LocalDataPoolManager& poolManager) {
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() {
|
||||||
|
return &hkManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() {
|
ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() {
|
||||||
// In this function, the task handle should be valid if the task
|
// In this function, the task handle should be valid if the task
|
||||||
// was implemented correctly. We still check to be 1000 % sure :-)
|
// was implemented correctly. We still check to be 1000 % sure :-)
|
||||||
if(executingTask != nullptr) {
|
if(executingTask != nullptr) {
|
||||||
pstIntervalMs = executingTask->getPeriodMs();
|
pstIntervalMs = executingTask->getPeriodMs();
|
||||||
}
|
}
|
||||||
|
this->hkManager.initializeAfterTaskCreation();
|
||||||
|
|
||||||
|
if(setStartupImmediately) {
|
||||||
|
startTransition(MODE_ON, SUBMODE_NONE);
|
||||||
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalPoolDataSetBase* DeviceHandlerBase::getDataSetHandle(sid_t sid) {
|
||||||
|
auto iter = deviceReplyMap.find(sid.ownerSetId);
|
||||||
|
if(iter != deviceReplyMap.end()) {
|
||||||
|
return iter->second.dataSet;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object_id_t DeviceHandlerBase::getObjectId() const {
|
||||||
|
return SystemObject::getObjectId();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceHandlerBase::setStartUpImmediately() {
|
||||||
|
this->setStartupImmediately = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
dur_millis_t DeviceHandlerBase::getPeriodicOperationFrequency() const {
|
||||||
|
return pstIntervalMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
#ifndef FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
||||||
#define FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
||||||
|
|
||||||
#include "DeviceHandlerIF.h"
|
#include "DeviceHandlerIF.h"
|
||||||
#include "DeviceCommunicationIF.h"
|
#include "DeviceCommunicationIF.h"
|
||||||
#include "DeviceHandlerFailureIsolation.h"
|
#include "DeviceHandlerFailureIsolation.h"
|
||||||
|
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
#include "../tasks/PeriodicTaskIF.h"
|
|
||||||
#include "../tasks/ExecutableObjectIF.h"
|
#include "../tasks/ExecutableObjectIF.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../action/HasActionsIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
@ -14,10 +13,13 @@
|
|||||||
#include "../modes/HasModesIF.h"
|
#include "../modes/HasModesIF.h"
|
||||||
#include "../power/PowerSwitchIF.h"
|
#include "../power/PowerSwitchIF.h"
|
||||||
#include "../ipc/MessageQueueIF.h"
|
#include "../ipc/MessageQueueIF.h"
|
||||||
|
#include "../tasks/PeriodicTaskIF.h"
|
||||||
#include "../action/ActionHelper.h"
|
#include "../action/ActionHelper.h"
|
||||||
#include "../health/HealthHelper.h"
|
#include "../health/HealthHelper.h"
|
||||||
#include "../parameters/ParameterHelper.h"
|
#include "../parameters/ParameterHelper.h"
|
||||||
#include "../datapool/HkSwitchHelper.h"
|
#include "../datapool/HkSwitchHelper.h"
|
||||||
|
#include "../datapoollocal/HasLocalDataPoolIF.h"
|
||||||
|
#include "../datapoollocal/LocalDataPoolManager.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -38,17 +40,16 @@ class StorageManagerIF;
|
|||||||
* Documentation: Dissertation Baetz p.138,139, p.141-149
|
* Documentation: Dissertation Baetz p.138,139, p.141-149
|
||||||
*
|
*
|
||||||
* It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink,
|
* It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink,
|
||||||
* communication with physical devices, using the @link DeviceCommunicationIF @endlink,
|
* communication with physical devices, using the
|
||||||
* and communication with commanding objects.
|
* @link DeviceCommunicationIF @endlink, and communication with commanding
|
||||||
* It inherits SystemObject and thus can be created by the ObjectManagerIF.
|
* objects. It inherits SystemObject and thus can be created by the
|
||||||
|
* ObjectManagerIF.
|
||||||
*
|
*
|
||||||
* This class uses the opcode of ExecutableObjectIF to perform a step-wise execution.
|
* This class uses the opcode of ExecutableObjectIF to perform a
|
||||||
* For each step an RMAP action is selected and executed.
|
* step-wise execution. For each step a different action is selected and
|
||||||
* If data has been received (GET_READ), the data will be interpreted.
|
* executed. Currently, the device handler base performs a 4-step
|
||||||
* The action for each step can be defined by the child class but as most
|
* execution related to 4 communication steps (based on RMAP).
|
||||||
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure,
|
* NOTE: RMAP is a standard which is used for Flying Laptop.
|
||||||
* a default implementation is provided.
|
|
||||||
* NOTE: RMAP is a standard which is used for FLP.
|
|
||||||
* RMAP communication is not mandatory for projects implementing the FSFW.
|
* RMAP communication is not mandatory for projects implementing the FSFW.
|
||||||
* However, the communication principles are similar to RMAP as there are
|
* However, the communication principles are similar to RMAP as there are
|
||||||
* two write and two send calls involved.
|
* two write and two send calls involved.
|
||||||
@ -69,9 +70,6 @@ class StorageManagerIF;
|
|||||||
*
|
*
|
||||||
* Other important virtual methods with a default implementation
|
* Other important virtual methods with a default implementation
|
||||||
* are the getTransitionDelayMs() function and the getSwitches() function.
|
* are the getTransitionDelayMs() function and the getSwitches() function.
|
||||||
* Please ensure that getSwitches() returns DeviceHandlerIF::NO_SWITCHES if
|
|
||||||
* power switches are not implemented yet. Otherwise, the device handler will
|
|
||||||
* not transition to MODE_ON, even if setMode(MODE_ON) is called.
|
|
||||||
* If a transition to MODE_ON is desired without commanding, override the
|
* If a transition to MODE_ON is desired without commanding, override the
|
||||||
* intialize() function and call setMode(_MODE_START_UP) before calling
|
* intialize() function and call setMode(_MODE_START_UP) before calling
|
||||||
* DeviceHandlerBase::initialize().
|
* DeviceHandlerBase::initialize().
|
||||||
@ -85,20 +83,18 @@ class DeviceHandlerBase: public DeviceHandlerIF,
|
|||||||
public HasModesIF,
|
public HasModesIF,
|
||||||
public HasHealthIF,
|
public HasHealthIF,
|
||||||
public HasActionsIF,
|
public HasActionsIF,
|
||||||
public ReceivesParameterMessagesIF {
|
public ReceivesParameterMessagesIF,
|
||||||
|
public HasLocalDataPoolIF {
|
||||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* The constructor passes the objectId to the SystemObject().
|
* The constructor passes the objectId to the SystemObject().
|
||||||
*
|
*
|
||||||
* @param setObjectId the ObjectId to pass to the SystemObject() Constructor
|
* @param setObjectId the ObjectId to pass to the SystemObject() Constructor
|
||||||
* @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
|
* @param deviceCommuncation Communcation Interface object which is used
|
||||||
* to implement communication functions
|
* to implement communication functions
|
||||||
* @param thermalStatePoolId
|
* @param comCookie This object will be passed to the communication inter-
|
||||||
* @param thermalRequestPoolId
|
* face and can contain user-defined information about the communication.
|
||||||
* @param fdirInstance
|
* @param fdirInstance
|
||||||
* @param cmdQueueSize
|
* @param cmdQueueSize
|
||||||
*/
|
*/
|
||||||
@ -106,8 +102,21 @@ public:
|
|||||||
CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr,
|
CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr,
|
||||||
size_t cmdQueueSize = 20);
|
size_t cmdQueueSize = 20);
|
||||||
|
|
||||||
|
void setHkDestination(object_id_t hkDestination);
|
||||||
void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId,
|
void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId,
|
||||||
uint32_t thermalRequestPoolId);
|
uint32_t thermalRequestPoolId);
|
||||||
|
/**
|
||||||
|
* @brief Helper function to ease device handler development.
|
||||||
|
* This will instruct the transition to MODE_ON immediately
|
||||||
|
* (leading to doStartUp() being called for the transition to the ON mode),
|
||||||
|
* so external mode commanding is not necessary anymore.
|
||||||
|
*
|
||||||
|
* This has to be called before the task is started!
|
||||||
|
* (e.g. in the task factory). This is only a helper function for
|
||||||
|
* development. Regular mode commanding should be performed by commanding
|
||||||
|
* the AssemblyBase or Subsystem objects resposible for the device handler.
|
||||||
|
*/
|
||||||
|
void setStartUpImmediately();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is the device handler base core component and is
|
* @brief This function is the device handler base core component and is
|
||||||
@ -153,6 +162,14 @@ public:
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t initialize();
|
virtual ReturnValue_t initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Intialization steps performed after all tasks have been created.
|
||||||
|
* This function will be called by the executing task.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
|
|
||||||
/** Destructor. */
|
/** Destructor. */
|
||||||
virtual ~DeviceHandlerBase();
|
virtual ~DeviceHandlerBase();
|
||||||
|
|
||||||
@ -320,6 +337,8 @@ protected:
|
|||||||
* @param packet
|
* @param packet
|
||||||
* @return
|
* @return
|
||||||
* - @c RETURN_OK when the reply was interpreted.
|
* - @c RETURN_OK when the reply was interpreted.
|
||||||
|
* - @c IGNORE_REPLY_DATA Ignore the reply and don't reset reply cycle
|
||||||
|
* counter.
|
||||||
* - @c RETURN_FAILED when the reply could not be interpreted,
|
* - @c RETURN_FAILED when the reply could not be interpreted,
|
||||||
* e.g. logical errors or range violations occurred
|
* e.g. logical errors or range violations occurred
|
||||||
*/
|
*/
|
||||||
@ -347,22 +366,10 @@ protected:
|
|||||||
* set to the maximum expected number of PST cycles between two replies
|
* set to the maximum expected number of PST cycles between two replies
|
||||||
* (also a tolerance should be added, as an FDIR message will be
|
* (also a tolerance should be added, as an FDIR message will be
|
||||||
* generated if it is missed).
|
* generated if it is missed).
|
||||||
*
|
|
||||||
* (Robin) This part confuses me. "must do as soon as" implies that
|
|
||||||
* the developer must do something somewhere else in the code. Is
|
|
||||||
* that really the case? If I understood correctly, DHB performs
|
|
||||||
* almost everything (e.g. in erirm function) as long as the commands
|
|
||||||
* are inserted correctly.
|
|
||||||
*
|
|
||||||
* As soon as the replies are enabled, DeviceCommandInfo.periodic must
|
|
||||||
* be set to true, DeviceCommandInfo.delayCycles to
|
|
||||||
* DeviceCommandInfo.maxDelayCycles.
|
|
||||||
* From then on, the base class handles the reception.
|
* From then on, the base class handles the reception.
|
||||||
* Then, scanForReply returns the id of the reply or the placeholder id
|
* Then, scanForReply returns the id of the reply or the placeholder id
|
||||||
* and the base class will take care of checking that all replies are
|
* and the base class will take care of checking that all replies are
|
||||||
* received and the interval is correct.
|
* received and the interval is correct.
|
||||||
* When the replies are disabled, DeviceCommandInfo.periodic must be set
|
|
||||||
* to 0, DeviceCommandInfo.delayCycles to 0;
|
|
||||||
*
|
*
|
||||||
* - Aperiodic, unrequested replies. These are replies that are sent
|
* - Aperiodic, unrequested replies. These are replies that are sent
|
||||||
* by the device without any preceding command and not in a defined
|
* by the device without any preceding command and not in a defined
|
||||||
@ -376,13 +383,17 @@ protected:
|
|||||||
* @param deviceCommand Identifier of the command to add.
|
* @param deviceCommand Identifier of the command to add.
|
||||||
* @param maxDelayCycles The maximum number of delay cycles the command
|
* @param maxDelayCycles The maximum number of delay cycles the command
|
||||||
* waits until it times out.
|
* waits until it times out.
|
||||||
|
* @param replyLen Will be supplied to the requestReceiveMessage call of
|
||||||
|
* the communication interface.
|
||||||
* @param periodic Indicates if the command is periodic (i.e. it is sent
|
* @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)
|
* by the device repeatedly without request) or not. Default is aperiodic (0)
|
||||||
* @return - @c RETURN_OK when the command was successfully inserted,
|
* @return - @c RETURN_OK when the command was successfully inserted,
|
||||||
* - @c RETURN_FAILED else.
|
* - @c RETURN_FAILED else.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
|
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
|
||||||
uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = false,
|
uint16_t maxDelayCycles,
|
||||||
|
LocalPoolDataSetBase* replyDataSet = nullptr,
|
||||||
|
size_t replyLen = 0, bool periodic = false,
|
||||||
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
|
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -396,7 +407,8 @@ protected:
|
|||||||
* - @c RETURN_FAILED else.
|
* - @c RETURN_FAILED else.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand,
|
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand,
|
||||||
uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = false);
|
uint16_t maxDelayCycles, LocalPoolDataSetBase* dataSet = nullptr,
|
||||||
|
size_t replyLen = 0, bool periodic = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A simple command to add a command to the commandList.
|
* @brief A simple command to add a command to the commandList.
|
||||||
@ -424,6 +436,9 @@ protected:
|
|||||||
uint16_t delayCycles, uint16_t maxDelayCycles,
|
uint16_t delayCycles, uint16_t maxDelayCycles,
|
||||||
bool periodic = false);
|
bool periodic = false);
|
||||||
|
|
||||||
|
ReturnValue_t setReplyDataset(DeviceCommandId_t replyId,
|
||||||
|
LocalPoolDataSetBase* dataset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Can be implemented by child handler to
|
* @brief Can be implemented by child handler to
|
||||||
* perform debugging
|
* perform debugging
|
||||||
@ -477,18 +492,22 @@ protected:
|
|||||||
* @param localDataPoolMap
|
* @param localDataPoolMap
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//virtual ReturnValue_t initializePoolEntries(
|
virtual ReturnValue_t initializeLocalDataPool(LocalDataPool& localDataPoolMap,
|
||||||
// LocalDataPool& localDataPoolMap) override;
|
LocalDataPoolManager& poolManager) override;
|
||||||
|
|
||||||
/** Get the HK manager object handle */
|
/** Get the HK manager object handle */
|
||||||
//virtual LocalDataPoolManager* getHkManagerHandle() override;
|
virtual LocalDataPoolManager* getHkManagerHandle() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Hook function for child handlers which is called once per
|
* @brief Hook function for child handlers which is called once per
|
||||||
* performOperation(). Default implementation is empty.
|
* performOperation(). Default implementation is empty.
|
||||||
*/
|
*/
|
||||||
virtual void performOperationHook();
|
virtual void performOperationHook();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Explicit interface implementation of getObjectId */
|
||||||
|
virtual object_id_t getObjectId() const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parentQueueId
|
* @param parentQueueId
|
||||||
*/
|
*/
|
||||||
@ -558,6 +577,7 @@ protected:
|
|||||||
|
|
||||||
/** This is the counter value from performOperation(). */
|
/** This is the counter value from performOperation(). */
|
||||||
uint8_t pstStep = 0;
|
uint8_t pstStep = 0;
|
||||||
|
uint8_t lastStep = 0;
|
||||||
uint32_t pstIntervalMs = 0;
|
uint32_t pstIntervalMs = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -608,7 +628,7 @@ protected:
|
|||||||
/** Action helper for HasActionsIF */
|
/** Action helper for HasActionsIF */
|
||||||
ActionHelper actionHelper;
|
ActionHelper actionHelper;
|
||||||
/** Housekeeping Manager */
|
/** Housekeeping Manager */
|
||||||
//LocalDataPoolManager hkManager;
|
LocalDataPoolManager hkManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Information about commands
|
* @brief Information about commands
|
||||||
@ -647,7 +667,7 @@ protected:
|
|||||||
//! The dataset used to access housekeeping data related to the
|
//! The dataset used to access housekeeping data related to the
|
||||||
//! respective device reply. Will point to a dataset held by
|
//! respective device reply. Will point to a dataset held by
|
||||||
//! the child handler (if one is specified)
|
//! the child handler (if one is specified)
|
||||||
// DataSetIF* dataSet = nullptr;
|
LocalPoolDataSetBase* dataSet;
|
||||||
//! The command that expects this reply.
|
//! The command that expects this reply.
|
||||||
DeviceCommandMap::iterator command;
|
DeviceCommandMap::iterator command;
|
||||||
};
|
};
|
||||||
@ -689,14 +709,18 @@ protected:
|
|||||||
uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER;
|
uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional Error code
|
* Optional Error code. Can be set in doStartUp(), doShutDown() and
|
||||||
* Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure.
|
* doTransition() to signal cause for Transition failure.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t childTransitionFailure;
|
ReturnValue_t childTransitionFailure;
|
||||||
|
|
||||||
uint32_t ignoreMissedRepliesCount = 0; //!< Counts if communication channel lost a reply, so some missed replys can be ignored.
|
/** Counts if communication channel lost a reply, so some missed
|
||||||
|
* replys can be ignored. */
|
||||||
|
uint32_t ignoreMissedRepliesCount = 0;
|
||||||
|
|
||||||
FailureIsolationBase* fdirInstance; //!< Pointer to the used FDIR instance. If not provided by child, default class is instantiated.
|
/** Pointer to the used FDIR instance. If not provided by child,
|
||||||
|
* default class is instantiated. */
|
||||||
|
FailureIsolationBase* fdirInstance;
|
||||||
|
|
||||||
HkSwitchHelper hkSwitcher;
|
HkSwitchHelper hkSwitcher;
|
||||||
|
|
||||||
@ -818,7 +842,7 @@ protected:
|
|||||||
* @return The Rmap action to execute in this step
|
* @return The Rmap action to execute in this step
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual CommunicationAction_t getComAction();
|
virtual CommunicationAction getComAction();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the device command to send for raw mode.
|
* Build the device command to send for raw mode.
|
||||||
@ -944,14 +968,17 @@ protected:
|
|||||||
|
|
||||||
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||||
uint32_t *msToReachTheMode);
|
uint32_t *msToReachTheMode);
|
||||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
|
||||||
virtual void setToExternalControl();
|
/* HasModesIF overrides */
|
||||||
virtual void announceMode(bool recursive);
|
virtual void startTransition(Mode_t mode, Submode_t submode) override;
|
||||||
|
virtual void setToExternalControl() override;
|
||||||
|
virtual void announceMode(bool recursive) override;
|
||||||
|
|
||||||
virtual ReturnValue_t letChildHandleMessage(CommandMessage *message);
|
virtual ReturnValue_t letChildHandleMessage(CommandMessage *message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites SystemObject::triggerEvent in order to inform FDIR"Helper" faster about executed events.
|
* Overwrites SystemObject::triggerEvent in order to inform FDIR"Helper"
|
||||||
|
* faster about executed events.
|
||||||
* This is a bit sneaky, but improves responsiveness of the device FDIR.
|
* This is a bit sneaky, but improves responsiveness of the device FDIR.
|
||||||
* @param event The event to be thrown
|
* @param event The event to be thrown
|
||||||
* @param parameter1 Optional parameter 1
|
* @param parameter1 Optional parameter 1
|
||||||
@ -1034,12 +1061,17 @@ private:
|
|||||||
/** the object used to set power switches */
|
/** the object used to set power switches */
|
||||||
PowerSwitchIF *powerSwitcher = nullptr;
|
PowerSwitchIF *powerSwitcher = nullptr;
|
||||||
|
|
||||||
|
/** HK destination can also be set individually */
|
||||||
|
object_id_t hkDestination = objects::NO_OBJECT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Used for timing out mode transitions.
|
* @brief Used for timing out mode transitions.
|
||||||
* Set when setMode() is called.
|
* Set when setMode() is called.
|
||||||
*/
|
*/
|
||||||
uint32_t timeoutStart = 0;
|
uint32_t timeoutStart = 0;
|
||||||
|
|
||||||
|
bool setStartupImmediately = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delay for the current mode transition, used for time out
|
* Delay for the current mode transition, used for time out
|
||||||
*/
|
*/
|
||||||
@ -1080,11 +1112,6 @@ private:
|
|||||||
void buildRawDeviceCommand(CommandMessage* message);
|
void buildRawDeviceCommand(CommandMessage* message);
|
||||||
void buildInternalCommand(void);
|
void buildInternalCommand(void);
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Send a reply with the current mode and submode.
|
|
||||||
// */
|
|
||||||
// void announceMode(void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrement the counter for the timout of replies.
|
* Decrement the counter for the timout of replies.
|
||||||
*
|
*
|
||||||
@ -1111,10 +1138,14 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Build and send a command to the device.
|
* Build and send a command to the device.
|
||||||
*
|
*
|
||||||
* This routine checks whether a raw or direct command has been received, checks the content of the received command and
|
* This routine checks whether a raw or direct command has been received,
|
||||||
* calls buildCommandFromCommand() for direct commands or sets #rawpacket to the received raw packet.
|
* checks the content of the received command and calls
|
||||||
* If no external command is received or the received command is invalid and the current mode is @c MODE_NORMAL or a transitional mode,
|
* buildCommandFromCommand() for direct commands or sets #rawpacket
|
||||||
* it asks the child class to build a command (via getNormalDeviceCommand() or getTransitionalDeviceCommand() and buildCommand()) and
|
* to the received raw packet.
|
||||||
|
* If no external command is received or the received command is invalid and
|
||||||
|
* the current mode is @c MODE_NORMAL or a transitional mode, it asks the
|
||||||
|
* child class to build a command (via getNormalDeviceCommand() or
|
||||||
|
* getTransitionalDeviceCommand() and buildCommand()) and
|
||||||
* sends the command via RMAP.
|
* sends the command via RMAP.
|
||||||
*/
|
*/
|
||||||
void doSendWrite(void);
|
void doSendWrite(void);
|
||||||
@ -1159,7 +1190,6 @@ private:
|
|||||||
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
|
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
|
||||||
uint32_t *len);
|
uint32_t *len);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
|
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
|
||||||
*/
|
*/
|
||||||
@ -1170,25 +1200,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
void callChildStatemachine();
|
void callChildStatemachine();
|
||||||
|
|
||||||
/**
|
|
||||||
* Switches the channel of the cookie used for the communication
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param newChannel the object Id of the channel to switch to
|
|
||||||
* @return
|
|
||||||
* - @c RETURN_OK when cookie was changed
|
|
||||||
* - @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 handleDeviceHandlerMessage(CommandMessage *message);
|
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
|
||||||
|
|
||||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||||
|
|
||||||
void parseReply(const uint8_t* receivedData,
|
virtual dur_millis_t getPeriodicOperationFrequency() const override;
|
||||||
size_t receivedDataLen);
|
|
||||||
|
void parseReply(const uint8_t* receivedData,
|
||||||
|
size_t receivedDataLen);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ void DeviceHandlerFailureIsolation::triggerEvent(Event event, uint32_t parameter
|
|||||||
uint32_t parameter2) {
|
uint32_t parameter2) {
|
||||||
//Do not throw error events if fdirState != none.
|
//Do not throw error events if fdirState != none.
|
||||||
//This will still forward MODE and HEALTH INFO events in any case.
|
//This will still forward MODE and HEALTH INFO events in any case.
|
||||||
if (fdirState == NONE || EVENT::getSeverity(event) == SEVERITY::INFO) {
|
if (fdirState == NONE || event::getSeverity(event) == severity::INFO) {
|
||||||
FailureIsolationBase::triggerEvent(event, parameter1, parameter2);
|
FailureIsolationBase::triggerEvent(event, parameter1, parameter2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ bool DeviceHandlerFailureIsolation::isFdirActionInProgress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerFailureIsolation::startRecovery(Event reason) {
|
void DeviceHandlerFailureIsolation::startRecovery(Event reason) {
|
||||||
throwFdirEvent(FDIR_STARTS_RECOVERY, EVENT::getEventId(reason));
|
throwFdirEvent(FDIR_STARTS_RECOVERY, event::getEventId(reason));
|
||||||
setOwnerHealth(HasHealthIF::NEEDS_RECOVERY);
|
setOwnerHealth(HasHealthIF::NEEDS_RECOVERY);
|
||||||
setFdirState(RECOVERY_ONGOING);
|
setFdirState(RECOVERY_ONGOING);
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ ReturnValue_t DeviceHandlerFailureIsolation::getParameter(uint8_t domainId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerFailureIsolation::setFaulty(Event reason) {
|
void DeviceHandlerFailureIsolation::setFaulty(Event reason) {
|
||||||
throwFdirEvent(FDIR_TURNS_OFF_DEVICE, EVENT::getEventId(reason));
|
throwFdirEvent(FDIR_TURNS_OFF_DEVICE, event::getEventId(reason));
|
||||||
setOwnerHealth(HasHealthIF::FAULTY);
|
setOwnerHealth(HasHealthIF::FAULTY);
|
||||||
setFdirState(AWAIT_SHUTDOWN);
|
setFdirState(AWAIT_SHUTDOWN);
|
||||||
}
|
}
|
||||||
@ -247,6 +247,14 @@ bool DeviceHandlerFailureIsolation::isFdirInActionOrAreWeFaulty(
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (owner == nullptr) {
|
||||||
|
// Configuration error.
|
||||||
|
sif::error << "DeviceHandlerFailureIsolation::"
|
||||||
|
<< "isFdirInActionOrAreWeFaulty: Owner not set!" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (owner->getHealth() == HasHealthIF::FAULTY
|
if (owner->getHealth() == HasHealthIF::FAULTY
|
||||||
|| owner->getHealth() == HasHealthIF::PERMANENT_FAULTY) {
|
|| owner->getHealth() == HasHealthIF::PERMANENT_FAULTY) {
|
||||||
//Ignore all events in case device is already faulty.
|
//Ignore all events in case device is already faulty.
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
#ifndef DEVICEHANDLERIF_H_
|
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
|
||||||
#define DEVICEHANDLERIF_H_
|
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
|
||||||
|
|
||||||
|
#include "DeviceHandlerMessage.h"
|
||||||
|
|
||||||
#include "../action/HasActionsIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
#include "DeviceHandlerMessage.h"
|
|
||||||
#include "../events/Event.h"
|
#include "../events/Event.h"
|
||||||
#include "../modes/HasModesIF.h"
|
#include "../modes/HasModesIF.h"
|
||||||
#include "../ipc/MessageQueueSenderIF.h"
|
#include "../ipc/MessageQueueSenderIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to uniquely identify commands that are sent to a device
|
||||||
|
* The values are defined in the device-specific implementations
|
||||||
|
*/
|
||||||
|
using DeviceCommandId_t = uint32_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the Interface used to communicate with a device handler.
|
* @brief This is the Interface used to communicate with a device handler.
|
||||||
* @details Includes all expected return values, events and modes.
|
* @details Includes all expected return values, events and modes.
|
||||||
@ -15,6 +22,7 @@
|
|||||||
class DeviceHandlerIF {
|
class DeviceHandlerIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
|
static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
|
||||||
static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
|
static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
|
||||||
|
|
||||||
@ -49,6 +57,8 @@ public:
|
|||||||
//! This is a transitional state which can not be commanded.
|
//! This is a transitional state which can not be commanded.
|
||||||
//! The device handler performs all actions and commands to get the device
|
//! The device handler performs all actions and commands to get the device
|
||||||
//! shut down. When the device is off, the mode changes to @c MODE_OFF.
|
//! shut down. When the device is off, the mode changes to @c MODE_OFF.
|
||||||
|
//! It is possible to set the mode to _MODE_SHUT_DOWN to use the to off
|
||||||
|
//! transition if available.
|
||||||
static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6;
|
static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6;
|
||||||
//! It is possible to set the mode to _MODE_TO_ON to use the to on
|
//! It is possible to set the mode to _MODE_TO_ON to use the to on
|
||||||
//! transition if available.
|
//! transition if available.
|
||||||
@ -83,22 +93,22 @@ public:
|
|||||||
static const Mode_t _MODE_SWITCH_IS_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 5;
|
static const Mode_t _MODE_SWITCH_IS_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 5;
|
||||||
|
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CDH;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CDH;
|
||||||
static const Event DEVICE_BUILDING_COMMAND_FAILED = MAKE_EVENT(0, SEVERITY::LOW);
|
static const Event DEVICE_BUILDING_COMMAND_FAILED = MAKE_EVENT(0, severity::LOW);
|
||||||
static const Event DEVICE_SENDING_COMMAND_FAILED = MAKE_EVENT(1, SEVERITY::LOW);
|
static const Event DEVICE_SENDING_COMMAND_FAILED = MAKE_EVENT(1, severity::LOW);
|
||||||
static const Event DEVICE_REQUESTING_REPLY_FAILED = MAKE_EVENT(2, SEVERITY::LOW);
|
static const Event DEVICE_REQUESTING_REPLY_FAILED = MAKE_EVENT(2, severity::LOW);
|
||||||
static const Event DEVICE_READING_REPLY_FAILED = MAKE_EVENT(3, SEVERITY::LOW);
|
static const Event DEVICE_READING_REPLY_FAILED = MAKE_EVENT(3, severity::LOW);
|
||||||
static const Event DEVICE_INTERPRETING_REPLY_FAILED = MAKE_EVENT(4, SEVERITY::LOW);
|
static const Event DEVICE_INTERPRETING_REPLY_FAILED = MAKE_EVENT(4, severity::LOW);
|
||||||
static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, SEVERITY::LOW);
|
static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, severity::LOW);
|
||||||
static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, SEVERITY::LOW);
|
static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, severity::LOW);
|
||||||
static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, SEVERITY::LOW);
|
static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, severity::LOW);
|
||||||
static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, SEVERITY::LOW); //!< Indicates a SW bug in child class.
|
static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, severity::LOW); //!< Indicates a SW bug in child class.
|
||||||
static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, SEVERITY::LOW);
|
static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, severity::LOW);
|
||||||
static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, SEVERITY::HIGH);
|
static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, severity::HIGH);
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
|
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
|
||||||
|
|
||||||
// Standard codes used when building commands.
|
// Standard codes used when building commands.
|
||||||
static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If the command size is 0. Checked in DHB
|
static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If no command data was given when expected.
|
||||||
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB
|
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB
|
||||||
static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB
|
static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB
|
||||||
static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3);
|
static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3);
|
||||||
@ -131,7 +141,8 @@ public:
|
|||||||
*
|
*
|
||||||
* This is used by the child class to tell the base class what to do.
|
* This is used by the child class to tell the base class what to do.
|
||||||
*/
|
*/
|
||||||
enum CommunicationAction_t: uint8_t {
|
enum CommunicationAction: uint8_t {
|
||||||
|
PERFORM_OPERATION,
|
||||||
SEND_WRITE,//!< Send write
|
SEND_WRITE,//!< Send write
|
||||||
GET_WRITE, //!< Get write
|
GET_WRITE, //!< Get write
|
||||||
SEND_READ, //!< Send read
|
SEND_READ, //!< Send read
|
||||||
@ -152,4 +163,4 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DEVICEHANDLERIF_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_ */
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#include "../objectmanager/ObjectManagerIF.h"
|
|
||||||
#include "DeviceHandlerMessage.h"
|
#include "DeviceHandlerMessage.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
|
||||||
DeviceHandlerMessage::DeviceHandlerMessage() {
|
|
||||||
}
|
|
||||||
|
|
||||||
store_address_t DeviceHandlerMessage::getStoreAddress(
|
store_address_t DeviceHandlerMessage::getStoreAddress(
|
||||||
const CommandMessage* message) {
|
const CommandMessage* message) {
|
||||||
return store_address_t(message->getParameter2());
|
return store_address_t(message->getParameter2());
|
||||||
@ -25,14 +21,6 @@ uint8_t DeviceHandlerMessage::getWiretappingMode(
|
|||||||
return message->getParameter();
|
return message->getParameter();
|
||||||
}
|
}
|
||||||
|
|
||||||
//void DeviceHandlerMessage::setDeviceHandlerDirectCommandMessage(
|
|
||||||
// CommandMessage* message, DeviceCommandId_t deviceCommand,
|
|
||||||
// store_address_t commandParametersStoreId) {
|
|
||||||
// message->setCommand(CMD_DIRECT);
|
|
||||||
// message->setParameter(deviceCommand);
|
|
||||||
// message->setParameter2(commandParametersStoreId.raw);
|
|
||||||
//}
|
|
||||||
|
|
||||||
void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage(
|
void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage(
|
||||||
CommandMessage* message, store_address_t rawPacketStoreId) {
|
CommandMessage* message, store_address_t rawPacketStoreId) {
|
||||||
message->setCommand(CMD_RAW);
|
message->setCommand(CMD_RAW);
|
||||||
@ -47,7 +35,7 @@ void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage(
|
|||||||
|
|
||||||
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
|
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
|
||||||
CommandMessage* message, uint32_t ioBoardIdentifier) {
|
CommandMessage* message, uint32_t ioBoardIdentifier) {
|
||||||
message->setCommand(CMD_SWITCH_IOBOARD);
|
message->setCommand(CMD_SWITCH_ADDRESS);
|
||||||
message->setParameter(ioBoardIdentifier);
|
message->setParameter(ioBoardIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,18 +67,17 @@ void DeviceHandlerMessage::setDeviceHandlerDirectCommandReply(
|
|||||||
void DeviceHandlerMessage::clear(CommandMessage* message) {
|
void DeviceHandlerMessage::clear(CommandMessage* message) {
|
||||||
switch (message->getCommand()) {
|
switch (message->getCommand()) {
|
||||||
case CMD_RAW:
|
case CMD_RAW:
|
||||||
// case CMD_DIRECT:
|
|
||||||
case REPLY_RAW_COMMAND:
|
case REPLY_RAW_COMMAND:
|
||||||
case REPLY_RAW_REPLY:
|
case REPLY_RAW_REPLY:
|
||||||
case REPLY_DIRECT_COMMAND_DATA: {
|
case REPLY_DIRECT_COMMAND_DATA: {
|
||||||
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
|
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
|
||||||
objects::IPC_STORE);
|
objects::IPC_STORE);
|
||||||
if (ipcStore != NULL) {
|
if (ipcStore != nullptr) {
|
||||||
ipcStore->deleteData(getStoreAddress(message));
|
ipcStore->deleteData(getStoreAddress(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* NO BREAK falls through*/
|
/* NO BREAK falls through*/
|
||||||
case CMD_SWITCH_IOBOARD:
|
case CMD_SWITCH_ADDRESS:
|
||||||
case CMD_WIRETAPPING:
|
case CMD_WIRETAPPING:
|
||||||
message->setCommand(CommandMessage::CMD_NONE);
|
message->setCommand(CommandMessage::CMD_NONE);
|
||||||
message->setParameter(0);
|
message->setParameter(0);
|
||||||
|
@ -1,69 +1,56 @@
|
|||||||
#ifndef DEVICEHANDLERMESSAGE_H_
|
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_
|
||||||
#define DEVICEHANDLERMESSAGE_H_
|
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_
|
||||||
|
|
||||||
#include "../action/ActionMessage.h"
|
#include "../action/ActionMessage.h"
|
||||||
#include "../ipc/CommandMessage.h"
|
#include "../ipc/CommandMessage.h"
|
||||||
#include "../objectmanager/SystemObjectIF.h"
|
#include "../objectmanager/SystemObjectIF.h"
|
||||||
#include "../storagemanager/StorageManagerIF.h"
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
//SHOULDDO: rework the static constructors to name the type of command they are building, maybe even hide setting the commandID.
|
// SHOULDDO: rework the static constructors to name the type of command
|
||||||
|
// they are building, maybe even hide setting the commandID.
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used to uniquely identify commands that are sent to a device
|
* @brief The DeviceHandlerMessage is used to send commands to classes
|
||||||
*
|
* implementing DeviceHandlerIF
|
||||||
* The values are defined in the device-specific implementations
|
|
||||||
*/
|
|
||||||
typedef uint32_t DeviceCommandId_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The DeviceHandlerMessage is used to send Commands to a DeviceHandlerIF
|
|
||||||
*/
|
*/
|
||||||
class DeviceHandlerMessage {
|
class DeviceHandlerMessage {
|
||||||
private:
|
|
||||||
DeviceHandlerMessage();
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Instantiation forbidden. Instead, use static functions to operate
|
||||||
|
* on messages.
|
||||||
|
*/
|
||||||
|
DeviceHandlerMessage() = delete;
|
||||||
|
virtual ~DeviceHandlerMessage() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These are the commands that can be sent to a DeviceHandlerBase
|
* These are the commands that can be sent to a DeviceHandlerBase
|
||||||
*/
|
*/
|
||||||
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
|
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
|
||||||
static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send
|
//! Sends a raw command, setParameter is a storeId containing the
|
||||||
// static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command
|
//! raw packet to send
|
||||||
static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
static const Command_t CMD_RAW = MAKE_COMMAND_ID(1);
|
||||||
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID( 4 ); //!< (De)Activates the monitoring of all raw traffic in DeviceHandlers, setParameter is 0 to deactivate, 1 to activate
|
//! Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
||||||
|
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID(3);
|
||||||
|
//! (De)Activates the monitoring of all raw traffic in DeviceHandlers,
|
||||||
|
//! setParameter is 0 to deactivate, 1 to activate
|
||||||
|
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID(4);
|
||||||
|
|
||||||
/*static const Command_t REPLY_SWITCHED_IOBOARD = MAKE_COMMAND_ID(1 );//!< Reply to a @c CMD_SWITCH_IOBOARD, indicates switch was successful, getParameter() contains the board switched to (0: nominal, 1: redundant)
|
//! Signals that a direct command was sent
|
||||||
static const Command_t REPLY_CANT_SWITCH_IOBOARD = MAKE_COMMAND_ID( 2); //!< Reply to a @c CMD_SWITCH_IOBOARD, indicating the switch could not be performed, getParameter() contains the error message
|
static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS;
|
||||||
static const Command_t REPLY_WIRETAPPING = MAKE_COMMAND_ID( 3); //!< Reply to a @c CMD_WIRETAPPING, getParameter() is the current state, 1 enabled, 0 disabled
|
//! Contains a raw command sent to the Device
|
||||||
|
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11);
|
||||||
static const Command_t REPLY_COMMAND_WAS_SENT = MAKE_COMMAND_ID(4 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates the command was successfully sent to the device, getParameter() contains the ::DeviceCommandId_t
|
//! Contains a raw reply from the Device, getParameter() is the ObjcetId
|
||||||
static const Command_t REPLY_COMMAND_NOT_SUPPORTED = MAKE_COMMAND_ID(5 );//!< Reply to a @c CMD_DIRECT, the requested ::DeviceCommand_t is not supported, getParameter() contains the requested ::DeviceCommand_t, getParameter2() contains the ::DeviceCommandId_t
|
//! of the sender, getParameter2() is a ::store_id_t containing the
|
||||||
static const Command_t REPLY_COMMAND_WAS_NOT_SENT = MAKE_COMMAND_ID(6 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates the command was not sent, getParameter contains the RMAP Return code (@see rmap.h), getParameter2() contains the ::DeviceCommandId_t
|
//! raw packet received
|
||||||
|
static const Command_t REPLY_RAW_REPLY = MAKE_COMMAND_ID(0x12);
|
||||||
static const Command_t REPLY_COMMAND_ALREADY_SENT = MAKE_COMMAND_ID(7 );//!< Reply to a @c CMD_DIRECT, the requested ::DeviceCommand_t has already been sent to the device and not ye been answered
|
|
||||||
static const Command_t REPLY_WRONG_MODE_FOR_CMD = MAKE_COMMAND_ID(8 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates that the requested command can not be sent in the curent mode, getParameter() contains the DeviceHandlerCommand_t
|
|
||||||
static const Command_t REPLY_NO_DATA = MAKE_COMMAND_ID(9 ); //!< Reply to a CMD_RAW or @c CMD_DIRECT, indicates that the ::store_id_t was invalid, getParameter() contains the ::DeviceCommandId_t, getPrameter2() contains the error code
|
|
||||||
*/
|
|
||||||
static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS; //!< Signals that a direct command was sent
|
|
||||||
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11 ); //!< Contains a raw command sent to the Device
|
|
||||||
static const Command_t REPLY_RAW_REPLY = MAKE_COMMAND_ID( 0x12); //!< Contains a raw reply from the Device, getParameter() is the ObjcetId of the sender, getParameter2() is a ::store_id_t containing the raw packet received
|
|
||||||
static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY;
|
static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY;
|
||||||
|
|
||||||
/**
|
|
||||||
* Default Destructor
|
|
||||||
*/
|
|
||||||
virtual ~DeviceHandlerMessage() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static store_address_t getStoreAddress(const CommandMessage* message);
|
static store_address_t getStoreAddress(const CommandMessage* message);
|
||||||
static uint32_t getDeviceCommandId(const CommandMessage* message);
|
static uint32_t getDeviceCommandId(const CommandMessage* message);
|
||||||
static object_id_t getDeviceObjectId(const CommandMessage *message);
|
static object_id_t getDeviceObjectId(const CommandMessage *message);
|
||||||
static object_id_t getIoBoardObjectId(const CommandMessage* message);
|
static object_id_t getIoBoardObjectId(const CommandMessage* message);
|
||||||
static uint8_t getWiretappingMode(const CommandMessage* message);
|
static uint8_t getWiretappingMode(const CommandMessage* message);
|
||||||
|
|
||||||
// static void setDeviceHandlerDirectCommandMessage(CommandMessage* message,
|
|
||||||
// DeviceCommandId_t deviceCommand,
|
|
||||||
// store_address_t commandParametersStoreId);
|
|
||||||
|
|
||||||
static void setDeviceHandlerDirectCommandReply(CommandMessage* message,
|
static void setDeviceHandlerDirectCommandReply(CommandMessage* message,
|
||||||
object_id_t deviceObjectid,
|
object_id_t deviceObjectid,
|
||||||
store_address_t commandParametersStoreId);
|
store_address_t commandParametersStoreId);
|
||||||
@ -75,11 +62,6 @@ public:
|
|||||||
object_id_t deviceObjectid, store_address_t rawPacketStoreId,
|
object_id_t deviceObjectid, store_address_t rawPacketStoreId,
|
||||||
bool isCommand);
|
bool isCommand);
|
||||||
|
|
||||||
// static void setDeviceHandlerMessage(CommandMessage* message,
|
|
||||||
// Command_t command, DeviceCommandId_t deviceCommand,
|
|
||||||
// store_address_t commandParametersStoreId);
|
|
||||||
// static void setDeviceHandlerMessage(CommandMessage* message,
|
|
||||||
// Command_t command, store_address_t rawPacketStoreId);
|
|
||||||
static void setDeviceHandlerWiretappingMessage(CommandMessage* message,
|
static void setDeviceHandlerWiretappingMessage(CommandMessage* message,
|
||||||
uint8_t wiretappingMode);
|
uint8_t wiretappingMode);
|
||||||
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
|
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
|
||||||
@ -88,4 +70,4 @@ public:
|
|||||||
static void clear(CommandMessage* message);
|
static void clear(CommandMessage* message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DEVICEHANDLERMESSAGE_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_ */
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include "../serialize/SerializeAdapter.h"
|
|
||||||
#include "DeviceTmReportingWrapper.h"
|
#include "DeviceTmReportingWrapper.h"
|
||||||
#include "../serialize/SerializeAdapter.h"
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef DEVICETMREPORTINGWRAPPER_H_
|
#ifndef FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_
|
||||||
#define DEVICETMREPORTINGWRAPPER_H_
|
#define FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_
|
||||||
|
|
||||||
#include "../action/HasActionsIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
#include "../objectmanager/SystemObjectIF.h"
|
#include "../objectmanager/SystemObjectIF.h"
|
||||||
@ -24,4 +24,4 @@ private:
|
|||||||
SerializeIF *data;
|
SerializeIF *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DEVICETMREPORTINGWRAPPER_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_ */
|
||||||
|
@ -13,10 +13,10 @@ HealthDevice::~HealthDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
|
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
|
||||||
CommandMessage message;
|
CommandMessage command;
|
||||||
ReturnValue_t result = commandQueue->receiveMessage(&message);
|
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
healthHelper.handleHealthCommand(&message);
|
healthHelper.handleHealthCommand(&command);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef HEALTHDEVICE_H_
|
#ifndef FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_
|
||||||
#define HEALTHDEVICE_H_
|
#define FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_
|
||||||
|
|
||||||
#include "../health/HasHealthIF.h"
|
#include "../health/HasHealthIF.h"
|
||||||
#include "../health/HealthHelper.h"
|
#include "../health/HealthHelper.h"
|
||||||
@ -37,4 +37,4 @@ public:
|
|||||||
HealthHelper healthHelper;
|
HealthHelper healthHelper;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HEALTHDEVICE_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_ */
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#include "Event.h"
|
|
||||||
namespace EVENT {
|
|
||||||
EventId_t getEventId(Event event) {
|
|
||||||
return (event & 0xFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
EventSeverity_t getSeverity(Event event) {
|
|
||||||
return ((event >> 16) & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
Event makeEvent(EventId_t eventId, EventSeverity_t eventSeverity) {
|
|
||||||
return (eventSeverity << 16) + (eventId & 0xFFFF);
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "fwSubsystemIdRanges.h"
|
#include "fwSubsystemIdRanges.h"
|
||||||
//could be move to more suitable location
|
// could be moved to more suitable location
|
||||||
#include <events/subsystemIdRanges.h>
|
#include <events/subsystemIdRanges.h>
|
||||||
|
|
||||||
typedef uint16_t EventId_t;
|
typedef uint16_t EventId_t;
|
||||||
@ -13,32 +13,28 @@ typedef uint8_t EventSeverity_t;
|
|||||||
|
|
||||||
typedef uint32_t Event;
|
typedef uint32_t Event;
|
||||||
|
|
||||||
namespace EVENT {
|
namespace event {
|
||||||
EventId_t getEventId(Event event);
|
|
||||||
|
|
||||||
EventSeverity_t getSeverity(Event event);
|
constexpr EventId_t getEventId(Event event) {
|
||||||
|
return (event & 0xFFFF);
|
||||||
Event makeEvent(EventId_t eventId, EventSeverity_t eventSeverity);
|
|
||||||
|
|
||||||
}
|
|
||||||
namespace SEVERITY {
|
|
||||||
static const EventSeverity_t INFO = 1;
|
|
||||||
static const EventSeverity_t LOW = 2;
|
|
||||||
static const EventSeverity_t MEDIUM = 3;
|
|
||||||
static const EventSeverity_t HIGH = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Unfortunately, this does not work nicely because of the inability to define static classes in headers.
|
constexpr EventSeverity_t getSeverity(Event event) {
|
||||||
//struct Event {
|
return ((event >> 16) & 0xFF);
|
||||||
// Event(uint8_t domain, uint8_t counter, EventSeverity_t severity) :
|
}
|
||||||
// id(domain*100+counter), severity(severity) {
|
|
||||||
// }
|
constexpr Event makeEvent(uint8_t subsystemId, uint8_t uniqueEventId,
|
||||||
// EventId_t id;
|
EventSeverity_t eventSeverity) {
|
||||||
// EventSeverity_t severity;
|
return (eventSeverity << 16) + (subsystemId * 100) + uniqueEventId;
|
||||||
// static const EventSeverity_t INFO = 1;
|
}
|
||||||
// static const EventSeverity_t LOW = 2;
|
|
||||||
// static const EventSeverity_t MEDIUM = 3;
|
}
|
||||||
// static const EventSeverity_t HIGH = 4;
|
|
||||||
//};
|
namespace severity {
|
||||||
|
static constexpr EventSeverity_t INFO = 1;
|
||||||
|
static constexpr EventSeverity_t LOW = 2;
|
||||||
|
static constexpr EventSeverity_t MEDIUM = 3;
|
||||||
|
static constexpr EventSeverity_t HIGH = 4;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* EVENTOBJECT_EVENT_H_ */
|
#endif /* EVENTOBJECT_EVENT_H_ */
|
||||||
|
@ -119,8 +119,8 @@ ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
|
|||||||
void EventManager::printEvent(EventMessage* message) {
|
void EventManager::printEvent(EventMessage* message) {
|
||||||
const char *string = 0;
|
const char *string = 0;
|
||||||
switch (message->getSeverity()) {
|
switch (message->getSeverity()) {
|
||||||
case SEVERITY::INFO:
|
case severity::INFO:
|
||||||
#if DEBUG_INFO_EVENT == 1
|
#ifdef DEBUG_INFO_EVENT
|
||||||
string = translateObject(message->getReporter());
|
string = translateObject(message->getReporter());
|
||||||
sif::info << "EVENT: ";
|
sif::info << "EVENT: ";
|
||||||
if (string != 0) {
|
if (string != 0) {
|
||||||
|
@ -48,7 +48,7 @@ void EventMessage::setMessageId(uint8_t id) {
|
|||||||
EventSeverity_t EventMessage::getSeverity() {
|
EventSeverity_t EventMessage::getSeverity() {
|
||||||
Event event;
|
Event event;
|
||||||
memcpy(&event, getData(), sizeof(Event));
|
memcpy(&event, getData(), sizeof(Event));
|
||||||
return EVENT::getSeverity(event);
|
return event::getSeverity(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventMessage::setSeverity(EventSeverity_t severity) {
|
void EventMessage::setSeverity(EventSeverity_t severity) {
|
||||||
@ -61,7 +61,7 @@ void EventMessage::setSeverity(EventSeverity_t severity) {
|
|||||||
EventId_t EventMessage::getEventId() {
|
EventId_t EventMessage::getEventId() {
|
||||||
Event event;
|
Event event;
|
||||||
memcpy(&event, getData(), sizeof(Event));
|
memcpy(&event, getData(), sizeof(Event));
|
||||||
return EVENT::getEventId(event);
|
return event::getEventId(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventMessage::setEventId(EventId_t eventId) {
|
void EventMessage::setEventId(EventId_t eventId) {
|
||||||
|
@ -139,7 +139,7 @@ void FailureIsolationBase::triggerEvent(Event event, uint32_t parameter1,
|
|||||||
uint32_t parameter2) {
|
uint32_t parameter2) {
|
||||||
//With this mechanism, all events are disabled for a certain device.
|
//With this mechanism, all events are disabled for a certain device.
|
||||||
//That's not so good for visibility.
|
//That's not so good for visibility.
|
||||||
if (isFdirDisabledForSeverity(EVENT::getSeverity(event))) {
|
if (isFdirDisabledForSeverity(event::getSeverity(event))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EventMessage message(event, ownerId, parameter1, parameter2);
|
EventMessage message(event, ownerId, parameter1, parameter2);
|
||||||
@ -148,7 +148,7 @@ void FailureIsolationBase::triggerEvent(Event event, uint32_t parameter1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FailureIsolationBase::isFdirDisabledForSeverity(EventSeverity_t severity) {
|
bool FailureIsolationBase::isFdirDisabledForSeverity(EventSeverity_t severity) {
|
||||||
if ((owner != NULL) && (severity != SEVERITY::INFO)) {
|
if ((owner != NULL) && (severity != severity::INFO)) {
|
||||||
if (owner->getHealth() == HasHealthIF::EXTERNAL_CONTROL) {
|
if (owner->getHealth() == HasHealthIF::EXTERNAL_CONTROL) {
|
||||||
//External control disables handling of fault messages.
|
//External control disables handling of fault messages.
|
||||||
return true;
|
return true;
|
||||||
|
@ -14,9 +14,9 @@ class FailureIsolationBase: public HasReturnvaluesIF,
|
|||||||
public HasParametersIF {
|
public HasParametersIF {
|
||||||
public:
|
public:
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::FDIR_1;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::FDIR_1;
|
||||||
static const Event FDIR_CHANGED_STATE = MAKE_EVENT(1, SEVERITY::INFO); //!< FDIR has an internal state, which changed from par2 (oldState) to par1 (newState).
|
static const Event FDIR_CHANGED_STATE = MAKE_EVENT(1, severity::INFO); //!< FDIR has an internal state, which changed from par2 (oldState) to par1 (newState).
|
||||||
static const Event FDIR_STARTS_RECOVERY = MAKE_EVENT(2, SEVERITY::MEDIUM); //!< FDIR tries to restart device. Par1: event that caused recovery.
|
static const Event FDIR_STARTS_RECOVERY = MAKE_EVENT(2, severity::MEDIUM); //!< FDIR tries to restart device. Par1: event that caused recovery.
|
||||||
static const Event FDIR_TURNS_OFF_DEVICE = MAKE_EVENT(3, SEVERITY::MEDIUM); //!< FDIR turns off device. Par1: event that caused recovery.
|
static const Event FDIR_TURNS_OFF_DEVICE = MAKE_EVENT(3, severity::MEDIUM); //!< FDIR turns off device. Par1: event that caused recovery.
|
||||||
|
|
||||||
FailureIsolationBase(object_id_t owner,
|
FailureIsolationBase(object_id_t owner,
|
||||||
object_id_t parent = objects::NO_OBJECT,
|
object_id_t parent = objects::NO_OBJECT,
|
||||||
|
3
fsfw.mk
3
fsfw.mk
@ -9,6 +9,9 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/controller/*.cpp)
|
|||||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/coordinates/*.cpp)
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/coordinates/*.cpp)
|
||||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datalinklayer/*.cpp)
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datalinklayer/*.cpp)
|
||||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapool/*.cpp)
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapool/*.cpp)
|
||||||
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoolglob/*.cpp)
|
||||||
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/datapoollocal/*.cpp)
|
||||||
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/housekeeping/*.cpp)
|
||||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/devicehandlers/*.cpp)
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/devicehandlers/*.cpp)
|
||||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/*.cpp)
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/*.cpp)
|
||||||
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/eventmatching/*.cpp)
|
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/events/eventmatching/*.cpp)
|
||||||
|
@ -7,16 +7,26 @@ PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PeriodicOperationDivider::checkAndIncrement() {
|
bool PeriodicOperationDivider::checkAndIncrement() {
|
||||||
if(counter >= divider) {
|
bool opNecessary = check();
|
||||||
|
if(opNecessary) {
|
||||||
if(resetAutomatically) {
|
if(resetAutomatically) {
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
return true;
|
return opNecessary;
|
||||||
}
|
}
|
||||||
counter ++;
|
counter ++;
|
||||||
|
return opNecessary;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PeriodicOperationDivider::check() {
|
||||||
|
if(counter >= divider) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PeriodicOperationDivider::resetCounter() {
|
void PeriodicOperationDivider::resetCounter() {
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
@ -21,17 +21,27 @@ public:
|
|||||||
*/
|
*/
|
||||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether operation is necessary.
|
* Check whether operation is necessary.
|
||||||
* If an operation is necessary and the class has been
|
* If an operation is necessary and the class has been
|
||||||
* configured to be reset automatically, the counter will be reset.
|
* configured to be reset automatically, the counter will be reset.
|
||||||
* If not, the counter will be incremented.
|
*
|
||||||
* @return
|
* @return
|
||||||
* -@c true if the counter is larger or equal to the divider
|
* -@c true if the counter is larger or equal to the divider
|
||||||
* -@c false otherwise
|
* -@c false otherwise
|
||||||
*/
|
*/
|
||||||
bool checkAndIncrement();
|
bool checkAndIncrement();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an operation is necessary.
|
||||||
|
* This function will not increment the counter!
|
||||||
|
* @return
|
||||||
|
* -@c true if the counter is larger or equal to the divider
|
||||||
|
* -@c false otherwise
|
||||||
|
*/
|
||||||
|
bool check();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to reset the counter to 0 manually.
|
* Can be used to reset the counter to 0 manually.
|
||||||
*/
|
*/
|
||||||
|
@ -21,13 +21,13 @@ public:
|
|||||||
static const ReturnValue_t INVALID_HEALTH_STATE = MAKE_RETURN_CODE(2);
|
static const ReturnValue_t INVALID_HEALTH_STATE = MAKE_RETURN_CODE(2);
|
||||||
|
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_MANAGER_1;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_MANAGER_1;
|
||||||
static const Event HEALTH_INFO = MAKE_EVENT(6, SEVERITY::INFO);
|
static const Event HEALTH_INFO = MAKE_EVENT(6, severity::INFO);
|
||||||
static const Event CHILD_CHANGED_HEALTH = MAKE_EVENT(7, SEVERITY::INFO);
|
static const Event CHILD_CHANGED_HEALTH = MAKE_EVENT(7, severity::INFO);
|
||||||
static const Event CHILD_PROBLEMS = MAKE_EVENT(8, SEVERITY::LOW);
|
static const Event CHILD_PROBLEMS = MAKE_EVENT(8, severity::LOW);
|
||||||
static const Event OVERWRITING_HEALTH = MAKE_EVENT(9, SEVERITY::LOW); //!< Assembly overwrites health information of children to keep satellite alive.
|
static const Event OVERWRITING_HEALTH = MAKE_EVENT(9, severity::LOW); //!< Assembly overwrites health information of children to keep satellite alive.
|
||||||
static const Event TRYING_RECOVERY = MAKE_EVENT(10, SEVERITY::MEDIUM); //!< Someone starts a recovery of a component (typically power-cycle). No parameters.
|
static const Event TRYING_RECOVERY = MAKE_EVENT(10, severity::MEDIUM); //!< Someone starts a recovery of a component (typically power-cycle). No parameters.
|
||||||
static const Event RECOVERY_STEP = MAKE_EVENT(11, SEVERITY::MEDIUM); //!< Recovery is ongoing. Comes twice during recovery. P1: 0 for the first, 1 for the second event. P2: 0
|
static const Event RECOVERY_STEP = MAKE_EVENT(11, severity::MEDIUM); //!< Recovery is ongoing. Comes twice during recovery. P1: 0 for the first, 1 for the second event. P2: 0
|
||||||
static const Event RECOVERY_DONE = MAKE_EVENT(12, SEVERITY::MEDIUM); //!< Recovery was completed. Not necessarily successful. No parameters.
|
static const Event RECOVERY_DONE = MAKE_EVENT(12, severity::MEDIUM); //!< Recovery was completed. Not necessarily successful. No parameters.
|
||||||
|
|
||||||
virtual ~HasHealthIF() {
|
virtual ~HasHealthIF() {
|
||||||
}
|
}
|
||||||
|
12
housekeeping/AcceptsHkPacketsIF.h
Normal file
12
housekeeping/AcceptsHkPacketsIF.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef FRAMEWORK_HOUSEKEEPING_ACCEPTSHKPACKETSIF_H_
|
||||||
|
#define FRAMEWORK_HOUSEKEEPING_ACCEPTSHKPACKETSIF_H_
|
||||||
|
|
||||||
|
#include "../ipc/MessageQueueMessageIF.h"
|
||||||
|
|
||||||
|
class AcceptsHkPacketsIF {
|
||||||
|
public:
|
||||||
|
virtual~ AcceptsHkPacketsIF() {};
|
||||||
|
virtual MessageQueueId_t getHkQueue() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_HOUSEKEEPING_ACCEPTSHKPACKETSIF_H_ */
|
215
housekeeping/HousekeepingMessage.cpp
Normal file
215
housekeeping/HousekeepingMessage.cpp
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
#include "HousekeepingMessage.h"
|
||||||
|
|
||||||
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
HousekeepingMessage::~HousekeepingMessage() {}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setHkReportReply(CommandMessage* message, sid_t sid,
|
||||||
|
store_address_t storeId) {
|
||||||
|
message->setCommand(HK_REPORT);
|
||||||
|
message->setMessageSize(HK_MESSAGE_SIZE);
|
||||||
|
setSid(message, sid);
|
||||||
|
message->setParameter3(storeId.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setHkDiagnosticsReply(CommandMessage* message,
|
||||||
|
sid_t sid, store_address_t storeId) {
|
||||||
|
message->setCommand(DIAGNOSTICS_REPORT);
|
||||||
|
message->setMessageSize(HK_MESSAGE_SIZE);
|
||||||
|
setSid(message, sid);
|
||||||
|
message->setParameter3(storeId.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t HousekeepingMessage::getHkDataReply(const CommandMessage *message,
|
||||||
|
store_address_t *storeIdToSet) {
|
||||||
|
if(storeIdToSet != nullptr) {
|
||||||
|
*storeIdToSet = message->getParameter3();
|
||||||
|
}
|
||||||
|
return getSid(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message,
|
||||||
|
sid_t sid, bool enableReporting, bool isDiagnostics) {
|
||||||
|
if(isDiagnostics) {
|
||||||
|
if(enableReporting) {
|
||||||
|
message->setCommand(ENABLE_PERIODIC_DIAGNOSTICS_GENERATION);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message->setCommand(DISABLE_PERIODIC_DIAGNOSTICS_GENERATION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(enableReporting) {
|
||||||
|
message->setCommand(ENABLE_PERIODIC_HK_REPORT_GENERATION);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message->setCommand(DISABLE_PERIODIC_HK_REPORT_GENERATION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSid(message, sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setStructureReportingCommand(CommandMessage *command,
|
||||||
|
sid_t sid, bool isDiagnostics) {
|
||||||
|
if(isDiagnostics) {
|
||||||
|
command->setCommand(REPORT_DIAGNOSTICS_REPORT_STRUCTURES);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command->setCommand(REPORT_HK_REPORT_STRUCTURES);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSid(command, sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setOneShotReportCommand(CommandMessage *command,
|
||||||
|
sid_t sid, bool isDiagnostics) {
|
||||||
|
if(isDiagnostics) {
|
||||||
|
command->setCommand(GENERATE_ONE_DIAGNOSTICS_REPORT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command->setCommand(GENERATE_ONE_PARAMETER_REPORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSid(command, sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setCollectionIntervalModificationCommand(
|
||||||
|
CommandMessage *command, sid_t sid, float collectionInterval,
|
||||||
|
bool isDiagnostics) {
|
||||||
|
if(isDiagnostics) {
|
||||||
|
command->setCommand(MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command->setCommand(MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL);
|
||||||
|
}
|
||||||
|
command->setParameter3(collectionInterval);
|
||||||
|
|
||||||
|
setSid(command, sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t HousekeepingMessage::getCollectionIntervalModificationCommand(
|
||||||
|
const CommandMessage* command, float* newCollectionInterval) {
|
||||||
|
if(newCollectionInterval != nullptr) {
|
||||||
|
*newCollectionInterval = command->getParameter3();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getSid(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setHkRequestSuccessReply(CommandMessage *reply,
|
||||||
|
sid_t sid) {
|
||||||
|
setSid(reply, sid);
|
||||||
|
reply->setCommand(HK_REQUEST_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setHkRequestFailureReply(CommandMessage *reply,
|
||||||
|
sid_t sid, ReturnValue_t error) {
|
||||||
|
setSid(reply, sid);
|
||||||
|
reply->setCommand(HK_REQUEST_FAILURE);
|
||||||
|
reply->setParameter3(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t HousekeepingMessage::getHkRequestFailureReply(const CommandMessage *reply,
|
||||||
|
ReturnValue_t *error) {
|
||||||
|
if(error != nullptr) {
|
||||||
|
*error = reply->getParameter3();
|
||||||
|
}
|
||||||
|
return getSid(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t HousekeepingMessage::getSid(const CommandMessage* message) {
|
||||||
|
sid_t sid;
|
||||||
|
std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw));
|
||||||
|
return sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) {
|
||||||
|
std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setHkStuctureReportReply(CommandMessage *reply,
|
||||||
|
sid_t sid, store_address_t storeId) {
|
||||||
|
reply->setCommand(HK_DEFINITIONS_REPORT);
|
||||||
|
setSid(reply, sid);
|
||||||
|
reply->setParameter3(storeId.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setDiagnosticsStuctureReportReply(
|
||||||
|
CommandMessage *reply, sid_t sid, store_address_t storeId) {
|
||||||
|
reply->setCommand(DIAGNOSTICS_DEFINITION_REPORT);
|
||||||
|
setSid(reply, sid);
|
||||||
|
reply->setParameter3(storeId.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::clear(CommandMessage* message) {
|
||||||
|
switch(message->getCommand()) {
|
||||||
|
case(HK_REPORT):
|
||||||
|
case(DIAGNOSTICS_REPORT):
|
||||||
|
case(HK_DEFINITIONS_REPORT):
|
||||||
|
case(DIAGNOSTICS_DEFINITION_REPORT):
|
||||||
|
case(UPDATE_SNAPSHOT_SET): {
|
||||||
|
store_address_t storeId;
|
||||||
|
getHkDataReply(message, &storeId);
|
||||||
|
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
|
||||||
|
objects::IPC_STORE);
|
||||||
|
if (ipcStore != nullptr) {
|
||||||
|
ipcStore->deleteData(storeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message->setCommand(CommandMessage::CMD_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setUpdateNotificationSetCommand(
|
||||||
|
CommandMessage *command, sid_t sid) {
|
||||||
|
command->setCommand(UPDATE_NOTIFICATION_SET);
|
||||||
|
setSid(command, sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setUpdateNotificationVariableCommand(
|
||||||
|
CommandMessage *command, lp_id_t localPoolId) {
|
||||||
|
command->setCommand(UPDATE_NOTIFICATION_VARIABLE);
|
||||||
|
command->setParameter(localPoolId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setUpdateSnapshotSetCommand(CommandMessage *command,
|
||||||
|
sid_t sid, store_address_t storeId) {
|
||||||
|
command->setCommand(UPDATE_SNAPSHOT_VARIABLE);
|
||||||
|
setSid(command, sid);
|
||||||
|
command->setParameter3(storeId.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HousekeepingMessage::setUpdateSnapshotVariableCommand(
|
||||||
|
CommandMessage *command, lp_id_t localPoolId, store_address_t storeId) {
|
||||||
|
command->setCommand(UPDATE_SNAPSHOT_VARIABLE);
|
||||||
|
command->setParameter(localPoolId);
|
||||||
|
command->setParameter3(storeId.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t HousekeepingMessage::getUpdateNotificationSetCommand(
|
||||||
|
const CommandMessage *command) {
|
||||||
|
return getSid(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
lp_id_t HousekeepingMessage::getUpdateNotificationVariableCommand(
|
||||||
|
const CommandMessage *command) {
|
||||||
|
return command->getParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
sid_t HousekeepingMessage::getUpdateSnapshotSetCommand(
|
||||||
|
const CommandMessage *command, store_address_t *storeId) {
|
||||||
|
if(storeId != nullptr) {
|
||||||
|
*storeId = command->getParameter3();
|
||||||
|
}
|
||||||
|
return getSid(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
lp_id_t HousekeepingMessage::getUpdateSnapshotVariableCommand(
|
||||||
|
const CommandMessage *command, store_address_t *storeId) {
|
||||||
|
if(storeId != nullptr) {
|
||||||
|
*storeId = command->getParameter3();
|
||||||
|
}
|
||||||
|
return command->getParameter();
|
||||||
|
}
|
149
housekeeping/HousekeepingMessage.h
Normal file
149
housekeeping/HousekeepingMessage.h
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGMESSAGE_H_
|
||||||
|
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGMESSAGE_H_
|
||||||
|
|
||||||
|
#include "../datapoollocal/locPoolDefinitions.h"
|
||||||
|
#include "../ipc/CommandMessage.h"
|
||||||
|
#include "../ipc/FwMessageTypes.h"
|
||||||
|
#include "../objectmanager/frameworkObjects.h"
|
||||||
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Special command message type for housekeeping messages
|
||||||
|
* @details
|
||||||
|
* This message is slightly larger than regular command messages to accomodate
|
||||||
|
* the uint64_t structure ID (SID).
|
||||||
|
*/
|
||||||
|
class HousekeepingMessage {
|
||||||
|
public:
|
||||||
|
|
||||||
|
static constexpr size_t HK_MESSAGE_SIZE = CommandMessageIF::HEADER_SIZE +
|
||||||
|
sizeof(sid_t) + sizeof(uint32_t);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Concrete instance is not used, instead this class operates on
|
||||||
|
* command message instances.
|
||||||
|
*/
|
||||||
|
HousekeepingMessage() = delete;
|
||||||
|
virtual ~HousekeepingMessage();
|
||||||
|
|
||||||
|
static constexpr uint8_t MESSAGE_ID = messagetypes::HOUSEKEEPING;
|
||||||
|
|
||||||
|
static constexpr Command_t ENABLE_PERIODIC_HK_REPORT_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 MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL =
|
||||||
|
MAKE_COMMAND_ID(31);
|
||||||
|
static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL =
|
||||||
|
MAKE_COMMAND_ID(32);
|
||||||
|
|
||||||
|
static constexpr Command_t HK_REQUEST_SUCCESS =
|
||||||
|
MAKE_COMMAND_ID(128);
|
||||||
|
static constexpr Command_t HK_REQUEST_FAILURE =
|
||||||
|
MAKE_COMMAND_ID(129);
|
||||||
|
|
||||||
|
static constexpr Command_t UPDATE_NOTIFICATION_SET =
|
||||||
|
MAKE_COMMAND_ID(130);
|
||||||
|
static constexpr Command_t UPDATE_NOTIFICATION_VARIABLE =
|
||||||
|
MAKE_COMMAND_ID(131);
|
||||||
|
|
||||||
|
static constexpr Command_t UPDATE_SNAPSHOT_SET = MAKE_COMMAND_ID(132);
|
||||||
|
static constexpr Command_t UPDATE_SNAPSHOT_VARIABLE = MAKE_COMMAND_ID(133);
|
||||||
|
|
||||||
|
//static constexpr Command_t UPDATE_HK_REPORT = MAKE_COMMAND_ID(134);
|
||||||
|
|
||||||
|
static sid_t getSid(const CommandMessage* message);
|
||||||
|
|
||||||
|
/* Housekeeping Interface Messages */
|
||||||
|
|
||||||
|
static void setToggleReportingCommand(CommandMessage* command, sid_t sid,
|
||||||
|
bool enableReporting, bool isDiagnostics);
|
||||||
|
static void setStructureReportingCommand(CommandMessage* command, sid_t sid,
|
||||||
|
bool isDiagnostics);
|
||||||
|
static void setOneShotReportCommand(CommandMessage* command, sid_t sid,
|
||||||
|
bool isDiagnostics);
|
||||||
|
static void setCollectionIntervalModificationCommand(
|
||||||
|
CommandMessage* command, sid_t sid, float collectionInterval,
|
||||||
|
bool isDiagnostics);
|
||||||
|
|
||||||
|
static void setHkReportReply(CommandMessage* reply, sid_t sid,
|
||||||
|
store_address_t storeId);
|
||||||
|
static void setHkDiagnosticsReply(CommandMessage* reply, sid_t sid,
|
||||||
|
store_address_t storeId);
|
||||||
|
|
||||||
|
static void setHkRequestSuccessReply(CommandMessage* reply, sid_t sid);
|
||||||
|
static void setHkRequestFailureReply(CommandMessage* reply, sid_t sid,
|
||||||
|
ReturnValue_t error);
|
||||||
|
|
||||||
|
static void setHkStuctureReportReply(CommandMessage* reply,
|
||||||
|
sid_t sid, store_address_t storeId);
|
||||||
|
static void setDiagnosticsStuctureReportReply(CommandMessage* reply,
|
||||||
|
sid_t sid, store_address_t storeId);
|
||||||
|
|
||||||
|
static sid_t getHkRequestFailureReply(const CommandMessage* reply,
|
||||||
|
ReturnValue_t* error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generic getter function for housekeeping data replies
|
||||||
|
* @details
|
||||||
|
* Command ID can be used beforehand to distinguish between diagnostics and
|
||||||
|
* regular HK packets. This getter function should be used for the
|
||||||
|
* command IDs 10, 12, 25 and 26.
|
||||||
|
*/
|
||||||
|
static sid_t getHkDataReply(const CommandMessage* message,
|
||||||
|
store_address_t * storeIdToSet);
|
||||||
|
static sid_t getCollectionIntervalModificationCommand(
|
||||||
|
const CommandMessage* command, float* newCollectionInterval);
|
||||||
|
|
||||||
|
|
||||||
|
/* Update Notification Messages */
|
||||||
|
|
||||||
|
static void setUpdateNotificationSetCommand(CommandMessage* command,
|
||||||
|
sid_t sid);
|
||||||
|
static void setUpdateNotificationVariableCommand(CommandMessage* command,
|
||||||
|
lp_id_t localPoolId);
|
||||||
|
|
||||||
|
static void setUpdateSnapshotSetCommand(CommandMessage* command, sid_t sid,
|
||||||
|
store_address_t storeId);
|
||||||
|
static void setUpdateSnapshotVariableCommand(CommandMessage* command,
|
||||||
|
lp_id_t localPoolId, store_address_t storeId);
|
||||||
|
|
||||||
|
static sid_t getUpdateNotificationSetCommand(const CommandMessage* command);
|
||||||
|
static lp_id_t getUpdateNotificationVariableCommand(
|
||||||
|
const CommandMessage* command);
|
||||||
|
|
||||||
|
static sid_t getUpdateSnapshotSetCommand(const CommandMessage* command,
|
||||||
|
store_address_t* storeId);
|
||||||
|
static lp_id_t getUpdateSnapshotVariableCommand(const CommandMessage* command,
|
||||||
|
store_address_t* storeId);
|
||||||
|
|
||||||
|
/** Utility */
|
||||||
|
static void clear(CommandMessage* message);
|
||||||
|
private:
|
||||||
|
static void setSid(CommandMessage* message, sid_t sid);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGMESSAGE_H_ */
|
34
housekeeping/HousekeepingPacketDownlink.h
Normal file
34
housekeeping/HousekeepingPacketDownlink.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETDOWNLINK_H_
|
||||||
|
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETDOWNLINK_H_
|
||||||
|
|
||||||
|
#include "../datapoollocal/LocalPoolDataSetBase.h"
|
||||||
|
#include "../serialize/SerialLinkedListAdapter.h"
|
||||||
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class will be used to serialize general housekeeping packets
|
||||||
|
* which are destined to be downlinked into the store.
|
||||||
|
* @details
|
||||||
|
* The housekeeping packets are stored into the IPC store and forwarded
|
||||||
|
* to the designated housekeeping handler.
|
||||||
|
*/
|
||||||
|
class HousekeepingPacketDownlink: public SerialLinkedListAdapter<SerializeIF> {
|
||||||
|
public:
|
||||||
|
HousekeepingPacketDownlink(sid_t sid, LocalPoolDataSetBase* dataSetPtr):
|
||||||
|
sourceId(sid.objectId), setId(sid.ownerSetId), hkData(dataSetPtr) {
|
||||||
|
setLinks();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setLinks() {
|
||||||
|
setStart(&sourceId);
|
||||||
|
sourceId.setNext(&setId);
|
||||||
|
setId.setNext(&hkData);
|
||||||
|
}
|
||||||
|
|
||||||
|
SerializeElement<object_id_t> sourceId;
|
||||||
|
SerializeElement<uint32_t> setId;
|
||||||
|
LinkedElement<SerializeIF> hkData;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_HOUSEKEEPING_HOUSEKEEPINGPACKETDOWNLINK_H_ */
|
92
housekeeping/HousekeepingPacketUpdate.h
Normal file
92
housekeeping/HousekeepingPacketUpdate.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_
|
||||||
|
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_
|
||||||
|
|
||||||
|
#include "../serialize/SerialBufferAdapter.h"
|
||||||
|
#include "../serialize/SerialLinkedListAdapter.h"
|
||||||
|
#include "../datapoollocal/LocalPoolDataSetBase.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This helper class will be used to serialize and deserialize
|
||||||
|
* update housekeeping packets into the store.
|
||||||
|
*/
|
||||||
|
class HousekeepingPacketUpdate: public SerializeIF {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Update packet constructor for datasets
|
||||||
|
* @param timeStamp
|
||||||
|
* @param timeStampSize
|
||||||
|
* @param hkData
|
||||||
|
* @param hkDataSize
|
||||||
|
*/
|
||||||
|
HousekeepingPacketUpdate(uint8_t* timeStamp, size_t timeStampSize,
|
||||||
|
LocalPoolDataSetBase* dataSetPtr):
|
||||||
|
timeStamp(timeStamp), timeStampSize(timeStampSize),
|
||||||
|
updateData(dataSetPtr) {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update packet constructor for pool variables.
|
||||||
|
* @param timeStamp
|
||||||
|
* @param timeStampSize
|
||||||
|
* @param dataSetPtr
|
||||||
|
*/
|
||||||
|
HousekeepingPacketUpdate(uint8_t* timeStamp, size_t timeStampSize,
|
||||||
|
LocalPoolObjectBase* dataSetPtr):
|
||||||
|
timeStamp(timeStamp), timeStampSize(timeStampSize),
|
||||||
|
updateData(dataSetPtr) {};
|
||||||
|
|
||||||
|
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||||
|
size_t maxSize, Endianness streamEndianness) const {
|
||||||
|
if(timeStamp != nullptr) {
|
||||||
|
/* Endianness will always be MACHINE, so we can simply use memcpy
|
||||||
|
here. */
|
||||||
|
std::memcpy(*buffer, timeStamp, timeStampSize);
|
||||||
|
*size += timeStampSize;
|
||||||
|
*buffer += timeStampSize;
|
||||||
|
}
|
||||||
|
if(updateData == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return updateData->serialize(buffer, size, maxSize, streamEndianness);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual size_t getSerializedSize() const {
|
||||||
|
if(updateData == nullptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return timeStampSize + updateData->getSerializedSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
SerializeIF::Endianness streamEndianness) override {
|
||||||
|
if(*size < timeStampSize) {
|
||||||
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(timeStamp != nullptr) {
|
||||||
|
/* Endianness will always be MACHINE, so we can simply use memcpy
|
||||||
|
here. */
|
||||||
|
std::memcpy(timeStamp, *buffer, timeStampSize);
|
||||||
|
*size -= timeStampSize;
|
||||||
|
*buffer += timeStampSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(updateData == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if(*size < updateData->getSerializedSize()) {
|
||||||
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return updateData->deSerialize(buffer, size, streamEndianness);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t* timeStamp = nullptr;
|
||||||
|
size_t timeStampSize = 0;
|
||||||
|
|
||||||
|
SerializeIF* updateData = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_ */
|
59
housekeeping/HousekeepingSetPacket.h
Normal file
59
housekeeping/HousekeepingSetPacket.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_
|
||||||
|
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_
|
||||||
|
|
||||||
|
#include "../housekeeping/HousekeepingMessage.h"
|
||||||
|
#include "../serialize/SerialLinkedListAdapter.h"
|
||||||
|
#include "../datapoollocal/LocalPoolDataSetBase.h"
|
||||||
|
|
||||||
|
class HousekeepingSetPacket: public SerialLinkedListAdapter<SerializeIF> {
|
||||||
|
public:
|
||||||
|
HousekeepingSetPacket(sid_t sid, bool reportingEnabled, bool valid,
|
||||||
|
float collectionInterval, LocalPoolDataSetBase* dataSetPtr):
|
||||||
|
objectId(sid.objectId), setId(sid.ownerSetId),
|
||||||
|
reportingEnabled(reportingEnabled), valid(valid),
|
||||||
|
collectionIntervalSeconds(collectionInterval), dataSet(dataSetPtr) {
|
||||||
|
setLinks();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
|
size_t maxSize, Endianness streamEndianness) const override {
|
||||||
|
ReturnValue_t result = SerialLinkedListAdapter::serialize(buffer, size,
|
||||||
|
maxSize, streamEndianness);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return dataSet->serializeLocalPoolIds(buffer, size ,maxSize,
|
||||||
|
streamEndianness);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getSerializedSize() const override {
|
||||||
|
size_t linkedSize = SerialLinkedListAdapter::getSerializedSize();
|
||||||
|
linkedSize += dataSet->getLocalPoolIdsSerializedSize();
|
||||||
|
return linkedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
Endianness streamEndianness) override {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void setLinks() {
|
||||||
|
setStart(&objectId);
|
||||||
|
objectId.setNext(&setId);
|
||||||
|
setId.setNext(&reportingEnabled);
|
||||||
|
reportingEnabled.setNext(&valid);
|
||||||
|
valid.setNext(&collectionIntervalSeconds);
|
||||||
|
collectionIntervalSeconds.setEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
SerializeElement<object_id_t> objectId;
|
||||||
|
SerializeElement<uint32_t> setId;
|
||||||
|
SerializeElement<bool> reportingEnabled;
|
||||||
|
SerializeElement<bool> valid;
|
||||||
|
SerializeElement<float> collectionIntervalSeconds;
|
||||||
|
LocalPoolDataSetBase* dataSet;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_ */
|
49
housekeeping/PeriodicHousekeepingHelper.cpp
Normal file
49
housekeeping/PeriodicHousekeepingHelper.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "PeriodicHousekeepingHelper.h"
|
||||||
|
|
||||||
|
#include "../datapoollocal/LocalPoolDataSetBase.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(
|
||||||
|
LocalPoolDataSetBase* owner): owner(owner) {}
|
||||||
|
|
||||||
|
|
||||||
|
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
|
||||||
|
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
|
||||||
|
uint8_t nonDiagIntervalFactor) {
|
||||||
|
this->minimumPeriodicInterval = minimumPeriodicInterval;
|
||||||
|
if(not isDiagnostics) {
|
||||||
|
this->minimumPeriodicInterval = this->minimumPeriodicInterval *
|
||||||
|
nonDiagIntervalFactor;
|
||||||
|
}
|
||||||
|
collectionIntervalTicks = intervalSecondsToInterval(collectionInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() {
|
||||||
|
return intervalToIntervalSeconds(collectionIntervalTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PeriodicHousekeepingHelper::checkOpNecessary() {
|
||||||
|
if(internalTickCounter >= collectionIntervalTicks) {
|
||||||
|
internalTickCounter = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
internalTickCounter++;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t PeriodicHousekeepingHelper::intervalSecondsToInterval(
|
||||||
|
float collectionIntervalSeconds) {
|
||||||
|
return std::ceil(collectionIntervalSeconds * 1000
|
||||||
|
/ minimumPeriodicInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
float PeriodicHousekeepingHelper::intervalToIntervalSeconds(
|
||||||
|
uint32_t collectionInterval) {
|
||||||
|
return static_cast<float>(collectionInterval *
|
||||||
|
minimumPeriodicInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PeriodicHousekeepingHelper::changeCollectionInterval(
|
||||||
|
float newIntervalSeconds) {
|
||||||
|
collectionIntervalTicks = intervalSecondsToInterval(newIntervalSeconds);
|
||||||
|
}
|
32
housekeeping/PeriodicHousekeepingHelper.h
Normal file
32
housekeeping/PeriodicHousekeepingHelper.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
|
||||||
|
#define FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
|
||||||
|
|
||||||
|
#include "../timemanager/Clock.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
class LocalPoolDataSetBase;
|
||||||
|
|
||||||
|
class PeriodicHousekeepingHelper {
|
||||||
|
public:
|
||||||
|
PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner);
|
||||||
|
|
||||||
|
void initialize(float collectionInterval,
|
||||||
|
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
|
||||||
|
uint8_t nonDiagIntervalFactor);
|
||||||
|
|
||||||
|
void changeCollectionInterval(float newInterval);
|
||||||
|
float getCollectionIntervalInSeconds();
|
||||||
|
bool checkOpNecessary();
|
||||||
|
private:
|
||||||
|
LocalPoolDataSetBase* owner = nullptr;
|
||||||
|
|
||||||
|
uint32_t intervalSecondsToInterval(float collectionIntervalSeconds);
|
||||||
|
float intervalToIntervalSeconds(uint32_t collectionInterval);
|
||||||
|
|
||||||
|
dur_millis_t minimumPeriodicInterval = 0;
|
||||||
|
uint32_t internalTickCounter = 1;
|
||||||
|
uint32_t collectionIntervalTicks = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ */
|
@ -1,17 +1,16 @@
|
|||||||
|
#include "../datapoolglob/GlobalDataSet.h"
|
||||||
#include "InternalErrorReporter.h"
|
#include "InternalErrorReporter.h"
|
||||||
|
|
||||||
#include "../datapool/DataSet.h"
|
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||||
#include "../datapool/PoolVariable.h"
|
|
||||||
#include "../ipc/MutexFactory.h"
|
#include "../ipc/MutexFactory.h"
|
||||||
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId,
|
InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId,
|
||||||
uint32_t queuePoolId, uint32_t tmPoolId, uint32_t storePoolId) :
|
uint32_t queuePoolId, uint32_t tmPoolId, uint32_t storePoolId) :
|
||||||
SystemObject(setObjectId), mutex(NULL), queuePoolId(queuePoolId), tmPoolId(
|
SystemObject(setObjectId), mutex(NULL), queuePoolId(queuePoolId),
|
||||||
tmPoolId), storePoolId(
|
tmPoolId(tmPoolId),storePoolId(storePoolId), queueHits(0), tmHits(0),
|
||||||
storePoolId), queueHits(0), tmHits(0), storeHits(
|
storeHits(0) {
|
||||||
0) {
|
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,13 +20,13 @@ InternalErrorReporter::~InternalErrorReporter() {
|
|||||||
|
|
||||||
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
|
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
|
||||||
|
|
||||||
DataSet mySet;
|
GlobDataSet mySet;
|
||||||
PoolVariable<uint32_t> queueHitsInPool(queuePoolId, &mySet,
|
gp_uint32_t queueHitsInPool(queuePoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
PoolVariable<uint32_t> tmHitsInPool(tmPoolId, &mySet,
|
gp_uint32_t tmHitsInPool(tmPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
|
|
||||||
PoolVariable<uint32_t> storeHitsInPool(storePoolId, &mySet,
|
gp_uint32_t storeHitsInPool(storePoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
namespace messagetypes {
|
namespace messagetypes {
|
||||||
//Remember to add new Message Types to the clearCommandMessage function!
|
//Remember to add new Message Types to the clearCommandMessage function!
|
||||||
enum FW_MESSAGE_TYPE {
|
enum FsfwMessageTypes {
|
||||||
COMMAND = 0,
|
COMMAND = 0,
|
||||||
MODE_COMMAND,
|
MODE_COMMAND,
|
||||||
HEALTH_COMMAND,
|
HEALTH_COMMAND,
|
||||||
@ -14,7 +14,10 @@ enum FW_MESSAGE_TYPE {
|
|||||||
MONITORING,
|
MONITORING,
|
||||||
MEMORY,
|
MEMORY,
|
||||||
PARAMETER,
|
PARAMETER,
|
||||||
FW_MESSAGES_COUNT
|
FILE_SYSTEM_MESSAGE,
|
||||||
|
HOUSEKEEPING,
|
||||||
|
|
||||||
|
FW_MESSAGES_COUNT,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,14 @@ public:
|
|||||||
static const ReturnValue_t INVALID_SUBMODE = MAKE_RETURN_CODE(0x04);
|
static const ReturnValue_t INVALID_SUBMODE = MAKE_RETURN_CODE(0x04);
|
||||||
|
|
||||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_MANAGER;
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_MANAGER;
|
||||||
static const Event CHANGING_MODE = MAKE_EVENT(0, SEVERITY::INFO); //!< An object announces changing the mode. p1: target mode. p2: target submode
|
static const Event CHANGING_MODE = MAKE_EVENT(0, severity::INFO); //!< An object announces changing the mode. p1: target mode. p2: target submode
|
||||||
static const Event MODE_INFO = MAKE_EVENT(1, SEVERITY::INFO); //!< An Object announces its mode; parameter1 is mode, parameter2 is submode
|
static const Event MODE_INFO = MAKE_EVENT(1, severity::INFO); //!< An Object announces its mode; parameter1 is mode, parameter2 is submode
|
||||||
static const Event FALLBACK_FAILED = MAKE_EVENT(2, SEVERITY::HIGH);
|
static const Event FALLBACK_FAILED = MAKE_EVENT(2, severity::HIGH);
|
||||||
static const Event MODE_TRANSITION_FAILED = MAKE_EVENT(3, SEVERITY::LOW);
|
static const Event MODE_TRANSITION_FAILED = MAKE_EVENT(3, severity::LOW);
|
||||||
static const Event CANT_KEEP_MODE = MAKE_EVENT(4, SEVERITY::HIGH);
|
static const Event CANT_KEEP_MODE = MAKE_EVENT(4, severity::HIGH);
|
||||||
static const Event OBJECT_IN_INVALID_MODE = MAKE_EVENT(5, SEVERITY::LOW); //!< Indicates a bug or configuration failure: Object is in a mode it should never be in.
|
static const Event OBJECT_IN_INVALID_MODE = MAKE_EVENT(5, severity::LOW); //!< Indicates a bug or configuration failure: Object is in a mode it should never be in.
|
||||||
static const Event FORCING_MODE = MAKE_EVENT(6, SEVERITY::MEDIUM); //!< The mode is changed, but for some reason, the change is forced, i.e. EXTERNAL_CONTROL ignored. p1: target mode. p2: target submode
|
static const Event FORCING_MODE = MAKE_EVENT(6, severity::MEDIUM); //!< The mode is changed, but for some reason, the change is forced, i.e. EXTERNAL_CONTROL ignored. p1: target mode. p2: target submode
|
||||||
static const Event MODE_CMD_REJECTED = MAKE_EVENT(7, SEVERITY::LOW); //!< A mode command was rejected by the called object. Par1: called object id, Par2: return code.
|
static const Event MODE_CMD_REJECTED = MAKE_EVENT(7, severity::LOW); //!< A mode command was rejected by the called object. Par1: called object id, Par2: return code.
|
||||||
|
|
||||||
static const Mode_t MODE_ON = 1; //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted
|
static const Mode_t MODE_ON = 1; //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted
|
||||||
static const Mode_t MODE_OFF = 0; //!< The device is powered off. The only command accepted in this mode is a mode change to on.
|
static const Mode_t MODE_OFF = 0; //!< The device is powered off. The only command accepted in this mode is a mode change to on.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_
|
#ifndef FSFW_MONITORING_ABSLIMITMONITOR_H_
|
||||||
#define FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_
|
#define FSFW_MONITORING_ABSLIMITMONITOR_H_
|
||||||
|
|
||||||
#include "MonitorBase.h"
|
#include "MonitorBase.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -7,9 +7,14 @@
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class AbsLimitMonitor: public MonitorBase<T> {
|
class AbsLimitMonitor: public MonitorBase<T> {
|
||||||
public:
|
public:
|
||||||
AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId, uint32_t parameterId,
|
AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId,
|
||||||
uint16_t confirmationLimit, T limit, Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE, bool aboveIsViolation = true) :
|
gp_id_t globalPoolId, uint16_t confirmationLimit, T limit,
|
||||||
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit), limit(limit), violationEvent(violationEvent), aboveIsViolation(aboveIsViolation) {
|
Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE,
|
||||||
|
bool aboveIsViolation = true) :
|
||||||
|
MonitorBase<T>(reporterId, monitorId, globalPoolId,
|
||||||
|
confirmationLimit),
|
||||||
|
limit(limit), violationEvent(violationEvent),
|
||||||
|
aboveIsViolation(aboveIsViolation) {
|
||||||
}
|
}
|
||||||
virtual ~AbsLimitMonitor() {
|
virtual ~AbsLimitMonitor() {
|
||||||
}
|
}
|
||||||
@ -32,8 +37,9 @@ public:
|
|||||||
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
||||||
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
|
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
|
||||||
parameterId, parameterWrapper, newValues, startAtIndex);
|
parameterId, parameterWrapper, newValues, startAtIndex);
|
||||||
//We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there.
|
// We'll reuse the DOMAIN_ID of MonitorReporter,
|
||||||
if (result != this->INVALID_MATRIX_ID) {
|
// as we know the parameterIds used there.
|
||||||
|
if (result != this->INVALID_IDENTIFIER_ID) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
switch (parameterId) {
|
switch (parameterId) {
|
||||||
@ -41,7 +47,7 @@ public:
|
|||||||
parameterWrapper->set(this->limit);
|
parameterWrapper->set(this->limit);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return this->INVALID_MATRIX_ID;
|
return this->INVALID_IDENTIFIER_ID;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -59,7 +65,9 @@ protected:
|
|||||||
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case MonitoringIF::OUT_OF_RANGE:
|
case MonitoringIF::OUT_OF_RANGE:
|
||||||
EventManagerIF::triggerEvent(this->reportingId, violationEvent, this->parameterId);
|
EventManagerIF::triggerEvent(this->reportingId,
|
||||||
|
violationEvent, this->globalPoolId.objectId,
|
||||||
|
this->globalPoolId.localPoolId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -70,4 +78,4 @@ protected:
|
|||||||
const bool aboveIsViolation;
|
const bool aboveIsViolation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_ */
|
#endif /* FSFW_MONITORING_ABSLIMITMONITOR_H_ */
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user