From fab259a2b5a6f8fc5f541ab30e2807493230bf94 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 17 Jan 2022 16:44:20 +0100 Subject: [PATCH] added BPX HK set --- mission/devices/BpxBatteryHandler.h | 4 +- .../devicedefinitions/BpxBatteryDefinitions.h | 144 ++++++++++++++++-- 2 files changed, 135 insertions(+), 13 deletions(-) diff --git a/mission/devices/BpxBatteryHandler.h b/mission/devices/BpxBatteryHandler.h index 5edc0348..6ab0ea9c 100644 --- a/mission/devices/BpxBatteryHandler.h +++ b/mission/devices/BpxBatteryHandler.h @@ -1,10 +1,10 @@ #ifndef MISSION_DEVICES_BPXBATTERYHANDLER_H_ #define MISSION_DEVICES_BPXBATTERYHANDLER_H_ -#include "devicedefinitions/BpxBatteryDefinitions.h" - #include +#include "devicedefinitions/BpxBatteryDefinitions.h" + class BpxBatteryHandler : public DeviceHandlerBase { public: BpxBatteryHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie); diff --git a/mission/devices/devicedefinitions/BpxBatteryDefinitions.h b/mission/devices/devicedefinitions/BpxBatteryDefinitions.h index ff96e857..b0ab8df7 100644 --- a/mission/devices/devicedefinitions/BpxBatteryDefinitions.h +++ b/mission/devices/devicedefinitions/BpxBatteryDefinitions.h @@ -1,11 +1,28 @@ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_BPXBATTERYDEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_BPXBATTERYDEFINITIONS_H_ +#include #include + #include namespace BpxBattery { +enum BpxPoolIds { + 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, + BOOTCAUSE = 9 +}; + +static constexpr uint32_t HK_SET_ID = 0; + static constexpr uint8_t PORT_PING = 1; static constexpr uint8_t PORT_REBOOT = 4; static constexpr uint8_t PORT_GET_HK = 9; @@ -16,6 +33,9 @@ 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; +static constexpr uint8_t HK_ENTRIES = 10; + + // Taken from BPX manual 3.14 typedef struct __attribute__((packed)) { //! Mode for battheater [0=OFF,1=Auto] @@ -26,11 +46,11 @@ typedef struct __attribute__((packed)) { //! Turn heater off at [degC] } bpx_config_t; -class BpxHkDeserializer: public SerialLinkedListAdapter { -public: - BpxHkDeserializer() { - setLinks(); - } + +//! Not used for more but might still be useful +class BpxHkDeserializer : public SerialLinkedListAdapter { + public: + BpxHkDeserializer() { setLinks(); } //! Charge current in mA SerializeElement chargeCurrent; @@ -42,17 +62,18 @@ public: //! Battery voltage in mV SerializeElement battVoltage; //! Battery temperature 1 in degC - SerializeElement battTemp1; + SerializeElement battTemp1; //! Battery temperature 2 in degC - SerializeElement battTemp2; + SerializeElement battTemp2; //! Battery temperature 3 in degC - SerializeElement battTemp3; + SerializeElement battTemp3; //! Battery temperature 4 in degC - SerializeElement battTemp4; + SerializeElement battTemp4; SerializeElement rebootCounter; SerializeElement bootcause; -private: + + private: void setLinks() { setStart(&chargeCurrent); chargeCurrent.setNext(&dischargeCurrent); @@ -67,6 +88,107 @@ private: } }; -} + +/** + * @brief BPX HK data holder + */ +class BpxBatteryHk : public StaticLocalDataSet { + public: + /** + * Constructor for data users + * @param gyroId + */ + BpxBatteryHk(object_id_t bpxId) : StaticLocalDataSet(sid_t(bpxId, BpxBattery::HK_SET_ID)) { + 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); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = dischargeCurrent.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = heaterCurrent.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = battVoltage.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = battTemp1.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = battTemp2.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = battTemp3.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = battTemp4.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = rebootCounter.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = bootcause.deSerialize(&data, &remSize, SerializeIF::Endianness::NETWORK); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return result; + } + + BpxBatteryHk(); + + private: + //! Charge current in mA + lp_var_t chargeCurrent = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::CHARGE_CURRENT, this); + //! Discharge current in mA + lp_var_t dischargeCurrent = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::DISCHARGE_CURRENT, this); + //! Heater current in mA + lp_var_t heaterCurrent = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::HEATER_CURRENT, this); + + //! Battery voltage in mV + lp_var_t battVoltage = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::BATT_VOLTAGE, this); + //! Battery temperature 1 in degC + SerializeElement battTemp1 = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::BATT_TEMP_1, this); + //! Battery temperature 2 in degC + SerializeElement battTemp2 = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::BATT_TEMP_2, this); + //! Battery temperature 3 in degC + SerializeElement battTemp3 = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::BATT_TEMP_3, this); + //! Battery temperature 4 in degC + SerializeElement battTemp4 = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::BATT_TEMP_4, this); + SerializeElement rebootCounter = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::REBOOT_COUNTER, this); + SerializeElement bootcause = + lp_var_t(sid.objectId, BpxBattery::BpxPoolIds::BOOTCAUSE, this); + + friend class BpxBatteryHandler; + /** + * Constructor for data creator + * @param hkOwner + */ + BpxBatteryHk(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, BpxBattery::HK_SET_ID) {} +}; + +}; #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_BPXBATTERYDEFINITIONS_H_ */