2021-09-26 08:29:30 +02:00
|
|
|
#include "VirtualChannel.h"
|
2021-09-22 16:54:55 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
#include "CCSDSHandler.h"
|
|
|
|
#include "OBSWConfig.h"
|
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2021-09-22 16:54:55 +02:00
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
2022-01-17 13:48:55 +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-01-17 13:48:55 +01:00
|
|
|
VirtualChannel::VirtualChannel(uint8_t vcId, uint32_t tmQueueDepth) : vcId(vcId) {
|
|
|
|
tmQueue = QueueFactory::instance()->createMessageQueue(tmQueueDepth,
|
|
|
|
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
2021-09-22 16:54:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t VirtualChannel::initialize() {
|
2022-01-17 13:48:55 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2021-09-22 16:54:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t VirtualChannel::performOperation() {
|
2022-01-17 13:48:55 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
TmTcMessage message;
|
2021-09-22 16:54:55 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
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;
|
|
|
|
}
|
2021-09-22 16:54:55 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
if (linkIsUp) {
|
|
|
|
result = ptme->writeToVc(vcId, data, size);
|
|
|
|
}
|
2021-09-22 16:54:55 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
tmStore->deleteData(storeId);
|
2021-09-22 16:54:55 +02:00
|
|
|
|
2022-01-17 13:48:55 +01:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2021-09-22 16:54:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t VirtualChannel::getReportReceptionQueue(uint8_t virtualChannel) {
|
2022-01-17 13:48:55 +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 13:48:55 +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 13:48:55 +01:00
|
|
|
void VirtualChannel::setLinkState(bool linkIsUp_) { linkIsUp = linkIsUp_; }
|