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/ipc/QueueFactory.h>
@ -13,14 +6,26 @@
TmTcBridge::TmTcBridge(object_id_t objectId_,
object_id_t ccsdsPacketDistributor_): SystemObject(objectId_),
ccsdsPacketDistributor(ccsdsPacketDistributor_)
ccsdsPacketDistributor(ccsdsPacketDistributor_),
sentPacketsPerCycle(5)
{
TmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
TmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
}
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() {
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
if (tcStore == NULL) {
@ -53,12 +58,14 @@ ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
}
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;
}
ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t result = readTmQueue();
ReturnValue_t result = handleTmQueue();
if(result != RETURN_OK) {
error << "TMTC Bridge: Reading TM Queue failed" << std::endl;
return RETURN_FAILED;
@ -71,7 +78,7 @@ ReturnValue_t TmTcBridge::handleTm() {
}
ReturnValue_t TmTcBridge::readTmQueue() {
ReturnValue_t TmTcBridge::handleTmQueue() {
TmTcMessage message;
const uint8_t* data = nullptr;
size_t size = 0;
@ -101,13 +108,13 @@ ReturnValue_t TmTcBridge::readTmQueue() {
}
ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
info << "TMTC Bridge: Comm Link down. "
"Saving packet ID to be sent later\r\n" << std::flush;
//debug << "TMTC Bridge: Comm Link down. "
// "Saving packet ID to be sent later\r\n" << std::flush;
store_address_t storeId = 0;
if(fifo.full()) {
info << "TMTC Bridge: TM downlink max. number of stored packet IDs reached."
" Overwriting old data" << std::endl;
error << "TMTC Bridge: TM downlink max. number of stored packet IDs "
"reached! Overwriting old data" << std::endl;
fifo.retrieve(&storeId);
tmStore->deleteData(storeId);
}
@ -120,15 +127,17 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
ReturnValue_t TmTcBridge::sendStoredTm() {
uint8_t counter = 0;
ReturnValue_t result = RETURN_OK;
while(!fifo.empty() && counter < MAX_STORED_DATA_SENT_PER_CYCLE) {
info << "TMTC Bridge: Sending stored TM data. There are "
<< (int) fifo.size() << " left to send\r\n" << std::flush;
while(!fifo.empty() && counter < sentPacketsPerCycle) {
//info << "TMTC Bridge: Sending stored TM data. There are "
// << (int) fifo.size() << " left to send\r\n" << std::flush;
store_address_t storeId;
const uint8_t* data = NULL;
size_t size = 0;
fifo.retrieve(&storeId);
result = tmStore->getData(storeId, &data, &size);
sendTm(data,size);
if(result != RETURN_OK) {
error << "TMTC Bridge: Could not send stored downlink data"
<< std::endl;
@ -162,7 +171,7 @@ MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
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: [";
for(uint32_t i=0;i<dataLen;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_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
@ -21,32 +15,42 @@ class TmTcBridge : public AcceptsTelemetryIF,
public HasReturnvaluesIF,
public SystemObject {
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_);
virtual ~TmTcBridge();
/**
* Initializes basic FSFW components for the TMTC Bridge
* @return
* Set number of packets sent per performOperation().Please note that this
* 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.
* @details There are no restrictions for calls within this method, so any
* other member of the class can be used.
* @return Currently, the return value is ignored.
* Initializes necessary FSFW components for the TMTC Bridge
* @return
*/
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
* @param virtualChannel
* @return
*/
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0);
void registerCommConnect();
void registerCommDisconnect();
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override;
protected:
//! Used to send and receive TMTC messages.
//! TmTcMessage is used to transport messages between tasks.
@ -59,19 +63,25 @@ protected:
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
*/
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 lwIP stack
* 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, uint32_t * size) = 0;
virtual ReturnValue_t receiveTc(uint8_t ** recvBuffer, size_t * size) = 0;
/**
* Handle Telemetry. Default implementation provided.
@ -93,14 +103,14 @@ protected:
* @param dataLen
* @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.
* @param message
* @return
*/
ReturnValue_t storeDownlinkData(TmTcMessage * message);
virtual ReturnValue_t storeDownlinkData(TmTcMessage * message);
/**
* Send stored data if communication link is active
@ -113,16 +123,11 @@ protected:
* @param data
* @param dataLen
*/
void printData(uint8_t * data, uint32_t dataLen);
void printData(uint8_t * data, size_t dataLen);
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;
uint8_t * recvBuffer = nullptr;
uint32_t size = 0;
uint8_t sentPacketsPerCycle = 10;
};