Merge pull request 'Improvements for devices' (#17) from mueller/acs-board-improvements into eive/develop

Reviewed-on: eive/fsfw#17
This commit is contained in:
Jakob Meier 2021-09-23 15:59:20 +02:00
commit ed2263b5f7
8 changed files with 123 additions and 65 deletions

View File

@ -3,11 +3,11 @@
#include "fsfw/datapool/PoolReadGuard.h" #include "fsfw/datapool/PoolReadGuard.h"
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
CookieIF *comCookie, uint8_t switchId, uint32_t transitionDelayMs): CookieIF *comCookie, uint32_t transitionDelayMs):
DeviceHandlerBase(objectId, deviceCommunication, comCookie), DeviceHandlerBase(objectId, deviceCommunication, comCookie),
switchId(switchId), transitionDelayMs(transitionDelayMs), dataset(this) { transitionDelayMs(transitionDelayMs), dataset(this) {
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1 #if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
debugDivider = new PeriodicOperationDivider(5); debugDivider = new PeriodicOperationDivider(3);
#endif #endif
} }
@ -215,11 +215,32 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
PoolReadGuard readSet(&dataset); PoolReadGuard readSet(&dataset);
if(readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) { if(readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if(std::abs(angVelocX) < this->absLimitX) {
dataset.angVelocX = angVelocX; dataset.angVelocX = angVelocX;
dataset.angVelocX.setValid(true);
}
else {
dataset.angVelocX.setValid(false);
}
if(std::abs(angVelocY) < this->absLimitY) {
dataset.angVelocY = angVelocY; dataset.angVelocY = angVelocY;
dataset.angVelocY.setValid(true);
}
else {
dataset.angVelocY.setValid(false);
}
if(std::abs(angVelocZ) < this->absLimitZ) {
dataset.angVelocZ = angVelocZ; dataset.angVelocZ = angVelocZ;
dataset.angVelocZ.setValid(true);
}
else {
dataset.angVelocZ.setValid(false);
}
dataset.temperature = temperature; dataset.temperature = temperature;
dataset.setValidity(true, true); dataset.temperature.setValid(true);
} }
break; break;
} }
@ -234,7 +255,7 @@ uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
return this->transitionDelayMs; return this->transitionDelayMs;
} }
void GyroHandlerL3GD20H::setGoNormalModeAtStartup() { void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) {
this->goNormalModeImmediately = true; this->goNormalModeImmediately = true;
} }
@ -256,3 +277,9 @@ void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
void GyroHandlerL3GD20H::modeChanged() { void GyroHandlerL3GD20H::modeChanged() {
internalState = InternalState::NONE; internalState = InternalState::NONE;
} }
void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) {
this->absLimitX = limitX;
this->absLimitY = limitY;
this->absLimitZ = limitZ;
}

View File

@ -19,13 +19,22 @@
class GyroHandlerL3GD20H: public DeviceHandlerBase { class GyroHandlerL3GD20H: public DeviceHandlerBase {
public: public:
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie, uint8_t switchId, uint32_t transitionDelayMs = 10000); CookieIF* comCookie, uint32_t transitionDelayMs);
virtual ~GyroHandlerL3GD20H(); virtual ~GyroHandlerL3GD20H();
/**
* Set the absolute limit for the values on the axis in degrees per second.
* The dataset values will be marked as invalid if that limit is exceeded
* @param xLimit
* @param yLimit
* @param zLimit
*/
void setAbsoluteLimits(float limitX, float limitY, float limitZ);
/** /**
* @brief Configure device handler to go to normal mode immediately * @brief Configure device handler to go to normal mode immediately
*/ */
void setGoNormalModeAtStartup(); void setToGoToNormalMode(bool enable);
protected: protected:
/* DeviceHandlerBase overrides */ /* DeviceHandlerBase overrides */
@ -40,12 +49,12 @@ protected:
size_t commandDataLen) override; size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, ReturnValue_t scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) override; DeviceCommandId_t *foundId, size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) override; const uint8_t *packet) override;
void fillCommandAndReplyMap() override; void fillCommandAndReplyMap() override;
void modeChanged() override; void modeChanged() override;
uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override; virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override; LocalDataPoolManager &poolManager) override;
@ -54,6 +63,10 @@ private:
uint32_t transitionDelayMs = 0; uint32_t transitionDelayMs = 0;
GyroPrimaryDataset dataset; GyroPrimaryDataset dataset;
float absLimitX = L3GD20H::RANGE_DPS_00;
float absLimitY = L3GD20H::RANGE_DPS_00;
float absLimitZ = L3GD20H::RANGE_DPS_00;
enum class InternalState { enum class InternalState {
NONE, NONE,
CONFIGURE, CONFIGURE,

View File

@ -6,13 +6,13 @@
#endif #endif
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication, MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie, uint8_t switchId, uint32_t transitionDelay): CookieIF* comCookie, uint32_t transitionDelay):
DeviceHandlerBase(objectId, deviceCommunication, comCookie), DeviceHandlerBase(objectId, deviceCommunication, comCookie),
dataset(this), transitionDelay(transitionDelay) { dataset(this), transitionDelay(transitionDelay) {
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 #if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
debugDivider = new PeriodicOperationDivider(5); debugDivider = new PeriodicOperationDivider(3);
#endif #endif
/* Set to default values right away. */ // Set to default values right away
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
@ -291,7 +291,6 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 #if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
if(debugDivider->checkAndIncrement()) { if(debugDivider->checkAndIncrement()) {
/* Set terminal to utf-8 if there is an issue with micro printout. */
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "MGMHandlerLIS3: Magnetic field strength in" sif::info << "MGMHandlerLIS3: Magnetic field strength in"
" microtesla:" << std::endl; " microtesla:" << std::endl;
@ -308,10 +307,29 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
#endif /* OBSW_VERBOSE_LEVEL >= 1 */ #endif /* OBSW_VERBOSE_LEVEL >= 1 */
PoolReadGuard readHelper(&dataset); PoolReadGuard readHelper(&dataset);
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) { if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if(std::abs(mgmX) < absLimitX) {
dataset.fieldStrengthX = mgmX; dataset.fieldStrengthX = mgmX;
dataset.fieldStrengthX.setValid(true);
}
else {
dataset.fieldStrengthX.setValid(false);
}
if(std::abs(mgmY) < absLimitY) {
dataset.fieldStrengthY = mgmY; dataset.fieldStrengthY = mgmY;
dataset.fieldStrengthY.setValid(true);
}
else {
dataset.fieldStrengthY.setValid(false);
}
if(std::abs(mgmZ) < absLimitZ) {
dataset.fieldStrengthZ = mgmZ; dataset.fieldStrengthZ = mgmZ;
dataset.setValidity(true, true); dataset.fieldStrengthZ.setValid(true);
}
else {
dataset.fieldStrengthZ.setValid(false);
}
} }
break; break;
} }
@ -321,7 +339,6 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0); float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 #if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
if(debugDivider->check()) { if(debugDivider->check()) {
/* Set terminal to utf-8 if there is an issue with micro printout. */
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" <<
std::endl; std::endl;
@ -444,16 +461,6 @@ ReturnValue_t MgmLIS3MDLHandler::setOperatingMode(const uint8_t *commandData,
} }
void MgmLIS3MDLHandler::fillCommandAndReplyMap() { void MgmLIS3MDLHandler::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_CONFIG_AND_DATA, 1, &dataset);
insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1);
insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1);
@ -475,7 +482,7 @@ ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
rawPacket = commandBuffer; rawPacket = commandBuffer;
rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1;
/* We dont have to check if this is working because we just did it */ // We dont have to check if this is working because we just did i
return RETURN_OK; return RETURN_OK;
} }
@ -503,3 +510,9 @@ ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(
new PoolEntry<float>({0.0})); new PoolEntry<float>({0.0}));
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void MgmLIS3MDLHandler::setAbsoluteLimits(float xLimit, float yLimit, float zLimit) {
this->absLimitX = xLimit;
this->absLimitY = yLimit;
this->absLimitZ = zLimit;
}

View File

@ -31,9 +31,17 @@ public:
static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW); static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW);
MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie, MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie,
uint8_t switchId, uint32_t transitionDelay = 10000); uint32_t transitionDelay);
virtual ~MgmLIS3MDLHandler(); virtual ~MgmLIS3MDLHandler();
/**
* Set the absolute limit for the values on the axis in microtesla. The dataset values will
* be marked as invalid if that limit is exceeded
* @param xLimit
* @param yLimit
* @param zLimit
*/
void setAbsoluteLimits(float xLimit, float yLimit, float zLimit);
void setToGoToNormalMode(bool enable); void setToGoToNormalMode(bool enable);
protected: protected:
@ -42,7 +50,7 @@ protected:
void doShutDown() override; void doShutDown() override;
void doStartUp() override; void doStartUp() override;
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override; void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override; virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
ReturnValue_t buildCommandFromCommand( ReturnValue_t buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData, DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) override; size_t commandDataLen) override;
@ -52,7 +60,14 @@ protected:
DeviceCommandId_t *id) override; DeviceCommandId_t *id) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, ReturnValue_t scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) override; DeviceCommandId_t *foundId, size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, /**
* This implementation is tailored towards space applications and will flag values larger
* than 100 microtesla on X,Y and 150 microtesla on Z as invalid
* @param id
* @param packet
* @return
*/
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) override; const uint8_t *packet) override;
void fillCommandAndReplyMap() override; void fillCommandAndReplyMap() override;
void modeChanged(void) override; void modeChanged(void) override;
@ -61,15 +76,19 @@ protected:
private: private:
MGMLIS3MDL::MgmPrimaryDataset dataset; MGMLIS3MDL::MgmPrimaryDataset dataset;
//Length a sindgle command SPI answer //Length a single command SPI answer
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2; static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
uint32_t transitionDelay; uint32_t transitionDelay;
// Single SPI command has 2 bytes, first for adress, second for content // Single SPI command has 2 bytes, first for adress, second for content
size_t singleComandSize = 2; size_t singleComandSize = 2;
//has the size for all adresses of the lis3mdl + the continous write bit // Has the size for all adresses of the lis3mdl + the continous write bit
uint8_t commandBuffer[MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1]; uint8_t commandBuffer[MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1];
float absLimitX = 100;
float absLimitY = 100;
float absLimitZ = 150;
/** /**
* We want to save the registers we set, so we dont have to read the * We want to save the registers we set, so we dont have to read the
* registers when we want to change something. * registers when we want to change something.

View File

@ -8,10 +8,9 @@
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId,
object_id_t deviceCommunication, CookieIF* comCookie, uint8_t switchId, object_id_t deviceCommunication, CookieIF* comCookie, uint32_t transitionDelay):
uint32_t transitionDelay):
DeviceHandlerBase(objectId, deviceCommunication, comCookie), DeviceHandlerBase(objectId, deviceCommunication, comCookie),
primaryDataset(this), switchId(switchId), transitionDelay(transitionDelay) { primaryDataset(this), transitionDelay(transitionDelay) {
#if FSFW_HAL_RM3100_MGM_DEBUG == 1 #if FSFW_HAL_RM3100_MGM_DEBUG == 1
debugDivider = new PeriodicOperationDivider(3); debugDivider = new PeriodicOperationDivider(3);
#endif #endif
@ -322,13 +321,7 @@ ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(
} }
uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) { uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
return 25000; return this->transitionDelay;
}
ReturnValue_t MgmRM3100Handler::getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) {
*switches = &switchId;
*numberOfSwitches = 1;
return HasReturnvaluesIF::RETURN_OK;
} }
void MgmRM3100Handler::setToGoToNormalMode(bool enable) { void MgmRM3100Handler::setToGoToNormalMode(bool enable) {

View File

@ -32,7 +32,7 @@ public:
SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO); SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication, MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie, uint8_t switchId, uint32_t transitionDelay = 10000); CookieIF* comCookie, uint32_t transitionDelay);
virtual ~MgmRM3100Handler(); virtual ~MgmRM3100Handler();
/** /**
@ -48,21 +48,16 @@ protected:
DeviceCommandId_t *id) override; DeviceCommandId_t *id) override;
void doStartUp() override; void doStartUp() override;
void doShutDown() override; void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand( ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
DeviceCommandId_t *id) override; ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
ReturnValue_t buildCommandFromCommand( const uint8_t *commandData, size_t commandDataLen) override;
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, ReturnValue_t scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) override; DeviceCommandId_t *foundId, size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
const uint8_t *packet) override;
ReturnValue_t getSwitches(const uint8_t **switches,
uint8_t *numberOfSwitches) override;
void fillCommandAndReplyMap() override; void fillCommandAndReplyMap() override;
void modeChanged(void) override; void modeChanged(void) override;
uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override; virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override; LocalDataPoolManager &poolManager) override;
@ -97,7 +92,6 @@ private:
float scaleFactorZ = 1.0 / RM3100::DEFAULT_GAIN; float scaleFactorZ = 1.0 / RM3100::DEFAULT_GAIN;
bool goToNormalModeAtStartup = false; bool goToNormalModeAtStartup = false;
uint8_t switchId;
uint32_t transitionDelay; uint32_t transitionDelay;
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand, ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,

View File

@ -7,14 +7,13 @@ PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
} }
bool PeriodicOperationDivider::checkAndIncrement() { bool PeriodicOperationDivider::checkAndIncrement() {
counter++;
bool opNecessary = check(); bool opNecessary = check();
if(opNecessary) { if(opNecessary) {
if(resetAutomatically) { if(resetAutomatically) {
counter = 1; resetCounter();
} }
return opNecessary;
} }
counter++;
return opNecessary; return opNecessary;
} }