scexDataHandler
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Irini Kosmidou
2022-04-29 15:46:16 +02:00
parent 57f3103e52
commit f2cb43a52f
10 changed files with 246 additions and 20 deletions

View File

@ -18,6 +18,7 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE
SusHandler.cpp
PayloadPcduHandler.cpp
SolarArrayDeploymentHandler.cpp
ScexDeviceHandler.cpp
)
add_subdirectory(devicedefinitions)

View File

@ -0,0 +1,128 @@
#include "ScexDeviceHandler.h"
#include <algorithm>
#include "mission/devices/devicedefinitions/ScexDefinitions.h"
#include "fsfw/globalfunctions/CRC.h"
#include <linux/devices/ScexHelper.h>
ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie)
: DeviceHandlerBase(objectId, reader.getObjectId(),cookie), reader(reader)
{
}
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(DeviceCommandId_t deviceCommand,
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) {
//helper.deSerialize(blabla);
//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() {}

View File

@ -0,0 +1,36 @@
#ifndef MISSION_DEVICES_SCEXDEVICEHANDLER_H_
#define MISSION_DEVICES_SCEXDEVICEHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <linux/devices/ScexHelper.h>
#include <linux/devices/ScexUartReader.h>
class ScexDeviceHandler : public DeviceHandlerBase {
public:
// ctor vervollst<73>ndigen
ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie);
private:
std::array<uint8_t, 64> cmdBuf = {};
// DeviceHandlerBase private function implementation
void doStartUp() override;
void doShutDown() override;
ScexHelper helper;
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,
size_t commandDataLen) override;
void fillCommandAndReplyMap() override;
ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId,
size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override;
void modeChanged() override;
};
#endif /* MISSION_DEVICES_SCEXDEVICEHANDLER_H_ */

View File

@ -1,5 +1,36 @@
#include "ScexDefinitions.h"
uint8_t scex::createCmdByte(ScexCmds cmd, bool tempCheck) {
#include <fsfw/globalfunctions/CRC.h>
#include <cstring>
uint8_t scex::createCmdByte(Cmds cmd, bool tempCheck) {
return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck;
}
ReturnValue_t scex::prepareScexCmd(scex::Cmds cmd, bool tempCheck,
std::pair<uint8_t*, size_t> cmdBufPair, size_t& cmdLen,
std::pair<const uint8_t*, size_t> usrDataPair) {
using namespace scex;
uint8_t* cmdBuf = cmdBufPair.first;
const uint8_t* userData = usrDataPair.first;
// Send command
if (cmdBuf == nullptr or (cmdBufPair.second < usrDataPair.second + HEADER_LEN + CRC_LEN) or
(usrDataPair.second > 0 and userData == nullptr)) {
cmdLen = 0;
return HasReturnvaluesIF::RETURN_FAILED;
}
cmdBuf[0] = scex::createCmdByte(cmd, tempCheck);
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
// telecommand so far
cmdBuf[1] = 1;
cmdBuf[2] = 1;
cmdBuf[3] = (usrDataPair.second >> 8) & 0xff;
cmdBuf[4] = usrDataPair.second & 0xff;
std::memcpy(cmdBuf + HEADER_LEN, userData, usrDataPair.second);
uint16_t crc = CRC::crc16ccitt(cmdBuf, usrDataPair.second + HEADER_LEN);
cmdBuf[usrDataPair.second + HEADER_LEN] = (crc >> 8) & 0xff;
cmdBuf[usrDataPair.second + HEADER_LEN + 1] = crc & 0xff;
cmdLen = usrDataPair.second + HEADER_LEN + CRC_LEN;
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,17 +1,46 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
#include <commonSubsystemIds.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <fsfw/events/Event.h>
#include <cstdint>
#include <vector>
// Definitions for the Solar Cell Experiment
namespace scex {
enum ScexCmds : uint8_t { PING = 0b00111, ONE_CELL = 0b00110, FRAM = 0b00001, INVALID = 255 };
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SCEX_HANDLER;
static constexpr Event MISSING_PACKET = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW);
static constexpr Event EXPERIMENT_TIMEDOUT = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW);
enum Cmds : DeviceCommandId_t {
PING = 0b00111,
ALL_CELLS_CMD = 0b00101,
ONE_CELL = 0b00110,
FRAM = 0b00001,
EXP_STATUS_CMD = 0b00010,
TEMP_CMD = 0b00011,
ION_CMD = 0b00100,
ERROR_REPLY = 0b01000,
INVALID = 255
};
static const std::vector<DeviceCommandId_t> VALID_CMDS = {
PING, ALL_CELLS_CMD, ONE_CELL, FRAM, EXP_STATUS_CMD, TEMP_CMD, ION_CMD};
static constexpr uint8_t HEADER_LEN = 5;
static constexpr uint8_t CRC_LEN = 2;
static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0;
static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1;
uint8_t createCmdByte(ScexCmds cmd, bool tempCheck);
uint8_t createCmdByte(Cmds cmd, bool tempCheck);
ReturnValue_t prepareScexCmd(scex::Cmds cmd, bool tempCheck, std::pair<uint8_t*, size_t> cmdBufPair,
size_t& cmdLen, std::pair<const uint8_t*, size_t> usrDataPair);
} // namespace scex