fsfw/unittests/devicehandler/DeviceHandlerCommander.cpp

65 lines
2.2 KiB
C++
Raw Normal View History

2022-07-18 08:59:40 +02:00
#include "DeviceHandlerCommander.h"
#include <fsfw/ipc/QueueFactory.h>
DeviceHandlerCommander::DeviceHandlerCommander(object_id_t objectId)
: SystemObject(objectId), commandActionHelper(this) {
auto mqArgs = MqArgs(this->getObjectId());
commandQueue = QueueFactory::instance()->createMessageQueue(
QUEUE_SIZE, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
}
DeviceHandlerCommander::~DeviceHandlerCommander() {}
ReturnValue_t DeviceHandlerCommander::performOperation(uint8_t operationCode) {
readCommandQueue();
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2022-07-18 08:59:40 +02:00
}
ReturnValue_t DeviceHandlerCommander::initialize() {
ReturnValue_t result = commandActionHelper.initialize();
2022-08-15 20:28:16 +02:00
if (result != returnvalue::OK) {
2022-07-18 08:59:40 +02:00
return result;
}
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2022-07-18 08:59:40 +02:00
}
MessageQueueIF* DeviceHandlerCommander::getCommandQueuePtr() { return commandQueue; }
void DeviceHandlerCommander::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) {}
void DeviceHandlerCommander::stepFailedReceived(ActionId_t actionId, uint8_t step,
ReturnValue_t returnCode) {}
void DeviceHandlerCommander::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) {
}
void DeviceHandlerCommander::completionSuccessfulReceived(ActionId_t actionId) {
2022-08-15 20:28:16 +02:00
lastReplyReturnCode = returnvalue::OK;
2022-07-18 08:59:40 +02:00
}
void DeviceHandlerCommander::completionFailedReceived(ActionId_t actionId,
ReturnValue_t returnCode) {
lastReplyReturnCode = returnCode;
}
void DeviceHandlerCommander::readCommandQueue() {
CommandMessage message;
2022-08-15 20:28:16 +02:00
ReturnValue_t result = returnvalue::OK;
for (result = commandQueue->receiveMessage(&message); result == returnvalue::OK;
2022-07-18 08:59:40 +02:00
result = commandQueue->receiveMessage(&message)) {
result = commandActionHelper.handleReply(&message);
2022-08-15 20:28:16 +02:00
if (result == returnvalue::OK) {
2022-07-18 08:59:40 +02:00
continue;
}
}
}
ReturnValue_t DeviceHandlerCommander::sendCommand(object_id_t target, ActionId_t actionId) {
return commandActionHelper.commandAction(target, actionId, nullptr, 0);
}
ReturnValue_t DeviceHandlerCommander::getReplyReturnCode() { return lastReplyReturnCode; }
2022-08-15 20:28:16 +02:00
void DeviceHandlerCommander::resetReplyReturnCode() { lastReplyReturnCode = returnvalue::FAILED; }