2021-05-03 11:59:33 +02:00
|
|
|
#ifndef MISSION_DEVICES_SUSHANDLER_H_
|
|
|
|
#define MISSION_DEVICES_SUSHANDLER_H_
|
|
|
|
|
|
|
|
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
2021-08-03 15:58:01 +02:00
|
|
|
#include <fsfw_hal/linux/gpio/LinuxLibgpioIF.h>
|
2021-05-03 11:59:33 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
#include "devicedefinitions/SusDefinitions.h"
|
2022-02-11 17:38:02 +01:00
|
|
|
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
2022-02-15 17:08:57 +01:00
|
|
|
#include "mission/devices/max1227.h"
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2021-05-03 11:59:33 +02:00
|
|
|
/**
|
2022-02-10 14:24:34 +01:00
|
|
|
* @brief This is the device handler class for the SUS sensor based on the MAX1227 ADC.
|
2021-05-03 11:59:33 +02:00
|
|
|
*
|
2022-02-10 14:24:34 +01:00
|
|
|
* @details
|
|
|
|
* Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf
|
|
|
|
* Details about the SUS electronic can be found at
|
|
|
|
* https://egit.irs.uni-stuttgart.de/eive/eive_dokumente/src/branch/master/400_Raumsegment/443_SunSensorDocumentation/release
|
2021-05-03 11:59:33 +02:00
|
|
|
*
|
2021-05-12 16:38:20 +02:00
|
|
|
* @note When adding a SusHandler to the polling sequence table make sure to add a slot with
|
|
|
|
* the executionStep FIRST_WRITE. Otherwise the communication sequence will never be
|
|
|
|
* started.
|
|
|
|
*
|
2021-05-03 11:59:33 +02:00
|
|
|
* @author J. Meier
|
|
|
|
*/
|
2022-01-17 15:58:27 +01:00
|
|
|
class SusHandler : public DeviceHandlerBase {
|
|
|
|
public:
|
2022-02-15 16:40:48 +01:00
|
|
|
enum ClkModes { INT_CLOCKED, EXT_CLOCKED, EXT_CLOCKED_WITH_TEMP };
|
2022-02-14 19:41:03 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
static const uint8_t FIRST_WRITE = 7;
|
2021-05-03 11:59:33 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
SusHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
|
|
|
|
LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId);
|
|
|
|
virtual ~SusHandler();
|
2021-05-12 16:38:20 +02:00
|
|
|
|
2022-02-14 17:13:06 +01:00
|
|
|
// virtual ReturnValue_t performOperation(uint8_t counter) override;
|
2021-05-12 13:06:56 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
virtual ReturnValue_t initialize() override;
|
2022-02-11 17:38:02 +01:00
|
|
|
void setToGoToNormalMode(bool enable);
|
2021-05-03 11:59:33 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
protected:
|
|
|
|
void doStartUp() override;
|
|
|
|
void doShutDown() override;
|
|
|
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
|
|
|
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
|
|
|
|
void fillCommandAndReplyMap() override;
|
|
|
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
|
|
|
size_t commandDataLen) 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;
|
2022-02-14 19:41:03 +01:00
|
|
|
// void setNormalDatapoolEntriesInvalid() override;
|
2022-01-17 15:58:27 +01:00
|
|
|
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
|
|
|
LocalDataPoolManager& poolManager) override;
|
2021-05-03 11:59:33 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
private:
|
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::SUS_HANDLER;
|
2021-05-12 13:06:56 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
static const ReturnValue_t ERROR_UNLOCK_MUTEX = MAKE_RETURN_CODE(0xA0);
|
|
|
|
static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1);
|
2021-05-12 13:06:56 +02:00
|
|
|
|
2022-02-14 19:41:03 +01:00
|
|
|
enum class ComStates {
|
|
|
|
IDLE,
|
|
|
|
WRITE_SETUP,
|
|
|
|
EXT_CLOCKED_CONVERSIONS,
|
2022-02-15 17:08:57 +01:00
|
|
|
EXT_CLOCKED_TEMP,
|
2022-02-14 19:41:03 +01:00
|
|
|
START_INT_CLOCKED_CONVERSIONS,
|
|
|
|
READ_INT_CLOCKED_CONVERSIONS
|
|
|
|
};
|
2021-05-03 11:59:33 +02:00
|
|
|
|
2022-02-11 17:38:02 +01:00
|
|
|
PeriodicOperationDivider divider;
|
2022-02-14 17:13:06 +01:00
|
|
|
// LinuxLibgpioIF* gpioComIF = nullptr;
|
2022-02-14 19:41:03 +01:00
|
|
|
// gpioId_t chipSelectId = gpio::NO_GPIO;
|
2022-02-11 17:38:02 +01:00
|
|
|
bool goToNormalModeImmediately = false;
|
2022-02-14 17:13:06 +01:00
|
|
|
bool commandExecuted = false;
|
2021-05-07 18:48:42 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
SUS::SusDataset dataset;
|
2022-02-15 16:40:48 +01:00
|
|
|
// Read temperature in each alternating communication step when using
|
|
|
|
// externally clocked mode
|
2022-02-16 21:29:37 +01:00
|
|
|
ClkModes clkMode = ClkModes::INT_CLOCKED;
|
2021-05-03 11:59:33 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
uint8_t cmdBuffer[SUS::MAX_CMD_SIZE];
|
2022-02-14 17:13:06 +01:00
|
|
|
ComStates comState = ComStates::IDLE;
|
2021-05-12 13:06:56 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
|
|
|
uint32_t timeoutMs = 20;
|
2022-02-14 19:41:03 +01:00
|
|
|
void printDataset();
|
2021-05-12 13:06:56 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
MutexIF* spiMutex = nullptr;
|
2021-05-03 11:59:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MISSION_DEVICES_SUSHANDLER_H_ */
|