2021-03-13 14:42:30 +01:00
|
|
|
#ifndef MISSION_DEVICES_MAX31865PT1000HANDLER_H_
|
|
|
|
#define MISSION_DEVICES_MAX31865PT1000HANDLER_H_
|
2021-03-05 12:57:42 +01:00
|
|
|
|
|
|
|
#include <OBSWConfig.h>
|
|
|
|
|
|
|
|
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
|
|
|
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
2021-03-13 14:42:30 +01:00
|
|
|
#include "devicedefinitions/Max31865Definitions.h"
|
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
|
|
|
|
*/
|
|
|
|
class Max31865PT1000Handler: public DeviceHandlerBase {
|
|
|
|
public:
|
2021-10-12 17:55:36 +02:00
|
|
|
Max31865PT1000Handler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie);
|
2021-03-05 12:57:42 +01:00
|
|
|
virtual~ Max31865PT1000Handler();
|
|
|
|
|
|
|
|
// Configuration in 8 digit code:
|
|
|
|
// 1. 1 for V_BIAS enabled, 0 for disabled
|
|
|
|
// 2. 1 for Auto-conversion, 0 for off
|
2021-06-02 10:25:35 +02:00
|
|
|
// 3. 1 for 1-shot enabled, 0 for disabled (self-clearing bit)
|
2021-10-29 19:11:46 +02:00
|
|
|
// 4. 1 for 3-wire enabled, 0 for disabled (two and four wired RTD)
|
2021-03-05 12:57:42 +01:00
|
|
|
// 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
|
2021-06-02 10:25:35 +02:00
|
|
|
// 7. Fault status: Write 1 to reset fault status register (Bit is self cleared afterwards)
|
2021-03-05 12:57:42 +01:00
|
|
|
// 8. 1 for 50 Hz filter, 0 for 60 Hz filter (noise rejection filter)
|
|
|
|
static constexpr uint8_t DEFAULT_CONFIG = 0b11000001;
|
|
|
|
|
2021-12-19 12:15:18 +01:00
|
|
|
void setInstantNormal(bool instantNormal);
|
2021-06-02 10:25:35 +02:00
|
|
|
/**
|
2021-10-12 17:55:36 +02:00
|
|
|
* Expected temperature range is -100 C and 100 C.
|
2021-06-02 10:25:35 +02:00
|
|
|
* 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
|
2021-10-12 17:55:36 +02:00
|
|
|
* indicates a temperature higher than 100 C or lower than -100 C.
|
2021-06-02 10:25:35 +02:00
|
|
|
* Default settings of MAX13865 are 0xFFFF for the high threshold register and 0x0 for the
|
|
|
|
* low threshold register.
|
|
|
|
*/
|
2021-10-12 17:55:36 +02:00
|
|
|
static constexpr uint16_t HIGH_THRESHOLD = 11298; // = 100 C
|
|
|
|
static constexpr uint16_t LOW_THRESHOLD = 4902; // = -100 C
|
2021-06-02 10:25:35 +02:00
|
|
|
|
|
|
|
static constexpr float RTD_RREF_PT1000 = 4020.0; //!< Ohm
|
2021-03-05 12:57:42 +01:00
|
|
|
static constexpr float RTD_RESISTANCE0_PT1000 = 1000.0; //!< Ohm
|
|
|
|
protected:
|
2021-12-19 12:15:18 +01:00
|
|
|
// DeviceHandlerBase abstract function implementation
|
2021-03-05 12:57:42 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
|
|
|
|
|
|
|
void debugInterface(uint8_t positionTracker = 0,
|
|
|
|
object_id_t objectId = 0, uint32_t parameter = 0) override;
|
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
|
|
|
LocalDataPoolManager& poolManager) override;
|
|
|
|
void modeChanged() override;
|
|
|
|
|
|
|
|
private:
|
2021-10-12 17:55:36 +02:00
|
|
|
uint8_t switchId = 0;
|
2021-12-19 12:15:18 +01:00
|
|
|
bool instantNormal = true;
|
2021-03-05 12:57:42 +01:00
|
|
|
|
|
|
|
enum class InternalState {
|
|
|
|
NONE,
|
|
|
|
WARMUP,
|
|
|
|
CONFIGURE,
|
2021-06-02 10:25:35 +02:00
|
|
|
CONFIG_HIGH_THRESHOLD,
|
|
|
|
REQUEST_HIGH_THRESHOLD,
|
|
|
|
CONFIG_LOW_THRESHOLD,
|
|
|
|
REQUEST_LOW_THRESHOLD,
|
2021-03-05 12:57:42 +01:00
|
|
|
REQUEST_CONFIG,
|
|
|
|
RUNNING,
|
2021-12-19 12:15:18 +01:00
|
|
|
REQUEST_FAULT_BYTE,
|
|
|
|
CLEAR_FAULT_BYTE
|
2021-03-05 12:57:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
InternalState internalState = InternalState::NONE;
|
|
|
|
bool commandExecuted = false;
|
|
|
|
|
2021-12-19 12:15:18 +01:00
|
|
|
bool resetFaultBit = false;
|
2021-03-05 12:57:42 +01:00
|
|
|
dur_millis_t startTime = 0;
|
|
|
|
uint8_t faultByte = 0;
|
|
|
|
std::array<uint8_t, 3> commandBuffer { 0 };
|
|
|
|
|
2021-03-13 14:42:30 +01:00
|
|
|
Max31865Definitions::Max31865Set sensorDataset;
|
2021-03-05 12:57:42 +01:00
|
|
|
sid_t sensorDatasetSid;
|
|
|
|
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
PeriodicOperationDivider* debugDivider;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2021-03-13 14:42:30 +01:00
|
|
|
#endif /* MISSION_DEVICES_MAX31865PT1000HANDLER_H_ */
|
2021-03-05 12:57:42 +01:00
|
|
|
|