1
0
forked from fsfw/fsfw

renormalized line endings

This commit is contained in:
2020-08-28 18:33:29 +02:00
parent 9abd796e6f
commit 1b9c8446b7
381 changed files with 38723 additions and 38723 deletions

View File

@ -1,43 +1,43 @@
#ifndef FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_
#define FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_
#include "../ipc/MessageQueueSenderIF.h"
/**
* @brief This interface is implemented by classes that are sinks for
* Telecommands.
* @details Any service receiving telecommands shall implement this interface
* and thus make the service id and the receiving message queue public.
*/
class AcceptsTelecommandsIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::ACCEPTS_TELECOMMANDS_IF;
static const ReturnValue_t ACTIVITY_STARTED = MAKE_RETURN_CODE(1); // is this used anywhere or can it be removed?
static const ReturnValue_t INVALID_SUBSERVICE = MAKE_RETURN_CODE(2);
static const ReturnValue_t ILLEGAL_APPLICATION_DATA = MAKE_RETURN_CODE(3);
static const ReturnValue_t SEND_TM_FAILED = MAKE_RETURN_CODE(4);
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(5);
/**
* @brief The virtual destructor as it is mandatory for C++ interfaces.
*/
virtual ~AcceptsTelecommandsIF() {
}
/**
* @brief Getter for the service id.
* @details Any receiving service (at least any PUS service) shall have a
* service ID. If the receiver can handle Telecommands, but for
* some reason has no service id, it shall return 0.
* @return The service ID or 0.
*/
virtual uint16_t getIdentifier() = 0;
/**
* @brief This method returns the message queue id of the telecommand
* receiving message queue.
* @return The telecommand reception message queue id.
*/
virtual MessageQueueId_t getRequestQueue() = 0;
};
#endif /* FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_ */
#ifndef FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_
#define FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_
#include "../ipc/MessageQueueSenderIF.h"
/**
* @brief This interface is implemented by classes that are sinks for
* Telecommands.
* @details Any service receiving telecommands shall implement this interface
* and thus make the service id and the receiving message queue public.
*/
class AcceptsTelecommandsIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::ACCEPTS_TELECOMMANDS_IF;
static const ReturnValue_t ACTIVITY_STARTED = MAKE_RETURN_CODE(1); // is this used anywhere or can it be removed?
static const ReturnValue_t INVALID_SUBSERVICE = MAKE_RETURN_CODE(2);
static const ReturnValue_t ILLEGAL_APPLICATION_DATA = MAKE_RETURN_CODE(3);
static const ReturnValue_t SEND_TM_FAILED = MAKE_RETURN_CODE(4);
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(5);
/**
* @brief The virtual destructor as it is mandatory for C++ interfaces.
*/
virtual ~AcceptsTelecommandsIF() {
}
/**
* @brief Getter for the service id.
* @details Any receiving service (at least any PUS service) shall have a
* service ID. If the receiver can handle Telecommands, but for
* some reason has no service id, it shall return 0.
* @return The service ID or 0.
*/
virtual uint16_t getIdentifier() = 0;
/**
* @brief This method returns the message queue id of the telecommand
* receiving message queue.
* @return The telecommand reception message queue id.
*/
virtual MessageQueueId_t getRequestQueue() = 0;
};
#endif /* FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_ */

View File

@ -1,26 +1,26 @@
#ifndef ACCEPTSTELEMETRYIF_H_
#define ACCEPTSTELEMETRYIF_H_
#include "../ipc/MessageQueueSenderIF.h"
/**
* @brief This interface is implemented by classes that are sinks for
* Telemetry.
* @details Any object receiving telemetry shall implement this interface
* and thus make the service id and the receiving message queue public.
*/
class AcceptsTelemetryIF {
public:
/**
* @brief The virtual destructor as it is mandatory for C++ interfaces.
*/
virtual ~AcceptsTelemetryIF() {
}
/**
* @brief This method returns the message queue id of the telemetry
* receiving message queue.
* @return The telemetry reception message queue id.
*/
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) = 0;
};
#endif /* ACCEPTSTELEMETRYIF_H_ */
#ifndef ACCEPTSTELEMETRYIF_H_
#define ACCEPTSTELEMETRYIF_H_
#include "../ipc/MessageQueueSenderIF.h"
/**
* @brief This interface is implemented by classes that are sinks for
* Telemetry.
* @details Any object receiving telemetry shall implement this interface
* and thus make the service id and the receiving message queue public.
*/
class AcceptsTelemetryIF {
public:
/**
* @brief The virtual destructor as it is mandatory for C++ interfaces.
*/
virtual ~AcceptsTelemetryIF() {
}
/**
* @brief This method returns the message queue id of the telemetry
* receiving message queue.
* @return The telemetry reception message queue id.
*/
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) = 0;
};
#endif /* ACCEPTSTELEMETRYIF_H_ */

View File

@ -1,15 +1,15 @@
#ifndef ACCEPTSVERIFICATIONMESSAGEIF_H_
#define ACCEPTSVERIFICATIONMESSAGEIF_H_
#include "../ipc/MessageQueueSenderIF.h"
class AcceptsVerifyMessageIF {
public:
virtual ~AcceptsVerifyMessageIF() {
}
virtual MessageQueueId_t getVerificationQueue() = 0;
};
#endif /* ACCEPTSVERIFICATIONMESSAGEIF_H_ */
#ifndef ACCEPTSVERIFICATIONMESSAGEIF_H_
#define ACCEPTSVERIFICATIONMESSAGEIF_H_
#include "../ipc/MessageQueueSenderIF.h"
class AcceptsVerifyMessageIF {
public:
virtual ~AcceptsVerifyMessageIF() {
}
virtual MessageQueueId_t getVerificationQueue() = 0;
};
#endif /* ACCEPTSVERIFICATIONMESSAGEIF_H_ */

View File

@ -1,427 +1,427 @@
#include "../tcdistribution/PUSDistributorIF.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../tmtcservices/CommandingServiceBase.h"
#include "../tmtcservices/TmTcMessage.h"
#include "../ipc/QueueFactory.h"
#include "../tmtcpacket/pus/TcPacketStored.h"
#include "../tmtcpacket/pus/TmPacketStored.h"
object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;
CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId,
uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, size_t queueDepth) :
SystemObject(setObjectId), apid(apid), service(service),
timeoutSeconds(commandTimeoutSeconds),
commandMap(numberOfParallelCommands) {
commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
}
void CommandingServiceBase::setPacketSource(object_id_t packetSource) {
this->packetSource = packetSource;
}
void CommandingServiceBase::setPacketDestination(
object_id_t packetDestination) {
this->packetDestination = packetDestination;
}
CommandingServiceBase::~CommandingServiceBase() {
QueueFactory::instance()->deleteMessageQueue(commandQueue);
QueueFactory::instance()->deleteMessageQueue(requestQueue);
}
ReturnValue_t CommandingServiceBase::performOperation(uint8_t opCode) {
handleCommandQueue();
handleRequestQueue();
checkTimeout();
doPeriodicOperation();
return RETURN_OK;
}
uint16_t CommandingServiceBase::getIdentifier() {
return service;
}
MessageQueueId_t CommandingServiceBase::getRequestQueue() {
return requestQueue->getId();
}
ReturnValue_t CommandingServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(packetDestination == objects::NO_OBJECT) {
packetDestination = defaultPacketDestination;
}
AcceptsTelemetryIF* packetForwarding =
objectManager->get<AcceptsTelemetryIF>(packetDestination);
if(packetSource == objects::NO_OBJECT) {
packetSource = defaultPacketSource;
}
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource);
if (packetForwarding == nullptr or distributor == nullptr) {
sif::error << "CommandingServiceBase::intialize: Packet source or "
"packet destination invalid!" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
distributor->registerService(this);
requestQueue->setDefaultDestination(
packetForwarding->getReportReceptionQueue());
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
TCStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
if (IPCStore == nullptr or TCStore == nullptr) {
sif::error << "CommandingServiceBase::intialize: IPC store or TC store "
"not initialized yet!" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
return RETURN_OK;
}
void CommandingServiceBase::handleCommandQueue() {
CommandMessage reply;
ReturnValue_t result = RETURN_FAILED;
for (result = commandQueue->receiveMessage(&reply); result == RETURN_OK;
result = commandQueue->receiveMessage(&reply)) {
handleCommandMessage(&reply);
}
}
void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
bool isStep = false;
CommandMessage nextCommand;
CommandMapIter iter = commandMap.find(reply->getSender());
// handle unrequested reply first
if (reply->getSender() == MessageQueueIF::NO_QUEUE or
iter == commandMap.end()) {
handleUnrequestedReply(reply);
return;
}
nextCommand.setCommand(CommandMessage::CMD_NONE);
// Implemented by child class, specifies what to do with reply.
ReturnValue_t result = handleReply(reply, iter->command, &iter->state,
&nextCommand, iter->objectId, &isStep);
/* If the child implementation does not implement special handling for
* rejected replies (RETURN_FAILED or INVALID_REPLY is returned), a
* failure verification will be generated with the reason as the
* return code and the initial command as failure parameter 1 */
if((reply->getCommand() == CommandMessage::REPLY_REJECTED) and
(result == RETURN_FAILED or result == INVALID_REPLY)) {
result = reply->getReplyRejectedReason();
failureParameter1 = iter->command;
}
switch (result) {
case EXECUTION_COMPLETE:
case RETURN_OK:
case NO_STEP_MESSAGE:
// handle result of reply handler implemented by developer.
handleReplyHandlerResult(result, iter, &nextCommand, reply, isStep);
break;
case INVALID_REPLY:
//might be just an unrequested reply at a bad moment
handleUnrequestedReply(reply);
break;
default:
if (isStep) {
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, ++iter->step, failureParameter1,
failureParameter2);
} else {
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, 0, failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(iter);
break;
}
}
void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
CommandMapIter iter, CommandMessage* nextCommand,
CommandMessage* reply, bool& isStep) {
iter->command = nextCommand->getCommand();
// In case a new command is to be sent immediately, this is performed here.
// If no new command is sent, only analyse reply result by initializing
// sendResult as RETURN_OK
ReturnValue_t sendResult = RETURN_OK;
if (nextCommand->getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(reply->getSender(),
nextCommand);
}
if (sendResult == RETURN_OK) {
if (isStep and result != NO_STEP_MESSAGE) {
verificationReporter.sendSuccessReport(
TC_VERIFY::PROGRESS_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, ++iter->step);
}
else {
verificationReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, 0);
checkAndExecuteFifo(iter);
}
}
else {
if (isStep) {
nextCommand->clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult,
++iter->step, failureParameter1, failureParameter2);
} else {
nextCommand->clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult, 0,
failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(iter);
}
}
void CommandingServiceBase::handleRequestQueue() {
TmTcMessage message;
ReturnValue_t result;
store_address_t address;
TcPacketStored packet;
MessageQueueId_t queue;
object_id_t objectId;
for (result = requestQueue->receiveMessage(&message); result == RETURN_OK;
result = requestQueue->receiveMessage(&message)) {
address = message.getStorageId();
packet.setStoreAddress(address);
if ((packet.getSubService() == 0)
or (isValidSubservice(packet.getSubService()) != RETURN_OK)) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, INVALID_SUBSERVICE);
continue;
}
result = getMessageQueueAndObject(packet.getSubService(),
packet.getApplicationData(), packet.getApplicationDataSize(),
&queue, &objectId);
if (result != HasReturnvaluesIF::RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, result);
continue;
}
//Is a command already active for the target object?
CommandMapIter iter;
iter = commandMap.find(queue);
if (iter != commandMap.end()) {
result = iter->fifo.insert(address);
if (result != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, OBJECT_BUSY);
}
} else {
CommandInfo newInfo; //Info will be set by startExecution if neccessary
newInfo.objectId = objectId;
result = commandMap.insert(queue, newInfo, &iter);
if (result != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, BUSY);
} else {
startExecution(&packet, iter);
}
}
}
}
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
const uint8_t* data, size_t dataLen, const uint8_t* headerData,
size_t headerSize) {
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, headerData, headerSize);
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++;
}
return result;
}
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
object_id_t objectId, const uint8_t *data, size_t dataLen) {
uint8_t buffer[sizeof(object_id_t)];
uint8_t* pBuffer = buffer;
size_t size = 0;
SerializeAdapter::serialize(&objectId, &pBuffer, &size,
sizeof(object_id_t), SerializeIF::Endianness::BIG);
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, buffer, size);
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++;
}
return result;
}
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
SerializeIF* content, SerializeIF* header) {
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, content, header);
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++;
}
return result;
}
void CommandingServiceBase::startExecution(TcPacketStored *storedPacket,
CommandMapIter iter) {
ReturnValue_t result = RETURN_OK;
CommandMessage command;
iter->subservice = storedPacket->getSubService();
result = prepareCommand(&command, iter->subservice,
storedPacket->getApplicationData(),
storedPacket->getApplicationDataSize(), &iter->state,
iter->objectId);
ReturnValue_t sendResult = RETURN_OK;
switch (result) {
case RETURN_OK:
if (command.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(iter.value->first,
&command);
}
if (sendResult == RETURN_OK) {
Clock::getUptime(&iter->uptimeOfStart);
iter->step = 0;
iter->subservice = storedPacket->getSubService();
iter->command = command.getCommand();
iter->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
iter->tcInfo.tcPacketId = storedPacket->getPacketId();
iter->tcInfo.tcSequenceControl =
storedPacket->getPacketSequenceControl();
acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket);
} else {
command.clearCommandMessage();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter);
}
break;
case EXECUTION_COMPLETE:
if (command.getCommand() != CommandMessage::CMD_NONE) {
//Fire-and-forget command.
sendResult = commandQueue->sendMessage(iter.value->first,
&command);
}
if (sendResult == RETURN_OK) {
verificationReporter.sendSuccessReport(TC_VERIFY::START_SUCCESS,
storedPacket);
acceptPacket(TC_VERIFY::COMPLETION_SUCCESS, storedPacket);
checkAndExecuteFifo(iter);
} else {
command.clearCommandMessage();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter);
}
break;
default:
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, result);
checkAndExecuteFifo(iter);
break;
}
}
void CommandingServiceBase::rejectPacket(uint8_t report_id,
TcPacketStored* packet, ReturnValue_t error_code) {
verificationReporter.sendFailureReport(report_id, packet, error_code);
packet->deletePacket();
}
void CommandingServiceBase::acceptPacket(uint8_t reportId,
TcPacketStored* packet) {
verificationReporter.sendSuccessReport(reportId, packet);
packet->deletePacket();
}
void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter iter) {
store_address_t address;
if (iter->fifo.retrieve(&address) != RETURN_OK) {
commandMap.erase(&iter);
} else {
TcPacketStored newPacket(address);
startExecution(&newPacket, iter);
}
}
void CommandingServiceBase::handleUnrequestedReply(CommandMessage* reply) {
reply->clearCommandMessage();
}
inline void CommandingServiceBase::doPeriodicOperation() {
}
MessageQueueId_t CommandingServiceBase::getCommandQueue() {
return commandQueue->getId();
}
void CommandingServiceBase::checkTimeout() {
uint32_t uptime;
Clock::getUptime(&uptime);
CommandMapIter iter;
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
if ((iter->uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
TIMEOUT);
checkAndExecuteFifo(iter);
}
}
}
void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) {
executingTask = task_;
}
#include "../tcdistribution/PUSDistributorIF.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../tmtcservices/CommandingServiceBase.h"
#include "../tmtcservices/TmTcMessage.h"
#include "../ipc/QueueFactory.h"
#include "../tmtcpacket/pus/TcPacketStored.h"
#include "../tmtcpacket/pus/TmPacketStored.h"
object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;
CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId,
uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, size_t queueDepth) :
SystemObject(setObjectId), apid(apid), service(service),
timeoutSeconds(commandTimeoutSeconds),
commandMap(numberOfParallelCommands) {
commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
}
void CommandingServiceBase::setPacketSource(object_id_t packetSource) {
this->packetSource = packetSource;
}
void CommandingServiceBase::setPacketDestination(
object_id_t packetDestination) {
this->packetDestination = packetDestination;
}
CommandingServiceBase::~CommandingServiceBase() {
QueueFactory::instance()->deleteMessageQueue(commandQueue);
QueueFactory::instance()->deleteMessageQueue(requestQueue);
}
ReturnValue_t CommandingServiceBase::performOperation(uint8_t opCode) {
handleCommandQueue();
handleRequestQueue();
checkTimeout();
doPeriodicOperation();
return RETURN_OK;
}
uint16_t CommandingServiceBase::getIdentifier() {
return service;
}
MessageQueueId_t CommandingServiceBase::getRequestQueue() {
return requestQueue->getId();
}
ReturnValue_t CommandingServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(packetDestination == objects::NO_OBJECT) {
packetDestination = defaultPacketDestination;
}
AcceptsTelemetryIF* packetForwarding =
objectManager->get<AcceptsTelemetryIF>(packetDestination);
if(packetSource == objects::NO_OBJECT) {
packetSource = defaultPacketSource;
}
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource);
if (packetForwarding == nullptr or distributor == nullptr) {
sif::error << "CommandingServiceBase::intialize: Packet source or "
"packet destination invalid!" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
distributor->registerService(this);
requestQueue->setDefaultDestination(
packetForwarding->getReportReceptionQueue());
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
TCStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
if (IPCStore == nullptr or TCStore == nullptr) {
sif::error << "CommandingServiceBase::intialize: IPC store or TC store "
"not initialized yet!" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
return RETURN_OK;
}
void CommandingServiceBase::handleCommandQueue() {
CommandMessage reply;
ReturnValue_t result = RETURN_FAILED;
for (result = commandQueue->receiveMessage(&reply); result == RETURN_OK;
result = commandQueue->receiveMessage(&reply)) {
handleCommandMessage(&reply);
}
}
void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
bool isStep = false;
CommandMessage nextCommand;
CommandMapIter iter = commandMap.find(reply->getSender());
// handle unrequested reply first
if (reply->getSender() == MessageQueueIF::NO_QUEUE or
iter == commandMap.end()) {
handleUnrequestedReply(reply);
return;
}
nextCommand.setCommand(CommandMessage::CMD_NONE);
// Implemented by child class, specifies what to do with reply.
ReturnValue_t result = handleReply(reply, iter->command, &iter->state,
&nextCommand, iter->objectId, &isStep);
/* If the child implementation does not implement special handling for
* rejected replies (RETURN_FAILED or INVALID_REPLY is returned), a
* failure verification will be generated with the reason as the
* return code and the initial command as failure parameter 1 */
if((reply->getCommand() == CommandMessage::REPLY_REJECTED) and
(result == RETURN_FAILED or result == INVALID_REPLY)) {
result = reply->getReplyRejectedReason();
failureParameter1 = iter->command;
}
switch (result) {
case EXECUTION_COMPLETE:
case RETURN_OK:
case NO_STEP_MESSAGE:
// handle result of reply handler implemented by developer.
handleReplyHandlerResult(result, iter, &nextCommand, reply, isStep);
break;
case INVALID_REPLY:
//might be just an unrequested reply at a bad moment
handleUnrequestedReply(reply);
break;
default:
if (isStep) {
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, ++iter->step, failureParameter1,
failureParameter2);
} else {
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, 0, failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(iter);
break;
}
}
void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
CommandMapIter iter, CommandMessage* nextCommand,
CommandMessage* reply, bool& isStep) {
iter->command = nextCommand->getCommand();
// In case a new command is to be sent immediately, this is performed here.
// If no new command is sent, only analyse reply result by initializing
// sendResult as RETURN_OK
ReturnValue_t sendResult = RETURN_OK;
if (nextCommand->getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(reply->getSender(),
nextCommand);
}
if (sendResult == RETURN_OK) {
if (isStep and result != NO_STEP_MESSAGE) {
verificationReporter.sendSuccessReport(
TC_VERIFY::PROGRESS_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, ++iter->step);
}
else {
verificationReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, 0);
checkAndExecuteFifo(iter);
}
}
else {
if (isStep) {
nextCommand->clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult,
++iter->step, failureParameter1, failureParameter2);
} else {
nextCommand->clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult, 0,
failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(iter);
}
}
void CommandingServiceBase::handleRequestQueue() {
TmTcMessage message;
ReturnValue_t result;
store_address_t address;
TcPacketStored packet;
MessageQueueId_t queue;
object_id_t objectId;
for (result = requestQueue->receiveMessage(&message); result == RETURN_OK;
result = requestQueue->receiveMessage(&message)) {
address = message.getStorageId();
packet.setStoreAddress(address);
if ((packet.getSubService() == 0)
or (isValidSubservice(packet.getSubService()) != RETURN_OK)) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, INVALID_SUBSERVICE);
continue;
}
result = getMessageQueueAndObject(packet.getSubService(),
packet.getApplicationData(), packet.getApplicationDataSize(),
&queue, &objectId);
if (result != HasReturnvaluesIF::RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, result);
continue;
}
//Is a command already active for the target object?
CommandMapIter iter;
iter = commandMap.find(queue);
if (iter != commandMap.end()) {
result = iter->fifo.insert(address);
if (result != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, OBJECT_BUSY);
}
} else {
CommandInfo newInfo; //Info will be set by startExecution if neccessary
newInfo.objectId = objectId;
result = commandMap.insert(queue, newInfo, &iter);
if (result != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, BUSY);
} else {
startExecution(&packet, iter);
}
}
}
}
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
const uint8_t* data, size_t dataLen, const uint8_t* headerData,
size_t headerSize) {
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, headerData, headerSize);
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++;
}
return result;
}
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
object_id_t objectId, const uint8_t *data, size_t dataLen) {
uint8_t buffer[sizeof(object_id_t)];
uint8_t* pBuffer = buffer;
size_t size = 0;
SerializeAdapter::serialize(&objectId, &pBuffer, &size,
sizeof(object_id_t), SerializeIF::Endianness::BIG);
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, buffer, size);
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++;
}
return result;
}
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
SerializeIF* content, SerializeIF* header) {
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, content, header);
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++;
}
return result;
}
void CommandingServiceBase::startExecution(TcPacketStored *storedPacket,
CommandMapIter iter) {
ReturnValue_t result = RETURN_OK;
CommandMessage command;
iter->subservice = storedPacket->getSubService();
result = prepareCommand(&command, iter->subservice,
storedPacket->getApplicationData(),
storedPacket->getApplicationDataSize(), &iter->state,
iter->objectId);
ReturnValue_t sendResult = RETURN_OK;
switch (result) {
case RETURN_OK:
if (command.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(iter.value->first,
&command);
}
if (sendResult == RETURN_OK) {
Clock::getUptime(&iter->uptimeOfStart);
iter->step = 0;
iter->subservice = storedPacket->getSubService();
iter->command = command.getCommand();
iter->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
iter->tcInfo.tcPacketId = storedPacket->getPacketId();
iter->tcInfo.tcSequenceControl =
storedPacket->getPacketSequenceControl();
acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket);
} else {
command.clearCommandMessage();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter);
}
break;
case EXECUTION_COMPLETE:
if (command.getCommand() != CommandMessage::CMD_NONE) {
//Fire-and-forget command.
sendResult = commandQueue->sendMessage(iter.value->first,
&command);
}
if (sendResult == RETURN_OK) {
verificationReporter.sendSuccessReport(TC_VERIFY::START_SUCCESS,
storedPacket);
acceptPacket(TC_VERIFY::COMPLETION_SUCCESS, storedPacket);
checkAndExecuteFifo(iter);
} else {
command.clearCommandMessage();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter);
}
break;
default:
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, result);
checkAndExecuteFifo(iter);
break;
}
}
void CommandingServiceBase::rejectPacket(uint8_t report_id,
TcPacketStored* packet, ReturnValue_t error_code) {
verificationReporter.sendFailureReport(report_id, packet, error_code);
packet->deletePacket();
}
void CommandingServiceBase::acceptPacket(uint8_t reportId,
TcPacketStored* packet) {
verificationReporter.sendSuccessReport(reportId, packet);
packet->deletePacket();
}
void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter iter) {
store_address_t address;
if (iter->fifo.retrieve(&address) != RETURN_OK) {
commandMap.erase(&iter);
} else {
TcPacketStored newPacket(address);
startExecution(&newPacket, iter);
}
}
void CommandingServiceBase::handleUnrequestedReply(CommandMessage* reply) {
reply->clearCommandMessage();
}
inline void CommandingServiceBase::doPeriodicOperation() {
}
MessageQueueId_t CommandingServiceBase::getCommandQueue() {
return commandQueue->getId();
}
void CommandingServiceBase::checkTimeout() {
uint32_t uptime;
Clock::getUptime(&uptime);
CommandMapIter iter;
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
if ((iter->uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
TIMEOUT);
checkAndExecuteFifo(iter);
}
}
}
void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) {
executingTask = task_;
}

View File

@ -1,348 +1,348 @@
#ifndef FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#define FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#include "../objectmanager/SystemObject.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../tmtcservices/VerificationReporter.h"
#include "../ipc/CommandMessage.h"
#include "../container/FixedMap.h"
#include "../container/FIFO.h"
#include "../serialize/SerializeIF.h"
class TcPacketStored;
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @brief This class is the basis for all PUS Services, which have to
* relay Telecommands to software bus.
*
* It manages Telecommand reception and the generation of Verification Reports
* similar to PusServiceBase. This class is used if a telecommand can't be
* handled immediately and must be relayed to the internal software bus.
* - isValidSubservice
* - getMessageQueueAndObject
* - prepareCommand
* - handleReply
* @author gaisser
* @ingroup pus_services
*/
class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF,
public ExecutableObjectIF,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2);
static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3);
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(4);
static const ReturnValue_t INVALID_TC = MAKE_RETURN_CODE(5);
static const ReturnValue_t INVALID_OBJECT = MAKE_RETURN_CODE(6);
static const ReturnValue_t INVALID_REPLY = MAKE_RETURN_CODE(7);
/**
* Class constructor. Initializes two important MessageQueues:
* commandQueue for command reception and requestQueue for device reception
* @param setObjectId
* @param apid
* @param service
* @param numberOfParallelCommands
* @param commandTimeout_seconds
* @param setPacketSource
* @param setPacketDestination
* @param queueDepth
*/
CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, size_t queueDepth = 20);
virtual ~CommandingServiceBase();
/**
* This setter can be used to set the packet source individually instead
* of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time!
* @param packetSource
*/
void setPacketSource(object_id_t packetSource);
/**
* This setter can be used to set the packet destination individually
* instead of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time!
* @param packetDestination
*/
void setPacketDestination(object_id_t packetDestination);
/***
* This is the periodically called function.
* Handle request queue for external commands.
* Handle command Queue for internal commands.
* @param opCode is unused here at the moment
* @return RETURN_OK
*/
virtual ReturnValue_t performOperation(uint8_t opCode) override;
virtual uint16_t getIdentifier();
/**
* Returns the requestQueue MessageQueueId_t
*
* The requestQueue is the queue for external commands (TC)
*
* @return requestQueue messageQueueId_t
*/
virtual MessageQueueId_t getRequestQueue();
/**
* Returns the commandQueue MessageQueueId_t
*
* Remember the CommandQueue is the queue for internal communication
* @return commandQueue messageQueueId_t
*/
virtual MessageQueueId_t getCommandQueue();
virtual ReturnValue_t initialize() override;
/**
* Implementation of ExecutableObjectIF function
*
* Used to setup the reference of the task, that executes this component
* @param task Pointer to the taskIF of this task
*/
virtual void setTaskIF(PeriodicTaskIF* task) override;
protected:
/**
* Check the target subservice
* @param subservice[in]
* @return
* -@c RETURN_OK Subservice valid, continue message handling
* -@c INVALID_SUBSERVICE if service is not known, rejects packet.
*/
virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0;
/**
* Once a TC Request is valid, the existence of the destination and its
* target interface is checked and retrieved. The target message queue ID
* can then be acquired by using the target interface.
* @param subservice
* @param tcData Application Data of TC Packet
* @param tcDataLen
* @param id MessageQueue ID is stored here
* @param objectId Object ID is extracted and stored here
* @return
* - @c RETURN_OK Cotinue message handling
* - @c RETURN_FAILED Reject the packet and generates a start failure
* verification
*/
virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice,
const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id,
object_id_t *objectId) = 0;
/**
* After the Message Queue and Object ID are determined, the command is
* prepared by using an implementation specific CommandMessage type
* which is sent to the target object. It contains all necessary information
* for the device to execute telecommands.
* @param message [out] message which can be set and is sent to the object
* @param subservice Subservice of the current communication
* @param tcData Application data of command
* @param tcDataLen Application data length
* @param state [out/in] Setable state of the communication.
* communication
* @param objectId Target object ID
* @return
* - @c RETURN_OK to generate a verification start message
* - @c EXECUTION_COMPELTE Fire-and-forget command. Generate a completion
* verification message.
* - @c Anything else rejects the packets and generates a start failure
* verification.
*/
virtual ReturnValue_t prepareCommand(CommandMessage* message,
uint8_t subservice, const uint8_t *tcData, size_t tcDataLen,
uint32_t *state, object_id_t objectId) = 0;
/**
* This function is implemented by child services to specify how replies
* to a command from another software component are handled.
* @param reply
* This is the reply in form of a generic read-only command message.
* @param previousCommand
* Command_t of related command
* @param state [out/in]
* Additional parameter which can be used to pass state information.
* State of the communication
* @param optionalNextCommand [out]
* An optional next command which can be set in this function
* @param objectId Source object ID
* @param isStep Flag value to mark steps of command execution
* @return
* - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to
* generate TC verification success
* - @c INVALID_REPLY Calls handleUnrequestedReply
* - Anything else triggers a TC verification failure. If RETURN_FAILED or
* INVALID_REPLY is returned and the command ID is
* CommandMessage::REPLY_REJECTED, a failure verification message with
* the reason as the error parameter and the initial command as
* failure parameter 1 is generated.
*/
virtual ReturnValue_t handleReply(const CommandMessage* reply,
Command_t previousCommand, uint32_t *state,
CommandMessage* optionalNextCommand, object_id_t objectId,
bool *isStep) = 0;
/**
* This function can be overidden to handle unrequested reply,
* when the reply sender ID is unknown or is not found is the command map.
* The default implementation will clear the command message and all
* its contents.
* @param reply
* Reply which is non-const so the default implementation can clear the
* message.
*/
virtual void handleUnrequestedReply(CommandMessage* reply);
virtual void doPeriodicOperation();
struct CommandInfo {
struct tcInfo {
uint8_t ackFlags;
uint16_t tcPacketId;
uint16_t tcSequenceControl;
} tcInfo;
uint32_t uptimeOfStart;
uint8_t step;
uint8_t subservice;
uint32_t state;
Command_t command;
object_id_t objectId;
FIFO<store_address_t, 3> fifo;
};
using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator;
const uint16_t apid;
const uint8_t service;
const uint16_t timeoutSeconds;
uint8_t tmPacketCounter = 0;
StorageManagerIF *IPCStore = nullptr;
StorageManagerIF *TCStore = nullptr;
MessageQueueIF* commandQueue = nullptr;
MessageQueueIF* requestQueue = nullptr;
VerificationReporter verificationReporter;
FixedMap<MessageQueueId_t, CommandInfo> commandMap;
/* May be set be children to return a more precise failure condition. */
uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0;
static object_id_t defaultPacketSource;
object_id_t packetSource = objects::NO_OBJECT;
static object_id_t defaultPacketDestination;
object_id_t packetDestination = objects::NO_OBJECT;
/**
* Pointer to the task which executes this component,
* is invalid before setTaskIF was called.
*/
PeriodicTaskIF* executingTask = nullptr;
/**
* @brief Send TM data from pointer to data.
* If a header is supplied it is added before data
* @param subservice Number of subservice
* @param data Pointer to the data in the Packet
* @param dataLen Lenght of data in the Packet
* @param headerData HeaderData will be placed before data
* @param headerSize Size of HeaderData
*/
ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t *data,
size_t dataLen, const uint8_t* headerData = nullptr,
size_t headerSize = 0);
/**
* @brief To send TM packets of objects that still need to be serialized
* and consist of an object ID with appended data.
* @param subservice Number of subservice
* @param objectId ObjectId is placed before data
* @param data Data to append to the packet
* @param dataLen Length of Data
*/
ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId,
const uint8_t *data, size_t dataLen);
/**
* @brief To send packets which are contained inside a class implementing
* SerializeIF.
* @param subservice Number of subservice
* @param content This is a pointer to the serialized packet
* @param header Serialize IF header which will be placed before content
*/
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = nullptr);
void checkAndExecuteFifo(CommandMapIter iter);
private:
/**
* This method handles internal execution of a command,
* once it has been started by @sa{startExecution()} in the request
* queue handler.
* It handles replies generated by the devices and relayed by the specific
* service implementation. This means that it determines further course of
* action depending on the return values specified in the service
* implementation.
* This includes the generation of TC verification messages. Note that
* the static framework object ID @c VerificationReporter::messageReceiver
* needs to be set.
* - TM[1,5] Step Successs
* - TM[1,6] Step Failure
* - TM[1,7] Completion Success
* - TM[1,8] Completion Failure
*/
void handleCommandQueue();
/**
* @brief Handler function for request queue
* @details
* Sequence of request queue handling:
* isValidSubservice -> getMessageQueueAndObject -> startExecution
* Generates a Start Success Reports TM[1,3] in subfunction
* @sa{startExecution()} or a Start Failure Report TM[1,4] by using the
* TC Verification Service.
*/
void handleRequestQueue();
void rejectPacket(uint8_t reportId, TcPacketStored* packet,
ReturnValue_t errorCode);
void acceptPacket(uint8_t reportId, TcPacketStored* packet);
void startExecution(TcPacketStored *storedPacket, CommandMapIter iter);
void handleCommandMessage(CommandMessage* reply);
void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter,
CommandMessage* nextCommand, CommandMessage* reply, bool& isStep);
void checkTimeout();
};
#endif /* COMMANDINGSERVICEBASE_H_ */
#ifndef FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#define FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#include "../objectmanager/SystemObject.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../tmtcservices/VerificationReporter.h"
#include "../ipc/CommandMessage.h"
#include "../container/FixedMap.h"
#include "../container/FIFO.h"
#include "../serialize/SerializeIF.h"
class TcPacketStored;
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @brief This class is the basis for all PUS Services, which have to
* relay Telecommands to software bus.
*
* It manages Telecommand reception and the generation of Verification Reports
* similar to PusServiceBase. This class is used if a telecommand can't be
* handled immediately and must be relayed to the internal software bus.
* - isValidSubservice
* - getMessageQueueAndObject
* - prepareCommand
* - handleReply
* @author gaisser
* @ingroup pus_services
*/
class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF,
public ExecutableObjectIF,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2);
static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3);
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(4);
static const ReturnValue_t INVALID_TC = MAKE_RETURN_CODE(5);
static const ReturnValue_t INVALID_OBJECT = MAKE_RETURN_CODE(6);
static const ReturnValue_t INVALID_REPLY = MAKE_RETURN_CODE(7);
/**
* Class constructor. Initializes two important MessageQueues:
* commandQueue for command reception and requestQueue for device reception
* @param setObjectId
* @param apid
* @param service
* @param numberOfParallelCommands
* @param commandTimeout_seconds
* @param setPacketSource
* @param setPacketDestination
* @param queueDepth
*/
CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, size_t queueDepth = 20);
virtual ~CommandingServiceBase();
/**
* This setter can be used to set the packet source individually instead
* of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time!
* @param packetSource
*/
void setPacketSource(object_id_t packetSource);
/**
* This setter can be used to set the packet destination individually
* instead of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time!
* @param packetDestination
*/
void setPacketDestination(object_id_t packetDestination);
/***
* This is the periodically called function.
* Handle request queue for external commands.
* Handle command Queue for internal commands.
* @param opCode is unused here at the moment
* @return RETURN_OK
*/
virtual ReturnValue_t performOperation(uint8_t opCode) override;
virtual uint16_t getIdentifier();
/**
* Returns the requestQueue MessageQueueId_t
*
* The requestQueue is the queue for external commands (TC)
*
* @return requestQueue messageQueueId_t
*/
virtual MessageQueueId_t getRequestQueue();
/**
* Returns the commandQueue MessageQueueId_t
*
* Remember the CommandQueue is the queue for internal communication
* @return commandQueue messageQueueId_t
*/
virtual MessageQueueId_t getCommandQueue();
virtual ReturnValue_t initialize() override;
/**
* Implementation of ExecutableObjectIF function
*
* Used to setup the reference of the task, that executes this component
* @param task Pointer to the taskIF of this task
*/
virtual void setTaskIF(PeriodicTaskIF* task) override;
protected:
/**
* Check the target subservice
* @param subservice[in]
* @return
* -@c RETURN_OK Subservice valid, continue message handling
* -@c INVALID_SUBSERVICE if service is not known, rejects packet.
*/
virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0;
/**
* Once a TC Request is valid, the existence of the destination and its
* target interface is checked and retrieved. The target message queue ID
* can then be acquired by using the target interface.
* @param subservice
* @param tcData Application Data of TC Packet
* @param tcDataLen
* @param id MessageQueue ID is stored here
* @param objectId Object ID is extracted and stored here
* @return
* - @c RETURN_OK Cotinue message handling
* - @c RETURN_FAILED Reject the packet and generates a start failure
* verification
*/
virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice,
const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id,
object_id_t *objectId) = 0;
/**
* After the Message Queue and Object ID are determined, the command is
* prepared by using an implementation specific CommandMessage type
* which is sent to the target object. It contains all necessary information
* for the device to execute telecommands.
* @param message [out] message which can be set and is sent to the object
* @param subservice Subservice of the current communication
* @param tcData Application data of command
* @param tcDataLen Application data length
* @param state [out/in] Setable state of the communication.
* communication
* @param objectId Target object ID
* @return
* - @c RETURN_OK to generate a verification start message
* - @c EXECUTION_COMPELTE Fire-and-forget command. Generate a completion
* verification message.
* - @c Anything else rejects the packets and generates a start failure
* verification.
*/
virtual ReturnValue_t prepareCommand(CommandMessage* message,
uint8_t subservice, const uint8_t *tcData, size_t tcDataLen,
uint32_t *state, object_id_t objectId) = 0;
/**
* This function is implemented by child services to specify how replies
* to a command from another software component are handled.
* @param reply
* This is the reply in form of a generic read-only command message.
* @param previousCommand
* Command_t of related command
* @param state [out/in]
* Additional parameter which can be used to pass state information.
* State of the communication
* @param optionalNextCommand [out]
* An optional next command which can be set in this function
* @param objectId Source object ID
* @param isStep Flag value to mark steps of command execution
* @return
* - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to
* generate TC verification success
* - @c INVALID_REPLY Calls handleUnrequestedReply
* - Anything else triggers a TC verification failure. If RETURN_FAILED or
* INVALID_REPLY is returned and the command ID is
* CommandMessage::REPLY_REJECTED, a failure verification message with
* the reason as the error parameter and the initial command as
* failure parameter 1 is generated.
*/
virtual ReturnValue_t handleReply(const CommandMessage* reply,
Command_t previousCommand, uint32_t *state,
CommandMessage* optionalNextCommand, object_id_t objectId,
bool *isStep) = 0;
/**
* This function can be overidden to handle unrequested reply,
* when the reply sender ID is unknown or is not found is the command map.
* The default implementation will clear the command message and all
* its contents.
* @param reply
* Reply which is non-const so the default implementation can clear the
* message.
*/
virtual void handleUnrequestedReply(CommandMessage* reply);
virtual void doPeriodicOperation();
struct CommandInfo {
struct tcInfo {
uint8_t ackFlags;
uint16_t tcPacketId;
uint16_t tcSequenceControl;
} tcInfo;
uint32_t uptimeOfStart;
uint8_t step;
uint8_t subservice;
uint32_t state;
Command_t command;
object_id_t objectId;
FIFO<store_address_t, 3> fifo;
};
using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator;
const uint16_t apid;
const uint8_t service;
const uint16_t timeoutSeconds;
uint8_t tmPacketCounter = 0;
StorageManagerIF *IPCStore = nullptr;
StorageManagerIF *TCStore = nullptr;
MessageQueueIF* commandQueue = nullptr;
MessageQueueIF* requestQueue = nullptr;
VerificationReporter verificationReporter;
FixedMap<MessageQueueId_t, CommandInfo> commandMap;
/* May be set be children to return a more precise failure condition. */
uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0;
static object_id_t defaultPacketSource;
object_id_t packetSource = objects::NO_OBJECT;
static object_id_t defaultPacketDestination;
object_id_t packetDestination = objects::NO_OBJECT;
/**
* Pointer to the task which executes this component,
* is invalid before setTaskIF was called.
*/
PeriodicTaskIF* executingTask = nullptr;
/**
* @brief Send TM data from pointer to data.
* If a header is supplied it is added before data
* @param subservice Number of subservice
* @param data Pointer to the data in the Packet
* @param dataLen Lenght of data in the Packet
* @param headerData HeaderData will be placed before data
* @param headerSize Size of HeaderData
*/
ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t *data,
size_t dataLen, const uint8_t* headerData = nullptr,
size_t headerSize = 0);
/**
* @brief To send TM packets of objects that still need to be serialized
* and consist of an object ID with appended data.
* @param subservice Number of subservice
* @param objectId ObjectId is placed before data
* @param data Data to append to the packet
* @param dataLen Length of Data
*/
ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId,
const uint8_t *data, size_t dataLen);
/**
* @brief To send packets which are contained inside a class implementing
* SerializeIF.
* @param subservice Number of subservice
* @param content This is a pointer to the serialized packet
* @param header Serialize IF header which will be placed before content
*/
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = nullptr);
void checkAndExecuteFifo(CommandMapIter iter);
private:
/**
* This method handles internal execution of a command,
* once it has been started by @sa{startExecution()} in the request
* queue handler.
* It handles replies generated by the devices and relayed by the specific
* service implementation. This means that it determines further course of
* action depending on the return values specified in the service
* implementation.
* This includes the generation of TC verification messages. Note that
* the static framework object ID @c VerificationReporter::messageReceiver
* needs to be set.
* - TM[1,5] Step Successs
* - TM[1,6] Step Failure
* - TM[1,7] Completion Success
* - TM[1,8] Completion Failure
*/
void handleCommandQueue();
/**
* @brief Handler function for request queue
* @details
* Sequence of request queue handling:
* isValidSubservice -> getMessageQueueAndObject -> startExecution
* Generates a Start Success Reports TM[1,3] in subfunction
* @sa{startExecution()} or a Start Failure Report TM[1,4] by using the
* TC Verification Service.
*/
void handleRequestQueue();
void rejectPacket(uint8_t reportId, TcPacketStored* packet,
ReturnValue_t errorCode);
void acceptPacket(uint8_t reportId, TcPacketStored* packet);
void startExecution(TcPacketStored *storedPacket, CommandMapIter iter);
void handleCommandMessage(CommandMessage* reply);
void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter,
CommandMessage* nextCommand, CommandMessage* reply, bool& isStep);
void checkTimeout();
};
#endif /* COMMANDINGSERVICEBASE_H_ */

View File

@ -1,123 +1,123 @@
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../tcdistribution/PUSDistributorIF.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../tmtcservices/PusServiceBase.h"
#include "../tmtcservices/PusVerificationReport.h"
#include "../tmtcservices/TmTcMessage.h"
#include "../ipc/QueueFactory.h"
object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0;
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId) :
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) {
requestQueue = QueueFactory::instance()->
createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
}
PusServiceBase::~PusServiceBase() {
QueueFactory::instance()->deleteMessageQueue(requestQueue);
}
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
handleRequestQueue();
ReturnValue_t result = this->performService();
if (result != RETURN_OK) {
sif::error << "PusService " << (uint16_t) this->serviceId
<< ": performService returned with " << (int16_t) result
<< std::endl;
return RETURN_FAILED;
}
return RETURN_OK;
}
void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) {
this->taskHandle = taskHandle;
}
void PusServiceBase::handleRequestQueue() {
TmTcMessage message;
ReturnValue_t result = RETURN_FAILED;
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
// if(status != MessageQueueIF::EMPTY) {
// sif::debug << "PusServiceBase::performOperation: Receiving from "
// << "MQ ID: " << std::hex << "0x" << std::setw(8)
// << std::setfill('0') << this->requestQueue->getId()
// << std::dec << " returned: " << status << std::setfill(' ')
// << std::endl;
// }
if (status == RETURN_OK) {
this->currentPacket.setStoreAddress(message.getStorageId());
//info << "Service " << (uint16_t) this->serviceId <<
// ": new packet!" << std::endl;
result = this->handleRequest(currentPacket.getSubService());
// debug << "Service " << (uint16_t)this->serviceId <<
// ": handleRequest returned: " << (int)return_code << std::endl;
if (result == RETURN_OK) {
this->verifyReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
}
else {
this->verifyReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
result, 0, errorParameter1, errorParameter2);
}
this->currentPacket.deletePacket();
errorParameter1 = 0;
errorParameter2 = 0;
}
else if (status == MessageQueueIF::EMPTY) {
status = RETURN_OK;
// debug << "PusService " << (uint16_t)this->serviceId <<
// ": no new packet." << std::endl;
break;
}
else {
sif::error << "PusServiceBase::performOperation: Service "
<< this->serviceId << ": Error receiving packet. Code: "
<< std::hex << status << std::dec << std::endl;
}
}
}
uint16_t PusServiceBase::getIdentifier() {
return this->serviceId;
}
MessageQueueId_t PusServiceBase::getRequestQueue() {
return this->requestQueue->getId();
}
ReturnValue_t PusServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
AcceptsTelemetryIF* destService = objectManager->get<AcceptsTelemetryIF>(
packetDestination);
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource);
if (destService == nullptr or distributor == nullptr) {
sif::error << "PusServiceBase::PusServiceBase: Service "
<< this->serviceId << ": Configuration error. Make sure "
<< "packetSource and packetDestination are defined correctly"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
this->requestQueue->setDefaultDestination(
destService->getReportReceptionQueue());
distributor->registerService(this);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PusServiceBase::initializeAfterTaskCreation() {
// If task parameters, for example task frequency are required, this
// function should be overriden and the system object task IF can
// be used to get those parameters.
return HasReturnvaluesIF::RETURN_OK;
}
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../tcdistribution/PUSDistributorIF.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../tmtcservices/PusServiceBase.h"
#include "../tmtcservices/PusVerificationReport.h"
#include "../tmtcservices/TmTcMessage.h"
#include "../ipc/QueueFactory.h"
object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0;
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId) :
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) {
requestQueue = QueueFactory::instance()->
createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
}
PusServiceBase::~PusServiceBase() {
QueueFactory::instance()->deleteMessageQueue(requestQueue);
}
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
handleRequestQueue();
ReturnValue_t result = this->performService();
if (result != RETURN_OK) {
sif::error << "PusService " << (uint16_t) this->serviceId
<< ": performService returned with " << (int16_t) result
<< std::endl;
return RETURN_FAILED;
}
return RETURN_OK;
}
void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) {
this->taskHandle = taskHandle;
}
void PusServiceBase::handleRequestQueue() {
TmTcMessage message;
ReturnValue_t result = RETURN_FAILED;
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
// if(status != MessageQueueIF::EMPTY) {
// sif::debug << "PusServiceBase::performOperation: Receiving from "
// << "MQ ID: " << std::hex << "0x" << std::setw(8)
// << std::setfill('0') << this->requestQueue->getId()
// << std::dec << " returned: " << status << std::setfill(' ')
// << std::endl;
// }
if (status == RETURN_OK) {
this->currentPacket.setStoreAddress(message.getStorageId());
//info << "Service " << (uint16_t) this->serviceId <<
// ": new packet!" << std::endl;
result = this->handleRequest(currentPacket.getSubService());
// debug << "Service " << (uint16_t)this->serviceId <<
// ": handleRequest returned: " << (int)return_code << std::endl;
if (result == RETURN_OK) {
this->verifyReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
}
else {
this->verifyReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
result, 0, errorParameter1, errorParameter2);
}
this->currentPacket.deletePacket();
errorParameter1 = 0;
errorParameter2 = 0;
}
else if (status == MessageQueueIF::EMPTY) {
status = RETURN_OK;
// debug << "PusService " << (uint16_t)this->serviceId <<
// ": no new packet." << std::endl;
break;
}
else {
sif::error << "PusServiceBase::performOperation: Service "
<< this->serviceId << ": Error receiving packet. Code: "
<< std::hex << status << std::dec << std::endl;
}
}
}
uint16_t PusServiceBase::getIdentifier() {
return this->serviceId;
}
MessageQueueId_t PusServiceBase::getRequestQueue() {
return this->requestQueue->getId();
}
ReturnValue_t PusServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
AcceptsTelemetryIF* destService = objectManager->get<AcceptsTelemetryIF>(
packetDestination);
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource);
if (destService == nullptr or distributor == nullptr) {
sif::error << "PusServiceBase::PusServiceBase: Service "
<< this->serviceId << ": Configuration error. Make sure "
<< "packetSource and packetDestination are defined correctly"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
this->requestQueue->setDefaultDestination(
destService->getReportReceptionQueue());
distributor->registerService(this);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PusServiceBase::initializeAfterTaskCreation() {
// If task parameters, for example task frequency are required, this
// function should be overriden and the system object task IF can
// be used to get those parameters.
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,159 +1,159 @@
#ifndef FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
#define FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
#include "../objectmanager/ObjectManagerIF.h"
#include "../objectmanager/SystemObject.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../tmtcpacket/pus/TcPacketStored.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../tmtcservices/VerificationCodes.h"
#include "../tmtcservices/VerificationReporter.h"
#include "../ipc/MessageQueueIF.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @defgroup pus_services PUS Service Framework
* These group contains all implementations of PUS Services in the OBSW.
* Most of the Services are directly taken from the ECSS PUS Standard.
*/
/**
* @brief This class is the basis for all PUS Services,
* which can immediately process Telecommand Packets.
* @details
* It manages Telecommand reception and the generation of Verification Reports.
* Every class that inherits from this abstract class has to implement
* handleRequest and performService. Services that are created with this
* Base class have to handle any kind of request immediately on reception.
* All PUS Services are System Objects, so an Object ID needs to be specified
* on construction.
* @ingroup pus_services
*/
class PusServiceBase : public ExecutableObjectIF,
public AcceptsTelecommandsIF,
public SystemObject,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* @brief The passed values are set, but inter-object initialization is
* done in the initialize method.
* @param setObjectId
* The system object identifier of this Service instance.
* @param setApid
* The APID the Service is instantiated for.
* @param setServiceId
* The Service Identifier as specified in ECSS PUS.
*/
PusServiceBase( object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId);
/**
* The destructor is empty.
*/
virtual ~PusServiceBase();
/**
* @brief The handleRequest method shall handle any kind of Telecommand
* Request immediately.
* @details
* Implemetations can take the Telecommand in currentPacket and perform
* any kind of operation.
* They may send additional "Start Success (1,3)" messages with the
* verifyReporter, but Completion Success or Failure Reports are generated
* automatically after execution of this method.
*
* If a Telecommand can not be executed within one call cycle,
* this Base class is not the right parent.
*
* The child class may add additional error information by setting
* #errorParameters which aren attached to the generated verification
* message.
*
* Subservice checking should be implemented in this method.
*
* @return The returned status_code is directly taken as main error code
* in the Verification Report.
* On success, RETURN_OK shall be returned.
*/
virtual ReturnValue_t handleRequest(uint8_t subservice) = 0;
/**
* In performService, implementations can handle periodic,
* non-TC-triggered activities.
* The performService method is always called.
* @return Currently, everything other that RETURN_OK only triggers
* diagnostic output.
*/
virtual ReturnValue_t performService() = 0;
/**
* This method implements the typical activity of a simple PUS Service.
* It checks for new requests, and, if found, calls handleRequest, sends
* completion verification messages and deletes
* the TC requests afterwards.
* performService is always executed afterwards.
* @return @c RETURN_OK if the periodic performService was successful.
* @c RETURN_FAILED else.
*/
ReturnValue_t performOperation(uint8_t opCode) override;
virtual uint16_t getIdentifier() override;
MessageQueueId_t getRequestQueue() override;
virtual ReturnValue_t initialize() override;
virtual void setTaskIF(PeriodicTaskIF* taskHandle) override;
virtual ReturnValue_t initializeAfterTaskCreation() override;
protected:
/**
* @brief Handle to the underlying task
* @details
* Will be set by setTaskIF(), which is called on task creation.
*/
PeriodicTaskIF* taskHandle = nullptr;
/**
* The APID of this instance of the Service.
*/
uint16_t apid;
/**
* The Service Identifier.
*/
uint8_t serviceId;
/**
* One of two error parameters for additional error information.
*/
uint32_t errorParameter1 = 0;
/**
* One of two error parameters for additional error information.
*/
uint32_t errorParameter2 = 0;
/**
* This is a complete instance of the telecommand reception queue
* of the class. It is initialized on construction of the class.
*/
MessageQueueIF* requestQueue = nullptr;
/**
* An instance of the VerificationReporter class, that simplifies
* sending any kind of verification message to the TC Verification Service.
*/
VerificationReporter verifyReporter;
/**
* The current Telecommand to be processed.
* It is deleted after handleRequest was executed.
*/
TcPacketStored currentPacket;
static object_id_t packetSource;
static object_id_t packetDestination;
private:
/**
* This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one
* #handleRequest call.
*/
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
void handleRequestQueue();
};
#endif /* PUSSERVICEBASE_H_ */
#ifndef FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
#define FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
#include "../objectmanager/ObjectManagerIF.h"
#include "../objectmanager/SystemObject.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../tmtcpacket/pus/TcPacketStored.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../tmtcservices/VerificationCodes.h"
#include "../tmtcservices/VerificationReporter.h"
#include "../ipc/MessageQueueIF.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @defgroup pus_services PUS Service Framework
* These group contains all implementations of PUS Services in the OBSW.
* Most of the Services are directly taken from the ECSS PUS Standard.
*/
/**
* @brief This class is the basis for all PUS Services,
* which can immediately process Telecommand Packets.
* @details
* It manages Telecommand reception and the generation of Verification Reports.
* Every class that inherits from this abstract class has to implement
* handleRequest and performService. Services that are created with this
* Base class have to handle any kind of request immediately on reception.
* All PUS Services are System Objects, so an Object ID needs to be specified
* on construction.
* @ingroup pus_services
*/
class PusServiceBase : public ExecutableObjectIF,
public AcceptsTelecommandsIF,
public SystemObject,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* @brief The passed values are set, but inter-object initialization is
* done in the initialize method.
* @param setObjectId
* The system object identifier of this Service instance.
* @param setApid
* The APID the Service is instantiated for.
* @param setServiceId
* The Service Identifier as specified in ECSS PUS.
*/
PusServiceBase( object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId);
/**
* The destructor is empty.
*/
virtual ~PusServiceBase();
/**
* @brief The handleRequest method shall handle any kind of Telecommand
* Request immediately.
* @details
* Implemetations can take the Telecommand in currentPacket and perform
* any kind of operation.
* They may send additional "Start Success (1,3)" messages with the
* verifyReporter, but Completion Success or Failure Reports are generated
* automatically after execution of this method.
*
* If a Telecommand can not be executed within one call cycle,
* this Base class is not the right parent.
*
* The child class may add additional error information by setting
* #errorParameters which aren attached to the generated verification
* message.
*
* Subservice checking should be implemented in this method.
*
* @return The returned status_code is directly taken as main error code
* in the Verification Report.
* On success, RETURN_OK shall be returned.
*/
virtual ReturnValue_t handleRequest(uint8_t subservice) = 0;
/**
* In performService, implementations can handle periodic,
* non-TC-triggered activities.
* The performService method is always called.
* @return Currently, everything other that RETURN_OK only triggers
* diagnostic output.
*/
virtual ReturnValue_t performService() = 0;
/**
* This method implements the typical activity of a simple PUS Service.
* It checks for new requests, and, if found, calls handleRequest, sends
* completion verification messages and deletes
* the TC requests afterwards.
* performService is always executed afterwards.
* @return @c RETURN_OK if the periodic performService was successful.
* @c RETURN_FAILED else.
*/
ReturnValue_t performOperation(uint8_t opCode) override;
virtual uint16_t getIdentifier() override;
MessageQueueId_t getRequestQueue() override;
virtual ReturnValue_t initialize() override;
virtual void setTaskIF(PeriodicTaskIF* taskHandle) override;
virtual ReturnValue_t initializeAfterTaskCreation() override;
protected:
/**
* @brief Handle to the underlying task
* @details
* Will be set by setTaskIF(), which is called on task creation.
*/
PeriodicTaskIF* taskHandle = nullptr;
/**
* The APID of this instance of the Service.
*/
uint16_t apid;
/**
* The Service Identifier.
*/
uint8_t serviceId;
/**
* One of two error parameters for additional error information.
*/
uint32_t errorParameter1 = 0;
/**
* One of two error parameters for additional error information.
*/
uint32_t errorParameter2 = 0;
/**
* This is a complete instance of the telecommand reception queue
* of the class. It is initialized on construction of the class.
*/
MessageQueueIF* requestQueue = nullptr;
/**
* An instance of the VerificationReporter class, that simplifies
* sending any kind of verification message to the TC Verification Service.
*/
VerificationReporter verifyReporter;
/**
* The current Telecommand to be processed.
* It is deleted after handleRequest was executed.
*/
TcPacketStored currentPacket;
static object_id_t packetSource;
static object_id_t packetDestination;
private:
/**
* This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one
* #handleRequest call.
*/
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
void handleRequestQueue();
};
#endif /* PUSSERVICEBASE_H_ */

View File

@ -1,163 +1,163 @@
#include "../serialize/SerializeAdapter.h"
#include "../tmtcservices/PusVerificationReport.h"
PusVerificationMessage::PusVerificationMessage() {
}
//PusVerificationMessage::PusVerificationMessage(uint8_t set_report_id,
// TcPacketBase* current_packet, ReturnValue_t set_error_code,
// uint8_t set_step, uint32_t parameter1, uint32_t parameter2) {
// uint8_t ackFlags = current_packet->getAcknowledgeFlags();
// uint16_t tcPacketId = current_packet->getPacketId();
// uint16_t tcSequenceControl = current_packet->getPacketSequenceControl();
// uint8_t* data = this->getBuffer();
// data[messageSize] = set_report_id;
// messageSize += sizeof(set_report_id);
// data[messageSize] = ackFlags;
// messageSize += sizeof(ackFlags);
// memcpy(&data[messageSize], &tcPacketId, sizeof(tcPacketId));
// messageSize += sizeof(tcPacketId);
// memcpy(&data[messageSize], &tcSequenceControl, sizeof(tcSequenceControl));
// messageSize += sizeof(tcSequenceControl);
// data[messageSize] = set_step;
// messageSize += sizeof(set_step);
// memcpy(&data[messageSize], &set_error_code, sizeof(set_error_code));
// messageSize += sizeof(set_error_code);
// memcpy(&data[messageSize], &parameter1, sizeof(parameter1));
// messageSize += sizeof(parameter1);
// memcpy(&data[messageSize], &parameter2, sizeof(parameter2));
// messageSize += sizeof(parameter2);
//}
PusVerificationMessage::PusVerificationMessage(uint8_t set_report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t set_error_code, uint8_t set_step, uint32_t parameter1,
uint32_t parameter2) {
uint8_t *data = this->getBuffer();
data[messageSize] = set_report_id;
messageSize += sizeof(set_report_id);
data[messageSize] = ackFlags;
messageSize += sizeof(ackFlags);
memcpy(&data[messageSize], &tcPacketId, sizeof(tcPacketId));
messageSize += sizeof(tcPacketId);
memcpy(&data[messageSize], &tcSequenceControl, sizeof(tcSequenceControl));
messageSize += sizeof(tcSequenceControl);
data[messageSize] = set_step;
messageSize += sizeof(set_step);
memcpy(&data[messageSize], &set_error_code, sizeof(set_error_code));
messageSize += sizeof(set_error_code);
memcpy(&data[messageSize], &parameter1, sizeof(parameter1));
messageSize += sizeof(parameter1);
memcpy(&data[messageSize], &parameter2, sizeof(parameter2));
messageSize += sizeof(parameter2);
}
uint8_t PusVerificationMessage::getReportId() {
return getContent()->reportId;
}
uint8_t PusVerificationMessage::getAckFlags() {
return getContent()->ackFlags;
}
uint16_t PusVerificationMessage::getTcPacketId() {
uint16_t tcPacketId;
memcpy(&tcPacketId, &getContent()->packetId_0, sizeof(tcPacketId));
return tcPacketId;
}
uint16_t PusVerificationMessage::getTcSequenceControl() {
uint16_t tcSequenceControl;
memcpy(&tcSequenceControl, &getContent()->tcSequenceControl_0,
sizeof(tcSequenceControl));
return tcSequenceControl;
}
uint8_t PusVerificationMessage::getStep() {
return getContent()->step;
}
ReturnValue_t PusVerificationMessage::getErrorCode() {
ReturnValue_t errorCode;
memcpy(&errorCode, &getContent()->error_code_0, sizeof(errorCode));
return errorCode;
}
PusVerificationMessage::verifciationMessageContent* PusVerificationMessage::getContent() {
return (verifciationMessageContent*) this->getData();
}
uint32_t PusVerificationMessage::getParameter1() {
uint32_t parameter;
memcpy(&parameter, &getContent()->parameter1_0, sizeof(parameter));
return parameter;
}
uint32_t PusVerificationMessage::getParameter2() {
uint32_t parameter;
memcpy(&parameter, &getContent()->parameter2_0, sizeof(parameter));
return parameter;
}
PusSuccessReport::PusSuccessReport(uint16_t setPacketId,
uint16_t setSequenceControl, uint8_t setStep) :
reportSize(0), pBuffer(reportBuffer) {
//Serialization won't fail, because we know the necessary max-size of the buffer.
SerializeAdapter::serialize(&setPacketId, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&setSequenceControl, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
if (setStep != 0) {
SerializeAdapter::serialize(&setStep, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
}
}
PusSuccessReport::~PusSuccessReport() {
}
uint32_t PusSuccessReport::getSize() {
return reportSize;
}
uint8_t* PusSuccessReport::getReport() {
return reportBuffer;
}
PusFailureReport::PusFailureReport(uint16_t setPacketId,
uint16_t setSequenceControl, ReturnValue_t setErrorCode,
uint8_t setStep, uint32_t parameter1, uint32_t parameter2) :
reportSize(0), pBuffer(reportBuffer) {
//Serialization won't fail, because we know the necessary max-size of the buffer.
SerializeAdapter::serialize(&setPacketId, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&setSequenceControl, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
if (setStep != 0) {
SerializeAdapter::serialize(&setStep, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
}
SerializeAdapter::serialize(&setErrorCode, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&parameter1, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&parameter2, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
}
PusFailureReport::~PusFailureReport() {
}
size_t PusFailureReport::getSize() {
return reportSize;
}
uint8_t* PusFailureReport::getReport() {
return reportBuffer;
}
#include "../serialize/SerializeAdapter.h"
#include "../tmtcservices/PusVerificationReport.h"
PusVerificationMessage::PusVerificationMessage() {
}
//PusVerificationMessage::PusVerificationMessage(uint8_t set_report_id,
// TcPacketBase* current_packet, ReturnValue_t set_error_code,
// uint8_t set_step, uint32_t parameter1, uint32_t parameter2) {
// uint8_t ackFlags = current_packet->getAcknowledgeFlags();
// uint16_t tcPacketId = current_packet->getPacketId();
// uint16_t tcSequenceControl = current_packet->getPacketSequenceControl();
// uint8_t* data = this->getBuffer();
// data[messageSize] = set_report_id;
// messageSize += sizeof(set_report_id);
// data[messageSize] = ackFlags;
// messageSize += sizeof(ackFlags);
// memcpy(&data[messageSize], &tcPacketId, sizeof(tcPacketId));
// messageSize += sizeof(tcPacketId);
// memcpy(&data[messageSize], &tcSequenceControl, sizeof(tcSequenceControl));
// messageSize += sizeof(tcSequenceControl);
// data[messageSize] = set_step;
// messageSize += sizeof(set_step);
// memcpy(&data[messageSize], &set_error_code, sizeof(set_error_code));
// messageSize += sizeof(set_error_code);
// memcpy(&data[messageSize], &parameter1, sizeof(parameter1));
// messageSize += sizeof(parameter1);
// memcpy(&data[messageSize], &parameter2, sizeof(parameter2));
// messageSize += sizeof(parameter2);
//}
PusVerificationMessage::PusVerificationMessage(uint8_t set_report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t set_error_code, uint8_t set_step, uint32_t parameter1,
uint32_t parameter2) {
uint8_t *data = this->getBuffer();
data[messageSize] = set_report_id;
messageSize += sizeof(set_report_id);
data[messageSize] = ackFlags;
messageSize += sizeof(ackFlags);
memcpy(&data[messageSize], &tcPacketId, sizeof(tcPacketId));
messageSize += sizeof(tcPacketId);
memcpy(&data[messageSize], &tcSequenceControl, sizeof(tcSequenceControl));
messageSize += sizeof(tcSequenceControl);
data[messageSize] = set_step;
messageSize += sizeof(set_step);
memcpy(&data[messageSize], &set_error_code, sizeof(set_error_code));
messageSize += sizeof(set_error_code);
memcpy(&data[messageSize], &parameter1, sizeof(parameter1));
messageSize += sizeof(parameter1);
memcpy(&data[messageSize], &parameter2, sizeof(parameter2));
messageSize += sizeof(parameter2);
}
uint8_t PusVerificationMessage::getReportId() {
return getContent()->reportId;
}
uint8_t PusVerificationMessage::getAckFlags() {
return getContent()->ackFlags;
}
uint16_t PusVerificationMessage::getTcPacketId() {
uint16_t tcPacketId;
memcpy(&tcPacketId, &getContent()->packetId_0, sizeof(tcPacketId));
return tcPacketId;
}
uint16_t PusVerificationMessage::getTcSequenceControl() {
uint16_t tcSequenceControl;
memcpy(&tcSequenceControl, &getContent()->tcSequenceControl_0,
sizeof(tcSequenceControl));
return tcSequenceControl;
}
uint8_t PusVerificationMessage::getStep() {
return getContent()->step;
}
ReturnValue_t PusVerificationMessage::getErrorCode() {
ReturnValue_t errorCode;
memcpy(&errorCode, &getContent()->error_code_0, sizeof(errorCode));
return errorCode;
}
PusVerificationMessage::verifciationMessageContent* PusVerificationMessage::getContent() {
return (verifciationMessageContent*) this->getData();
}
uint32_t PusVerificationMessage::getParameter1() {
uint32_t parameter;
memcpy(&parameter, &getContent()->parameter1_0, sizeof(parameter));
return parameter;
}
uint32_t PusVerificationMessage::getParameter2() {
uint32_t parameter;
memcpy(&parameter, &getContent()->parameter2_0, sizeof(parameter));
return parameter;
}
PusSuccessReport::PusSuccessReport(uint16_t setPacketId,
uint16_t setSequenceControl, uint8_t setStep) :
reportSize(0), pBuffer(reportBuffer) {
//Serialization won't fail, because we know the necessary max-size of the buffer.
SerializeAdapter::serialize(&setPacketId, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&setSequenceControl, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
if (setStep != 0) {
SerializeAdapter::serialize(&setStep, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
}
}
PusSuccessReport::~PusSuccessReport() {
}
uint32_t PusSuccessReport::getSize() {
return reportSize;
}
uint8_t* PusSuccessReport::getReport() {
return reportBuffer;
}
PusFailureReport::PusFailureReport(uint16_t setPacketId,
uint16_t setSequenceControl, ReturnValue_t setErrorCode,
uint8_t setStep, uint32_t parameter1, uint32_t parameter2) :
reportSize(0), pBuffer(reportBuffer) {
//Serialization won't fail, because we know the necessary max-size of the buffer.
SerializeAdapter::serialize(&setPacketId, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&setSequenceControl, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
if (setStep != 0) {
SerializeAdapter::serialize(&setStep, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
}
SerializeAdapter::serialize(&setErrorCode, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&parameter1, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&parameter2, &pBuffer, &reportSize,
sizeof(reportBuffer), SerializeIF::Endianness::BIG);
}
PusFailureReport::~PusFailureReport() {
}
size_t PusFailureReport::getSize() {
return reportSize;
}
uint8_t* PusFailureReport::getReport() {
return reportBuffer;
}

View File

@ -1,77 +1,77 @@
#ifndef PUSVERIFICATIONREPORT_H_
#define PUSVERIFICATIONREPORT_H_
#include "../ipc/MessageQueueMessage.h"
#include "../tmtcpacket/pus/TcPacketBase.h"
#include "../tmtcservices/VerificationCodes.h"
class PusVerificationMessage: public MessageQueueMessage {
private:
struct verifciationMessageContent {
uint8_t reportId;
uint8_t ackFlags;
uint8_t packetId_0;
uint8_t packetId_1;
uint8_t tcSequenceControl_0;
uint8_t tcSequenceControl_1;
uint8_t step;
uint8_t error_code_0;
uint8_t error_code_1;
uint8_t parameter1_0;
uint8_t parameter1_1;
uint8_t parameter1_2;
uint8_t parameter1_3;
uint8_t parameter2_0;
uint8_t parameter2_1;
uint8_t parameter2_2;
uint8_t parameter2_3;
};
verifciationMessageContent* getContent();
public:
static const uint8_t VERIFICATION_MIN_SIZE = 6;
PusVerificationMessage();
// PusVerificationMessage( uint8_t set_report_id, TcPacketBase* current_packet, ReturnValue_t set_error_code = 0, uint8_t set_step = 0, uint32_t parameter1 = 0, uint32_t parameter2 = 0 );
PusVerificationMessage(uint8_t set_report_id, uint8_t ackFlags,
uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t set_error_code = 0, uint8_t set_step = 0,
uint32_t parameter1 = 0, uint32_t parameter2 = 0);
uint8_t getReportId();
uint8_t getAckFlags();
uint16_t getTcPacketId();
uint16_t getTcSequenceControl();
ReturnValue_t getErrorCode();
uint8_t getStep();
uint32_t getParameter1();
uint32_t getParameter2();
};
class PusSuccessReport {
private:
static const uint16_t MAX_SIZE = 7;
uint8_t reportBuffer[MAX_SIZE];
size_t reportSize;
uint8_t * pBuffer;
public:
PusSuccessReport(uint16_t setPacketId, uint16_t setSequenceControl,
uint8_t set_step = 0);
~PusSuccessReport();
uint32_t getSize();
uint8_t* getReport();
};
class PusFailureReport {
private:
static const uint16_t MAX_SIZE = 16;
uint8_t reportBuffer[MAX_SIZE];
size_t reportSize;
uint8_t * pBuffer;
public:
PusFailureReport(uint16_t setPacketId, uint16_t setSequenceControl,
ReturnValue_t setErrorCode, uint8_t setStep = 0,
uint32_t parameter1 = 0, uint32_t parameter2 = 0);
~PusFailureReport();
size_t getSize();
uint8_t* getReport();
};
#endif /* PUSVERIFICATIONREPORT_H_ */
#ifndef PUSVERIFICATIONREPORT_H_
#define PUSVERIFICATIONREPORT_H_
#include "../ipc/MessageQueueMessage.h"
#include "../tmtcpacket/pus/TcPacketBase.h"
#include "../tmtcservices/VerificationCodes.h"
class PusVerificationMessage: public MessageQueueMessage {
private:
struct verifciationMessageContent {
uint8_t reportId;
uint8_t ackFlags;
uint8_t packetId_0;
uint8_t packetId_1;
uint8_t tcSequenceControl_0;
uint8_t tcSequenceControl_1;
uint8_t step;
uint8_t error_code_0;
uint8_t error_code_1;
uint8_t parameter1_0;
uint8_t parameter1_1;
uint8_t parameter1_2;
uint8_t parameter1_3;
uint8_t parameter2_0;
uint8_t parameter2_1;
uint8_t parameter2_2;
uint8_t parameter2_3;
};
verifciationMessageContent* getContent();
public:
static const uint8_t VERIFICATION_MIN_SIZE = 6;
PusVerificationMessage();
// PusVerificationMessage( uint8_t set_report_id, TcPacketBase* current_packet, ReturnValue_t set_error_code = 0, uint8_t set_step = 0, uint32_t parameter1 = 0, uint32_t parameter2 = 0 );
PusVerificationMessage(uint8_t set_report_id, uint8_t ackFlags,
uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t set_error_code = 0, uint8_t set_step = 0,
uint32_t parameter1 = 0, uint32_t parameter2 = 0);
uint8_t getReportId();
uint8_t getAckFlags();
uint16_t getTcPacketId();
uint16_t getTcSequenceControl();
ReturnValue_t getErrorCode();
uint8_t getStep();
uint32_t getParameter1();
uint32_t getParameter2();
};
class PusSuccessReport {
private:
static const uint16_t MAX_SIZE = 7;
uint8_t reportBuffer[MAX_SIZE];
size_t reportSize;
uint8_t * pBuffer;
public:
PusSuccessReport(uint16_t setPacketId, uint16_t setSequenceControl,
uint8_t set_step = 0);
~PusSuccessReport();
uint32_t getSize();
uint8_t* getReport();
};
class PusFailureReport {
private:
static const uint16_t MAX_SIZE = 16;
uint8_t reportBuffer[MAX_SIZE];
size_t reportSize;
uint8_t * pBuffer;
public:
PusFailureReport(uint16_t setPacketId, uint16_t setSequenceControl,
ReturnValue_t setErrorCode, uint8_t setStep = 0,
uint32_t parameter1 = 0, uint32_t parameter2 = 0);
~PusFailureReport();
size_t getSize();
uint8_t* getReport();
};
#endif /* PUSVERIFICATIONREPORT_H_ */

View File

@ -1,30 +1,30 @@
/**
* @file SourceSequenceCounter.h
* @brief This file defines the SourceSequenceCounter class.
* @date 04.02.2013
* @author baetz
*/
#ifndef SOURCESEQUENCECOUNTER_H_
#define SOURCESEQUENCECOUNTER_H_
#include "../tmtcpacket/SpacePacketBase.h"
class SourceSequenceCounter {
private:
uint16_t sequenceCount;
public:
SourceSequenceCounter() : sequenceCount(0) {}
void increment() {
sequenceCount = (sequenceCount+1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
}
void decrement() {
sequenceCount = (sequenceCount-1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
}
uint16_t get() { return this->sequenceCount; }
void reset(uint16_t toValue = 0) {
sequenceCount = toValue % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
}
};
#endif /* SOURCESEQUENCECOUNTER_H_ */
/**
* @file SourceSequenceCounter.h
* @brief This file defines the SourceSequenceCounter class.
* @date 04.02.2013
* @author baetz
*/
#ifndef SOURCESEQUENCECOUNTER_H_
#define SOURCESEQUENCECOUNTER_H_
#include "../tmtcpacket/SpacePacketBase.h"
class SourceSequenceCounter {
private:
uint16_t sequenceCount;
public:
SourceSequenceCounter() : sequenceCount(0) {}
void increment() {
sequenceCount = (sequenceCount+1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
}
void decrement() {
sequenceCount = (sequenceCount-1) % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
}
uint16_t get() { return this->sequenceCount; }
void reset(uint16_t toValue = 0) {
sequenceCount = toValue % (SpacePacketBase::LIMIT_SEQUENCE_COUNT);
}
};
#endif /* SOURCESEQUENCECOUNTER_H_ */

View File

@ -1,237 +1,237 @@
#include "../tmtcservices/TmTcBridge.h"
#include "../ipc/QueueFactory.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../globalfunctions/arrayprinter.h"
TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId):
SystemObject(objectId),tmStoreId(tmStoreId), tcStoreId(tcStoreId),
tcDestination(tcDestination)
{
tmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
}
TmTcBridge::~TmTcBridge() {}
ReturnValue_t TmTcBridge::setNumberOfSentPacketsPerCycle(
uint8_t sentPacketsPerCycle) {
if(sentPacketsPerCycle <= LIMIT_STORED_DATA_SENT_PER_CYCLE) {
this->sentPacketsPerCycle = sentPacketsPerCycle;
return RETURN_OK;
}
else {
sif::warning << "TmTcBridge::setNumberOfSentPacketsPerCycle: Number of "
<< "packets sent per cycle exceeds limits. "
<< "Keeping default value." << std::endl;
return RETURN_FAILED;
}
}
ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(
uint8_t maxNumberOfPacketsStored) {
if(maxNumberOfPacketsStored <= LIMIT_DOWNLINK_PACKETS_STORED) {
this->maxNumberOfPacketsStored = maxNumberOfPacketsStored;
return RETURN_OK;
}
else {
sif::warning << "TmTcBridge::setMaxNumberOfPacketsStored: Number of "
<< "packets stored exceeds limits. "
<< "Keeping default value." << std::endl;
return RETURN_FAILED;
}
}
ReturnValue_t TmTcBridge::initialize() {
tcStore = objectManager->get<StorageManagerIF>(tcStoreId);
if (tcStore == nullptr) {
sif::error << "TmTcBridge::initialize: TC store invalid. Make sure"
"it is created and set up properly." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmStore = objectManager->get<StorageManagerIF>(tmStoreId);
if (tmStore == nullptr) {
sif::error << "TmTcBridge::initialize: TM store invalid. Make sure"
"it is created and set up properly." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
AcceptsTelecommandsIF* tcDistributor =
objectManager->get<AcceptsTelecommandsIF>(tcDestination);
if (tcDistributor == nullptr) {
sif::error << "TmTcBridge::initialize: TC Distributor invalid"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmFifo = new DynamicFIFO<store_address_t>(maxNumberOfPacketsStored);
tmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());
return RETURN_OK;
}
ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
ReturnValue_t result;
result = handleTc();
if(result != RETURN_OK) {
sif::debug << "TmTcBridge::performOperation: "
<< "Error handling TCs" << std::endl;
}
result = handleTm();
if (result != RETURN_OK) {
sif::debug << "TmTcBridge::performOperation: "
<< "Error handling TMs" << std::endl;
}
return result;
}
ReturnValue_t TmTcBridge::handleTc() {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = handleTmQueue();
if(result != RETURN_OK) {
sif::error << "TmTcBridge::handleTm: Error handling TM queue!"
<< std::endl;
status = result;
}
if(tmStored and communicationLinkUp and
(packetSentCounter < sentPacketsPerCycle)) {
result = handleStoredTm();
if(result != RETURN_OK) {
sif::error << "TmTcBridge::handleTm: Error handling stored TMs!"
<< std::endl;
status = result;
}
}
packetSentCounter = 0;
return status;
}
ReturnValue_t TmTcBridge::handleTmQueue() {
TmTcMessage message;
const uint8_t* data = nullptr;
size_t size = 0;
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
for (ReturnValue_t result = tmTcReceptionQueue->receiveMessage(&message);
result == HasReturnvaluesIF::RETURN_OK;
result = tmTcReceptionQueue->receiveMessage(&message))
{
//sif::info << (int) packetSentCounter << std::endl;
if(communicationLinkUp == false or
packetSentCounter >= sentPacketsPerCycle) {
storeDownlinkData(&message);
continue;
}
result = tmStore->getData(message.getStorageId(), &data, &size);
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
continue;
}
result = sendTm(data, size);
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
else {
tmStore->deleteData(message.getStorageId());
packetSentCounter++;
}
}
return status;
}
ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
store_address_t storeId = 0;
if(tmFifo->full()) {
sif::debug << "TmTcBridge::storeDownlinkData: TM downlink max. number "
<< "of stored packet IDs reached! " << std::endl;
if(overwriteOld) {
tmFifo->retrieve(&storeId);
tmStore->deleteData(storeId);
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
storeId = message->getStorageId();
tmFifo->insert(storeId);
tmStored = true;
return RETURN_OK;
}
ReturnValue_t TmTcBridge::handleStoredTm() {
ReturnValue_t status = RETURN_OK;
while(not tmFifo->empty() and packetSentCounter < sentPacketsPerCycle) {
//sif::info << "TMTC Bridge: Sending stored TM data. There are "
// << (int) tmFifo->size() << " left to send\r\n" << std::flush;
store_address_t storeId;
const uint8_t* data = nullptr;
size_t size = 0;
tmFifo->retrieve(&storeId);
ReturnValue_t result = tmStore->getData(storeId, &data, &size);
if(result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
result = sendTm(data,size);
if(result != RETURN_OK) {
sif::error << "TMTC Bridge: Could not send stored downlink data"
<< std::endl;
status = result;
}
packetSentCounter ++;
if(tmFifo->empty()) {
tmStored = false;
}
tmStore->deleteData(storeId);
}
return status;
}
void TmTcBridge::registerCommConnect() {
if(not communicationLinkUp) {
//sif::info << "TMTC Bridge: Registered Comm Link Connect" << std::endl;
communicationLinkUp = true;
}
}
void TmTcBridge::registerCommDisconnect() {
//sif::info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl;
if(communicationLinkUp) {
communicationLinkUp = false;
}
}
MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
return tmTcReceptionQueue->getId();
}
void TmTcBridge::printData(uint8_t * data, size_t dataLen) {
arrayprinter::print(data, dataLen);
}
uint16_t TmTcBridge::getIdentifier() {
// This is no PUS service, so we just return 0
return 0;
}
MessageQueueId_t TmTcBridge::getRequestQueue() {
// Default implementation: Relay TC messages to TC distributor directly.
return tmTcReceptionQueue->getDefaultDestination();
}
void TmTcBridge::setFifoToOverwriteOldData(bool overwriteOld) {
this->overwriteOld = overwriteOld;
}
#include "../tmtcservices/TmTcBridge.h"
#include "../ipc/QueueFactory.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../globalfunctions/arrayprinter.h"
TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId):
SystemObject(objectId),tmStoreId(tmStoreId), tcStoreId(tcStoreId),
tcDestination(tcDestination)
{
tmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
}
TmTcBridge::~TmTcBridge() {}
ReturnValue_t TmTcBridge::setNumberOfSentPacketsPerCycle(
uint8_t sentPacketsPerCycle) {
if(sentPacketsPerCycle <= LIMIT_STORED_DATA_SENT_PER_CYCLE) {
this->sentPacketsPerCycle = sentPacketsPerCycle;
return RETURN_OK;
}
else {
sif::warning << "TmTcBridge::setNumberOfSentPacketsPerCycle: Number of "
<< "packets sent per cycle exceeds limits. "
<< "Keeping default value." << std::endl;
return RETURN_FAILED;
}
}
ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(
uint8_t maxNumberOfPacketsStored) {
if(maxNumberOfPacketsStored <= LIMIT_DOWNLINK_PACKETS_STORED) {
this->maxNumberOfPacketsStored = maxNumberOfPacketsStored;
return RETURN_OK;
}
else {
sif::warning << "TmTcBridge::setMaxNumberOfPacketsStored: Number of "
<< "packets stored exceeds limits. "
<< "Keeping default value." << std::endl;
return RETURN_FAILED;
}
}
ReturnValue_t TmTcBridge::initialize() {
tcStore = objectManager->get<StorageManagerIF>(tcStoreId);
if (tcStore == nullptr) {
sif::error << "TmTcBridge::initialize: TC store invalid. Make sure"
"it is created and set up properly." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmStore = objectManager->get<StorageManagerIF>(tmStoreId);
if (tmStore == nullptr) {
sif::error << "TmTcBridge::initialize: TM store invalid. Make sure"
"it is created and set up properly." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
AcceptsTelecommandsIF* tcDistributor =
objectManager->get<AcceptsTelecommandsIF>(tcDestination);
if (tcDistributor == nullptr) {
sif::error << "TmTcBridge::initialize: TC Distributor invalid"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmFifo = new DynamicFIFO<store_address_t>(maxNumberOfPacketsStored);
tmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());
return RETURN_OK;
}
ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
ReturnValue_t result;
result = handleTc();
if(result != RETURN_OK) {
sif::debug << "TmTcBridge::performOperation: "
<< "Error handling TCs" << std::endl;
}
result = handleTm();
if (result != RETURN_OK) {
sif::debug << "TmTcBridge::performOperation: "
<< "Error handling TMs" << std::endl;
}
return result;
}
ReturnValue_t TmTcBridge::handleTc() {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = handleTmQueue();
if(result != RETURN_OK) {
sif::error << "TmTcBridge::handleTm: Error handling TM queue!"
<< std::endl;
status = result;
}
if(tmStored and communicationLinkUp and
(packetSentCounter < sentPacketsPerCycle)) {
result = handleStoredTm();
if(result != RETURN_OK) {
sif::error << "TmTcBridge::handleTm: Error handling stored TMs!"
<< std::endl;
status = result;
}
}
packetSentCounter = 0;
return status;
}
ReturnValue_t TmTcBridge::handleTmQueue() {
TmTcMessage message;
const uint8_t* data = nullptr;
size_t size = 0;
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
for (ReturnValue_t result = tmTcReceptionQueue->receiveMessage(&message);
result == HasReturnvaluesIF::RETURN_OK;
result = tmTcReceptionQueue->receiveMessage(&message))
{
//sif::info << (int) packetSentCounter << std::endl;
if(communicationLinkUp == false or
packetSentCounter >= sentPacketsPerCycle) {
storeDownlinkData(&message);
continue;
}
result = tmStore->getData(message.getStorageId(), &data, &size);
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
continue;
}
result = sendTm(data, size);
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
else {
tmStore->deleteData(message.getStorageId());
packetSentCounter++;
}
}
return status;
}
ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
store_address_t storeId = 0;
if(tmFifo->full()) {
sif::debug << "TmTcBridge::storeDownlinkData: TM downlink max. number "
<< "of stored packet IDs reached! " << std::endl;
if(overwriteOld) {
tmFifo->retrieve(&storeId);
tmStore->deleteData(storeId);
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
storeId = message->getStorageId();
tmFifo->insert(storeId);
tmStored = true;
return RETURN_OK;
}
ReturnValue_t TmTcBridge::handleStoredTm() {
ReturnValue_t status = RETURN_OK;
while(not tmFifo->empty() and packetSentCounter < sentPacketsPerCycle) {
//sif::info << "TMTC Bridge: Sending stored TM data. There are "
// << (int) tmFifo->size() << " left to send\r\n" << std::flush;
store_address_t storeId;
const uint8_t* data = nullptr;
size_t size = 0;
tmFifo->retrieve(&storeId);
ReturnValue_t result = tmStore->getData(storeId, &data, &size);
if(result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
result = sendTm(data,size);
if(result != RETURN_OK) {
sif::error << "TMTC Bridge: Could not send stored downlink data"
<< std::endl;
status = result;
}
packetSentCounter ++;
if(tmFifo->empty()) {
tmStored = false;
}
tmStore->deleteData(storeId);
}
return status;
}
void TmTcBridge::registerCommConnect() {
if(not communicationLinkUp) {
//sif::info << "TMTC Bridge: Registered Comm Link Connect" << std::endl;
communicationLinkUp = true;
}
}
void TmTcBridge::registerCommDisconnect() {
//sif::info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl;
if(communicationLinkUp) {
communicationLinkUp = false;
}
}
MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
return tmTcReceptionQueue->getId();
}
void TmTcBridge::printData(uint8_t * data, size_t dataLen) {
arrayprinter::print(data, dataLen);
}
uint16_t TmTcBridge::getIdentifier() {
// This is no PUS service, so we just return 0
return 0;
}
MessageQueueId_t TmTcBridge::getRequestQueue() {
// Default implementation: Relay TC messages to TC distributor directly.
return tmTcReceptionQueue->getDefaultDestination();
}
void TmTcBridge::setFifoToOverwriteOldData(bool overwriteOld) {
this->overwriteOld = overwriteOld;
}

View File

@ -1,162 +1,162 @@
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#include "../objectmanager/SystemObject.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../container/DynamicFIFO.h"
#include "../tmtcservices/TmTcMessage.h"
class TmTcBridge : public AcceptsTelemetryIF,
public AcceptsTelecommandsIF,
public ExecutableObjectIF,
public HasReturnvaluesIF,
public SystemObject {
public:
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 20;
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId);
virtual ~TmTcBridge();
/**
* Set number of packets sent per performOperation().Please note that this
* value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE
* @param sentPacketsPerCycle
* @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/
ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle);
/**
* Set number of packets sent per performOperation().Please note that this
* value must be smaller than MAX_DOWNLINK_PACKETS_STORED
* @param sentPacketsPerCycle
* @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/
ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored);
/**
* This will set up the bridge to overwrite old data in the FIFO.
* @param overwriteOld
*/
void setFifoToOverwriteOldData(bool overwriteOld);
virtual void registerCommConnect();
virtual void registerCommDisconnect();
/**
* Initializes necessary FSFW components for the TMTC Bridge
* @return
*/
virtual ReturnValue_t initialize() override;
/**
* @brief Handles TMTC reception
*/
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/** AcceptsTelemetryIF override */
virtual MessageQueueId_t getReportReceptionQueue(
uint8_t virtualChannel = 0) override;
/** AcceptsTelecommandsIF override */
virtual uint16_t getIdentifier() override;
virtual MessageQueueId_t getRequestQueue() override;
protected:
//! Cached for initialize function.
object_id_t tmStoreId = objects::NO_OBJECT;
object_id_t tcStoreId = objects::NO_OBJECT;
object_id_t tcDestination = objects::NO_OBJECT;
//! Used to send and receive TMTC messages.
//! The TmTcMessage class is used to transport messages between tasks.
MessageQueueIF* tmTcReceptionQueue = nullptr;
StorageManagerIF* tmStore = nullptr;
StorageManagerIF* tcStore = nullptr;
//! Used to specify whether communication link is up. Will be true
//! by default, so telemetry will be handled immediately.
bool communicationLinkUp = true;
bool tmStored = false;
bool overwriteOld = true;
uint8_t packetSentCounter = 0;
/**
* @brief Handle TC reception
* @details
* Default implementation provided, but is empty.
* In most cases, TC reception will be handled in a separate task anyway.
* @return
*/
virtual ReturnValue_t handleTc();
/**
* Handle Telemetry. Default implementation provided.
* Calls sendTm()
* @return
*/
virtual ReturnValue_t handleTm();
/**
* Read the TM Queue and send TM if necessary.
* Default implementation provided
* @return
*/
virtual ReturnValue_t handleTmQueue();
/**
* Send stored data if communication link is active
* @return
*/
virtual ReturnValue_t handleStoredTm();
/**
* Implemented by child class. Perform sending of Telemetry by implementing
* communication drivers or wrappers, e.g. serial communication or a socket
* call.
* @param data
* @param dataLen
* @return
*/
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) = 0;
/**
* Store data to be sent later if communication link is not up.
* @param message
* @return
*/
virtual ReturnValue_t storeDownlinkData(TmTcMessage * message);
/**
* Print data as hexidecimal array
* @param data
* @param dataLen
*/
void printData(uint8_t * data, size_t dataLen);
/**
* This fifo can be used to store downlink data
* which can not be sent at the moment.
*/
DynamicFIFO<store_address_t>* tmFifo = nullptr;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
};
#endif /* FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ */
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#include "../objectmanager/SystemObject.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../container/DynamicFIFO.h"
#include "../tmtcservices/TmTcMessage.h"
class TmTcBridge : public AcceptsTelemetryIF,
public AcceptsTelecommandsIF,
public ExecutableObjectIF,
public HasReturnvaluesIF,
public SystemObject {
public:
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 20;
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId);
virtual ~TmTcBridge();
/**
* Set number of packets sent per performOperation().Please note that this
* value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE
* @param sentPacketsPerCycle
* @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/
ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle);
/**
* Set number of packets sent per performOperation().Please note that this
* value must be smaller than MAX_DOWNLINK_PACKETS_STORED
* @param sentPacketsPerCycle
* @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/
ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored);
/**
* This will set up the bridge to overwrite old data in the FIFO.
* @param overwriteOld
*/
void setFifoToOverwriteOldData(bool overwriteOld);
virtual void registerCommConnect();
virtual void registerCommDisconnect();
/**
* Initializes necessary FSFW components for the TMTC Bridge
* @return
*/
virtual ReturnValue_t initialize() override;
/**
* @brief Handles TMTC reception
*/
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/** AcceptsTelemetryIF override */
virtual MessageQueueId_t getReportReceptionQueue(
uint8_t virtualChannel = 0) override;
/** AcceptsTelecommandsIF override */
virtual uint16_t getIdentifier() override;
virtual MessageQueueId_t getRequestQueue() override;
protected:
//! Cached for initialize function.
object_id_t tmStoreId = objects::NO_OBJECT;
object_id_t tcStoreId = objects::NO_OBJECT;
object_id_t tcDestination = objects::NO_OBJECT;
//! Used to send and receive TMTC messages.
//! The TmTcMessage class is used to transport messages between tasks.
MessageQueueIF* tmTcReceptionQueue = nullptr;
StorageManagerIF* tmStore = nullptr;
StorageManagerIF* tcStore = nullptr;
//! Used to specify whether communication link is up. Will be true
//! by default, so telemetry will be handled immediately.
bool communicationLinkUp = true;
bool tmStored = false;
bool overwriteOld = true;
uint8_t packetSentCounter = 0;
/**
* @brief Handle TC reception
* @details
* Default implementation provided, but is empty.
* In most cases, TC reception will be handled in a separate task anyway.
* @return
*/
virtual ReturnValue_t handleTc();
/**
* Handle Telemetry. Default implementation provided.
* Calls sendTm()
* @return
*/
virtual ReturnValue_t handleTm();
/**
* Read the TM Queue and send TM if necessary.
* Default implementation provided
* @return
*/
virtual ReturnValue_t handleTmQueue();
/**
* Send stored data if communication link is active
* @return
*/
virtual ReturnValue_t handleStoredTm();
/**
* Implemented by child class. Perform sending of Telemetry by implementing
* communication drivers or wrappers, e.g. serial communication or a socket
* call.
* @param data
* @param dataLen
* @return
*/
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) = 0;
/**
* Store data to be sent later if communication link is not up.
* @param message
* @return
*/
virtual ReturnValue_t storeDownlinkData(TmTcMessage * message);
/**
* Print data as hexidecimal array
* @param data
* @param dataLen
*/
void printData(uint8_t * data, size_t dataLen);
/**
* This fifo can be used to store downlink data
* which can not be sent at the moment.
*/
DynamicFIFO<store_address_t>* tmFifo = nullptr;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
};
#endif /* FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ */

View File

@ -1,29 +1,29 @@
#include "../tmtcservices/TmTcMessage.h"
#include <string.h>
TmTcMessage::TmTcMessage() {
this->messageSize += sizeof(store_address_t);
}
TmTcMessage::~TmTcMessage() {
}
store_address_t TmTcMessage::getStorageId() {
store_address_t temp_id;
memcpy(&temp_id, this->getData(), sizeof(store_address_t) );
return temp_id;
}
TmTcMessage::TmTcMessage(store_address_t store_id) {
this->messageSize += sizeof(store_address_t);
this->setStorageId(store_id);
}
size_t TmTcMessage::getMinimumMessageSize() {
return this->HEADER_SIZE + sizeof(store_address_t);
}
void TmTcMessage::setStorageId(store_address_t store_id) {
memcpy(this->getData(), &store_id, sizeof(store_address_t) );
}
#include "../tmtcservices/TmTcMessage.h"
#include <string.h>
TmTcMessage::TmTcMessage() {
this->messageSize += sizeof(store_address_t);
}
TmTcMessage::~TmTcMessage() {
}
store_address_t TmTcMessage::getStorageId() {
store_address_t temp_id;
memcpy(&temp_id, this->getData(), sizeof(store_address_t) );
return temp_id;
}
TmTcMessage::TmTcMessage(store_address_t store_id) {
this->messageSize += sizeof(store_address_t);
this->setStorageId(store_id);
}
size_t TmTcMessage::getMinimumMessageSize() {
return this->HEADER_SIZE + sizeof(store_address_t);
}
void TmTcMessage::setStorageId(store_address_t store_id) {
memcpy(this->getData(), &store_id, sizeof(store_address_t) );
}

View File

@ -1,50 +1,50 @@
#ifndef TMTCMESSAGE_H_
#define TMTCMESSAGE_H_
#include "../ipc/MessageQueueMessage.h"
#include "../storagemanager/StorageManagerIF.h"
/**
* @brief This message class is used to pass Telecommand and Telemetry
* packets between tasks.
* @details Within such a packet, nothing is transported but the identifier of
* a packet stored in one of the IPC stores (typically a special TM and
* a special TC store). This makes passing commands very simple and
* efficient.
* \ingroup message_queue
*/
class TmTcMessage : public MessageQueueMessage {
protected:
/**
* @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + \c sizeof(store_address_t).
*/
size_t getMinimumMessageSize();
public:
/**
* @brief In the default constructor, only the message_size is set.
*/
TmTcMessage();
/**
* @brief With this constructor, the passed packet id is directly put
* into the message.
* @param packet_id The packet id to put into the message.
*/
TmTcMessage( store_address_t packet_id );
/**
* @brief The class's destructor is empty.
*/
~TmTcMessage();
/**
* @brief This getter returns the packet id in the correct format.
* @return Returns the packet id.
*/
store_address_t getStorageId();
/**
* @brief In some cases it might be useful to have a setter for packet id
* as well.
* @param packet_id The packet id to put into the message.
*/
void setStorageId( store_address_t packet_id );
};
#endif /* TMTCMESSAGE_H_ */
#ifndef TMTCMESSAGE_H_
#define TMTCMESSAGE_H_
#include "../ipc/MessageQueueMessage.h"
#include "../storagemanager/StorageManagerIF.h"
/**
* @brief This message class is used to pass Telecommand and Telemetry
* packets between tasks.
* @details Within such a packet, nothing is transported but the identifier of
* a packet stored in one of the IPC stores (typically a special TM and
* a special TC store). This makes passing commands very simple and
* efficient.
* \ingroup message_queue
*/
class TmTcMessage : public MessageQueueMessage {
protected:
/**
* @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + \c sizeof(store_address_t).
*/
size_t getMinimumMessageSize();
public:
/**
* @brief In the default constructor, only the message_size is set.
*/
TmTcMessage();
/**
* @brief With this constructor, the passed packet id is directly put
* into the message.
* @param packet_id The packet id to put into the message.
*/
TmTcMessage( store_address_t packet_id );
/**
* @brief The class's destructor is empty.
*/
~TmTcMessage();
/**
* @brief This getter returns the packet id in the correct format.
* @return Returns the packet id.
*/
store_address_t getStorageId();
/**
* @brief In some cases it might be useful to have a setter for packet id
* as well.
* @param packet_id The packet id to put into the message.
*/
void setStorageId( store_address_t packet_id );
};
#endif /* TMTCMESSAGE_H_ */

View File

@ -1,105 +1,105 @@
#include "../tmtcservices/VerificationReporter.h"
#include "../ipc/MessageQueueIF.h"
#include "../tmtcservices/AcceptsVerifyMessageIF.h"
#include "../tmtcservices/PusVerificationReport.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../objectmanager/frameworkObjects.h"
object_id_t VerificationReporter::messageReceiver = objects::PUS_SERVICE_1;
VerificationReporter::VerificationReporter() :
acknowledgeQueue(MessageQueueIF::NO_QUEUE) {
}
VerificationReporter::~VerificationReporter() {}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
TcPacketBase* current_packet, uint8_t set_step) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(set_report_id,
current_packet->getAcknowledgeFlags(),
current_packet->getPacketId(),
current_packet->getPacketSequenceControl(), 0, set_step);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendSuccessReport: Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(set_report_id, ackFlags, tcPacketId,
tcSequenceControl, 0, set_step);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendSuccessReport: Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
void VerificationReporter::sendFailureReport(uint8_t report_id,
TcPacketBase* current_packet, ReturnValue_t error_code, uint8_t step,
uint32_t parameter1, uint32_t parameter2) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(report_id,
current_packet->getAcknowledgeFlags(),
current_packet->getPacketId(),
current_packet->getPacketSequenceControl(), error_code, step,
parameter1, parameter2);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendFailureReport Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
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) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(report_id, ackFlags, tcPacketId,
tcSequenceControl, error_code, step, parameter1, parameter2);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendFailureReport Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
void VerificationReporter::initialize() {
if(messageReceiver == objects::NO_OBJECT) {
sif::warning << "VerificationReporter::initialize: Verification message"
" receiver object ID not set yet in Factory!" << std::endl;
return;
}
AcceptsVerifyMessageIF* temp = objectManager->get<AcceptsVerifyMessageIF>(
messageReceiver);
if (temp == nullptr) {
sif::error << "VerificationReporter::initialize: Message "
<< "receiver invalid. Make sure it is set up properly and "
<<"implementsAcceptsVerifyMessageIF" << std::endl;
}
this->acknowledgeQueue = temp->getVerificationQueue();
}
#include "../tmtcservices/VerificationReporter.h"
#include "../ipc/MessageQueueIF.h"
#include "../tmtcservices/AcceptsVerifyMessageIF.h"
#include "../tmtcservices/PusVerificationReport.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../objectmanager/frameworkObjects.h"
object_id_t VerificationReporter::messageReceiver = objects::PUS_SERVICE_1;
VerificationReporter::VerificationReporter() :
acknowledgeQueue(MessageQueueIF::NO_QUEUE) {
}
VerificationReporter::~VerificationReporter() {}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
TcPacketBase* current_packet, uint8_t set_step) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(set_report_id,
current_packet->getAcknowledgeFlags(),
current_packet->getPacketId(),
current_packet->getPacketSequenceControl(), 0, set_step);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendSuccessReport: Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(set_report_id, ackFlags, tcPacketId,
tcSequenceControl, 0, set_step);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendSuccessReport: Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
void VerificationReporter::sendFailureReport(uint8_t report_id,
TcPacketBase* current_packet, ReturnValue_t error_code, uint8_t step,
uint32_t parameter1, uint32_t parameter2) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(report_id,
current_packet->getAcknowledgeFlags(),
current_packet->getPacketId(),
current_packet->getPacketSequenceControl(), error_code, step,
parameter1, parameter2);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendFailureReport Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
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) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize();
}
PusVerificationMessage message(report_id, ackFlags, tcPacketId,
tcSequenceControl, error_code, step, parameter1, parameter2);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue,
&message);
if (status != HasReturnvaluesIF::RETURN_OK) {
sif::error << "VerificationReporter::sendFailureReport Error writing "
<< "to queue. Code: " << std::hex << status << std::dec
<< std::endl;
}
}
void VerificationReporter::initialize() {
if(messageReceiver == objects::NO_OBJECT) {
sif::warning << "VerificationReporter::initialize: Verification message"
" receiver object ID not set yet in Factory!" << std::endl;
return;
}
AcceptsVerifyMessageIF* temp = objectManager->get<AcceptsVerifyMessageIF>(
messageReceiver);
if (temp == nullptr) {
sif::error << "VerificationReporter::initialize: Message "
<< "receiver invalid. Make sure it is set up properly and "
<<"implementsAcceptsVerifyMessageIF" << std::endl;
}
this->acknowledgeQueue = temp->getVerificationQueue();
}

View File

@ -1,50 +1,50 @@
#ifndef FRAMEWORK_TMTCSERVICES_VERIFICATIONREPORTER_H_
#define FRAMEWORK_TMTCSERVICES_VERIFICATIONREPORTER_H_
#include "../objectmanager/ObjectManagerIF.h"
#include "../tmtcservices/PusVerificationReport.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @brief This helper object is used to forward verification messages
* which are generated by the Flight Software Framework.
* @details
* The messages can be relayed to an arbitrary object, for example a dedicated
* Verification Reporter. The destination is set by setting the static framework
* Id VerificationReporter::messageReceiver. The default verification reporter
* will be the PUS service 1, which sends verification messages according
* to the PUS standard.
*
*/
class VerificationReporter {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
VerificationReporter();
virtual ~VerificationReporter();
void sendSuccessReport( uint8_t set_report_id, TcPacketBase* current_packet,
uint8_t set_step = 0 );
void sendSuccessReport(uint8_t set_report_id, uint8_t ackFlags,
uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step = 0);
void sendFailureReport( uint8_t report_id, TcPacketBase* current_packet,
ReturnValue_t error_code = 0,
uint8_t step = 0, uint32_t parameter1 = 0,
uint32_t parameter2 = 0 );
void sendFailureReport(uint8_t report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t error_code = 0, uint8_t step = 0,
uint32_t parameter1 = 0, uint32_t parameter2 = 0);
void initialize();
private:
static object_id_t messageReceiver;
MessageQueueId_t acknowledgeQueue;
};
#endif /* FRAMEWORK_TMTCSERVICES_VERIFICATIONREPORTER_H_ */
#ifndef FRAMEWORK_TMTCSERVICES_VERIFICATIONREPORTER_H_
#define FRAMEWORK_TMTCSERVICES_VERIFICATIONREPORTER_H_
#include "../objectmanager/ObjectManagerIF.h"
#include "../tmtcservices/PusVerificationReport.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* @brief This helper object is used to forward verification messages
* which are generated by the Flight Software Framework.
* @details
* The messages can be relayed to an arbitrary object, for example a dedicated
* Verification Reporter. The destination is set by setting the static framework
* Id VerificationReporter::messageReceiver. The default verification reporter
* will be the PUS service 1, which sends verification messages according
* to the PUS standard.
*
*/
class VerificationReporter {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
VerificationReporter();
virtual ~VerificationReporter();
void sendSuccessReport( uint8_t set_report_id, TcPacketBase* current_packet,
uint8_t set_step = 0 );
void sendSuccessReport(uint8_t set_report_id, uint8_t ackFlags,
uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step = 0);
void sendFailureReport( uint8_t report_id, TcPacketBase* current_packet,
ReturnValue_t error_code = 0,
uint8_t step = 0, uint32_t parameter1 = 0,
uint32_t parameter2 = 0 );
void sendFailureReport(uint8_t report_id,
uint8_t ackFlags, uint16_t tcPacketId, uint16_t tcSequenceControl,
ReturnValue_t error_code = 0, uint8_t step = 0,
uint32_t parameter1 = 0, uint32_t parameter2 = 0);
void initialize();
private:
static object_id_t messageReceiver;
MessageQueueId_t acknowledgeQueue;
};
#endif /* FRAMEWORK_TMTCSERVICES_VERIFICATIONREPORTER_H_ */