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:
parent
5026517028
commit
b252299bdb
@ -1,19 +1,16 @@
|
|||||||
/**
|
|
||||||
* @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>
|
||||||
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||||
|
#include <framework/osal/FreeRTOS/PeriodicTask.h>
|
||||||
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
#include <framework/tasks/PeriodicTaskIF.h>
|
||||||
|
|
||||||
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), delayBetweenSentPacketsMs(0)
|
||||||
{
|
{
|
||||||
TmTcReceptionQueue = QueueFactory::instance()->
|
TmTcReceptionQueue = QueueFactory::instance()->
|
||||||
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
|
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
|
||||||
@ -21,6 +18,21 @@ TmTcBridge::TmTcBridge(object_id_t objectId_,
|
|||||||
|
|
||||||
TmTcBridge::~TmTcBridge() {}
|
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() {
|
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,7 +65,21 @@ 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);
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +132,8 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
|
|||||||
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,14 +146,16 @@ 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;
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
fifo.retrieve(&storeId);
|
fifo.retrieve(&storeId);
|
||||||
result = tmStore->getData(storeId, &data, &size);
|
result = tmStore->getData(storeId, &data, &size);
|
||||||
|
// This does not work yet: is not static function
|
||||||
|
//PeriodicTaskIF::sleepFor(delayBetweenSentPacketsMs);
|
||||||
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"
|
||||||
@ -162,7 +190,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];
|
||||||
|
@ -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,44 @@ 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();
|
||||||
|
|
||||||
/**
|
void setDelayBetweenSentPackets(uint32_t delayBetweenSentPackets);
|
||||||
* Initializes basic FSFW components for the TMTC Bridge
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t initialize();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The performOperation method is executed in a task.
|
* Set number of packets sent per performOperation().Please note that this
|
||||||
* @details There are no restrictions for calls within this method, so any
|
* value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE
|
||||||
* other member of the class can be used.
|
* @param sentPacketsPerCycle
|
||||||
* @return Currently, the return value is ignored.
|
* @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
|
* 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.
|
||||||
@ -65,13 +71,14 @@ protected:
|
|||||||
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,7 +100,7 @@ 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.
|
||||||
@ -113,16 +120,12 @@ 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;
|
uint32_t delayBetweenSentPacketsMs = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user