eive-obsw/mission/devices/PDU2Handler.cpp

179 lines
6.6 KiB
C++
Raw Normal View History

2021-01-23 17:22:40 +01:00
#include "PDU2Handler.h"
2021-09-08 13:41:27 +02:00
#include <fsfw/datapool/PoolReadGuard.h>
2022-01-18 11:41:19 +01:00
#include <mission/devices/devicedefinitions/GomSpacePackets.h>
2021-01-23 17:22:40 +01:00
2022-04-07 19:48:09 +02:00
#include "devices/powerSwitcherList.h"
2021-01-23 17:22:40 +01:00
2022-04-28 15:58:31 +02:00
PDU2Handler::PDU2Handler(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) {}
2021-01-23 17:22:40 +01:00
2022-01-18 11:41:19 +01:00
PDU2Handler::~PDU2Handler() {}
ReturnValue_t PDU2Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
2022-08-23 23:34:20 +02:00
*id = GomspaceCommands::REQUEST_HK_TABLE;
2022-01-18 11:41:19 +01:00
return buildCommandFromCommand(*id, NULL, 0);
2021-01-28 14:55:21 +01:00
}
void PDU2Handler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *packet) {
2022-01-18 11:41:19 +01:00
parseHkTableReply(packet);
/**
* Hk table will be sent to the commander if hk table request was not triggered by the
* PDU2Handler itself.
*/
2022-04-07 19:48:09 +02:00
handleDeviceTM(&coreHk, id, true);
2021-01-28 14:55:21 +01:00
}
2022-01-19 18:05:17 +01:00
void PDU2Handler::assignChannelHookFunction(GOMSPACE::ChannelSwitchHook hook, void *args) {
this->channelSwitchHook = hook;
this->hookArgs = args;
2022-01-19 17:17:06 +01:00
}
2022-04-07 12:22:08 +02:00
LocalPoolDataSetBase *PDU2Handler::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-02-06 11:57:45 +01:00
void PDU2Handler::parseHkTableReply(const uint8_t *packet) {
2022-04-07 19:48:09 +02:00
GomspaceDeviceHandler::parsePduHkTable(coreHk, auxHk, packet);
2021-02-06 11:57:45 +01:00
}
2022-01-18 11:41:19 +01:00
ReturnValue_t PDU2Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
initializePduPool(localDataPoolMap, poolManager, pcdu::INIT_SWITCHES_PDU2);
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
}
2021-09-08 13:41:27 +02:00
ReturnValue_t PDU2Handler::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-08 13:41:27 +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-08 13:41:27 +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-08 13:41:27 +02:00
}
void PDU2Handler::printHkTableSwitchVI() {
2022-04-07 19:48:09 +02:00
using namespace PDU2;
sif::info << "PDU2 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("Q7S", Channels::Q7S);
printerHelper("PL PCDU CH1", Channels::PAYLOAD_PCDU_CH1);
printerHelper("Reaction Wheels", Channels::RW);
printerHelper("TCS Board Heater Input", Channels::TCS_HEATER_IN);
printerHelper("SUS Redundant", Channels::SUS_REDUNDANT);
printerHelper("Deployment Mechanism", Channels::DEPY_MECHANISM);
printerHelper("PL PCDU CH6", Channels::PAYLOAD_PCDU_CH6);
printerHelper("ACS Board B Side", Channels::ACS_B_SIDE);
printerHelper("Payload Camera", Channels::PAYLOAD_CAMERA);
2021-09-16 14:51:14 +02:00
}
2022-01-19 17:17:06 +01:00
void PDU2Handler::printHkTableLatchups() {
2022-04-07 19:48:09 +02:00
using namespace PDU2;
sif::info << "PDU2 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("Q7S", Channels::Q7S);
printerHelper("PL PCDU CH1", Channels::PAYLOAD_PCDU_CH1);
printerHelper("Reaction Wheels", Channels::RW);
printerHelper("TCS Board Heater Input", Channels::TCS_HEATER_IN);
printerHelper("SUS Redundant", Channels::SUS_REDUNDANT);
printerHelper("Deployment Mechanism", Channels::DEPY_MECHANISM);
printerHelper("PL PCDU CH6", Channels::PAYLOAD_PCDU_CH6);
printerHelper("ACS Board B Side", Channels::ACS_B_SIDE);
printerHelper("Payload Camera", Channels::PAYLOAD_CAMERA);
}
2022-01-26 17:59:31 +01:00
ReturnValue_t PDU2Handler::setParamCallback(SetParamMessageUnpacker &unpacker,
bool afterExecution) {
2022-01-19 17:17:06 +01:00
using namespace PDU2;
2022-01-19 18:05:17 +01:00
GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU2;
2022-01-26 17:59:31 +01:00
if (not afterExecution) {
2022-01-19 18:51:44 +01:00
return HasReturnvaluesIF::RETURN_OK;
}
2022-01-19 17:17:06 +01:00
if (channelSwitchHook != nullptr and unpacker.getParameterSize() == 1) {
switch (unpacker.getAddress()) {
case (CONFIG_ADDRESS_OUT_EN_Q7S): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 0, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH1): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 1, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_RW): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 2, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_TCS_BOARD_HEATER_IN): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 3, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_SUS_REDUNDANT): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 4, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_DEPLOYMENT_MECHANISM): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 5, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH6): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 6, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_B): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 7, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
case (CONFIG_ADDRESS_OUT_EN_PAYLOAD_CAMERA): {
2022-01-19 18:05:17 +01:00
channelSwitchHook(pdu, 8, unpacker.getParameter()[0], hookArgs);
2022-01-19 17:17:06 +01:00
break;
}
}
}
return HasReturnvaluesIF::RETURN_OK;
}