fixed merge conflicts
This commit is contained in:
@ -1,38 +1,55 @@
|
||||
#include <mission/devices/GyroL3GD20Handler.h>
|
||||
#include <fsfw/datapool/PoolReadHelper.h>
|
||||
#include "GyroL3GD20Handler.h"
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
GyroHandler::GyroHandler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
|
||||
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
dataset(this) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(5);
|
||||
#endif
|
||||
}
|
||||
|
||||
GyroHandler::~GyroHandler() {}
|
||||
GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
|
||||
|
||||
void GyroHandler::doStartUp() {
|
||||
if(internalState == InternalState::STATE_NONE) {
|
||||
internalState = InternalState::STATE_CONFIGURE;
|
||||
void GyroHandlerL3GD20H::doStartUp() {
|
||||
if(internalState == InternalState::NONE) {
|
||||
internalState = InternalState::CONFIGURE;
|
||||
}
|
||||
|
||||
if(internalState == InternalState::STATE_CONFIGURE) {
|
||||
if(internalState == InternalState::CONFIGURE) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::STATE_NORMAL;
|
||||
internalState = InternalState::CHECK_REGS;
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(internalState == InternalState::CHECK_REGS) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::NORMAL;
|
||||
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
setMode(MODE_NORMAL);
|
||||
#else
|
||||
setMode(_MODE_TO_ON);
|
||||
#endif
|
||||
commandExecuted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GyroHandler::doShutDown() {
|
||||
void GyroHandlerL3GD20H::doShutDown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
switch(internalState) {
|
||||
case(InternalState::STATE_NONE):
|
||||
case(InternalState::STATE_NORMAL): {
|
||||
case(InternalState::NONE):
|
||||
case(InternalState::NORMAL): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(InternalState::STATE_CONFIGURE): {
|
||||
case(InternalState::CONFIGURE): {
|
||||
*id = L3GD20H::CONFIGURE_CTRL_REGS;
|
||||
uint8_t command [5];
|
||||
command[0] = L3GD20H::CTRL_REG_1_VAL;
|
||||
@ -41,10 +58,13 @@ ReturnValue_t GyroHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
command[3] = L3GD20H::CTRL_REG_4_VAL;
|
||||
command[4] = L3GD20H::CTRL_REG_5_VAL;
|
||||
return buildCommandFromCommand(*id, command, 5);
|
||||
break;
|
||||
}
|
||||
case(InternalState::CHECK_REGS): {
|
||||
*id = L3GD20H::READ_REGS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
default:
|
||||
// might be a configuration error.
|
||||
/* Might be a configuration error. */
|
||||
sif::debug << "GyroHandler::buildTransitionDeviceCommand: Unknown "
|
||||
<< "internal state!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -52,12 +72,12 @@ ReturnValue_t GyroHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
*id = L3GD20H::READ_REGS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandler::buildCommandFromCommand(
|
||||
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
@ -120,24 +140,25 @@ ReturnValue_t GyroHandler::buildCommandFromCommand(
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandler::scanForReply(const uint8_t *start, size_t len,
|
||||
ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
// SPI, ID will always be the one of the last sent command.
|
||||
/* For SPI, the ID will always be the one of the last sent command. */
|
||||
*foundId = this->getPendingCommand();
|
||||
*foundLen = this->rawPacketLen;
|
||||
|
||||
// Data with SPI Interface has always this answer
|
||||
/* Data with SPI Interface has always this answer */
|
||||
if (start[0] == 0b11111111) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(id) {
|
||||
case(L3GD20H::CONFIGURE_CTRL_REGS): {
|
||||
commandExecuted = true;
|
||||
break;
|
||||
}
|
||||
case(L3GD20H::READ_CTRL_REGS): {
|
||||
@ -147,18 +168,23 @@ ReturnValue_t GyroHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
commandExecuted = true;
|
||||
}
|
||||
else {
|
||||
// Attempt reconfiguration.
|
||||
internalState = InternalState::STATE_CONFIGURE;
|
||||
/* Attempt reconfiguration. */
|
||||
internalState = InternalState::CONFIGURE;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(L3GD20H::READ_START): {
|
||||
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];
|
||||
|
||||
@ -171,8 +197,25 @@ ReturnValue_t GyroHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
|
||||
int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX];
|
||||
float temperature = 25.0 + temperaturOffset;
|
||||
#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 << "GyroHandlerL3GD20H: Angular velocities in degrees per second:" <<
|
||||
std::endl;
|
||||
sif::info << "X: " << angVelocX << " \xC2\xB0" << std::endl;
|
||||
sif::info << "Y: " << angVelocY << " \xC2\xB0" << std::endl;
|
||||
sif::info << "Z: " << angVelocZ << " \xC2\xB0" << std::endl;
|
||||
#else
|
||||
sif::printInfo("GyroHandlerL3GD20H: Angular velocities in degrees per second:\n");
|
||||
sif::printInfo("X: %f " "\xC2\xB0" "T\n", angVelocX);
|
||||
sif::printInfo("Y: %f " "\xC2\xB0" "T\n", angVelocY);
|
||||
sif::printInfo("Z: %f " "\xC2\xB0" "T\n", angVelocZ);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
PoolReadHelper readSet(&dataset);
|
||||
PoolReadGuard readSet(&dataset);
|
||||
if(readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
dataset.angVelocX = angVelocX;
|
||||
dataset.angVelocY = angVelocY;
|
||||
@ -189,11 +232,11 @@ ReturnValue_t GyroHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
}
|
||||
|
||||
|
||||
uint32_t GyroHandler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 5000;
|
||||
uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 10000;
|
||||
}
|
||||
|
||||
ReturnValue_t GyroHandler::initializeLocalDataPool(
|
||||
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X,
|
||||
new PoolEntry<float>({0.0}));
|
||||
@ -206,12 +249,12 @@ ReturnValue_t GyroHandler::initializeLocalDataPool(
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void GyroHandler::fillCommandAndReplyMap() {
|
||||
void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(L3GD20H::READ_REGS, 1, &dataset);
|
||||
insertInCommandAndReplyMap(L3GD20H::CONFIGURE_CTRL_REGS, 1);
|
||||
insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1);
|
||||
}
|
||||
|
||||
void GyroHandler::modeChanged() {
|
||||
internalState = InternalState::STATE_NONE;
|
||||
void GyroHandlerL3GD20H::modeChanged() {
|
||||
internalState = InternalState::NONE;
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include "devicedefinitions/GyroL3GD20Definitions.h"
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Device Handler for the L3GD20H gyroscope sensor
|
||||
@ -10,12 +14,14 @@
|
||||
* @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 GyroHandler: public DeviceHandlerBase {
|
||||
class GyroHandlerL3GD20H: public DeviceHandlerBase {
|
||||
public:
|
||||
GyroHandler(object_id_t objectId, object_id_t deviceCommunication,
|
||||
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF* comCookie);
|
||||
virtual ~GyroHandler();
|
||||
virtual ~GyroHandlerL3GD20H();
|
||||
|
||||
protected:
|
||||
|
||||
@ -41,14 +47,15 @@ protected:
|
||||
LocalDataPoolManager &poolManager) override;
|
||||
|
||||
private:
|
||||
L3GD20H::GyroPrimaryDataset dataset;
|
||||
GyroPrimaryDataset dataset;
|
||||
|
||||
enum class InternalState {
|
||||
STATE_NONE,
|
||||
STATE_CONFIGURE,
|
||||
STATE_NORMAL
|
||||
NONE,
|
||||
CONFIGURE,
|
||||
CHECK_REGS,
|
||||
NORMAL
|
||||
};
|
||||
InternalState internalState = InternalState::STATE_NONE;
|
||||
InternalState internalState = InternalState::NONE;
|
||||
bool commandExecuted = false;
|
||||
|
||||
uint8_t statusReg = 0;
|
||||
@ -62,6 +69,10 @@ private:
|
||||
uint8_t commandBuffer[L3GD20H::READ_LEN + 1];
|
||||
|
||||
float scaleFactor = static_cast<float>(L3GD20H::RANGE_DPS_00) / INT16_MAX;
|
||||
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
PeriodicOperationDivider* debugDivider = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
#include <fsfw/datapool/PoolReadHelper.h>
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include "MGMHandlerLIS3MDL.h"
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
|
||||
MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId,
|
||||
object_id_t deviceCommunication, CookieIF* comCookie):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
dataset(this) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(10);
|
||||
debugDivider = new PeriodicOperationDivider(5);
|
||||
#endif
|
||||
/* Set to default values right away. */
|
||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||
@ -44,8 +45,11 @@ void MGMHandlerLIS3MDL::doStartUp() {
|
||||
/* Set up cached registers which will be used to configure the MGM. */
|
||||
if(commandExecuted) {
|
||||
commandExecuted = false;
|
||||
/* Replace _MODE_TO_ON with MODE_NORMAL to jump to normal mode quickly */
|
||||
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
setMode(MODE_NORMAL);
|
||||
#else
|
||||
setMode(_MODE_TO_ON);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -299,7 +303,7 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
PoolReadHelper readHelper(&dataset);
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
dataset.fieldStrengthX = mgmX;
|
||||
dataset.fieldStrengthY = mgmY;
|
||||
@ -459,7 +463,7 @@ void MGMHandlerLIS3MDL::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||
}
|
||||
|
||||
uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 30000;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::modeChanged(void) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include "MGMHandlerRM3100.h"
|
||||
|
||||
#include <fsfw/globalfunctions/bitutility.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerMessage.h>
|
||||
#include <fsfw/objectmanager/SystemObjectIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
@ -7,345 +9,355 @@
|
||||
|
||||
MGMHandlerRM3100::MGMHandlerRM3100(object_id_t objectId,
|
||||
object_id_t deviceCommunication, CookieIF* comCookie):
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
primaryDataset(this) {
|
||||
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
|
||||
primaryDataset(this) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(10);
|
||||
debugDivider = new PeriodicOperationDivider(5);
|
||||
#endif
|
||||
}
|
||||
|
||||
MGMHandlerRM3100::~MGMHandlerRM3100() {}
|
||||
|
||||
void MGMHandlerRM3100::doStartUp() {
|
||||
if(internalState == InternalState::STATE_NONE) {
|
||||
internalState = InternalState::STATE_CONFIGURE_CMM;
|
||||
}
|
||||
|
||||
if(internalState == InternalState::STATE_CONFIGURE_CMM) {
|
||||
internalState = InternalState::STATE_READ_CMM;
|
||||
}
|
||||
else if(internalState == InternalState::STATE_READ_CMM) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
}
|
||||
}
|
||||
|
||||
if(internalState == InternalState::STATE_CONFIGURE_TMRC) {
|
||||
internalState = InternalState::STATE_READ_TMRC;
|
||||
}
|
||||
else if(internalState == InternalState::STATE_READ_TMRC) {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::STATE_NORMAL;
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
}
|
||||
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);
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t *id) {
|
||||
switch(internalState) {
|
||||
case(InternalState::STATE_NONE):
|
||||
case(InternalState::STATE_NORMAL): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case(InternalState::STATE_CONFIGURE_CMM): {
|
||||
*id = RM3100::CONFIGURE_CMM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_READ_CMM): {
|
||||
*id = RM3100::READ_CMM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_CONFIGURE_TMRC): {
|
||||
*id = RM3100::CONFIGURE_TMRC;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_READ_TMRC): {
|
||||
*id = RM3100::READ_TMRC;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// might be a configuration error.
|
||||
sif::debug << "GyroHandler::buildTransitionDeviceCommand: Unknown "
|
||||
<< "internal state!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
DeviceCommandId_t *id) {
|
||||
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): {
|
||||
*id = RM3100::CONFIGURE_TMRC;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_READ_TMRC): {
|
||||
*id = RM3100::READ_TMRC;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* Might be a configuration error. */
|
||||
sif::debug << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!" <<
|
||||
std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
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) {
|
||||
size_t *foundLen) {
|
||||
|
||||
// SPI, ID will always be the one of the last sent command.
|
||||
*foundId = this->getPendingCommand();
|
||||
*foundLen = this->rawPacketLen;
|
||||
|
||||
// Data with SPI Interface has always this answer
|
||||
if (start[0] == 0b11111111) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
/* 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 sucessful with read operation.
|
||||
break;
|
||||
}
|
||||
case(RM3100::READ_CMM): {
|
||||
if(packet[1] == cmmRegValue) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
else {
|
||||
// Attempt reconfiguration.
|
||||
internalState = InternalState::STATE_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;
|
||||
}
|
||||
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;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::handleCycleCountConfigCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if(commandData == nullptr) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
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;
|
||||
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) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
if(commandData == nullptr) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
if(commandDataLen != 1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
if(commandDataLen != 1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
commandBuffer[0] = RM3100::TMRC_REGISTER;
|
||||
commandBuffer[1] = commandData[1];
|
||||
rawPacketLen = 2;
|
||||
rawPacket = commandBuffer;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
commandBuffer[0] = RM3100::TMRC_REGISTER;
|
||||
commandBuffer[1] = commandData[1];
|
||||
rawPacketLen = 2;
|
||||
rawPacket = commandBuffer;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CMM, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CMM, 1);
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CMM, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CMM, 1);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_TMRC, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_TMRC, 1);
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_TMRC, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_TMRC, 1);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CYCLE_COUNT, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CYCLE_COUNT, 1);
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CYCLE_COUNT, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CYCLE_COUNT, 1);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 1, &primaryDataset);
|
||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 1, &primaryDataset);
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::modeChanged(void) {
|
||||
internalState = InternalState::STATE_NONE;
|
||||
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;
|
||||
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 5000;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::handleDataReadout(const uint8_t *packet) {
|
||||
// analyze data here.
|
||||
// Field strengths in micro Tesla
|
||||
int32_t fieldStrengthX = (packet[1] << 16 | packet[2] << 8 | packet[3])
|
||||
* scaleFactorX;
|
||||
int32_t fieldStrengthY = (packet[4] << 16 | packet[5] << 8 | packet[6])
|
||||
* scaleFactorY;
|
||||
int32_t fieldStrengthZ = (packet[7] << 16 | packet[8] << 8 | packet[9])
|
||||
* scaleFactorZ;
|
||||
/* 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 << "MGMHandlerLIS3: Magnetic field strength in"
|
||||
" microtesla:" << std::endl;
|
||||
// Set terminal to utf-8 if there is an issue with micro printout.
|
||||
sif::info << "X: " << fieldStrengthX << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Y: " << fieldStrengthY << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Z: " << fieldStrengthZ << " \xC2\xB5T" << std::endl;
|
||||
}
|
||||
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 << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Y: " << fieldStrengthY << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Z: " << fieldStrengthZ << " \xC2\xB5T" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
ReturnValue_t result = primaryDataset.read();
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
primaryDataset.fieldStrengthX = fieldStrengthX;
|
||||
primaryDataset.fieldStrengthY = fieldStrengthY;
|
||||
primaryDataset.fieldStrengthZ = fieldStrengthZ;
|
||||
primaryDataset.setValidity(true, true);
|
||||
result = primaryDataset.commit();
|
||||
}
|
||||
return result;
|
||||
/* 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;
|
||||
}
|
||||
|
@ -61,18 +61,18 @@ protected:
|
||||
private:
|
||||
|
||||
enum class InternalState {
|
||||
STATE_NONE,
|
||||
STATE_CONFIGURE_CMM,
|
||||
STATE_READ_CMM,
|
||||
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,
|
||||
STATE_NORMAL
|
||||
NORMAL
|
||||
};
|
||||
InternalState internalState = InternalState::STATE_NONE;
|
||||
InternalState internalState = InternalState::NONE;
|
||||
bool commandExecuted = false;
|
||||
RM3100::Rm3100PrimaryDataset primaryDataset;
|
||||
|
||||
|
@ -49,7 +49,7 @@ ReturnValue_t PCDUHandler::initialize() {
|
||||
sif::error << "PCDUHandler::initialize: Invalid pdu2Handler" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
result = pdu2Handler->getSubscriptionInterface()->subscribeForSetUpdateMessages(
|
||||
result = pdu2Handler->getSubscriptionInterface()->subscribeForSetUpdateMessage(
|
||||
PDU2::HK_TABLE_DATA_SET_ID, this->getObjectId(), commandQueue->getId(), true);
|
||||
if (result != RETURN_OK) {
|
||||
sif::error << "PCDUHandler::initialize: Failed to subscribe for set update messages from "
|
||||
@ -63,7 +63,7 @@ ReturnValue_t PCDUHandler::initialize() {
|
||||
sif::error << "PCDUHandler::initialize: Invalid pdu1Handler" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
result = pdu1Handler->getSubscriptionInterface()->subscribeForSetUpdateMessages(
|
||||
result = pdu1Handler->getSubscriptionInterface()->subscribeForSetUpdateMessage(
|
||||
PDU1::HK_TABLE_DATA_SET_ID, this->getObjectId(), commandQueue->getId(), true);
|
||||
if (result != RETURN_OK) {
|
||||
sif::error << "PCDUHandler::initialize: Failed to subscribe for set update messages from "
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <mission/devices/SyrlinksHkHandler.h>
|
||||
#include <fsfwconfig/OBSWConfig.h>
|
||||
#include <fsfw/globalfunctions/CRC.h>
|
||||
#include <fsfw/datapool/PoolReadHelper.h>
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfwconfig/OBSWConfig.h>
|
||||
|
||||
SyrlinksHkHandler::SyrlinksHkHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) :
|
||||
@ -364,7 +364,7 @@ ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size
|
||||
}
|
||||
|
||||
void SyrlinksHkHandler::parseRxStatusRegistersReply(const uint8_t* packet) {
|
||||
PoolReadHelper readHelper(&rxDataset);
|
||||
PoolReadGuard readHelper(&rxDataset);
|
||||
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
|
||||
rxDataset.rxStatus = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
||||
offset += 2;
|
||||
@ -396,7 +396,7 @@ void SyrlinksHkHandler::parseRxStatusRegistersReply(const uint8_t* packet) {
|
||||
}
|
||||
|
||||
void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) {
|
||||
PoolReadHelper readHelper(&txDataset);
|
||||
PoolReadGuard readHelper(&txDataset);
|
||||
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
|
||||
txDataset.txStatus = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
|
||||
@ -406,7 +406,7 @@ void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) {
|
||||
}
|
||||
|
||||
void SyrlinksHkHandler::parseTxWaveformReply(const uint8_t* packet) {
|
||||
PoolReadHelper readHelper(&txDataset);
|
||||
PoolReadGuard readHelper(&txDataset);
|
||||
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
|
||||
txDataset.txWaveform = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
|
||||
@ -416,7 +416,7 @@ void SyrlinksHkHandler::parseTxWaveformReply(const uint8_t* packet) {
|
||||
}
|
||||
|
||||
void SyrlinksHkHandler::parseAgcLowByte(const uint8_t* packet) {
|
||||
PoolReadHelper readHelper(&txDataset);
|
||||
PoolReadGuard readHelper(&txDataset);
|
||||
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
|
||||
txDataset.txAgcValue = agcValueHighByte << 8 | convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
|
||||
@ -425,7 +425,7 @@ void SyrlinksHkHandler::parseAgcLowByte(const uint8_t* packet) {
|
||||
}
|
||||
|
||||
void SyrlinksHkHandler::parseAgcHighByte(const uint8_t* packet) {
|
||||
PoolReadHelper readHelper(&txDataset);
|
||||
PoolReadGuard readHelper(&txDataset);
|
||||
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
|
||||
agcValueHighByte = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
#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 {
|
||||
|
||||
/* Actual size is 15 but we round up a bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
||||
|
||||
static constexpr uint8_t READ_MASK = 0b1000'0000;
|
||||
|
||||
static constexpr uint8_t AUTO_INCREMENT_MASK = 0b0100'0000;
|
||||
@ -22,7 +26,7 @@ static constexpr uint8_t CTRL_REG_3 = 0b0010'0010;
|
||||
static constexpr uint8_t CTRL_REG_4 = 0b0010'0011;
|
||||
static constexpr uint8_t CTRL_REG_5 = 0b0010'0100;
|
||||
|
||||
// Register 1
|
||||
/* 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;
|
||||
@ -35,7 +39,7 @@ 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
|
||||
/* 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;
|
||||
@ -47,10 +51,10 @@ static constexpr uint8_t SET_HPCF_0 = 1;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_2_VAL = 0b0000'0000;
|
||||
|
||||
// Register 3
|
||||
/* Register 3 */
|
||||
static constexpr uint8_t CTRL_REG_3_VAL = 0b0000'0000;
|
||||
|
||||
// Register 4
|
||||
/* 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;
|
||||
@ -60,15 +64,16 @@ 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;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_4_VAL = 0b0000'0000;
|
||||
/* Enable big endian data format */
|
||||
static constexpr uint8_t CTRL_REG_4_VAL = SET_BLE;
|
||||
|
||||
// Register 5
|
||||
/* Register 5 */
|
||||
static constexpr uint8_t SET_REBOOT_MEM = 1 << 7;
|
||||
static constexpr uint8_t SET_FIFO_ENB = 1 << 6;
|
||||
|
||||
static constexpr uint8_t CTRL_REG_5_VAL = 0b0000'0000;
|
||||
|
||||
// In degrees per second (DPS) for now.
|
||||
/* Possible range values in degrees per second (DPS). */
|
||||
static constexpr uint16_t RANGE_DPS_00 = 245;
|
||||
static constexpr uint16_t RANGE_DPS_01 = 500;
|
||||
static constexpr uint16_t RANGE_DPS_11 = 2000;
|
||||
@ -76,16 +81,16 @@ static constexpr uint16_t RANGE_DPS_11 = 2000;
|
||||
static constexpr uint8_t READ_START = CTRL_REG_1;
|
||||
static constexpr size_t READ_LEN = 14;
|
||||
|
||||
// Indexing
|
||||
/* 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_L = 9;
|
||||
static constexpr uint8_t OUT_X_H = 10;
|
||||
static constexpr uint8_t OUT_Y_L = 11;
|
||||
static constexpr uint8_t OUT_Y_H = 12;
|
||||
static constexpr uint8_t OUT_Z_L = 13;
|
||||
static constexpr uint8_t OUT_Z_H = 14;
|
||||
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 */
|
||||
@ -103,27 +108,33 @@ enum GyroPoolIds: lp_id_t {
|
||||
TEMPERATURE
|
||||
};
|
||||
|
||||
class GyroPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> {
|
||||
public:
|
||||
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, GYRO_DATASET_ID) {}
|
||||
|
||||
GyroPrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, GYRO_DATASET_ID)) {}
|
||||
|
||||
// Angular velocities in degrees per second (DPS)
|
||||
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId,
|
||||
ANG_VELOC_X, this);
|
||||
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId,
|
||||
ANG_VELOC_Y, this);
|
||||
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId,
|
||||
ANG_VELOC_Z, this);
|
||||
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
|
||||
TEMPERATURE, this);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class GyroPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> {
|
||||
public:
|
||||
|
||||
/** Constructor for data users like controllers */
|
||||
GyroPrimaryDataset(object_id_t mgmId):
|
||||
StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
|
||||
setAllVariablesReadOnly();
|
||||
}
|
||||
|
||||
/* 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:
|
||||
|
||||
friend class GyroHandlerL3GD20H;
|
||||
/** Constructor for the data creator */
|
||||
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
|
||||
};
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
COIL_Z_CURRENT_A, this);
|
||||
/** All temperatures in [<5B>C] */
|
||||
lp_var_t<uint16_t> coilXTemperature = lp_var_t<uint16_t>(sid.objectId,
|
||||
COIL_X_TEMPEARTURE, this);
|
||||
COIL_X_TEMPERATURE, this);
|
||||
lp_var_t<uint16_t> coilYTemperature = lp_var_t<uint16_t>(sid.objectId,
|
||||
COIL_Y_TEMPERATURE, this);
|
||||
lp_var_t<uint16_t> coilZTemperature = lp_var_t<uint16_t>(sid.objectId,
|
||||
|
@ -15,6 +15,9 @@ enum opMode {
|
||||
LOW, MEDIUM, HIGH, ULTRA
|
||||
};
|
||||
|
||||
/* Actually 15, we just round up a bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 16;
|
||||
|
||||
static constexpr uint8_t GAUSS_TO_MICROTESLA_FACTOR = 100;
|
||||
|
||||
static const DeviceCommandId_t SETUP_MGM = 0x00;
|
||||
|
@ -9,6 +9,9 @@
|
||||
|
||||
namespace RM3100 {
|
||||
|
||||
/* Actually 10, we round up a little bit */
|
||||
static constexpr size_t MAX_BUFFER_SIZE = 12;
|
||||
|
||||
static constexpr uint8_t READ_MASK = 0b1000'0000;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
Reference in New Issue
Block a user