Merge remote-tracking branch 'origin/develop' into mueller/acs-ss-init
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
This commit is contained in:
@ -19,4 +19,7 @@ target_sources(
|
||||
max1227.cpp
|
||||
SusHandler.cpp
|
||||
PayloadPcduHandler.cpp
|
||||
SolarArrayDeploymentHandler.cpp)
|
||||
SolarArrayDeploymentHandler.cpp
|
||||
ScexDeviceHandler.cpp)
|
||||
|
||||
add_subdirectory(devicedefinitions)
|
||||
|
@ -20,7 +20,7 @@ IMTQHandler::IMTQHandler(object_id_t objectId, object_id_t comIF, CookieIF* comC
|
||||
posZselfTestDataset(this),
|
||||
negZselfTestDataset(this),
|
||||
switcher(pwrSwitcher) {
|
||||
if (comCookie == NULL) {
|
||||
if (comCookie == nullptr) {
|
||||
sif::error << "IMTQHandler: Invalid com cookie" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -491,8 +491,8 @@ void PayloadPcduHandler::checkAdcValues() {
|
||||
|
||||
void PayloadPcduHandler::checkJsonFileInit() {
|
||||
if (not jsonFileInitComplete) {
|
||||
sd::SdCard activeSd = sdcMan->getActiveSdCard();
|
||||
if (sdcMan->isSdCardUsable(activeSd)) {
|
||||
auto activeSd = sdcMan->getActiveSdCard();
|
||||
if (activeSd and sdcMan->isSdCardUsable(activeSd.value())) {
|
||||
params.initialize(sdcMan->getCurrentMountPrefix());
|
||||
jsonFileInitComplete = true;
|
||||
}
|
||||
|
369
mission/devices/ScexDeviceHandler.cpp
Normal file
369
mission/devices/ScexDeviceHandler.cpp
Normal file
@ -0,0 +1,369 @@
|
||||
#include "ScexDeviceHandler.h"
|
||||
|
||||
#include <linux/devices/ScexHelper.h>
|
||||
#include <mission/memory/SdCardMountedIF.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "mission/devices/devicedefinitions/ScexDefinitions.h"
|
||||
|
||||
using std::ofstream;
|
||||
using namespace returnvalue;
|
||||
|
||||
ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie,
|
||||
SdCardMountedIF& sdcMan)
|
||||
: DeviceHandlerBase(objectId, reader.getObjectId(), cookie), sdcMan(sdcMan), reader(reader) {}
|
||||
|
||||
ScexDeviceHandler::~ScexDeviceHandler() {}
|
||||
|
||||
void ScexDeviceHandler::doStartUp() { setMode(MODE_ON); }
|
||||
|
||||
void ScexDeviceHandler::doShutDown() {
|
||||
reader.reset();
|
||||
commandActive = false;
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { return OK; }
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { return OK; }
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
using namespace scex;
|
||||
|
||||
auto cmdTyped = static_cast<scex::Cmds>(deviceCommand);
|
||||
if (std::find(VALID_CMDS.begin(), VALID_CMDS.end(), deviceCommand) == VALID_CMDS.end()) {
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
bool tempCheck = false;
|
||||
if (commandDataLen == 1) {
|
||||
tempCheck = commandData[0];
|
||||
}
|
||||
if (commandActive) {
|
||||
return DeviceHandlerIF::BUSY;
|
||||
}
|
||||
|
||||
switch (deviceCommand) {
|
||||
case (PING): {
|
||||
finishCountdown.setTimeout(SHORT_CD);
|
||||
// countdown starten
|
||||
finishCountdown.resetTimer();
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
|
||||
tempCheck);
|
||||
break;
|
||||
}
|
||||
case (EXP_STATUS_CMD): {
|
||||
finishCountdown.setTimeout(SHORT_CD);
|
||||
// countdown starten
|
||||
finishCountdown.resetTimer();
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
|
||||
tempCheck);
|
||||
break;
|
||||
}
|
||||
case (ION_CMD): {
|
||||
finishCountdown.setTimeout(SHORT_CD);
|
||||
// countdown starten
|
||||
finishCountdown.resetTimer();
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
|
||||
tempCheck);
|
||||
break;
|
||||
}
|
||||
case (TEMP_CMD): {
|
||||
finishCountdown.setTimeout(SHORT_CD);
|
||||
// countdown starten
|
||||
finishCountdown.resetTimer();
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
|
||||
tempCheck);
|
||||
break;
|
||||
}
|
||||
case (FRAM): {
|
||||
finishCountdown.setTimeout(LONG_CD);
|
||||
// countdown starten
|
||||
finishCountdown.resetTimer();
|
||||
if (debugMode) {
|
||||
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
|
||||
|
||||
sif::info << "ScexDeviceHandler::buildCommandFromCommand: RemainingMillis: "
|
||||
<< remainingMillis << std::endl;
|
||||
}
|
||||
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
|
||||
{commandData + 1, commandDataLen - 1}, tempCheck);
|
||||
updatePeriodicReply(true, deviceCommand);
|
||||
finishAction(true, deviceCommand, OK);
|
||||
break;
|
||||
}
|
||||
case (ONE_CELL): {
|
||||
finishCountdown.setTimeout(LONG_CD);
|
||||
// countdown starts
|
||||
finishCountdown.resetTimer();
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
|
||||
{commandData + 1, commandDataLen - 1}, tempCheck);
|
||||
updatePeriodicReply(true, deviceCommand);
|
||||
finishAction(true, deviceCommand, OK);
|
||||
break;
|
||||
}
|
||||
case (ALL_CELLS_CMD): {
|
||||
finishCountdown.setTimeout(LONG_CD);
|
||||
// countdown starts
|
||||
finishCountdown.resetTimer();
|
||||
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
|
||||
{commandData + 1, commandDataLen - 1}, tempCheck);
|
||||
finishAction(true, deviceCommand, OK);
|
||||
updatePeriodicReply(true, deviceCommand);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
commandActive = true;
|
||||
rawPacket = cmdBuf.data();
|
||||
return OK;
|
||||
}
|
||||
|
||||
void ScexDeviceHandler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(scex::Cmds::PING, 5, nullptr, 0, false, false, 0, &finishCountdown);
|
||||
insertInCommandAndReplyMap(scex::Cmds::ION_CMD, 3, nullptr, 0, false, false, 0, &finishCountdown);
|
||||
insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3, nullptr, 0, false, false, 0,
|
||||
&finishCountdown);
|
||||
insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_CMD, 3, nullptr, 0, false, false, 0,
|
||||
&finishCountdown);
|
||||
|
||||
insertInCommandAndReplyMap(scex::Cmds::ALL_CELLS_CMD, 0, nullptr, 0, true, false,
|
||||
scex::Cmds::ALL_CELLS_CMD, &finishCountdown);
|
||||
insertInCommandAndReplyMap(scex::Cmds::ONE_CELL, 0, nullptr, 0, true, false, scex::Cmds::ONE_CELL,
|
||||
&finishCountdown);
|
||||
insertInCommandAndReplyMap(scex::Cmds::FRAM, 0, nullptr, 0, true, false, scex::Cmds::FRAM,
|
||||
&finishCountdown);
|
||||
|
||||
insertInReplyMap(scex::Cmds::ERROR_REPLY, 3);
|
||||
}
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||
size_t len = remainingSize;
|
||||
ReturnValue_t result = helper.deSerialize(&start, &len);
|
||||
|
||||
if (result == ScexHelper::INVALID_CRC) {
|
||||
sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl;
|
||||
*foundLen = remainingSize;
|
||||
} else {
|
||||
result = handleValidReply(remainingSize, foundId, foundLen);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::handleValidReply(size_t remSize, DeviceCommandId_t* foundId,
|
||||
size_t* foundLen) {
|
||||
using namespace scex;
|
||||
ReturnValue_t result = OK;
|
||||
|
||||
switch (helper.getCmd()) {
|
||||
case (FRAM): {
|
||||
if (debugMode) {
|
||||
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
|
||||
|
||||
sif::info << "ScexDeviceHandler::handleValidReply: RemMillis: " << remainingMillis
|
||||
<< std::endl;
|
||||
}
|
||||
result = APERIODIC_REPLY;
|
||||
break;
|
||||
}
|
||||
case (ONE_CELL): {
|
||||
result = APERIODIC_REPLY;
|
||||
break;
|
||||
}
|
||||
case (ALL_CELLS_CMD): {
|
||||
result = APERIODIC_REPLY;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*foundId = helper.getCmd();
|
||||
*foundLen = remSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
|
||||
using namespace scex;
|
||||
|
||||
ReturnValue_t status = OK;
|
||||
auto oneFileHandler = [&](std::string cmdName) {
|
||||
fileId = date_time_string();
|
||||
std::ostringstream oss;
|
||||
auto prefix = sdcMan.getCurrentMountPrefix();
|
||||
oss << prefix << "/scex/scex-" << cmdName << fileId << ".bin";
|
||||
fileName = oss.str();
|
||||
ofstream out(fileName, ofstream::binary);
|
||||
if (out.bad()) {
|
||||
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
|
||||
<< std::endl;
|
||||
return FAILED;
|
||||
}
|
||||
out << helper;
|
||||
return OK;
|
||||
};
|
||||
auto multiFileHandler = [&](std::string cmdName) {
|
||||
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
|
||||
fileId = date_time_string();
|
||||
std::ostringstream oss;
|
||||
auto prefix = sdcMan.getCurrentMountPrefix();
|
||||
oss << prefix << "/scex/scex-" << cmdName << fileId << ".bin";
|
||||
fileName = oss.str();
|
||||
fileNameSet = true;
|
||||
ofstream out(fileName, ofstream::binary);
|
||||
if (out.bad()) {
|
||||
sif::error << "ScexDeviceHandler::handleValidReply: Could not open file " << fileName
|
||||
<< std::endl;
|
||||
return FAILED;
|
||||
}
|
||||
out << helper;
|
||||
} else {
|
||||
ofstream out(fileName,
|
||||
ofstream::binary | ofstream::app); // append
|
||||
if (out.bad()) {
|
||||
sif::error << "ScexDeviceHandler::handleValidReply: Could not open file " << fileName
|
||||
<< std::endl;
|
||||
return FAILED;
|
||||
}
|
||||
out << helper;
|
||||
}
|
||||
return OK;
|
||||
};
|
||||
switch (id) {
|
||||
case (PING): {
|
||||
status = oneFileHandler("ping_");
|
||||
break;
|
||||
}
|
||||
case (ION_CMD): {
|
||||
status = oneFileHandler("ion_");
|
||||
break;
|
||||
}
|
||||
case (TEMP_CMD): {
|
||||
status = oneFileHandler("temp_");
|
||||
break;
|
||||
}
|
||||
case (EXP_STATUS_CMD): {
|
||||
status = oneFileHandler("exp_status_");
|
||||
break;
|
||||
}
|
||||
case (FRAM): {
|
||||
status = multiFileHandler("fram_");
|
||||
break;
|
||||
}
|
||||
case (ONE_CELL): {
|
||||
status = multiFileHandler("one_cell_");
|
||||
break;
|
||||
}
|
||||
case (ALL_CELLS_CMD): {
|
||||
status = multiFileHandler("multi_cell_");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Unknown DeviceCommand
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
|
||||
reader.finish();
|
||||
commandActive = false;
|
||||
if (id != PING) {
|
||||
fileNameSet = false;
|
||||
}
|
||||
if (id == FRAM or id == ALL_CELLS_CMD or id == ONE_CELL) {
|
||||
triggerEvent(MULTI_PACKET_COMMAND_DONE, id);
|
||||
updatePeriodicReply(false, id);
|
||||
}
|
||||
}
|
||||
if (debugMode) {
|
||||
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
|
||||
sif::info << __FILE__ << __func__ << "(" << __LINE__ << ") RemMillis: " << remainingMillis
|
||||
<< std::endl;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void ScexDeviceHandler::performOperationHook() {
|
||||
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
|
||||
if (commandActive and finishCountdown.hasTimedOut()) {
|
||||
triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0);
|
||||
reader.finish();
|
||||
sif::warning << "ScexDeviceHandler::scanForReply: Reader timeout; RemMillis: "
|
||||
<< remainingMillis << std::endl;
|
||||
fileNameSet = false;
|
||||
commandActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return OK; }
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches) {
|
||||
if (switchId) {
|
||||
*numberOfSwitches = 1;
|
||||
*switches = &switchId.value();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
std::string ScexDeviceHandler::date_time_string() {
|
||||
using namespace std;
|
||||
string date_time;
|
||||
Clock::TimeOfDay_t tod;
|
||||
Clock::getDateAndTime(&tod);
|
||||
ostringstream oss(std::ostringstream::ate);
|
||||
|
||||
if (tod.hour < 10) {
|
||||
oss << tod.year << tod.month << tod.day << "_0" << tod.hour;
|
||||
} else {
|
||||
oss << tod.year << tod.month << tod.day << "_" << tod.hour;
|
||||
}
|
||||
if (tod.minute < 10) {
|
||||
oss << 0 << tod.minute;
|
||||
|
||||
} else {
|
||||
oss << tod.minute;
|
||||
}
|
||||
if (tod.second < 10) {
|
||||
oss << 0 << tod.second;
|
||||
} else {
|
||||
oss << tod.second;
|
||||
}
|
||||
|
||||
date_time = oss.str();
|
||||
|
||||
return date_time;
|
||||
}
|
||||
|
||||
void ScexDeviceHandler::modeChanged() {}
|
||||
|
||||
void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Switch_t switchId) {
|
||||
DeviceHandlerBase::setPowerSwitcher(&powerSwitcher);
|
||||
this->switchId = switchId;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexDeviceHandler::initializeAfterTaskCreation() {
|
||||
auto mntPrefix = sdcMan.getCurrentMountPrefix();
|
||||
std::filesystem::path fullFilePath = mntPrefix;
|
||||
fullFilePath /= "scex";
|
||||
bool fileExists = std::filesystem::exists(fullFilePath);
|
||||
|
||||
if (not fileExists) {
|
||||
std::filesystem::create_directory(fullFilePath);
|
||||
}
|
||||
return DeviceHandlerBase::initializeAfterTaskCreation();
|
||||
}
|
64
mission/devices/ScexDeviceHandler.h
Normal file
64
mission/devices/ScexDeviceHandler.h
Normal file
@ -0,0 +1,64 @@
|
||||
#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>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "eive/eventSubsystemIds.h"
|
||||
|
||||
class SdCardMountedIF;
|
||||
|
||||
class ScexDeviceHandler : public DeviceHandlerBase {
|
||||
public:
|
||||
ScexDeviceHandler(object_id_t objectId, ScexUartReader &reader, CookieIF *cookie,
|
||||
SdCardMountedIF &sdcMan);
|
||||
void setPowerSwitcher(PowerSwitchIF &powerSwitcher, power::Switch_t switchId);
|
||||
virtual ~ScexDeviceHandler();
|
||||
|
||||
private:
|
||||
static constexpr uint32_t LONG_CD = 180 * 1000;
|
||||
static constexpr uint32_t SHORT_CD = 12000;
|
||||
std::array<uint8_t, 64> cmdBuf = {};
|
||||
|
||||
std::optional<power::Switch_t> switchId;
|
||||
std::string fileId = "";
|
||||
std::string fileName = "";
|
||||
bool fileNameSet = false;
|
||||
bool commandActive = false;
|
||||
bool debugMode = false;
|
||||
|
||||
scex::Cmds currCmd = scex::Cmds::PING;
|
||||
SdCardMountedIF &sdcMan;
|
||||
Countdown finishCountdown = Countdown(LONG_CD);
|
||||
|
||||
std::string date_time_string();
|
||||
|
||||
// DeviceHandlerBase private function implementation
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ScexHelper helper;
|
||||
ScexUartReader &reader;
|
||||
|
||||
void performOperationHook() override;
|
||||
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;
|
||||
ReturnValue_t handleValidReply(size_t remSize, DeviceCommandId_t *foundId, size_t *foundLen);
|
||||
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;
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
void modeChanged() override;
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_SCEXDEVICEHANDLER_H_ */
|
1
mission/devices/devicedefinitions/CMakeLists.txt
Normal file
1
mission/devices/devicedefinitions/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
target_sources(${LIB_EIVE_MISSION} PRIVATE ScexDefinitions.cpp)
|
@ -1,13 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Definitions for the Solar Cell Experiment
|
||||
namespace scex {
|
||||
|
||||
static constexpr uint8_t CMD_PING = 0x4e;
|
||||
|
||||
}
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ */
|
35
mission/devices/devicedefinitions/ScexDefinitions.cpp
Normal file
35
mission/devices/devicedefinitions/ScexDefinitions.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "ScexDefinitions.h"
|
||||
|
||||
#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(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufPair, size_t& cmdLen,
|
||||
std::pair<const uint8_t*, size_t> usrDataPair, bool tempCheck) {
|
||||
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 returnvalue::FAILED;
|
||||
}
|
||||
cmdBuf[0] = 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 returnvalue::OK;
|
||||
}
|
52
mission/devices/devicedefinitions/ScexDefinitions.h
Normal file
52
mission/devices/devicedefinitions/ScexDefinitions.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <fsfw/events/Event.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "eive/eventSubsystemIds.h"
|
||||
#include "eive/objects.h"
|
||||
|
||||
// Definitions for the Solar Cell Experiment
|
||||
namespace scex {
|
||||
|
||||
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, 1, severity::LOW);
|
||||
//! FRAM, One Cell or All cells command finished. P1: Command ID
|
||||
static constexpr Event MULTI_PACKET_COMMAND_DONE =
|
||||
event::makeEvent(SUBSYSTEM_ID, 2, severity::INFO);
|
||||
|
||||
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(Cmds cmd, bool tempCheck = false);
|
||||
|
||||
ReturnValue_t prepareScexCmd(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufPair, size_t& cmdLen,
|
||||
std::pair<const uint8_t*, size_t> usrDataPair, bool tempCheck = false);
|
||||
|
||||
} // namespace scex
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ */
|
@ -1,6 +1,7 @@
|
||||
#ifndef MISSION_MEMORY_SDCARDMOUNTERIF_H_
|
||||
#define MISSION_MEMORY_SDCARDMOUNTERIF_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "definitions.h"
|
||||
@ -8,11 +9,11 @@
|
||||
class SdCardMountedIF {
|
||||
public:
|
||||
virtual ~SdCardMountedIF(){};
|
||||
virtual std::string getCurrentMountPrefix() const = 0;
|
||||
virtual const std::string& getCurrentMountPrefix() const = 0;
|
||||
virtual bool isSdCardUsable(sd::SdCard sdCard) = 0;
|
||||
virtual sd::SdCard getPreferredSdCard() const = 0;
|
||||
virtual std::optional<sd::SdCard> getPreferredSdCard() const = 0;
|
||||
virtual void setActiveSdCard(sd::SdCard sdCard) = 0;
|
||||
virtual sd::SdCard getActiveSdCard() const = 0;
|
||||
virtual std::optional<sd::SdCard> getActiveSdCard() const = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
@ -1,12 +1,11 @@
|
||||
#ifndef MISSION_UTILITY_INITMISSION_H_
|
||||
#define MISSION_UTILITY_INITMISSION_H_
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/objectmanager/SystemObjectIF.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
namespace initmission {
|
||||
|
||||
void printAddObjectError(const char* name, object_id_t objectId) {
|
||||
static void printAddObjectError(const char* name, object_id_t objectId) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "InitMission::printAddError: Adding object " << name << " with object ID 0x"
|
||||
<< std::hex << std::setfill('0') << std::setw(8) << objectId << " failed!" << std::dec
|
||||
@ -18,5 +17,3 @@ void printAddObjectError(const char* name, object_id_t objectId) {
|
||||
}
|
||||
|
||||
} // namespace initmission
|
||||
|
||||
#endif /* MISSION_UTILITY_INITMISSION_H_ */
|
||||
|
Reference in New Issue
Block a user