#include "TestEchoComIF.h" #include "TestCookie.h" #include #include #include #include TestEchoComIF::TestEchoComIF(object_id_t objectId): SystemObject(objectId) { } TestEchoComIF::~TestEchoComIF() {} ReturnValue_t TestEchoComIF::initializeInterface(CookieIF * cookie) { TestCookie* testCookie = dynamic_cast(cookie); if(testCookie == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TestEchoComIF::initializeInterface: Invalid cookie!" << std::endl; #else sif::printWarning("TestEchoComIF::initializeInterface: Invalid cookie!\n"); #endif return HasReturnvaluesIF::RETURN_FAILED; } replyBuffer.reserve(testCookie->getReplyMaxLen()); replyBuffer.resize(testCookie->getReplyMaxLen()); return RETURN_OK; } ReturnValue_t TestEchoComIF::sendMessage(CookieIF *cookie, const uint8_t * sendData, size_t sendLen) { if(sendLen > replyBuffer.size()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TestEchoComIF::sendMessage: Send length larger than current reply buffer " "length. Allocating additional memory!" << std::endl; #else sif::printWarning("TestEchoComIF::sendMessage: Send length larger than current reply buffer " "length. Allocating additional memory!\n"); #endif replyBuffer.reserve(sendLen); replyBuffer.resize(sendLen); } memcpy(replyBuffer.data(),sendData, sendLen); dummyBufferSize = sendLen; return RETURN_OK; } ReturnValue_t TestEchoComIF::getSendSuccess(CookieIF *cookie) { return RETURN_OK; } ReturnValue_t TestEchoComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) { return RETURN_OK; } ReturnValue_t TestEchoComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) { *buffer = replyBuffer.data(); *size = dummyBufferSize; this->dummyBufferSize = 0; dummyReplyCounter ++; if(dummyReplyCounter == 10) { // add anything that needs to be read periodically by dummy handler dummyReplyCounter = 0; } return RETURN_OK; }