moved lis3mdl to fsfw
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
parent
8dcd2f0c95
commit
48a8a52b1c
@ -1,4 +1,3 @@
|
||||
#include <mission/devices/MgmLIS3MDLHandler.h>
|
||||
#include "ObjectFactory.h"
|
||||
#include "OBSWConfig.h"
|
||||
#include "devConf.h"
|
||||
@ -53,6 +52,7 @@
|
||||
|
||||
#include "fsfw_hal/linux/uart/UartComIF.h"
|
||||
#include "fsfw_hal/linux/uart/UartCookie.h"
|
||||
#include "fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h"
|
||||
#include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h"
|
||||
#include "fsfw_hal/devicehandlers/MgmRM3100Handler.h"
|
||||
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
||||
@ -448,9 +448,12 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF *gpioComIF, UartComI
|
||||
std::string spiDev = q7s::SPI_DEFAULT_DEV;
|
||||
SpiCookie* spiCookie = new SpiCookie(addresses::MGM_0_LIS3, gpioIds::MGM_0_LIS3_CS, spiDev,
|
||||
MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED);
|
||||
auto mgmLis3Handler = new MGMHandlerLIS3MDL(objects::MGM_0_LIS3_HANDLER,
|
||||
auto mgmLis3Handler = new MgmLIS3MDLHandler(objects::MGM_0_LIS3_HANDLER,
|
||||
objects::SPI_COM_IF, spiCookie, 0);
|
||||
mgmLis3Handler->setStartUpImmediately();
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
mgmLis3Handler->setToGoToNormalMode(true);
|
||||
#endif
|
||||
|
||||
spiCookie = new SpiCookie(addresses::MGM_1_RM3100, gpioIds::MGM_1_RM3100_CS, spiDev,
|
||||
RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED);
|
||||
@ -463,9 +466,12 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF *gpioComIF, UartComI
|
||||
|
||||
spiCookie = new SpiCookie(addresses::MGM_2_LIS3, gpioIds::MGM_2_LIS3_CS, spiDev,
|
||||
MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED);
|
||||
auto mgmLis3Handler2 = new MGMHandlerLIS3MDL(objects::MGM_2_LIS3_HANDLER,
|
||||
auto mgmLis3Handler2 = new MgmLIS3MDLHandler(objects::MGM_2_LIS3_HANDLER,
|
||||
objects::SPI_COM_IF, spiCookie, 0);
|
||||
mgmLis3Handler2->setStartUpImmediately();
|
||||
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
|
||||
mgmLis3Handler2->setToGoToNormalMode(true);
|
||||
#endif
|
||||
|
||||
spiCookie = new SpiCookie(addresses::MGM_3_RM3100, gpioIds::MGM_3_RM3100_CS, spiDev,
|
||||
RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED);
|
||||
|
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit 6d0d04ac230962024580ef3769cc8ec063db4093
|
||||
Subproject commit b1a56a71cdba538e82b4052413e1663b34cfee90
|
@ -77,5 +77,6 @@ static constexpr size_t FSFW_MAX_TM_PACKET_SIZE = 2048;
|
||||
|
||||
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
|
||||
#define FSFW_HAL_RM3100_MGM_DEBUG 0
|
||||
#define FSFW_HAL_LIS3MDL_MGM_DEBUG 0
|
||||
|
||||
#endif /* CONFIG_FSFWCONFIG_H_ */
|
||||
|
@ -425,16 +425,16 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
|
||||
thisSequence->addSlot(objects::RW4, length * 0.8, DeviceHandlerIF::GET_READ);
|
||||
|
||||
#if OBSW_ADD_ACS_BOARD == 1
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2,
|
||||
DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4,
|
||||
DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6,
|
||||
DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2,
|
||||
// DeviceHandlerIF::SEND_WRITE);
|
||||
// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4,
|
||||
// DeviceHandlerIF::GET_WRITE);
|
||||
// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6,
|
||||
// DeviceHandlerIF::SEND_READ);
|
||||
// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
|
||||
thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
@ -447,27 +447,27 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
|
||||
thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
|
||||
thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2,
|
||||
DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4,
|
||||
DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6,
|
||||
DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
|
||||
thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.2,
|
||||
DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.4,
|
||||
DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.6,
|
||||
DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2,
|
||||
// DeviceHandlerIF::SEND_WRITE);
|
||||
// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4,
|
||||
// DeviceHandlerIF::GET_WRITE);
|
||||
// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6,
|
||||
// DeviceHandlerIF::SEND_READ);
|
||||
// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
//
|
||||
// thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
// thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.2,
|
||||
// DeviceHandlerIF::SEND_WRITE);
|
||||
// thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.4,
|
||||
// DeviceHandlerIF::GET_WRITE);
|
||||
// thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.6,
|
||||
// DeviceHandlerIF::SEND_READ);
|
||||
// thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
|
||||
// thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
@ -480,16 +480,16 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
|
||||
// thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
|
||||
thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2,
|
||||
DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4,
|
||||
DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6,
|
||||
DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2,
|
||||
// DeviceHandlerIF::SEND_WRITE);
|
||||
// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4,
|
||||
// DeviceHandlerIF::GET_WRITE);
|
||||
// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6,
|
||||
// DeviceHandlerIF::SEND_READ);
|
||||
// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
|
||||
// thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
@ -502,16 +502,16 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
|
||||
// thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
|
||||
thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.2,
|
||||
DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.4,
|
||||
DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.6,
|
||||
DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
// thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0,
|
||||
// DeviceHandlerIF::PERFORM_OPERATION);
|
||||
// thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.2,
|
||||
// DeviceHandlerIF::SEND_WRITE);
|
||||
// thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.4,
|
||||
// DeviceHandlerIF::GET_WRITE);
|
||||
// thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.6,
|
||||
// DeviceHandlerIF::SEND_READ);
|
||||
// thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * 0.8,
|
||||
// DeviceHandlerIF::GET_READ);
|
||||
#endif /* OBSW_ADD_ACS_BOARD == 1 */
|
||||
|
||||
if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
GPSHyperionHandler.cpp
|
||||
MgmLIS3MDLHandler.cpp
|
||||
GomspaceDeviceHandler.cpp
|
||||
Tmp1075Handler.cpp
|
||||
PCDUHandler.cpp
|
||||
|
@ -1,497 +0,0 @@
|
||||
#include <mission/devices/MgmLIS3MDLHandler.h>
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#endif
|
||||
|
||||
MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF* comCookie, uint8_t switchId, uint32_t transitionDelay):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
dataset(this) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(5);
|
||||
#endif
|
||||
/* Set to default values right away. */
|
||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||
registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT;
|
||||
registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
MGMHandlerLIS3MDL::~MGMHandlerLIS3MDL() {
|
||||
}
|
||||
|
||||
|
||||
void MGMHandlerLIS3MDL::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 OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
setMode(MODE_NORMAL);
|
||||
#else
|
||||
setMode(_MODE_TO_ON);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::doShutDown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
switch (internalState) {
|
||||
case(InternalState::STATE_NONE):
|
||||
case(InternalState::STATE_NORMAL): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(InternalState::STATE_FIRST_CONTACT): {
|
||||
*id = MGMLIS3MDL::IDENTIFY_DEVICE;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_SETUP): {
|
||||
*id = MGMLIS3MDL::SETUP_MGM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_CHECK_REGISTERS): {
|
||||
*id = MGMLIS3MDL::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 HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
}
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
|
||||
uint8_t MGMHandlerLIS3MDL::readCommand(uint8_t command, bool continuousCom) {
|
||||
command |= (1 << MGMLIS3MDL::RW_BIT);
|
||||
if (continuousCom == true) {
|
||||
command |= (1 << MGMLIS3MDL::MS_BIT);
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
uint8_t MGMHandlerLIS3MDL::writeCommand(uint8_t command, bool continuousCom) {
|
||||
command &= ~(1 << MGMLIS3MDL::RW_BIT);
|
||||
if (continuousCom == true) {
|
||||
command |= (1 << MGMLIS3MDL::MS_BIT);
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::setupMgm() {
|
||||
|
||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||
registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT;
|
||||
registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT;
|
||||
|
||||
prepareCtrlRegisterWrite();
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
// Data/config register will be read in an alternating manner.
|
||||
if(communicationStep == CommunicationStep::DATA) {
|
||||
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||
communicationStep = CommunicationStep::TEMPERATURE;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
else {
|
||||
*id = MGMLIS3MDL::READ_TEMPERATURE;
|
||||
communicationStep = CommunicationStep::DATA;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(MGMLIS3MDL::READ_CONFIG_AND_DATA): {
|
||||
std::memset(commandBuffer, 0, sizeof(commandBuffer));
|
||||
commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true);
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(MGMLIS3MDL::READ_TEMPERATURE): {
|
||||
std::memset(commandBuffer, 0, 3);
|
||||
commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true);
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 3;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(MGMLIS3MDL::IDENTIFY_DEVICE): {
|
||||
return identifyDevice();
|
||||
}
|
||||
case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): {
|
||||
return enableTemperatureSensor(commandData, commandDataLen);
|
||||
}
|
||||
case(MGMLIS3MDL::SETUP_MGM): {
|
||||
setupMgm();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): {
|
||||
return setOperatingMode(commandData, commandDataLen);
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::identifyDevice() {
|
||||
uint32_t size = 2;
|
||||
commandBuffer[0] = readCommand(MGMLIS3MDL::IDENTIFY_DEVICE_REG_ADDR);
|
||||
commandBuffer[1] = 0x00;
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = size;
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::scanForReply(const uint8_t *start,
|
||||
size_t len, DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
*foundLen = len;
|
||||
if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) {
|
||||
*foundLen = len;
|
||||
*foundId = MGMLIS3MDL::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 OBSW_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(mode == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = MGMLIS3MDL::READ_TEMPERATURE;
|
||||
}
|
||||
else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = MGMLIS3MDL::SETUP_MGM;
|
||||
}
|
||||
else if (len == SINGLE_COMMAND_ANSWER_LEN) {
|
||||
*foundLen = len;
|
||||
*foundId = getPendingCommand();
|
||||
if(*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
|
||||
if(start[1] != MGMLIS3MDL::DEVICE_ID) {
|
||||
#if OBSW_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(mode == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
/* Data with SPI Interface always has this answer */
|
||||
if (start[0] == 0b11111111) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
}
|
||||
ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
|
||||
switch (id) {
|
||||
case MGMLIS3MDL::IDENTIFY_DEVICE: {
|
||||
break;
|
||||
}
|
||||
case MGMLIS3MDL::SETUP_MGM: {
|
||||
break;
|
||||
}
|
||||
case MGMLIS3MDL::READ_CONFIG_AND_DATA: {
|
||||
// TODO: Store configuration in new local datasets.
|
||||
float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2]));
|
||||
|
||||
int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::X_LOWBYTE_IDX] ;
|
||||
int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ;
|
||||
int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ;
|
||||
|
||||
/* Target value in microtesla */
|
||||
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
if(debugDivider->checkAndIncrement()) {
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
#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 */
|
||||
}
|
||||
#endif /* OBSW_VERBOSE_LEVEL >= 1 */
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
dataset.fieldStrengthX = mgmX;
|
||||
dataset.fieldStrengthY = mgmY;
|
||||
dataset.fieldStrengthZ = mgmZ;
|
||||
dataset.setValidity(true, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MGMLIS3MDL::READ_TEMPERATURE: {
|
||||
int16_t tempValueRaw = packet[2] << 8 | packet[1];
|
||||
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
if(debugDivider->check()) {
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result = dataset.read();
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
dataset.temperature = tempValue;
|
||||
dataset.commit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
MGMLIS3MDL::Sensitivies MGMHandlerLIS3MDL::getSensitivity(uint8_t ctrlRegister2) {
|
||||
bool fs0Set = ctrlRegister2 & (1 << MGMLIS3MDL::FSO); // Checks if FS0 bit is set
|
||||
bool fs1Set = ctrlRegister2 & (1 << MGMLIS3MDL::FS1); // Checks if FS1 bit is set
|
||||
|
||||
if (fs0Set && fs1Set)
|
||||
return MGMLIS3MDL::Sensitivies::GAUSS_16;
|
||||
else if (!fs0Set && fs1Set)
|
||||
return MGMLIS3MDL::Sensitivies::GAUSS_12;
|
||||
else if (fs0Set && !fs1Set)
|
||||
return MGMLIS3MDL::Sensitivies::GAUSS_8;
|
||||
else
|
||||
return MGMLIS3MDL::Sensitivies::GAUSS_4;
|
||||
}
|
||||
|
||||
float MGMHandlerLIS3MDL::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
|
||||
switch(sens) {
|
||||
case(MGMLIS3MDL::GAUSS_4): {
|
||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS;
|
||||
}
|
||||
case(MGMLIS3MDL::GAUSS_8): {
|
||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_8_SENS;
|
||||
}
|
||||
case(MGMLIS3MDL::GAUSS_12): {
|
||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_12_SENS;
|
||||
}
|
||||
case(MGMLIS3MDL::GAUSS_16): {
|
||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_16_SENS;
|
||||
}
|
||||
default: {
|
||||
// Should never happen
|
||||
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::enableTemperatureSensor(
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
|
||||
uint32_t size = 2;
|
||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1);
|
||||
if (commandDataLen > 1) {
|
||||
return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
switch (*commandData) {
|
||||
case (MGMLIS3MDL::ON): {
|
||||
commandBuffer[1] = registers[0] | (1 << 7);
|
||||
break;
|
||||
}
|
||||
case (MGMLIS3MDL::OFF): {
|
||||
commandBuffer[1] = registers[0] & ~(1 << 7);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
registers[0] = commandBuffer[1];
|
||||
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = size;
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::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 MGMLIS3MDL::LOW:
|
||||
registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) & (~(1 << MGMLIS3MDL::OM0));
|
||||
registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) & (~(1 << MGMLIS3MDL::OMZ0));
|
||||
break;
|
||||
case MGMLIS3MDL::MEDIUM:
|
||||
registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) | (1 << MGMLIS3MDL::OM0);
|
||||
registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) | (1 << MGMLIS3MDL::OMZ0);
|
||||
break;
|
||||
|
||||
case MGMLIS3MDL::HIGH:
|
||||
registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) & (~(1 << MGMLIS3MDL::OM0));
|
||||
registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) & (~(1 << MGMLIS3MDL::OMZ0));
|
||||
break;
|
||||
|
||||
case MGMLIS3MDL::ULTRA:
|
||||
registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) | (1 << MGMLIS3MDL::OM0);
|
||||
registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) | (1 << MGMLIS3MDL::OMZ0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return prepareCtrlRegisterWrite();
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::fillCommandAndReplyMap() {
|
||||
/*
|
||||
* Regarding ArduinoBoard:
|
||||
* Actually SPI answers directly, but as commanding ArduinoBoard the
|
||||
* communication could be delayed
|
||||
* SPI always has to be triggered, so there could be no periodic answer of
|
||||
* the device, the device has to asked with a command, so periodic is zero.
|
||||
*
|
||||
* We dont read single registers, we just expect special
|
||||
* reply from he Readall_MGM
|
||||
*/
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1, &dataset);
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1);
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1);
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1);
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1);
|
||||
insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1);
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::prepareCtrlRegisterWrite() {
|
||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true);
|
||||
|
||||
for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) {
|
||||
commandBuffer[i + 1] = registers[i];
|
||||
}
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1;
|
||||
|
||||
/* We dont have to check if this is working because we just did it */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||
|
||||
}
|
||||
|
||||
uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 20000;
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::modeChanged(void) {
|
||||
internalState = InternalState::STATE_NONE;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS,
|
||||
new PoolEntry<float>({0.0}));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "devicedefinitions/MGMHandlerLIS3Definitions.h"
|
||||
#include "events/subsystemIdRanges.h"
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.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 MGMHandlerLIS3MDL: 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);
|
||||
|
||||
MGMHandlerLIS3MDL(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie,
|
||||
uint8_t switchId, uint32_t transitionDelay = 10000);
|
||||
virtual ~MGMHandlerLIS3MDL();
|
||||
|
||||
protected:
|
||||
|
||||
/** DeviceHandlerBase overrides */
|
||||
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(
|
||||
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;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
void modeChanged(void) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) override;
|
||||
|
||||
private:
|
||||
MGMLIS3MDL::MgmPrimaryDataset dataset;
|
||||
//Length a sindgle command SPI answer
|
||||
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
|
||||
|
||||
//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
|
||||
uint8_t commandBuffer[MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1];
|
||||
|
||||
/**
|
||||
* 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[MGMLIS3MDL::NR_OF_CTRL_REGISTERS];
|
||||
|
||||
uint8_t statusRegister = 0;
|
||||
|
||||
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;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
* e.g.: +- 4 gauss. See p.25 datasheet.
|
||||
* @return The ReturnValue does not contain the sign of the value
|
||||
*/
|
||||
MGMLIS3MDL::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(MGMLIS3MDL::Sensitivies sens);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
PeriodicOperationDivider* debugDivider;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */
|
@ -1,178 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_
|
||||
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace MGMLIS3MDL {
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
/* 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_STRENGTH_X,
|
||||
FIELD_STRENGTH_Y,
|
||||
FIELD_STRENGTH_Z,
|
||||
TEMPERATURE_CELCIUS
|
||||
};
|
||||
|
||||
class MgmPrimaryDataset: public StaticLocalDataSet<5> {
|
||||
public:
|
||||
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
|
||||
|
||||
MgmPrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
|
||||
|
||||
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_X, this);
|
||||
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_Y, this);
|
||||
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
|
||||
FIELD_STRENGTH_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
||||
TEMPERATURE_CELCIUS, this);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_ */
|
Loading…
Reference in New Issue
Block a user