eive-obsw/mission/devices/ScexDeviceHandler.cpp
Irini Kosmidou 7179d9dec3
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
deSerialize
2022-05-19 09:59:33 +02:00

135 lines
4.2 KiB
C++

#include "ScexDeviceHandler.h"
#include <linux/devices/ScexHelper.h>
#include <algorithm>
#include "fsfw/globalfunctions/CRC.h"
#include "mission/devices/devicedefinitions/ScexDefinitions.h"
ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie)
: DeviceHandlerBase(objectId, reader.getObjectId(), cookie), reader(reader) {}
ScexDeviceHandler::~ScexDeviceHandler() {}
void ScexDeviceHandler::doStartUp() {
// mode on
setMode(MODE_ON);
}
void ScexDeviceHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
return RETURN_OK;
}
ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return RETURN_OK;
}
ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(
scex::Cmds deviceCommand, // DeviceCommandId_t
const uint8_t* commandData, size_t commandDataLen) {
using namespace scex;
if (not std::find(VALID_CMDS.begin(), VALID_CMDS.end(), deviceCommand) != VALID_CMDS.end()) {
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
if (commandDataLen < 1) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
switch (deviceCommand) {
case (PING): {
rawPacket = cmdBuf.size();
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
}
case (FRAM): {
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
}
case (ION_CMD): {
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
}
case (TEMP_CMD): {
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
}
case (ONE_CELL): {
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandData - 1});
return RETURN_OK;
}
case (ALL_CELLS_CMD): {
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandData - 1});
return RETURN_OK;
}
case (EXP_STATUS_CMD): {
prepareScexCmd(deviceCommand, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
}
}
return RETURN_OK;
}
void ScexDeviceHandler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(scex::Cmds::PING, 3);
insertInCommandAndReplyMap(scex::Cmds::ION_CMD, 3);
insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3);
insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_CMD, 3);
insertInCommandMap(scex::Cmds::ALL_CELLS_CMD);
insertInCommandMap(scex::Cmds::ONE_CELL);
insertInCommandMap(scex::Cmds::FRAM);
insertInReplyMap(scex::Cmds::ERROR_REPLY, 3);
}
ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
uint8_t* decodedPacket = nullptr;
size_t len = 0;
const uint8_t* helperPtr = decodedPacket;
ReturnValue_t result = helper.deSerialize(&helperPtr, &len);
if (result == ScexHelper::INVALID_CRC) {
sif::warning << "CRC invalid" << std::endl;
}
sif::info << helper << std::endl;
// crc check
*foundId = helper.getCmd();
*foundLen = remainingSize;
return RETURN_OK;
}
ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
// cmd auswertung (in file reinschreiben)
return RETURN_OK;
}
uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
return RETURN_OK;
}
ReturnValue_t ScexDeviceHandler::getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches) {
return RETURN_OK;
}
ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
return RETURN_OK;
}
void ScexDeviceHandler::modeChanged() {}