added srv17 and srv201

This commit is contained in:
Robin Müller 2020-08-19 17:00:50 +02:00
parent 7b998268cb
commit f90bd01282
5 changed files with 275 additions and 0 deletions

View File

@ -0,0 +1,84 @@
#include "CService201HealthCommanding.h"
#include "../health/HasHealthIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../health/HealthMessage.h"
#include "servicepackets/Service201Packets.h"
CService201HealthCommanding::CService201HealthCommanding(object_id_t objectId,
uint16_t apid, uint8_t serviceId):
CommandingServiceBase(objectId, apid, serviceId,
NUMBER_OF_PARALLEL_COMMANDS,COMMAND_TIMEOUT_SECONDS) {
}
CService201HealthCommanding::~CService201HealthCommanding() {
}
ReturnValue_t CService201HealthCommanding::isValidSubservice(uint8_t subservice) {
switch(subservice) {
case(Subservice::COMMAND_SET_HEALTH):
return RETURN_OK;
default:
sif::error << "Invalid Subservice" << std::endl;
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
}
}
ReturnValue_t CService201HealthCommanding::getMessageQueueAndObject(
uint8_t subservice, const uint8_t *tcData, size_t tcDataLen,
MessageQueueId_t *id, object_id_t *objectId) {
if(tcDataLen < sizeof(object_id_t)) {
return CommandingServiceBase::INVALID_TC;
}
SerializeAdapter::deSerialize(objectId, &tcData, &tcDataLen,
SerializeIF::Endianness::BIG);
return checkInterfaceAndAcquireMessageQueue(id,objectId);
}
ReturnValue_t CService201HealthCommanding::checkInterfaceAndAcquireMessageQueue(
MessageQueueId_t* messageQueueToSet, object_id_t* objectId) {
HasHealthIF * destination = objectManager->get<HasHealthIF>(*objectId);
if(destination == nullptr) {
return CommandingServiceBase::INVALID_OBJECT;
}
*messageQueueToSet = destination->getCommandQueue();
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CService201HealthCommanding::prepareCommand
(CommandMessage* message, uint8_t subservice, const uint8_t *tcData,
size_t tcDataLen, uint32_t *state, object_id_t objectId) {
HealthCommand healthCommand;
ReturnValue_t result = healthCommand.deSerialize(&tcData, &tcDataLen,
SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
return result;
} else {
HealthMessage::setHealthMessage(dynamic_cast<CommandMessage*>(message),
HealthMessage::HEALTH_SET, healthCommand.getHealth());
return result;
}
}
ReturnValue_t CService201HealthCommanding::handleReply
(const CommandMessage* reply, Command_t previousCommand,
uint32_t *state, CommandMessage* optionalNextCommand,
object_id_t objectId, bool *isStep) {
Command_t replyId = reply->getCommand();
if (replyId == HealthMessage::REPLY_HEALTH_SET) {
prepareHealthSetReply(reply);
}
return RETURN_OK;
}
void CService201HealthCommanding::prepareHealthSetReply(
const CommandMessage* reply) {
prepareHealthSetReply(reply);
uint8_t health = static_cast<uint8_t>(HealthMessage::getHealth(reply));
uint8_t oldHealth = static_cast<uint8_t>(HealthMessage::getOldHealth(reply));
HealthSetReply healthSetReply(health, oldHealth);
sendTmPacket(Subservice::REPLY_HEALTH_SET,&healthSetReply);
}

View File

@ -0,0 +1,58 @@
#ifndef FSFW_PUS_CSERVICE201HEALTHCOMMANDING_H_
#define FSFW_PUS_CSERVICE201HEALTHCOMMANDING_H_
#include "../tmtcservices/CommandingServiceBase.h"
/**
* @brief Custom PUS service to set health of all objects
* implementing hasHealthIF.
*
* Examples: Device Handlers, Assemblies or Subsystems.
* Full Documentation: ECSS-E-ST-70-41C or ECSS-E-70-41A
* Dissertation Baetz p. 115, 116, 165-167.
*
* This is a gateway service. It relays device commands using the software bus.
* This service is very closely tied to the Commanding Service Base template
* class. There is constant interaction between this Service Base und a
* child class like this service
*
*/
class CService201HealthCommanding: public CommandingServiceBase {
public:
static const uint8_t NUMBER_OF_PARALLEL_COMMANDS = 4;
static const uint16_t COMMAND_TIMEOUT_SECONDS = 60;
CService201HealthCommanding(object_id_t objectId, uint16_t apid,
uint8_t serviceId);
virtual~ CService201HealthCommanding();
protected:
/* CSB abstract function implementations */
ReturnValue_t isValidSubservice(uint8_t subservice) override;
ReturnValue_t getMessageQueueAndObject(uint8_t subservice,
const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id,
object_id_t *objectId) override;
/** Prepare health command */
ReturnValue_t prepareCommand(CommandMessage* message,
uint8_t subservice, const uint8_t *tcData, size_t tcDataLen,
uint32_t *state, object_id_t objectId) override;
/** Handle health reply */
ReturnValue_t handleReply(const CommandMessage* reply,
Command_t previousCommand, uint32_t *state,
CommandMessage* optionalNextCommand, object_id_t objectId,
bool *isStep) override;
private:
ReturnValue_t checkAndAcquireTargetID(object_id_t* objectIdToSet,
const uint8_t* tcData, size_t tcDataLen);
ReturnValue_t checkInterfaceAndAcquireMessageQueue(
MessageQueueId_t* MessageQueueToSet, object_id_t* objectId);
void prepareHealthSetReply(const CommandMessage *reply);
enum Subservice {
COMMAND_SET_HEALTH = 1, //!< [EXPORT] : [TC] Set health of target object
REPLY_HEALTH_SET = 2 //!< [EXPORT] : [TM] Reply to health set command which also provides old health
};
};
#endif /* FSFW_PUS_CSERVICE201HEALTHCOMMANDING_H_ */

41
pus/Service17Test.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "Service17Test.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../objectmanager/SystemObject.h"
#include "../tmtcpacket/pus/TmPacketStored.h"
Service17Test::Service17Test(object_id_t objectId,
uint16_t apid, uint8_t serviceId):
PusServiceBase(objectId, apid, serviceId),
packetSubCounter(0) {
}
Service17Test::~Service17Test() {
}
ReturnValue_t Service17Test::handleRequest(uint8_t subservice) {
switch(subservice){
case Subservice::CONNECTION_TEST: {
TmPacketStored connectionPacket(apid, serviceId,
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
connectionPacket.sendPacket(requestQueue->getDefaultDestination(),
requestQueue->getId());
return HasReturnvaluesIF::RETURN_OK;
}
case Subservice::EVENT_TRIGGER_TEST: {
TmPacketStored connectionPacket(apid, serviceId,
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
connectionPacket.sendPacket(requestQueue->getDefaultDestination(),
requestQueue->getId());
triggerEvent(TEST, 1234, 5678);
return RETURN_OK;
}
default:
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
}
}
ReturnValue_t Service17Test::performService() {
return HasReturnvaluesIF::RETURN_OK;
}

44
pus/Service17Test.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef MISSION_PUS_SERVICE17TEST_H_
#define MISSION_PUS_SERVICE17TEST_H_
#include "../tmtcservices/PusServiceBase.h"
#include "../objectmanager/SystemObject.h"
/**
* @brief Test Service
* Full Documentation: ECSS-E70-41A p.167
*
* The test service provides the capability to activate test functions
* implemented on-board and to report the results of such tests.
* Service capability:
* - TC[17,1]: Perform connection test
* - TM[17,2]: Send Connection Test Report
* - TC[17,128]: Perform connection test and trigger event
*
* @ingroup pus_services
*/
class Service17Test: public PusServiceBase {
public:
// Custom events which can be triggered
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_17;
static constexpr Event TEST = MAKE_EVENT(0, SEVERITY::INFO);
enum Subservice: uint8_t {
//! [EXPORT] : [COMMAND] Perform connection test
CONNECTION_TEST = 1,
//! [EXPORT] : [REPLY] Connection test reply
CONNECTION_TEST_REPORT = 2,
//! [EXPORT] : [COMMAND] Trigger test reply and test event
EVENT_TRIGGER_TEST = 128,
};
Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId);
virtual ~Service17Test();
virtual ReturnValue_t handleRequest(uint8_t subservice) override;
virtual ReturnValue_t performService() override;
protected:
uint16_t packetSubCounter = 0;
};
#endif /* MISSION_PUS_SERVICE17TEST_H_ */

View File

@ -0,0 +1,48 @@
#ifndef FSFW_PUS_SERVICEPACKETS_SERVICE201PACKETS_H_
#define FSFW_PUS_SERVICEPACKETS_SERVICE201PACKETS_H_
#include "../../serialize/SerialLinkedListAdapter.h"
#include "../../serialize/SerializeIF.h"
#include "../../health/HasHealthIF.h"
class HealthCommand: public SerialLinkedListAdapter<SerializeIF> { //!< [EXPORT] : [SUBSERVICE] 1
public:
HealthCommand() {
setLinks();
}
HasHealthIF::HealthState getHealth() {
return static_cast<HasHealthIF::HealthState>(health.entry);
}
private:
void setLinks() {
setStart(&objectId);
objectId.setNext(&health);
}
SerializeElement<uint32_t> objectId; //!< [EXPORT] : [COMMENT] Target object Id
SerializeElement<uint8_t> health; //!< [EXPORT] : [COMMENT] Health to set
};
class HealthSetReply: public SerialLinkedListAdapter<SerializeIF> { //!< [EXPORT] : [SUBSERVICE] 2
public:
HealthSetReply(uint8_t health_, uint8_t oldHealth_):
health(health_), oldHealth(oldHealth_)
{
setLinks();
}
private:
HealthSetReply(const HealthSetReply &reply);
void setLinks() {
setStart(&objectId);
objectId.setNext(&health);
health.setNext(&oldHealth);
}
SerializeElement<uint32_t> objectId; //!< [EXPORT] : [COMMENT] Source object ID
SerializeElement<uint8_t> health; //!< [EXPORT] : [COMMENT] New Health
SerializeElement<uint8_t> oldHealth; //!< [EXPORT] : [COMMENT] Old Health
};
#endif /* FSFW_PUS_SERVICEPACKETS_SERVICE201PACKETS_H_ */