fsfw/tmtcservices/VerificationReporter.cpp

126 lines
4.2 KiB
C++
Raw Normal View History

2020-09-29 13:34:27 +02:00
#include "VerificationReporter.h"
2020-08-13 20:53:35 +02:00
#include "AcceptsVerifyMessageIF.h"
#include "PusVerificationReport.h"
2021-06-05 19:52:38 +02:00
#include "../objectmanager/ObjectManager.h"
2020-09-29 13:34:27 +02:00
#include "../ipc/MessageQueueIF.h"
2021-06-05 19:52:38 +02:00
#include "../serviceinterface/ServiceInterface.h"
2020-09-29 13:34:27 +02:00
#include "../objectmanager/frameworkObjects.h"
object_id_t VerificationReporter::messageReceiver =
objects::PUS_SERVICE_1_VERIFICATION;
VerificationReporter::VerificationReporter() :
2020-09-29 13:34:27 +02:00
acknowledgeQueue(MessageQueueIF::NO_QUEUE) {
}
2020-09-29 13:34:27 +02:00
VerificationReporter::~VerificationReporter() {}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
2021-06-13 16:29:13 +02:00
TcPacketBase* currentPacket, uint8_t set_step) {
2020-09-29 13:34:27 +02:00
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
2021-06-13 16:29:13 +02:00
if(currentPacket == nullptr) {
return;
}
PusVerificationMessage message(set_report_id,
2021-06-13 16:29:13 +02:00
currentPacket->getAcknowledgeFlags(),
currentPacket->getPacketId(),
currentPacket->getPacketSequenceControl(), 0, set_step);
2020-09-29 13:34:27 +02:00
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-09-29 13:34:27 +02:00
sif::error << "VerificationReporter::sendSuccessReport: Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
#endif
}
}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step) {
2020-09-29 13:34:27 +02:00
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(set_report_id, ackFlags, tcPacketId,
tcSequenceControl, 0, set_step);
2020-09-29 13:34:27 +02:00
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-09-29 13:34:27 +02:00
sif::error << "VerificationReporter::sendSuccessReport: Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
#endif
}
}
void VerificationReporter::sendFailureReport(uint8_t report_id,
2021-06-13 16:29:13 +02:00
TcPacketBase* currentPacket, ReturnValue_t error_code, uint8_t step,
uint32_t parameter1, uint32_t parameter2) {
2020-09-29 13:34:27 +02:00
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
2021-06-13 16:29:13 +02:00
if(currentPacket == nullptr) {
return;
}
PusVerificationMessage message(report_id,
2021-06-13 16:29:13 +02:00
currentPacket->getAcknowledgeFlags(),
currentPacket->getPacketId(),
currentPacket->getPacketSequenceControl(), error_code, step,
parameter1, parameter2);
2020-09-29 13:34:27 +02:00
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-09-29 13:34:27 +02:00
sif::error << "VerificationReporter::sendFailureReport: Error writing "
<< "to queue. Code: " << std::hex << "0x" << status << std::dec
<< std::endl;
#endif
}
}
void VerificationReporter::sendFailureReport(uint8_t report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t error_code, uint8_t step, uint32_t parameter1,
uint32_t parameter2) {
2020-09-29 13:34:27 +02:00
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(report_id, ackFlags, tcPacketId,
tcSequenceControl, error_code, step, parameter1, parameter2);
2020-09-29 13:34:27 +02:00
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-09-29 13:34:27 +02:00
sif::error << "VerificationReporter::sendFailureReport: Error writing "
<< "to queue. Code: " << std::hex << "0x" << status << std::dec
<< std::endl;
#endif
}
}
void VerificationReporter::initialize() {
2020-09-29 13:34:27 +02:00
if(messageReceiver == objects::NO_OBJECT) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-09-29 13:34:27 +02:00
sif::warning << "VerificationReporter::initialize: Verification message"
" receiver object ID not set yet in Factory!" << std::endl;
#endif
2020-09-29 13:34:27 +02:00
return;
}
2021-06-05 19:52:38 +02:00
AcceptsVerifyMessageIF* temp = ObjectManager::instance()->get<AcceptsVerifyMessageIF>(
messageReceiver);
2020-09-29 13:34:27 +02:00
if (temp == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-09-29 13:34:27 +02:00
sif::error << "VerificationReporter::initialize: Message "
<< "receiver invalid. Make sure it is set up properly and "
<< "implementsAcceptsVerifyMessageIF" << std::endl;
#endif
2020-09-29 13:34:27 +02:00
return;
}
2020-09-29 13:34:27 +02:00
this->acknowledgeQueue = temp->getVerificationQueue();
}