fixed merge conflicts and added threshold configuration to Max31865Handler

This commit is contained in:
2021-06-02 10:25:35 +02:00
parent d6d11e26e7
commit 7dfaedd1d5
5 changed files with 177 additions and 16 deletions

View File

@ -8,7 +8,7 @@ Max31865PT1000Handler::Max31865PT1000Handler(object_id_t objectId,
DeviceHandlerBase(objectId, comIF, comCookie), switchId(switchId),
sensorDataset(this), sensorDatasetSid(sensorDataset.getSid()) {
#if OBSW_VERBOSE_LEVEL >= 1
debugDivider = new PeriodicOperationDivider(10);
debugDivider = new PeriodicOperationDivider(0);
#endif
}
@ -38,10 +38,38 @@ void Max31865PT1000Handler::doStartUp() {
if(internalState == InternalState::REQUEST_CONFIG) {
if (commandExecuted) {
commandExecuted = false;
internalState = InternalState::CONFIG_HIGH_THRESHOLD;
}
}
if(internalState == InternalState::CONFIG_HIGH_THRESHOLD) {
if(commandExecuted) {
internalState = InternalState::REQUEST_HIGH_THRESHOLD;
commandExecuted = false;
}
}
if(internalState == InternalState::REQUEST_HIGH_THRESHOLD) {
if(commandExecuted) {
internalState = InternalState::CONFIG_LOW_THRESHOLD;
commandExecuted = false;
}
}
if(internalState == InternalState::CONFIG_LOW_THRESHOLD) {
if(commandExecuted) {
internalState = InternalState::REQUEST_LOW_THRESHOLD;
commandExecuted = false;
}
}
if(internalState == InternalState::REQUEST_LOW_THRESHOLD) {
if(commandExecuted) {
setMode(MODE_ON);
setMode(MODE_NORMAL);
commandExecuted = false;
internalState = InternalState::RUNNING;
commandExecuted = false;
}
}
}
@ -82,6 +110,22 @@ ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand(
*id = Max31865Definitions::REQUEST_CONFIG;
return buildCommandFromCommand(*id, nullptr, 0);
}
case(InternalState::CONFIG_HIGH_THRESHOLD): {
*id = Max31865Definitions::WRITE_HIGH_THRESHOLD;
return buildCommandFromCommand(*id, nullptr, 0);
}
case(InternalState::REQUEST_HIGH_THRESHOLD): {
*id = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
return buildCommandFromCommand(*id, nullptr, 0);
}
case(InternalState::CONFIG_LOW_THRESHOLD): {
*id = Max31865Definitions::WRITE_LOW_THRESHOLD;
return buildCommandFromCommand(*id, nullptr, 0);
}
case(InternalState::REQUEST_LOW_THRESHOLD): {
*id = Max31865Definitions::REQUEST_LOW_THRESHOLD;
return buildCommandFromCommand(*id, nullptr, 0);
}
default:
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -110,13 +154,49 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(
}
}
case(Max31865Definitions::REQUEST_CONFIG): {
commandBuffer[0] = 0x00; // dummy byte
commandBuffer[1] = static_cast<uint8_t>(
commandBuffer[0] = static_cast<uint8_t>(
Max31865Definitions::REQUEST_CONFIG);
commandBuffer[1] = 0x00; // dummy byte
DeviceHandlerBase::rawPacketLen = 2;
DeviceHandlerBase::rawPacket = commandBuffer.data();
return HasReturnvaluesIF::RETURN_OK;
}
case(Max31865Definitions::WRITE_HIGH_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(
Max31865Definitions::WRITE_HIGH_THRESHOLD);
commandBuffer[1] = static_cast<uint8_t>(HIGH_THRESHOLD >> 8);
commandBuffer[2] = static_cast<uint8_t>(HIGH_THRESHOLD & 0xFF);
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
return HasReturnvaluesIF::RETURN_OK;
}
case(Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(
Max31865Definitions::REQUEST_HIGH_THRESHOLD);
commandBuffer[1] = 0x00; //dummy byte
commandBuffer[2] = 0x00; //dummy byte
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
return HasReturnvaluesIF::RETURN_OK;
}
case(Max31865Definitions::WRITE_LOW_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(
Max31865Definitions::WRITE_LOW_THRESHOLD);
commandBuffer[1] = static_cast<uint8_t>(LOW_THRESHOLD >> 8);
commandBuffer[2] = static_cast<uint8_t>(LOW_THRESHOLD & 0xFF);
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
return HasReturnvaluesIF::RETURN_OK;
}
case(Max31865Definitions::REQUEST_LOW_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(
Max31865Definitions::REQUEST_LOW_THRESHOLD);
commandBuffer[1] = 0x00; //dummy byte
commandBuffer[2] = 0x00; //dummy byte
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
return HasReturnvaluesIF::RETURN_OK;
}
case(Max31865Definitions::REQUEST_RTD): {
commandBuffer[0] = static_cast<uint8_t>(
Max31865Definitions::REQUEST_RTD);
@ -144,6 +224,10 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(
void Max31865PT1000Handler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(Max31865Definitions::CONFIG_CMD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_CONFIG, 3);
insertInCommandAndReplyMap(Max31865Definitions::WRITE_LOW_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_LOW_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::WRITE_HIGH_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_HIGH_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3,
&sensorDataset);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3);
@ -158,6 +242,39 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start,
internalState == InternalState::RUNNING) {
*foundId = Max31865Definitions::REQUEST_RTD;
*foundLen = rtdReplySize;
return RETURN_OK;
}
if(remainingSize == 3) {
switch(internalState) {
case(InternalState::CONFIG_HIGH_THRESHOLD): {
*foundLen = 3;
*foundId = Max31865Definitions::WRITE_HIGH_THRESHOLD;
commandExecuted = true;
return RETURN_OK;
}
case(InternalState::REQUEST_HIGH_THRESHOLD): {
*foundLen = 3;
*foundId = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
return RETURN_OK;
}
case(InternalState::CONFIG_LOW_THRESHOLD): {
*foundLen = 3;
*foundId = Max31865Definitions::WRITE_LOW_THRESHOLD;
commandExecuted = true;
return RETURN_OK;
}
case(InternalState::REQUEST_LOW_THRESHOLD): {
*foundLen = 3;
*foundId = Max31865Definitions::REQUEST_LOW_THRESHOLD;
return RETURN_OK;
}
default: {
sif::debug << "Max31865PT1000Handler::scanForReply: Unknown internal state"
<< std::endl;
return RETURN_OK;
}
}
}
if(remainingSize == configReplySize) {
@ -203,14 +320,38 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(
}
break;
}
case(Max31865Definitions::REQUEST_LOW_THRESHOLD): {
uint16_t readLowThreshold = packet[0] << 8 | packet[1];
if(readLowThreshold != LOW_THRESHOLD) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 && DEBUG_RTD == 1
sif::error
<< "Max31865PT1000Handler::interpretDeviceReply: Missmatch between written "
<< "and readback value of low threshold register"
<< std::endl;
#endif
}
commandExecuted = true;
break;
}
case(Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
uint16_t readHighThreshold = packet[0] << 8 | packet[1];
if(readHighThreshold != HIGH_THRESHOLD) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 && DEBUG_RTD == 1
sif::error
<< "Max31865PT1000Handler::interpretDeviceReply: Missmatch between written "
<< "and readback value of high threshold register"
<< std::endl;
#endif
}
commandExecuted = true;
break;
}
case(Max31865Definitions::REQUEST_RTD): {
// first bit of LSB reply byte is the fault bit
uint8_t faultBit = packet[2] & 0b0000'0001;
if(faultBit == 1) {
// Maybe we should attempt to restart it?
if(faultByte == 0) {
internalState = InternalState::REQUEST_FAULT_BYTE;
}
internalState = InternalState::REQUEST_FAULT_BYTE;
}
// RTD value consists of last seven bits of the LSB reply byte and
@ -329,7 +470,7 @@ void Max31865PT1000Handler::debugInterface(uint8_t positionTracker,
uint32_t Max31865PT1000Handler::getTransitionDelayMs(
Mode_t modeFrom, Mode_t modeTo) {
return 10000;
return 20000;
}
ReturnValue_t Max31865PT1000Handler::getSwitches(