eive-obsw/mission/devices/devicedefinitions/payloadPcduDefinitions.h

209 lines
8.3 KiB
C
Raw Normal View History

2022-02-22 13:27:21 +01:00
#ifndef LINUX_DEVICES_DEVICEDEFINITIONS_PAYLOADPCDUDEFINITIONS_H_
#define LINUX_DEVICES_DEVICEDEFINITIONS_PAYLOADPCDUDEFINITIONS_H_
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <cstddef>
#include <filesystem>
2022-02-25 19:07:47 +01:00
#include <nlohmann/json.hpp>
2022-02-22 13:27:21 +01:00
2022-02-25 19:07:47 +01:00
#include "OBSWConfig.h"
#include "mission/devices/max1227.h"
#include "mission/memory/NVMParameterBase.h"
2022-02-22 13:27:21 +01:00
namespace plpcdu {
using namespace max1227;
enum PlPcduAdcChannels : uint8_t {
U_BAT_DIV_6 = 0,
// According to schematic, will be 2.2158V for Vneg = +0V and 0.2446V for Vneg = -6V
// Full Forumula: V_neg = V_post - (R1 + R2) / R1 * (V_pos - V_out) with R1 being 27.4k
2022-02-25 15:28:59 +01:00
// and R2 being 49.9k. FB = Feedback
U_NEG_V_FB = 1,
I_HPA = 2,
U_HPA_DIV_6 = 3,
I_MPA = 4,
U_MPA_DIV_6 = 5,
I_TX = 6,
U_TX_DIV_6 = 7,
I_X8 = 8,
U_X8_DIV_6 = 9,
I_DRO = 10,
U_DRO_DIV_6 = 11,
NUM_CHANNELS = 12
};
2022-02-25 15:28:59 +01:00
enum PlPcduPoolIds : uint32_t { CHANNEL_VEC = 0, PROCESSED_VEC = 1, TEMP = 2 };
2022-02-22 13:27:21 +01:00
static constexpr size_t MAX_ADC_REPLY_SIZE = 64;
static constexpr DeviceCommandId_t READ_CMD = 0;
static constexpr DeviceCommandId_t SETUP_CMD = 1;
2022-02-22 16:51:26 +01:00
static constexpr DeviceCommandId_t READ_TEMP_EXT = 2;
static constexpr DeviceCommandId_t READ_WITH_TEMP_EXT = 3;
2022-02-22 13:27:21 +01:00
static constexpr Submode_t NORMAL_ADC_ONLY = 0;
static constexpr Submode_t NORMAL_ALL_ON = 1;
// 12 ADC values * 2 + trailing zero
static constexpr size_t ADC_REPLY_SIZE = 25;
// Conversion byte + 24 * zero
static constexpr size_t TEMP_REPLY_SIZE = 25;
static constexpr uint8_t SETUP_BYTE =
max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
static constexpr uint32_t ADC_SET_ID = READ_CMD;
static constexpr uint8_t CHANNELS_NUM = 12;
static constexpr uint8_t CHANNEL_N = CHANNELS_NUM - 1;
// Store temperature as well
static constexpr size_t DATASET_ENTRIES = CHANNELS_NUM + 1;
2022-02-25 15:28:59 +01:00
static constexpr uint8_t VOLTAGE_DIV = 6;
// 12-bit ADC: 2 to the power of 12 minus 1
static constexpr uint16_t MAX122X_BIT = 4095;
static constexpr float MAX122X_VREF = 2.5;
static constexpr float GAIN_INA169 = 100.0;
static constexpr float R_SHUNT_HPA = 0.008;
static constexpr float R_SHUNT_MPA = 0.015;
static constexpr float R_SHUNT_TX = 0.05;
static constexpr float R_SHUNT_X8 = 0.015;
static constexpr float R_SHUNT_DRO = 0.022;
static constexpr float V_POS = 3.3;
static constexpr float VOLTAGE_DIV_U_NEG = (49.9 + 27.4) / 27.4;
static constexpr float MAX122X_SCALE = MAX122X_VREF / MAX122X_BIT;
static constexpr float SCALE_VOLTAGE = MAX122X_SCALE * VOLTAGE_DIV;
static constexpr float SCALE_CURRENT_HPA = MAX122X_SCALE / (GAIN_INA169 * R_SHUNT_HPA);
static constexpr float SCALE_CURRENT_MPA = MAX122X_SCALE / (GAIN_INA169 * R_SHUNT_MPA);
static constexpr float SCALE_CURRENT_TX = MAX122X_SCALE / (GAIN_INA169 * R_SHUNT_TX);
static constexpr float SCALE_CURRENT_X8 = MAX122X_SCALE / (GAIN_INA169 * R_SHUNT_X8);
static constexpr float SCALE_CURRENT_DRO = MAX122X_SCALE / (GAIN_INA169 * R_SHUNT_DRO);
// TODO: Make these configurable parameters using a JSON file
// Upper bound of currents in milliamperes [mA]
2022-02-25 20:14:59 +01:00
static constexpr double NEG_V_LOWER_BOUND = -6.5;
static constexpr double NEG_V_UPPER_BOUND = -2.7;
2022-02-25 19:07:47 +01:00
static constexpr double DRO_U_LOWER_BOUND = 5.0;
static constexpr double DRO_U_UPPER_BOUND = 7.0;
static constexpr double DRO_I_UPPER_BOUND = 40.0;
2022-02-25 19:07:47 +01:00
static constexpr double X8_U_LOWER_BOUND = 2.6;
static constexpr double X8_U_UPPER_BOUND = 4.0;
static constexpr double X8_I_UPPER_BOUND = 100.0;
2022-02-25 19:07:47 +01:00
static constexpr double TX_U_LOWER_BOUND = 2.6;
static constexpr double TX_U_UPPER_BOUND = 4.0;
static constexpr double TX_I_UPPER_BOUND = 250.0;
2022-02-25 19:07:47 +01:00
static constexpr double MPA_U_LOWER_BOUND = 2.6;
static constexpr double MPA_U_UPPER_BOUND = 4.0;
static constexpr double MPA_I_UPPER_BOUND = 650.0;
2022-02-25 20:19:23 +01:00
static constexpr double HPA_U_LOWER_BOUND = 9.4;
2022-02-25 19:07:47 +01:00
static constexpr double HPA_U_UPPER_BOUND = 11.0;
static constexpr double HPA_I_UPPER_BOUND = 3000.0;
// Wait time in floating point seconds
2022-02-25 19:07:47 +01:00
static constexpr double SSR_TO_DRO_WAIT_TIME = 5.0;
static constexpr double DRO_TO_X8_WAIT_TIME = 905.0;
static constexpr double X8_TO_TX_WAIT_TIME = 5.0;
static constexpr double TX_TO_MPA_WAIT_TIME = 5.0;
static constexpr double MPA_TO_HPA_WAIT_TIME = 5.0;
2022-02-25 15:28:59 +01:00
/**
* The current of the processed values is calculated and stored as a milliamperes [mA].
2022-02-25 15:28:59 +01:00
* The voltages are stored as Volt values.
*/
2022-02-22 13:27:21 +01:00
class PlPcduAdcSet : public StaticLocalDataSet<DATASET_ENTRIES> {
public:
PlPcduAdcSet(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, ADC_SET_ID) {}
PlPcduAdcSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, ADC_SET_ID)) {}
lp_vec_t<uint16_t, 12> channels = lp_vec_t<uint16_t, 12>(sid.objectId, CHANNEL_VEC, this);
2022-02-25 15:28:59 +01:00
lp_vec_t<float, 12> processed = lp_vec_t<float, 12>(sid.objectId, PROCESSED_VEC, this);
2022-02-22 13:27:21 +01:00
lp_var_t<float> tempC = lp_var_t<float>(sid.objectId, TEMP, this);
};
class PlPcduParameter : public NVMParameterBase {
public:
static constexpr char SSR_TO_DRO_WAIT_TIME_K[] = "ssrToDroWait";
static constexpr char DRO_TO_X8_WAIT_TIME_K[] = "droToX8Wait";
static constexpr char X8_TO_TX_WAIT_TIME_K[] = "X8ToTxWait";
static constexpr char TX_TO_MPA_WAIT_TIME_K[] = "txToMpaWait";
static constexpr char MPA_TO_HPA_WAIT_TIME_K[] = "mpaToHpaWait";
2022-02-25 19:07:47 +01:00
static constexpr char NEG_V_LOWER_BOUND_K[] = "negVoltLowerBound";
static constexpr char NEG_V_UPPER_BOUND_K[] = "negVoltUpperBound";
static constexpr char DRO_U_LOWER_BOUND_K[] = "droVoltLowerBound";
static constexpr char DRO_U_UPPER_BOUND_K[] = "droVoltUpperBound";
static constexpr char DRO_I_UPPER_BOUND_K[] = "droCurrUpperBound";
static constexpr char X8_U_LOWER_BOUND_K[] = "x8VoltLowerBound";
static constexpr char X8_U_UPPER_BOUND_K[] = "x8VoltUpperBound";
static constexpr char X8_I_UPPER_BOUND_K[] = "x8CurrUpperBound";
static constexpr char TX_U_LOWER_BOUND_K[] = "txVoltLowerBound";
static constexpr char TX_U_UPPER_BOUND_K[] = "txVoltUpperBound";
static constexpr char TX_I_UPPER_BOUND_K[] = "txCurrUpperBound";
static constexpr char MPA_U_LOWER_BOUND_K[] = "mpaVoltLowerBound";
static constexpr char MPA_U_UPPER_BOUND_K[] = "mpaVoltUpperBound";
static constexpr char MPA_I_UPPER_BOUND_K[] = "mpaCurrUpperBound";
static constexpr char HPA_U_LOWER_BOUND_K[] = "hpaVoltLowerBound";
static constexpr char HPA_U_UPPER_BOUND_K[] = "hpaVoltUpperBound";
static constexpr char HPA_I_UPPER_BOUND_K[] = "hpaCurrUpperBound";
PlPcduParameter() : NVMParameterBase(""), mountPrefix("") {
// Initialize with default values
insertValue(SSR_TO_DRO_WAIT_TIME_K, SSR_TO_DRO_WAIT_TIME);
insertValue(DRO_TO_X8_WAIT_TIME_K, DRO_TO_X8_WAIT_TIME);
insertValue(X8_TO_TX_WAIT_TIME_K, X8_TO_TX_WAIT_TIME);
insertValue(TX_TO_MPA_WAIT_TIME_K, TX_TO_MPA_WAIT_TIME);
insertValue(MPA_TO_HPA_WAIT_TIME_K, MPA_TO_HPA_WAIT_TIME);
2022-02-25 19:07:47 +01:00
insertValue(NEG_V_LOWER_BOUND_K, NEG_V_LOWER_BOUND);
insertValue(NEG_V_UPPER_BOUND_K, NEG_V_UPPER_BOUND);
insertValue(DRO_U_LOWER_BOUND_K, DRO_U_LOWER_BOUND);
insertValue(DRO_U_UPPER_BOUND_K, DRO_U_UPPER_BOUND);
insertValue(DRO_I_UPPER_BOUND_K, DRO_I_UPPER_BOUND);
insertValue(X8_U_LOWER_BOUND_K, X8_U_LOWER_BOUND);
insertValue(X8_U_UPPER_BOUND_K, X8_U_UPPER_BOUND);
insertValue(X8_I_UPPER_BOUND_K, X8_I_UPPER_BOUND);
insertValue(TX_U_LOWER_BOUND_K, TX_U_LOWER_BOUND);
insertValue(TX_U_UPPER_BOUND_K, TX_U_UPPER_BOUND);
insertValue(TX_I_UPPER_BOUND_K, TX_I_UPPER_BOUND);
insertValue(MPA_U_LOWER_BOUND_K, MPA_U_LOWER_BOUND);
insertValue(MPA_U_UPPER_BOUND_K, MPA_U_UPPER_BOUND);
insertValue(MPA_I_UPPER_BOUND_K, MPA_I_UPPER_BOUND);
insertValue(HPA_U_LOWER_BOUND_K, HPA_U_LOWER_BOUND);
insertValue(HPA_U_UPPER_BOUND_K, HPA_U_UPPER_BOUND);
insertValue(HPA_I_UPPER_BOUND_K, HPA_I_UPPER_BOUND);
}
ReturnValue_t initialize(std::string mountPrefix) {
setFullName(mountPrefix + "/conf/plpcdu.json");
ReturnValue_t result = readJsonFile();
2022-02-25 19:07:47 +01:00
if (result != HasReturnvaluesIF::RETURN_OK) {
// File does not exist. Create it. Keys and appropriate init values were
// specified in constructor
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "Creating PL PCDU JSON file at " << getFullName() << std::endl;
#endif
writeJsonFile();
}
return HasReturnvaluesIF::RETURN_OK;
}
private:
std::string mountPrefix;
};
2022-02-22 13:27:21 +01:00
} // namespace plpcdu
#endif /* LINUX_DEVICES_DEVICEDEFINITIONS_PAYLOADPCDUDEFINITIONS_H_ */