fsfw/tests/src/fsfw_tests/unit/devicehandler/DeviceHandlerMock.cpp

104 lines
3.3 KiB
C++
Raw Normal View History

2022-05-16 11:10:35 +02:00
#include "DeviceHandlerMock.h"
2022-06-05 12:52:55 +02:00
#include <catch2/catch_test_macros.hpp>
2022-05-16 11:10:35 +02:00
2022-06-05 12:52:55 +02:00
DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication,
CookieIF *comCookie, FailureIsolationBase *fdirInstance)
: DeviceHandlerBase(objectId, deviceCommunication, comCookie, fdirInstance) {
mode = MODE_ON;
2022-05-16 11:10:35 +02:00
}
2022-06-05 12:52:55 +02:00
DeviceHandlerMock::~DeviceHandlerMock() {}
2022-05-16 11:10:35 +02:00
2022-06-05 12:52:55 +02:00
void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); }
void DeviceHandlerMock::doShutDown() { setMode(_MODE_POWER_DOWN); }
2022-05-16 11:10:35 +02:00
ReturnValue_t DeviceHandlerMock::buildNormalDeviceCommand(DeviceCommandId_t *id) {
return NOTHING_TO_SEND;
}
ReturnValue_t DeviceHandlerMock::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
return NOTHING_TO_SEND;
}
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
2022-06-05 12:52:55 +02:00
switch (deviceCommand) {
case SIMPLE_COMMAND: {
commandBuffer[0] = SIMPLE_COMMAND_DATA;
2022-05-16 11:10:35 +02:00
rawPacket = commandBuffer;
2022-06-05 12:52:55 +02:00
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
break;
2022-05-16 11:10:35 +02:00
}
default:
WARN("DeviceHandlerMock::buildCommandFromCommand: Invalid device command");
2022-06-05 12:52:55 +02:00
break;
2022-05-16 11:10:35 +02:00
}
return RETURN_OK;
}
2022-06-05 12:52:55 +02:00
ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) {
switch (*start) {
2022-06-06 11:55:42 +02:00
case SIMPLE_COMMAND_DATA: {
*foundId = SIMPLE_COMMAND;
*foundLen = sizeof(SIMPLE_COMMAND_DATA);
return RETURN_OK;
break;
}
case PERIODIC_REPLY_DATA: {
2022-06-05 12:52:55 +02:00
*foundId = PERIODIC_REPLY;
*foundLen = sizeof(PERIODIC_REPLY_DATA);
2022-05-16 11:10:35 +02:00
return RETURN_OK;
break;
}
default:
break;
}
return RETURN_FAILED;
}
ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
2022-06-05 12:52:55 +02:00
switch (id) {
case SIMPLE_COMMAND:
case PERIODIC_REPLY: {
2022-06-06 11:55:42 +02:00
periodicReplyReceived = true;
2022-05-16 11:10:35 +02:00
break;
2022-06-05 12:52:55 +02:00
}
2022-05-16 11:10:35 +02:00
default:
break;
}
2022-06-05 12:52:55 +02:00
return RETURN_OK;
2022-05-16 11:10:35 +02:00
}
void DeviceHandlerMock::fillCommandAndReplyMap() {
2022-06-06 11:55:42 +02:00
insertInCommandAndReplyMap(SIMPLE_COMMAND, 0, nullptr, 0, false, false, 0,
&simpleCommandReplyTimeout);
insertInCommandAndReplyMap(PERIODIC_REPLY, 0, nullptr, 0, true, false, 0,
2022-06-05 12:52:55 +02:00
&periodicReplyCountdown);
2022-05-16 11:10:35 +02:00
}
2022-06-05 12:52:55 +02:00
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
void DeviceHandlerMock::changePeriodicReplyCountdown(uint32_t timeout) {
periodicReplyCountdown.setTimeout(timeout);
}
void DeviceHandlerMock::changeSimpleCommandReplyCountdown(uint32_t timeout) {
simpleCommandReplyTimeout.setTimeout(timeout);
2022-05-16 11:10:35 +02:00
}
2022-06-06 11:55:42 +02:00
void DeviceHandlerMock::resetPeriodicReplyState() { periodicReplyReceived = false; }
2022-06-05 12:52:55 +02:00
2022-06-06 11:55:42 +02:00
bool DeviceHandlerMock::getPeriodicReplyReceived() { return periodicReplyReceived; }
ReturnValue_t DeviceHandlerMock::enablePeriodicReply(DeviceCommandId_t replyId) {
return updatePeriodicReply(true, replyId);
}
ReturnValue_t DeviceHandlerMock::disablePeriodicReply(DeviceCommandId_t replyId) {
return updatePeriodicReply(false, replyId);
}