U. Mohr suggestions worked in

Furthermore, some enhancements added:
delay between sent tm and max number of sent tm per cycle
can be specified
This commit is contained in:
Robin Müller 2020-04-21 14:51:26 +02:00
parent 5026517028
commit b252299bdb
2 changed files with 77 additions and 46 deletions

View File

@ -1,19 +1,16 @@
/**
* @file TmTcBridge.cpp
*
* @date 26.12.2019
* @author R. Mueller
*/
#include <framework/tmtcservices/TmTcBridge.h>
#include <framework/ipc/QueueFactory.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/osal/FreeRTOS/PeriodicTask.h>
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tasks/PeriodicTaskIF.h>
TmTcBridge::TmTcBridge(object_id_t objectId_,
object_id_t ccsdsPacketDistributor_): SystemObject(objectId_),
ccsdsPacketDistributor(ccsdsPacketDistributor_)
ccsdsPacketDistributor(ccsdsPacketDistributor_),
sentPacketsPerCycle(5), delayBetweenSentPacketsMs(0)
{
TmTcReceptionQueue = QueueFactory::instance()->
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
@ -21,6 +18,21 @@ TmTcBridge::TmTcBridge(object_id_t objectId_,
TmTcBridge::~TmTcBridge() {}
void TmTcBridge::setDelayBetweenSentPackets(uint32_t delayBetweenSentPackets) {
this->delayBetweenSentPacketsMs = delayBetweenSentPackets;
}
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,7 +65,21 @@ 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);
if(result == RETURN_OK and recvLen > 0 and recvBuffer != nullptr) {
store_address_t storeId = 0;
ReturnValue_t result = tcStore->addData(&storeId,
recvBuffer, (uint32_t)recvLen);
if(result != RETURN_OK) {
return result;
}
TmTcMessage message(storeId);
if (TmTcReceptionQueue->sendToDefault(&message) != RETURN_OK) {
tcStore->deleteData(storeId);
}
}
return result;
}
@ -106,8 +132,8 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
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,14 +146,16 @@ 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;
uint32_t size = 0;
fifo.retrieve(&storeId);
result = tmStore->getData(storeId, &data, &size);
// This does not work yet: is not static function
//PeriodicTaskIF::sleepFor(delayBetweenSentPacketsMs);
sendTm(data,size);
if(result != RETURN_OK) {
error << "TMTC Bridge: Could not send stored downlink data"
@ -162,7 +190,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,44 @@ 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
*/
virtual ReturnValue_t initialize();
void setDelayBetweenSentPackets(uint32_t delayBetweenSentPackets);
/**
* @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.
* 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 performOperation(uint8_t operationCode = 0);
ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle);
void registerCommConnect();
void registerCommDisconnect();
/**
* Initializes necessary FSFW components for the TMTC Bridge
* @return
*/
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.
@ -65,13 +71,14 @@ protected:
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,7 +100,7 @@ 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.
@ -113,16 +120,12 @@ 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;
uint32_t delayBetweenSentPacketsMs = 0;
};