2023-03-31 01:14:59 +02:00
|
|
|
#include "VirtualChannelWithQueue.h"
|
2023-03-09 17:44:05 +01:00
|
|
|
|
|
|
|
#include "OBSWConfig.h"
|
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
|
|
|
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
|
|
|
|
#include "fsfw/tmtcservices/TmTcMessage.h"
|
2023-03-24 19:49:08 +01:00
|
|
|
#include "mission/com/CcsdsIpCoreHandler.h"
|
2023-03-09 17:44:05 +01:00
|
|
|
|
2023-03-09 19:42:20 +01:00
|
|
|
VirtualChannelWithQueue::VirtualChannelWithQueue(object_id_t objectId, uint8_t vcId,
|
|
|
|
const char* vcName, PtmeIF& ptme,
|
|
|
|
const std::atomic_bool& linkStateProvider,
|
|
|
|
StorageManagerIF& tmStore, uint32_t tmQueueDepth)
|
2023-03-10 02:05:51 +01:00
|
|
|
: VirtualChannel(objectId, vcId, vcName, ptme, linkStateProvider), tmStore(tmStore) {
|
2023-03-09 19:42:20 +01:00
|
|
|
auto mqArgs = MqArgs(getObjectId(), reinterpret_cast<void*>(getVcid()));
|
2023-03-09 17:44:05 +01:00
|
|
|
tmQueue = QueueFactory::instance()->createMessageQueue(
|
|
|
|
tmQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
|
|
|
}
|
|
|
|
|
2023-03-09 19:42:20 +01:00
|
|
|
const char* VirtualChannelWithQueue::getName() const { return VirtualChannel::getName(); }
|
|
|
|
|
2023-03-31 01:14:59 +02:00
|
|
|
ReturnValue_t VirtualChannelWithQueue::handleNextTm(bool performWriteOp) {
|
2023-03-09 17:44:05 +01:00
|
|
|
TmTcMessage message;
|
|
|
|
ReturnValue_t result = tmQueue->receiveMessage(&message);
|
|
|
|
if (result == MessageQueueIF::EMPTY) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
store_address_t storeId = message.getStorageId();
|
|
|
|
const uint8_t* data = nullptr;
|
|
|
|
size_t size = 0;
|
2023-03-10 02:05:51 +01:00
|
|
|
result = tmStore.getData(storeId, &data, &size);
|
2023-03-09 17:44:05 +01:00
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
sif::warning << "VirtualChannel::performOperation: Failed to read data from TM store"
|
|
|
|
<< std::endl;
|
2023-03-10 02:05:51 +01:00
|
|
|
tmStore.deleteData(storeId);
|
2023-03-09 17:44:05 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-31 01:14:59 +02:00
|
|
|
if (performWriteOp) {
|
|
|
|
result = write(data, size);
|
|
|
|
}
|
2023-03-28 14:59:31 +02:00
|
|
|
// Try delete in any case, ignore failures (which should not happen), it is more important to
|
|
|
|
// propagate write errors.
|
2023-03-10 02:05:51 +01:00
|
|
|
tmStore.deleteData(storeId);
|
2023-03-28 14:59:31 +02:00
|
|
|
return result;
|
2023-03-09 17:44:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t VirtualChannelWithQueue::getReportReceptionQueue(uint8_t virtualChannel) const {
|
|
|
|
return tmQueue->getId();
|
|
|
|
}
|