eive-obsw/mission/tmtc/VirtualChannel.cpp

76 lines
2.2 KiB
C++
Raw Normal View History

2021-09-26 08:29:30 +02:00
#include "VirtualChannel.h"
2021-09-22 16:54:55 +02:00
#include "CcsdsIpCoreHandler.h"
2022-01-17 15:58:27 +01:00
#include "OBSWConfig.h"
#include "fsfw/ipc/QueueFactory.h"
2021-09-22 16:54:55 +02:00
#include "fsfw/objectmanager/ObjectManager.h"
2022-01-17 15:58:27 +01:00
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
2021-09-26 08:29:30 +02:00
#include "fsfw/tmtcservices/TmTcMessage.h"
2021-09-22 16:54:55 +02:00
2022-02-22 20:27:13 +01:00
VirtualChannel::VirtualChannel(uint8_t vcId, uint32_t tmQueueDepth, object_id_t ownerId)
: vcId(vcId) {
auto mqArgs = MqArgs(ownerId, reinterpret_cast<void*>(vcId));
tmQueue = QueueFactory::instance()->createMessageQueue(
tmQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
2022-09-16 11:43:11 +02:00
vcName = "VC " + vcId;
2021-09-22 16:54:55 +02:00
}
ReturnValue_t VirtualChannel::initialize() {
2022-01-17 15:58:27 +01:00
tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (tmStore == nullptr) {
sif::error << "VirtualChannel::initialize: Failed to get tm store" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-01-17 15:58:27 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-09-22 16:54:55 +02:00
}
ReturnValue_t VirtualChannel::performOperation() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-01-17 15:58:27 +01:00
TmTcMessage message;
2021-09-22 16:54:55 +02:00
2023-02-19 17:06:08 +01:00
unsigned int count = 0;
2022-08-24 17:27:47 +02:00
while (tmQueue->receiveMessage(&message) == returnvalue::OK) {
2022-01-17 15:58:27 +01:00
store_address_t storeId = message.getStorageId();
const uint8_t* data = nullptr;
size_t size = 0;
result = tmStore->getData(storeId, &data, &size);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-03 15:10:42 +01:00
sif::warning << "VirtualChannel::performOperation: Failed to read data from TM store"
2022-01-17 15:58:27 +01:00
<< std::endl;
tmStore->deleteData(storeId);
return result;
}
2021-09-22 16:54:55 +02:00
2022-01-17 15:58:27 +01:00
if (linkIsUp) {
result = ptme->writeToVc(vcId, data, size);
}
tmStore->deleteData(storeId);
2023-02-19 17:08:55 +01:00
if (result != returnvalue::OK) {
return result;
}
2023-02-19 17:06:08 +01:00
count++;
2023-02-21 20:43:16 +01:00
if (count == 500) {
2023-02-19 17:06:08 +01:00
sif::error << "VirtualChannel: Possible message storm detected" << std::endl;
break;
2022-01-17 15:58:27 +01:00
}
}
return result;
2021-09-22 16:54:55 +02:00
}
2022-10-21 11:31:38 +02:00
MessageQueueId_t VirtualChannel::getReportReceptionQueue(uint8_t virtualChannel) const {
2022-01-17 15:58:27 +01:00
return tmQueue->getId();
2021-09-22 16:54:55 +02:00
}
2021-09-29 14:47:20 +02:00
void VirtualChannel::setPtmeObject(PtmeIF* ptme_) {
2022-01-17 15:58:27 +01:00
if (ptme_ == nullptr) {
sif::warning << "VirtualChannel::setPtmeObject: Invalid ptme object" << std::endl;
return;
}
ptme = ptme_;
2021-09-22 16:54:55 +02:00
}
2022-01-17 15:58:27 +01:00
void VirtualChannel::setLinkState(bool linkIsUp_) { linkIsUp = linkIsUp_; }
2022-09-16 11:43:11 +02:00
const char* VirtualChannel::getName() const { return vcName.c_str(); }