2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/pus/Service1TelecommandVerification.h"
|
2020-07-10 14:16:55 +02:00
|
|
|
|
2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/pus/servicepackets/Service1Packets.h"
|
2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h"
|
2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/tmtcservices/PusVerificationReport.h"
|
2020-07-10 14:16:55 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
Service1TelecommandVerification::Service1TelecommandVerification(object_id_t objectId,
|
|
|
|
uint16_t apid, uint8_t serviceId,
|
|
|
|
object_id_t targetDestination,
|
|
|
|
uint16_t messageQueueDepth)
|
|
|
|
: SystemObject(objectId),
|
|
|
|
apid(apid),
|
|
|
|
serviceId(serviceId),
|
|
|
|
targetDestination(targetDestination) {
|
2022-02-19 16:14:02 +01:00
|
|
|
auto mqArgs = MqArgs(objectId, static_cast<void*>(this));
|
2022-02-22 10:17:56 +01:00
|
|
|
tmQueue = QueueFactory::instance()->createMessageQueue(
|
|
|
|
messageQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
2021-04-09 09:14:42 +02:00
|
|
|
Service1TelecommandVerification::~Service1TelecommandVerification() {
|
2022-02-02 10:29:30 +01:00
|
|
|
QueueFactory::instance()->deleteMessageQueue(tmQueue);
|
2021-04-09 09:14:42 +02:00
|
|
|
}
|
2020-07-10 14:16:55 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
MessageQueueId_t Service1TelecommandVerification::getVerificationQueue() {
|
|
|
|
return tmQueue->getId();
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t Service1TelecommandVerification::performOperation(uint8_t operationCode) {
|
|
|
|
PusVerificationMessage message;
|
|
|
|
ReturnValue_t status = tmQueue->receiveMessage(&message);
|
|
|
|
while (status == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
status = sendVerificationReport(&message);
|
|
|
|
if (status != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
status = tmQueue->receiveMessage(&message);
|
|
|
|
}
|
|
|
|
if (status == MessageQueueIF::EMPTY) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
} else {
|
|
|
|
return status;
|
|
|
|
}
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Service1TelecommandVerification::sendVerificationReport(
|
2022-02-02 10:29:30 +01:00
|
|
|
PusVerificationMessage* message) {
|
|
|
|
ReturnValue_t result;
|
|
|
|
if (message->getReportId() % 2 == 0) {
|
|
|
|
result = generateFailureReport(message);
|
|
|
|
} else {
|
|
|
|
result = generateSuccessReport(message);
|
|
|
|
}
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::error << "Service1TelecommandVerification::sendVerificationReport: "
|
|
|
|
"Sending verification packet failed !"
|
|
|
|
<< std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
return result;
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Service1TelecommandVerification::generateFailureReport(
|
2022-02-02 10:29:30 +01:00
|
|
|
PusVerificationMessage* message) {
|
|
|
|
FailureReport report(message->getReportId(), message->getTcPacketId(),
|
|
|
|
message->getTcSequenceControl(), message->getStep(), message->getErrorCode(),
|
|
|
|
message->getParameter1(), message->getParameter2());
|
2021-04-13 00:19:09 +02:00
|
|
|
#if FSFW_USE_PUS_C_TELEMETRY == 0
|
2022-02-02 10:29:30 +01:00
|
|
|
TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report);
|
2021-04-13 00:19:09 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report);
|
2021-04-13 00:19:09 +02:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(), tmQueue->getId());
|
|
|
|
return result;
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Service1TelecommandVerification::generateSuccessReport(
|
2022-02-02 10:29:30 +01:00
|
|
|
PusVerificationMessage* message) {
|
|
|
|
SuccessReport report(message->getReportId(), message->getTcPacketId(),
|
|
|
|
message->getTcSequenceControl(), message->getStep());
|
2021-04-13 00:19:09 +02:00
|
|
|
#if FSFW_USE_PUS_C_TELEMETRY == 0
|
2022-02-02 10:29:30 +01:00
|
|
|
TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report);
|
2021-04-13 00:19:09 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report);
|
2021-04-13 00:19:09 +02:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(), tmQueue->getId());
|
|
|
|
return result;
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Service1TelecommandVerification::initialize() {
|
2022-02-02 10:29:30 +01:00
|
|
|
// Get target object for TC verification messages
|
|
|
|
AcceptsTelemetryIF* funnel =
|
|
|
|
ObjectManager::instance()->get<AcceptsTelemetryIF>(targetDestination);
|
|
|
|
if (funnel == nullptr) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::error << "Service1TelecommandVerification::initialize: Specified"
|
|
|
|
" TM funnel invalid. Make sure it is set up and implements"
|
|
|
|
" AcceptsTelemetryIF."
|
|
|
|
<< std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
tmQueue->setDefaultDestination(funnel->getReportReceptionQueue());
|
|
|
|
return SystemObject::initialize();
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|