2021-09-26 22:22:55 +02:00
|
|
|
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
|
|
|
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
|
|
|
|
2024-11-04 17:32:21 +01:00
|
|
|
#include "mgmLis3Helpers.h"
|
2023-02-26 21:26:24 +01:00
|
|
|
|
2021-09-26 22:22:55 +02:00
|
|
|
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
2022-02-22 11:33:41 +01:00
|
|
|
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
2021-09-26 22:22:55 +02:00
|
|
|
|
|
|
|
class PeriodicOperationDivider;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device handler object for the LIS3MDL 3-axis magnetometer
|
|
|
|
* by STMicroeletronics
|
|
|
|
* @details
|
|
|
|
* Datasheet can be found online by googling LIS3MDL.
|
|
|
|
* Flight manual:
|
|
|
|
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/LIS3MDL_MGM
|
|
|
|
* @author L. Loidold, R. Mueller
|
|
|
|
*/
|
2022-02-02 10:29:30 +01:00
|
|
|
class MgmLIS3MDLHandler : public DeviceHandlerBase {
|
|
|
|
public:
|
|
|
|
enum class CommunicationStep { DATA, TEMPERATURE };
|
|
|
|
|
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL;
|
|
|
|
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL;
|
|
|
|
// Notifies a command to change the setup parameters
|
|
|
|
static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW);
|
|
|
|
|
|
|
|
MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
|
|
|
uint32_t transitionDelay);
|
|
|
|
virtual ~MgmLIS3MDLHandler();
|
|
|
|
|
2022-02-22 11:33:41 +01:00
|
|
|
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* Set the absolute limit for the values on the axis in microtesla. The dataset values will
|
|
|
|
* be marked as invalid if that limit is exceeded
|
|
|
|
* @param xLimit
|
|
|
|
* @param yLimit
|
|
|
|
* @param zLimit
|
|
|
|
*/
|
|
|
|
void setAbsoluteLimits(float xLimit, float yLimit, float zLimit);
|
|
|
|
void setToGoToNormalMode(bool enable);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** DeviceHandlerBase overrides */
|
|
|
|
void doShutDown() override;
|
|
|
|
void doStartUp() override;
|
|
|
|
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
|
|
|
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
|
|
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen) override;
|
|
|
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
|
|
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
|
|
|
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
|
|
|
size_t *foundLen) override;
|
|
|
|
/**
|
|
|
|
* This implementation is tailored towards space applications and will flag values larger
|
|
|
|
* than 100 microtesla on X,Y and 150 microtesla on Z as invalid
|
|
|
|
* @param id
|
|
|
|
* @param packet
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
|
|
|
void fillCommandAndReplyMap() override;
|
|
|
|
void modeChanged(void) override;
|
2024-11-04 17:32:21 +01:00
|
|
|
// ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
|
|
|
// PeriodicHkGenerationHelper &poolManager) override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
private:
|
2023-02-26 21:26:24 +01:00
|
|
|
mgmLis3::MgmPrimaryDataset dataset;
|
2022-02-02 10:29:30 +01:00
|
|
|
// Length a single command SPI answer
|
|
|
|
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
|
|
|
|
|
|
|
|
uint32_t transitionDelay;
|
|
|
|
// Single SPI command has 2 bytes, first for adress, second for content
|
|
|
|
size_t singleComandSize = 2;
|
|
|
|
// Has the size for all adresses of the lis3mdl + the continous write bit
|
2023-02-26 21:26:24 +01:00
|
|
|
uint8_t commandBuffer[mgmLis3::NR_OF_DATA_AND_CFG_REGISTERS + 1];
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
float absLimitX = 100;
|
|
|
|
float absLimitY = 100;
|
|
|
|
float absLimitZ = 150;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We want to save the registers we set, so we dont have to read the
|
|
|
|
* registers when we want to change something.
|
|
|
|
* --> everytime we change set a register we have to save it
|
|
|
|
*/
|
2023-02-26 21:26:24 +01:00
|
|
|
uint8_t registers[mgmLis3::NR_OF_CTRL_REGISTERS];
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
uint8_t statusRegister = 0;
|
|
|
|
bool goToNormalMode = false;
|
|
|
|
|
|
|
|
enum class InternalState {
|
|
|
|
STATE_NONE,
|
|
|
|
STATE_FIRST_CONTACT,
|
|
|
|
STATE_SETUP,
|
|
|
|
STATE_CHECK_REGISTERS,
|
|
|
|
STATE_NORMAL
|
|
|
|
};
|
|
|
|
|
|
|
|
InternalState internalState = InternalState::STATE_NONE;
|
|
|
|
CommunicationStep communicationStep = CommunicationStep::DATA;
|
|
|
|
bool commandExecuted = false;
|
|
|
|
|
2022-08-15 10:49:00 +02:00
|
|
|
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
|
|
|
|
PoolEntry<float> temperature = PoolEntry<float>();
|
2022-02-02 10:29:30 +01:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/* Device specific commands and variables */
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Command detects the device ID
|
|
|
|
*/
|
|
|
|
ReturnValue_t identifyDevice();
|
|
|
|
|
|
|
|
virtual void setupMgm();
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/* Non normal commands */
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* Enables/Disables the integrated Temperaturesensor
|
|
|
|
* @param commandData On or Off
|
|
|
|
* @param length of the commandData: has to be 1
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData, size_t commandDataLen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the accuracy of the measurement of the axis. The noise is changing.
|
|
|
|
* @param commandData LOW, MEDIUM, HIGH, ULTRA
|
|
|
|
* @param length of the command, has to be 1
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData, size_t commandDataLen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We always update all registers together, so this method updates
|
|
|
|
* the rawpacket and rawpacketLen, so we just manipulate the local
|
|
|
|
* saved register
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ReturnValue_t prepareCtrlRegisterWrite();
|
2021-09-26 22:22:55 +02:00
|
|
|
|
2022-02-22 11:33:41 +01:00
|
|
|
bool periodicPrintout = false;
|
|
|
|
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
2021-09-26 22:22:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */
|