eive-obsw/mission/tmtc/VirtualChannel.cpp

69 lines
1.9 KiB
C++
Raw Normal View History

2021-09-22 16:54:55 +02:00
#include "CCSDSHandler.h"
2021-09-26 08:29:30 +02:00
#include "VirtualChannel.h"
2021-09-22 16:54:55 +02:00
#include "OBSWConfig.h"
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
#include "fsfw/objectmanager/ObjectManager.h"
2021-09-26 08:29:30 +02:00
#include "fsfw/tmtcservices/TmTcMessage.h"
#include "fsfw/ipc/QueueFactory.h"
2021-09-22 16:54:55 +02:00
VirtualChannel::VirtualChannel(uint8_t vcId, uint32_t tmQueueDepth) :
vcId(vcId) {
tmQueue = QueueFactory::instance()->createMessageQueue(tmQueueDepth,
MessageQueueMessage::MAX_MESSAGE_SIZE);
}
ReturnValue_t VirtualChannel::initialize() {
tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if(tmStore == nullptr) {
sif::error << "VirtualChannel::initialize: Failed to get tm store" << std::endl;
return RETURN_FAILED;
}
2021-09-26 08:29:30 +02:00
return RETURN_OK;
2021-09-22 16:54:55 +02:00
}
ReturnValue_t VirtualChannel::performOperation() {
2021-09-26 08:29:30 +02:00
ReturnValue_t result = RETURN_OK;
2021-09-22 16:54:55 +02:00
TmTcMessage message;
while(tmQueue->receiveMessage(&message) == RETURN_OK) {
store_address_t storeId = message.getStorageId();
const uint8_t* data = nullptr;
size_t size = 0;
result = tmStore->getData(storeId, &data, &size);
if (result != RETURN_OK) {
sif::warning << "VirtualChannel::performOperation: Failed to read data from IPC store"
<< std::endl;
tmStore->deleteData(storeId);
return result;
}
if (linkIsUp) {
2021-09-26 08:29:30 +02:00
result = ptme->writeToVc(vcId, data, size);
2021-09-22 16:54:55 +02:00
}
tmStore->deleteData(storeId);
if (result != RETURN_OK) {
return result;
}
}
return result;
}
MessageQueueId_t VirtualChannel::getReportReceptionQueue(uint8_t virtualChannel) {
2021-09-26 08:29:30 +02:00
return tmQueue->getId();
2021-09-22 16:54:55 +02:00
}
void VirtualChannel::setPtmeObject(PtmeIF* ptme) {
if (ptme == nullptr) {
sif::warning << "VirtualChannel::setPtmeObject: Invalid ptme object" << std::endl;
}
ptme = ptme;
}
2021-09-26 08:29:30 +02:00
void VirtualChannel::setLinkState(bool linkIsUp) {
linkIsUp = linkIsUp;
2021-09-22 16:54:55 +02:00
}