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;
}
LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse,
uint8_t nonDiagInvlFactor) {
if(queueToUse == nullptr) {
@ -42,17 +44,11 @@ ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse,
setNonDiagnosticIntervalFactor(nonDiagInvlFactor);
diagnosticMinimumInterval = owner->getPeriodicOperationFrequency();
regularMinimumInterval = diagnosticMinimumInterval * nonDiagnosticIntervalFactor;
regularMinimumInterval = diagnosticMinimumInterval *
nonDiagnosticIntervalFactor;
return initializeHousekeepingPoolEntriesOnce();
}
void LocalDataPoolManager::setHkPacketDestination(
MessageQueueId_t hkDestination) {
this->hkDestination = hkDestination;
}
LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
if(not mapInitialized) {
ReturnValue_t result = owner->initializePoolEntries(localPoolMap);
@ -66,6 +62,58 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
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(
CommandMessage* message) {
Command_t command = message->getCommand();
@ -106,46 +154,46 @@ const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
float collectionInterval, MessageQueueId_t sendTo) {
LocalPoolDataSetBase* dataSetToSerialize = dynamic_cast<LocalPoolDataSetBase*>(
owner->getDataSetHandle(sid));
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
LocalPoolDataSetBase* dataSetToSerialize =
dynamic_cast<LocalPoolDataSetBase*>(owner->getDataSetHandle(sid));
if(dataSetToSerialize == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
store_address_t storeId;
HousekeepingPacketDownlink hkPacket(sid, collectionInterval,
dataSetToSerialize->getFillCount(), dataSetToSerialize);
ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, &storeId);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
// store_address_t storeId;
// HousekeepingPacketDownlink hkPacket(sid, collectionInterval,
// dataSetToSerialize->getFillCount(), dataSetToSerialize);
// ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, &storeId);
// if(result != HasReturnvaluesIF::RETURN_OK) {
// return result;
// }
// and now we set a HK message and send it the HK packet destination.
CommandMessage hkMessage;
HousekeepingMessage::setHkReportMessage(&hkMessage, sid, storeId);
if(hkQueue == nullptr) {
return QUEUE_OR_DESTINATION_NOT_SET;
}
// CommandMessage hkMessage;
// HousekeepingMessage::setHkReportMessage(&hkMessage, sid, storeId);
// if(hkQueue == nullptr) {
// 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) {
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);
}
}
return result;
// return result;
return 0;
}
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) {
if(receiver->intervalCounter >= intervalSecondsToInterval(
receiver->isDiagnostics,
receiver->hkParameter.collectionIntervalSeconds)) {
ReturnValue_t result = generateHousekeepingPacket(
receiver->dataId.dataSetSid, receiver->destinationQueue);
receiver->dataId.dataSetSid /*, receiver->destinationQueue */);
if(result != HasReturnvaluesIF::RETURN_OK) {
// configuration error
sif::debug << "LocalDataPoolManager::performHkOperation:"
@ -259,7 +281,8 @@ uint32_t LocalDataPoolManager::intervalSecondsToInterval(bool isDiagnostics,
float LocalDataPoolManager::intervalToIntervalSeconds(bool isDiagnostics,
uint32_t collectionInterval) {
if(isDiagnostics) {
return static_cast<float>(collectionInterval * diagnosticMinimumInterval);
return static_cast<float>(collectionInterval *
diagnosticMinimumInterval);
}
else {
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 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
@ -79,6 +78,13 @@ public:
ReturnValue_t initialize(MessageQueueIF* queueToUse,
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
* than diagnostic packets.
@ -96,20 +102,13 @@ public:
* @return
*/
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.
* @param sid
* @return
*/
ReturnValue_t generateHousekeepingPacket(sid_t sid, float collectionInterval,
MessageQueueId_t sendTo = MessageQueueIF::NO_QUEUE);
ReturnValue_t generateHousekeepingPacket(sid_t sid);
ReturnValue_t generateSetStructurePacket(sid_t sid);
ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
@ -174,14 +173,15 @@ private:
type of data the receiver is interested in (full datasets or
single data variables. */
union DataId {
DataId(): dataSetSid() {}
/** Will be initialized to INVALID_ADDRESS */
sid_t dataSetSid;
lp_id_t localPoolId = HasLocalDataPoolIF::NO_POOL_ID;
};
DataId dataId;
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
ReportingType reportingType = ReportingType::PERIODIC;
MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE;
bool reportingEnabled = true;
/** Different members of this union will be used depending on reporting
type */
@ -216,13 +216,6 @@ private:
*/
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. */
StorageManagerIF* ipcStore = nullptr;
/**