A lot of new features and tweaks #12

Merged
muellerr merged 17 commits from mueller_framework into front_branch 2020-07-08 18:49:10 +02:00
7 changed files with 622 additions and 1 deletions
Showing only changes of commit 359163886b - Show all commits

View File

@ -58,4 +58,4 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/packetmatcher/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/pus/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/test/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/pus/*.cpp)

View File

@ -0,0 +1,100 @@
#include <framework/pus/Service1TelecommandVerification.h>
#include <framework/pus/servicepackets/Service1Packets.h>
#include <framework/ipc/QueueFactory.h>
#include <framework/tmtcservices/PusVerificationReport.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tmtcservices/AcceptsTelemetryIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
Service1TelecommandVerification::Service1TelecommandVerification(
object_id_t objectId, uint16_t apid, uint8_t serviceId,
object_id_t targetDestination):
SystemObject(objectId), apid(apid), serviceId(serviceId),
targetDestination(targetDestination) {
tmQueue = QueueFactory::instance()->createMessageQueue();
}
Service1TelecommandVerification::~Service1TelecommandVerification() {}
MessageQueueId_t Service1TelecommandVerification::getVerificationQueue(){
return tmQueue->getId();
}
ReturnValue_t Service1TelecommandVerification::performOperation(
uint8_t operationCode){
PusVerificationMessage message;
ReturnValue_t status = tmQueue->receiveMessage(&message);
while(status == HasReturnvaluesIF::RETURN_OK) {
status = sendVerificationReport(&message);
if(status != HasReturnvaluesIF::RETURN_OK) {
return status;
}
status = tmQueue->receiveMessage(&message);
}
if (status == MessageQueueIF::EMPTY) {
return HasReturnvaluesIF::RETURN_OK;
}
else {
return status;
}
}
ReturnValue_t Service1TelecommandVerification::sendVerificationReport(
PusVerificationMessage* message) {
ReturnValue_t result;
if(message->getReportId() % 2 == 0) {
result = generateFailureReport(message);
} else {
result = generateSuccessReport(message);
}
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Service1TelecommandVerification::initialize: "
"Sending verification packet failed !" << std::endl;
}
return result;
}
ReturnValue_t Service1TelecommandVerification::generateFailureReport(
PusVerificationMessage *message) {
FailureReport report(
message->getReportId(), message->getTcPacketId(),
message->getTcSequenceControl(), message->getStep(),
message->getErrorCode(), message->getParameter1(),
message->getParameter2());
TmPacketStored tmPacket(apid, serviceId, message->getReportId(),
packetSubCounter++, &report);
ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(),
tmQueue->getId());
return result;
}
ReturnValue_t Service1TelecommandVerification::generateSuccessReport(
PusVerificationMessage *message) {
SuccessReport report(message->getReportId(),message->getTcPacketId(),
message->getTcSequenceControl(),message->getStep());
TmPacketStored tmPacket(apid, serviceId, message->getReportId(),
packetSubCounter++, &report);
ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(),
tmQueue->getId());
return result;
}
ReturnValue_t Service1TelecommandVerification::initialize() {
// Get target object for TC verification messages
AcceptsTelemetryIF* funnel = objectManager->
get<AcceptsTelemetryIF>(targetDestination);
if(funnel == nullptr){
sif::error << "Service1TelecommandVerification::initialize: Specified"
" TM funnel invalid. Make sure it is set up and implements"
" AcceptsTelemetryIF." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmQueue->setDefaultDestination(funnel->getReportReceptionQueue());
return SystemObject::initialize();
}

View File

@ -0,0 +1,94 @@
#ifndef MISSION_PUS_SERVICE1TELECOMMANDVERIFICATION_H_
#define MISSION_PUS_SERVICE1TELECOMMANDVERIFICATION_H_
#include <framework/objectmanager/SystemObject.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/tasks/ExecutableObjectIF.h>
#include <framework/tmtcservices/AcceptsVerifyMessageIF.h>
#include <framework/tmtcservices/PusVerificationReport.h>
#include <framework/ipc/MessageQueueIF.h>
/**
* @brief Verify TC acceptance, start, progress and execution.
*
* Full Documentation: ECSS-E70-41A p.51
*
* The telecommand verification service provides the capability for
* explicit verification of each distinct stage of execution of a telecommand
* packet, from on-board acceptance through to completion of execution.
*
* Minimum capabilities of this service:
*
* - TM[1,1]: Telecommand Acceptance Report - Success.
* - TM[1,2]: Telecommand Acceptance Report - Failure.
*
* Additional capabilities of this service:
*
* - TM[1,3]: Telecommand Execution Started Report - Success (Req. 4).
* - TM[1,4]: Telecommand Execution Started Report - Failure (Req. 3).
* - TM[1,5]: Telecommand Execution Progress Report - Success (Req. 6).
* - TM[1,6]: Telecommand Execution Progress Report - Failure (Req. 5).
* - TM[1,7]: Telecommand Execution Completed Report - Success (Req. 8).
* - TM[1,8]: Telecommand Execution Completed Report - Failure (Req. 7).
*
* This Service is not inherited from PUSServiceBase unlike other PUS Services
* because all services implementing PUSServiceBase use this service to
* generate verification reports.
* @ingroup pus_services
*/
class Service1TelecommandVerification: public AcceptsVerifyMessageIF,
public SystemObject,
public ExecutableObjectIF,
public HasReturnvaluesIF {
public:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_1;
Service1TelecommandVerification(object_id_t objectId,
uint16_t apid, uint8_t serviceId, object_id_t targetDestination);
virtual ~Service1TelecommandVerification();
/**
*
* @return ID of Verification Queue
*/
virtual MessageQueueId_t getVerificationQueue();
/**
* Performs the service periodically as specified in init_mission().
* Triggers the handlePacket function to send TC verification messages
* @param operationCode
* @return
*/
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/**
* Initializes the destination for TC verification messages and initializes
* Service 1 as a system object
* @return
*/
ReturnValue_t initialize() override;
private:
uint16_t apid = 0;
uint8_t serviceId = 0;
object_id_t targetDestination = objects::NO_OBJECT;
ReturnValue_t sendVerificationReport(PusVerificationMessage* message);
ReturnValue_t generateFailureReport(PusVerificationMessage* message);
ReturnValue_t generateSuccessReport(PusVerificationMessage* message);
uint16_t packetSubCounter = 0;
MessageQueueIF* tmQueue = nullptr;
enum class Subservice: uint8_t {
VERIFY_ACCEPTANCE_SUCCESS = 1, //!< [EXPORT] : [TM]
VERIFY_ACCEPTANCE_FAILED = 2, //!< [EXPORT] : [TM]
VERIFY_START_SUCCESS = 3, //!< [EXPORT] : [TM]
VERIFY_START_FAILED = 4, //!< [EXPORT] : [TM]
VERIFY_STEP_SUCCESS = 5, //!< [EXPORT] : [TM]
VERIFY_STEP_FAILED = 6 //!< [EXPORT] : [TM]
};
};
#endif /* MISSION_PUS_SERVICE1TELECOMMANDVERIFICATION_H_ */

View File

@ -0,0 +1,92 @@
#include <framework/pus/Service5EventReporting.h>
#include <framework/pus/servicepackets/Service5Packets.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/events/EventManagerIF.h>
#include <framework/ipc/QueueFactory.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h>
Service5EventReporting::Service5EventReporting(object_id_t objectId,
uint16_t apid, uint8_t serviceId, size_t maxNumberReportsPerCycle):
PusServiceBase(objectId, apid, serviceId),
maxNumberReportsPerCycle(maxNumberReportsPerCycle) {
eventQueue = QueueFactory::instance()->createMessageQueue();
}
Service5EventReporting::~Service5EventReporting(){}
ReturnValue_t Service5EventReporting::performService() {
EventMessage message;
ReturnValue_t status = RETURN_OK;
for(uint8_t counter = 0;
counter < maxNumberReportsPerCycle;
counter++)
{
// Receive messages even if reporting is disabled for now.
status = eventQueue->receiveMessage(&message);
if(status == MessageQueueIF::EMPTY) {
return HasReturnvaluesIF::RETURN_OK;
}
if(enableEventReport) {
status = generateEventReport(message);
if(status != HasReturnvaluesIF::RETURN_OK) {
return status;
}
}
}
sif::debug << "Service5EventReporting::generateEventReport:"
" Too many events" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Service5EventReporting::generateEventReport(
EventMessage message)
{
EventReport report(message.getEventId(),message.getReporter(),
message.getParameter1(),message.getParameter2());
TmPacketStored tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
message.getSeverity(), packetSubCounter++, &report);
ReturnValue_t result = tmPacket.sendPacket(
requestQueue->getDefaultDestination(),requestQueue->getId());
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "Service5EventReporting::generateEventReport:"
" Could not send TM packet" << std::endl;
}
return result;
}
ReturnValue_t Service5EventReporting::handleRequest(uint8_t subservice) {
switch(subservice)
{
case Subservice::ENABLE: {
enableEventReport = true;
return HasReturnvaluesIF::RETURN_OK;
}
case Subservice::DISABLE: {
enableEventReport = false;
return HasReturnvaluesIF::RETURN_OK;
}
default:
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
}
}
// In addition to the default PUSServiceBase initialization, this service needs
// to be registered to the event manager to listen for events.
ReturnValue_t Service5EventReporting::initialize() {
EventManagerIF* manager = objectManager->get<EventManagerIF>(
objects::EVENT_MANAGER);
if (manager == NULL) {
return RETURN_FAILED;
}
// register Service 5 as listener for events
ReturnValue_t result = manager->registerListener(eventQueue->getId(),true);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return PusServiceBase::initialize();
}

View File

@ -0,0 +1,86 @@
#ifndef FRAMEWORK_PUS_SERVICE5EVENTREPORTING_H_
#define FRAMEWORK_PUS_SERVICE5EVENTREPORTING_H_
#include <framework/tmtcservices/PusServiceBase.h>
#include <framework/events/EventMessage.h>
/**
* @brief Report on-board events like information or errors
* @details
* Full Documentation: ECSS-E70-41A p.79
* Implements the PusServiceBase template class.
* Documentation: Dissertation Baetz p.135,136
*
* This service provides for the reporting to the service user of information of
* operational significance.
* 1. reporting of failures or anomalies detected on-board;
* 2. reporting of autonomous on-board actions;
* 3. reporting of normal progress of operations and activities, e.g.
* detection of events which are not anomalous (such as payload events),
* reaching of predefined steps in an operation. Some reports can combine
* more than one of these events.
*
* Minimum capabilities of this service:
*
* - TM[5,1]: Normal/Progress Report
* - TM[5,2]: Error/Anomaly Report - Low Severity
* - TM[5,3]: Error/Anomaly Report - Medium Severity
* - TM[5,4]: Error/Anomaly Report - High Severity
*
* Events can be translated by using translator files located in
* /config/objects/ and /config/events/. Description to events can be added by
* adding a comment behind the event definition with [//!<] as leading string
*
* Additional capabilities of this service:
*
* - TC[5,5]: Enable Event Report Generation (Req. 6)
* - TC[5,6]: Disable Event Report Generation (Req. 5)
* @author R. Mueller
* @ingroup pus_services
*/
class Service5EventReporting: public PusServiceBase {
public:
Service5EventReporting(object_id_t objectId, uint16_t apid,
uint8_t serviceId, size_t maxNumberReportsPerCycle = 10);
virtual ~Service5EventReporting();
/***
* Check for events and generate event reports if required.
* @return
*/
ReturnValue_t performService() override;
/***
* Turn event generation on or off.
* @return
*/
ReturnValue_t handleRequest(uint8_t subservice) override;
/**
* The default PusServiceBase initialize has been overridden but is still
* executed. Registers this service as a listener for events at the
* EventManager.
* @return
*/
ReturnValue_t initialize() override;
enum Subservice: uint8_t {
NORMAL_REPORT = 1, //!< [EXPORT] : [REPLY] Generate normal report
ERROR_LOW_SEVERITY = 2, //!< [EXPORT] : [REPLY] Generate error report with low severity
ERROR_MED_SEVERITY = 3, //!< [EXPORT] : [REPLY] Generate error report with medium severity
ERROR_HIGH_SEVERITY = 4, //!< [EXPORT] : [REPLY] Generate error report with high severity
ENABLE = 5, //!< [EXPORT] : [COMMAND] Enable report generation
DISABLE = 6 //!< [EXPORT] : [COMMAND] Disable report generation
};
private:
uint16_t packetSubCounter = 0;
MessageQueueIF* eventQueue = nullptr;
bool enableEventReport = true;
const uint8_t maxNumberReportsPerCycle;
ReturnValue_t generateEventReport(EventMessage message);
};
#endif /* MISSION_PUS_SERVICE5EVENTREPORTING_H_ */

View File

@ -0,0 +1,166 @@
/**
* @defgroup spacepackets PUS Packet Definitions
* This group contains all implemented TM or TM packages that are sent to
* or sent by the OBC.They are exported later to display
* packet structures in Mission Information Base (MIB).
*/
#ifndef MISSION_PUS_SERVICEPACKETS_SERVICE1PACKETS_H_
#define MISSION_PUS_SERVICEPACKETS_SERVICE1PACKETS_H_
#include <framework/serialize/SerializeAdapter.h>
#include <framework/tmtcservices/VerificationCodes.h>
/**
* @brief FailureReport class to serialize a failure report
* @brief Subservice 1, 3, 5, 7
* @ingroup spacepackets
*/
class FailureReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 1, 3, 5, 7
public:
FailureReport(uint8_t failureSubtype_, uint16_t packetId_,
uint16_t packetSequenceControl_, uint8_t stepNumber_,
ReturnValue_t errorCode_, uint32_t errorParameter1_,
uint32_t errorParameter2_) :
packetId(packetId_), packetSequenceControl(packetSequenceControl_),
stepNumber(stepNumber_), errorCode(errorCode_),
errorParameter1(errorParameter1_), errorParameter2(errorParameter2_),
failureSubtype(failureSubtype_) {}
/**
* This function is called by the FSFW when calling the tm packet send
* function and supplying the SerializeIF* as parameter
* @param buffer Object content is serialized into the buffer
* @param size
* @param max_size
* @param bigEndian
* @return
*/
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, SerializeIF::Endianness streamEndianness
) const override {
ReturnValue_t result = SerializeAdapter::serialize(&packetId, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&packetSequenceControl, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (failureSubtype == TC_VERIFY::PROGRESS_FAILURE) {
result = SerializeAdapter::serialize(&stepNumber, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
}
result = SerializeAdapter::serialize(&errorCode, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&errorParameter1, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&errorParameter2, buffer, size,
maxSize, streamEndianness);
return result;
}
virtual size_t getSerializedSize() const {
size_t size = 0;
size += SerializeAdapter::getSerializedSize(&packetId);
size += sizeof(packetSequenceControl);
if(failureSubtype==TC_VERIFY::PROGRESS_FAILURE){
size += SerializeAdapter::getSerializedSize(&stepNumber);
}
size += SerializeAdapter::getSerializedSize(&errorCode);
size += SerializeAdapter::getSerializedSize(&errorParameter1);
size += SerializeAdapter::getSerializedSize(&errorParameter2);
return size;
}
/**
* Deserialization is not allowed for a report.
* @param buffer
* @param size
* @param bigEndian
* @return
*/
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_FAILED;
}
private:
uint16_t packetId; //!< [EXPORT] : [COMMENT] Packet ID of respective Telecommand
uint16_t packetSequenceControl; //!< [EXPORT] : [COMMENT] Packet SSC of respective Telecommand
uint8_t stepNumber; //!< [EXPORT] : [OPTIONAL][SUBSERVICE] 6
ReturnValue_t errorCode; //!< [EXPORT] : [COMMENT] Error code which can be looked up in generated error code file
uint32_t errorParameter1;
uint32_t errorParameter2;
const uint8_t failureSubtype; //!< [EXPORT] : [IGNORE]
};
/**
* @brief Subservices 2, 4, 6, 8
* @ingroup spacepackets
*/
class SuccessReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 2, 4, 6, 8
public:
SuccessReport(uint8_t subtype_, uint16_t packetId_,
uint16_t packetSequenceControl_,uint8_t stepNumber_) :
packetId(packetId_), packetSequenceControl(packetSequenceControl_),
stepNumber(stepNumber_), subtype(subtype_) {}
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, SerializeIF::Endianness streamEndianness
) const override {
ReturnValue_t result = SerializeAdapter::serialize(&packetId, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&packetSequenceControl, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (subtype == TC_VERIFY::PROGRESS_SUCCESS) {
result = SerializeAdapter::serialize(&stepNumber, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
}
return result;
}
virtual size_t getSerializedSize() const override {
size_t size = 0;
size += SerializeAdapter::getSerializedSize(&packetId);
size += sizeof(packetSequenceControl);
if(subtype == TC_VERIFY::PROGRESS_SUCCESS){
size += SerializeAdapter::getSerializedSize(&stepNumber);
}
return size;
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_FAILED;
}
private:
uint16_t packetId; //!< [EXPORT] : [COMMENT] Packet ID of respective Telecommand
uint16_t packetSequenceControl; //!< [EXPORT] : [COMMENT] Packet SSC of respective Telecommand
uint8_t stepNumber; //!< [EXPORT] : [OPTIONAL][SUBSERVICE] 6
const uint8_t subtype; //!< [EXPORT] : [IGNORE]
};
#endif /* MISSION_PUS_SERVICEPACKETS_SERVICE1PACKETS_H_ */

View File

@ -0,0 +1,83 @@
/**
* \file Service5Packets.h
*
* Structure of Event Report.
* It consists of:
* 1. Report ID(RID). This is the Event ID in the FSFW
* 2. Object ID of the reporter (e.g. subsystem)
* 2. Parameter 1
* 3. Parameter 2
*
* Created on: 21.05.2019
* Author: R. Mueller, J. Meier
*/
#ifndef MISSION_PUS_SERVICEPACKETS_SERVICE5PACKETS_H_
#define MISSION_PUS_SERVICEPACKETS_SERVICE5PACKETS_H_
#include <framework/serialize/SerializeAdapter.h>
#include <framework/tmtcservices/VerificationCodes.h>
/**
* \brief Subservice 1, 2, 3, 4
* \ingroup spacepackets
*/
class EventReport: public SerializeIF { //!< [EXPORT] : [SUBSERVICE] 1, 2, 3, 4
public:
EventReport(EventId_t reportId_, object_id_t objectId_, uint32_t parameter1_,
uint32_t parameter2_):
reportId(reportId_),objectId(objectId_), parameter1(parameter1_),
parameter2(parameter2_) {}
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize,
SerializeIF::Endianness streamEndianness) const override
{
ReturnValue_t result = SerializeAdapter::serialize(&reportId, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&objectId, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&parameter1, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&parameter2, buffer, size,
maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return result;
}
virtual size_t getSerializedSize() const override {
uint32_t size = 0;
size += SerializeAdapter::getSerializedSize(&reportId);
size += SerializeAdapter::getSerializedSize(&objectId);
size += SerializeAdapter::getSerializedSize(&parameter1);
size += SerializeAdapter::getSerializedSize(&parameter2);
return size;
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_FAILED;
}
private:
EventId_t reportId;
object_id_t objectId;
uint32_t parameter1;
uint32_t parameter2;
};
#endif /* MISSION_PUS_SERVICEPACKETS_SERVICE5PACKETS_H_ */