first subscriptio nfunction written

This commit is contained in:
Robin Müller 2020-08-23 23:24:48 +02:00
parent a95bc6b293
commit a5227115e5
2 changed files with 100 additions and 84 deletions

View File

@ -32,6 +32,8 @@ LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner,
hkQueue = queueToUse; hkQueue = queueToUse;
} }
LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse, ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse,
uint8_t nonDiagInvlFactor) { uint8_t nonDiagInvlFactor) {
if(queueToUse == nullptr) { if(queueToUse == nullptr) {
@ -42,17 +44,11 @@ ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse,
setNonDiagnosticIntervalFactor(nonDiagInvlFactor); setNonDiagnosticIntervalFactor(nonDiagInvlFactor);
diagnosticMinimumInterval = owner->getPeriodicOperationFrequency(); diagnosticMinimumInterval = owner->getPeriodicOperationFrequency();
regularMinimumInterval = diagnosticMinimumInterval * nonDiagnosticIntervalFactor; regularMinimumInterval = diagnosticMinimumInterval *
nonDiagnosticIntervalFactor;
return initializeHousekeepingPoolEntriesOnce(); return initializeHousekeepingPoolEntriesOnce();
} }
void LocalDataPoolManager::setHkPacketDestination(
MessageQueueId_t hkDestination) {
this->hkDestination = hkDestination;
}
LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
if(not mapInitialized) { if(not mapInitialized) {
ReturnValue_t result = owner->initializePoolEntries(localPoolMap); ReturnValue_t result = owner->initializePoolEntries(localPoolMap);
@ -66,6 +62,58 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t LocalDataPoolManager::performHkOperation() {
for(auto& hkReceiversIter: hkReceiversMap) {
HkReceiver* receiver = &hkReceiversIter.second;
if(not receiver->reportingEnabled) {
return HasReturnvaluesIF::RETURN_OK;
}
switch(receiver->reportingType) {
case(ReportingType::PERIODIC): {
if(receiver->dataId.dataSetSid.notSet()) {
// Periodic packets shall only be generated from datasets.
continue;
}
performPeriodicHkGeneration(receiver);
break;
}
case(ReportingType::UPDATE_SNAPSHOT): {
// check whether data has changed and send messages in case it has.
break;
}
default:
// This should never happen.
return HasReturnvaluesIF::RETURN_FAILED;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
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.dataSetSid = sid;
hkReceiver.reportingType = ReportingType::PERIODIC;
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
hkReceiver.reportingEnabled = enableReporting;
hkReceiver.hkParameter.collectionIntervalSeconds = collectionInterval;
hkReceiver.isDiagnostics = isDiagnostics;
hkReceiver.intervalCounter = 1;
hkReceiversMap.emplace(packetDestination, hkReceiver);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
CommandMessage* message) { CommandMessage* message) {
Command_t command = message->getCommand(); Command_t command = message->getCommand();
@ -106,46 +154,46 @@ const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner; return owner;
} }
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
float collectionInterval, MessageQueueId_t sendTo) { LocalPoolDataSetBase* dataSetToSerialize =
LocalPoolDataSetBase* dataSetToSerialize = dynamic_cast<LocalPoolDataSetBase*>( dynamic_cast<LocalPoolDataSetBase*>(owner->getDataSetHandle(sid));
owner->getDataSetHandle(sid));
if(dataSetToSerialize == nullptr) { if(dataSetToSerialize == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:" sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl; " Set ID not found" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
store_address_t storeId; // store_address_t storeId;
HousekeepingPacketDownlink hkPacket(sid, collectionInterval, // HousekeepingPacketDownlink hkPacket(sid, collectionInterval,
dataSetToSerialize->getFillCount(), dataSetToSerialize); // dataSetToSerialize->getFillCount(), dataSetToSerialize);
ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, &storeId); // ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, &storeId);
if(result != HasReturnvaluesIF::RETURN_OK) { // if(result != HasReturnvaluesIF::RETURN_OK) {
return result; // return result;
} // }
// and now we set a HK message and send it the HK packet destination. // and now we set a HK message and send it the HK packet destination.
CommandMessage hkMessage; // CommandMessage hkMessage;
HousekeepingMessage::setHkReportMessage(&hkMessage, sid, storeId); // HousekeepingMessage::setHkReportMessage(&hkMessage, sid, storeId);
if(hkQueue == nullptr) { // if(hkQueue == nullptr) {
return QUEUE_OR_DESTINATION_NOT_SET; // return QUEUE_OR_DESTINATION_NOT_SET;
} // }
//
// if(sendTo != MessageQueueIF::NO_QUEUE) {
// result = hkQueue->sendMessage(sendTo, &hkMessage);
// }
// else {
// if(hkDestination == MessageQueueIF::NO_QUEUE) {
// sif::warning << "LocalDataPoolManager::generateHousekeepingPacket:"
// " Destination is not set properly!" << std::endl;
// return QUEUE_OR_DESTINATION_NOT_SET;
// }
// else {
// result = hkQueue->sendMessage(hkDestination, &hkMessage);
// }
// }
if(sendTo != MessageQueueIF::NO_QUEUE) { // return result;
result = hkQueue->sendMessage(sendTo, &hkMessage); return 0;
}
else {
if(hkDestination == MessageQueueIF::NO_QUEUE) {
sif::warning << "LocalDataPoolManager::generateHousekeepingPacket:"
" Destination is not set properly!" << std::endl;
return QUEUE_OR_DESTINATION_NOT_SET;
}
else {
result = hkQueue->sendMessage(hkDestination, &hkMessage);
}
}
return result;
} }
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore( ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
@ -198,40 +246,14 @@ void LocalDataPoolManager::setNonDiagnosticIntervalFactor(
} }
ReturnValue_t LocalDataPoolManager::performHkOperation() {
for(auto& hkReceiversIter: hkReceiversMap) {
HkReceiver* receiver = &hkReceiversIter.second;
if(not receiver->reportingEnabled) {
return HasReturnvaluesIF::RETURN_OK;
}
switch(receiver->reportingType) {
case(ReportingType::PERIODIC): {
if(receiver->dataId.dataSetSid.notSet()) {
// Periodic packets shall only be generated from datasets.
continue;
}
performPeriodicHkGeneration(receiver);
break;
}
case(ReportingType::UPDATE_SNAPSHOT): {
// check whether data has changed and send messages in case it has.
break;
}
default:
// This should never happen.
return HasReturnvaluesIF::RETURN_FAILED;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver* receiver) { void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver* receiver) {
if(receiver->intervalCounter >= intervalSecondsToInterval( if(receiver->intervalCounter >= intervalSecondsToInterval(
receiver->isDiagnostics, receiver->isDiagnostics,
receiver->hkParameter.collectionIntervalSeconds)) { receiver->hkParameter.collectionIntervalSeconds)) {
ReturnValue_t result = generateHousekeepingPacket( ReturnValue_t result = generateHousekeepingPacket(
receiver->dataId.dataSetSid, receiver->destinationQueue); receiver->dataId.dataSetSid /*, receiver->destinationQueue */);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
// configuration error // configuration error
sif::debug << "LocalDataPoolManager::performHkOperation:" sif::debug << "LocalDataPoolManager::performHkOperation:"
@ -259,7 +281,8 @@ uint32_t LocalDataPoolManager::intervalSecondsToInterval(bool isDiagnostics,
float LocalDataPoolManager::intervalToIntervalSeconds(bool isDiagnostics, float LocalDataPoolManager::intervalToIntervalSeconds(bool isDiagnostics,
uint32_t collectionInterval) { uint32_t collectionInterval) {
if(isDiagnostics) { if(isDiagnostics) {
return static_cast<float>(collectionInterval * diagnosticMinimumInterval); return static_cast<float>(collectionInterval *
diagnosticMinimumInterval);
} }
else { else {
return static_cast<float>(collectionInterval * regularMinimumInterval); return static_cast<float>(collectionInterval * regularMinimumInterval);

View File

@ -53,7 +53,6 @@ public:
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x1); static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x1);
static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x2); static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x2);
//static constexpr ReturnValue_t SET_NOT_FOUND = MAKE_RETURN_CODE(0x3);
/** /**
* This constructor is used by a class which wants to implement * This constructor is used by a class which wants to implement
@ -79,6 +78,13 @@ public:
ReturnValue_t initialize(MessageQueueIF* queueToUse, ReturnValue_t initialize(MessageQueueIF* queueToUse,
uint8_t nonDiagInvlFactor = 5); uint8_t nonDiagInvlFactor = 5);
/**
* @return
*/
ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting,
float collectionInterval, bool isDiagnostics,
object_id_t packetDestination = defaultHkDestination);
/** /**
* Non-Diagnostics packets usually have a lower minimum sampling frequency * Non-Diagnostics packets usually have a lower minimum sampling frequency
* than diagnostic packets. * than diagnostic packets.
@ -96,20 +102,13 @@ public:
* @return * @return
*/ */
ReturnValue_t performHkOperation(); ReturnValue_t performHkOperation();
/**
* This function is used to set the default HK packet destination.
* This destination will usually only be set once.
* @param hkDestination
*/
void setHkPacketDestination(MessageQueueId_t hkDestination);
/** /**
* Generate a housekeeping packet with a given SID. * Generate a housekeeping packet with a given SID.
* @param sid * @param sid
* @return * @return
*/ */
ReturnValue_t generateHousekeepingPacket(sid_t sid, float collectionInterval, ReturnValue_t generateHousekeepingPacket(sid_t sid);
MessageQueueId_t sendTo = MessageQueueIF::NO_QUEUE);
ReturnValue_t generateSetStructurePacket(sid_t sid); ReturnValue_t generateSetStructurePacket(sid_t sid);
ReturnValue_t handleHousekeepingMessage(CommandMessage* message); ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
@ -174,14 +173,15 @@ private:
type of data the receiver is interested in (full datasets or type of data the receiver is interested in (full datasets or
single data variables. */ single data variables. */
union DataId { union DataId {
DataId(): dataSetSid() {}
/** Will be initialized to INVALID_ADDRESS */ /** Will be initialized to INVALID_ADDRESS */
sid_t dataSetSid; sid_t dataSetSid;
lp_id_t localPoolId = HasLocalDataPoolIF::NO_POOL_ID; lp_id_t localPoolId = HasLocalDataPoolIF::NO_POOL_ID;
}; };
DataId dataId; DataId dataId;
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
ReportingType reportingType = ReportingType::PERIODIC; ReportingType reportingType = ReportingType::PERIODIC;
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
bool reportingEnabled = true; bool reportingEnabled = true;
/** Different members of this union will be used depending on reporting /** Different members of this union will be used depending on reporting
type */ type */
@ -216,13 +216,6 @@ private:
*/ */
MessageQueueIF* hkQueue = nullptr; MessageQueueIF* hkQueue = nullptr;
/**
* HK replies will always be a reply to the commander, but HK packet
* can be sent to another destination by specifying this message queue
* ID, for example to a dedicated housekeeping service implementation.
*/
MessageQueueId_t hkDestination = 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;
/** /**