some minor improvements

This commit is contained in:
Robin Müller 2020-06-23 10:45:47 +02:00
parent d51b3b68e4
commit e935b8bd04
2 changed files with 32 additions and 38 deletions

View File

@ -1,9 +1,9 @@
#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/tmtcservices/AcceptsTelecommandsIF.h> #include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/globalfunctions/arrayprinter.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_),
@ -22,7 +22,7 @@ ReturnValue_t TmTcBridge::setNumberOfSentPacketsPerCycle(
return RETURN_OK; return RETURN_OK;
} }
else { else {
warning << "TmTcBridge: Number of packets sent per cycle " sif::warning << "TmTcBridge: Number of packets sent per cycle "
"exceeds limits. Keeping default value." << std::endl; "exceeds limits. Keeping default value." << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -35,7 +35,7 @@ ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(
return RETURN_OK; return RETURN_OK;
} }
else { else {
warning << "TmTcBridge: Number of packets stored " sif::warning << "TmTcBridge: Number of packets stored "
"exceeds limits. Keeping default value." << std::endl; "exceeds limits. Keeping default value." << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -63,11 +63,11 @@ ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
ReturnValue_t result; ReturnValue_t result;
result = handleTc(); result = handleTc();
if(result != RETURN_OK) { if(result != RETURN_OK) {
error << "TMTC Bridge: Error handling TCs" << std::endl; sif::error << "TMTC Bridge: Error handling TCs" << std::endl;
} }
result = handleTm(); result = handleTm();
if (result != RETURN_OK) { if (result != RETURN_OK) {
error << "TMTC Bridge: Error handling TMs" << std::endl; sif::error << "TMTC Bridge: Error handling TMs" << std::endl;
} }
return result; return result;
} }
@ -82,11 +82,11 @@ ReturnValue_t TmTcBridge::handleTc() {
ReturnValue_t TmTcBridge::handleTm() { ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t result = handleTmQueue(); ReturnValue_t result = handleTmQueue();
if(result != RETURN_OK) { if(result != RETURN_OK) {
error << "TMTC Bridge: Reading TM Queue failed" << std::endl; sif::error << "TMTC Bridge: Reading TM Queue failed" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
if(tmStored && communicationLinkUp) { if(tmStored and communicationLinkUp) {
result = handleStoredTm(); result = handleStoredTm();
} }
return result; return result;
@ -96,7 +96,7 @@ ReturnValue_t TmTcBridge::handleTm() {
ReturnValue_t TmTcBridge::handleTmQueue() { ReturnValue_t TmTcBridge::handleTmQueue() {
TmTcMessage message; TmTcMessage message;
const uint8_t* data = nullptr; const uint8_t* data = nullptr;
uint32_t size = 0; size_t size = 0;
for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message); for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message);
result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message)) result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message))
{ {
@ -112,7 +112,7 @@ ReturnValue_t TmTcBridge::handleTmQueue() {
result = sendTm(data, size); result = sendTm(data, size);
if (result != RETURN_OK) { if (result != RETURN_OK) {
error << "TMTC Bridge: Could not send TM packet"<< std::endl; sif::error << "TMTC Bridge: Could not send TM packet"<< std::endl;
tmStore->deleteData(message.getStorageId()); tmStore->deleteData(message.getStorageId());
return result; return result;
@ -127,14 +127,14 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
// "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(tmFifo.full()) {
error << "TMTC Bridge: TM downlink max. number of stored packet IDs " sif::error << "TMTC Bridge: TM downlink max. number of stored packet IDs "
"reached! Overwriting old data" << std::endl; "reached! Overwriting old data" << std::endl;
fifo.retrieve(&storeId); tmFifo.retrieve(&storeId);
tmStore->deleteData(storeId); tmStore->deleteData(storeId);
} }
storeId = message->getStorageId(); storeId = message->getStorageId();
fifo.insert(storeId); tmFifo.insert(storeId);
tmStored = true; tmStored = true;
return RETURN_OK; return RETURN_OK;
} }
@ -142,25 +142,25 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
ReturnValue_t TmTcBridge::handleStoredTm() { ReturnValue_t TmTcBridge::handleStoredTm() {
uint8_t counter = 0; uint8_t counter = 0;
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
while(not fifo.empty() && counter < sentPacketsPerCycle) { while(not tmFifo.empty() and 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 = nullptr;
uint32_t size = 0; size_t size = 0;
fifo.retrieve(&storeId); tmFifo.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" sif::error << "TMTC Bridge: Could not send stored downlink data"
<< std::endl; << std::endl;
result = RETURN_FAILED; result = RETURN_FAILED;
} }
counter ++; counter ++;
if(fifo.empty()) { if(tmFifo.empty()) {
tmStored = false; tmStored = false;
} }
tmStore->deleteData(storeId); tmStore->deleteData(storeId);
@ -187,14 +187,6 @@ MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
} }
void TmTcBridge::printData(uint8_t * data, size_t dataLen) { void TmTcBridge::printData(uint8_t * data, size_t dataLen) {
info << "TMTC Bridge: Printing data: ["; arrayprinter::print(data, dataLen);
for(uint32_t i = 0; i < dataLen; i++) {
info << std::hex << (int)data[i];
if(i < dataLen-1){
info << " , ";
}
}
info << " ] " << std::endl;
} }

View File

@ -25,8 +25,6 @@ public:
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);
/** /**
* Set number of packets sent per performOperation().Please note that this * Set number of packets sent per performOperation().Please note that this
* value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE * value must be smaller than MAX_STORED_DATA_SENT_PER_CYCLE
@ -45,8 +43,8 @@ public:
*/ */
ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored); ReturnValue_t setMaxNumberOfPacketsStored(uint8_t maxNumberOfPacketsStored);
void registerCommConnect(); virtual void registerCommConnect();
void registerCommDisconnect(); virtual void registerCommDisconnect();
/** /**
* Initializes necessary FSFW components for the TMTC Bridge * Initializes necessary FSFW components for the TMTC Bridge
@ -64,7 +62,8 @@ public:
* @param virtualChannel * @param virtualChannel
* @return * @return
*/ */
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; MessageQueueId_t getReportReceptionQueue(
uint8_t virtualChannel = 0) override;
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.
@ -75,7 +74,6 @@ protected:
//! Used to specify whether communication link is up //! Used to specify whether communication link is up
bool communicationLinkUp = false; bool communicationLinkUp = false;
bool tmStored = false; bool tmStored = false;
FIFO<store_address_t, LIMIT_DOWNLINK_PACKETS_STORED> fifo;
/** /**
* @brief Handle TC reception * @brief Handle TC reception
@ -141,9 +139,13 @@ protected:
*/ */
void printData(uint8_t * data, size_t dataLen); void printData(uint8_t * data, size_t dataLen);
private: /**
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE; * This fifo can be used to store downlink data
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED; * which can not be sent at the moment.
*/
FIFO<store_address_t, LIMIT_DOWNLINK_PACKETS_STORED> tmFifo;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
uint8_t maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
}; };