2019-12-26 19:47:46 +01:00
|
|
|
/**
|
|
|
|
* @file TmTcBridge.cpp
|
|
|
|
*
|
|
|
|
* @date 26.12.2019
|
2019-12-26 20:17:21 +01:00
|
|
|
* @author R. Mueller
|
2019-12-26 19:47:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <framework/tmtcservices/TmTcBridge.h>
|
|
|
|
|
|
|
|
#include <framework/ipc/QueueFactory.h>
|
|
|
|
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
|
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
|
2020-04-18 13:16:00 +02:00
|
|
|
TmTcBridge::TmTcBridge(object_id_t objectId_,
|
|
|
|
object_id_t ccsdsPacketDistributor_): SystemObject(objectId_),
|
|
|
|
ccsdsPacketDistributor(ccsdsPacketDistributor_)
|
|
|
|
{
|
|
|
|
TmTcReceptionQueue = QueueFactory::instance()->
|
2019-12-26 19:47:46 +01:00
|
|
|
createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH);
|
|
|
|
}
|
|
|
|
|
2020-04-18 13:16:00 +02:00
|
|
|
TmTcBridge::~TmTcBridge() {}
|
2019-12-26 19:47:46 +01:00
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::initialize() {
|
|
|
|
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
|
|
|
if (tcStore == NULL) {
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
tmStore = objectManager->get<StorageManagerIF>(objects::TM_STORE);
|
|
|
|
if (tmStore == NULL) {
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
AcceptsTelecommandsIF* tcDistributor =
|
|
|
|
objectManager->get<AcceptsTelecommandsIF>(ccsdsPacketDistributor);
|
|
|
|
if (tcDistributor == NULL) {
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
TmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue());
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) {
|
|
|
|
ReturnValue_t result;
|
|
|
|
result = handleTc();
|
|
|
|
if(result != RETURN_OK) {
|
|
|
|
error << "TMTC Bridge: Error handling TCs" << std::endl;
|
|
|
|
}
|
|
|
|
result = handleTm();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
error << "TMTC Bridge: Error handling TMs" << std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::handleTc() {
|
2020-01-01 16:54:05 +01:00
|
|
|
ReturnValue_t result = receiveTc(&recvBuffer, &size);
|
2019-12-26 19:47:46 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::handleTm() {
|
|
|
|
ReturnValue_t result = readTmQueue();
|
|
|
|
if(result != RETURN_OK) {
|
|
|
|
error << "TMTC Bridge: Reading TM Queue failed" << std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tmStored && communicationLinkUp) {
|
|
|
|
result = sendStoredTm();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::readTmQueue() {
|
|
|
|
TmTcMessage message;
|
2020-04-18 13:16:00 +02:00
|
|
|
const uint8_t* data = nullptr;
|
2020-03-23 17:58:23 +01:00
|
|
|
size_t size = 0;
|
2020-04-18 13:16:00 +02:00
|
|
|
|
2019-12-26 19:47:46 +01:00
|
|
|
for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message);
|
|
|
|
result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message))
|
|
|
|
{
|
2020-01-02 21:12:21 +01:00
|
|
|
if(communicationLinkUp == false) {
|
2019-12-26 19:47:46 +01:00
|
|
|
result = storeDownlinkData(&message);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = tmStore->getData(message.getStorageId(), &data, &size);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = sendTm(data, size);
|
|
|
|
if (result != RETURN_OK) {
|
2020-01-02 21:12:21 +01:00
|
|
|
error << "TMTC Bridge: Could not send TM packet"<< std::endl;
|
2019-12-26 19:47:46 +01:00
|
|
|
tmStore->deleteData(message.getStorageId());
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
tmStore->deleteData(message.getStorageId());
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) {
|
2019-12-26 20:35:11 +01:00
|
|
|
info << "TMTC Bridge: Comm Link down. "
|
2020-04-10 17:06:06 +02:00
|
|
|
"Saving packet ID to be sent later\r\n" << std::flush;
|
2020-04-18 13:16:00 +02:00
|
|
|
store_address_t storeId = 0;
|
2019-12-26 19:47:46 +01:00
|
|
|
|
|
|
|
if(fifo.full()) {
|
2019-12-26 20:35:11 +01:00
|
|
|
info << "TMTC Bridge: TM downlink max. number of stored packet IDs reached."
|
|
|
|
" Overwriting old data" << std::endl;
|
2019-12-26 19:47:46 +01:00
|
|
|
fifo.retrieve(&storeId);
|
2019-12-26 22:07:17 +01:00
|
|
|
tmStore->deleteData(storeId);
|
2019-12-26 19:47:46 +01:00
|
|
|
}
|
|
|
|
storeId = message->getStorageId();
|
|
|
|
fifo.insert(storeId);
|
|
|
|
tmStored = true;
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TmTcBridge::sendStoredTm() {
|
|
|
|
uint8_t counter = 0;
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
while(!fifo.empty() && counter < MAX_STORED_DATA_SENT_PER_CYCLE) {
|
|
|
|
info << "UDP Server: Sending stored TM data. There are "
|
2020-04-10 17:06:06 +02:00
|
|
|
<< (int) fifo.size() << " left to send\r\n" << std::flush;
|
2019-12-26 19:47:46 +01:00
|
|
|
store_address_t storeId;
|
|
|
|
const uint8_t* data = NULL;
|
2020-03-23 17:58:23 +01:00
|
|
|
size_t size = 0;
|
2019-12-26 19:47:46 +01:00
|
|
|
fifo.retrieve(&storeId);
|
|
|
|
result = tmStore->getData(storeId, &data, &size);
|
|
|
|
sendTm(data,size);
|
|
|
|
if(result != RETURN_OK) {
|
|
|
|
error << "UDP Server: Could not send stored downlink data" << std::endl;
|
|
|
|
result = RETURN_FAILED;
|
|
|
|
}
|
|
|
|
counter ++;
|
|
|
|
|
|
|
|
if(fifo.empty()) {
|
|
|
|
tmStored = false;
|
|
|
|
}
|
|
|
|
tmStore->deleteData(storeId);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TmTcBridge::registerCommConnect() {
|
2019-12-26 20:17:21 +01:00
|
|
|
if(!communicationLinkUp) {
|
|
|
|
info << "TMTC Bridge: Registered Comm Link Connect" << std::endl;
|
2019-12-26 19:47:46 +01:00
|
|
|
communicationLinkUp = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TmTcBridge::registerCommDisconnect() {
|
|
|
|
info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl;
|
|
|
|
if(communicationLinkUp) {
|
|
|
|
communicationLinkUp = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) {
|
|
|
|
return TmTcReceptionQueue->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TmTcBridge::printData(uint8_t * data, uint32_t dataLen) {
|
|
|
|
info << "TMTC Bridge: Printing data: [";
|
|
|
|
for(uint32_t i=0;i<dataLen;i++) {
|
|
|
|
info << std::hex << (int)data[i];
|
|
|
|
if(i < dataLen-1){
|
|
|
|
info << " , ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info << " ] " << std::endl;
|
|
|
|
}
|