2022-01-17 15:58:27 +01:00
|
|
|
#include <OBSWConfig.h>
|
2022-03-16 20:13:21 +01:00
|
|
|
#include <devices/powerSwitcherList.h>
|
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
2021-02-05 07:37:21 +01:00
|
|
|
#include <fsfw/housekeeping/HousekeepingSnapshot.h>
|
2022-03-16 20:13:21 +01:00
|
|
|
#include <fsfw/ipc/MutexFactory.h>
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <fsfw/ipc/QueueFactory.h>
|
2023-03-26 16:13:54 +02:00
|
|
|
#include <mission/power/GomSpacePackets.h>
|
|
|
|
#include <mission/power/PcduHandler.h>
|
2021-02-27 19:46:13 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
PcduHandler::PcduHandler(object_id_t setObjectId, size_t cmdQueueSize)
|
2022-01-17 15:58:27 +01:00
|
|
|
: SystemObject(setObjectId),
|
|
|
|
poolManager(this, nullptr),
|
2022-12-21 17:30:21 +01:00
|
|
|
p60CoreHk(objects::P60DOCK_HANDLER),
|
2022-04-07 19:48:09 +02:00
|
|
|
pdu1CoreHk(this),
|
|
|
|
pdu2CoreHk(this),
|
|
|
|
switcherSet(this),
|
2022-01-17 15:58:27 +01:00
|
|
|
cmdQueueSize(cmdQueueSize) {
|
2022-03-16 20:13:21 +01:00
|
|
|
auto mqArgs = MqArgs(setObjectId, static_cast<void*>(this));
|
2022-01-17 15:58:27 +01:00
|
|
|
commandQueue = QueueFactory::instance()->createMessageQueue(
|
2022-03-16 20:13:21 +01:00
|
|
|
cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
2023-03-02 15:21:45 +01:00
|
|
|
pwrLock = MutexFactory::instance()->createMutex();
|
2023-03-14 13:32:13 +01:00
|
|
|
std::memset(switchStates, SWITCH_STATE_UNKNOWN, sizeof(switchStates));
|
2021-01-23 17:22:40 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
PcduHandler::~PcduHandler() {}
|
2021-01-23 17:22:40 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::performOperation(uint8_t counter) {
|
2022-01-17 15:58:27 +01:00
|
|
|
if (counter == DeviceHandlerIF::PERFORM_OPERATION) {
|
|
|
|
readCommandQueue();
|
|
|
|
}
|
2023-04-03 16:25:32 +02:00
|
|
|
uint8_t switchState5V = 0;
|
|
|
|
uint8_t switchState3V3 = 0;
|
2022-12-21 17:30:21 +01:00
|
|
|
{
|
|
|
|
PoolReadGuard pg(&p60CoreHk.outputEnables);
|
|
|
|
if (pg.getReadResult() == returnvalue::OK) {
|
2023-04-03 16:25:32 +02:00
|
|
|
switchState5V = p60CoreHk.outputEnables.value[P60Dock::hk::STACK_5V];
|
|
|
|
switchState3V3 = p60CoreHk.outputEnables.value[P60Dock::hk::STACK_3V3];
|
2022-12-22 16:18:30 +01:00
|
|
|
} else {
|
|
|
|
return returnvalue::OK;
|
2022-12-21 17:30:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2023-04-03 16:25:32 +02:00
|
|
|
PoolReadGuard pg(&switcherSet);
|
2022-12-21 17:30:21 +01:00
|
|
|
if (pg.getReadResult() == returnvalue::OK) {
|
2023-04-03 16:25:32 +02:00
|
|
|
if (switcherSet.p60Dock5VStack.value != switchState5V) {
|
|
|
|
triggerEvent(power::SWITCH_HAS_CHANGED, switchState5V, power::Switches::P60_DOCK_5V_STACK);
|
2023-03-02 15:22:21 +01:00
|
|
|
MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
|
2023-04-03 16:25:32 +02:00
|
|
|
switchStates[power::P60_DOCK_5V_STACK] = switchState5V;
|
|
|
|
}
|
|
|
|
if (switcherSet.p60Dock3V3Stack.value != switchState3V3) {
|
|
|
|
triggerEvent(power::SWITCH_HAS_CHANGED, switchState3V3,
|
|
|
|
power::Switches::P60_DOCK_3V3_STACK);
|
|
|
|
MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
|
|
|
|
switchStates[power::P60_DOCK_3V3_STACK] = switchState3V3;
|
2022-12-21 17:30:21 +01:00
|
|
|
}
|
2022-12-22 16:18:30 +01:00
|
|
|
switcherSet.p60Dock5VStack.setValid(true);
|
2023-04-03 16:25:32 +02:00
|
|
|
switcherSet.p60Dock5VStack.value = switchState5V;
|
|
|
|
switcherSet.p60Dock3V3Stack.setValid(true);
|
|
|
|
switcherSet.p60Dock3V3Stack.value = switchState3V3;
|
2022-12-21 17:30:21 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::initialize() {
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t result;
|
|
|
|
|
2024-01-01 17:19:07 +01:00
|
|
|
ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
|
|
|
if (ipcStore == nullptr) {
|
2022-01-17 15:58:27 +01:00
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = poolManager.initialize(commandQueue);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subscribing for housekeeping table update messages of the PDU2 */
|
|
|
|
HasLocalDataPoolIF* pdu2Handler =
|
|
|
|
ObjectManager::instance()->get<HasLocalDataPoolIF>(objects::PDU2_HANDLER);
|
|
|
|
if (pdu2Handler == nullptr) {
|
|
|
|
sif::error << "PCDUHandler::initialize: Invalid pdu2Handler" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
result = pdu2Handler->getSubscriptionInterface()->subscribeForSetUpdateMessage(
|
2022-10-19 10:46:57 +02:00
|
|
|
static_cast<uint32_t>(P60System::SetIds::CORE), this->getObjectId(), commandQueue->getId(),
|
|
|
|
true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::error << "PCDUHandler::initialize: Failed to subscribe for set update messages from "
|
|
|
|
<< "PDU2Handler" << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subscribing for housekeeping table update messages of the PDU1 */
|
|
|
|
HasLocalDataPoolIF* pdu1Handler =
|
|
|
|
ObjectManager::instance()->get<HasLocalDataPoolIF>(objects::PDU1_HANDLER);
|
|
|
|
if (pdu1Handler == nullptr) {
|
|
|
|
sif::error << "PCDUHandler::initialize: Invalid pdu1Handler" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
result = pdu1Handler->getSubscriptionInterface()->subscribeForSetUpdateMessage(
|
2022-10-19 10:46:57 +02:00
|
|
|
static_cast<uint32_t>(P60System::SetIds::CORE), this->getObjectId(), commandQueue->getId(),
|
|
|
|
true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::error << "PCDUHandler::initialize: Failed to subscribe for set update messages from "
|
|
|
|
<< "PDU1Handler" << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::initializeSwitchStates() {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace pcdu;
|
2022-04-21 09:35:02 +02:00
|
|
|
try {
|
2023-03-16 18:47:51 +01:00
|
|
|
for (uint8_t idx = 0; idx < power::NUMBER_OF_SWITCHES; idx++) {
|
2022-04-21 09:35:02 +02:00
|
|
|
if (idx < PDU::CHANNELS_LEN) {
|
|
|
|
switchStates[idx] = INIT_SWITCHES_PDU1.at(idx);
|
2023-01-10 14:17:55 +01:00
|
|
|
} else if (idx < PDU::CHANNELS_LEN * 2) {
|
2022-04-21 09:35:02 +02:00
|
|
|
switchStates[idx] = INIT_SWITCHES_PDU2.at(idx - PDU::CHANNELS_LEN);
|
2023-01-10 14:17:55 +01:00
|
|
|
} else {
|
|
|
|
switchStates[idx] = OFF;
|
2022-04-21 09:35:02 +02:00
|
|
|
}
|
2022-04-07 19:48:09 +02:00
|
|
|
}
|
2022-04-21 09:35:02 +02:00
|
|
|
} catch (const std::out_of_range& err) {
|
|
|
|
sif::error << "PCDUHandler::initializeSwitchStates: " << err.what() << std::endl;
|
2022-03-16 20:13:21 +01:00
|
|
|
}
|
2021-02-01 11:17:20 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::readCommandQueue() {
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
CommandMessage command;
|
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
for (result = commandQueue->receiveMessage(&command); result == returnvalue::OK;
|
2022-04-21 09:35:02 +02:00
|
|
|
result = commandQueue->receiveMessage(&command)) {
|
|
|
|
result = poolManager.handleHousekeepingMessage(&command);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-05-02 13:50:44 +02:00
|
|
|
continue;
|
2022-04-21 09:35:02 +02:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
MessageQueueId_t PcduHandler::getCommandQueue() const { return commandQueue->getId(); }
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) {
|
2022-10-18 11:01:33 +02:00
|
|
|
if (sid == sid_t(objects::PDU2_HANDLER, static_cast<uint32_t>(P60System::SetIds::CORE))) {
|
2022-04-07 19:48:09 +02:00
|
|
|
updateHkTableDataset(storeId, &pdu2CoreHk, &timeStampPdu2HkDataset);
|
2022-01-17 15:58:27 +01:00
|
|
|
updatePdu2SwitchStates();
|
2022-10-19 10:46:57 +02:00
|
|
|
} else if (sid == sid_t(objects::PDU1_HANDLER, static_cast<uint32_t>(P60System::SetIds::CORE))) {
|
2022-04-07 19:48:09 +02:00
|
|
|
updateHkTableDataset(storeId, &pdu1CoreHk, &timeStampPdu1HkDataset);
|
2022-01-17 15:58:27 +01:00
|
|
|
updatePdu1SwitchStates();
|
|
|
|
} else {
|
|
|
|
sif::error << "PCDUHandler::handleChangedDataset: Invalid sid" << std::endl;
|
|
|
|
}
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::updateHkTableDataset(store_address_t storeId, LocalPoolDataSetBase* dataset,
|
2022-01-17 15:58:27 +01:00
|
|
|
CCSDSTime::CDS_short* datasetTimeStamp) {
|
|
|
|
ReturnValue_t result;
|
|
|
|
|
|
|
|
HousekeepingSnapshot packetUpdate(reinterpret_cast<uint8_t*>(datasetTimeStamp),
|
|
|
|
sizeof(CCSDSTime::CDS_short), dataset);
|
2022-04-12 16:11:04 +02:00
|
|
|
const uint8_t* packet_ptr = nullptr;
|
|
|
|
size_t size = 0;
|
2024-01-01 17:19:07 +01:00
|
|
|
result = ipcStore->getData(storeId, &packet_ptr, &size);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2024-01-01 17:19:07 +01:00
|
|
|
sif::error << "PCDUHandler::updateHkTableDataset: Failed to get data from IPC store, result 0x"
|
|
|
|
<< std::hex << std::setw(4) << std::setfill('0') << result << std::dec
|
|
|
|
<< std::setfill(' ') << std::endl;
|
|
|
|
result = ipcStore->deleteData(storeId);
|
|
|
|
return;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
result = packetUpdate.deSerialize(&packet_ptr, &size, SerializeIF::Endianness::MACHINE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::error << "PCDUHandler::updateHkTableDataset: Failed to deserialize received packet "
|
|
|
|
"in hk table dataset"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2024-01-01 17:19:07 +01:00
|
|
|
result = ipcStore->deleteData(storeId);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::error << "PCDUHandler::updateHkTableDataset: Failed to delete data in IPCStore"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2021-02-06 11:57:45 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::updatePdu2SwitchStates() {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace pcdu;
|
|
|
|
using namespace PDU2;
|
2022-03-16 20:13:21 +01:00
|
|
|
GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU2;
|
2022-04-07 19:48:09 +02:00
|
|
|
PoolReadGuard rg0(&switcherSet);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (rg0.getReadResult() == returnvalue::OK) {
|
2022-04-07 19:48:09 +02:00
|
|
|
for (uint8_t idx = 0; idx < PDU::CHANNELS_LEN; idx++) {
|
|
|
|
switcherSet.pdu2Switches[idx] = pdu2CoreHk.outputEnables[idx];
|
|
|
|
}
|
2022-12-22 16:20:32 +01:00
|
|
|
switcherSet.pdu2Switches.setValid(true);
|
2023-03-02 15:21:45 +01:00
|
|
|
MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::PDU2_CH0_Q7S, pdu2CoreHk.outputEnables[Channels::Q7S]);
|
2023-01-10 15:04:49 +01:00
|
|
|
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::PAYLOAD_PCDU_CH1]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH2_RW_5V,
|
|
|
|
pdu2CoreHk.outputEnables[Channels::RW]);
|
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::TCS_HEATER_IN]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH4_SUS_REDUNDANT_3V3,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::SUS_REDUNDANT]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH5_DEPLOYMENT_MECHANISM_8V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::DEPY_MECHANISM]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH6_PL_PCDU_BATT_1_14V8,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::PAYLOAD_PCDU_CH6]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH7_ACS_BOARD_SIDE_B_3V3,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::ACS_B_SIDE]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU2_CH8_PAYLOAD_CAMERA,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu2CoreHk.outputEnables[Channels::PAYLOAD_CAMERA]);
|
2022-03-16 20:13:21 +01:00
|
|
|
if (firstSwitchInfoPdu2) {
|
|
|
|
firstSwitchInfoPdu2 = false;
|
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
} else {
|
|
|
|
sif::debug << "PCDUHandler::updatePdu2SwitchStates: Failed to read PDU2 Hk Dataset"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2021-02-01 11:17:20 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::updatePdu1SwitchStates() {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace pcdu;
|
|
|
|
using namespace PDU1;
|
|
|
|
PoolReadGuard rg0(&switcherSet);
|
2022-03-16 20:13:21 +01:00
|
|
|
GOMSPACE::Pdu pdu = GOMSPACE::Pdu::PDU1;
|
2022-08-24 17:27:47 +02:00
|
|
|
if (rg0.getReadResult() == returnvalue::OK) {
|
2022-04-07 19:48:09 +02:00
|
|
|
for (uint8_t idx = 0; idx < PDU::CHANNELS_LEN; idx++) {
|
|
|
|
switcherSet.pdu1Switches[idx] = pdu1CoreHk.outputEnables[idx];
|
|
|
|
}
|
2022-12-22 16:20:32 +01:00
|
|
|
switcherSet.pdu1Switches.setValid(true);
|
2023-03-02 15:21:45 +01:00
|
|
|
MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH0_TCS_BOARD_3V3,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::TCS_BOARD_3V3]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH1_SYRLINKS_12V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::SYRLINKS]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH2_STAR_TRACKER_5V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::STR]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH3_MGT_5V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::MGT]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH4_SUS_NOMINAL_3V3,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::SUS_NOMINAL]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH5_SOLAR_CELL_EXP_5V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::SOL_CELL_EXPERIMENT]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH6_PLOC_12V,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::PLOC]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH7_ACS_A_SIDE_3V3,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::ACS_A_SIDE]);
|
2023-03-16 18:47:51 +01:00
|
|
|
checkAndUpdatePduSwitch(pdu, power::Switches::PDU1_CH8_UNOCCUPIED,
|
2023-01-10 15:04:49 +01:00
|
|
|
pdu1CoreHk.outputEnables[Channels::UNUSED]);
|
2022-03-16 20:13:21 +01:00
|
|
|
if (firstSwitchInfoPdu1) {
|
|
|
|
firstSwitchInfoPdu1 = false;
|
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
} else {
|
|
|
|
sif::debug << "PCDUHandler::updatePdu1SwitchStates: Failed to read dataset" << std::endl;
|
|
|
|
}
|
2021-02-01 11:17:20 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
LocalDataPoolManager* PcduHandler::getHkManagerHandle() { return &poolManager; }
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace pcdu;
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t result;
|
2022-03-16 20:13:21 +01:00
|
|
|
uint16_t memoryAddress = 0;
|
2022-01-17 15:58:27 +01:00
|
|
|
size_t parameterValueSize = sizeof(uint8_t);
|
2022-03-16 20:13:21 +01:00
|
|
|
uint8_t parameterValue = 0;
|
2023-01-10 15:08:38 +01:00
|
|
|
GomspaceDeviceHandler* module = nullptr;
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (switchNr) {
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH0_TCS_BOARD_3V3: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_TCS_BOARD_3V3;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH1_SYRLINKS_12V: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_SYRLINKS;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH2_STAR_TRACKER_5V: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_STAR_TRACKER;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH3_MGT_5V: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_MGT;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH4_SUS_NOMINAL_3V3: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_SUS_NOMINAL;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH5_SOLAR_CELL_EXP_5V: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_SOLAR_CELL_EXP;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH6_PLOC_12V: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_PLOC;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH7_ACS_A_SIDE_3V3: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_A;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU1_CH8_UNOCCUPIED: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU1::CONFIG_ADDRESS_OUT_EN_CHANNEL8;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU1_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// This is a dangerous command. Reject/Igore it for now
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH0_Q7S: {
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-03-16 20:13:21 +01:00
|
|
|
// memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_Q7S;
|
|
|
|
// pdu = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
|
|
|
// break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH1_PL_PCDU_BATT_0_14V8: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH1;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH2_RW_5V: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_RW;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH3_TCS_BOARD_HEATER_IN_8V: {
|
2022-01-17 15:58:27 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_TCS_BOARD_HEATER_IN;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2022-03-16 20:13:21 +01:00
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH4_SUS_REDUNDANT_3V3: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_SUS_REDUNDANT;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH5_DEPLOYMENT_MECHANISM_8V: {
|
2022-01-17 15:58:27 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_DEPLOYMENT_MECHANISM;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2022-03-16 20:13:21 +01:00
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH6_PL_PCDU_BATT_1_14V8: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_PAYLOAD_PCDU_CH6;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH7_ACS_BOARD_SIDE_B_3V3: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_ACS_BOARD_SIDE_B;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::PDU2_CH8_PAYLOAD_CAMERA: {
|
2022-03-16 20:13:21 +01:00
|
|
|
memoryAddress = PDU2::CONFIG_ADDRESS_OUT_EN_PAYLOAD_CAMERA;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::PDU2_HANDLER);
|
2022-03-16 20:13:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-16 18:47:51 +01:00
|
|
|
case power::P60_DOCK_5V_STACK: {
|
2022-12-21 13:40:31 +01:00
|
|
|
memoryAddress = P60Dock::CONFIG_ADDRESS_OUT_EN_5V_STACK;
|
2023-01-10 15:08:38 +01:00
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::P60DOCK_HANDLER);
|
2022-12-21 13:40:31 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-04-03 16:25:32 +02:00
|
|
|
case power::P60_DOCK_3V3_STACK: {
|
|
|
|
memoryAddress = P60Dock::CONFIG_ADDRESS_OUT_EN_3V3_STACK;
|
|
|
|
module = ObjectManager::instance()->get<GomspaceDeviceHandler>(objects::P60DOCK_HANDLER);
|
|
|
|
break;
|
|
|
|
}
|
2022-03-16 20:13:21 +01:00
|
|
|
|
|
|
|
default: {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::error << "PCDUHandler::sendSwitchCommand: Invalid switch number " << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-03-16 20:13:21 +01:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (onOff) {
|
2021-01-28 14:55:21 +01:00
|
|
|
case PowerSwitchIF::SWITCH_ON:
|
2022-01-17 15:58:27 +01:00
|
|
|
parameterValue = 1;
|
|
|
|
break;
|
2021-01-28 14:55:21 +01:00
|
|
|
case PowerSwitchIF::SWITCH_OFF:
|
2022-01-17 15:58:27 +01:00
|
|
|
parameterValue = 0;
|
|
|
|
break;
|
2021-01-28 14:55:21 +01:00
|
|
|
default:
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::error << "PCDUHandler::sendSwitchCommand: Invalid state commanded" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
GomspaceSetParamMessage setParamMessage(memoryAddress, ¶meterValue, parameterValueSize);
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
size_t serializedLength = 0;
|
|
|
|
uint8_t command[4];
|
|
|
|
uint8_t* commandPtr = command;
|
|
|
|
size_t maxSize = sizeof(command);
|
|
|
|
setParamMessage.serialize(&commandPtr, &serializedLength, maxSize, SerializeIF::Endianness::BIG);
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
store_address_t storeAddress;
|
2024-01-01 17:19:07 +01:00
|
|
|
result = ipcStore->addData(&storeAddress, command, sizeof(command));
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
CommandMessage message;
|
|
|
|
ActionMessage::setCommand(&message, GOMSPACE::PARAM_SET, storeAddress);
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2023-01-10 15:08:38 +01:00
|
|
|
result = commandQueue->sendMessage(module->getCommandQueue(), &message, 0);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "PCDUHandler::sendSwitchCommand: Failed to send message to PDU Handler"
|
|
|
|
<< std::endl;
|
2022-03-16 20:13:21 +01:00
|
|
|
} else {
|
|
|
|
// Can't use trigger event because of const function constraint, but this hack seems to work
|
|
|
|
this->forwardEvent(power::SWITCH_CMD_SENT, parameterValue, switchNr);
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-30 12:22:49 +02:00
|
|
|
return result;
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::sendFuseOnCommand(uint8_t fuseNr) { return returnvalue::OK; }
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::getSwitchState(uint8_t switchNr) const {
|
2023-03-16 18:47:51 +01:00
|
|
|
if (switchNr >= power::NUMBER_OF_SWITCHES) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "PCDUHandler::getSwitchState: Invalid switch number" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2023-03-02 15:21:45 +01:00
|
|
|
uint8_t currentState = 0;
|
|
|
|
{
|
|
|
|
MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
|
2023-03-02 15:22:21 +01:00
|
|
|
currentState = switchStates[switchNr];
|
2023-03-02 15:21:45 +01:00
|
|
|
}
|
2023-03-14 13:32:13 +01:00
|
|
|
if (currentState == SWITCH_STATE_UNKNOWN) {
|
2023-03-14 13:56:19 +01:00
|
|
|
return PowerSwitchIF::SWITCH_UNKNOWN;
|
2023-03-14 13:32:13 +01:00
|
|
|
}
|
2022-03-16 20:13:21 +01:00
|
|
|
if (currentState == 1) {
|
2022-01-17 15:58:27 +01:00
|
|
|
return PowerSwitchIF::SWITCH_ON;
|
|
|
|
} else {
|
|
|
|
return PowerSwitchIF::SWITCH_OFF;
|
|
|
|
}
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::getFuseState(uint8_t fuseNr) const { return returnvalue::OK; }
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
uint32_t PcduHandler::getSwitchDelayMs(void) const { return 20000; }
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
object_id_t PcduHandler::getObjectId() const { return SystemObject::getObjectId(); }
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
2022-01-17 15:58:27 +01:00
|
|
|
LocalDataPoolManager& poolManager) {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace pcdu;
|
|
|
|
localDataPoolMap.emplace(PoolIds::PDU1_SWITCHES, &pdu1Switches);
|
2022-04-12 16:11:04 +02:00
|
|
|
localDataPoolMap.emplace(PoolIds::PDU2_SWITCHES, &pdu2Switches);
|
2023-04-03 16:25:32 +02:00
|
|
|
localDataPoolMap.emplace(PoolIds::P60DOCK_5V, &p60Dock5VSwitch);
|
|
|
|
localDataPoolMap.emplace(PoolIds::P60DOCK_3V3, &p60Dock3V3Switch);
|
2023-01-24 13:18:29 +01:00
|
|
|
poolManager.subscribeForDiagPeriodicPacket(
|
|
|
|
subdp::DiagnosticsHkPeriodicParams(switcherSet.getSid(), false, 5.0));
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
ReturnValue_t PcduHandler::initializeAfterTaskCreation() {
|
2022-01-17 15:58:27 +01:00
|
|
|
if (executingTask != nullptr) {
|
|
|
|
pstIntervalMs = executingTask->getPeriodMs();
|
|
|
|
}
|
|
|
|
this->poolManager.initializeAfterTaskCreation();
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
initializeSwitchStates();
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
uint32_t PcduHandler::getPeriodicOperationFrequency() const { return pstIntervalMs; }
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
void PcduHandler::setTaskIF(PeriodicTaskIF* task) { executingTask = task; }
|
2021-01-28 14:55:21 +01:00
|
|
|
|
2023-03-14 13:56:19 +01:00
|
|
|
LocalPoolDataSetBase* PcduHandler::getDataSetHandle(sid_t sid) {
|
2022-04-07 19:48:09 +02:00
|
|
|
if (sid == switcherSet.getSid()) {
|
|
|
|
return &switcherSet;
|
2022-01-17 15:58:27 +01:00
|
|
|
} else {
|
|
|
|
sif::error << "PCDUHandler::getDataSetHandle: Invalid sid" << std::endl;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-01-28 14:55:21 +01:00
|
|
|
}
|
2022-03-16 20:13:21 +01:00
|
|
|
|
2023-03-17 17:36:51 +01:00
|
|
|
void PcduHandler::checkAndUpdatePduSwitch(GOMSPACE::Pdu pdu, power::Switches switchIdx,
|
2023-01-10 15:04:49 +01:00
|
|
|
uint8_t setValue) {
|
2022-04-07 19:48:09 +02:00
|
|
|
using namespace pcdu;
|
2022-03-16 20:13:21 +01:00
|
|
|
if (switchStates[switchIdx] != setValue) {
|
|
|
|
triggerEvent(power::SWITCH_HAS_CHANGED, setValue, switchIdx);
|
|
|
|
}
|
|
|
|
switchStates[switchIdx] = setValue;
|
|
|
|
}
|