eive-obsw/test/testtasks/PusTcInjector.cpp

66 lines
2.5 KiB
C++
Raw Normal View History

2022-01-17 15:58:27 +01:00
#include <fsfw/globalfunctions/arrayprinter.h>
#include <fsfw/ipc/QueueFactory.h>
2021-06-08 16:45:25 +02:00
#include <fsfw/objectmanager/ObjectManager.h>
2020-09-16 16:22:36 +02:00
#include <fsfw/tmtcpacket/pus/TcPacketBase.h>
#include <fsfw/tmtcpacket/pus/TcPacketStored.h>
2022-01-17 15:58:27 +01:00
#include <fsfw/tmtcservices/AcceptsTelecommandsIF.h>
#include <fsfw/tmtcservices/TmTcMessage.h>
#include <test/testtasks/PusTcInjector.h>
2020-09-16 16:22:36 +02:00
2022-01-17 15:58:27 +01:00
PusTcInjector::PusTcInjector(object_id_t objectId, object_id_t destination, object_id_t tcStore,
uint16_t defaultApid)
: SystemObject(objectId),
defaultApid(defaultApid),
destination(destination),
tcStoreId(tcStore) {}
2020-09-16 16:22:36 +02:00
2022-01-17 15:58:27 +01:00
PusTcInjector::~PusTcInjector() {}
2020-09-16 16:22:36 +02:00
2022-01-17 15:58:27 +01:00
// ReturnValue_t PusTcInjector::injectPusTelecommand(uint8_t service,
2020-09-16 16:22:36 +02:00
// uint8_t subservice,const uint8_t* appData, size_t appDataLen) {
// return injectPusTelecommand(service, subservice, defaultApid, appData,
// appDataLen);
2022-01-17 15:58:27 +01:00
// }
2020-09-16 16:22:36 +02:00
// TODO: ACK flags
2022-01-17 15:58:27 +01:00
// ReturnValue_t PusTcInjector::injectPusTelecommand(uint8_t service,
2020-09-16 16:22:36 +02:00
// uint8_t subservice,uint16_t apid, const uint8_t* appData,
// size_t appDataLen) {
// // Prepare TC packet. Store into TC store immediately.
// TcPacketStored tcPacket(service, subservice, apid, sequenceCount++);
//
// const uint8_t* packetPtr = nullptr;
// size_t packetSize = 0;
// tcPacket.getData(&packetPtr, &packetSize);
// //arrayprinter::print(packetPtr, packetSize, OutputType::BIN);
//
// // Send TC packet.
// TmTcMessage tcMessage(tcPacket.getStoreAddress());
// ReturnValue_t result = injectionQueue->sendToDefault(&tcMessage);
// if(result != HasReturnvaluesIF::RETURN_OK) {
// sif::warning << "PusTcInjector: Sending TMTC message failed!" << std::endl;
// }
// return result;
//}
ReturnValue_t PusTcInjector::initialize() {
2022-01-17 15:58:27 +01:00
// Prepare message queue which is used to send telecommands.
injectionQueue = QueueFactory::instance()->createMessageQueue(INJECTION_QUEUE_DEPTH);
AcceptsTelecommandsIF* targetQueue =
ObjectManager::instance()->get<AcceptsTelecommandsIF>(destination);
if (targetQueue == nullptr) {
sif::error << "PusTcInjector: CCSDS distributor not initialized yet!" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
} else {
injectionQueue->setDefaultDestination(targetQueue->getRequestQueue());
}
2020-09-16 16:22:36 +02:00
2022-01-17 15:58:27 +01:00
// Prepare store used to store TC messages
tcStore = ObjectManager::instance()->get<StorageManagerIF>(tcStoreId);
if (tcStore == nullptr) {
sif::error << "PusTcInjector: TC Store not initialized!" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
2020-09-16 16:22:36 +02:00
}