Update and clean up HK and Local Pool Modules
This commit is contained in:
281
misc/archive/GyroL3GD20Handler.cpp
Normal file
281
misc/archive/GyroL3GD20Handler.cpp
Normal file
@ -0,0 +1,281 @@
|
||||
#include "GyroL3GD20Handler.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
||||
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, uint32_t transitionDelayMs)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
transitionDelayMs(transitionDelayMs),
|
||||
sharedPool(DeviceHandlerBase::getObjectId()),
|
||||
dataset(sharedPool) {}
|
||||
|
||||
GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
|
||||
|
||||
void GyroHandlerL3GD20H::doStartUp() {
|
||||
if (internalState == InternalState::NONE) {
|
||||
internalState = InternalState::CONFIGURE;
|
||||
}
|
||||
|
||||
if (internalState == InternalState::CONFIGURE) {
|
||||
if (commandExecuted) {
|
||||
internalState = InternalState::CHECK_REGS;
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (internalState == InternalState::CHECK_REGS) {
|
||||
if (commandExecuted) {
|
||||
internalState = InternalState::NORMAL;
|
||||
if (goNormalModeImmediately) {
|
||||
setMode(MODE_NORMAL);
|
||||
} else {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
switch (internalState) {
|
||||
case (InternalState::NONE):
|
||||
case (InternalState::NORMAL): {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
case (InternalState::CONFIGURE): {
|
||||
*id = l3gd20h::CONFIGURE_CTRL_REGS;
|
||||
uint8_t command[5];
|
||||
command[0] = l3gd20h::CTRL_REG_1_VAL;
|
||||
command[1] = l3gd20h::CTRL_REG_2_VAL;
|
||||
command[2] = l3gd20h::CTRL_REG_3_VAL;
|
||||
command[3] = l3gd20h::CTRL_REG_4_VAL;
|
||||
command[4] = l3gd20h::CTRL_REG_5_VAL;
|
||||
return buildCommandFromCommand(*id, command, 5);
|
||||
}
|
||||
case (InternalState::CHECK_REGS): {
|
||||
*id = l3gd20h::READ_REGS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
default:
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
/* Might be a configuration error. */
|
||||
sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printDebug(
|
||||
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state!\n");
|
||||
#endif
|
||||
return returnvalue::OK;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
*id = l3gd20h::READ_REGS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (l3gd20h::READ_REGS): {
|
||||
commandBuffer[0] = l3gd20h::READ_START | l3gd20h::AUTO_INCREMENT_MASK | l3gd20h::READ_MASK;
|
||||
std::memset(commandBuffer + 1, 0, l3gd20h::READ_LEN);
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = l3gd20h::READ_LEN + 1;
|
||||
break;
|
||||
}
|
||||
case (l3gd20h::CONFIGURE_CTRL_REGS): {
|
||||
commandBuffer[0] = l3gd20h::CTRL_REG_1 | l3gd20h::AUTO_INCREMENT_MASK;
|
||||
if (commandData == nullptr or commandDataLen != 5) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
ctrlReg1Value = commandData[0];
|
||||
ctrlReg2Value = commandData[1];
|
||||
ctrlReg3Value = commandData[2];
|
||||
ctrlReg4Value = commandData[3];
|
||||
ctrlReg5Value = commandData[4];
|
||||
|
||||
bool fsH = ctrlReg4Value & l3gd20h::SET_FS_1;
|
||||
bool fsL = ctrlReg4Value & l3gd20h::SET_FS_0;
|
||||
|
||||
if (not fsH and not fsL) {
|
||||
sensitivity = l3gd20h::SENSITIVITY_00;
|
||||
} else if (not fsH and fsL) {
|
||||
sensitivity = l3gd20h::SENSITIVITY_01;
|
||||
} else {
|
||||
sensitivity = l3gd20h::SENSITIVITY_11;
|
||||
}
|
||||
|
||||
commandBuffer[1] = ctrlReg1Value;
|
||||
commandBuffer[2] = ctrlReg2Value;
|
||||
commandBuffer[3] = ctrlReg3Value;
|
||||
commandBuffer[4] = ctrlReg4Value;
|
||||
commandBuffer[5] = ctrlReg5Value;
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 6;
|
||||
break;
|
||||
}
|
||||
case (l3gd20h::READ_CTRL_REGS): {
|
||||
commandBuffer[0] = l3gd20h::READ_START | l3gd20h::AUTO_INCREMENT_MASK | l3gd20h::READ_MASK;
|
||||
|
||||
std::memset(commandBuffer + 1, 0, 5);
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 6;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
// For SPI, the ID will always be the one of the last sent command
|
||||
*foundId = this->getPendingCommand();
|
||||
*foundLen = this->rawPacketLen;
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
switch (id) {
|
||||
case (l3gd20h::CONFIGURE_CTRL_REGS): {
|
||||
commandExecuted = true;
|
||||
break;
|
||||
}
|
||||
case (l3gd20h::READ_CTRL_REGS): {
|
||||
if (packet[1] == ctrlReg1Value and packet[2] == ctrlReg2Value and
|
||||
packet[3] == ctrlReg3Value and packet[4] == ctrlReg4Value and
|
||||
packet[5] == ctrlReg5Value) {
|
||||
commandExecuted = true;
|
||||
} else {
|
||||
// Attempt reconfiguration
|
||||
internalState = InternalState::CONFIGURE;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (l3gd20h::READ_REGS): {
|
||||
if (packet[1] != ctrlReg1Value and packet[2] != ctrlReg2Value and
|
||||
packet[3] != ctrlReg3Value and packet[4] != ctrlReg4Value and
|
||||
packet[5] != ctrlReg5Value) {
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
} else {
|
||||
if (internalState == InternalState::CHECK_REGS) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
}
|
||||
|
||||
statusReg = packet[l3gd20h::STATUS_IDX];
|
||||
|
||||
int16_t angVelocXRaw = packet[l3gd20h::OUT_X_H] << 8 | packet[l3gd20h::OUT_X_L];
|
||||
int16_t angVelocYRaw = packet[l3gd20h::OUT_Y_H] << 8 | packet[l3gd20h::OUT_Y_L];
|
||||
int16_t angVelocZRaw = packet[l3gd20h::OUT_Z_H] << 8 | packet[l3gd20h::OUT_Z_L];
|
||||
float angVelocX = angVelocXRaw * sensitivity;
|
||||
float angVelocY = angVelocYRaw * sensitivity;
|
||||
float angVelocZ = angVelocZRaw * sensitivity;
|
||||
|
||||
int8_t temperaturOffset = (-1) * packet[l3gd20h::TEMPERATURE_IDX];
|
||||
float temperature = 25.0 + temperaturOffset;
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.checkAndIncrement()) {
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl;
|
||||
sif::info << "X: " << angVelocX << std::endl;
|
||||
sif::info << "Y: " << angVelocY << std::endl;
|
||||
sif::info << "Z: " << angVelocZ << std::endl;
|
||||
#else
|
||||
sif::printInfo("GyroHandlerL3GD20H: Angular velocities (deg/s):\n");
|
||||
sif::printInfo("X: %f\n", angVelocX);
|
||||
sif::printInfo("Y: %f\n", angVelocY);
|
||||
sif::printInfo("Z: %f\n", angVelocZ);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
PoolReadGuard readSet(&dataset);
|
||||
if (readSet.getReadResult() == returnvalue::OK) {
|
||||
if (std::abs(angVelocX) < this->absLimitX) {
|
||||
dataset.angVelocX = angVelocX;
|
||||
// dataset.angVelocX.setValid(true);
|
||||
} else {
|
||||
// dataset.angVelocX.setValid(false);
|
||||
}
|
||||
|
||||
if (std::abs(angVelocY) < this->absLimitY) {
|
||||
dataset.angVelocY = angVelocY;
|
||||
// dataset.angVelocY.setValid(true);
|
||||
} else {
|
||||
// dataset.angVelocY.setValid(false);
|
||||
}
|
||||
|
||||
if (std::abs(angVelocZ) < this->absLimitZ) {
|
||||
dataset.angVelocZ = angVelocZ;
|
||||
// dataset.angVelocZ.setValid(true);
|
||||
} else {
|
||||
// dataset.angVelocZ.setValid(false);
|
||||
}
|
||||
|
||||
dataset.temperature = temperature;
|
||||
// dataset.temperature.setValid(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return this->transitionDelayMs;
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) { this->goNormalModeImmediately = true; }
|
||||
|
||||
// TODO
|
||||
/*
|
||||
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
PeriodicHkGenerationHelper &hkGenHelper) {
|
||||
localDataPoolMap.emplace(l3gd20h::ANG_VELOC_X, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(l3gd20h::ANG_VELOC_Y, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(l3gd20h::ANG_VELOC_Z, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(l3gd20h::TEMPERATURE, new PoolEntry<float>({0.0}));
|
||||
hkGenHelper.enableRegularPeriodicPacket(
|
||||
subdp::RegularHkPeriodicParams(dataset.getSid(), false, 10.0));
|
||||
return returnvalue::OK;
|
||||
}
|
||||
*/
|
||||
|
||||
void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(l3gd20h::READ_REGS, 1, &dataset);
|
||||
insertInCommandAndReplyMap(l3gd20h::CONFIGURE_CTRL_REGS, 1);
|
||||
insertInCommandAndReplyMap(l3gd20h::READ_CTRL_REGS, 1);
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::modeChanged() { internalState = InternalState::NONE; }
|
||||
|
||||
void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) {
|
||||
this->absLimitX = limitX;
|
||||
this->absLimitY = limitY;
|
||||
this->absLimitZ = limitZ;
|
||||
}
|
||||
|
||||
void GyroHandlerL3GD20H::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
||||
periodicPrintout = enable;
|
||||
debugDivider.setDivider(divider);
|
||||
}
|
88
misc/archive/GyroL3GD20Handler.h
Normal file
88
misc/archive/GyroL3GD20Handler.h
Normal file
@ -0,0 +1,88 @@
|
||||
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#include "gyroL3gHelpers.h"
|
||||
|
||||
/**
|
||||
* @brief Device Handler for the L3GD20H gyroscope sensor
|
||||
* (https://www.st.com/en/mems-and-sensors/l3gd20h.html)
|
||||
* @details
|
||||
* Advanced documentation:
|
||||
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/L3GD20H_Gyro
|
||||
*
|
||||
* Data is read big endian with the smallest possible range of 245 degrees per second.
|
||||
*/
|
||||
class GyroHandlerL3GD20H : public DeviceHandlerBase {
|
||||
public:
|
||||
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||
uint32_t transitionDelayMs);
|
||||
virtual ~GyroHandlerL3GD20H();
|
||||
|
||||
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
||||
|
||||
/**
|
||||
* Set the absolute limit for the values on the axis in degrees per second.
|
||||
* The dataset values will be marked as invalid if that limit is exceeded
|
||||
* @param xLimit
|
||||
* @param yLimit
|
||||
* @param zLimit
|
||||
*/
|
||||
void setAbsoluteLimits(float limitX, float limitY, float limitZ);
|
||||
|
||||
/**
|
||||
* @brief Configure device handler to go to normal mode immediately
|
||||
*/
|
||||
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;
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||
|
||||
void fillCommandAndReplyMap() override;
|
||||
void modeChanged() override;
|
||||
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
||||
// ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
// PeriodicHkGenerationHelper &hkGenHelper) override;
|
||||
|
||||
private:
|
||||
uint32_t transitionDelayMs = 0;
|
||||
localpool::SharedPool sharedPool;
|
||||
GyroPrimaryDataset dataset;
|
||||
|
||||
float absLimitX = l3gd20h::RANGE_DPS_00;
|
||||
float absLimitY = l3gd20h::RANGE_DPS_00;
|
||||
float absLimitZ = l3gd20h::RANGE_DPS_00;
|
||||
|
||||
enum class InternalState { NONE, CONFIGURE, CHECK_REGS, NORMAL };
|
||||
InternalState internalState = InternalState::NONE;
|
||||
bool commandExecuted = false;
|
||||
|
||||
uint8_t statusReg = 0;
|
||||
bool goNormalModeImmediately = false;
|
||||
|
||||
uint8_t ctrlReg1Value = l3gd20h::CTRL_REG_1_VAL;
|
||||
uint8_t ctrlReg2Value = l3gd20h::CTRL_REG_2_VAL;
|
||||
uint8_t ctrlReg3Value = l3gd20h::CTRL_REG_3_VAL;
|
||||
uint8_t ctrlReg4Value = l3gd20h::CTRL_REG_4_VAL;
|
||||
uint8_t ctrlReg5Value = l3gd20h::CTRL_REG_5_VAL;
|
||||
|
||||
uint8_t commandBuffer[l3gd20h::READ_LEN + 1];
|
||||
|
||||
// Set default value
|
||||
float sensitivity = l3gd20h::SENSITIVITY_00;
|
||||
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */
|
13
misc/archive/HasLocalDpIFManagerAttorney.cpp
Normal file
13
misc/archive/HasLocalDpIFManagerAttorney.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "HasLocalDpIFManagerAttorney.h"
|
||||
|
||||
#include "fsfw/datapool/LocalPoolObjectBase.h"
|
||||
#include "fsfw/housekeeping/GeneratesPeriodicHkIF.h"
|
||||
|
||||
LocalPoolObjectBase* HasLocalDpIFManagerAttorney::getPoolObjectHandle(
|
||||
PeriodicHkGenerationIF* clientIF, dp::lp_id_t localPoolId) {
|
||||
return clientIF->getPoolObjectHandle(localPoolId);
|
||||
}
|
||||
|
||||
object_id_t HasLocalDpIFManagerAttorney::getObjectId(PeriodicHkGenerationIF* clientIF) {
|
||||
return clientIF->getObjectId();
|
||||
}
|
17
misc/archive/HasLocalDpIFManagerAttorney.h
Normal file
17
misc/archive/HasLocalDpIFManagerAttorney.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <fsfw/housekeeping/PeriodicHkHelper.h>
|
||||
|
||||
#include "fsfw/datapool/definitions.h"
|
||||
|
||||
class PeriodicHkGenerationIF;
|
||||
class LocalPoolDataSetBase;
|
||||
class LocalPoolObjectBase;
|
||||
|
||||
class HasLocalDpIFManagerAttorney {
|
||||
static LocalPoolObjectBase* getPoolObjectHandle(PeriodicHkGenerationIF* clientIF,
|
||||
dp::id_t localPoolId);
|
||||
|
||||
static object_id_t getObjectId(PeriodicHkGenerationIF* clientIF);
|
||||
|
||||
friend class hk::PeriodicHelper;
|
||||
};
|
1
misc/archive/HasLocalDpIFUserAttorney.cpp
Normal file
1
misc/archive/HasLocalDpIFUserAttorney.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "HasLocalDpIFUserAttorney.h"
|
15
misc/archive/HasLocalDpIFUserAttorney.h
Normal file
15
misc/archive/HasLocalDpIFUserAttorney.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_HASLOCALDPIFUSERATTORNEY_H_
|
||||
#define FSFW_DATAPOOLLOCAL_HASLOCALDPIFUSERATTORNEY_H_
|
||||
|
||||
class PeriodicHkGenerationIF;
|
||||
class AccessPoolManagerIF;
|
||||
|
||||
class HasLocalDpIFUserAttorney {
|
||||
private:
|
||||
// static AccessPoolManagerIF* getAccessorHandle(PeriodicHkGenerationIF* clientIF);
|
||||
|
||||
friend class LocalPoolObjectBase;
|
||||
friend class LocalPoolDataSetBase;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDPIFUSERATTORNEY_H_ */
|
437
misc/archive/MgmLIS3MDLHandler.cpp
Normal file
437
misc/archive/MgmLIS3MDLHandler.cpp
Normal file
@ -0,0 +1,437 @@
|
||||
#include "MgmLIS3MDLHandler.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
||||
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, uint32_t transitionDelay)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
dataset(this),
|
||||
transitionDelay(transitionDelay) {
|
||||
// Set to default values right away
|
||||
registers[0] = mgmLis3::CTRL_REG1_DEFAULT;
|
||||
registers[1] = mgmLis3::CTRL_REG2_DEFAULT;
|
||||
registers[2] = mgmLis3::CTRL_REG3_DEFAULT;
|
||||
registers[3] = mgmLis3::CTRL_REG4_DEFAULT;
|
||||
registers[4] = mgmLis3::CTRL_REG5_DEFAULT;
|
||||
}
|
||||
|
||||
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {}
|
||||
|
||||
void MgmLIS3MDLHandler::doStartUp() {
|
||||
switch (internalState) {
|
||||
case (InternalState::STATE_NONE): {
|
||||
internalState = InternalState::STATE_FIRST_CONTACT;
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_FIRST_CONTACT): {
|
||||
/* Will be set by checking device ID (WHO AM I register) */
|
||||
if (commandExecuted) {
|
||||
commandExecuted = false;
|
||||
internalState = InternalState::STATE_SETUP;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_SETUP): {
|
||||
internalState = InternalState::STATE_CHECK_REGISTERS;
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_CHECK_REGISTERS): {
|
||||
/* Set up cached registers which will be used to configure the MGM. */
|
||||
if (commandExecuted) {
|
||||
commandExecuted = false;
|
||||
if (goToNormalMode) {
|
||||
setMode(MODE_NORMAL);
|
||||
} else {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
switch (internalState) {
|
||||
case (InternalState::STATE_NONE):
|
||||
case (InternalState::STATE_NORMAL): {
|
||||
return DeviceHandlerBase::NOTHING_TO_SEND;
|
||||
}
|
||||
case (InternalState::STATE_FIRST_CONTACT): {
|
||||
*id = mgmLis3::IDENTIFY_DEVICE;
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_SETUP): {
|
||||
*id = mgmLis3::SETUP_MGM;
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_CHECK_REGISTERS): {
|
||||
*id = mgmLis3::READ_CONFIG_AND_DATA;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
/* might be a configuration error. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
return returnvalue::OK;
|
||||
}
|
||||
}
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::setupMgm() {
|
||||
registers[0] = mgmLis3::CTRL_REG1_DEFAULT;
|
||||
registers[1] = mgmLis3::CTRL_REG2_DEFAULT;
|
||||
registers[2] = mgmLis3::CTRL_REG3_DEFAULT;
|
||||
registers[3] = mgmLis3::CTRL_REG4_DEFAULT;
|
||||
registers[4] = mgmLis3::CTRL_REG5_DEFAULT;
|
||||
|
||||
prepareCtrlRegisterWrite();
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
// Data/config register will be read in an alternating manner.
|
||||
if (communicationStep == CommunicationStep::DATA) {
|
||||
*id = mgmLis3::READ_CONFIG_AND_DATA;
|
||||
communicationStep = CommunicationStep::TEMPERATURE;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
} else {
|
||||
*id = mgmLis3::READ_TEMPERATURE;
|
||||
communicationStep = CommunicationStep::DATA;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (mgmLis3::READ_CONFIG_AND_DATA): {
|
||||
std::memset(commandBuffer, 0, sizeof(commandBuffer));
|
||||
commandBuffer[0] = mgmLis3::readCommand(mgmLis3::CTRL_REG1, true);
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = mgmLis3::NR_OF_DATA_AND_CFG_REGISTERS + 1;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (mgmLis3::READ_TEMPERATURE): {
|
||||
std::memset(commandBuffer, 0, 3);
|
||||
commandBuffer[0] = mgmLis3::readCommand(mgmLis3::TEMP_LOWBYTE, true);
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 3;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (mgmLis3::IDENTIFY_DEVICE): {
|
||||
return identifyDevice();
|
||||
}
|
||||
case (mgmLis3::TEMP_SENSOR_ENABLE): {
|
||||
return enableTemperatureSensor(commandData, commandDataLen);
|
||||
}
|
||||
case (mgmLis3::SETUP_MGM): {
|
||||
setupMgm();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (mgmLis3::ACCURACY_OP_MODE_SET): {
|
||||
return setOperatingMode(commandData, commandDataLen);
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
|
||||
uint32_t size = 2;
|
||||
commandBuffer[0] = mgmLis3::readCommand(mgmLis3::IDENTIFY_DEVICE_REG_ADDR);
|
||||
commandBuffer[1] = 0x00;
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = size;
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
*foundLen = len;
|
||||
if (len == mgmLis3::NR_OF_DATA_AND_CFG_REGISTERS + 1) {
|
||||
*foundLen = len;
|
||||
*foundId = mgmLis3::READ_CONFIG_AND_DATA;
|
||||
// Check validity by checking config registers
|
||||
if (start[1] != registers[0] or start[2] != registers[1] or start[3] != registers[2] or
|
||||
start[4] != registers[3] or start[5] != registers[4]) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("MGMHandlerLIS3MDL::scanForReply: Invalid registers!\n");
|
||||
#endif
|
||||
#endif
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
if (getMode() == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
|
||||
} else if (len == mgmLis3::TEMPERATURE_REPLY_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = mgmLis3::READ_TEMPERATURE;
|
||||
} else if (len == mgmLis3::SETUP_REPLY_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = mgmLis3::SETUP_MGM;
|
||||
} else if (len == SINGLE_COMMAND_ANSWER_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = getPendingCommand();
|
||||
if (*foundId == mgmLis3::IDENTIFY_DEVICE) {
|
||||
if (start[1] != mgmLis3::DEVICE_ID) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: "
|
||||
"Device identification failed!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning(
|
||||
"MGMHandlerLIS3MDL::scanForReply: "
|
||||
"Device identification failed!\n");
|
||||
#endif
|
||||
#endif
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
if (getMode() == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
/* Data with SPI Interface always has this answer */
|
||||
if (start[0] == 0b11111111) {
|
||||
return returnvalue::OK;
|
||||
} else {
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
}
|
||||
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case mgmLis3::IDENTIFY_DEVICE: {
|
||||
break;
|
||||
}
|
||||
case mgmLis3::SETUP_MGM: {
|
||||
break;
|
||||
}
|
||||
case mgmLis3::READ_CONFIG_AND_DATA: {
|
||||
using namespace mgmLis3;
|
||||
// TODO: Store configuration in new local datasets.
|
||||
float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2]));
|
||||
|
||||
int16_t mgmMeasurementRawX =
|
||||
packet[mgmLis3::X_HIGHBYTE_IDX] << 8 | packet[mgmLis3::X_LOWBYTE_IDX];
|
||||
int16_t mgmMeasurementRawY =
|
||||
packet[mgmLis3::Y_HIGHBYTE_IDX] << 8 | packet[mgmLis3::Y_LOWBYTE_IDX];
|
||||
int16_t mgmMeasurementRawZ =
|
||||
packet[mgmLis3::Z_HIGHBYTE_IDX] << 8 | packet[mgmLis3::Z_LOWBYTE_IDX];
|
||||
|
||||
// Target value in microtesla
|
||||
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor *
|
||||
mgmLis3::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor *
|
||||
mgmLis3::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor *
|
||||
mgmLis3::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.checkAndIncrement()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MGMHandlerLIS3: Magnetic field strength in"
|
||||
" microtesla:"
|
||||
<< std::endl;
|
||||
sif::info << "X: " << mgmX << " uT" << std::endl;
|
||||
sif::info << "Y: " << mgmY << " uT" << std::endl;
|
||||
sif::info << "Z: " << mgmZ << " uT" << std::endl;
|
||||
#else
|
||||
sif::printInfo("MGMHandlerLIS3: Magnetic field strength in microtesla:\n");
|
||||
sif::printInfo("X: %f uT\n", mgmX);
|
||||
sif::printInfo("Y: %f uT\n", mgmY);
|
||||
sif::printInfo("Z: %f uT\n", mgmZ);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
|
||||
}
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if (readHelper.getReadResult() == returnvalue::OK) {
|
||||
if (std::abs(mgmX) > absLimitX or std::abs(mgmY) > absLimitY or
|
||||
std::abs(mgmZ) > absLimitZ) {
|
||||
dataset.setIsValid = false;
|
||||
}
|
||||
if (std::abs(mgmX) < absLimitX) {
|
||||
dataset.fieldStrengths[0] = mgmX;
|
||||
}
|
||||
|
||||
if (std::abs(mgmY) < absLimitY) {
|
||||
dataset.fieldStrengths[1] = mgmY;
|
||||
}
|
||||
|
||||
if (std::abs(mgmZ) < absLimitZ) {
|
||||
dataset.fieldStrengths[2] = mgmZ;
|
||||
}
|
||||
dataset.setIsValid = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case mgmLis3::READ_TEMPERATURE: {
|
||||
int16_t tempValueRaw = packet[2] << 8 | packet[1];
|
||||
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.check()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl;
|
||||
#else
|
||||
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t result = dataset.read();
|
||||
if (result == returnvalue::OK) {
|
||||
dataset.temperature = tempValue;
|
||||
dataset.commit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if (commandData == nullptr) {
|
||||
return INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
|
||||
uint32_t size = 2;
|
||||
commandBuffer[0] = mgmLis3::writeCommand(mgmLis3::CTRL_REG1);
|
||||
if (commandDataLen > 1) {
|
||||
return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
switch (commandData[0]) {
|
||||
case (mgmLis3::ON): {
|
||||
commandBuffer[1] = registers[0] | (1 << 7);
|
||||
break;
|
||||
}
|
||||
case (mgmLis3::OFF): {
|
||||
commandBuffer[1] = registers[0] & ~(1 << 7);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
registers[0] = commandBuffer[1];
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = size;
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::setOperatingMode(const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
|
||||
if (commandDataLen != 1) {
|
||||
return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
|
||||
switch (commandData[0]) {
|
||||
case mgmLis3::LOW:
|
||||
registers[0] = (registers[0] & (~(1 << mgmLis3::OM1))) & (~(1 << mgmLis3::OM0));
|
||||
registers[3] = (registers[3] & (~(1 << mgmLis3::OMZ1))) & (~(1 << mgmLis3::OMZ0));
|
||||
break;
|
||||
case mgmLis3::MEDIUM:
|
||||
registers[0] = (registers[0] & (~(1 << mgmLis3::OM1))) | (1 << mgmLis3::OM0);
|
||||
registers[3] = (registers[3] & (~(1 << mgmLis3::OMZ1))) | (1 << mgmLis3::OMZ0);
|
||||
break;
|
||||
|
||||
case mgmLis3::HIGH:
|
||||
registers[0] = (registers[0] | (1 << mgmLis3::OM1)) & (~(1 << mgmLis3::OM0));
|
||||
registers[3] = (registers[3] | (1 << mgmLis3::OMZ1)) & (~(1 << mgmLis3::OMZ0));
|
||||
break;
|
||||
|
||||
case mgmLis3::ULTRA:
|
||||
registers[0] = (registers[0] | (1 << mgmLis3::OM1)) | (1 << mgmLis3::OM0);
|
||||
registers[3] = (registers[3] | (1 << mgmLis3::OMZ1)) | (1 << mgmLis3::OMZ0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return prepareCtrlRegisterWrite();
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(mgmLis3::READ_CONFIG_AND_DATA, 1, &dataset);
|
||||
insertInCommandAndReplyMap(mgmLis3::READ_TEMPERATURE, 1);
|
||||
insertInCommandAndReplyMap(mgmLis3::SETUP_MGM, 1);
|
||||
insertInCommandAndReplyMap(mgmLis3::IDENTIFY_DEVICE, 1);
|
||||
insertInCommandAndReplyMap(mgmLis3::TEMP_SENSOR_ENABLE, 1);
|
||||
insertInCommandAndReplyMap(mgmLis3::ACCURACY_OP_MODE_SET, 1);
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) { this->goToNormalMode = enable; }
|
||||
|
||||
ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
|
||||
commandBuffer[0] = mgmLis3::writeCommand(mgmLis3::CTRL_REG1, true);
|
||||
|
||||
for (size_t i = 0; i < mgmLis3::NR_OF_CTRL_REGISTERS; i++) {
|
||||
commandBuffer[i + 1] = registers[i];
|
||||
}
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = mgmLis3::NR_OF_CTRL_REGISTERS + 1;
|
||||
|
||||
// We dont have to check if this is working because we just did i
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||
DeviceHandlerBase::doTransition(modeFrom, subModeFrom);
|
||||
}
|
||||
|
||||
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { return transitionDelay; }
|
||||
|
||||
void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE_NONE; }
|
||||
|
||||
/*
|
||||
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
PeriodicHkGenerationHelper &poolManager) {
|
||||
localDataPoolMap.emplace(mgmLis3::FIELD_STRENGTHS, &mgmXYZ);
|
||||
localDataPoolMap.emplace(mgmLis3::TEMPERATURE_CELCIUS, &temperature);
|
||||
poolManager.setPeriodicFrequency(dataset.getSid(), 10'000);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
*/
|
||||
|
||||
void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLimit) {
|
||||
this->absLimitX = xLimit;
|
||||
this->absLimitY = yLimit;
|
||||
this->absLimitZ = zLimit;
|
||||
}
|
||||
|
||||
void MgmLIS3MDLHandler::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
||||
periodicPrintout = enable;
|
||||
debugDivider.setDivider(divider);
|
||||
}
|
148
misc/archive/MgmLIS3MDLHandler.h
Normal file
148
misc/archive/MgmLIS3MDLHandler.h
Normal file
@ -0,0 +1,148 @@
|
||||
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||
|
||||
#include "mgmLis3Helpers.h"
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
|
||||
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
|
||||
*/
|
||||
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();
|
||||
|
||||
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
||||
/**
|
||||
* 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;
|
||||
// ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
// PeriodicHkGenerationHelper &poolManager) override;
|
||||
|
||||
private:
|
||||
mgmLis3::MgmPrimaryDataset dataset;
|
||||
// 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
|
||||
uint8_t commandBuffer[mgmLis3::NR_OF_DATA_AND_CFG_REGISTERS + 1];
|
||||
|
||||
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
|
||||
*/
|
||||
uint8_t registers[mgmLis3::NR_OF_CTRL_REGISTERS];
|
||||
|
||||
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;
|
||||
|
||||
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
|
||||
PoolEntry<float> temperature = PoolEntry<float>();
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* 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();
|
||||
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */
|
370
misc/archive/MgmRM3100Handler.cpp
Normal file
370
misc/archive/MgmRM3100Handler.cpp
Normal file
@ -0,0 +1,370 @@
|
||||
#include "MgmRM3100Handler.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
|
||||
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, uint32_t transitionDelay)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
primaryDataset(sharedPool),
|
||||
transitionDelay(transitionDelay) {}
|
||||
|
||||
MgmRM3100Handler::~MgmRM3100Handler() {}
|
||||
|
||||
void MgmRM3100Handler::doStartUp() {
|
||||
switch (internalState) {
|
||||
case (InternalState::NONE): {
|
||||
internalState = InternalState::CONFIGURE_CMM;
|
||||
break;
|
||||
}
|
||||
case (InternalState::CONFIGURE_CMM): {
|
||||
internalState = InternalState::READ_CMM;
|
||||
break;
|
||||
}
|
||||
case (InternalState::READ_CMM): {
|
||||
if (commandExecuted) {
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_CONFIGURE_TMRC): {
|
||||
if (commandExecuted) {
|
||||
internalState = InternalState::STATE_READ_TMRC;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_READ_TMRC): {
|
||||
if (commandExecuted) {
|
||||
internalState = InternalState::NORMAL;
|
||||
if (goToNormalModeAtStartup) {
|
||||
setMode(MODE_NORMAL);
|
||||
} else {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
size_t commandLen = 0;
|
||||
switch (internalState) {
|
||||
case (InternalState::NONE):
|
||||
case (InternalState::NORMAL): {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
case (InternalState::CONFIGURE_CMM): {
|
||||
*id = mgmRm3100::CONFIGURE_CMM;
|
||||
break;
|
||||
}
|
||||
case (InternalState::READ_CMM): {
|
||||
*id = mgmRm3100::READ_CMM;
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_CONFIGURE_TMRC): {
|
||||
commandBuffer[0] = mgmRm3100::TMRC_DEFAULT_VALUE;
|
||||
commandLen = 1;
|
||||
*id = mgmRm3100::CONFIGURE_TMRC;
|
||||
break;
|
||||
}
|
||||
case (InternalState::STATE_READ_TMRC): {
|
||||
*id = mgmRm3100::READ_TMRC;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
// Might be a configuration error
|
||||
sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning(
|
||||
"MgmRM3100Handler::buildTransitionDeviceCommand: "
|
||||
"Unknown internal state\n");
|
||||
#endif
|
||||
#endif
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
return buildCommandFromCommand(*id, commandBuffer, commandLen);
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (mgmRm3100::CONFIGURE_CMM): {
|
||||
commandBuffer[0] = mgmRm3100::CMM_REGISTER;
|
||||
commandBuffer[1] = mgmRm3100::CMM_VALUE;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::READ_CMM): {
|
||||
commandBuffer[0] = mgmRm3100::CMM_REGISTER | mgmRm3100::READ_MASK;
|
||||
commandBuffer[1] = 0;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::CONFIGURE_TMRC): {
|
||||
return handleTmrcConfigCommand(deviceCommand, commandData, commandDataLen);
|
||||
}
|
||||
case (mgmRm3100::READ_TMRC): {
|
||||
commandBuffer[0] = mgmRm3100::TMRC_REGISTER | mgmRm3100::READ_MASK;
|
||||
commandBuffer[1] = 0;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::CONFIGURE_CYCLE_COUNT): {
|
||||
return handleCycleCountConfigCommand(deviceCommand, commandData, commandDataLen);
|
||||
}
|
||||
case (mgmRm3100::READ_CYCLE_COUNT): {
|
||||
commandBuffer[0] = mgmRm3100::CYCLE_COUNT_START_REGISTER | mgmRm3100::READ_MASK;
|
||||
std::memset(commandBuffer + 1, 0, 6);
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 7;
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::READ_DATA): {
|
||||
commandBuffer[0] = mgmRm3100::MEASUREMENT_REG_START | mgmRm3100::READ_MASK;
|
||||
std::memset(commandBuffer + 1, 0, 9);
|
||||
rawPacketLen = 10;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
*id = mgmRm3100::READ_DATA;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
// For SPI, ID will always be the one of the last sent command
|
||||
*foundId = this->getPendingCommand();
|
||||
*foundLen = len;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
switch (id) {
|
||||
case (mgmRm3100::CONFIGURE_CMM):
|
||||
case (mgmRm3100::CONFIGURE_CYCLE_COUNT):
|
||||
case (mgmRm3100::CONFIGURE_TMRC): {
|
||||
// We can only check whether write was successful with read operation
|
||||
if (getMode() == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::READ_CMM): {
|
||||
uint8_t cmmValue = packet[1];
|
||||
// We clear the seventh bit in any case
|
||||
// because this one is zero sometimes for some reason
|
||||
bitutil::clear(&cmmValue, 6);
|
||||
if (cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||
commandExecuted = true;
|
||||
} else {
|
||||
// Attempt reconfiguration
|
||||
internalState = InternalState::CONFIGURE_CMM;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::READ_TMRC): {
|
||||
if (packet[1] == tmrcRegValue) {
|
||||
commandExecuted = true;
|
||||
// Reading TMRC was commanded. Trigger event to inform ground
|
||||
if (getMode() != _MODE_START_UP) {
|
||||
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
||||
}
|
||||
} else {
|
||||
// Attempt reconfiguration
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::READ_CYCLE_COUNT): {
|
||||
uint16_t cycleCountX = packet[1] << 8 | packet[2];
|
||||
uint16_t cycleCountY = packet[3] << 8 | packet[4];
|
||||
uint16_t cycleCountZ = packet[5] << 8 | packet[6];
|
||||
if (cycleCountX != cycleCountRegValueX or cycleCountY != cycleCountRegValueY or
|
||||
cycleCountZ != cycleCountRegValueZ) {
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
// Reading TMRC was commanded. Trigger event to inform ground
|
||||
if (getMode() != _MODE_START_UP) {
|
||||
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
|
||||
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (mgmRm3100::READ_DATA): {
|
||||
result = handleDataReadout(packet);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if (commandData == nullptr) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
// Set cycle count
|
||||
if (commandDataLen == 2) {
|
||||
handleCycleCommand(true, commandData, commandDataLen);
|
||||
} else if (commandDataLen == 6) {
|
||||
handleCycleCommand(false, commandData, commandDataLen);
|
||||
} else {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
commandBuffer[0] = mgmRm3100::CYCLE_COUNT_VALUE;
|
||||
std::memcpy(commandBuffer + 1, &cycleCountRegValueX, 2);
|
||||
std::memcpy(commandBuffer + 3, &cycleCountRegValueY, 2);
|
||||
std::memcpy(commandBuffer + 5, &cycleCountRegValueZ, 2);
|
||||
rawPacketLen = 7;
|
||||
rawPacket = commandBuffer;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
mgmRm3100::CycleCountCommand command(oneCycleValue);
|
||||
ReturnValue_t result =
|
||||
command.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts."
|
||||
if (command.cycleCountX > 450) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
if (not oneCycleValue and (command.cycleCountY > 450 or command.cycleCountZ > 450)) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
cycleCountRegValueX = command.cycleCountX;
|
||||
cycleCountRegValueY = command.cycleCountY;
|
||||
cycleCountRegValueZ = command.cycleCountZ;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if (commandData == nullptr or commandDataLen != 1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
commandBuffer[0] = mgmRm3100::TMRC_REGISTER;
|
||||
commandBuffer[1] = commandData[0];
|
||||
tmrcRegValue = commandData[0];
|
||||
rawPacketLen = 2;
|
||||
rawPacket = commandBuffer;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(mgmRm3100::CONFIGURE_CMM, 3);
|
||||
insertInCommandAndReplyMap(mgmRm3100::READ_CMM, 3);
|
||||
|
||||
insertInCommandAndReplyMap(mgmRm3100::CONFIGURE_TMRC, 3);
|
||||
insertInCommandAndReplyMap(mgmRm3100::READ_TMRC, 3);
|
||||
|
||||
insertInCommandAndReplyMap(mgmRm3100::CONFIGURE_CYCLE_COUNT, 3);
|
||||
insertInCommandAndReplyMap(mgmRm3100::READ_CYCLE_COUNT, 3);
|
||||
|
||||
insertInCommandAndReplyMap(mgmRm3100::READ_DATA, 3, &primaryDataset);
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::modeChanged() { internalState = InternalState::NONE; }
|
||||
|
||||
// TODO: Fix
|
||||
/*
|
||||
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
PeriodicHkGenerationHelper &poolManager) {
|
||||
localDataPoolMap.emplace(mgmRm3100::FIELD_STRENGTHS, &mgmXYZ);
|
||||
poolManager.setPeriodicFrequency(primaryDataset.getSid(), 10'000);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
*/
|
||||
|
||||
uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return this->transitionDelay;
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::setToGoToNormalMode(bool enable) { goToNormalModeAtStartup = enable; }
|
||||
|
||||
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||
// Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift
|
||||
// trickery here to calculate the raw values first
|
||||
int32_t fieldStrengthRawX = ((packet[1] << 24) | (packet[2] << 16) | (packet[3] << 8)) >> 8;
|
||||
int32_t fieldStrengthRawY = ((packet[4] << 24) | (packet[5] << 16) | (packet[6] << 8)) >> 8;
|
||||
int32_t fieldStrengthRawZ = ((packet[7] << 24) | (packet[8] << 16) | (packet[9] << 8)) >> 8;
|
||||
|
||||
// Now scale to physical value in microtesla
|
||||
float fieldStrengthX = fieldStrengthRawX * scaleFactorX;
|
||||
float fieldStrengthY = fieldStrengthRawY * scaleFactorY;
|
||||
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorZ;
|
||||
|
||||
if (periodicPrintout) {
|
||||
if (debugDivider.checkAndIncrement()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MgmRM3100Handler: Magnetic field strength in"
|
||||
" microtesla:"
|
||||
<< std::endl;
|
||||
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
|
||||
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
|
||||
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
|
||||
#else
|
||||
sif::printInfo("MgmRM3100Handler: Magnetic field strength in microtesla:\n");
|
||||
sif::printInfo("X: %f uT\n", fieldStrengthX);
|
||||
sif::printInfo("Y: %f uT\n", fieldStrengthY);
|
||||
sif::printInfo("Z: %f uT\n", fieldStrengthZ);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Sanity check on values?
|
||||
PoolReadGuard readGuard(&primaryDataset);
|
||||
if (readGuard.getReadResult() == returnvalue::OK) {
|
||||
primaryDataset.fieldStrengths[0] = fieldStrengthX;
|
||||
primaryDataset.fieldStrengths[1] = fieldStrengthY;
|
||||
primaryDataset.fieldStrengths[2] = fieldStrengthZ;
|
||||
primaryDataset.valid = true;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void MgmRM3100Handler::enablePeriodicPrintouts(bool enable, uint8_t divider) {
|
||||
periodicPrintout = enable;
|
||||
debugDivider.setDivider(divider);
|
||||
}
|
105
misc/archive/MgmRM3100Handler.h
Normal file
105
misc/archive/MgmRM3100Handler.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||
|
||||
#include "mgmRm3100Helpers.h"
|
||||
|
||||
#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
|
||||
*/
|
||||
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();
|
||||
|
||||
void enablePeriodicPrintouts(bool enable, uint8_t divider);
|
||||
/**
|
||||
* 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;
|
||||
// ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
// PeriodicHkGenerationHelper &poolManager) override;
|
||||
|
||||
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;
|
||||
mgmRm3100::Rm3100PrimaryDataset primaryDataset;
|
||||
|
||||
uint8_t commandBuffer[10];
|
||||
uint8_t commandBufferLen = 0;
|
||||
|
||||
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;
|
||||
|
||||
bool goToNormalModeAtStartup = false;
|
||||
uint32_t transitionDelay;
|
||||
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
|
||||
|
||||
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);
|
||||
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider debugDivider = PeriodicOperationDivider(3);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ */
|
46
misc/archive/ProvidesDataPoolSubscriptionIF.h
Normal file
46
misc/archive/ProvidesDataPoolSubscriptionIF.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_
|
||||
#define FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_
|
||||
|
||||
#include <fsfw/timemanager/clockDefinitions.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "fsfw/housekeeping/AcceptsHkPacketsIF.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/ipc/messageQueueDefinitions.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
#include "localPoolDefinitions.h"
|
||||
|
||||
namespace subdp {
|
||||
|
||||
struct ParamsBase {
|
||||
ParamsBase(sid_t sid, bool enableReporting, dur_millis_t collectionIntervalMs)
|
||||
: sid(sid), enableReporting(enableReporting), collectionIntervalMs(collectionIntervalMs) {}
|
||||
|
||||
[[nodiscard]] bool isDiagnostics() const { return diagnostics; }
|
||||
|
||||
sid_t sid;
|
||||
bool enableReporting;
|
||||
dur_millis_t collectionIntervalMs;
|
||||
MessageQueueId_t receiver = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
protected:
|
||||
bool diagnostics;
|
||||
};
|
||||
|
||||
struct RegularHkPeriodicParams : public ParamsBase {
|
||||
RegularHkPeriodicParams(sid_t sid, bool enableReporting, dur_millis_t collectionIntervalMs)
|
||||
: ParamsBase(sid, enableReporting, collectionIntervalMs) {}
|
||||
};
|
||||
|
||||
struct RegularHkUpdateParams : public ParamsBase {
|
||||
RegularHkUpdateParams(sid_t sid, bool enableReporting) : ParamsBase(sid, enableReporting, 0) {}
|
||||
};
|
||||
|
||||
struct DiagnosticsHkUpdateParams : public ParamsBase {
|
||||
DiagnosticsHkUpdateParams(sid_t sid, bool enableReporting)
|
||||
: ParamsBase(sid, enableReporting, 0) {}
|
||||
};
|
||||
} // namespace subdp
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ */
|
33
misc/archive/SharedLocalDataset.cpp
Normal file
33
misc/archive/SharedLocalDataset.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "fsfw/datapool/SharedLocalDataset.h"
|
||||
|
||||
SharedLocalDataset::SharedLocalDataset(object_id_t objectId, structure_id_t sid, const size_t maxSize)
|
||||
: SystemObject(objectId), SharedDatasetBase(sid, nullptr, maxSize), poolVarVector(maxSize) {
|
||||
this->setContainer(poolVarVector.data());
|
||||
datasetLock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SharedLocalDataset::SharedLocalDataset(object_id_t objectId, localpool::SharedPool& sharedPool,
|
||||
uint32_t setId, const size_t maxSize)
|
||||
: SystemObject(objectId),
|
||||
SharedDatasetBase(sharedPool, setId, nullptr, maxSize),
|
||||
poolVarVector(maxSize) {
|
||||
this->setContainer(poolVarVector.data());
|
||||
datasetLock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SharedLocalDataset::~SharedLocalDataset() { MutexFactory::instance()->deleteMutex(datasetLock); }
|
||||
|
||||
ReturnValue_t SharedLocalDataset::lockDataset(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t mutexTimeout) {
|
||||
if (datasetLock != nullptr) {
|
||||
return datasetLock->lockMutex(timeoutType, mutexTimeout);
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t SharedLocalDataset::unlockDataset() {
|
||||
if (datasetLock != nullptr) {
|
||||
return datasetLock->unlockMutex();
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
37
misc/archive/SharedLocalDataset.h
Normal file
37
misc/archive/SharedLocalDataset.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/datapool/SharedDataSetIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "SharedSetBase.h"
|
||||
#include "SharedPool.h"
|
||||
|
||||
namespace datapool {
|
||||
|
||||
/**
|
||||
* This local dataset variation can be used if the dataset is used concurrently across
|
||||
* multiple threads. It provides a lock in addition to all other functionalities provided
|
||||
* by the LocalPoolDataSetBase class.
|
||||
*
|
||||
* The user is completely responsible for locking and unlocking the dataset when using the
|
||||
* shared dataset.
|
||||
*/
|
||||
class SharedLocalDataset : public SystemObject, public SharedSetBase, public SharedDataSetIF {
|
||||
public:
|
||||
SharedLocalDataset(object_id_t objectId, SharedPool& sharedPool, uint32_t setId,
|
||||
size_t maxSize);
|
||||
SharedLocalDataset(object_id_t objectId, sid_t sid, size_t maxSize);
|
||||
|
||||
~SharedLocalDataset() override;
|
||||
|
||||
ReturnValue_t lockDataset(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||
dur_millis_t mutexTimeout = 20) override;
|
||||
ReturnValue_t unlockDataset() override;
|
||||
|
||||
private:
|
||||
MutexIF* datasetLock = nullptr;
|
||||
std::vector<PoolVariableIF*> poolVarVector;
|
||||
};
|
||||
|
||||
}
|
14
misc/archive/gyroL3gHelpers.cpp
Normal file
14
misc/archive/gyroL3gHelpers.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "gyroL3gHelpers.h"
|
||||
|
||||
float l3gd20h::ctrlReg4ToSensitivity(uint8_t reg) {
|
||||
bool fsH = reg & l3gd20h::SET_FS_1;
|
||||
bool fsL = reg & l3gd20h::SET_FS_0;
|
||||
|
||||
if (not fsH and not fsL) {
|
||||
return l3gd20h::SENSITIVITY_00;
|
||||
} else if (not fsH and fsL) {
|
||||
return l3gd20h::SENSITIVITY_01;
|
||||
} else {
|
||||
return l3gd20h::SENSITIVITY_11;
|
||||
}
|
||||
}
|
139
misc/archive/gyroL3gHelpers.h
Normal file
139
misc/archive/gyroL3gHelpers.h
Normal file
@ -0,0 +1,139 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_
|
||||
|
||||
#include "fsfw/datapoollocal/StaticLocalDataSet.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerIF.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace l3gd20h {
|
||||
|
||||
float ctrlReg4ToSensitivity(uint8_t reg);
|
||||
|
||||
/* Actual size is 15 but we round up a bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
||||
|
||||
static constexpr uint8_t READ_MASK = 0b10000000;
|
||||
|
||||
static constexpr uint8_t AUTO_INCREMENT_MASK = 0b01000000;
|
||||
|
||||
static constexpr uint8_t WHO_AM_I_REG = 0b00001111;
|
||||
static constexpr uint8_t WHO_AM_I_VAL = 0b11010111;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Control registers */
|
||||
/*------------------------------------------------------------------------*/
|
||||
static constexpr uint8_t CTRL_REG_1 = 0b00100000;
|
||||
static constexpr uint8_t CTRL_REG_2 = 0b00100001;
|
||||
static constexpr uint8_t CTRL_REG_3 = 0b00100010;
|
||||
static constexpr uint8_t CTRL_REG_4 = 0b00100011;
|
||||
static constexpr uint8_t CTRL_REG_5 = 0b00100100;
|
||||
|
||||
/* Register 1 */
|
||||
static constexpr uint8_t SET_DR_1 = 1 << 7;
|
||||
static constexpr uint8_t SET_DR_0 = 1 << 6;
|
||||
static constexpr uint8_t SET_BW_1 = 1 << 5;
|
||||
static constexpr uint8_t SET_BW_0 = 1 << 4;
|
||||
static constexpr uint8_t SET_POWER_NORMAL_MODE = 1 << 3;
|
||||
static constexpr uint8_t SET_Z_ENABLE = 1 << 2;
|
||||
static constexpr uint8_t SET_X_ENABLE = 1 << 1;
|
||||
static constexpr uint8_t SET_Y_ENABLE = 1;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_1_VAL =
|
||||
SET_POWER_NORMAL_MODE | SET_Z_ENABLE | SET_Y_ENABLE | SET_X_ENABLE;
|
||||
|
||||
/* Register 2 */
|
||||
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
|
||||
static constexpr uint8_t LEVEL_SENSITIVE_TRIGGER = 1 << 6;
|
||||
static constexpr uint8_t SET_HPM_1 = 1 << 5;
|
||||
static constexpr uint8_t SET_HPM_0 = 1 << 4;
|
||||
static constexpr uint8_t SET_HPCF_3 = 1 << 3;
|
||||
static constexpr uint8_t SET_HPCF_2 = 1 << 2;
|
||||
static constexpr uint8_t SET_HPCF_1 = 1 << 1;
|
||||
static constexpr uint8_t SET_HPCF_0 = 1;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_2_VAL = 0b00000000;
|
||||
|
||||
/* Register 3 */
|
||||
static constexpr uint8_t CTRL_REG_3_VAL = 0b00000000;
|
||||
|
||||
/* Register 4 */
|
||||
static constexpr uint8_t SET_BNU = 1 << 7;
|
||||
static constexpr uint8_t SET_BLE = 1 << 6;
|
||||
static constexpr uint8_t SET_FS_1 = 1 << 5;
|
||||
static constexpr uint8_t SET_FS_0 = 1 << 4;
|
||||
static constexpr uint8_t SET_IMP_ENB = 1 << 3;
|
||||
static constexpr uint8_t SET_SELF_TEST_ENB_1 = 1 << 2;
|
||||
static constexpr uint8_t SET_SELF_TEST_ENB_0 = 1 << 1;
|
||||
static constexpr uint8_t SET_SPI_IF_SELECT = 1;
|
||||
|
||||
/* Enable big endian data format */
|
||||
static constexpr uint8_t CTRL_REG_4_VAL = SET_BLE;
|
||||
|
||||
/* Register 5 */
|
||||
static constexpr uint8_t SET_REBOOT_MEM = 1 << 7;
|
||||
static constexpr uint8_t SET_FIFO_ENB = 1 << 6;
|
||||
static constexpr uint8_t SET_OUT_SEL_1 = 1 << 1;
|
||||
static constexpr uint8_t SET_OUT_SEL_0 = 1 << 0;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_5_VAL = SET_OUT_SEL_1 | SET_OUT_SEL_0;
|
||||
|
||||
/* Possible range values in degrees per second (DPS). */
|
||||
static constexpr uint16_t RANGE_DPS_00 = 245;
|
||||
static constexpr float SENSITIVITY_00 = 8.75 * 0.001;
|
||||
static constexpr uint16_t RANGE_DPS_01 = 500;
|
||||
static constexpr float SENSITIVITY_01 = 17.5 * 0.001;
|
||||
static constexpr uint16_t RANGE_DPS_11 = 2000;
|
||||
static constexpr float SENSITIVITY_11 = 70.0 * 0.001;
|
||||
|
||||
static constexpr uint8_t READ_START = CTRL_REG_1;
|
||||
static constexpr size_t READ_LEN = 14;
|
||||
|
||||
/* Indexing */
|
||||
static constexpr uint8_t REFERENCE_IDX = 6;
|
||||
static constexpr uint8_t TEMPERATURE_IDX = 7;
|
||||
static constexpr uint8_t STATUS_IDX = 8;
|
||||
static constexpr uint8_t OUT_X_H = 9;
|
||||
static constexpr uint8_t OUT_X_L = 10;
|
||||
static constexpr uint8_t OUT_Y_H = 11;
|
||||
static constexpr uint8_t OUT_Y_L = 12;
|
||||
static constexpr uint8_t OUT_Z_H = 13;
|
||||
static constexpr uint8_t OUT_Z_L = 14;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Device Handler specific */
|
||||
/*------------------------------------------------------------------------*/
|
||||
static constexpr DeviceCommandId_t READ_REGS = 0;
|
||||
static constexpr DeviceCommandId_t CONFIGURE_CTRL_REGS = 1;
|
||||
static constexpr DeviceCommandId_t READ_CTRL_REGS = 2;
|
||||
|
||||
static constexpr DeviceCommandId_t REQUEST = 0x70;
|
||||
static constexpr DeviceCommandId_t REPLY = 0x77;
|
||||
|
||||
static constexpr uint32_t GYRO_DATASET_ID = READ_REGS;
|
||||
|
||||
enum GyroPoolIds : lp_id_t { ANG_VELOC_X, ANG_VELOC_Y, ANG_VELOC_Z, TEMPERATURE };
|
||||
|
||||
} // namespace l3gd20h
|
||||
|
||||
class GyroPrimaryDataset : public StaticLocalDataSet<5> {
|
||||
public:
|
||||
/** Constructor for data users like controllers */
|
||||
GyroPrimaryDataset(object_id_t mgmId)
|
||||
: StaticLocalDataSet(sid_t(mgmId, l3gd20h::GYRO_DATASET_ID)) {
|
||||
setAllVariablesReadOnly();
|
||||
}
|
||||
/** Constructor for the data creator */
|
||||
GyroPrimaryDataset(localpool::SharedPool& sharedPool)
|
||||
: StaticLocalDataSet(sharedPool, l3gd20h::GYRO_DATASET_ID) {}
|
||||
|
||||
/* Angular velocities in degrees per second (DPS) */
|
||||
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId, l3gd20h::ANG_VELOC_X, this);
|
||||
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId, l3gd20h::ANG_VELOC_Y, this);
|
||||
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId, l3gd20h::ANG_VELOC_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, l3gd20h::TEMPERATURE, this);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */
|
52
misc/archive/mgmLis3Helpers.cpp
Normal file
52
misc/archive/mgmLis3Helpers.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "mgmLis3Helpers.h"
|
||||
|
||||
uint8_t mgmLis3::readCommand(uint8_t command, bool continuousCom) {
|
||||
command |= (1 << mgmLis3::RW_BIT);
|
||||
if (continuousCom == true) {
|
||||
command |= (1 << mgmLis3::MS_BIT);
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
uint8_t mgmLis3::writeCommand(uint8_t command, bool continuousCom) {
|
||||
command &= ~(1 << mgmLis3::RW_BIT);
|
||||
if (continuousCom == true) {
|
||||
command |= (1 << mgmLis3::MS_BIT);
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
mgmLis3::Sensitivies mgmLis3::getSensitivity(uint8_t ctrlRegister2) {
|
||||
bool fs0Set = ctrlRegister2 & (1 << mgmLis3::FSO); // Checks if FS0 bit is set
|
||||
bool fs1Set = ctrlRegister2 & (1 << mgmLis3::FS1); // Checks if FS1 bit is set
|
||||
|
||||
if (fs0Set && fs1Set)
|
||||
return mgmLis3::Sensitivies::GAUSS_16;
|
||||
else if (!fs0Set && fs1Set)
|
||||
return mgmLis3::Sensitivies::GAUSS_12;
|
||||
else if (fs0Set && !fs1Set)
|
||||
return mgmLis3::Sensitivies::GAUSS_8;
|
||||
else
|
||||
return mgmLis3::Sensitivies::GAUSS_4;
|
||||
}
|
||||
|
||||
float mgmLis3::getSensitivityFactor(mgmLis3::Sensitivies sens) {
|
||||
switch (sens) {
|
||||
case (mgmLis3::GAUSS_4): {
|
||||
return mgmLis3::FIELD_LSB_PER_GAUSS_4_SENS;
|
||||
}
|
||||
case (mgmLis3::GAUSS_8): {
|
||||
return mgmLis3::FIELD_LSB_PER_GAUSS_8_SENS;
|
||||
}
|
||||
case (mgmLis3::GAUSS_12): {
|
||||
return mgmLis3::FIELD_LSB_PER_GAUSS_12_SENS;
|
||||
}
|
||||
case (mgmLis3::GAUSS_16): {
|
||||
return mgmLis3::FIELD_LSB_PER_GAUSS_16_SENS;
|
||||
}
|
||||
default: {
|
||||
// Should never happen
|
||||
return mgmLis3::FIELD_LSB_PER_GAUSS_4_SENS;
|
||||
}
|
||||
}
|
||||
}
|
191
misc/archive/mgmLis3Helpers.h
Normal file
191
misc/archive/mgmLis3Helpers.h
Normal file
@ -0,0 +1,191 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
|
||||
|
||||
#include "fsfw/datapoollocal/LocalPoolVariable.h"
|
||||
#include "fsfw/datapoollocal/StaticLocalDataSet.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerIF.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace mgmLis3 {
|
||||
|
||||
enum Set { ON, OFF };
|
||||
enum OpMode { LOW, MEDIUM, HIGH, ULTRA };
|
||||
|
||||
enum Sensitivies : uint8_t { GAUSS_4 = 4, GAUSS_8 = 8, GAUSS_12 = 12, GAUSS_16 = 16 };
|
||||
|
||||
/**
|
||||
* 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
|
||||
* e.g.: +- 4 gauss. See p.25 datasheet.
|
||||
* @return The ReturnValue does not contain the sign of the value
|
||||
*/
|
||||
mgmLis3::Sensitivies getSensitivity(uint8_t ctrlReg2);
|
||||
|
||||
/**
|
||||
* The 16 bit value needs to be multiplied with a sensitivity factor
|
||||
* which depends on the sensitivity configuration
|
||||
*
|
||||
* @param sens Configured sensitivity of the LIS3 device
|
||||
* @return Multiplication factor to get the sensor value from raw data.
|
||||
*/
|
||||
float getSensitivityFactor(mgmLis3::Sensitivies sens);
|
||||
|
||||
/* Actually 15, we just round up a bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
||||
|
||||
/* Field data register scaling */
|
||||
static constexpr uint8_t GAUSS_TO_MICROTESLA_FACTOR = 100;
|
||||
static constexpr float FIELD_LSB_PER_GAUSS_4_SENS = 1.0 / 6842.0;
|
||||
static constexpr float FIELD_LSB_PER_GAUSS_8_SENS = 1.0 / 3421.0;
|
||||
static constexpr float FIELD_LSB_PER_GAUSS_12_SENS = 1.0 / 2281.0;
|
||||
static constexpr float FIELD_LSB_PER_GAUSS_16_SENS = 1.0 / 1711.0;
|
||||
|
||||
static const DeviceCommandId_t READ_CONFIG_AND_DATA = 0x00;
|
||||
static const DeviceCommandId_t SETUP_MGM = 0x01;
|
||||
static const DeviceCommandId_t READ_TEMPERATURE = 0x02;
|
||||
static const DeviceCommandId_t IDENTIFY_DEVICE = 0x03;
|
||||
static const DeviceCommandId_t TEMP_SENSOR_ENABLE = 0x04;
|
||||
static const DeviceCommandId_t ACCURACY_OP_MODE_SET = 0x05;
|
||||
|
||||
/* Number of all control registers */
|
||||
static const uint8_t NR_OF_CTRL_REGISTERS = 5;
|
||||
/* Number of registers in the MGM */
|
||||
static const uint8_t NR_OF_REGISTERS = 19;
|
||||
/* Total number of adresses for all registers */
|
||||
static const uint8_t TOTAL_NR_OF_ADRESSES = 52;
|
||||
static const uint8_t NR_OF_DATA_AND_CFG_REGISTERS = 14;
|
||||
static const uint8_t TEMPERATURE_REPLY_LEN = 3;
|
||||
static const uint8_t SETUP_REPLY_LEN = 6;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Register adresses */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Register adress returns identifier of device with default 0b00111101 */
|
||||
static const uint8_t IDENTIFY_DEVICE_REG_ADDR = 0b00001111;
|
||||
static const uint8_t DEVICE_ID = 0b00111101; // Identifier for Device
|
||||
|
||||
/* Register adress to access register 1 */
|
||||
static const uint8_t CTRL_REG1 = 0b00100000;
|
||||
/* Register adress to access register 2 */
|
||||
static const uint8_t CTRL_REG2 = 0b00100001;
|
||||
/* Register adress to access register 3 */
|
||||
static const uint8_t CTRL_REG3 = 0b00100010;
|
||||
/* Register adress to access register 4 */
|
||||
static const uint8_t CTRL_REG4 = 0b00100011;
|
||||
/* Register adress to access register 5 */
|
||||
static const uint8_t CTRL_REG5 = 0b00100100;
|
||||
|
||||
/* Register adress to access status register */
|
||||
static const uint8_t STATUS_REG_IDX = 8;
|
||||
static const uint8_t STATUS_REG = 0b00100111;
|
||||
|
||||
/* Register adress to access low byte of x-axis */
|
||||
static const uint8_t X_LOWBYTE_IDX = 9;
|
||||
static const uint8_t X_LOWBYTE = 0b00101000;
|
||||
/* Register adress to access high byte of x-axis */
|
||||
static const uint8_t X_HIGHBYTE_IDX = 10;
|
||||
static const uint8_t X_HIGHBYTE = 0b00101001;
|
||||
/* Register adress to access low byte of y-axis */
|
||||
static const uint8_t Y_LOWBYTE_IDX = 11;
|
||||
static const uint8_t Y_LOWBYTE = 0b00101010;
|
||||
/* Register adress to access high byte of y-axis */
|
||||
static const uint8_t Y_HIGHBYTE_IDX = 12;
|
||||
static const uint8_t Y_HIGHBYTE = 0b00101011;
|
||||
/* Register adress to access low byte of z-axis */
|
||||
static const uint8_t Z_LOWBYTE_IDX = 13;
|
||||
static const uint8_t Z_LOWBYTE = 0b00101100;
|
||||
/* Register adress to access high byte of z-axis */
|
||||
static const uint8_t Z_HIGHBYTE_IDX = 14;
|
||||
static const uint8_t Z_HIGHBYTE = 0b00101101;
|
||||
|
||||
/* Register adress to access low byte of temperature sensor */
|
||||
static const uint8_t TEMP_LOWBYTE = 0b00101110;
|
||||
/* Register adress to access high byte of temperature sensor */
|
||||
static const uint8_t TEMP_HIGHBYTE = 0b00101111;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Initialize Setup Register set bits */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* General transfer bits */
|
||||
// Read=1 / Write=0 Bit
|
||||
static const uint8_t RW_BIT = 7;
|
||||
// Continous Read/Write Bit, increment adress
|
||||
static const uint8_t MS_BIT = 6;
|
||||
|
||||
/* CTRL_REG1 bits */
|
||||
static const uint8_t ST = 0; // Self test enable bit, enabled = 1
|
||||
// Enable rates higher than 80 Hz enabled = 1
|
||||
static const uint8_t FAST_ODR = 1;
|
||||
static const uint8_t DO0 = 2; // Output data rate bit 2
|
||||
static const uint8_t DO1 = 3; // Output data rate bit 3
|
||||
static const uint8_t DO2 = 4; // Output data rate bit 4
|
||||
static const uint8_t OM0 = 5; // XY operating mode bit 5
|
||||
static const uint8_t OM1 = 6; // XY operating mode bit 6
|
||||
static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1
|
||||
static const uint8_t CTRL_REG1_DEFAULT =
|
||||
(1 << TEMP_EN) | (1 << OM1) | (1 << DO0) | (1 << DO1) | (1 << DO2);
|
||||
|
||||
/* CTRL_REG2 bits */
|
||||
// reset configuration registers and user registers
|
||||
static const uint8_t SOFT_RST = 2;
|
||||
static const uint8_t REBOOT = 3; // reboot memory content
|
||||
static const uint8_t FSO = 5; // full-scale selection bit 5
|
||||
static const uint8_t FS1 = 6; // full-scale selection bit 6
|
||||
static const uint8_t CTRL_REG2_DEFAULT = 0;
|
||||
|
||||
/* CTRL_REG3 bits */
|
||||
static const uint8_t MD0 = 0; // Operating mode bit 0
|
||||
static const uint8_t MD1 = 1; // Operating mode bit 1
|
||||
// SPI serial interface mode selection enabled = 3-wire-mode
|
||||
static const uint8_t SIM = 2;
|
||||
static const uint8_t LP = 5; // low-power mode
|
||||
static const uint8_t CTRL_REG3_DEFAULT = 0;
|
||||
|
||||
/* CTRL_REG4 bits */
|
||||
// big/little endian data selection enabled = MSb at lower adress
|
||||
static const uint8_t BLE = 1;
|
||||
static const uint8_t OMZ0 = 2; // Z operating mode bit 2
|
||||
static const uint8_t OMZ1 = 3; // Z operating mode bit 3
|
||||
static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1);
|
||||
|
||||
/* CTRL_REG5 bits */
|
||||
static const uint8_t BDU = 6; // Block data update
|
||||
static const uint8_t FAST_READ = 7; // Fast read enabled = 1
|
||||
static const uint8_t CTRL_REG5_DEFAULT = 0;
|
||||
|
||||
static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA;
|
||||
|
||||
enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS = 0, TEMPERATURE_CELCIUS = 1, SET_IS_VALID = 2 };
|
||||
|
||||
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
|
||||
public:
|
||||
MgmPrimaryDataset(localpool::SharedPool& sharedPool)
|
||||
: StaticLocalDataSet(sharedPool, MGM_DATA_SET_ID) {}
|
||||
|
||||
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
||||
|
||||
/**
|
||||
* Field strenghts in uT
|
||||
*/
|
||||
lp_vec_t<float, 3> fieldStrengths = lp_vec_t<float, 3>(sid.objectId, FIELD_STRENGTHS, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
|
||||
lp_var_t<uint8_t> setIsValid = lp_var_t<uint8_t>(sid.objectId, SET_IS_VALID, this);
|
||||
};
|
||||
|
||||
} // namespace mgmLis3
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ */
|
122
misc/archive/mgmRm3100Helpers.h
Normal file
122
misc/archive/mgmRm3100Helpers.h
Normal file
@ -0,0 +1,122 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "fsfw/datapoollocal/LocalPoolVariable.h"
|
||||
#include "fsfw/datapoollocal/StaticLocalDataSet.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerIF.h"
|
||||
#include "fsfw/serialize/SerialLinkedListAdapter.h"
|
||||
|
||||
namespace mgmRm3100 {
|
||||
|
||||
/* Actually 10, we round up a little bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 12;
|
||||
|
||||
static constexpr uint8_t READ_MASK = 0x80;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* CMM Register */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static constexpr uint8_t SET_CMM_CMZ = 1 << 6;
|
||||
static constexpr uint8_t SET_CMM_CMY = 1 << 5;
|
||||
static constexpr uint8_t SET_CMM_CMX = 1 << 4;
|
||||
static constexpr uint8_t SET_CMM_DRDM = 1 << 2;
|
||||
static constexpr uint8_t SET_CMM_START = 1;
|
||||
static constexpr uint8_t CMM_REGISTER = 0x01;
|
||||
|
||||
static constexpr uint8_t CMM_VALUE =
|
||||
SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX | SET_CMM_DRDM | SET_CMM_START;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Cycle count register */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
// Default value (200)
|
||||
static constexpr uint8_t CYCLE_COUNT_VALUE = 0xC8;
|
||||
|
||||
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) / 100 * 38;
|
||||
static constexpr uint8_t CYCLE_COUNT_START_REGISTER = 0x04;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* TMRC register */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static constexpr uint8_t TMRC_150HZ_VALUE = 0x94;
|
||||
static constexpr uint8_t TMRC_75HZ_VALUE = 0x95;
|
||||
static constexpr uint8_t TMRC_DEFAULT_37HZ_VALUE = 0x96;
|
||||
|
||||
static constexpr uint8_t TMRC_REGISTER = 0x0B;
|
||||
static constexpr uint8_t TMRC_DEFAULT_VALUE = TMRC_DEFAULT_37HZ_VALUE;
|
||||
|
||||
static constexpr uint8_t MEASUREMENT_REG_START = 0x24;
|
||||
static constexpr uint8_t BIST_REGISTER = 0x33;
|
||||
static constexpr uint8_t DATA_READY_VAL = 0b10000000;
|
||||
static constexpr uint8_t STATUS_REGISTER = 0x34;
|
||||
static constexpr uint8_t REVID_REGISTER = 0x36;
|
||||
|
||||
// Range in Microtesla. 1 T equals 10000 Gauss (for comparison with LIS3 MGM)
|
||||
static constexpr uint16_t RANGE = 800;
|
||||
|
||||
static constexpr DeviceCommandId_t READ_DATA = 0;
|
||||
|
||||
static constexpr DeviceCommandId_t CONFIGURE_CMM = 1;
|
||||
static constexpr DeviceCommandId_t READ_CMM = 2;
|
||||
|
||||
static constexpr DeviceCommandId_t CONFIGURE_TMRC = 3;
|
||||
static constexpr DeviceCommandId_t READ_TMRC = 4;
|
||||
|
||||
static constexpr DeviceCommandId_t CONFIGURE_CYCLE_COUNT = 5;
|
||||
static constexpr DeviceCommandId_t READ_CYCLE_COUNT = 6;
|
||||
|
||||
class CycleCountCommand : public SerialLinkedListAdapter<SerializeIF> {
|
||||
public:
|
||||
CycleCountCommand(bool oneCycleCount = true) : oneCycleCount(oneCycleCount) {
|
||||
setLinks(oneCycleCount);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override {
|
||||
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer, size, streamEndianness);
|
||||
if (oneCycleCount) {
|
||||
cycleCountY = cycleCountX;
|
||||
cycleCountZ = cycleCountX;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SerializeElement<uint16_t> cycleCountX;
|
||||
SerializeElement<uint16_t> cycleCountY;
|
||||
SerializeElement<uint16_t> cycleCountZ;
|
||||
|
||||
private:
|
||||
void setLinks(bool oneCycleCount) {
|
||||
setStart(&cycleCountX);
|
||||
if (not oneCycleCount) {
|
||||
cycleCountX.setNext(&cycleCountY);
|
||||
cycleCountY.setNext(&cycleCountZ);
|
||||
}
|
||||
}
|
||||
|
||||
bool oneCycleCount;
|
||||
};
|
||||
|
||||
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
|
||||
|
||||
enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS = 0, VALID = 1 };
|
||||
|
||||
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
|
||||
public:
|
||||
Rm3100PrimaryDataset(localpool::SharedPool& sharedPool)
|
||||
: StaticLocalDataSet(sharedPool, MGM_DATASET_ID) {}
|
||||
|
||||
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
||||
|
||||
/**
|
||||
* Field strenghts in uT
|
||||
*/
|
||||
lp_vec_t<float, 3> fieldStrengths = lp_vec_t<float, 3>(sid.objectId, FIELD_STRENGTHS, this);
|
||||
lp_var_t<uint8_t> valid = lp_var_t<uint8_t>(sid.objectId, VALID, this);
|
||||
};
|
||||
|
||||
} // namespace mgmRm3100
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */
|
Reference in New Issue
Block a user