add syrlinks submode handling
Some checks are pending
EIVE/eive-obsw/pipeline/head Build started...
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
2023-01-24 19:40:27 +01:00
parent 1f08d85319
commit ae6f6538d2
4 changed files with 117 additions and 21 deletions

View File

@ -1,10 +1,11 @@
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/globalfunctions/CRC.h>
#include <mission/devices/SyrlinksHandler.h>
#include "OBSWConfig.h"
SyrlinksHandler::SyrlinksHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
power::Switch_t powerSwitch, FailureIsolationBase* customFdir)
power::Switch_t powerSwitch, FailureIsolationBase* customFdir)
: DeviceHandlerBase(objectId, comIF, comCookie, customFdir),
rxDataset(this),
txDataset(this),
@ -15,16 +16,17 @@ SyrlinksHandler::SyrlinksHandler(object_id_t objectId, object_id_t comIF, Cookie
}
}
SyrlinksHandler::~SyrlinksHandler() {}
SyrlinksHandler::~SyrlinksHandler() = default;
void SyrlinksHandler::doStartUp() {
switch (startupState) {
case StartupState::OFF: {
startupState = StartupState::ENABLE_TEMPERATURE_PROTECTION;
switch (internalState) {
case InternalState::OFF: {
internalState = InternalState::ENABLE_TEMPERATURE_PROTECTION;
break;
}
case StartupState::DONE: {
case InternalState::IDLE: {
setMode(_MODE_TO_ON);
commandExecuted = false;
break;
}
default:
@ -34,6 +36,8 @@ void SyrlinksHandler::doStartUp() {
void SyrlinksHandler::doShutDown() {
setMode(_MODE_POWER_DOWN);
commandExecuted = false;
internalState = InternalState::OFF;
temperatureSet.setValidity(false, true);
}
@ -84,11 +88,23 @@ ReturnValue_t SyrlinksHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
}
ReturnValue_t SyrlinksHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
switch (startupState) {
case StartupState::ENABLE_TEMPERATURE_PROTECTION: {
switch (internalState) {
case InternalState::ENABLE_TEMPERATURE_PROTECTION: {
*id = syrlinks::WRITE_LCL_CONFIG;
return buildCommandFromCommand(*id, nullptr, 0);
}
case InternalState::SET_TX_MODULATION: {
*id = syrlinks::SET_TX_MODE_MODULATION;
return buildCommandFromCommand(*id, nullptr, 0);
}
case InternalState::SET_TX_CW: {
*id = syrlinks::SET_TX_MODE_CW;
return buildCommandFromCommand(*id, nullptr, 0);
}
case InternalState::SET_TX_STANDBY: {
*id = syrlinks::SET_TX_MODE_STANDBY;
return buildCommandFromCommand(*id, nullptr, 0);
}
default:
break;
}
@ -96,8 +112,8 @@ ReturnValue_t SyrlinksHandler::buildTransitionDeviceCommand(DeviceCommandId_t* i
}
ReturnValue_t SyrlinksHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
const uint8_t* commandData,
size_t commandDataLen) {
switch (deviceCommand) {
case (syrlinks::RESET_UNIT): {
prepareCommand(resetCommand, deviceCommand);
@ -223,7 +239,7 @@ void SyrlinksHandler::fillCommandAndReplyMap() {
}
ReturnValue_t SyrlinksHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
DeviceCommandId_t* foundId, size_t* foundLen) {
ReturnValue_t result = returnvalue::OK;
if (*start != '<') {
@ -592,7 +608,7 @@ void SyrlinksHandler::setNormalDatapoolEntriesInvalid() {}
uint32_t SyrlinksHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
ReturnValue_t SyrlinksHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(syrlinks::RX_STATUS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(syrlinks::RX_SENSITIVITY, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(syrlinks::RX_FREQUENCY_SHIFT, new PoolEntry<int32_t>({0}));
@ -624,10 +640,36 @@ float SyrlinksHandler::calcTempVal(uint16_t raw) { return 0.126984 * raw - 67.87
ReturnValue_t SyrlinksHandler::handleAckReply(const uint8_t* packet) {
ReturnValue_t result =
parseReplyStatus(reinterpret_cast<const char*>(packet + syrlinks::MESSAGE_HEADER_SIZE));
if (rememberCommandId == syrlinks::WRITE_LCL_CONFIG and result != returnvalue::OK) {
startupState = StartupState::OFF;
} else if (rememberCommandId == syrlinks::WRITE_LCL_CONFIG and result == returnvalue::OK) {
startupState = StartupState::DONE;
switch (rememberCommandId) {
case (syrlinks::WRITE_LCL_CONFIG): {
if (result != returnvalue::OK) {
internalState = InternalState::OFF;
} else if (result == returnvalue::OK) {
internalState = InternalState::IDLE;
}
break;
}
case (syrlinks::SET_TX_MODE_STANDBY): {
if (result == returnvalue::OK) {
internalState = InternalState::IDLE;
commandExecuted = true;
}
break;
}
case (syrlinks::SET_TX_MODE_MODULATION): {
if (result == returnvalue::OK) {
internalState = InternalState::IDLE;
commandExecuted = true;
}
break;
}
case (syrlinks::SET_TX_MODE_CW): {
if (result == returnvalue::OK) {
internalState = InternalState::IDLE;
commandExecuted = true;
}
break;
}
}
return result;
}
@ -640,3 +682,40 @@ void SyrlinksHandler::prepareCommand(std::string command, DeviceCommandId_t comm
}
void SyrlinksHandler::setDebugMode(bool enable) { this->debugMode = enable; }
void SyrlinksHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
Mode_t tgtMode = getBaseMode(getMode());
if (tgtMode == HasModesIF::MODE_ON or tgtMode == DeviceHandlerIF::MODE_NORMAL) {
switch (getSubmode()) {
case (syrlinks::Submode::TX_MODULATION): {
if (commandExecuted) {
setMode(tgtMode);
return;
}
internalState = InternalState::SET_TX_MODULATION;
break;
}
case (syrlinks::Submode::TX_STANDBY): {
if (commandExecuted) {
setMode(tgtMode);
return;
}
internalState = InternalState::SET_TX_STANDBY;
break;
}
case (syrlinks::Submode::TX_CW): {
if (commandExecuted) {
setMode(tgtMode);
return;
}
internalState = InternalState::SET_TX_CW;
break;
}
default: {
setMode(tgtMode);
}
}
} else {
setMode(tgtMode);
}
}