2020-09-30 22:14:44 +02:00
|
|
|
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
|
|
|
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
2020-09-30 21:49:00 +02:00
|
|
|
|
2020-10-01 02:06:39 +02:00
|
|
|
#include "devicedefinitions/MGMHandlerLIS3Definitions.h"
|
2020-12-03 12:49:14 +01:00
|
|
|
|
2020-12-14 22:21:47 +01:00
|
|
|
#include <OBSWConfig.h>
|
|
|
|
#include <events/subsystemIdRanges.h>
|
2020-12-03 12:49:14 +01:00
|
|
|
|
|
|
|
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
|
|
|
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
|
|
|
|
2020-09-30 21:49:00 +02:00
|
|
|
/**
|
|
|
|
* @brief Device handler object for the LIS3MDL 3-axis magnetometer
|
|
|
|
* by STMicroeletronics
|
|
|
|
* @details
|
|
|
|
* Datasheet can be found online by googling LIS3MDL.
|
|
|
|
* @author L. Loidold, R. Mueller
|
|
|
|
*/
|
|
|
|
class MGMHandlerLIS3MDL: public DeviceHandlerBase {
|
|
|
|
public:
|
2020-12-14 22:21:47 +01:00
|
|
|
enum class CommunicationStep {
|
|
|
|
DATA,
|
|
|
|
TEMPERATURE
|
|
|
|
};
|
2020-12-03 12:49:14 +01:00
|
|
|
|
2020-09-30 21:49:00 +02:00
|
|
|
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
|
2020-12-14 22:03:57 +01:00
|
|
|
static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW);
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
MGMHandlerLIS3MDL(uint32_t objectId, object_id_t deviceCommunication,
|
2020-12-14 22:21:47 +01:00
|
|
|
CookieIF* comCookie);
|
2020-09-30 21:49:00 +02:00
|
|
|
virtual ~MGMHandlerLIS3MDL();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/** DeviceHandlerBase overrides */
|
2020-12-22 00:24:19 +01:00
|
|
|
void doShutDown() override;
|
|
|
|
void doStartUp() override;
|
|
|
|
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
|
|
|
uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
|
|
|
ReturnValue_t buildCommandFromCommand(
|
2020-09-30 21:49:00 +02:00
|
|
|
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
2020-09-30 22:00:37 +02:00
|
|
|
size_t commandDataLen) override;
|
2020-12-22 00:24:19 +01:00
|
|
|
ReturnValue_t buildTransitionDeviceCommand(
|
2020-12-14 22:21:47 +01:00
|
|
|
DeviceCommandId_t *id) override;
|
2020-12-22 13:32:40 +01:00
|
|
|
ReturnValue_t buildNormalDeviceCommand(
|
2020-12-14 22:21:47 +01:00
|
|
|
DeviceCommandId_t *id) override;
|
2020-12-22 00:24:19 +01:00
|
|
|
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
2020-12-14 22:21:47 +01:00
|
|
|
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
2020-12-22 00:24:19 +01:00
|
|
|
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
2020-09-30 22:00:37 +02:00
|
|
|
const uint8_t *packet) override;
|
2020-12-22 00:24:19 +01:00
|
|
|
void fillCommandAndReplyMap() override;
|
|
|
|
void modeChanged(void) override;
|
2021-01-14 11:37:32 +01:00
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
2020-12-14 22:21:47 +01:00
|
|
|
LocalDataPoolManager &poolManager) override;
|
2020-12-03 12:49:14 +01:00
|
|
|
|
2020-09-30 21:49:00 +02:00
|
|
|
private:
|
2020-12-14 22:50:15 +01:00
|
|
|
MGMLIS3MDL::MgmPrimaryDataset dataset;
|
2020-12-03 12:49:14 +01:00
|
|
|
|
2020-09-30 21:49:00 +02:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/* Device specific commands and variables */
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* Sets the read bit for the command
|
|
|
|
* @param single command to set the read-bit at
|
|
|
|
* @param boolean to select a continuous read bit, default = false
|
|
|
|
*/
|
|
|
|
uint8_t readCommand(uint8_t command, bool continuousCom = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the write bit for the command
|
|
|
|
* @param single command to set the write-bit at
|
|
|
|
* @param boolean to select a continuous write bit, default = false
|
|
|
|
*/
|
|
|
|
uint8_t writeCommand(uint8_t command, bool continuousCom = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Method gets the full scale for the measurement range
|
2020-10-01 02:06:39 +02:00
|
|
|
* e.g.: +- 4 gauss. See p.25 datasheet.
|
2020-09-30 21:49:00 +02:00
|
|
|
* @return The ReturnValue does not contain the sign of the value
|
|
|
|
*/
|
2020-12-03 12:49:14 +01:00
|
|
|
uint8_t getFullScale(uint8_t ctrlReg2);
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
/**
|
2020-10-01 02:06:39 +02:00
|
|
|
* The 16 bit value needs to be divided by the full range of a 16bit value
|
|
|
|
* and then multiplied with the current scale of the MGM.
|
|
|
|
* This factor returns the factor required to achieve this with
|
|
|
|
* one multiplication.
|
2020-09-30 21:49:00 +02:00
|
|
|
*
|
|
|
|
* @param scale is the return value of the getFulscale Method
|
2020-10-01 02:06:39 +02:00
|
|
|
* @return Multiplication factor to get the sensor value from raw data.
|
2020-09-30 21:49:00 +02:00
|
|
|
*/
|
2020-10-01 02:06:39 +02:00
|
|
|
float getSensitivityFactor(uint8_t scale);
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This Command detects the device ID
|
|
|
|
*/
|
|
|
|
ReturnValue_t identifyDevice();
|
|
|
|
|
2020-12-03 12:49:14 +01:00
|
|
|
virtual void setupMgm();
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
/* 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);
|
|
|
|
|
2020-10-01 02:06:39 +02:00
|
|
|
|
2020-09-30 22:00:37 +02:00
|
|
|
//Length a sindgle command SPI answer
|
|
|
|
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
//Single SPIcommand 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
|
2020-12-03 12:49:14 +01:00
|
|
|
uint8_t commandBuffer[MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1];
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-30 22:00:37 +02:00
|
|
|
* We want to save the registers we set, so we dont have to read the
|
|
|
|
* registers when we want to change something.
|
2020-09-30 21:49:00 +02:00
|
|
|
* --> everytime we change set a register we have to save it
|
|
|
|
*/
|
2020-10-01 02:06:39 +02:00
|
|
|
uint8_t registers[MGMLIS3MDL::NR_OF_CTRL_REGISTERS];
|
2020-09-30 21:49:00 +02:00
|
|
|
|
2020-12-03 12:49:14 +01:00
|
|
|
uint8_t statusRegister = 0;
|
|
|
|
|
2020-09-30 21:49:00 +02:00
|
|
|
/**
|
|
|
|
* We always update all registers together, so this method updates
|
|
|
|
* the rawpacket and rawpacketLen, so we just manipulate the local
|
|
|
|
* saved register
|
|
|
|
*
|
|
|
|
*/
|
2020-10-30 13:02:31 +01:00
|
|
|
ReturnValue_t prepareCtrlRegisterWrite();
|
2020-09-30 21:49:00 +02:00
|
|
|
|
2020-12-23 20:17:39 +01:00
|
|
|
enum class InternalState {
|
|
|
|
STATE_NONE,
|
|
|
|
STATE_FIRST_CONTACT,
|
|
|
|
STATE_SETUP,
|
|
|
|
STATE_CHECK_REGISTERS,
|
|
|
|
STATE_NORMAL
|
2020-09-30 21:49:00 +02:00
|
|
|
};
|
|
|
|
|
2020-12-23 20:17:39 +01:00
|
|
|
InternalState internalState = InternalState::STATE_NONE;
|
2020-12-03 12:49:14 +01:00
|
|
|
CommunicationStep communicationStep = CommunicationStep::DATA;
|
|
|
|
bool commandExecuted = false;
|
|
|
|
|
2021-02-14 13:07:05 +01:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
2020-12-14 22:21:47 +01:00
|
|
|
PeriodicOperationDivider* debugDivider;
|
2020-12-03 12:49:14 +01:00
|
|
|
#endif
|
2020-09-30 21:49:00 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-09-30 22:14:44 +02:00
|
|
|
#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */
|