Merge branch 'mueller/update-package' into mueller/master
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:
commit
d0cba24a37
@ -37,7 +37,6 @@
|
||||
#include "mission/devices/IMTQHandler.h"
|
||||
#include "mission/devices/SyrlinksHkHandler.h"
|
||||
#include "mission/devices/MGMHandlerLIS3MDL.h"
|
||||
#include "mission/devices/MGMHandlerRM3100.h"
|
||||
#include "mission/devices/PlocMPSoCHandler.h"
|
||||
#include "mission/devices/RadiationSensorHandler.h"
|
||||
#include "mission/devices/RwHandler.h"
|
||||
@ -55,6 +54,7 @@
|
||||
#include "fsfw_hal/linux/uart/UartComIF.h"
|
||||
#include "fsfw_hal/linux/uart/UartCookie.h"
|
||||
#include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h"
|
||||
#include "fsfw_hal/devicehandlers/MgmRM3100Handler.h"
|
||||
#include "fsfw_hal/linux/i2c/I2cCookie.h"
|
||||
#include "fsfw_hal/linux/i2c/I2cComIF.h"
|
||||
#include "fsfw_hal/linux/spi/SpiCookie.h"
|
||||
@ -454,7 +454,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF *gpioComIF, UartComI
|
||||
|
||||
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);
|
||||
auto mgmRm3100Handler = new MGMHandlerRM3100(objects::MGM_1_RM3100_HANDLER,
|
||||
auto mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_1_RM3100_HANDLER,
|
||||
objects::SPI_COM_IF, spiCookie, pcduSwitches::SwitcherList::ACS_BOARD_SIDE_A);
|
||||
mgmRm3100Handler->setStartUpImmediately();
|
||||
|
||||
@ -466,7 +466,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF *gpioComIF, UartComI
|
||||
|
||||
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);
|
||||
mgmRm3100Handler = new MGMHandlerRM3100(objects::MGM_3_RM3100_HANDLER,
|
||||
mgmRm3100Handler = new MgmRM3100Handler(objects::MGM_3_RM3100_HANDLER,
|
||||
objects::SPI_COM_IF, spiCookie, pcduSwitches::SwitcherList::ACS_BOARD_SIDE_B);
|
||||
mgmRm3100Handler->setStartUpImmediately();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
GPSHyperionHandler.cpp
|
||||
MGMHandlerLIS3MDL.cpp
|
||||
MGMHandlerRM3100.cpp
|
||||
GomspaceDeviceHandler.cpp
|
||||
Tmp1075Handler.cpp
|
||||
PCDUHandler.cpp
|
||||
|
@ -1,364 +0,0 @@
|
||||
#include "MGMHandlerRM3100.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
|
||||
MGMHandlerRM3100::MGMHandlerRM3100(object_id_t objectId,
|
||||
object_id_t deviceCommunication, CookieIF* comCookie, uint8_t switchId):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
primaryDataset(this), switchId(switchId) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(5);
|
||||
#endif
|
||||
}
|
||||
|
||||
MGMHandlerRM3100::~MGMHandlerRM3100() {}
|
||||
|
||||
void MGMHandlerRM3100::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 OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
setMode(MODE_NORMAL);
|
||||
#else
|
||||
setMode(_MODE_TO_ON);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::doShutDown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
size_t commandLen = 0;
|
||||
switch(internalState) {
|
||||
case(InternalState::NONE):
|
||||
case(InternalState::NORMAL): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(InternalState::CONFIGURE_CMM): {
|
||||
*id = RM3100::CONFIGURE_CMM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::READ_CMM): {
|
||||
*id = RM3100::READ_CMM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_CONFIGURE_TMRC): {
|
||||
commandBuffer[0] = RM3100::TMRC_DEFAULT_VALUE;
|
||||
commandLen = 1;
|
||||
*id = RM3100::CONFIGURE_TMRC;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_READ_TMRC): {
|
||||
*id = RM3100::READ_TMRC;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Might be a configuration error
|
||||
sif::warning << "MGMHandlerRM3100::buildTransitionDeviceCommand: Unknown internal state!" <<
|
||||
std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
return buildCommandFromCommand(*id, commandBuffer, commandLen);
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(RM3100::CONFIGURE_CMM): {
|
||||
commandBuffer[0] = RM3100::CMM_REGISTER;
|
||||
commandBuffer[1] = RM3100::CMM_VALUE;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case(RM3100::READ_CMM): {
|
||||
commandBuffer[0] = RM3100::CMM_REGISTER | RM3100::READ_MASK;
|
||||
commandBuffer[1] = 0;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case(RM3100::CONFIGURE_TMRC): {
|
||||
return handleTmrcConfigCommand(deviceCommand, commandData, commandDataLen);
|
||||
}
|
||||
case(RM3100::READ_TMRC): {
|
||||
commandBuffer[0] = RM3100::TMRC_REGISTER | RM3100::READ_MASK;
|
||||
commandBuffer[1] = 0;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case(RM3100::CONFIGURE_CYCLE_COUNT): {
|
||||
return handleCycleCountConfigCommand(deviceCommand, commandData, commandDataLen);
|
||||
}
|
||||
case(RM3100::READ_CYCLE_COUNT): {
|
||||
commandBuffer[0] = RM3100::CYCLE_COUNT_START_REGISTER | RM3100::READ_MASK;
|
||||
std::memset(commandBuffer + 1, 0, 6);
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 7;
|
||||
break;
|
||||
}
|
||||
case(RM3100::READ_DATA): {
|
||||
commandBuffer[0] = RM3100::MEASUREMENT_REG_START | RM3100::READ_MASK;
|
||||
std::memset(commandBuffer + 1, 0, 9);
|
||||
rawPacketLen = 10;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
*id = RM3100::READ_DATA;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::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 HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(id) {
|
||||
case(RM3100::CONFIGURE_CMM):
|
||||
case(RM3100::CONFIGURE_CYCLE_COUNT):
|
||||
case(RM3100::CONFIGURE_TMRC): {
|
||||
/* We can only check whether write was successful with read operation. */
|
||||
if(mode == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(RM3100::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::bitClear(&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(RM3100::READ_TMRC): {
|
||||
if(packet[1] == tmrcRegValue) {
|
||||
commandExecuted = true;
|
||||
/* Reading TMRC was commanded. Trigger event to inform ground. */
|
||||
if(mode != _MODE_START_UP) {
|
||||
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Attempt reconfiguration. */
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(RM3100::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(mode != _MODE_START_UP) {
|
||||
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
|
||||
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(RM3100::READ_DATA): {
|
||||
result = handleDataReadout(packet);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::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] = RM3100::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 HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::handleCycleCommand(bool oneCycleValue,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
RM3100::CycleCountCommand command(oneCycleValue);
|
||||
ReturnValue_t result = command.deSerialize(&commandData, &commandDataLen,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if(result != HasReturnvaluesIF::RETURN_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 HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData, size_t commandDataLen) {
|
||||
if(commandData == nullptr or commandDataLen != 1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
commandBuffer[0] = RM3100::TMRC_REGISTER;
|
||||
commandBuffer[1] = commandData[0];
|
||||
tmrcRegValue = commandData[0];
|
||||
rawPacketLen = 2;
|
||||
rawPacket = commandBuffer;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CMM, 3);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CMM, 3);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_TMRC, 3);
|
||||
insertInCommandAndReplyMap(RM3100::READ_TMRC, 3);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CYCLE_COUNT, 3);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CYCLE_COUNT, 3);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::modeChanged(void) {
|
||||
internalState = InternalState::NONE;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t MGMHandlerRM3100::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 25000;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) {
|
||||
*switches = &switchId;
|
||||
*numberOfSwitches = 1;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::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[3] << 8)) >> 8;
|
||||
|
||||
/* Now scale to physical value in microtesla */
|
||||
float fieldStrengthX = fieldStrengthRawX * scaleFactorX;
|
||||
float fieldStrengthY = fieldStrengthRawY * scaleFactorX;
|
||||
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
|
||||
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
if(debugDivider->checkAndIncrement()) {
|
||||
sif::info << "MGMHandlerRM3100: Magnetic field strength in"
|
||||
" microtesla:" << std::endl;
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
|
||||
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
|
||||
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* TODO: Sanity check on values */
|
||||
PoolReadGuard readGuard(&primaryDataset);
|
||||
if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
primaryDataset.fieldStrengthX = fieldStrengthX;
|
||||
primaryDataset.fieldStrengthY = fieldStrengthY;
|
||||
primaryDataset.fieldStrengthZ = fieldStrengthZ;
|
||||
primaryDataset.setValidity(true, true);
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "devices/powerSwitcherList.h"
|
||||
#include "devicedefinitions/MGMHandlerRM3100Definitions.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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 MGMHandlerRM3100: 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);
|
||||
|
||||
MGMHandlerRM3100(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF* comCookie, uint8_t switchId);
|
||||
virtual ~MGMHandlerRM3100();
|
||||
|
||||
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;
|
||||
ReturnValue_t getSwitches(const uint8_t **switches,
|
||||
uint8_t *numberOfSwitches) override;
|
||||
|
||||
void fillCommandAndReplyMap() override;
|
||||
void modeChanged(void) override;
|
||||
uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &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;
|
||||
RM3100::Rm3100PrimaryDataset primaryDataset;
|
||||
|
||||
uint8_t commandBuffer[10];
|
||||
uint8_t commandBufferLen = 0;
|
||||
|
||||
uint8_t cmmRegValue = RM3100::CMM_VALUE;
|
||||
uint8_t tmrcRegValue = RM3100::TMRC_DEFAULT_VALUE;
|
||||
uint16_t cycleCountRegValueX = RM3100::CYCLE_COUNT_VALUE;
|
||||
uint16_t cycleCountRegValueY = RM3100::CYCLE_COUNT_VALUE;
|
||||
uint16_t cycleCountRegValueZ = RM3100::CYCLE_COUNT_VALUE;
|
||||
float scaleFactorX = 1 / RM3100::DEFAULT_GAIN;
|
||||
float scaleFactorY = 1 / RM3100::DEFAULT_GAIN;
|
||||
float scaleFactorZ = 1 / RM3100::DEFAULT_GAIN;
|
||||
|
||||
uint8_t switchId;
|
||||
|
||||
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);
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
PeriodicOperationDivider* debugDivider;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ */
|
@ -1,132 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
|
||||
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <fsfw/serialize/SerialLinkedListAdapter.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace RM3100 {
|
||||
|
||||
/* 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_75HZ_VALUE;
|
||||
|
||||
static constexpr uint8_t MEASUREMENT_REG_START = 0x24;
|
||||
static constexpr uint8_t BIST_REGISTER = 0x33;
|
||||
static constexpr uint8_t DATA_READY_VAL = 0b1000'0000;
|
||||
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_STRENGTH_X,
|
||||
FIELD_STRENGTH_Y,
|
||||
FIELD_STRENGTH_Z,
|
||||
};
|
||||
|
||||
class Rm3100PrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> {
|
||||
public:
|
||||
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
|
||||
|
||||
Rm3100PrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
|
||||
|
||||
// Field strengths in micro Tesla.
|
||||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */
|
Loading…
Reference in New Issue
Block a user