started rm3100 testing
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include "MGMHandlerRM3100.h"
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerMessage.h>
|
||||
@ -17,28 +18,37 @@ MGMHandlerRM3100::MGMHandlerRM3100(object_id_t objectId,
|
||||
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::STATE_NONE): {
|
||||
internalState = InternalState::STATE_CONFIGURE_CMM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_CONFIGURE_CMM): {
|
||||
internalState = InternalState::STATE_READ_CMM;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_READ_CMM): {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_CONFIGURE_TMRC): {
|
||||
internalState = InternalState::STATE_READ_TMRC;
|
||||
break;
|
||||
}
|
||||
case(InternalState::STATE_READ_TMRC): {
|
||||
if(commandExecuted) {
|
||||
internalState = InternalState::STATE_NORMAL;
|
||||
//setMode(_MODE_TO_ON);
|
||||
setMode(MODE_NORMAL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::doShutDown() {
|
||||
@ -141,15 +151,10 @@ ReturnValue_t MGMHandlerRM3100::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, 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;
|
||||
*foundLen = len;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::interpretDeviceReply(
|
||||
@ -159,7 +164,7 @@ ReturnValue_t MGMHandlerRM3100::interpretDeviceReply(
|
||||
case(RM3100::CONFIGURE_CMM):
|
||||
case(RM3100::CONFIGURE_CYCLE_COUNT):
|
||||
case(RM3100::CONFIGURE_TMRC): {
|
||||
// We can only check whether write was sucessful with read operation.
|
||||
/* We can only check whether write was successful with read operation. */
|
||||
break;
|
||||
}
|
||||
case(RM3100::READ_CMM): {
|
||||
@ -167,7 +172,7 @@ ReturnValue_t MGMHandlerRM3100::interpretDeviceReply(
|
||||
commandExecuted = true;
|
||||
}
|
||||
else {
|
||||
// Attempt reconfiguration.
|
||||
/* Attempt reconfiguration. */
|
||||
internalState = InternalState::STATE_CONFIGURE_CMM;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
@ -176,13 +181,13 @@ ReturnValue_t MGMHandlerRM3100::interpretDeviceReply(
|
||||
case(RM3100::READ_TMRC): {
|
||||
if(packet[1] == tmrcRegValue) {
|
||||
commandExecuted = true;
|
||||
// Reading TMRC was commanded. Trigger event to inform ground.
|
||||
/* Reading TMRC was commanded. Trigger event to inform ground. */
|
||||
if(mode != _MODE_START_UP) {
|
||||
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Attempt reconfiguration.
|
||||
/* Attempt reconfiguration. */
|
||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
@ -197,7 +202,7 @@ ReturnValue_t MGMHandlerRM3100::interpretDeviceReply(
|
||||
cycleCountZ != cycleCountRegValueZ) {
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
// Reading TMRC was commanded. Trigger event to inform ground.
|
||||
/* Reading TMRC was commanded. Trigger event to inform ground. */
|
||||
if(mode != _MODE_START_UP) {
|
||||
uint32_t eventParam1 = cycleCountX << 16 | cycleCountY;
|
||||
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
||||
@ -287,16 +292,16 @@ ReturnValue_t MGMHandlerRM3100::handleTmrcConfigCommand(
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CMM, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CMM, 1);
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CMM, 2);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CMM, 2);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_TMRC, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_TMRC, 1);
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_TMRC, 2);
|
||||
insertInCommandAndReplyMap(RM3100::READ_TMRC, 2);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CYCLE_COUNT, 1);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CYCLE_COUNT, 1);
|
||||
insertInCommandAndReplyMap(RM3100::CONFIGURE_CYCLE_COUNT, 2);
|
||||
insertInCommandAndReplyMap(RM3100::READ_CYCLE_COUNT, 2);
|
||||
|
||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 1, &primaryDataset);
|
||||
insertInCommandAndReplyMap(RM3100::READ_DATA, 2, &primaryDataset);
|
||||
}
|
||||
|
||||
void MGMHandlerRM3100::modeChanged(void) {
|
||||
@ -315,12 +320,11 @@ ReturnValue_t MGMHandlerRM3100::initializeLocalDataPool(
|
||||
}
|
||||
|
||||
uint32_t MGMHandlerRM3100::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 5000;
|
||||
return 60000;
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerRM3100::handleDataReadout(const uint8_t *packet) {
|
||||
// analyze data here.
|
||||
// Field strengths in micro Tesla
|
||||
/* Analyze data here. Field strengths in microtesla */
|
||||
int32_t fieldStrengthX = (packet[1] << 16 | packet[2] << 8 | packet[3])
|
||||
* scaleFactorX;
|
||||
int32_t fieldStrengthY = (packet[4] << 16 | packet[5] << 8 | packet[6])
|
||||
@ -332,20 +336,19 @@ ReturnValue_t MGMHandlerRM3100::handleDataReadout(const uint8_t *packet) {
|
||||
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.
|
||||
/* 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) {
|
||||
PoolReadGuard readGuard(&primaryDataset);
|
||||
if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
primaryDataset.fieldStrengthX = fieldStrengthX;
|
||||
primaryDataset.fieldStrengthY = fieldStrengthY;
|
||||
primaryDataset.fieldStrengthZ = fieldStrengthZ;
|
||||
primaryDataset.setValidity(true, true);
|
||||
result = primaryDataset.commit();
|
||||
}
|
||||
return result;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user