2021-04-27 17:22:34 +02:00
|
|
|
#include "TestEchoComIF.h"
|
|
|
|
#include "TestCookie.h"
|
|
|
|
|
|
|
|
#include <fsfw/serialize/SerializeAdapter.h>
|
|
|
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
|
|
|
#include <fsfw/tmtcservices/CommandingServiceBase.h>
|
|
|
|
#include <fsfw/tmtcpacket/pus/TmPacketStored.h>
|
|
|
|
|
|
|
|
|
|
|
|
TestEchoComIF::TestEchoComIF(object_id_t objectId):
|
|
|
|
SystemObject(objectId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
TestEchoComIF::~TestEchoComIF() {}
|
|
|
|
|
|
|
|
ReturnValue_t TestEchoComIF::initializeInterface(CookieIF * cookie) {
|
2021-04-29 15:58:00 +02:00
|
|
|
DummyCookie* dummyCookie = dynamic_cast<DummyCookie*>(cookie);
|
|
|
|
if(dummyCookie == nullptr) {
|
2021-04-27 17:22:34 +02:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "TestEchoComIF::initializeInterface: Invalid cookie!" << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printWarning("TestEchoComIF::initializeInterface: Invalid cookie!\n");
|
|
|
|
#endif
|
2021-04-29 15:58:00 +02:00
|
|
|
return NULLPOINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto resultPair = replyMap.emplace(
|
|
|
|
dummyCookie->getAddress(), ReplyBuffer(dummyCookie->getReplyMaxLen()));
|
|
|
|
if(not resultPair.second) {
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
2021-04-27 17:22:34 +02:00
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TestEchoComIF::sendMessage(CookieIF *cookie,
|
|
|
|
const uint8_t * sendData, size_t sendLen) {
|
2021-04-29 15:58:00 +02:00
|
|
|
DummyCookie* dummyCookie = dynamic_cast<DummyCookie*>(cookie);
|
|
|
|
if(dummyCookie == nullptr) {
|
|
|
|
return NULLPOINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyBuffer& replyBuffer = replyMap.find(dummyCookie->getAddress())->second;
|
|
|
|
if(sendLen > replyBuffer.capacity()) {
|
2021-04-27 17:22:34 +02:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-04-29 15:58:00 +02:00
|
|
|
sif::warning << "TestEchoComIF::sendMessage: Send length " << sendLen << " larger than "
|
|
|
|
"current reply buffer length!" << std::endl;
|
2021-04-27 17:22:34 +02:00
|
|
|
#else
|
2021-04-29 15:58:00 +02:00
|
|
|
sif::printWarning("TestEchoComIF::sendMessage: Send length %d larger than current "
|
|
|
|
"reply buffer length!\n", sendLen);
|
2021-04-27 17:22:34 +02:00
|
|
|
#endif
|
2021-04-29 15:58:00 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
2021-04-27 17:22:34 +02:00
|
|
|
}
|
2021-04-29 15:58:00 +02:00
|
|
|
replyBuffer.resize(sendLen);
|
|
|
|
memcpy(replyBuffer.data(), sendData, sendLen);
|
2021-04-27 17:22:34 +02:00
|
|
|
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) {
|
2021-04-29 15:58:00 +02:00
|
|
|
DummyCookie* dummyCookie = dynamic_cast<DummyCookie*>(cookie);
|
|
|
|
if(dummyCookie == nullptr) {
|
|
|
|
return NULLPOINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyBuffer& replyBuffer = replyMap.find(dummyCookie->getAddress())->second;
|
2021-04-27 17:22:34 +02:00
|
|
|
*buffer = replyBuffer.data();
|
2021-04-29 15:58:00 +02:00
|
|
|
*size = replyBuffer.size();
|
2021-04-27 17:22:34 +02:00
|
|
|
|
|
|
|
dummyReplyCounter ++;
|
|
|
|
if(dummyReplyCounter == 10) {
|
|
|
|
// add anything that needs to be read periodically by dummy handler
|
|
|
|
dummyReplyCounter = 0;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|