WIP: somethings wrong.. #19

Closed
muellerr wants to merge 808 commits from source/master into master
5 changed files with 119 additions and 54 deletions
Showing only changes of commit 9ec2283d13 - Show all commits

View File

@ -2,9 +2,11 @@
#define FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_ #define FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_
#include <framework/datapool/PoolEntryIF.h> #include <framework/datapool/PoolEntryIF.h>
#include <framework/ipc/MessageQueueSenderIF.h> #include <framework/ipc/MessageQueueSenderIF.h>
#include <framework/housekeeping/HousekeepingMessage.h>
#include <map> #include <map>
class HousekeepingManager; class HousekeepingManager;
class DataSetIF;
/** /**
* @brief Type definition for local pool entries. * @brief Type definition for local pool entries.
*/ */
@ -13,17 +15,34 @@ using LocalDataPoolMap = std::map<lp_id_t, PoolEntryIF*>;
using LocalDataPoolMapIter = LocalDataPoolMap::iterator; using LocalDataPoolMapIter = LocalDataPoolMap::iterator;
/** /**
* @brief * @brief This interface is implemented by classes which posses a local
* data pool (not the managing class)
* @details
* Any class implementing this interface shall also have a HousekeepingManager
* member class which handles the retrieval of the local pool data.
* This is required because the pool entries are templates, which makes
* specifying an interface rather difficult.
*
* This could be circumvented by using a wrapper/accessor function, 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 housekeeping manager.
*/ */
class HasHkPoolParametersIF { class HasHkPoolParametersIF {
public: public:
virtual~ HasHkPoolParametersIF() {}; virtual~ HasHkPoolParametersIF() {};
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING;
static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0XA0);
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0xA1);
virtual MessageQueueId_t getCommandQueue() const = 0; virtual MessageQueueId_t getCommandQueue() const = 0;
virtual ReturnValue_t initializeHousekeepingPoolEntries( virtual ReturnValue_t initializeHousekeepingPoolEntries(
LocalDataPoolMap& localDataPoolMap) = 0; LocalDataPoolMap& localDataPoolMap) = 0;
virtual float setMinimalHkSamplingFrequency() = 0; //virtual float setMinimalHkSamplingFrequency() = 0;
virtual HousekeepingManager* getHkManagerHandle() = 0; virtual HousekeepingManager* getHkManagerHandle() = 0;
virtual DataSetIF* getDataSetHandle(sid_t sid) = 0;
}; };
#endif /* FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_ */ #endif /* FRAMEWORK_DATAPOOL_HASHKPOOLPARAMETERSIF_H_ */

View File

@ -1,17 +1,19 @@
#include <framework/datapoollocal/LocalDataSet.h>
#include <framework/housekeeping/HousekeepingManager.h> #include <framework/housekeeping/HousekeepingManager.h>
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/ipc/MutexFactory.h> #include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h> #include <framework/ipc/MutexHelper.h>
#include <array>
HousekeepingManager::HousekeepingManager(HasHkPoolParametersIF* owner) { HousekeepingManager::HousekeepingManager(HasHkPoolParametersIF* owner) {
//todo :: nullptr check owner.
if(owner == nullptr) { if(owner == nullptr) {
sif::error << "HkManager: Invalid supplied owner!" << std::endl; sif::error << "HkManager: Invalid supplied owner!" << std::endl;
std::exit(0); std::exit(0);
} }
this->owner = owner; this->owner = owner;
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
owner->setMinimalHkSamplingFrequency(); //owner->setMinimalHkSamplingFrequency();
} }
HousekeepingManager::~HousekeepingManager() {} HousekeepingManager::~HousekeepingManager() {}
@ -24,7 +26,7 @@ ReturnValue_t HousekeepingManager::initializeHousekeepingPoolEntriesOnce() {
} }
return result; return result;
} }
sif::warning << "hk manager says no" << std::endl; sif::warning << "HousekeepingManager: The map" << std::endl;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -33,18 +35,48 @@ ReturnValue_t HousekeepingManager::handleHousekeepingMessage(
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t HousekeepingManager::printPoolEntry(
lp_id_t localPoolId) {
auto poolIter = localDpMap.find(localPoolId);
if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl;
return HasHkPoolParametersIF::POOL_ENTRY_NOT_FOUND;
}
poolIter->second->print();
return HasReturnvaluesIF::RETURN_OK;
}
MutexIF* HousekeepingManager::getMutexHandle() { MutexIF* HousekeepingManager::getMutexHandle() {
return mutex; return mutex;
} }
void HousekeepingManager::setMinimalSamplingFrequency(float frequencySeconds) { //void HousekeepingManager::setMinimalSamplingFrequency(float frequencySeconds) {
this->samplingFrequency = frequencySeconds; // this->samplingFrequency = frequencySeconds;
//
//}
} void HousekeepingManager::generateHousekeepingPacket(sid_t sid) {
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
owner->getDataSetHandle(sid));
if(dataSetToSerialize == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl;
return;
}
std::array<uint8_t, 256> testBuffer = {};
uint8_t* dataPtr = testBuffer.data();
size_t size = 0;
dataSetToSerialize->serialize(&dataPtr, &size, testBuffer.size(),
false);
// and now we send it to the TM funnel or somewhere else
void HousekeepingManager::generateHousekeepingPacket(DataSetIF *dataSet) {
} }
void HousekeepingManager::setHkPacketQueue(MessageQueueIF *msgQueue) { void HousekeepingManager::setHkPacketQueue(MessageQueueIF *msgQueue) {
this->hkPacketQueue = msgQueue; this->hkPacketQueue = msgQueue;
} }
const HasHkPoolParametersIF* HousekeepingManager::getOwner() const {
return owner;
}

View File

@ -5,6 +5,7 @@
#include <framework/housekeeping/HasHkPoolParametersIF.h> #include <framework/housekeeping/HasHkPoolParametersIF.h>
#include <framework/ipc/MutexIF.h> #include <framework/ipc/MutexIF.h>
#include <framework/housekeeping/HousekeepingMessage.h>
#include <framework/datapool/PoolEntry.h> #include <framework/datapool/PoolEntry.h>
#include <framework/ipc/CommandMessage.h> #include <framework/ipc/CommandMessage.h>
#include <framework/ipc/MessageQueueIF.h> #include <framework/ipc/MessageQueueIF.h>
@ -14,47 +15,36 @@
class HousekeepingManager { class HousekeepingManager {
template<typename T>
friend class LocalPoolVar;
template<typename T, uint16_t vecSize>
friend class LocalPoolVector;
friend class LocalDataSet;
public: public:
static constexpr float MINIMAL_SAMPLING_FREQUENCY = 0.2; static constexpr float MINIMAL_SAMPLING_FREQUENCY = 0.2;
HousekeepingManager(HasHkPoolParametersIF* owner); HousekeepingManager(HasHkPoolParametersIF* owner);
virtual~ HousekeepingManager(); virtual~ HousekeepingManager();
MutexIF* getMutexHandle();
// propably will just call respective local data set functions. // propably will just call respective local data set functions.
void generateHousekeepingPacket(DataSetIF* dataSet); void generateHousekeepingPacket(sid_t sid);
ReturnValue_t handleHousekeepingMessage(CommandMessage* message); ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
/**
* Read a variable by supplying its local pool ID and assign the pool
* entry to the supplied PoolEntry pointer. The type of the pool entry
* is deduced automatically. This call is not thread-safe!
* @tparam T Type of the pool entry
* @param localPoolId Pool ID of the variable to read
* @param poolVar [out] Corresponding pool entry will be assigned to the
* supplied pointer.
* @return
*/
template <class T>
ReturnValue_t fetchPoolEntry(lp_id_t localPoolId, PoolEntry<T> *poolEntry);
void setMinimalSamplingFrequency(float frequencySeconds);
/** /**
* This function is used to fill the local data pool map with pool * This function is used to fill the local data pool map with pool
* entries. The default implementation is empty. * entries. It should only be called once by the pool owner.
* @param localDataPoolMap * @param localDataPoolMap
* @return * @return
*/ */
ReturnValue_t initializeHousekeepingPoolEntriesOnce(); ReturnValue_t initializeHousekeepingPoolEntriesOnce();
void setHkPacketQueue(MessageQueueIF* msgQueue); void setHkPacketQueue(MessageQueueIF* msgQueue);
private: const HasHkPoolParametersIF* getOwner() const;
//! this depends on the PST frequency.. maybe it would be better to just
//! set this manually with a global configuration value which is also
//! passed to the PST. Or force setting this in device handler.
float samplingFrequency = MINIMAL_SAMPLING_FREQUENCY;
ReturnValue_t printPoolEntry(lp_id_t localPoolId);
private:
//! This is the map holding the actual data. Should only be initialized //! This is the map holding the actual data. Should only be initialized
//! once ! //! once !
bool mapInitialized = false; bool mapInitialized = false;
@ -72,24 +62,53 @@ private:
//! message..) //! message..)
MessageQueueIF* hkReplyQueue = nullptr; MessageQueueIF* hkReplyQueue = nullptr;
//! Used for HK packets, which are generated without requests. //! Used for HK packets, which are generated without requests.
//! Maybe this will just be the TM funnel.
MessageQueueIF* hkPacketQueue = nullptr; MessageQueueIF* hkPacketQueue = nullptr;
/**
* Get the pointer to the mutex. Can be used to lock the data pool
* eternally. 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);
void setMinimalSamplingFrequency(float frequencySeconds);
}; };
template<class T> inline template<class T> inline
ReturnValue_t HousekeepingManager::fetchPoolEntry(lp_id_t localPoolId, ReturnValue_t HousekeepingManager::fetchPoolEntry(lp_id_t localPoolId,
PoolEntry<T> *poolEntry) { PoolEntry<T> **poolEntry) {
auto poolIter = localDpMap.find(localPoolId); auto poolIter = localDpMap.find(localPoolId);
if (poolIter == localDpMap.end()) { if (poolIter == localDpMap.end()) {
// todo: special returnvalue. sif::debug << "HousekeepingManager::fechPoolEntry:"
return HasReturnvaluesIF::RETURN_FAILED; " Pool entry not found." << std::endl;
return HasHkPoolParametersIF::POOL_ENTRY_NOT_FOUND;
} }
poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second); *poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
if(poolEntry == nullptr) { if(*poolEntry == nullptr) {
// todo: special returnvalue. sif::debug << "HousekeepingManager::fetchPoolEntry:"
return HasReturnvaluesIF::RETURN_FAILED; " Pool entry not found." << std::endl;
return HasHkPoolParametersIF::POOL_ENTRY_TYPE_CONFLICT;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
#endif /* FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ */ #endif /* FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ */

View File

@ -1,10 +1,10 @@
#include <framework/housekeeping/HousekeepingMessage.h> #include <framework/housekeeping/HousekeepingMessage.h>
void HousekeepingMessage::setAddHkReportStructMessage(CommandMessage *message, //void HousekeepingMessage::setAddHkReportStructMessage(CommandMessage *message,
set_t setId, store_address_t packet) { // set_t setId, store_address_t packet) {
message->setCommand(ADD_HK_REPORT_STRUCT); // message->setCommand(ADD_HK_REPORT_STRUCT);
message->setParameter(setId); // message->setParameter(setId);
message->setParameter2(packet.raw); // message->setParameter2(packet.raw);
} //}
//void Housekeeping //void Housekeeping

View File

@ -4,20 +4,15 @@
#include <framework/storagemanager/StorageManagerIF.h> #include <framework/storagemanager/StorageManagerIF.h>
#include <limits> #include <limits>
/**
* the sid consists of the target object ID and... something else I forgot.
* Propably a special HK id to distinguish multiple hk pool packages
* inside a handler or controller
*/
typedef uint32_t set_t;
union sid_t { union sid_t {
static constexpr uint64_t INVALID_ADDRESS = std::numeric_limits<uint64_t>::max(); static constexpr uint64_t INVALID_ADDRESS = std::numeric_limits<uint64_t>::max();
sid_t(): raw(INVALID_ADDRESS) {} sid_t(): raw(INVALID_ADDRESS) {}
struct { struct {
object_id_t objectId ; object_id_t objectId ;
set_t hkId; // 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. * Alternative access to the raw value.
@ -79,8 +74,8 @@ public:
static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL = static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL =
MAKE_COMMAND_ID(32); MAKE_COMMAND_ID(32);
static void setAddHkReportStructMessage(CommandMessage* message, // static void setAddHkReportStructMessage(CommandMessage* message,
set_t setId, store_address_t packet); // DevisetId, store_address_t packet);
}; };