scexDataHandler
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user