2021-09-26 08:29:30 +02:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
|
|
#include "fsfw/serviceinterface/serviceInterfaceDefintions.h"
|
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
#include "CCSDSHandler.h"
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
CCSDSHandler::CCSDSHandler(object_id_t objectId, object_id_t ptmeId) :
|
|
|
|
SystemObject(objectId), ptmeId(ptmeId), parameterHelper(this) {
|
|
|
|
commandQueue = QueueFactory::instance()->createMessageQueue(QUEUE_SIZE);
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CCSDSHandler::~CCSDSHandler() {
|
|
|
|
}
|
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
ReturnValue_t CCSDSHandler::performOperation(uint8_t operationCode) {
|
2021-09-19 12:27:48 +02:00
|
|
|
readCommandQueue();
|
2021-09-22 16:54:55 +02:00
|
|
|
handleTelemetry();
|
|
|
|
handleTelecommands();
|
2021-09-19 12:27:48 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-09-22 16:54:55 +02:00
|
|
|
void CCSDSHandler::handleTelemetry() {
|
|
|
|
VirtualChannelMapIter iter;
|
2021-09-26 08:29:30 +02:00
|
|
|
for (iter = virtualChannelMap.begin(); iter != virtualChannelMap.end(); iter++) {
|
|
|
|
iter->second->performOperation();
|
2021-09-22 16:54:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSDSHandler::handleTelecommands() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-19 12:27:48 +02:00
|
|
|
ReturnValue_t CCSDSHandler::initialize() {
|
2021-09-26 08:29:30 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
PtmeIF* ptme = ObjectManager::instance()->get<PtmeIF>(ptmeId);
|
2021-09-19 12:27:48 +02:00
|
|
|
if (ptme == nullptr) {
|
2021-09-26 08:29:30 +02:00
|
|
|
sif::warning << "Invalid PTME object" << std::endl;
|
2021-09-19 12:27:48 +02:00
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
2021-09-26 08:29:30 +02:00
|
|
|
|
|
|
|
result = parameterHelper.initialize();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
2021-09-29 14:47:20 +02:00
|
|
|
|
|
|
|
VirtualChannelMapIter iter;
|
|
|
|
for (iter = virtualChannelMap.begin(); iter != virtualChannelMap.end(); iter++) {
|
|
|
|
result = iter->second->initialize();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
iter->second->setPtmeObject(ptme);
|
|
|
|
}
|
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
return result;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSDSHandler::readCommandQueue(void) {
|
|
|
|
CommandMessage commandMessage;
|
|
|
|
ReturnValue_t result = RETURN_FAILED;
|
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
result = commandQueue->receiveMessage(&commandMessage);
|
2021-09-22 16:54:55 +02:00
|
|
|
if (result == RETURN_OK) {
|
|
|
|
result = parameterHelper.handleParameterMessage(&commandMessage);
|
|
|
|
if (result == RETURN_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CommandMessage reply;
|
2021-09-26 08:29:30 +02:00
|
|
|
reply.setReplyRejected(CommandMessage::UNKNOWN_COMMAND,
|
2021-09-22 16:54:55 +02:00
|
|
|
commandMessage.getCommand());
|
2021-09-26 08:29:30 +02:00
|
|
|
commandQueue->reply(&reply);
|
2021-09-22 16:54:55 +02:00
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t CCSDSHandler::getCommandQueue() const {
|
2021-09-26 08:29:30 +02:00
|
|
|
return commandQueue->getId();
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
void CCSDSHandler::addVirtualChannel(VcId_t vcId, VirtualChannel* virtualChannel) {
|
|
|
|
if (vcId > config::NUMBER_OF_VIRTUAL_CHANNELS) {
|
|
|
|
sif::warning << "CCSDSHandler::addVirtualChannel: Invalid virtual channel ID" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
if (virtualChannel == nullptr) {
|
|
|
|
sif::warning << "CCSDSHandler::addVirtualChannel: Invalid virtual channel interface" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
auto status = virtualChannelMap.emplace(vcId, virtualChannel);
|
|
|
|
if (status.second == false) {
|
|
|
|
sif::warning << "CCSDSHandler::addVirtualChannel: Failed to add virtual channel to "
|
|
|
|
"virtual channel map" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t CCSDSHandler::getReportReceptionQueue(uint8_t virtualChannel) {
|
2021-09-22 16:54:55 +02:00
|
|
|
if (virtualChannel < config::NUMBER_OF_VIRTUAL_CHANNELS) {
|
2021-09-26 08:29:30 +02:00
|
|
|
VirtualChannelMapIter iter = virtualChannelMap.find(virtualChannel);
|
|
|
|
if (iter != virtualChannelMap.end()) {
|
|
|
|
return iter->second->getReportReceptionQueue();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sif::warning << "CCSDSHandler::getReportReceptionQueue: Virtual channel with ID "
|
|
|
|
<< static_cast<unsigned int>(virtualChannel) << " not in virtual channel map"
|
|
|
|
<< std::endl;
|
|
|
|
return MessageQueueIF::NO_QUEUE;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
} else {
|
|
|
|
sif::debug << "CCSDSHandler::getReportReceptionQueue: Invalid virtual channel requested";
|
2021-09-26 08:29:30 +02:00
|
|
|
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
2021-09-26 08:29:30 +02:00
|
|
|
return MessageQueueIF::NO_QUEUE;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 16:54:55 +02:00
|
|
|
ReturnValue_t CCSDSHandler::getParameter(uint8_t domainId, uint8_t uniqueIdentifier,
|
|
|
|
ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues,
|
|
|
|
uint16_t startAtIndex) {
|
|
|
|
return RETURN_OK;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|