2023-03-26 16:42:00 +02:00
|
|
|
#ifndef MISSION_TCS_MAX31865PT1000HANDLER_H_
|
|
|
|
#define MISSION_TCS_MAX31865PT1000HANDLER_H_
|
2021-03-05 12:57:42 +01:00
|
|
|
|
|
|
|
#include <OBSWConfig.h>
|
|
|
|
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
|
|
|
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
2023-03-26 16:42:00 +02:00
|
|
|
#include <mission/tcs/Max31865Definitions.h>
|
2021-03-05 12:57:42 +01:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2021-03-05 12:57:42 +01:00
|
|
|
/**
|
|
|
|
* @brief Device Handler for the thermal sensors
|
|
|
|
* @details
|
|
|
|
* Documentation of devices:
|
|
|
|
* MAX31865 RTD converter:
|
|
|
|
* https://datasheets.maximintegrated.com/en/ds/MAX31865.pdf
|
|
|
|
* Pt1000 platinum resistance thermometers OMEGA F2020-1000-1/3B:
|
|
|
|
* https://br.omega.com/omegaFiles/temperature/pdf/F1500_F2000_F4000.pdf
|
|
|
|
*
|
|
|
|
* The thermal sensor values are measured using the MAX31865 RTD converter IC
|
|
|
|
* which creates digital values from the measured resistance of the Pt1000
|
|
|
|
* devices which can be read with the SPI interface.
|
|
|
|
* Refer to the SOURCE system schematic for the exact setup and number
|
|
|
|
* of devices.
|
|
|
|
*
|
|
|
|
* @author R. Mueller
|
|
|
|
* @ingroup devices
|
|
|
|
*/
|
2022-01-17 15:58:27 +01:00
|
|
|
class Max31865PT1000Handler : public DeviceHandlerBase {
|
|
|
|
public:
|
|
|
|
Max31865PT1000Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie);
|
|
|
|
virtual ~Max31865PT1000Handler();
|
|
|
|
|
2022-04-26 10:37:25 +02:00
|
|
|
void setDebugMode(bool enable);
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
// Configuration in 8 digit code:
|
|
|
|
// 1. 1 for V_BIAS enabled, 0 for disabled
|
|
|
|
// 2. 1 for Auto-conversion, 0 for off
|
|
|
|
// 3. 1 for 1-shot enabled, 0 for disabled (self-clearing bit)
|
|
|
|
// 4. 1 for 3-wire enabled, 0 for disabled (two and four wired RTD)
|
|
|
|
// 5./6. Fault detection: 00 for no action, 01 for automatic delay, 1
|
|
|
|
// 0 for run fault detection with manual delay,
|
|
|
|
// 11 for finish fault detection with manual delay
|
|
|
|
// 7. Fault status: Write 1 to reset fault status register (Bit is self cleared afterwards)
|
|
|
|
// 8. 1 for 50 Hz filter, 0 for 60 Hz filter (noise rejection filter)
|
|
|
|
static constexpr uint8_t DEFAULT_CONFIG = 0b11000001;
|
|
|
|
|
|
|
|
void setInstantNormal(bool instantNormal);
|
2022-05-12 12:12:47 +02:00
|
|
|
void setDeviceInfo(uint8_t idx, std::string locString);
|
2022-03-23 15:02:48 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
/**
|
|
|
|
* Expected temperature range is -100 C and 100 C.
|
|
|
|
* If there are temperatures beyond this range there must be a fault.
|
|
|
|
* The threshold variables cause the MAX1385 to signal an error in case the measured resistance
|
|
|
|
* indicates a temperature higher than 100 C or lower than -100 C.
|
|
|
|
* Default settings of MAX13865 are 0xFFFF for the high threshold register and 0x0 for the
|
|
|
|
* low threshold register.
|
|
|
|
*/
|
|
|
|
static constexpr uint16_t HIGH_THRESHOLD = 11298; // = 100 C
|
|
|
|
static constexpr uint16_t LOW_THRESHOLD = 4902; // = -100 C
|
|
|
|
|
|
|
|
static constexpr float RTD_RESISTANCE0_PT1000 = 1000.0; //!< Ohm
|
|
|
|
protected:
|
|
|
|
// DeviceHandlerBase abstract function implementation
|
|
|
|
void doStartUp() override;
|
|
|
|
void doShutDown() override;
|
|
|
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
|
|
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
|
|
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen) override;
|
|
|
|
void fillCommandAndReplyMap() override;
|
|
|
|
ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId,
|
|
|
|
size_t *foundLen) override;
|
|
|
|
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
|
|
|
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
|
|
|
ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) override;
|
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
|
|
|
LocalDataPoolManager &poolManager) override;
|
|
|
|
void modeChanged() override;
|
2022-05-13 10:27:26 +02:00
|
|
|
bool shouldFaultStatusBeRequested(bool faultBit);
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t switchId = 0;
|
2022-03-22 20:35:37 +01:00
|
|
|
bool instantNormal = false;
|
2022-04-26 10:37:25 +02:00
|
|
|
bool debugMode = false;
|
2022-03-22 19:30:10 +01:00
|
|
|
bool warningSwitch = true;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
enum class InternalState {
|
|
|
|
NONE,
|
|
|
|
WARMUP,
|
|
|
|
CONFIGURE,
|
|
|
|
CONFIG_HIGH_THRESHOLD,
|
|
|
|
REQUEST_HIGH_THRESHOLD,
|
|
|
|
CONFIG_LOW_THRESHOLD,
|
|
|
|
REQUEST_LOW_THRESHOLD,
|
|
|
|
REQUEST_CONFIG,
|
|
|
|
RUNNING,
|
|
|
|
REQUEST_FAULT_BYTE,
|
|
|
|
CLEAR_FAULT_BYTE
|
|
|
|
};
|
|
|
|
|
|
|
|
InternalState internalState = InternalState::NONE;
|
|
|
|
bool commandExecuted = false;
|
|
|
|
|
|
|
|
bool resetFaultBit = false;
|
|
|
|
dur_millis_t startTime = 0;
|
2022-05-12 11:27:30 +02:00
|
|
|
uint8_t currentCfg = 0;
|
2022-05-13 10:27:26 +02:00
|
|
|
uint8_t currentFaultStatus = 0;
|
2022-05-13 10:10:02 +02:00
|
|
|
uint8_t lastFaultStatus = 0;
|
|
|
|
uint16_t sameFaultStatusCounter = 0;
|
2022-05-09 21:29:54 +02:00
|
|
|
std::string locString;
|
2022-03-23 15:02:48 +01:00
|
|
|
uint8_t deviceIdx = 0;
|
2022-01-17 15:58:27 +01:00
|
|
|
std::array<uint8_t, 3> commandBuffer{0};
|
|
|
|
|
2022-11-25 10:13:24 +01:00
|
|
|
MAX31865::PrimarySet sensorDataset;
|
2022-01-17 15:58:27 +01:00
|
|
|
sid_t sensorDatasetSid;
|
2021-03-05 12:57:42 +01:00
|
|
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
2022-01-17 15:58:27 +01:00
|
|
|
PeriodicOperationDivider *debugDivider;
|
2021-03-05 12:57:42 +01:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2023-03-26 16:42:00 +02:00
|
|
|
#endif /* MISSION_TCS_MAX31865PT1000HANDLER_H_ */
|