fsfw/src/fsfw/tcdistribution/TcDistributor.cpp

48 lines
1.7 KiB
C++
Raw Normal View History

2021-07-13 20:22:54 +02:00
#include "fsfw/tcdistribution/TcDistributor.h"
2020-10-01 13:23:06 +02:00
2022-02-02 10:29:30 +01:00
#include "fsfw/ipc/QueueFactory.h"
2021-07-13 20:22:54 +02:00
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
2022-02-02 10:29:30 +01:00
TcDistributor::TcDistributor(object_id_t objectId) : SystemObject(objectId) {
2022-02-19 16:14:02 +01:00
auto mqArgs = MqArgs(objectId);
2022-02-22 10:17:56 +01:00
tcQueue = QueueFactory::instance()->createMessageQueue(
DISTRIBUTER_MAX_PACKETS, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
}
2022-02-02 10:29:30 +01:00
TcDistributor::~TcDistributor() { QueueFactory::instance()->deleteMessageQueue(tcQueue); }
ReturnValue_t TcDistributor::performOperation(uint8_t opCode) {
2022-07-27 17:00:43 +02:00
ReturnValue_t status;
2022-02-02 10:29:30 +01:00
for (status = tcQueue->receiveMessage(&currentMessage); status == RETURN_OK;
status = tcQueue->receiveMessage(&currentMessage)) {
status = handlePacket();
}
if (status == MessageQueueIF::EMPTY) {
return RETURN_OK;
}
2022-07-27 17:00:43 +02:00
return status;
}
ReturnValue_t TcDistributor::handlePacket() {
2022-07-27 17:00:43 +02:00
auto queueMapIt = selectDestination();
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
if (queueMapIt != queueMap.end()) {
result = tcQueue->sendMessage(queueMapIt->second, &currentMessage);
2022-02-02 10:29:30 +01:00
}
2022-07-27 17:00:43 +02:00
return callbackAfterSending(result);
}
void TcDistributor::print() {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::debug << "Distributor content is: " << std::endl << "ID\t| Message Queue ID" << std::endl;
sif::debug << std::setfill('0') << std::setw(8) << std::hex;
for (const auto& queueMapIter : queueMap) {
sif::debug << queueMapIter.first << "\t| 0x" << queueMapIter.second << std::endl;
}
sif::debug << std::setfill(' ') << std::dec;
#endif
}
2022-02-02 10:29:30 +01:00
ReturnValue_t TcDistributor::callbackAfterSending(ReturnValue_t queueStatus) { return RETURN_OK; }