Merge branch 'mueller_TmTcBridge_cherryPicked' into mueller_framework

This commit is contained in:
Robin Müller 2020-04-23 10:03:15 +02:00
commit db535e25f2
2 changed files with 66 additions and 52 deletions

View File

@ -1,10 +1,3 @@
/**
* @file TmTcBridge.cpp
*
* @date 26.12.2019
* @author R. Mueller
*/
#include <framework/tmtcservices/TmTcBridge.h> #include <framework/tmtcservices/TmTcBridge.h>
#include <framework/ipc/QueueFactory.h> #include <framework/ipc/QueueFactory.h>
@ -13,14 +6,26 @@
TmTcBridge::TmTcBridge(object_id_t objectId_, TmTcBridge::TmTcBridge(object_id_t objectId_,
object_id_t ccsdsPacketDistributor_): SystemObject(objectId_), object_id_t ccsdsPacketDistributor_): SystemObject(objectId_),
ccsdsPacketDistributor(ccsdsPacketDistributor_) ccsdsPacketDistributor(ccsdsPacketDistributor_),
sentPacketsPerCycle(5)
{ {
TmTcReceptionQueue = QueueFactory::instance()-> TmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
} }
TmTcBridge::~TmTcBridge() {} TmTcBridge::~TmTcBridge() {}
ReturnValue_t TmTcBridge::setNumberOfSentPacketsPerCycle(
uint8_t sentPacketsPerCycle) {
if(sentPacketsPerCycle <= MAX_STORED_DATA_SENT_PER_CYCLE) {
this->sentPacketsPerCycle = sentPacketsPerCycle;
return RETURN_OK;
}
else {
return RETURN_FAILED;
}
}
ReturnValue_t TmTcBridge::initialize() { ReturnValue_t TmTcBridge::initialize() {
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE); tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
if (tcStore == NULL) { if (tcStore == NULL) {
@ -53,12 +58,14 @@ ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
} }
ReturnValue_t TmTcBridge::handleTc() { ReturnValue_t TmTcBridge::handleTc() {
ReturnValue_t result = receiveTc(&recvBuffer, &size); uint8_t * recvBuffer = nullptr;
size_t recvLen = 0;
ReturnValue_t result = receiveTc(&recvBuffer, &recvLen);
return result; return result;
} }
ReturnValue_t TmTcBridge::handleTm() { ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t result = readTmQueue(); ReturnValue_t result = handleTmQueue();
if(result != RETURN_OK) { if(result != RETURN_OK) {
error << "TMTC Bridge: Reading TM Queue failed" << std::endl; error << "TMTC Bridge: Reading TM Queue failed" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
@ -71,7 +78,7 @@ ReturnValue_t TmTcBridge::handleTm() {
} }
ReturnValue_t TmTcBridge::readTmQueue() { 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;
@ -101,13 +108,13 @@ ReturnValue_t TmTcBridge::readTmQueue() {
} }
ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) { ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
info << "TMTC Bridge: Comm Link down. " //debug << "TMTC Bridge: Comm Link down. "
"Saving packet ID to be sent later\r\n" << std::flush; // "Saving packet ID to be sent later\r\n" << std::flush;
store_address_t storeId = 0; store_address_t storeId = 0;
if(fifo.full()) { if(fifo.full()) {
info << "TMTC Bridge: TM downlink max. number of stored packet IDs reached." error << "TMTC Bridge: TM downlink max. number of stored packet IDs "
" Overwriting old data" << std::endl; "reached! Overwriting old data" << std::endl;
fifo.retrieve(&storeId); fifo.retrieve(&storeId);
tmStore->deleteData(storeId); tmStore->deleteData(storeId);
} }
@ -120,15 +127,17 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
ReturnValue_t TmTcBridge::sendStoredTm() { ReturnValue_t TmTcBridge::sendStoredTm() {
uint8_t counter = 0; uint8_t counter = 0;
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
while(!fifo.empty() && counter < MAX_STORED_DATA_SENT_PER_CYCLE) { while(!fifo.empty() && counter < sentPacketsPerCycle) {
info << "TMTC Bridge: Sending stored TM data. There are " //info << "TMTC Bridge: Sending stored TM data. There are "
<< (int) fifo.size() << " left to send\r\n" << std::flush; // << (int) fifo.size() << " left to send\r\n" << std::flush;
store_address_t storeId; store_address_t storeId;
const uint8_t* data = NULL; const uint8_t* data = NULL;
size_t size = 0; size_t size = 0;
fifo.retrieve(&storeId); fifo.retrieve(&storeId);
result = tmStore->getData(storeId, &data, &size); result = tmStore->getData(storeId, &data, &size);
sendTm(data,size); sendTm(data,size);
if(result != RETURN_OK) { if(result != RETURN_OK) {
error << "TMTC Bridge: Could not send stored downlink data" error << "TMTC Bridge: Could not send stored downlink data"
<< std::endl; << std::endl;
@ -162,7 +171,7 @@ MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
return TmTcReceptionQueue->getId(); return TmTcReceptionQueue->getId();
} }
void TmTcBridge::printData(uint8_t * data, uint32_t dataLen) { void TmTcBridge::printData(uint8_t * data, size_t dataLen) {
info << "TMTC Bridge: Printing data: ["; info << "TMTC Bridge: Printing data: [";
for(uint32_t i=0;i<dataLen;i++) { for(uint32_t i=0;i<dataLen;i++) {
info << std::hex << (int)data[i]; info << std::hex << (int)data[i];

View File

@ -1,9 +1,3 @@
/**
* @file TmTcBridge.h
*
* @date 26.12.2019
*/
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ #ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ #define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
@ -21,32 +15,42 @@ class TmTcBridge : public AcceptsTelemetryIF,
public HasReturnvaluesIF, public HasReturnvaluesIF,
public SystemObject { public SystemObject {
public: public:
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
static constexpr uint8_t MAX_STORED_DATA_SENT_PER_CYCLE = 10;
static constexpr uint8_t MAX_DOWNLINK_PACKETS_STORED = 15;
TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_); TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_);
virtual ~TmTcBridge(); virtual ~TmTcBridge();
/** /**
* Initializes basic FSFW components for the TMTC Bridge * Set number of packets sent per performOperation().Please note that this
* @return * value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE
* @param sentPacketsPerCycle
* @return -@c RETURN_OK if value was set successfully
* -@c RETURN_FAILED otherwise, stored value stays the same
*/ */
virtual ReturnValue_t initialize(); ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle);
void registerCommConnect();
void registerCommDisconnect();
/** /**
* @brief The performOperation method is executed in a task. * Initializes necessary FSFW components for the TMTC Bridge
* @details There are no restrictions for calls within this method, so any * @return
* other member of the class can be used.
* @return Currently, the return value is ignored.
*/ */
virtual ReturnValue_t performOperation(uint8_t operationCode = 0); ReturnValue_t initialize() override;
/**
* @brief Handles TMTC reception
*/
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/** /**
* Return TMTC Reception Queue * Return TMTC Reception Queue
* @param virtualChannel * @param virtualChannel
* @return * @return
*/ */
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0); MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override;
void registerCommConnect();
void registerCommDisconnect();
protected: protected:
//! 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.
@ -59,19 +63,25 @@ protected:
bool tmStored = false; bool tmStored = false;
/** /**
* Handle TC reception. Default implementation provided * @brief Handle TC reception
* @details
* Default implementation provided, but is empty.
* Child handler should override this in most cases orsend TC to the
* 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 * Implemented by child class. Perform receiving of Telecommand,
* specific drivers or wrappers, e.g. UART Communication or lwIP stack * for example by implementing specific drivers or wrappers,
* e.g. UART Communication or an ethernet stack
* @param recvBuffer [out] Received data * @param recvBuffer [out] Received data
* @param size [out] Size of received data * @param size [out] Size of received data
* @return * @return
*/ */
virtual ReturnValue_t receiveTc(uint8_t ** recvBuffer, uint32_t * size) = 0; virtual ReturnValue_t receiveTc(uint8_t ** recvBuffer, size_t * size) = 0;
/** /**
* Handle Telemetry. Default implementation provided. * Handle Telemetry. Default implementation provided.
@ -93,14 +103,14 @@ protected:
* @param dataLen * @param dataLen
* @return * @return
*/ */
virtual ReturnValue_t sendTm(const uint8_t * data, uint32_t dataLen) = 0; virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) = 0;
/** /**
* Store data to be sent later if communication link is not up. * Store data to be sent later if communication link is not up.
* @param message * @param message
* @return * @return
*/ */
ReturnValue_t storeDownlinkData(TmTcMessage * message); virtual ReturnValue_t storeDownlinkData(TmTcMessage * message);
/** /**
* Send stored data if communication link is active * Send stored data if communication link is active
@ -113,16 +123,11 @@ protected:
* @param data * @param data
* @param dataLen * @param dataLen
*/ */
void printData(uint8_t * data, uint32_t dataLen); void printData(uint8_t * data, size_t dataLen);
private: private:
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
static constexpr uint8_t MAX_STORED_DATA_SENT_PER_CYCLE = 10;
static constexpr uint8_t MAX_DOWNLINK_PACKETS_STORED = 15;
FIFO<store_address_t, MAX_DOWNLINK_PACKETS_STORED> fifo; FIFO<store_address_t, MAX_DOWNLINK_PACKETS_STORED> fifo;
uint8_t * recvBuffer = nullptr; uint8_t sentPacketsPerCycle = 10;
uint32_t size = 0;
}; };