created all pool entries for bpx handler
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2022-02-02 16:33:36 +01:00
parent 89bbf98b4a
commit 0067cac94d
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 159 additions and 122 deletions

View File

@ -6,11 +6,11 @@ BpxBatteryHandler::BpxBatteryHandler(object_id_t objectId, object_id_t comIF, Co
BpxBatteryHandler::~BpxBatteryHandler() {} BpxBatteryHandler::~BpxBatteryHandler() {}
void BpxBatteryHandler::doStartUp() { void BpxBatteryHandler::doStartUp() {
if(state == States::CHECK_COM) { if (state == States::CHECK_COM) {
if(commandExecuted) { if (commandExecuted) {
state = States::IDLE; state = States::IDLE;
commandExecuted = false; commandExecuted = false;
if(goToNormalModeImmediately) { if (goToNormalModeImmediately) {
setMode(MODE_NORMAL); setMode(MODE_NORMAL);
} else { } else {
setMode(_MODE_TO_ON); setMode(_MODE_TO_ON);
@ -45,9 +45,9 @@ void BpxBatteryHandler::fillCommandAndReplyMap() {
ReturnValue_t BpxBatteryHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, ReturnValue_t BpxBatteryHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData, const uint8_t* commandData,
size_t commandDataLen) { size_t commandDataLen) {
switch(deviceCommand) { switch (deviceCommand) {
case(BpxBattery::PING): { case (BpxBattery::PING): {
if(commandDataLen == 1) { if (commandDataLen == 1) {
sentPingByte = commandData[0]; sentPingByte = commandData[0];
} else { } else {
sentPingByte = BpxBattery::DEFAULT_PING_SENT_BYTE; sentPingByte = BpxBattery::DEFAULT_PING_SENT_BYTE;
@ -58,57 +58,59 @@ ReturnValue_t BpxBatteryHandler::buildCommandFromCommand(DeviceCommandId_t devic
this->rawPacketLen = 2; this->rawPacketLen = 2;
break; break;
} }
case(BpxBattery::REBOOT): { case (BpxBattery::REBOOT): {
cmdBuf[0] = BpxBattery::PORT_REBOOT; cmdBuf[0] = BpxBattery::PORT_REBOOT;
cmdBuf[1] = 0x80; cmdBuf[1] = 0x80;
cmdBuf[2] = 0x07; cmdBuf[2] = 0x07;
cmdBuf[3] = 0x80; cmdBuf[3] = 0x80;
cmdBuf[4] = 0x07; cmdBuf[4] = 0x07;
this->rawPacketLen = 5; this->rawPacketLen = 5;
// This instructs the FDIR to set the device mode off and on again
// to ensure the I2C communication is also verified
triggerEvent(DeviceHandlerIF::DEVICE_WANTS_HARD_REBOOT); triggerEvent(DeviceHandlerIF::DEVICE_WANTS_HARD_REBOOT);
break; break;
} }
case(BpxBattery::RESET_COUNTERS): { case (BpxBattery::RESET_COUNTERS): {
cmdBuf[0] = BpxBattery::PORT_RESET_COUNTERS; cmdBuf[0] = BpxBattery::PORT_RESET_COUNTERS;
cmdBuf[1] = BpxBattery::RESET_COUNTERS_MAGIC_VALUE; cmdBuf[1] = BpxBattery::RESET_COUNTERS_MAGIC_VALUE;
this->rawPacketLen = 2; this->rawPacketLen = 2;
break; break;
} }
case(BpxBattery::CONFIG_CMD): { case (BpxBattery::CONFIG_CMD): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_CMD; cmdBuf[0] = BpxBattery::PORT_CONFIG_CMD;
// Needs to be set to 0x01 according to datasheet // Needs to be set to 0x01 according to datasheet
cmdBuf[1] = 0x01; cmdBuf[1] = 0x01;
this->rawPacketLen = 2; this->rawPacketLen = 2;
break; break;
} }
case(BpxBattery::CONFIG_GET): { case (BpxBattery::CONFIG_GET): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_GET; cmdBuf[0] = BpxBattery::PORT_CONFIG_GET;
this->rawPacketLen = 1; this->rawPacketLen = 1;
break; break;
} }
case(BpxBattery::CONFIG_SET): { case (BpxBattery::CONFIG_SET): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_SET; cmdBuf[0] = BpxBattery::PORT_CONFIG_SET;
if(commandDataLen != 3) { if (commandDataLen != 3) {
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
} }
for(uint8_t idx = 0; idx < 3; idx ++) { for (uint8_t idx = 0; idx < 3; idx++) {
cmdBuf[idx + 1] = commandData[idx]; cmdBuf[idx + 1] = commandData[idx];
} }
this->rawPacketLen = 4; this->rawPacketLen = 4;
break; break;
} }
case(BpxBattery::MAN_HEAT_ON): { case (BpxBattery::MAN_HEAT_ON): {
cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_ON; cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_ON;
if(commandDataLen != 2) { if (commandDataLen != 2) {
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
} }
for(uint8_t idx = 0; idx < 2; idx++) { for (uint8_t idx = 0; idx < 2; idx++) {
cmdBuf[idx + 1] = commandData[idx]; cmdBuf[idx + 1] = commandData[idx];
} }
this->rawPacketLen = 3; this->rawPacketLen = 3;
break; break;
} }
case(BpxBattery::MAN_HEAT_OFF): { case (BpxBattery::MAN_HEAT_OFF): {
cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_OFF; cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_OFF;
this->rawPacketLen = 1; this->rawPacketLen = 1;
break; break;
@ -125,35 +127,35 @@ ReturnValue_t BpxBatteryHandler::buildCommandFromCommand(DeviceCommandId_t devic
ReturnValue_t BpxBatteryHandler::scanForReply(const uint8_t* start, size_t remainingSize, ReturnValue_t BpxBatteryHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) { DeviceCommandId_t* foundId, size_t* foundLen) {
switch(lastCmd) { switch (lastCmd) {
case(BpxBattery::GET_HK): { case (BpxBattery::GET_HK): {
if(remainingSize != 21) { if (remainingSize != 21) {
return DeviceHandlerIF::LENGTH_MISSMATCH; return DeviceHandlerIF::LENGTH_MISSMATCH;
} }
*foundLen = 21; *foundLen = 21;
break; break;
} }
case(BpxBattery::PING): case (BpxBattery::PING):
case(BpxBattery::MAN_HEAT_ON): case (BpxBattery::MAN_HEAT_ON):
case(BpxBattery::MAN_HEAT_OFF): { case (BpxBattery::MAN_HEAT_OFF): {
if(remainingSize != 1) { if (remainingSize != 1) {
return DeviceHandlerIF::LENGTH_MISSMATCH; return DeviceHandlerIF::LENGTH_MISSMATCH;
} }
*foundLen = 1; *foundLen = 1;
break; break;
} }
case(BpxBattery::REBOOT): case (BpxBattery::REBOOT):
case(BpxBattery::RESET_COUNTERS): case (BpxBattery::RESET_COUNTERS):
case(BpxBattery::CONFIG_CMD): case (BpxBattery::CONFIG_CMD):
case(BpxBattery::CONFIG_SET): { case (BpxBattery::CONFIG_SET): {
if(remainingSize != 0) { if (remainingSize != 0) {
return DeviceHandlerIF::LENGTH_MISSMATCH; return DeviceHandlerIF::LENGTH_MISSMATCH;
} }
*foundLen = 0; *foundLen = 0;
break; break;
} }
case(BpxBattery::CONFIG_GET): { case (BpxBattery::CONFIG_GET): {
if(remainingSize != 3) { if (remainingSize != 3) {
return DeviceHandlerIF::LENGTH_MISSMATCH; return DeviceHandlerIF::LENGTH_MISSMATCH;
} }
*foundLen = 3; *foundLen = 3;
@ -167,23 +169,38 @@ ReturnValue_t BpxBatteryHandler::scanForReply(const uint8_t* start, size_t remai
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t BpxBatteryHandler::interpretDeviceReply(DeviceCommandId_t id, ReturnValue_t BpxBatteryHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
const uint8_t* packet) { switch (id) {
switch(id) { case (BpxBattery::GET_HK): {
case(BpxBattery::GET_HK): {
ReturnValue_t result = hkSet.parseRawHk(packet, 21); ReturnValue_t result = hkSet.parseRawHk(packet, 21);
if(result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
break; break;
} }
case(BpxBattery::PING): { case (BpxBattery::PING): {
if (packet[0] != sentPingByte) { if (packet[0] != sentPingByte) {
return DeviceHandlerIF::INVALID_DATA; return DeviceHandlerIF::INVALID_DATA;
} }
break; break;
} }
case(BpxBattery::RESET_COUNTERS): { case (BpxBattery::RESET_COUNTERS):
case (BpxBattery::CONFIG_CMD):
case (BpxBattery::CONFIG_SET): {
break;
}
case (BpxBattery::MAN_HEAT_ON):
case (BpxBattery::MAN_HEAT_OFF): {
if (packet[0] != 0x01) {
return DeviceHandlerIF::DEVICE_DID_NOT_EXECUTE;
}
break;
}
case (BpxBattery::CONFIG_GET): {
ReturnValue_t result = cfgSet.parseRawHk(packet, 3);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
break; break;
} }
default: { default: {
@ -197,5 +214,15 @@ uint32_t BpxBatteryHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo)
ReturnValue_t BpxBatteryHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, ReturnValue_t BpxBatteryHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) { LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(BpxBattery::HkPoolIds::BATT_TEMP_1, &battTemp1);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::BATT_TEMP_2, &battTemp2);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::BATT_TEMP_3, &battTemp3);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::BATT_TEMP_4, &battTemp4);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::CHARGE_CURRENT, &chargeCurrent);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::DISCHARGE_CURRENT, &dischargeCurrent);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::HEATER_CURRENT, &heaterCurrent);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::BATT_VOLTAGE, &battVolt);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::REBOOT_COUNTER, &rebootCounter);
localDataPoolMap.emplace(BpxBattery::HkPoolIds::BOOTCAUSE, &bootCause);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -24,6 +24,16 @@ class BpxBatteryHandler : public DeviceHandlerBase {
DeviceCommandId_t lastCmd = DeviceHandlerIF::NO_COMMAND_ID; DeviceCommandId_t lastCmd = DeviceHandlerIF::NO_COMMAND_ID;
BpxBatteryCfg cfgSet; BpxBatteryCfg cfgSet;
std::array<uint8_t, 8> cmdBuf = {}; std::array<uint8_t, 8> cmdBuf = {};
PoolEntry<uint16_t> chargeCurrent = PoolEntry<uint16_t>({0});
PoolEntry<uint16_t> dischargeCurrent = PoolEntry<uint16_t>({0});
PoolEntry<uint16_t> heaterCurrent = PoolEntry<uint16_t>({0});
PoolEntry<uint16_t> battVolt = PoolEntry<uint16_t>({0});
PoolEntry<int16_t> battTemp1 = PoolEntry<int16_t>({0});
PoolEntry<int16_t> battTemp2 = PoolEntry<int16_t>({0});
PoolEntry<int16_t> battTemp3 = PoolEntry<int16_t>({0});
PoolEntry<int16_t> battTemp4 = PoolEntry<int16_t>({0});
PoolEntry<uint32_t> rebootCounter = PoolEntry<uint32_t>({0});
PoolEntry<uint8_t> bootCause = PoolEntry<uint8_t>({0});
void doStartUp() override; void doStartUp() override;
void doShutDown() override; void doShutDown() override;