hk continued

This commit is contained in:
Robin Müller 2020-06-19 03:03:17 +02:00
parent 583efec3f8
commit 84b8d733c0
8 changed files with 186 additions and 56 deletions

View File

@ -102,7 +102,7 @@ public:
virtual ReturnValue_t unlockDataPool() override; virtual ReturnValue_t unlockDataPool() override;
/* SerializeIF implementations */ /* SerializeIF implementations */
ReturnValue_t serialize(uint8_t** buffer, size_t* size, virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
const size_t maxSize, bool bigEndian) const override; const size_t maxSize, bool bigEndian) const override;
virtual size_t getSerializedSize() const override; virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,

View File

@ -1,16 +1,17 @@
#include <framework/datapoollocal/LocalDataPoolManager.h> #include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/LocalDataSet.h> #include <framework/datapoollocal/LocalDataSet.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/objectmanager/frameworkObjects.h>
#include <framework/ipc/MutexFactory.h> #include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h> #include <framework/ipc/MutexHelper.h>
#include <framework/ipc/QueueFactory.h>
#include <array> #include <array>
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner) { LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner,
uint32_t replyQueueDepth, bool appendValidityBuffer):
appendValidityBuffer(appendValidityBuffer) {
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); return;
} }
this->owner = owner; this->owner = owner;
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
@ -23,6 +24,8 @@ LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: " sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
"Could not set IPC store." << std::endl; "Could not set IPC store." << std::endl;
} }
hkQueue = QueueFactory::instance()->createMessageQueue(replyQueueDepth,
HousekeepingMessage::HK_MESSAGE_SIZE);
} }
LocalDataPoolManager::~LocalDataPoolManager() {} LocalDataPoolManager::~LocalDataPoolManager() {}
@ -36,13 +39,21 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
} }
return result; return result;
} }
sif::warning << "HousekeepingManager: The map" << std::endl; sif::warning << "HousekeepingManager: The map should only be initialized "
"once!" << std::endl;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
HousekeepingMessage& message) { HousekeepingMessage& message) {
return HasReturnvaluesIF::RETURN_FAILED; Command_t command = message.getCommand();
switch(command) {
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT):
return generateHousekeepingPacket(message.getSid());
default:
return CommandMessageIF::UNKNOWN_COMMAND;
}
} }
ReturnValue_t LocalDataPoolManager::printPoolEntry( ReturnValue_t LocalDataPoolManager::printPoolEntry(
@ -51,7 +62,7 @@ ReturnValue_t LocalDataPoolManager::printPoolEntry(
if (poolIter == localDpMap.end()) { if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:" sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl; " Pool entry not found." << std::endl;
return OwnsLocalDataPoolIF::POOL_ENTRY_NOT_FOUND; return POOL_ENTRY_NOT_FOUND;
} }
poolIter->second->print(); poolIter->second->print();
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
@ -61,6 +72,15 @@ MutexIF* LocalDataPoolManager::getMutexHandle() {
return mutex; return mutex;
} }
void LocalDataPoolManager::setHkPacketDestination(
MessageQueueId_t destinationQueueId) {
this->currentHkPacketDestination = destinationQueueId;
}
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) { ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>( LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
owner->getDataSetHandle(sid)); owner->getDataSetHandle(sid));
@ -70,28 +90,56 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
store_address_t storeId; store_address_t storeId;
size_t hkSize = dataSetToSerialize->getSerializedSize(); ReturnValue_t result = serializeHkPacketIntoStore(&storeId,
uint8_t* storePtr = nullptr; dataSetToSerialize);
ReturnValue_t result = ipcStore->getFreeElement(&storeId, hkSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket: "
"Could not get free element from IPC store." << std::endl;
return result; return result;
} }
size_t size = 0;
dataSetToSerialize->serialize(&storePtr, &size, hkSize, false); // and now we set a HK message and send it the HK packet destination.
// and now we have to set a HK message and send it the queue. MessageQueueMessage message;
return HasReturnvaluesIF::RETURN_OK; HousekeepingMessage hkMessage(&message);
hkMessage.setHkReportMessage(sid, storeId);
if(hkQueue == nullptr) {
return QUEUE_NOT_SET;
}
if(currentHkPacketDestination != MessageQueueIF::NO_QUEUE) {
result = hkQueue->sendMessage(currentHkPacketDestination, &hkMessage);
}
else {
result = hkQueue->sendToDefault(&hkMessage);
}
return result;
} }
void LocalDataPoolManager::setHkPacketQueue(MessageQueueIF *msgQueue) { ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
this->hkPacketQueue = msgQueue; store_address_t *storeId, LocalDataSet* dataSet) {
size_t hkSize = dataSet->getSerializedSize();
uint8_t* storePtr = nullptr;
ReturnValue_t result = ipcStore->getFreeElement(storeId, hkSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket: "
"Could not get free element from IPC store." << std::endl;
return result;
}
size_t size = 0;
if(appendValidityBuffer) {
result = dataSet->serializeWithValidityBuffer(&storePtr,
&size, hkSize, false);
}
else {
result = dataSet->serialize(&storePtr, &size, hkSize, false);
}
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "HousekeepingManager::serializeHkPacketIntoStore: "
"Serialization proccess failed!" << std::endl;
}
return result;
} }
void LocalDataPoolManager::setHkReplyQueue(MessageQueueIF *replyQueue) {
this->hkReplyQueue = replyQueue;
}
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}

View File

@ -13,6 +13,8 @@
#include <map> #include <map>
class LocalDataSet;
/** /**
* @brief This class is the managing instance for local data pool. * @brief This class is the managing instance for local data pool.
* @details * @details
@ -37,8 +39,16 @@ class LocalDataPoolManager {
friend class LocalPoolVector; friend class LocalPoolVector;
friend class LocalDataSet; friend class LocalDataSet;
public: public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER;
LocalDataPoolManager(OwnsLocalDataPoolIF* owner); static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x0);
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x1);
static constexpr ReturnValue_t QUEUE_NOT_SET = MAKE_RETURN_CODE(0x2);
//static constexpr ReturnValue_t SET_NOT_FOUND = MAKE_RETURN_CODE(0x3);
LocalDataPoolManager(OwnsLocalDataPoolIF* owner,
uint32_t replyQueueDepth = 20, bool appendValidityBuffer = true);
virtual~ LocalDataPoolManager(); virtual~ LocalDataPoolManager();
/* Copying forbidden */ /* Copying forbidden */
@ -57,10 +67,7 @@ public:
ReturnValue_t initializeHousekeepingPoolEntriesOnce(); ReturnValue_t initializeHousekeepingPoolEntriesOnce();
//! Set the queue for HK packets, which are sent unrequested. //! Set the queue for HK packets, which are sent unrequested.
void setHkPacketQueue(MessageQueueIF* msgQueue); void setHkPacketDestination(MessageQueueId_t destinationQueueId);
//! Set the queue for replies. This can be set manually or by the owner
//! class if the manager if message are relayed by it.
void setHkReplyQueue(MessageQueueIF* replyQueue);
const OwnsLocalDataPoolIF* getOwner() const; const OwnsLocalDataPoolIF* getOwner() const;
@ -70,6 +77,10 @@ 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;
//! This specifies whether a validity buffer is appended at the end
//! of generated housekeeping packets.
bool appendValidityBuffer = true;
LocalDataPool localDpMap; LocalDataPool localDpMap;
//! Every housekeeping data manager has a mutex to protect access //! Every housekeeping data manager has a mutex to protect access
@ -79,13 +90,14 @@ private:
//! The class which actually owns the manager (and its datapool). //! The class which actually owns the manager (and its datapool).
OwnsLocalDataPoolIF* owner = nullptr; OwnsLocalDataPoolIF* owner = nullptr;
//! Used for replies. //! Queue used for communication, for example commands.
//! (maybe we dont need this, the sender can be retrieved from command //! Is also used to send messages.
//! message..) MessageQueueIF* hkQueue = nullptr;
MessageQueueIF* hkReplyQueue = nullptr;
//! Used for HK packets, which are generated without requests. //! HK replies will always be a reply to the commander, but HK packet
//! Maybe this will just be the TM funnel. //! can be sent to another destination by specifying this message queue
MessageQueueIF* hkPacketQueue = nullptr; //! ID, for example to a dedicated housekeeping service implementation.
MessageQueueId_t currentHkPacketDestination = MessageQueueIF::NO_QUEUE;
//! Global IPC store is used to store all packets. //! Global IPC store is used to store all packets.
StorageManagerIF* ipcStore = nullptr; StorageManagerIF* ipcStore = nullptr;
@ -113,6 +125,8 @@ private:
PoolEntry<T> **poolEntry); PoolEntry<T> **poolEntry);
void setMinimalSamplingFrequency(float frequencySeconds); void setMinimalSamplingFrequency(float frequencySeconds);
ReturnValue_t serializeHkPacketIntoStore(store_address_t* storeId,
LocalDataSet* dataSet);
}; };
@ -123,14 +137,14 @@ ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
if (poolIter == localDpMap.end()) { if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:" sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl; " Pool entry not found." << std::endl;
return OwnsLocalDataPoolIF::POOL_ENTRY_NOT_FOUND; return POOL_ENTRY_NOT_FOUND;
} }
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second); *poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
if(*poolEntry == nullptr) { if(*poolEntry == nullptr) {
sif::debug << "HousekeepingManager::fetchPoolEntry:" sif::debug << "HousekeepingManager::fetchPoolEntry:"
" Pool entry not found." << std::endl; " Pool entry not found." << std::endl;
return OwnsLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT; return POOL_ENTRY_TYPE_CONFLICT;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -1,22 +1,25 @@
#include <framework/datapoollocal/LocalDataPoolManager.h> #include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/LocalDataSet.h> #include <framework/datapoollocal/LocalDataSet.h>
#include <cmath>
#include <cstring>
LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner): DataSetBase() { LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner): DataSetBase() {
if(hkOwner != nullptr) { if(hkOwner == nullptr) {
hkManager = hkOwner->getHkManagerHandle(); sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
} << std::endl;
else { }
// config error, error output here. hkManager = hkOwner->getHkManagerHandle();
}
} }
LocalDataSet::LocalDataSet(object_id_t ownerId): DataSetBase() { LocalDataSet::LocalDataSet(object_id_t ownerId): DataSetBase() {
OwnsLocalDataPoolIF* hkOwner = objectManager->get<OwnsLocalDataPoolIF>( OwnsLocalDataPoolIF* hkOwner = objectManager->get<OwnsLocalDataPoolIF>(
ownerId); ownerId);
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
// config error, error output here. sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
} << std::endl;
hkManager = hkOwner->getHkManagerHandle(); }
hkManager = hkOwner->getHkManagerHandle();
} }
LocalDataSet::~LocalDataSet() { LocalDataSet::~LocalDataSet() {
@ -27,9 +30,50 @@ ReturnValue_t LocalDataSet::lockDataPool(uint32_t timeoutMs) {
return mutex->lockMutex(timeoutMs); return mutex->lockMutex(timeoutMs);
} }
ReturnValue_t LocalDataSet::serializeWithValidityBuffer(uint8_t **buffer,
size_t *size, const size_t maxSize, bool bigEndian) 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, true);
if(validBufferIndexBit == 7) {
validBufferIndex ++;
validBufferIndexBit = 0;
}
else {
validBufferIndexBit ++;
}
}
result = registeredVariables[count]->serialize(buffer, size, maxSize,
bigEndian);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
}
// copy validity buffer to end
std::memcpy(*buffer, validityMask, validityMaskSize);
*size += validityMaskSize;
return result;
}
ReturnValue_t LocalDataSet::unlockDataPool() { ReturnValue_t LocalDataSet::unlockDataPool() {
MutexIF* mutex = hkManager->getMutexHandle(); MutexIF* mutex = hkManager->getMutexHandle();
return mutex->unlockMutex(); return mutex->unlockMutex();
} }
void LocalDataSet::bitSetter(uint8_t* byte, uint8_t position,
bool value) const {
if(position > 7) {
sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
return;
}
uint8_t shiftNumber = position + (7 - 2 * position);
*byte |= 1UL << shiftNumber;
}

View File

@ -55,6 +55,20 @@ public:
*/ */
~LocalDataSet(); ~LocalDataSet();
/**
* 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.
* @param buffer
* @param size
* @param maxSize
* @param bigEndian
* @param withValidityBuffer
* @return
*/
ReturnValue_t serializeWithValidityBuffer(uint8_t** buffer,
size_t* size, const size_t maxSize, bool bigEndian) const ;
protected: protected:
private: private:
/** /**
@ -79,6 +93,16 @@ private:
ReturnValue_t unlockDataPool() override; ReturnValue_t unlockDataPool() override;
LocalDataPoolManager* hkManager; LocalDataPoolManager* hkManager;
/**
* Sets the bit at the bit-position of a byte provided by its address
* to the specified value (zero or one).
* @param byte Pointer to byte to bitset.
* @param position MSB first, 0 to 7 possible.
* @param value Value to set.
* @return
*/
void bitSetter(uint8_t* byte, uint8_t position, bool value) const;
}; };
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */ #endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */

View File

@ -40,9 +40,7 @@ class OwnsLocalDataPoolIF {
public: public:
virtual~ OwnsLocalDataPoolIF() {}; virtual~ OwnsLocalDataPoolIF() {};
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING; static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF;
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(

View File

@ -96,6 +96,7 @@ public:
void setParameter(uint32_t parameter); void setParameter(uint32_t parameter);
uint32_t getParameter() const; uint32_t getParameter() const;
sid_t getSid() const;
void setHkReportMessage(sid_t sid, store_address_t storeId); void setHkReportMessage(sid_t sid, store_address_t storeId);
void setHkDiagnosticsMessage(sid_t sid, store_address_t storeId); void setHkDiagnosticsMessage(sid_t sid, store_address_t storeId);
@ -106,7 +107,7 @@ public:
virtual size_t getMinimumMessageSize() const override; virtual size_t getMinimumMessageSize() const override;
virtual void clear() override; virtual void clear() override;
private: private:
sid_t getSid() const;
void setSid(sid_t sid); void setSid(sid_t sid);
virtual uint8_t* getData() override; virtual uint8_t* getData() override;

View File

@ -61,8 +61,9 @@ enum {
MUTEX_IF, //MUX 55 MUTEX_IF, //MUX 55
MESSAGE_QUEUE_IF,//MQI 56 MESSAGE_QUEUE_IF,//MQI 56
SEMAPHORE_IF, //SPH 57 SEMAPHORE_IF, //SPH 57
HOUSEKEEPING, //HK 58 LOCAL_POOL_OWNER_IF, //LPIF 58
POOL_VARIABLE_IF, //PVA 59 POOL_VARIABLE_IF, //PVA 59
HOUSEKEEPING_MANAGER, //HKM 60
FW_CLASS_ID_COUNT //is actually count + 1 ! FW_CLASS_ID_COUNT //is actually count + 1 !
}; };