2021-09-08 13:41:27 +02:00
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
2023-03-14 13:32:13 +01:00
|
|
|
#include <mission/devices/Pdu2Handler.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
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
Pdu2Handler::Pdu2Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie,
|
2022-04-28 15:58:31 +02:00
|
|
|
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();
|
|
|
|
}
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
Pdu2Handler::~Pdu2Handler() {}
|
2022-01-18 11:41:19 +01:00
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
ReturnValue_t Pdu2Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
2022-01-18 11:41:19 +01:00
|
|
|
*id = GOMSPACE::REQUEST_HK_TABLE;
|
|
|
|
return buildCommandFromCommand(*id, NULL, 0);
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
void Pdu2Handler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *packet) {
|
2022-01-18 11:41:19 +01:00
|
|
|
parseHkTableReply(packet);
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
void Pdu2Handler::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
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
void Pdu2Handler::assignChannelHookFunction(GOMSPACE::ChannelSwitchHook hook, void *args) {
|
2022-01-19 18:05:17 +01:00
|
|
|
this->channelSwitchHook = hook;
|
|
|
|
this->hookArgs = args;
|
2022-01-19 17:17:06 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01: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;
|
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +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
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
ReturnValue_t Pdu2Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
2022-01-18 11:41:19 +01:00
|
|
|
LocalDataPoolManager &poolManager) {
|
2022-04-07 19:53:29 +02:00
|
|
|
initializePduPool(localDataPoolMap, poolManager, pcdu::INIT_SWITCHES_PDU2);
|
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
|
|
|
}
|
2021-09-08 13:41:27 +02:00
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
ReturnValue_t Pdu2Handler::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);
|
2022-03-16 20:13:21 +01:00
|
|
|
result = pg.getReadResult();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
printHkTableSwitchVI();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (GOMSPACE::PRINT_LATCHUPS): {
|
2022-04-07 19:48:09 +02:00
|
|
|
PoolReadGuard pg(&auxHk);
|
2022-03-16 20:13:21 +01:00
|
|
|
result = pg.getReadResult();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
2022-01-18 11:41:19 +01:00
|
|
|
}
|
2022-03-16 20:13:21 +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
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-16 20:13:21 +01:00
|
|
|
sif::warning << "Reading PDU1 HK table failed!" << std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
2021-09-08 13:41:27 +02:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
void Pdu2Handler::printHkTableSwitchVI() {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace PDU2;
|
2022-03-16 20:13:21 +01:00
|
|
|
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;
|
2022-03-16 20:13:21 +01:00
|
|
|
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
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
void Pdu2Handler::printHkTableLatchups() {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace PDU2;
|
2022-03-16 20:13:21 +01:00
|
|
|
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-03-16 20:13:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:32:13 +01:00
|
|
|
ReturnValue_t Pdu2Handler::setParamCallback(SetParamMessageUnpacker &unpacker,
|
2022-01-26 17:59:31 +01:00
|
|
|
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-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-19 18:51:44 +01:00
|
|
|
}
|
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;
|
|
|
|
}
|
2022-03-16 20:13:21 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-19 17:17:06 +01:00
|
|
|
}
|