eive-obsw/mission/devices/ACUHandler.cpp

309 lines
17 KiB
C++
Raw Normal View History

2021-01-28 14:55:21 +01:00
#include "ACUHandler.h"
2021-02-16 17:02:03 +01:00
#include "OBSWConfig.h"
2021-01-28 14:55:21 +01:00
2021-02-06 11:57:45 +01:00
ACUHandler::ACUHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) :
GomspaceDeviceHandler(objectId, comIF, comCookie, ACU::MAX_CONFIGTABLE_ADDRESS,
2021-02-14 11:40:40 +01:00
ACU::MAX_HKTABLE_ADDRESS, ACU::HK_TABLE_REPLY_SIZE, &acuHkTableDataset), acuHkTableDataset(
2021-02-06 11:57:45 +01:00
this) {
2021-01-28 14:55:21 +01:00
}
ACUHandler::~ACUHandler() {
}
2021-02-12 14:31:43 +01:00
ReturnValue_t ACUHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
*id = GOMSPACE::REQUEST_HK_TABLE;
return buildCommandFromCommand(*id, NULL, 0);
}
void ACUHandler::fillCommandAndReplyMap() {
GomspaceDeviceHandler::fillCommandAndReplyMap();
this->insertInCommandMap(PRINT_CHANNEL_STATS);
}
2021-01-28 14:55:21 +01:00
void ACUHandler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *packet) {
2021-02-14 11:40:40 +01:00
parseHkTableReply(packet);
handleDeviceTM(&acuHkTableDataset, id, true);
2021-08-17 17:48:51 +02:00
#if OBSW_ENHANCED_PRINTOUT == 1 && OBSW_DEBUG_ACU == 1
2021-02-14 11:40:40 +01:00
acuHkTableDataset.read();
float temperatureC_1 = acuHkTableDataset.temperature1.value * 0.1;
float temperatureC_2 = acuHkTableDataset.temperature2.value * 0.1;
float temperatureC_3 = acuHkTableDataset.temperature3.value * 0.1;
sif::info << "ACU: Temperature 1: " << temperatureC_1 << " °C" << std::endl;
sif::info << "ACU: Temperature 2: " << temperatureC_2 << " °C" << std::endl;
sif::info << "ACU: Temperature 3: " << temperatureC_3 << " °C" << std::endl;
2021-02-16 17:02:03 +01:00
sif::info << "ACU: Ground Watchdog Timer Count: "
<< acuHkTableDataset.wdtCntGnd.value << std::endl;
sif::info << "ACU: Ground watchdog timer, seconds left before reboot: "
<< acuHkTableDataset.wdtGndLeft.value << std::endl;
2021-02-14 11:40:40 +01:00
acuHkTableDataset.commit();
#endif
2021-01-28 14:55:21 +01:00
}
2021-02-12 14:31:43 +01:00
void ACUHandler::parseHkTableReply(const uint8_t *packet) {
uint16_t dataOffset = 0;
acuHkTableDataset.read();
dataOffset += 12;
acuHkTableDataset.currentInChannel0 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.currentInChannel1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.currentInChannel2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.currentInChannel3 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.currentInChannel4 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.currentInChannel5 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.voltageInChannel0 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.voltageInChannel1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.voltageInChannel2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.voltageInChannel3 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.voltageInChannel4 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.voltageInChannel5 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vcc = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vbat = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.temperature1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.temperature2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.temperature3 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.mpptMode = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.vboostInChannel0 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vboostInChannel1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vboostInChannel2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vboostInChannel3 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vboostInChannel4 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.vboostInChannel5 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.powerInChannel0 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.powerInChannel1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.powerInChannel2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.powerInChannel3 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.powerInChannel4 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.powerInChannel5 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.dac0Enable = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.dac1Enable = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.dac2Enable = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.dacRawChannelVal0 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.dacRawChannelVal1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.dacRawChannelVal2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.dacRawChannelVal3 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.dacRawChannelVal4 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.dacRawChannelVal5 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.bootCause = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6;
acuHkTableDataset.bootcnt = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6;
acuHkTableDataset.uptime = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6;
acuHkTableDataset.resetCause = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.mpptTime = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
2021-02-16 17:02:03 +01:00
/* +12 because here starts the second csp packet */
dataOffset += 2 + 12;
acuHkTableDataset.mpptPeriod = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4;
acuHkTableDataset.device0 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device1 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device2 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device3 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device4 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device5 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device6 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device7 = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device0Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device1Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device2Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device3Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device4Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device5Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device6Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.device7Status = *(packet + dataOffset);
dataOffset += 3;
acuHkTableDataset.wdtCntGnd = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6;
acuHkTableDataset.wdtGndLeft = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6;
2021-02-12 14:31:43 +01:00
acuHkTableDataset.commit();
}
ReturnValue_t ACUHandler::initializeLocalDataPool(
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(P60System::ACU_CURRENT_IN_CHANNEL0, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_CURRENT_IN_CHANNEL1, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_CURRENT_IN_CHANNEL2, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_CURRENT_IN_CHANNEL3, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_CURRENT_IN_CHANNEL4, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_CURRENT_IN_CHANNEL5, new PoolEntry<int16_t>( { 0 }));
2021-02-14 12:07:18 +01:00
localDataPoolMap.emplace(P60System::ACU_VOLTAGE_IN_CHANNEL0, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VOLTAGE_IN_CHANNEL1, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VOLTAGE_IN_CHANNEL2, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VOLTAGE_IN_CHANNEL3, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VOLTAGE_IN_CHANNEL4, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VOLTAGE_IN_CHANNEL5, new PoolEntry<uint16_t>( { 0 }));
2021-02-12 14:31:43 +01:00
localDataPoolMap.emplace(P60System::ACU_VCC, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VBAT, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_TEMPERATURE_1, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_TEMPERATURE_2, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_TEMPERATURE_3, new PoolEntry<int16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_MPPT_MODE, new PoolEntry<uint8_t>( { 0 }));
2021-02-12 14:31:43 +01:00
localDataPoolMap.emplace(P60System::ACU_VBOOST_CHANNEL0, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VBOOST_CHANNEL1, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VBOOST_CHANNEL2, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VBOOST_CHANNEL3, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VBOOST_CHANNEL4, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_VBOOST_CHANNEL5, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_POWER_CHANNEL0, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_POWER_CHANNEL1, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_POWER_CHANNEL2, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_POWER_CHANNEL3, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_POWER_CHANNEL4, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_POWER_CHANNEL5, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_EN_0, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_EN_1, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_EN_2, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_RAW_0, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_RAW_1, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_RAW_2, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_RAW_3, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_RAW_4, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DAC_RAW_5, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_BOOTCAUSE, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_BOOTCNT, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_UPTIME, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_RESET_CAUSE, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_MPPT_TIME, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_MPPT_PERIOD, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_0, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_1, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_2, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_3, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_4, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_5, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_6, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_7, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_0_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_1_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_2_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_3_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_4_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_5_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_6_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_DEVICE_7_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_WDT_CNT_GND, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(P60System::ACU_WDT_GND_LEFT, new PoolEntry<uint32_t>( { 0 }));
return HasReturnvaluesIF::RETURN_OK;
}
2021-12-17 10:45:55 +01:00
ReturnValue_t ACUHandler::deviceSpecificCommand(DeviceCommandId_t cmd) {
switch(cmd) {
case PRINT_CHANNEL_STATS: {
printChannelStats();
return RETURN_OK;
}
default: {
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
}
}
void ACUHandler::printChannelStats() {
PoolReadGuard pg(&acuHkTableDataset);
sif::info << "ACU Info: Current [mA], Voltage [mV]" << std::endl;
sif::info << std::setw(8) << std::left << "Ch0" << std::dec << "| " <<
2021-12-17 15:24:23 +01:00
static_cast<unsigned int>(acuHkTableDataset.currentInChannel0.value) <<
std::setw(15) << std::right << acuHkTableDataset.voltageInChannel0.value << std::endl;
sif::info << std::setw(8) << std::left << "Ch1" << std::dec << "| " <<
2021-12-17 15:24:23 +01:00
static_cast<unsigned int>(acuHkTableDataset.currentInChannel1.value) <<
std::setw(15) << std::right << acuHkTableDataset.voltageInChannel1.value << std::endl;
sif::info << std::setw(8) << std::left << "Ch2" << std::dec << "| " <<
2021-12-17 15:24:23 +01:00
static_cast<unsigned int>(acuHkTableDataset.currentInChannel2.value) <<
std::setw(15) << std::right << acuHkTableDataset.voltageInChannel2.value << std::endl;
sif::info << std::setw(8) << std::left << "Ch3" << std::dec << "| " <<
2021-12-17 15:24:23 +01:00
static_cast<unsigned int>(acuHkTableDataset.currentInChannel3.value) <<
std::setw(15) << std::right << acuHkTableDataset.voltageInChannel3.value << std::endl;
sif::info << std::setw(8) << std::left << "Ch4" << std::dec << "| " <<
2021-12-17 15:24:23 +01:00
static_cast<unsigned int>(acuHkTableDataset.currentInChannel4.value) <<
std::setw(15) << std::right << acuHkTableDataset.voltageInChannel4.value << std::endl;
sif::info << std::setw(8) << std::left << "Ch5" << std::dec << "| " <<
2021-12-17 15:24:23 +01:00
static_cast<unsigned int>(acuHkTableDataset.currentInChannel5.value) <<
std::setw(15) << std::right << acuHkTableDataset.voltageInChannel5.value << std::endl;
2021-12-17 10:45:55 +01:00
}