Merge pull request 'tmtc bridge update, uses dynamic FIFO now' (#187) from KSat/fsfw:mueller/TmTcBridgeUpdate into master

Reviewed-on: fsfw/fsfw#187
This commit is contained in:
taheran 2020-09-08 14:12:43 +02:00
commit 5dd08877a5
2 changed files with 81 additions and 47 deletions

View File

@ -1,7 +1,7 @@
#include "TmTcBridge.h"
#include "../tmtcservices/TmTcBridge.h"
#include "../ipc/QueueFactory.h"
#include "AcceptsTelecommandsIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../globalfunctions/arrayprinter.h"
@ -66,6 +66,8 @@ ReturnValue_t TmTcBridge::initialize() {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
tmFifo = new DynamicFIFO<store_address_t>(maxNumberOfPacketsStored);
tmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());
return RETURN_OK;
}
@ -90,102 +92,122 @@ ReturnValue_t TmTcBridge::handleTc() {
}
ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = handleTmQueue();
if(result != RETURN_OK) {
sif::warning << "TmTcBridge: Reading TM Queue failed" << std::endl;
return RETURN_FAILED;
sif::error << "TmTcBridge::handleTm: Error handling TM queue!"
<< std::endl;
status = result;
}
if(tmStored and communicationLinkUp) {
result = handleStoredTm();
if(tmStored and communicationLinkUp and
(packetSentCounter < sentPacketsPerCycle)) {
result = handleStoredTm();
if(result != RETURN_OK) {
sif::error << "TmTcBridge::handleTm: Error handling stored TMs!"
<< std::endl;
status = result;
}
}
return result;
packetSentCounter = 0;
return status;
}
ReturnValue_t TmTcBridge::handleTmQueue() {
TmTcMessage message;
const uint8_t* data = nullptr;
size_t size = 0;
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
for (ReturnValue_t result = tmTcReceptionQueue->receiveMessage(&message);
result == RETURN_OK; result = tmTcReceptionQueue->receiveMessage(&message))
result == HasReturnvaluesIF::RETURN_OK;
result = tmTcReceptionQueue->receiveMessage(&message))
{
if(communicationLinkUp == false) {
result = storeDownlinkData(&message);
return result;
//sif::info << (int) packetSentCounter << std::endl;
if(communicationLinkUp == false or
packetSentCounter >= sentPacketsPerCycle) {
storeDownlinkData(&message);
continue;
}
result = tmStore->getData(message.getStorageId(), &data, &size);
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
continue;
}
result = sendTm(data, size);
if (result != RETURN_OK) {
sif::warning << "TmTcBridge: Could not send TM packet" << std::endl;
tmStore->deleteData(message.getStorageId());
return result;
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
else {
tmStore->deleteData(message.getStorageId());
packetSentCounter++;
}
tmStore->deleteData(message.getStorageId());
}
return RETURN_OK;
return status;
}
ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
store_address_t storeId = 0;
if(tmFifo.full()) {
sif::error << "TmTcBridge::storeDownlinkData: TM downlink max. number "
<< "of stored packet IDs reached! "
<< "Overwriting old data" << std::endl;
tmFifo.retrieve(&storeId);
tmStore->deleteData(storeId);
if(tmFifo->full()) {
sif::debug << "TmTcBridge::storeDownlinkData: TM downlink max. number "
<< "of stored packet IDs reached! " << std::endl;
if(overwriteOld) {
tmFifo->retrieve(&storeId);
tmStore->deleteData(storeId);
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
storeId = message->getStorageId();
tmFifo.insert(storeId);
tmFifo->insert(storeId);
tmStored = true;
return RETURN_OK;
}
ReturnValue_t TmTcBridge::handleStoredTm() {
uint8_t counter = 0;
ReturnValue_t result = RETURN_OK;
while(not tmFifo.empty() and counter < sentPacketsPerCycle) {
//info << "TMTC Bridge: Sending stored TM data. There are "
// << (int) fifo.size() << " left to send\r\n" << std::flush;
ReturnValue_t status = RETURN_OK;
while(not tmFifo->empty() and packetSentCounter < sentPacketsPerCycle) {
//sif::info << "TMTC Bridge: Sending stored TM data. There are "
// << (int) tmFifo->size() << " left to send\r\n" << std::flush;
store_address_t storeId;
const uint8_t* data = nullptr;
size_t size = 0;
tmFifo.retrieve(&storeId);
result = tmStore->getData(storeId, &data, &size);
sendTm(data,size);
tmFifo->retrieve(&storeId);
ReturnValue_t result = tmStore->getData(storeId, &data, &size);
if(result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
result = sendTm(data,size);
if(result != RETURN_OK) {
sif::error << "TMTC Bridge: Could not send stored downlink data"
<< std::endl;
result = RETURN_FAILED;
status = result;
}
counter ++;
packetSentCounter ++;
if(tmFifo.empty()) {
if(tmFifo->empty()) {
tmStored = false;
}
tmStore->deleteData(storeId);
}
return result;
return status;
}
void TmTcBridge::registerCommConnect() {
if(not communicationLinkUp) {
//info << "TMTC Bridge: Registered Comm Link Connect" << std::endl;
//sif::info << "TMTC Bridge: Registered Comm Link Connect" << std::endl;
communicationLinkUp = true;
}
}
void TmTcBridge::registerCommDisconnect() {
//info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl;
//sif::info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl;
if(communicationLinkUp) {
communicationLinkUp = false;
}
@ -209,3 +231,7 @@ MessageQueueId_t TmTcBridge::getRequestQueue() {
// Default implementation: Relay TC messages to TC distributor directly.
return tmTcReceptionQueue->getDefaultDestination();
}
void TmTcBridge::setFifoToOverwriteOldData(bool overwriteOld) {
this->overwriteOld = overwriteOld;
}

View File

@ -1,15 +1,15 @@
#ifndef FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#define FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_
#include "../objectmanager/SystemObject.h"
#include "AcceptsTelemetryIF.h"
#include "../tmtcservices/AcceptsTelemetryIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../storagemanager/StorageManagerIF.h"
#include "AcceptsTelecommandsIF.h"
#include "../container/FIFO.h"
#include "TmTcMessage.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../container/DynamicFIFO.h"
#include "../tmtcservices/TmTcMessage.h"
class TmTcBridge : public AcceptsTelemetryIF,
public AcceptsTelecommandsIF,
@ -46,6 +46,12 @@ public:
*/
ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored);
/**
* This will set up the bridge to overwrite old data in the FIFO.
* @param overwriteOld
*/
void setFifoToOverwriteOldData(bool overwriteOld);
virtual void registerCommConnect();
virtual void registerCommDisconnect();
@ -86,6 +92,8 @@ protected:
//! by default, so telemetry will be handled immediately.
bool communicationLinkUp = true;
bool tmStored = false;
bool overwriteOld = true;
uint8_t packetSentCounter = 0;
/**
* @brief Handle TC reception
@ -145,7 +153,7 @@ protected:
* This fifo can be used to store downlink data
* which can not be sent at the moment.
*/
FIFO<store_address_t, LIMIT_DOWNLINK_PACKETS_STORED> tmFifo;
DynamicFIFO<store_address_t>* tmFifo = nullptr;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
};