From 7179d9dec314f35ccfa48bb1042754fb5bf8ec50 Mon Sep 17 00:00:00 2001 From: Irini Kosmidou Date: Thu, 19 May 2022 09:59:33 +0200 Subject: [PATCH] deSerialize --- mission/devices/ScexDeviceHandler.cpp | 36 ++++++++++++++++----------- mission/devices/ScexDeviceHandler.h | 10 +++++--- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mission/devices/ScexDeviceHandler.cpp b/mission/devices/ScexDeviceHandler.cpp index fe948a7e..8b80bc0e 100644 --- a/mission/devices/ScexDeviceHandler.cpp +++ b/mission/devices/ScexDeviceHandler.cpp @@ -1,16 +1,16 @@ #include "ScexDeviceHandler.h" +#include + #include -#include "mission/devices/devicedefinitions/ScexDefinitions.h" #include "fsfw/globalfunctions/CRC.h" -#include +#include "mission/devices/devicedefinitions/ScexDefinitions.h" ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie) - : DeviceHandlerBase(objectId, reader.getObjectId(),cookie), reader(reader) -{ + : DeviceHandlerBase(objectId, reader.getObjectId(), cookie), reader(reader) {} -} +ScexDeviceHandler::~ScexDeviceHandler() {} void ScexDeviceHandler::doStartUp() { // mode on @@ -27,9 +27,9 @@ ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* return RETURN_OK; } -ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, - const uint8_t* commandData, - size_t commandDataLen) { +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()) { @@ -96,17 +96,25 @@ void ScexDeviceHandler::fillCommandAndReplyMap() { ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId, size_t* foundLen) { - //helper.deSerialize(blabla); - //crc check + uint8_t* decodedPacket = nullptr; + size_t len = 0; - *foundId = helper.getCmd(); - *foundLen = remainingSize; + 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) + // cmd auswertung (in file reinschreiben) return RETURN_OK; } @@ -123,6 +131,4 @@ ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& lo return RETURN_OK; } - - void ScexDeviceHandler::modeChanged() {} diff --git a/mission/devices/ScexDeviceHandler.h b/mission/devices/ScexDeviceHandler.h index 5058ed3b..f5a46971 100644 --- a/mission/devices/ScexDeviceHandler.h +++ b/mission/devices/ScexDeviceHandler.h @@ -7,8 +7,10 @@ class ScexDeviceHandler : public DeviceHandlerBase { public: - // ctor vervollständigen - ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie); + // ctor vervollständigen + ScexDeviceHandler(object_id_t objectId, ScexUartReader &reader, CookieIF *cookie); + virtual ~ScexDeviceHandler(); + private: std::array cmdBuf = {}; @@ -16,10 +18,10 @@ class ScexDeviceHandler : public DeviceHandlerBase { void doStartUp() override; void doShutDown() override; ScexHelper helper; - ScexUartReader& reader; + ScexUartReader &reader; ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override; ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override; - ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData, + ReturnValue_t buildCommandFromCommand(scex::Cmds deviceCommand, const uint8_t *commandData, size_t commandDataLen) override; void fillCommandAndReplyMap() override; ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId,