eive-obsw/linux/payload/FreshSupvHandler.cpp
Robin Mueller 42cc9c0fa8
All checks were successful
EIVE/eive-obsw/pipeline/pr-main This commit looks good
add required fields
2023-11-09 11:57:49 +01:00

150 lines
7.6 KiB
C++

#include "FreshSupvHandler.h"
#include <atomic>
using namespace supv;
using namespace returnvalue;
std::atomic_bool supv::SUPV_ON = false;
FreshSupvHandler::FreshSupvHandler(DhbConfig cfg, CookieIF *comCookie, Gpio uartIsolatorSwitch,
PowerSwitchIF &switchIF, power::Switch_t powerSwitch,
PlocSupvUartManager &supvHelper)
: FreshDeviceHandlerBase(cfg),
hkSet(this),
bootStatusReport(this),
latchupStatusReport(this),
countersReport(this),
adcReport(this),
uartManager(supvHelper) {}
void FreshSupvHandler::performDeviceOperation(uint8_t opCode) {
if (!transitionActive and mode == MODE_OFF) {
// Nothing to do for now.
return;
}
if (opCode == OpCode::DEFAULT_OPERATION) {
if (transitionActive) {
// TODO: Perform transition handling: OFF to ON and ON to OFF.
// For OFF to ON, command power switch first, then to isolato switch handling, and lastly
// ensure succesfull communication
// For ON to OFF ????
} else {
if (mode == MODE_NORMAL) {
// Normal mode handling. Request normal datasets and add them to command map.
}
}
// TODO: Check whether any active commands have timeouted.
} else if (opCode == OpCode::HANDLE_ACTIVE_CMDS) {
// TODO: Parse TM from ring buffer and check whether they complete any active commands.
// If they do, check whether anyone needs to be informed.
}
}
ReturnValue_t FreshSupvHandler::handleCommandMessage(CommandMessage *message) {
// No custom messages.
return returnvalue::FAILED;
}
LocalPoolDataSetBase *FreshSupvHandler::getDataSetHandle(sid_t sid) {
// TODO: return all relevant datasets.
return nullptr;
}
ReturnValue_t FreshSupvHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
// TODO: Copy code from god handler here.
localDataPoolMap.emplace(supv::NUM_TMS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TEMP_PS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TEMP_PL, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::HK_SOC_STATE, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::NVM0_1_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::NVM3_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::MISSION_IO_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::FMC_STATE, &fmcStateEntry);
localDataPoolMap.emplace(supv::NUM_TCS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TEMP_SUP, &tempSupEntry);
localDataPoolMap.emplace(supv::UPTIME, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(supv::CPULOAD, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::AVAILABLEHEAP, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::BR_SOC_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::POWER_CYCLES, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BOOT_AFTER_MS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::BOOT_TIMEOUT_MS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::ACTIVE_NVM, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BP0_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BP1_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BP2_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BOOT_STATE, &bootStateEntry);
localDataPoolMap.emplace(supv::BOOT_CYCLES, &bootCyclesEntry);
localDataPoolMap.emplace(supv::LATCHUP_ID, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::CNT0, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT1, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT2, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT3, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT4, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT5, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT6, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_MSEC, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_SEC, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_MIN, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_HOUR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_DAY, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_MON, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_YEAR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_IS_SET, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::SIGNATURE, new PoolEntry<uint32_t>());
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNTS, &latchupCounters);
localDataPoolMap.emplace(supv::ADC_DEVIATION_TRIGGERS_CNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TC_RECEIVED_CNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TM_AVAILABLE_CNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::SUPERVISOR_BOOTS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_BOOTS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_BOOT_FAILED_ATTEMPTS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_POWER_UP, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_UPDATES, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_HEARTBEAT_RESETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::CPU_WDT_RESETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::PS_HEARTBEATS_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::PL_HEARTBEATS_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::EB_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::BM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::LM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::AM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TCTMM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::HK_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::DL_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::RWS_TASKS_LOST, new PoolEntry<uint32_t>(3));
localDataPoolMap.emplace(supv::ADC_RAW, &adcRawEntry);
localDataPoolMap.emplace(supv::ADC_ENG, &adcEngEntry);
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(hkSet.getSid(), false, 10.0));
return returnvalue::OK;
}
ReturnValue_t FreshSupvHandler::setHealth(HealthState health) {
// TODO: Go to off is the device is commanded faulty.
return returnvalue::OK;
}
ReturnValue_t FreshSupvHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t *data, size_t size) {
// TODO: Handle all commands here. Need to add them to some command map. Send command immediately
// then.
return returnvalue::OK;
}
ReturnValue_t FreshSupvHandler::checkModeCommand(Mode_t mode_, Submode_t submode_,
uint32_t *msToReachTheMode) {
if (mode_ != HasModesIF::MODE_OFF and mode_ != HasModesIF::MODE_ON and mode_ != MODE_NORMAL) {
return returnvalue::FAILED;
}
return returnvalue::OK;
}