2021-09-26 22:22:55 +02:00
|
|
|
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
|
|
|
|
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
|
|
|
|
|
2024-11-04 17:32:21 +01:00
|
|
|
#include "mgmRm3100Helpers.h"
|
2023-02-26 21:26:24 +01:00
|
|
|
|
2021-09-26 22:22:55 +02:00
|
|
|
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
|
|
|
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device Handler for the RM3100 geomagnetic magnetometer sensor
|
|
|
|
* (https://www.pnicorp.com/rm3100/)
|
|
|
|
* @details
|
|
|
|
* Flight manual:
|
|
|
|
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/RM3100_MGM
|
|
|
|
*/
|
2022-02-02 10:29:30 +01:00
|
|
|
class MgmRM3100Handler : public DeviceHandlerBase {
|
|
|
|
public:
|
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_RM3100;
|
|
|
|
|
|
|
|
//! [EXPORT] : [COMMENT] P1: TMRC value which was set, P2: 0
|
|
|
|
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x00, severity::INFO);
|
|
|
|
|
|
|
|
//! [EXPORT] : [COMMENT] Cycle counter set. P1: First two bytes new Cycle Count X
|
|
|
|
//! P1: Second two bytes new Cycle Count Y
|
|
|
|
//! P2: New cycle count Z
|
|
|
|
static constexpr Event cycleCountersSet =
|
|
|
|
event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
|
|
|
|
|
|
|
|
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
|
|
|
uint32_t transitionDelay);
|
|
|
|
virtual ~MgmRM3100Handler();
|
|
|
|
|
2022-02-22 11:33:41 +01:00
|
|
|
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* Configure device handler to go to normal mode after startup immediately
|
|
|
|
* @param enable
|
|
|
|
*/
|
|
|
|
void setToGoToNormalMode(bool enable);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/* DeviceHandlerBase overrides */
|
|
|
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
|
|
|
void doStartUp() override;
|
|
|
|
void doShutDown() override;
|
|
|
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
|
|
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen) override;
|
|
|
|
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
|
|
|
size_t *foundLen) override;
|
|
|
|
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
|
|
|
|
|
|
|
void fillCommandAndReplyMap() override;
|
|
|
|
void modeChanged(void) override;
|
|
|
|
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) 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:
|
|
|
|
enum class InternalState {
|
|
|
|
NONE,
|
|
|
|
CONFIGURE_CMM,
|
|
|
|
READ_CMM,
|
|
|
|
// The cycle count states are propably not going to be used because
|
|
|
|
// the default cycle count will be used.
|
|
|
|
STATE_CONFIGURE_CYCLE_COUNT,
|
|
|
|
STATE_READ_CYCLE_COUNT,
|
|
|
|
STATE_CONFIGURE_TMRC,
|
|
|
|
STATE_READ_TMRC,
|
|
|
|
NORMAL
|
|
|
|
};
|
|
|
|
InternalState internalState = InternalState::NONE;
|
|
|
|
bool commandExecuted = false;
|
2023-02-26 21:26:24 +01:00
|
|
|
mgmRm3100::Rm3100PrimaryDataset primaryDataset;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
uint8_t commandBuffer[10];
|
|
|
|
uint8_t commandBufferLen = 0;
|
|
|
|
|
2023-02-26 21:26:24 +01:00
|
|
|
uint8_t cmmRegValue = mgmRm3100::CMM_VALUE;
|
|
|
|
uint8_t tmrcRegValue = mgmRm3100::TMRC_DEFAULT_VALUE;
|
|
|
|
uint16_t cycleCountRegValueX = mgmRm3100::CYCLE_COUNT_VALUE;
|
|
|
|
uint16_t cycleCountRegValueY = mgmRm3100::CYCLE_COUNT_VALUE;
|
|
|
|
uint16_t cycleCountRegValueZ = mgmRm3100::CYCLE_COUNT_VALUE;
|
|
|
|
float scaleFactorX = 1.0 / mgmRm3100::DEFAULT_GAIN;
|
|
|
|
float scaleFactorY = 1.0 / mgmRm3100::DEFAULT_GAIN;
|
|
|
|
float scaleFactorZ = 1.0 / mgmRm3100::DEFAULT_GAIN;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
bool goToNormalModeAtStartup = false;
|
|
|
|
uint32_t transitionDelay;
|
2022-08-15 10:49:00 +02:00
|
|
|
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
|
|
|
const uint8_t *commandData, size_t commandDataLen);
|
|
|
|
ReturnValue_t handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen);
|
|
|
|
|
|
|
|
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen);
|
|
|
|
|
|
|
|
ReturnValue_t handleDataReadout(const uint8_t *packet);
|
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_DEVICEHANDLING_MGMRM3100HANDLER_H_ */
|