eive-obsw/mission/devices/PDU1Handler.cpp

177 lines
6.2 KiB
C++
Raw Normal View History

2021-01-28 14:55:21 +01:00
#include "PDU1Handler.h"
2021-09-20 11:22:11 +02:00
#include <fsfw/datapool/PoolReadGuard.h>
2022-01-19 17:10:51 +01:00
#include <mission/devices/devicedefinitions/GomSpacePackets.h>
2021-01-28 14:55:21 +01:00
2022-04-07 19:48:09 +02:00
#include "devices/powerSwitcherList.h"
2021-01-28 14:55:21 +01:00
2022-04-28 15:58:31 +02:00
PDU1Handler::PDU1Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie,
FailureIsolationBase *customFdir)
: GomspaceDeviceHandler(objectId, comIF, comCookie, customFdir, PDU::MAX_CONFIGTABLE_ADDRESS,
2022-04-07 12:22:08 +02:00
PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE),
2022-04-07 19:48:09 +02:00
coreHk(this),
auxHk(this) {}
2022-01-18 11:41:19 +01:00
PDU1Handler::~PDU1Handler() {}
2021-01-28 14:55:21 +01:00
2022-01-18 11:41:19 +01:00
ReturnValue_t PDU1Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
2022-08-23 23:34:20 +02:00
*id = GomspaceCommands::REQUEST_HK_TABLE;
return requestHkTableAction.handle();
2021-01-28 14:55:21 +01:00
}
void PDU1Handler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *packet) {
2022-01-18 11:41:19 +01:00
parseHkTableReply(packet);
2022-04-07 19:48:09 +02:00
handleDeviceTM(&coreHk, id, true);
2021-02-06 16:13:31 +01:00
}
2022-01-19 18:05:17 +01:00
void PDU1Handler::assignChannelHookFunction(GOMSPACE::ChannelSwitchHook hook, void *args) {
2022-01-19 17:10:51 +01:00
this->channelSwitchHook = hook;
2022-01-19 18:05:17 +01:00
this->hookArgs = args;
2022-01-19 17:10:51 +01:00
}
2022-08-24 17:19:14 +02:00
ReturnValue_t PDU1Handler::setParamCallback(uint16_t address, uint32_t value, uint8_t valueBytes, bool afterExecution) {
2022-01-19 17:10:51 +01:00
using namespace PDU1;
2022-01-19 18:05:17 +01:00
GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU1;
2022-01-26 17:59:31 +01:00
if (not afterExecution) {
2022-01-19 18:51:44 +01:00
return HasReturnvaluesIF::RETURN_OK;
}
2022-08-24 17:19:14 +02:00
if (channelSwitchHook != nullptr and valueBytes == 1) {
switch (address) {
2022-01-19 17:10:51 +01:00
case (CONFIG_ADDRESS_OUT_EN_TCS_BOARD_3V3): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 0, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SYRLINKS): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 1, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_STAR_TRACKER): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 2, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_MGT): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 3, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SUS_NOMINAL): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 4, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SOLAR_CELL_EXP): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 5, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_PLOC): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 6, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_A): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 7, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_CHANNEL8): {
2022-08-24 17:19:14 +02:00
channelSwitchHook(pdu, 8, value, hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
}
}
return HasReturnvaluesIF::RETURN_OK;
}
2021-02-06 16:13:31 +01:00
void PDU1Handler::parseHkTableReply(const uint8_t *packet) {
2022-04-07 19:48:09 +02:00
GomspaceDeviceHandler::parsePduHkTable(coreHk, auxHk, packet);
2021-02-06 16:13:31 +01:00
}
2022-01-18 11:41:19 +01:00
ReturnValue_t PDU1Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
2022-04-07 19:48:09 +02:00
initializePduPool(localDataPoolMap, poolManager, pcdu::INIT_SWITCHES_PDU1);
2022-04-12 16:36:04 +02:00
poolManager.subscribeForPeriodicPacket(coreHk.getSid(), false, 10.0, true);
2022-04-07 19:48:09 +02:00
poolManager.subscribeForPeriodicPacket(auxHk.getSid(), false, 30.0, false);
2022-01-18 11:41:19 +01:00
return HasReturnvaluesIF::RETURN_OK;
2021-01-28 14:55:21 +01:00
}
2022-04-07 12:22:08 +02:00
LocalPoolDataSetBase *PDU1Handler::getDataSetHandle(sid_t sid) {
2022-04-07 19:48:09 +02:00
if (sid == coreHk.getSid()) {
return &coreHk;
} else if (sid == auxHk.getSid()) {
return &auxHk;
2022-04-07 12:22:08 +02:00
}
return nullptr;
}
2021-09-07 16:11:02 +02:00
ReturnValue_t PDU1Handler::printStatus(DeviceCommandId_t cmd) {
ReturnValue_t result = RETURN_OK;
2022-01-18 11:41:19 +01:00
switch (cmd) {
2022-08-23 23:34:20 +02:00
case (GomspaceCommands::PRINT_SWITCH_V_I): {
2022-04-07 19:48:09 +02:00
PoolReadGuard pg(&coreHk);
result = pg.getReadResult();
if (result != HasReturnvaluesIF::RETURN_OK) {
break;
}
printHkTableSwitchVI();
break;
}
2022-08-23 23:34:20 +02:00
case (GomspaceCommands::PRINT_LATCHUPS): {
2022-04-07 19:48:09 +02:00
PoolReadGuard pg(&auxHk);
result = pg.getReadResult();
if (result != HasReturnvaluesIF::RETURN_OK) {
break;
2022-01-18 11:41:19 +01:00
}
printHkTableLatchups();
break;
2021-09-07 16:11:02 +02:00
}
2022-01-18 11:41:19 +01:00
default: {
2022-05-23 11:25:58 +02:00
return DeviceHandlerIF::COMMAND_NOT_SUPPORTED;
2021-09-07 16:11:02 +02:00
}
2022-01-18 11:41:19 +01:00
}
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Reading PDU1 HK table failed!" << std::endl;
}
return result;
2021-09-07 16:11:02 +02:00
}
2021-09-20 11:22:11 +02:00
void PDU1Handler::printHkTableSwitchVI() {
2022-04-07 19:48:09 +02:00
using namespace PDU1;
sif::info << "PDU1 Info: " << std::endl;
2022-04-07 19:48:09 +02:00
sif::info << "Boot Cause: " << auxHk.bootcause << " | Boot Count: " << std::setw(4) << std::right
<< coreHk.bootcount << std::endl;
sif::info << "Reset Cause: " << auxHk.resetcause
<< " | Battery Mode: " << static_cast<int>(coreHk.battMode.value) << std::endl;
sif::info << "SwitchState, Currents [mA], Voltages [mV]:" << std::endl;
2022-04-07 19:48:09 +02:00
auto printerHelper = [&](std::string channelStr, Channels idx) {
sif::info << std::setw(30) << std::left << channelStr << std::dec << "| "
<< unsigned(coreHk.outputEnables[idx]) << ", " << std::setw(4) << std::right
<< coreHk.currents[idx] << ", " << std::setw(4) << coreHk.voltages[idx] << std::endl;
};
printerHelper("TCS Board", Channels::TCS_BOARD_3V3);
printerHelper("Syrlinks", Channels::SYRLINKS);
printerHelper("Star Tracker", Channels::STR);
printerHelper("MGT", Channels::MGT);
printerHelper("SUS Nominal", Channels::SUS_NOMINAL);
printerHelper("SCEX", Channels::SOL_CELL_EXPERIMENT);
printerHelper("PLOC", Channels::PLOC);
printerHelper("ACS Board A Side", Channels::ACS_A_SIDE);
printerHelper("Channel 8", Channels::UNUSED);
printerHelper("Syrlinks", Channels::SYRLINKS);
2021-09-20 11:22:11 +02:00
}
void PDU1Handler::printHkTableLatchups() {
2022-04-07 19:48:09 +02:00
using namespace PDU1;
sif::info << "PDU1 Latchup Information" << std::endl;
2022-04-07 19:48:09 +02:00
auto printerHelper = [&](std::string channelStr, Channels idx) {
sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << "TCS Board" << std::dec << "| "
<< std::setw(4) << std::right << auxHk.latchups[idx] << std::endl;
};
printerHelper("TCS Board", Channels::TCS_BOARD_3V3);
printerHelper("Syrlinks", Channels::SYRLINKS);
printerHelper("Star Tracker", Channels::STR);
printerHelper("MGT", Channels::MGT);
printerHelper("SUS Nominal", Channels::SUS_NOMINAL);
printerHelper("SCEX", Channels::SOL_CELL_EXPERIMENT);
printerHelper("PLOC", Channels::PLOC);
printerHelper("ACS Board A Side", Channels::ACS_A_SIDE);
printerHelper("Channel 8", Channels::UNUSED);
printerHelper("Syrlinks", Channels::SYRLINKS);
}