all necessary modifications

This commit is contained in:
Robin Müller 2022-09-14 20:21:03 +02:00
parent 0849c8a08d
commit 237e29cc59
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
12 changed files with 91 additions and 112 deletions

View File

@ -18,7 +18,7 @@
TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId,
object_id_t tcStoreId)
: TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
: TmTcBridge("TCP TMTC Bridge", objectId, tcDestination, tmStoreId, tcStoreId) {
mutex = MutexFactory::instance()->createMutex();
// Connection is always up, TM is requested by connecting to server and receiving packets
registerCommConnect();

View File

@ -22,7 +22,7 @@ const std::string UdpTmTcBridge::DEFAULT_SERVER_PORT = tcpip::DEFAULT_SERVER_POR
UdpTmTcBridge::UdpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
const std::string &udpServerPort_, object_id_t tmStoreId,
object_id_t tcStoreId)
: TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
: TmTcBridge("UDP TMTC Bridge", objectId, tcDestination, tmStoreId, tcStoreId) {
if (udpServerPort_.empty()) {
udpServerPort = DEFAULT_SERVER_PORT;
} else {

View File

@ -59,7 +59,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() {
}
}
MessageQueueId_t CCSDSDistributor::getRequestQueue() { return tcQueue->getId(); }
MessageQueueId_t CCSDSDistributor::getRequestQueue() const { return tcQueue->getId(); }
ReturnValue_t CCSDSDistributor::registerApplication(AcceptsTelecommandsIF* application) {
ReturnValue_t returnValue = returnvalue::OK;
@ -80,7 +80,7 @@ ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid, MessageQueueI
return returnValue;
}
uint16_t CCSDSDistributor::getIdentifier() { return 0; }
uint32_t CCSDSDistributor::getIdentifier() const { return 0; }
ReturnValue_t CCSDSDistributor::initialize() {
if (packetChecker == nullptr) {

View File

@ -35,10 +35,10 @@ class CCSDSDistributor : public TcDistributor,
*/
~CCSDSDistributor() override;
MessageQueueId_t getRequestQueue() override;
MessageQueueId_t getRequestQueue() const override;
ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override;
ReturnValue_t registerApplication(AcceptsTelecommandsIF* application) override;
uint16_t getIdentifier() override;
uint32_t getIdentifier() const override;
ReturnValue_t initialize() override;
protected:

View File

@ -1,4 +1,4 @@
target_sources(
${LIB_FSFW_NAME}
PRIVATE CcsdsDistributor.cpp PusDistributor.cpp TcDistributorBase.cpp
PusPacketChecker.cpp TcPacketCheckCFDP.cpp CcsdsPacketChecker.cpp)
PRIVATE CCSDSDistributor.cpp PusDistributor.cpp TcDistributor.cpp
TcPacketCheckCFDP.cpp CcsdsPacketChecker.cpp)

View File

@ -10,19 +10,19 @@ ReturnValue_t CcsdsPacketChecker::checkPacket(const SpacePacketReader& currentPa
size_t packetLen) {
if (checkApid) {
if (currentPacket.getApid() != apid) {
return tmtcdistrib::INVALID_APID;
return tcdistrib::INVALID_APID;
}
}
if (currentPacket.getVersion() != ccsdsVersion) {
return tmtcdistrib::INVALID_CCSDS_VERSION;
return tcdistrib::INVALID_CCSDS_VERSION;
}
if (currentPacket.getPacketType() != packetType) {
return tmtcdistrib::INVALID_PACKET_TYPE;
return tcdistrib::INVALID_PACKET_TYPE;
}
// This assumes that the getFullPacketLen version uses the space packet data length field
if (currentPacket.getFullPacketLen() != packetLen) {
return tmtcdistrib::INCOMPLETE_PACKET;
return tcdistrib::INCOMPLETE_PACKET;
}
return returnvalue::OK;
}

View File

@ -3,14 +3,14 @@
#include "definitions.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tcdistribution/CcsdsDistributorIF.h"
#include "fsfw/tcdistribution/CCSDSDistributorIF.h"
#include "fsfw/tmtcservices/PusVerificationReport.h"
#define PUS_DISTRIBUTOR_DEBUGGING 0
PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId,
CcsdsDistributorIF* distributor, StorageManagerIF* store_)
: TcDistributorBase(setObjectId),
CCSDSDistributorIF* distributor, StorageManagerIF* store_)
: TcDistributor(setObjectId),
store(store_),
checker(setApid, ccsds::PacketType::TC),
ccsdsDistributor(distributor),
@ -18,41 +18,42 @@ PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId,
PusDistributor::~PusDistributor() = default;
ReturnValue_t PusDistributor::selectDestination(MessageQueueId_t& destId) {
PusDistributor::TcMqMapIter PusDistributor::selectDestination() {
#if FSFW_CPP_OSTREAM_ENABLED == 1 && PUS_DISTRIBUTOR_DEBUGGING == 1
store_address_t storeId = currentMessage.getStorageId();
sif::debug << "PUSDistributor::handlePacket received: " << storeId.poolIndex << ", "
<< storeId.packetIndex << std::endl;
#endif
auto queueMapIt = queueMap.end();
// TODO: Need to set the data
const uint8_t* packetPtr = nullptr;
size_t packetLen = 0;
ReturnValue_t result =
store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != returnvalue::OK;
if (result != returnvalue::OK) {
tcStatus = PACKET_LOST;
return result;
if (store->getData(currentMessage.getStorageId(), &packetPtr, &packetLen) != returnvalue::OK) {
return queueMapIt;
}
result = reader.setReadOnlyData(packetPtr, packetLen);
ReturnValue_t result = reader.setReadOnlyData(packetPtr, packetLen);
if (result != returnvalue::OK) {
tcStatus = PACKET_LOST;
return result;
return queueMapIt;
}
// CRC check done by checker
result = reader.parseDataWithoutCrcCheck();
if (result != returnvalue::OK) {
tcStatus = PACKET_LOST;
return result;
return queueMapIt;
}
if (reader.getFullData() != nullptr) {
tcStatus = checker.checkPacket(reader, reader.getFullPacketLen());
if (tcStatus != returnvalue::OK) {
checkerFailurePrinter();
}
uint8_t pusId = reader.getService();
auto iter = receiverMap.find(pusId);
if (iter == receiverMap.end()) {
uint32_t queue_id = reader.getService();
queueMapIt = queueMap.find(queue_id);
} else {
tcStatus = PACKET_LOST;
}
if (queueMapIt == this->queueMap.end()) {
tcStatus = DESTINATION_NOT_FOUND;
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -62,15 +63,16 @@ ReturnValue_t PusDistributor::selectDestination(MessageQueueId_t& destId) {
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif
}
destId = iter->second.destId;
if (tcStatus != returnvalue::OK) {
return this->queueMap.end();
} else {
tcStatus = PACKET_LOST;
return queueMapIt;
}
return tcStatus;
}
ReturnValue_t PusDistributor::registerService(const AcceptsTelecommandsIF& service) {
uint16_t serviceId = service.getIdentifier();
ReturnValue_t PusDistributor::registerService(AcceptsTelecommandsIF* service) {
uint16_t serviceId = service->getIdentifier();
#if PUS_DISTRIBUTOR_DEBUGGING == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Service ID: " << static_cast<int>(serviceId) << std::endl;
@ -78,8 +80,8 @@ ReturnValue_t PusDistributor::registerService(const AcceptsTelecommandsIF& servi
sif::printInfo("Service ID: %d\n", static_cast<int>(serviceId));
#endif
#endif
MessageQueueId_t queue = service.getRequestQueue();
auto returnPair = receiverMap.emplace(serviceId, ServiceInfo(service.getName(), queue));
MessageQueueId_t queue = service->getRequestQueue();
auto returnPair = queueMap.emplace(serviceId, queue);
if (not returnPair.second) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -128,7 +130,7 @@ ReturnValue_t PusDistributor::initialize() {
sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl;
#else
sif::printError("PusDistributor::initialize: Packet source invalid\n");
sif::printError("Make sure it exists and implements CcsdsDistributorIF\n");
sif::printError("Make sure it exists and implements CCSDSDistributorIF\n");
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
}
@ -139,29 +141,28 @@ ReturnValue_t PusDistributor::initialize() {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
}
return ccsdsDistributor->registerApplication(CcsdsDistributorIF::DestInfo(*this, false));
return ccsdsDistributor->registerApplication(this);
}
void PusDistributor::checkerFailurePrinter() const {
#if FSFW_VERBOSE_LEVEL >= 1
const char* reason = "Unknown reason";
if (tcStatus == tmtcdistrib::INCORRECT_CHECKSUM) {
reason = "Checksum Error";
} else if (tcStatus == tmtcdistrib::INCORRECT_PRIMARY_HEADER) {
reason = "Incorrect Primary Header";
} else if (tcStatus == tmtcdistrib::INVALID_APID) {
reason = "Illegal APID";
} else if (tcStatus == tmtcdistrib::INCORRECT_SECONDARY_HEADER) {
reason = "Incorrect Secondary Header";
} else if (tcStatus == tmtcdistrib::INCOMPLETE_PACKET) {
reason = "Incomplete packet";
const char* keyword = "unnamed error";
if (tcStatus == tcdistrib::INCORRECT_CHECKSUM) {
keyword = "checksum";
} else if (tcStatus == tcdistrib::INCORRECT_PRIMARY_HEADER) {
keyword = "incorrect primary header";
} else if (tcStatus == tcdistrib::INVALID_APID) {
keyword = "illegal APID";
} else if (tcStatus == tcdistrib::INCORRECT_SECONDARY_HEADER) {
keyword = "incorrect secondary header";
} else if (tcStatus == tcdistrib::INCOMPLETE_PACKET) {
keyword = "incomplete packet";
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "PUSDistributor::handlePacket: Check failed: " << reason << std::endl;
sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " << keyword << " error"
<< std::endl;
#else
sif::printWarning("PUSDistributor::handlePacket: Check failed: %s\n", reason);
sif::printWarning("PUSDistributor::handlePacket: Packet format invalid, %s error\n", keyword);
#endif
#endif
}
const char* PusDistributor::getName() const { return "PUS Distributor"; }

View File

@ -1,17 +1,15 @@
#ifndef FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_
#define FSFW_TCDISTRIBUTION_PUSDISTRIBUTOR_H_
#include <map>
#include "PusDistributorIF.h"
#include "PUSDistributorIF.h"
#include "PusPacketChecker.h"
#include "TcDistributorBase.h"
#include "TcDistributor.h"
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/tmtcpacket/pus/tc.h"
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
#include "fsfw/tmtcservices/VerificationReporter.h"
class CcsdsDistributorIF;
class CCSDSDistributorIF;
/**
* This class accepts PUS Telecommands and forwards them to Application
@ -19,9 +17,7 @@ class CcsdsDistributorIF;
* sends acceptance success or failure messages.
* @ingroup tc_distribution
*/
class PusDistributor : public TcDistributorBase,
public PusDistributorIF,
public AcceptsTelecommandsIF {
class PusDistributor : public TcDistributor, public PUSDistributorIF, public AcceptsTelecommandsIF {
public:
/**
* The ctor passes @c set_apid to the checker class and calls the
@ -29,31 +25,20 @@ class PusDistributor : public TcDistributorBase,
* @param setApid The APID of this receiving Application.
* @param setObjectId Object ID of the distributor itself
* @param setPacketSource Object ID of the source of TC packets.
* Must implement CcsdsDistributorIF.
* Must implement CCSDSDistributorIF.
*/
PusDistributor(uint16_t setApid, object_id_t setObjectId, CcsdsDistributorIF* packetSource,
PusDistributor(uint16_t setApid, object_id_t setObjectId, CCSDSDistributorIF* packetSource,
StorageManagerIF* store = nullptr);
[[nodiscard]] const char* getName() const override;
/**
* The destructor is empty.
*/
~PusDistributor() override;
ReturnValue_t registerService(const AcceptsTelecommandsIF& service) override;
[[nodiscard]] MessageQueueId_t getRequestQueue() const override;
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
MessageQueueId_t getRequestQueue() const override;
ReturnValue_t initialize() override;
[[nodiscard]] uint32_t getIdentifier() const override;
uint32_t getIdentifier() const override;
protected:
struct ServiceInfo {
ServiceInfo(const char* name, MessageQueueId_t destId) : name(name), destId(destId) {}
const char* name;
MessageQueueId_t destId;
};
/// PUS recipient map. The key value will generally be the PUS Service
using PusReceiverMap = std::map<uint8_t, ServiceInfo>;
PusReceiverMap receiverMap;
StorageManagerIF* store;
/**
* This attribute contains the class, that performs a formal packet check.
@ -65,7 +50,7 @@ class PusDistributor : public TcDistributorBase,
*/
VerificationReporterIF* verifyChannel = nullptr;
//! Cached for initialization
CcsdsDistributorIF* ccsdsDistributor = nullptr;
CCSDSDistributorIF* ccsdsDistributor = nullptr;
PusTcReader reader;
/**
@ -82,7 +67,7 @@ class PusDistributor : public TcDistributorBase,
* @return Iterator to map entry of found service id
* or iterator to @c map.end().
*/
ReturnValue_t selectDestination(MessageQueueId_t& destId) override;
TcMqMapIter selectDestination() override;
/**
* The callback here handles the generation of acceptance
* success/failure messages.

View File

@ -12,17 +12,17 @@ PusPacketChecker::PusPacketChecker(uint16_t apid, ccsds::PacketType packetType_,
ReturnValue_t PusPacketChecker::checkPacket(const PusTcReader& pusPacket, size_t packetLen) {
// Other primary header fields are checked by base class
if (not pusPacket.hasSecHeader()) {
return tmtcdistrib::INVALID_SEC_HEADER_FIELD;
return tcdistrib::INVALID_SEC_HEADER_FIELD;
}
uint16_t calculated_crc = CRC::crc16ccitt(pusPacket.getFullData(), pusPacket.getFullPacketLen());
if (calculated_crc != 0) {
return tmtcdistrib::INCORRECT_CHECKSUM;
return tcdistrib::INCORRECT_CHECKSUM;
}
if (pusPacket.getApid() != apid) {
return tmtcdistrib::INVALID_APID;
return tcdistrib::INVALID_APID;
}
if (pusPacket.getPusVersion() != pusVersion) {
return tmtcdistrib::INVALID_PUS_VERSION;
return tcdistrib::INVALID_PUS_VERSION;
}
return returnvalue::OK;
}

View File

@ -3,19 +3,16 @@
#include <cstdint>
#include "fsfw/events/Event.h"
#include "fsfw/events/fwSubsystemIdRanges.h"
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/returnvalues/returnvalue.h"
namespace tmtcdistrib {
static const uint8_t INTERFACE_ID = CLASS_ID::TMTC_DISTRIBUTION;
static constexpr ReturnValue_t NO_DESTINATION_FOUND = returnvalue::makeCode(INTERFACE_ID, 0);
static constexpr ReturnValue_t INVALID_CCSDS_VERSION = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(2);
static constexpr ReturnValue_t INVALID_PACKET_TYPE = MAKE_RETURN_CODE(3);
static constexpr ReturnValue_t INVALID_SEC_HEADER_FIELD = MAKE_RETURN_CODE(4);
static constexpr ReturnValue_t INCORRECT_PRIMARY_HEADER = MAKE_RETURN_CODE(5);
namespace tcdistrib {
static const uint8_t INTERFACE_ID = CLASS_ID::PACKET_CHECK;
static constexpr ReturnValue_t INVALID_CCSDS_VERSION = MAKE_RETURN_CODE(0);
static constexpr ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t INVALID_PACKET_TYPE = MAKE_RETURN_CODE(2);
static constexpr ReturnValue_t INVALID_SEC_HEADER_FIELD = MAKE_RETURN_CODE(3);
static constexpr ReturnValue_t INCORRECT_PRIMARY_HEADER = MAKE_RETURN_CODE(4);
static constexpr ReturnValue_t INCOMPLETE_PACKET = MAKE_RETURN_CODE(5);
static constexpr ReturnValue_t INVALID_PUS_VERSION = MAKE_RETURN_CODE(6);
@ -23,9 +20,5 @@ static constexpr ReturnValue_t INCORRECT_CHECKSUM = MAKE_RETURN_CODE(7);
static constexpr ReturnValue_t ILLEGAL_PACKET_SUBTYPE = MAKE_RETURN_CODE(8);
static constexpr ReturnValue_t INCORRECT_SECONDARY_HEADER = MAKE_RETURN_CODE(9);
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TMTC_DISTRIBUTION;
//! P1: Returnvalue, P2: 0 for TM issues, 1 for TC issues
static constexpr Event HANDLE_PACKET_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW);
}; // namespace tmtcdistrib
}; // namespace tcdistrib
#endif // FSFW_TMTCPACKET_DEFINITIONS_H

View File

@ -3,7 +3,7 @@
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tcdistribution/PusDistributorIF.h"
#include "fsfw/tcdistribution/PUSDistributorIF.h"
#include "fsfw/tmtcpacket/pus/tc.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
@ -70,7 +70,7 @@ ReturnValue_t CommandingServiceBase::initialize() {
if (packetSource == objects::NO_OBJECT) {
packetSource = defaultPacketSource;
}
auto* distributor = ObjectManager::instance()->get<PusDistributorIF>(packetSource);
auto* distributor = ObjectManager::instance()->get<PUSDistributorIF>(packetSource);
if (packetForwarding == nullptr or distributor == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -81,7 +81,7 @@ ReturnValue_t CommandingServiceBase::initialize() {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
distributor->registerService(*this);
distributor->registerService(this);
requestQueue->setDefaultDestination(packetForwarding->getReportReceptionQueue());
ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);

View File

@ -3,7 +3,7 @@
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tcdistribution/PusDistributorIF.h"
#include "fsfw/tcdistribution/PUSDistributorIF.h"
#include "fsfw/timemanager/CdsShortTimeStamper.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
#include "fsfw/tmtcservices/PusVerificationReport.h"
@ -111,7 +111,7 @@ ReturnValue_t PusServiceBase::initialize() {
}
if (psbParams.pusDistributor == nullptr) {
psbParams.pusDistributor = ObjectManager::instance()->get<PusDistributorIF>(PUS_DISTRIBUTOR);
psbParams.pusDistributor = ObjectManager::instance()->get<PUSDistributorIF>(PUS_DISTRIBUTOR);
if (psbParams.pusDistributor != nullptr) {
registerService(*psbParams.pusDistributor);
}
@ -193,8 +193,8 @@ void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) {
psbParams.verifReporter = &reporter;
}
ReturnValue_t PusServiceBase::registerService(PusDistributorIF& distributor) {
return distributor.registerService(*this);
ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) {
return distributor.registerService(this);
}
void PusServiceBase::setTmReceiver(AcceptsTelemetryIF& tmReceiver_) {