Update FSFW #13
@ -158,7 +158,7 @@ ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start,
|
|||||||
size_t len, DeviceCommandId_t *foundId,
|
size_t len, DeviceCommandId_t *foundId,
|
||||||
size_t *foundLen) {
|
size_t *foundLen) {
|
||||||
|
|
||||||
/* For 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();
|
*foundId = this->getPendingCommand();
|
||||||
*foundLen = len;
|
*foundLen = len;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
@ -170,7 +170,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
|||||||
case(RM3100::CONFIGURE_CMM):
|
case(RM3100::CONFIGURE_CMM):
|
||||||
case(RM3100::CONFIGURE_CYCLE_COUNT):
|
case(RM3100::CONFIGURE_CYCLE_COUNT):
|
||||||
case(RM3100::CONFIGURE_TMRC): {
|
case(RM3100::CONFIGURE_TMRC): {
|
||||||
/* We can only check whether write was successful with read operation. */
|
// We can only check whether write was successful with read operation
|
||||||
if(mode == _MODE_START_UP) {
|
if(mode == _MODE_START_UP) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
@ -178,14 +178,14 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
|||||||
}
|
}
|
||||||
case(RM3100::READ_CMM): {
|
case(RM3100::READ_CMM): {
|
||||||
uint8_t cmmValue = packet[1];
|
uint8_t cmmValue = packet[1];
|
||||||
/* We clear the seventh bit in any case
|
// We clear the seventh bit in any case
|
||||||
* because this one is zero sometimes for some reason */
|
// because this one is zero sometimes for some reason
|
||||||
bitutil::bitClear(&cmmValue, 6);
|
bitutil::bitClear(&cmmValue, 6);
|
||||||
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Attempt reconfiguration. */
|
// Attempt reconfiguration
|
||||||
internalState = InternalState::CONFIGURE_CMM;
|
internalState = InternalState::CONFIGURE_CMM;
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
}
|
||||||
@ -194,13 +194,13 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
|||||||
case(RM3100::READ_TMRC): {
|
case(RM3100::READ_TMRC): {
|
||||||
if(packet[1] == tmrcRegValue) {
|
if(packet[1] == tmrcRegValue) {
|
||||||
commandExecuted = true;
|
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) {
|
if(mode != _MODE_START_UP) {
|
||||||
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
triggerEvent(tmrcSet, tmrcRegValue, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Attempt reconfiguration. */
|
// Attempt reconfiguration
|
||||||
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
internalState = InternalState::STATE_CONFIGURE_TMRC;
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
|||||||
cycleCountZ != cycleCountRegValueZ) {
|
cycleCountZ != cycleCountRegValueZ) {
|
||||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
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) {
|
if(mode != _MODE_START_UP) {
|
||||||
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
|
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
|
||||||
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
|
||||||
@ -267,7 +267,7 @@ ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts." */
|
// Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts."
|
||||||
if(command.cycleCountX > 450 ) {
|
if(command.cycleCountX > 450 ) {
|
||||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||||
}
|
}
|
||||||
@ -336,13 +336,13 @@ void MgmRM3100Handler::setToGoToNormalMode(bool enable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
||||||
/* Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift
|
// 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 */
|
// trickery here to calculate the raw values first
|
||||||
int32_t fieldStrengthRawX = ((packet[1] << 24) | (packet[2] << 16) | (packet[3] << 8)) >> 8;
|
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 fieldStrengthRawY = ((packet[4] << 24) | (packet[5] << 16) | (packet[6] << 8)) >> 8;
|
||||||
int32_t fieldStrengthRawZ = ((packet[7] << 24) | (packet[8] << 16) | (packet[3] << 8)) >> 8;
|
int32_t fieldStrengthRawZ = ((packet[7] << 24) | (packet[8] << 16) | (packet[3] << 8)) >> 8;
|
||||||
|
|
||||||
/* Now scale to physical value in microtesla */
|
// Now scale to physical value in microtesla
|
||||||
float fieldStrengthX = fieldStrengthRawX * scaleFactorX;
|
float fieldStrengthX = fieldStrengthRawX * scaleFactorX;
|
||||||
float fieldStrengthY = fieldStrengthRawY * scaleFactorX;
|
float fieldStrengthY = fieldStrengthRawY * scaleFactorX;
|
||||||
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
|
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
|
||||||
@ -358,7 +358,7 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO: Sanity check on values */
|
// TODO: Sanity check on values?
|
||||||
PoolReadGuard readGuard(&primaryDataset);
|
PoolReadGuard readGuard(&primaryDataset);
|
||||||
if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
primaryDataset.fieldStrengthX = fieldStrengthX;
|
primaryDataset.fieldStrengthX = fieldStrengthX;
|
||||||
|
Loading…
Reference in New Issue
Block a user