eive-obsw/mission/devices/PDU1Handler.cpp

184 lines
6.5 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)
2022-08-26 14:28:06 +02:00
: GomspaceDeviceHandler(objectId, comIF, comCookie, cfg, customFdir),
2022-04-07 19:48:09 +02:00
coreHk(this),
2022-08-26 14:28:06 +02:00
auxHk(this) {
initPduConfigTable();
}
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) {
*id = GOMSPACE::REQUEST_HK_TABLE;
return buildCommandFromCommand(*id, NULL, 0);
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);
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-01-26 17:59:31 +01:00
ReturnValue_t PDU1Handler::setParamCallback(SetParamMessageUnpacker &unpacker,
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-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-19 18:51:44 +01:00
}
2022-01-19 17:10:51 +01:00
if (channelSwitchHook != nullptr and unpacker.getParameterSize() == 1) {
switch (unpacker.getAddress()) {
case (CONFIG_ADDRESS_OUT_EN_TCS_BOARD_3V3): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 0, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SYRLINKS): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 1, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_STAR_TRACKER): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 2, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_MGT): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 3, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SUS_NOMINAL): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 4, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SOLAR_CELL_EXP): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 5, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_PLOC): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 6, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_A): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 7, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_CHANNEL8): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 8, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:10:51 +01:00
break;
}
}
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-19 17:10:51 +01:00
}
2022-08-27 01:02:08 +02:00
void PDU1Handler::letChildHandleConfigReply(DeviceCommandId_t id, const uint8_t *packet) {
2022-08-30 23:54:05 +02:00
handleDeviceTm(packet, PDU::CONFIG_TABLE_SIZE, id);
2022-08-27 01:02:08 +02:00
}
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-08-15 11:57:57 +02:00
poolManager.subscribeForDiagPeriodicPacket(
subdp::DiagnosticsHkPeriodicParams(coreHk.getSid(), false, 10.0));
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(auxHk.getSid(), false, 30.0));
2022-08-24 17:27:47 +02:00
return returnvalue::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) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-01-18 11:41:19 +01:00
switch (cmd) {
case (GOMSPACE::PRINT_SWITCH_V_I): {
2022-04-07 19:48:09 +02:00
PoolReadGuard pg(&coreHk);
result = pg.getReadResult();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
break;
}
printHkTableSwitchVI();
break;
}
case (GOMSPACE::PRINT_LATCHUPS): {
2022-04-07 19:48:09 +02:00
PoolReadGuard pg(&auxHk);
result = pg.getReadResult();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::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
}
2022-08-24 17:27:47 +02:00
if (result != returnvalue::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);
}