PusServiceBase enhancements #103
@ -9,10 +9,11 @@
|
|||||||
object_id_t PusServiceBase::packetSource = 0;
|
object_id_t PusServiceBase::packetSource = 0;
|
||||||
object_id_t PusServiceBase::packetDestination = 0;
|
object_id_t PusServiceBase::packetDestination = 0;
|
||||||
|
|
||||||
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId) :
|
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid,
|
||||||
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), errorParameter1(
|
uint8_t setServiceId) :
|
||||||
0), errorParameter2(0), requestQueue(NULL) {
|
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) {
|
||||||
requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
|
requestQueue = QueueFactory::instance()->
|
||||||
|
createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
PusServiceBase::~PusServiceBase() {
|
PusServiceBase::~PusServiceBase() {
|
||||||
@ -20,50 +21,64 @@ PusServiceBase::~PusServiceBase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
|
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;
|
TmTcMessage message;
|
||||||
|
ReturnValue_t result = RETURN_FAILED;
|
||||||
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
|
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
|
||||||
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
|
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
|
||||||
// debug << "PusServiceBase::performOperation: Receiving from MQ ID: " << std::hex << this->requestQueue.getId()
|
// debug << "PusServiceBase::performOperation: Receiving from MQ ID: "
|
||||||
// << std::dec << " returned: " << status << std::endl;
|
// << std::hex << this->requestQueue.getId()
|
||||||
|
// << std::dec << " returned: " << status << std::endl;
|
||||||
if (status == RETURN_OK) {
|
if (status == RETURN_OK) {
|
||||||
this->currentPacket.setStoreAddress(message.getStorageId());
|
this->currentPacket.setStoreAddress(message.getStorageId());
|
||||||
// info << "Service " << (uint16_t) this->serviceId << ": new packet!" << std::endl;
|
//info << "Service " << (uint16_t) this->serviceId <<
|
||||||
|
// ": new packet!" << std::endl;
|
||||||
|
|
||||||
ReturnValue_t return_code = this->handleRequest();
|
result = this->handleRequest(currentPacket.getSubService());
|
||||||
// debug << "Service " << (uint16_t)this->serviceId << ": handleRequest returned: " << (int)return_code << std::endl;
|
|
||||||
if (return_code == RETURN_OK) {
|
// debug << "Service " << (uint16_t)this->serviceId <<
|
||||||
|
// ": handleRequest returned: " << (int)return_code << std::endl;
|
||||||
|
if (result == RETURN_OK) {
|
||||||
this->verifyReporter.sendSuccessReport(
|
this->verifyReporter.sendSuccessReport(
|
||||||
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
|
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this->verifyReporter.sendFailureReport(
|
this->verifyReporter.sendFailureReport(
|
||||||
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
|
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
|
||||||
return_code, 0, errorParameter1, errorParameter2);
|
result, 0, errorParameter1, errorParameter2);
|
||||||
}
|
}
|
||||||
this->currentPacket.deletePacket();
|
this->currentPacket.deletePacket();
|
||||||
errorParameter1 = 0;
|
errorParameter1 = 0;
|
||||||
errorParameter2 = 0;
|
errorParameter2 = 0;
|
||||||
} else if (status == MessageQueueIF::EMPTY) {
|
}
|
||||||
|
else if (status == MessageQueueIF::EMPTY) {
|
||||||
status = RETURN_OK;
|
status = RETURN_OK;
|
||||||
// debug << "PusService " << (uint16_t)this->serviceId << ": no new packet." << std::endl;
|
// debug << "PusService " << (uint16_t)this->serviceId <<
|
||||||
|
// ": no new packet." << std::endl;
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sif::error << "PusServiceBase::performOperation: Service "
|
sif::error << "PusServiceBase::performOperation: Service "
|
||||||
<< (uint16_t) this->serviceId
|
<< (uint16_t) this->serviceId
|
||||||
<< ": Error receiving packet. Code: " << std::hex << status
|
<< ": Error receiving packet. Code: " << std::hex << status
|
||||||
<< std::dec << std::endl;
|
<< std::dec << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReturnValue_t return_code = this->performService();
|
|
||||||
if (return_code == RETURN_OK) {
|
|
||||||
return RETURN_OK;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
sif::error << "PusService " << (uint16_t) this->serviceId
|
|
||||||
<< ": performService returned with " << (int16_t) return_code
|
|
||||||
<< std::endl;
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t PusServiceBase::getIdentifier() {
|
uint16_t PusServiceBase::getIdentifier() {
|
||||||
@ -79,19 +94,28 @@ ReturnValue_t PusServiceBase::initialize() {
|
|||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
AcceptsTelemetryIF* dest_service = objectManager->get<AcceptsTelemetryIF>(
|
AcceptsTelemetryIF* destService = objectManager->get<AcceptsTelemetryIF>(
|
||||||
packetDestination);
|
packetDestination);
|
||||||
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
|
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
|
||||||
packetSource);
|
packetSource);
|
||||||
if ((dest_service != NULL) && (distributor != NULL)) {
|
if ((destService != nullptr) && (distributor != nullptr)) {
|
||||||
this->requestQueue->setDefaultDestination(
|
this->requestQueue->setDefaultDestination(
|
||||||
dest_service->getReportReceptionQueue());
|
destService->getReportReceptionQueue());
|
||||||
distributor->registerService(this);
|
distributor->registerService(this);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sif::error << "PusServiceBase::PusServiceBase: Service "
|
sif::error << "PusServiceBase::PusServiceBase: Service "
|
||||||
<< (uint32_t) this->serviceId << ": Configuration error."
|
<< (uint32_t) this->serviceId << ": Configuration error."
|
||||||
<< " Make sure packetSource and packetDestination are defined correctly" << std::endl;
|
<< " Make sure packetSource and packetDestination are defined "
|
||||||
|
"correctly" << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef PUSSERVICEBASE_H_
|
#ifndef FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
|
||||||
#define PUSSERVICEBASE_H_
|
#define FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
|
||||||
|
|
||||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||||
#include <framework/objectmanager/SystemObject.h>
|
#include <framework/objectmanager/SystemObject.h>
|
||||||
@ -9,7 +9,6 @@
|
|||||||
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
||||||
#include <framework/tmtcservices/VerificationCodes.h>
|
#include <framework/tmtcservices/VerificationCodes.h>
|
||||||
#include <framework/tmtcservices/VerificationReporter.h>
|
#include <framework/tmtcservices/VerificationReporter.h>
|
||||||
#include <framework/internalError/InternalErrorReporterIF.h>
|
|
||||||
#include <framework/ipc/MessageQueueIF.h>
|
#include <framework/ipc/MessageQueueIF.h>
|
||||||
|
|
||||||
namespace Factory{
|
namespace Factory{
|
||||||
@ -17,72 +16,100 @@ void setStaticFrameworkObjectIds();
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \defgroup pus_services PUS Service Framework
|
* @defgroup pus_services PUS Service Framework
|
||||||
* These group contains all implementations of PUS Services in the OBSW.
|
* These group contains all implementations of PUS Services in the OBSW.
|
||||||
* Most of the Services are directly taken from the ECSS PUS Standard.
|
* 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.
|
* @brief This class is the basis for all PUS Services,
|
||||||
* It manages Telecommand reception and the generation of Verification Reports. Every class that inherits
|
* which can immediately process Telecommand Packets.
|
||||||
* from this abstract class has to implement handleRequest and performService. Services that are created with this
|
* @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.
|
* 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.
|
* All PUS Services are System Objects, so an Object ID needs to be specified
|
||||||
* \ingroup pus_services
|
* on construction.
|
||||||
|
* @ingroup pus_services
|
||||||
*/
|
*/
|
||||||
class PusServiceBase : public ExecutableObjectIF, public AcceptsTelecommandsIF, public SystemObject, public HasReturnvaluesIF {
|
class PusServiceBase : public ExecutableObjectIF,
|
||||||
|
public AcceptsTelecommandsIF,
|
||||||
|
public SystemObject,
|
||||||
|
public HasReturnvaluesIF {
|
||||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* The constructor for the class.
|
* @brief The passed values are set, but inter-object initialization is
|
||||||
* The passed values are set, but inter-object initialization is done in the initialize method.
|
* done in the initialize method.
|
||||||
* @param setObjectId The system object identifier of this Service instance.
|
* @param setObjectId
|
||||||
* @param set_apid The APID the Service is instantiated for.
|
* The system object identifier of this Service instance.
|
||||||
* @param set_service_id The Service Identifier as specified in ECSS PUS.
|
* @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);
|
PusServiceBase( object_id_t setObjectId, uint16_t setApid,
|
||||||
|
uint8_t setServiceId);
|
||||||
/**
|
/**
|
||||||
* The destructor is empty.
|
* The destructor is empty.
|
||||||
*/
|
*/
|
||||||
virtual ~PusServiceBase();
|
virtual ~PusServiceBase();
|
||||||
/**
|
/**
|
||||||
* @brief The handleRequest method shall handle any kind of Telecommand Request immediately.
|
* @brief The handleRequest method shall handle any kind of Telecommand
|
||||||
|
* Request immediately.
|
||||||
* @details
|
* @details
|
||||||
* Implemetations can take the Telecommand in currentPacket and perform any kind of operation.
|
* Implemetations can take the Telecommand in currentPacket and perform
|
||||||
* They may send additional "Start Success (1,3)" messages with the verifyReporter, but Completion
|
* any kind of operation.
|
||||||
* Success or Failure Reports are generated automatically after execution of this method.
|
* 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,
|
* If a Telecommand can not be executed within one call cycle,
|
||||||
* this Base class is not the right parent.
|
* this Base class is not the right parent.
|
||||||
*
|
*
|
||||||
* The child class may add additional error information by setting #errorParameters which are
|
* The child class may add additional error information by setting
|
||||||
* attached to the generated verification message.
|
* #errorParameters which aren attached to the generated verification
|
||||||
|
* message.
|
||||||
*
|
*
|
||||||
* Subservice checking should be implemented in this method.
|
* Subservice checking should be implemented in this method.
|
||||||
*
|
*
|
||||||
* @return The returned status_code is directly taken as main error code in the Verification Report.
|
* @return The returned status_code is directly taken as main error code
|
||||||
|
* in the Verification Report.
|
||||||
* On success, RETURN_OK shall be returned.
|
* On success, RETURN_OK shall be returned.
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t handleRequest() = 0;
|
virtual ReturnValue_t handleRequest(uint8_t subservice) = 0;
|
||||||
/**
|
/**
|
||||||
* In performService, implementations can handle periodic, non-TC-triggered activities.
|
* In performService, implementations can handle periodic,
|
||||||
|
* non-TC-triggered activities.
|
||||||
* The performService method is always called.
|
* The performService method is always called.
|
||||||
* @return A success or failure code that does not trigger any kind of verification message.
|
* @return Currently, everything other that RETURN_OK only triggers
|
||||||
|
* diagnostic output.
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t performService() = 0;
|
virtual ReturnValue_t performService() = 0;
|
||||||
/**
|
/**
|
||||||
* This method implements the typical activity of a simple PUS Service.
|
* 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
|
* It checks for new requests, and, if found, calls handleRequest, sends
|
||||||
|
* completion verification messages and deletes
|
||||||
* the TC requests afterwards.
|
* the TC requests afterwards.
|
||||||
* performService is always executed afterwards.
|
* performService is always executed afterwards.
|
||||||
* @return \c RETURN_OK if the periodic performService was successful.
|
* @return @c RETURN_OK if the periodic performService was successful.
|
||||||
* \c RETURN_FAILED else.
|
* @c RETURN_FAILED else.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t performOperation(uint8_t opCode);
|
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||||
virtual uint16_t getIdentifier();
|
virtual uint16_t getIdentifier() override;
|
||||||
MessageQueueId_t getRequestQueue();
|
MessageQueueId_t getRequestQueue() override;
|
||||||
virtual ReturnValue_t initialize();
|
virtual ReturnValue_t initialize() override;
|
||||||
|
|
||||||
|
virtual void setTaskIF(PeriodicTaskIF* taskHandle) override;
|
||||||
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
protected:
|
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.
|
* The APID of this instance of the Service.
|
||||||
*/
|
*/
|
||||||
@ -94,19 +121,19 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* One of two error parameters for additional error information.
|
* One of two error parameters for additional error information.
|
||||||
*/
|
*/
|
||||||
uint32_t errorParameter1;
|
uint32_t errorParameter1 = 0;
|
||||||
/**
|
/**
|
||||||
* One of two error parameters for additional error information.
|
* One of two error parameters for additional error information.
|
||||||
*/
|
*/
|
||||||
uint32_t errorParameter2;
|
uint32_t errorParameter2 = 0;
|
||||||
/**
|
/**
|
||||||
* This is a complete instance of the Telecommand reception queue of the class.
|
* This is a complete instance of the telecommand reception queue
|
||||||
* It is initialized on construction of the class.
|
* of the class. It is initialized on construction of the class.
|
||||||
*/
|
*/
|
||||||
MessageQueueIF* requestQueue;
|
MessageQueueIF* requestQueue = nullptr;
|
||||||
/**
|
/**
|
||||||
* An instance of the VerificationReporter class, that simplifies sending any kind of
|
* An instance of the VerificationReporter class, that simplifies
|
||||||
* Verification Message to the TC Verification Service.
|
* sending any kind of verification message to the TC Verification Service.
|
||||||
*/
|
*/
|
||||||
VerificationReporter verifyReporter;
|
VerificationReporter verifyReporter;
|
||||||
/**
|
/**
|
||||||
@ -121,9 +148,12 @@ protected:
|
|||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* This constant sets the maximum number of packets accepted per call.
|
* This constant sets the maximum number of packets accepted per call.
|
||||||
* Remember that one packet must be completely handled in one #handleRequest call.
|
* Remember that one packet must be completely handled in one
|
||||||
|
* #handleRequest call.
|
||||||
*/
|
*/
|
||||||
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
|
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
|
||||||
|
|
||||||
|
void handleRequestQueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PUSSERVICEBASE_H_ */
|
#endif /* PUSSERVICEBASE_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user