tmtc bridge improvements

This commit is contained in:
Robin Müller 2020-07-09 19:31:28 +02:00
parent 9f4f8d945c
commit 133ed9586b
2 changed files with 63 additions and 48 deletions

View File

@ -5,11 +5,13 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/globalfunctions/arrayprinter.h> #include <framework/globalfunctions/arrayprinter.h>
TmTcBridge::TmTcBridge(object_id_t objectId_, TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t ccsdsPacketDistributor_): SystemObject(objectId_), object_id_t tmStoreId, object_id_t tcStoreId):
ccsdsPacketDistributor(ccsdsPacketDistributor_) SystemObject(objectId),tmStoreId(tmStoreId), tcStoreId(tcStoreId),
tcDestination(tcDestination)
{ {
TmTcReceptionQueue = QueueFactory::instance()-> tmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
} }
@ -42,20 +44,27 @@ ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(
} }
ReturnValue_t TmTcBridge::initialize() { ReturnValue_t TmTcBridge::initialize() {
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE); tcStore = objectManager->get<StorageManagerIF>(tcStoreId);
if (tcStore == NULL) { if (tcStore == nullptr) {
return RETURN_FAILED; 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>(objects::TM_STORE); tmStore = objectManager->get<StorageManagerIF>(tmStoreId);
if (tmStore == NULL) { if (tmStore == nullptr) {
return RETURN_FAILED; 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 = AcceptsTelecommandsIF* tcDistributor =
objectManager->get<AcceptsTelecommandsIF>(ccsdsPacketDistributor); objectManager->get<AcceptsTelecommandsIF>(tcDestination);
if (tcDistributor == NULL) { if (tcDistributor == nullptr) {
return RETURN_FAILED; sif::error << "TmTcBridge::initialize: TC Distributor invalid"
<< std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
} }
TmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());
tmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());
return RETURN_OK; return RETURN_OK;
} }
@ -73,10 +82,7 @@ ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
} }
ReturnValue_t TmTcBridge::handleTc() { ReturnValue_t TmTcBridge::handleTc() {
uint8_t * recvBuffer = nullptr; return HasReturnvaluesIF::RETURN_OK;
size_t recvLen = 0;
ReturnValue_t result = receiveTc(&recvBuffer, &recvLen);
return result;
} }
ReturnValue_t TmTcBridge::handleTm() { ReturnValue_t TmTcBridge::handleTm() {
@ -97,8 +103,8 @@ ReturnValue_t TmTcBridge::handleTmQueue() {
TmTcMessage message; TmTcMessage message;
const uint8_t* data = nullptr; const uint8_t* data = nullptr;
size_t size = 0; size_t size = 0;
for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message); for (ReturnValue_t result = tmTcReceptionQueue->receiveMessage(&message);
result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message)) result == RETURN_OK; result = tmTcReceptionQueue->receiveMessage(&message))
{ {
if(communicationLinkUp == false) { if(communicationLinkUp == false) {
result = storeDownlinkData(&message); result = storeDownlinkData(&message);
@ -183,10 +189,20 @@ void TmTcBridge::registerCommDisconnect() {
} }
MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) { MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
return TmTcReceptionQueue->getId(); return tmTcReceptionQueue->getId();
} }
void TmTcBridge::printData(uint8_t * data, size_t dataLen) { void TmTcBridge::printData(uint8_t * data, size_t dataLen) {
arrayprinter::print(data, 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();
}

View File

@ -1,16 +1,18 @@
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ #ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ #define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#include <framework/objectmanager/SystemObject.h>
#include <framework/tmtcservices/AcceptsTelemetryIF.h> #include <framework/tmtcservices/AcceptsTelemetryIF.h>
#include <framework/tasks/ExecutableObjectIF.h> #include <framework/tasks/ExecutableObjectIF.h>
#include <framework/ipc/MessageQueueIF.h> #include <framework/ipc/MessageQueueIF.h>
#include <framework/storagemanager/StorageManagerIF.h> #include <framework/storagemanager/StorageManagerIF.h>
#include <framework/objectmanager/SystemObject.h> #include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/tmtcservices/TmTcMessage.h>
#include <framework/container/FIFO.h> #include <framework/container/FIFO.h>
#include <framework/tmtcservices/TmTcMessage.h>
class TmTcBridge : public AcceptsTelemetryIF, class TmTcBridge : public AcceptsTelemetryIF,
public AcceptsTelecommandsIF,
public ExecutableObjectIF, public ExecutableObjectIF,
public HasReturnvaluesIF, public HasReturnvaluesIF,
public SystemObject { public SystemObject {
@ -22,7 +24,8 @@ public:
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_); TmTcBridge(object_id_t objectId, object_id_t tcDestination,
object_id_t tmStoreId, object_id_t tcStoreId);
virtual ~TmTcBridge(); virtual ~TmTcBridge();
/** /**
@ -57,45 +60,41 @@ public:
*/ */
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/**
* Return TMTC Reception Queue /** AcceptsTelemetryIF override */
* @param virtualChannel virtual MessageQueueId_t getReportReceptionQueue(
* @return
*/
MessageQueueId_t getReportReceptionQueue(
uint8_t virtualChannel = 0) override; uint8_t virtualChannel = 0) override;
/** AcceptsTelecommandsIF override */
virtual uint16_t getIdentifier() override;
virtual MessageQueueId_t getRequestQueue() override;
protected: 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. //! Used to send and receive TMTC messages.
//! TmTcMessage is used to transport messages between tasks. //! TmTcMessage is used to transport messages between tasks.
MessageQueueIF* TmTcReceptionQueue = nullptr; MessageQueueIF* tmTcReceptionQueue = nullptr;
StorageManagerIF* tcStore = nullptr;
StorageManagerIF* tmStore = nullptr; StorageManagerIF* tmStore = nullptr;
object_id_t ccsdsPacketDistributor = 0; StorageManagerIF* tcStore = nullptr;
//! Used to specify whether communication link is up
bool communicationLinkUp = false; //! Used to specify whether communication link is up by default.
bool communicationLinkUp = true;
bool tmStored = false; bool tmStored = false;
/** /**
* @brief Handle TC reception * @brief Handle TC reception
* @details * @details
* Default implementation provided, but is empty. * Default implementation provided, but is empty.
* Child handler should override this in most cases orsend TC to the * In most cases, TC reception will be handled in a separate task anyway.
* TC distributor directly with the address of the reception queue by
* calling getReportRecptionQueue()
* @return * @return
*/ */
virtual ReturnValue_t handleTc(); virtual ReturnValue_t handleTc();
/**
* Implemented by child class. Perform receiving of Telecommand,
* for example by implementing specific drivers or wrappers,
* e.g. UART Communication or an ethernet stack
* @param recvBuffer [out] Received data
* @param size [out] Size of received data
* @return
*/
virtual ReturnValue_t receiveTc(uint8_t ** recvBuffer, size_t * size) = 0;
/** /**
* Handle Telemetry. Default implementation provided. * Handle Telemetry. Default implementation provided.
* Calls sendTm() * Calls sendTm()