eive-obsw/mission/power/bpxBattDefs.h

249 lines
8.1 KiB
C
Raw Permalink Normal View History

2023-03-26 16:13:54 +02:00
#ifndef MISSION_POWER_BPXBATTDEFS_H_
#define MISSION_POWER_BPXBATTDEFS_H_
2022-01-17 15:36:52 +01:00
2022-01-17 16:44:20 +01:00
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
2022-01-17 16:21:33 +01:00
#include <fsfw/serialize/SerialLinkedListAdapter.h>
2022-01-17 16:44:20 +01:00
2022-01-17 16:21:33 +01:00
#include <cstdint>
2022-02-03 16:04:24 +01:00
#include "fsfw/devicehandlers/DeviceHandlerIF.h"
2023-04-06 22:35:23 +02:00
namespace bpxBat {
2022-01-17 15:36:52 +01:00
2022-02-03 15:31:18 +01:00
enum LocalPoolIds {
2022-01-17 16:44:20 +01:00
CHARGE_CURRENT = 0,
DISCHARGE_CURRENT = 1,
HEATER_CURRENT = 2,
BATT_VOLTAGE = 3,
BATT_TEMP_1 = 4,
BATT_TEMP_2 = 5,
BATT_TEMP_3 = 6,
BATT_TEMP_4 = 7,
REBOOT_COUNTER = 8,
2022-02-03 15:31:18 +01:00
BOOTCAUSE = 9,
2022-01-17 16:44:20 +01:00
2022-02-03 15:31:18 +01:00
BATTERY_HEATER_MODE = 10,
BATTHEAT_LOW_LIMIT = 11,
BATTHEAT_HIGH_LIMIT = 12
};
2022-01-17 17:11:27 +01:00
2022-02-02 16:07:28 +01:00
static constexpr DeviceCommandId_t GET_HK = 0;
2022-01-17 17:11:27 +01:00
static constexpr DeviceCommandId_t PING = 1;
static constexpr DeviceCommandId_t REBOOT = 2;
static constexpr DeviceCommandId_t RESET_COUNTERS = 3;
2022-02-02 16:07:28 +01:00
// This is the mnemonic GomSpace chose, but this command actually restores the default config
static constexpr DeviceCommandId_t CONFIG_CMD = 4;
static constexpr DeviceCommandId_t CONFIG_GET = 5;
static constexpr DeviceCommandId_t CONFIG_SET = 6;
2022-01-17 17:11:27 +01:00
2022-02-02 16:07:28 +01:00
static constexpr DeviceCommandId_t MAN_HEAT_ON = 10;
static constexpr DeviceCommandId_t MAN_HEAT_OFF = 11;
static constexpr uint8_t RESET_COUNTERS_MAGIC_VALUE = 0x42;
static constexpr uint8_t DEFAULT_PING_SENT_BYTE = 0x07;
2022-01-17 17:11:27 +01:00
2022-02-03 12:02:25 +01:00
static constexpr uint32_t HK_SET_ID = GET_HK;
static constexpr uint32_t CFG_SET_ID = CONFIG_GET;
2022-01-17 16:44:20 +01:00
static constexpr size_t GET_HK_REPLY_LEN = 23;
static constexpr size_t PING_REPLY_LEN = 3;
static constexpr size_t EMPTY_REPLY_LEN = 2;
2023-06-14 05:17:27 +02:00
static constexpr size_t MAN_HEAT_REPLY_LEN = 3;
static constexpr size_t CONFIG_GET_REPLY_LEN = 5;
2022-01-17 16:21:33 +01:00
static constexpr uint8_t PORT_PING = 1;
static constexpr uint8_t PORT_REBOOT = 4;
static constexpr uint8_t PORT_GET_HK = 9;
static constexpr uint8_t PORT_RESET_COUNTERS = 15;
static constexpr uint8_t PORT_CONFIG_CMD = 17;
static constexpr uint8_t PORT_CONFIG_GET = 18;
static constexpr uint8_t PORT_CONFIG_SET = 19;
static constexpr uint8_t PORT_MAN_HEAT_ON = 20;
static constexpr uint8_t PORT_MAN_HEAT_OFF = 21;
2022-01-17 16:44:20 +01:00
static constexpr uint8_t HK_ENTRIES = 10;
2022-01-17 17:11:27 +01:00
static constexpr uint8_t CFG_ENTRIES = 3;
2022-01-17 16:44:20 +01:00
2022-01-17 16:21:33 +01:00
// Taken from BPX manual 3.14
typedef struct __attribute__((packed)) {
//! Mode for battheater [0=OFF,1=Auto]
uint8_t battheater_mode;
int8_t battheater_low;
//! Turn heater on at [degC]
int8_t battheater_high;
//! Turn heater off at [degC]
} bpx_config_t;
2022-01-17 16:44:20 +01:00
//! Not used for more but might still be useful
class BpxHkDeserializer : public SerialLinkedListAdapter<SerializeIF> {
public:
BpxHkDeserializer() { setLinks(); }
2022-01-17 16:21:33 +01:00
//! Charge current in mA
SerializeElement<uint16_t> chargeCurrent;
//! Discharge current in mA
SerializeElement<uint16_t> dischargeCurrent;
//! Heater current in mA
SerializeElement<uint16_t> heaterCurrent;
//! Battery voltage in mV
SerializeElement<uint16_t> battVoltage;
//! Battery temperature 1 in degC
2022-01-17 16:44:20 +01:00
SerializeElement<int16_t> battTemp1;
2022-01-17 16:21:33 +01:00
//! Battery temperature 2 in degC
2022-01-17 16:44:20 +01:00
SerializeElement<int16_t> battTemp2;
2022-01-17 16:21:33 +01:00
//! Battery temperature 3 in degC
2022-01-17 16:44:20 +01:00
SerializeElement<int16_t> battTemp3;
2022-01-17 16:21:33 +01:00
//! Battery temperature 4 in degC
2022-01-17 16:44:20 +01:00
SerializeElement<int16_t> battTemp4;
2022-01-17 16:21:33 +01:00
SerializeElement<uint32_t> rebootCounter;
SerializeElement<uint8_t> bootcause;
2022-01-17 16:44:20 +01:00
private:
2022-01-17 16:21:33 +01:00
void setLinks() {
setStart(&chargeCurrent);
chargeCurrent.setNext(&dischargeCurrent);
dischargeCurrent.setNext(&heaterCurrent);
heaterCurrent.setNext(&battVoltage);
battVoltage.setNext(&battTemp1);
battTemp1.setNext(&battTemp2);
battTemp2.setNext(&battTemp3);
battTemp3.setNext(&battTemp4);
battTemp4.setNext(&rebootCounter);
rebootCounter.setNext(&bootcause);
}
};
2023-04-06 22:35:23 +02:00
}; // namespace bpxBat
2022-01-17 16:44:20 +01:00
/**
* @brief BPX HK data holder
*/
2023-04-06 22:35:23 +02:00
class BpxBatteryHk : public StaticLocalDataSet<bpxBat::HK_ENTRIES> {
2022-01-17 16:44:20 +01:00
public:
/**
* Constructor for data users
* @param gyroId
*/
2023-04-06 22:35:23 +02:00
BpxBatteryHk(object_id_t bpxId) : StaticLocalDataSet(sid_t(bpxId, bpxBat::HK_SET_ID)) {
2022-01-17 16:44:20 +01:00
setAllVariablesReadOnly();
}
ReturnValue_t parseRawHk(const uint8_t* data, size_t size) {
size_t remSize = size;
ReturnValue_t result =
chargeCurrent.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = dischargeCurrent.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = heaterCurrent.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = battVoltage.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = battTemp1.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = battTemp2.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = battTemp3.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = battTemp4.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = rebootCounter.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
result = bootcause.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 16:44:20 +01:00
return result;
}
return result;
}
//! Charge current in mA
2023-04-06 22:35:23 +02:00
lp_var_t<uint16_t> chargeCurrent = lp_var_t<uint16_t>(sid.objectId, bpxBat::CHARGE_CURRENT, this);
2022-01-17 16:44:20 +01:00
//! Discharge current in mA
lp_var_t<uint16_t> dischargeCurrent =
2023-04-06 22:35:23 +02:00
lp_var_t<uint16_t>(sid.objectId, bpxBat::DISCHARGE_CURRENT, this);
2022-01-17 16:44:20 +01:00
//! Heater current in mA
2023-04-06 22:35:23 +02:00
lp_var_t<uint16_t> heaterCurrent = lp_var_t<uint16_t>(sid.objectId, bpxBat::HEATER_CURRENT, this);
2022-01-17 16:44:20 +01:00
//! Battery voltage in mV
2023-04-06 22:35:23 +02:00
lp_var_t<uint16_t> battVoltage = lp_var_t<uint16_t>(sid.objectId, bpxBat::BATT_VOLTAGE, this);
2022-01-17 16:44:20 +01:00
//! Battery temperature 1 in degC
2023-04-06 22:35:23 +02:00
lp_var_t<int16_t> battTemp1 = lp_var_t<int16_t>(sid.objectId, bpxBat::BATT_TEMP_1, this);
2022-01-17 16:44:20 +01:00
//! Battery temperature 2 in degC
2023-04-06 22:35:23 +02:00
lp_var_t<int16_t> battTemp2 = lp_var_t<int16_t>(sid.objectId, bpxBat::BATT_TEMP_2, this);
2022-01-17 16:44:20 +01:00
//! Battery temperature 3 in degC
2023-04-06 22:35:23 +02:00
lp_var_t<int16_t> battTemp3 = lp_var_t<int16_t>(sid.objectId, bpxBat::BATT_TEMP_3, this);
2022-01-17 16:44:20 +01:00
//! Battery temperature 4 in degC
2023-04-06 22:35:23 +02:00
lp_var_t<int16_t> battTemp4 = lp_var_t<int16_t>(sid.objectId, bpxBat::BATT_TEMP_4, this);
lp_var_t<uint32_t> rebootCounter = lp_var_t<uint32_t>(sid.objectId, bpxBat::REBOOT_COUNTER, this);
lp_var_t<uint8_t> bootcause = lp_var_t<uint8_t>(sid.objectId, bpxBat::BOOTCAUSE, this);
2022-01-17 16:44:20 +01:00
2022-02-03 12:02:25 +01:00
private:
2022-01-17 16:44:20 +01:00
friend class BpxBatteryHandler;
/**
* Constructor for data creator
* @param hkOwner
*/
2023-04-06 22:35:23 +02:00
BpxBatteryHk(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, bpxBat::HK_SET_ID) {}
2022-01-17 16:44:20 +01:00
};
2023-04-06 22:35:23 +02:00
class BpxBatteryCfg : public StaticLocalDataSet<bpxBat::CFG_ENTRIES> {
2022-01-17 17:11:27 +01:00
public:
/**
* Constructor for data users
* @param gyroId
*/
2023-04-06 22:35:23 +02:00
BpxBatteryCfg(object_id_t bpxId) : StaticLocalDataSet(sid_t(bpxId, bpxBat::CFG_SET_ID)) {
2022-01-17 17:11:27 +01:00
setAllVariablesReadOnly();
}
ReturnValue_t parseRawHk(const uint8_t* data, size_t size) {
if (size < 3) {
return SerializeIF::STREAM_TOO_SHORT;
}
2023-06-14 05:17:27 +02:00
2022-01-17 17:11:27 +01:00
battheatermode.value = data[0];
battheaterLow.value = data[1];
battheaterHigh.value = data[2];
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 17:11:27 +01:00
}
//! Mode for battheater [0=OFF,1=Auto]
lp_var_t<uint8_t> battheatermode =
2023-04-06 22:35:23 +02:00
lp_var_t<uint8_t>(sid.objectId, bpxBat::BATTERY_HEATER_MODE, this);
2022-01-17 17:11:27 +01:00
//! Turn heater on at [degC]
2023-04-06 22:35:23 +02:00
lp_var_t<int8_t> battheaterLow = lp_var_t<int8_t>(sid.objectId, bpxBat::BATTHEAT_LOW_LIMIT, this);
2022-01-17 17:11:27 +01:00
//! Turn heater off at [degC]
lp_var_t<int8_t> battheaterHigh =
2023-04-06 22:35:23 +02:00
lp_var_t<int8_t>(sid.objectId, bpxBat::BATTHEAT_HIGH_LIMIT, this);
2022-01-17 17:11:27 +01:00
private:
friend class BpxBatteryHandler;
/**
* Constructor for data creator
* @param hkOwner
*/
2023-04-06 22:35:23 +02:00
BpxBatteryCfg(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, bpxBat::CFG_SET_ID) {}
2022-01-17 16:44:20 +01:00
};
2022-01-17 15:36:52 +01:00
2023-03-26 16:13:54 +02:00
#endif /* MISSION_POWER_BPXBATTDEFS_H_ */