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() {}
void BpxBatteryHandler::doStartUp() {
if(state == States::CHECK_COM) {
if(commandExecuted) {
if (state == States::CHECK_COM) {
if (commandExecuted) {
state = States::IDLE;
commandExecuted = false;
if(goToNormalModeImmediately) {
if (goToNormalModeImmediately) {
setMode(MODE_NORMAL);
} else {
setMode(_MODE_TO_ON);
@ -45,77 +45,79 @@ void BpxBatteryHandler::fillCommandAndReplyMap() {
ReturnValue_t BpxBatteryHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
switch(deviceCommand) {
case(BpxBattery::PING): {
if(commandDataLen == 1) {
sentPingByte = commandData[0];
} else {
sentPingByte = BpxBattery::DEFAULT_PING_SENT_BYTE;
}
switch (deviceCommand) {
case (BpxBattery::PING): {
if (commandDataLen == 1) {
sentPingByte = commandData[0];
} else {
sentPingByte = BpxBattery::DEFAULT_PING_SENT_BYTE;
}
cmdBuf[0] = BpxBattery::PORT_PING;
cmdBuf[1] = sentPingByte;
this->rawPacketLen = 2;
break;
}
case(BpxBattery::REBOOT): {
cmdBuf[0] = BpxBattery::PORT_REBOOT;
cmdBuf[1] = 0x80;
cmdBuf[2] = 0x07;
cmdBuf[3] = 0x80;
cmdBuf[4] = 0x07;
this->rawPacketLen = 5;
triggerEvent(DeviceHandlerIF::DEVICE_WANTS_HARD_REBOOT);
break;
}
case(BpxBattery::RESET_COUNTERS): {
cmdBuf[0] = BpxBattery::PORT_RESET_COUNTERS;
cmdBuf[1] = BpxBattery::RESET_COUNTERS_MAGIC_VALUE;
this->rawPacketLen = 2;
break;
}
case(BpxBattery::CONFIG_CMD): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_CMD;
// Needs to be set to 0x01 according to datasheet
cmdBuf[1] = 0x01;
this->rawPacketLen = 2;
break;
}
case(BpxBattery::CONFIG_GET): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_GET;
this->rawPacketLen = 1;
break;
}
case(BpxBattery::CONFIG_SET): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_SET;
if(commandDataLen != 3) {
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
cmdBuf[0] = BpxBattery::PORT_PING;
cmdBuf[1] = sentPingByte;
this->rawPacketLen = 2;
break;
}
for(uint8_t idx = 0; idx < 3; idx ++) {
cmdBuf[idx + 1] = commandData[idx];
case (BpxBattery::REBOOT): {
cmdBuf[0] = BpxBattery::PORT_REBOOT;
cmdBuf[1] = 0x80;
cmdBuf[2] = 0x07;
cmdBuf[3] = 0x80;
cmdBuf[4] = 0x07;
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);
break;
}
this->rawPacketLen = 4;
break;
}
case(BpxBattery::MAN_HEAT_ON): {
cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_ON;
if(commandDataLen != 2) {
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
case (BpxBattery::RESET_COUNTERS): {
cmdBuf[0] = BpxBattery::PORT_RESET_COUNTERS;
cmdBuf[1] = BpxBattery::RESET_COUNTERS_MAGIC_VALUE;
this->rawPacketLen = 2;
break;
}
for(uint8_t idx = 0; idx < 2; idx++) {
cmdBuf[idx + 1] = commandData[idx];
case (BpxBattery::CONFIG_CMD): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_CMD;
// Needs to be set to 0x01 according to datasheet
cmdBuf[1] = 0x01;
this->rawPacketLen = 2;
break;
}
case (BpxBattery::CONFIG_GET): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_GET;
this->rawPacketLen = 1;
break;
}
case (BpxBattery::CONFIG_SET): {
cmdBuf[0] = BpxBattery::PORT_CONFIG_SET;
if (commandDataLen != 3) {
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
}
for (uint8_t idx = 0; idx < 3; idx++) {
cmdBuf[idx + 1] = commandData[idx];
}
this->rawPacketLen = 4;
break;
}
case (BpxBattery::MAN_HEAT_ON): {
cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_ON;
if (commandDataLen != 2) {
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
}
for (uint8_t idx = 0; idx < 2; idx++) {
cmdBuf[idx + 1] = commandData[idx];
}
this->rawPacketLen = 3;
break;
}
case (BpxBattery::MAN_HEAT_OFF): {
cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_OFF;
this->rawPacketLen = 1;
break;
}
default: {
return DeviceHandlerIF::COMMAND_NOT_SUPPORTED;
}
this->rawPacketLen = 3;
break;
}
case(BpxBattery::MAN_HEAT_OFF): {
cmdBuf[0] = BpxBattery::PORT_MAN_HEAT_OFF;
this->rawPacketLen = 1;
break;
}
default: {
return DeviceHandlerIF::COMMAND_NOT_SUPPORTED;
}
}
this->rawPacket = cmdBuf.data();
@ -125,70 +127,85 @@ ReturnValue_t BpxBatteryHandler::buildCommandFromCommand(DeviceCommandId_t devic
ReturnValue_t BpxBatteryHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
switch(lastCmd) {
case(BpxBattery::GET_HK): {
if(remainingSize != 21) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
switch (lastCmd) {
case (BpxBattery::GET_HK): {
if (remainingSize != 21) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
}
*foundLen = 21;
break;
}
*foundLen = 21;
break;
}
case(BpxBattery::PING):
case(BpxBattery::MAN_HEAT_ON):
case(BpxBattery::MAN_HEAT_OFF): {
if(remainingSize != 1) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
case (BpxBattery::PING):
case (BpxBattery::MAN_HEAT_ON):
case (BpxBattery::MAN_HEAT_OFF): {
if (remainingSize != 1) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
}
*foundLen = 1;
break;
}
*foundLen = 1;
break;
}
case(BpxBattery::REBOOT):
case(BpxBattery::RESET_COUNTERS):
case(BpxBattery::CONFIG_CMD):
case(BpxBattery::CONFIG_SET): {
if(remainingSize != 0) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
case (BpxBattery::REBOOT):
case (BpxBattery::RESET_COUNTERS):
case (BpxBattery::CONFIG_CMD):
case (BpxBattery::CONFIG_SET): {
if (remainingSize != 0) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
}
*foundLen = 0;
break;
}
*foundLen = 0;
break;
}
case(BpxBattery::CONFIG_GET): {
if(remainingSize != 3) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
case (BpxBattery::CONFIG_GET): {
if (remainingSize != 3) {
return DeviceHandlerIF::LENGTH_MISSMATCH;
}
*foundLen = 3;
break;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
*foundLen = 3;
break;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
*foundId = lastCmd;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t BpxBatteryHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t* packet) {
switch(id) {
case(BpxBattery::GET_HK): {
ReturnValue_t result = hkSet.parseRawHk(packet, 21);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
ReturnValue_t BpxBatteryHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
switch (id) {
case (BpxBattery::GET_HK): {
ReturnValue_t result = hkSet.parseRawHk(packet, 21);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
break;
}
break;
}
case(BpxBattery::PING): {
if (packet[0] != sentPingByte) {
return DeviceHandlerIF::INVALID_DATA;
case (BpxBattery::PING): {
if (packet[0] != sentPingByte) {
return DeviceHandlerIF::INVALID_DATA;
}
break;
}
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;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
break;
}
case(BpxBattery::RESET_COUNTERS): {
break;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
@ -197,5 +214,15 @@ uint32_t BpxBatteryHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo)
ReturnValue_t BpxBatteryHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
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;
}

View File

@ -24,6 +24,16 @@ class BpxBatteryHandler : public DeviceHandlerBase {
DeviceCommandId_t lastCmd = DeviceHandlerIF::NO_COMMAND_ID;
BpxBatteryCfg cfgSet;
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 doShutDown() override;