2022-08-01 11:00:36 +02:00
|
|
|
#include "fsfw/tcdistribution/TcDistributorBase.h"
|
2022-08-01 11:05:46 +02:00
|
|
|
|
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/tmtcservices/TmTcMessage.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-08-01 17:16:37 +02:00
|
|
|
TcDistributorBase::TcDistributorBase(object_id_t objectId, MessageQueueIF* tcQueue_)
|
|
|
|
: SystemObject(objectId), tcQueue(tcQueue_) {
|
|
|
|
if (tcQueue == nullptr) {
|
|
|
|
ownedQueue = true;
|
|
|
|
tcQueue = QueueFactory::instance()->createMessageQueue(DISTRIBUTER_MAX_PACKETS);
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-08-01 17:16:37 +02:00
|
|
|
TcDistributorBase::~TcDistributorBase() {
|
|
|
|
if (ownedQueue) {
|
|
|
|
QueueFactory::instance()->deleteMessageQueue(tcQueue);
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-08-01 11:00:36 +02:00
|
|
|
ReturnValue_t TcDistributorBase::performOperation(uint8_t opCode) {
|
2022-07-27 17:00:43 +02:00
|
|
|
ReturnValue_t status;
|
2022-08-01 17:16:37 +02:00
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK;
|
|
|
|
status = tcQueue->receiveMessage(¤tMessage)) {
|
2022-08-01 17:16:37 +02:00
|
|
|
ReturnValue_t packetResult = handlePacket();
|
|
|
|
if (packetResult != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
result = packetResult;
|
|
|
|
triggerEvent(HANDLE_PACKET_FAILED, packetResult, __LINE__);
|
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
if (status == MessageQueueIF::EMPTY) {
|
2022-08-01 17:16:37 +02:00
|
|
|
return result;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2022-08-01 17:16:37 +02:00
|
|
|
return result;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-08-01 11:00:36 +02:00
|
|
|
ReturnValue_t TcDistributorBase::handlePacket() {
|
|
|
|
MessageQueueId_t destId;
|
|
|
|
ReturnValue_t result = selectDestination(destId);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2022-08-03 11:33:10 +02:00
|
|
|
return callbackAfterSending(tcQueue->sendMessage(destId, ¤tMessage));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-08-01 11:00:36 +02:00
|
|
|
ReturnValue_t TcDistributorBase::callbackAfterSending(ReturnValue_t queueStatus) {
|
|
|
|
return RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|