eive-obsw/mission/tcs/Max31865PT1000Handler.cpp

548 lines
19 KiB
C++
Raw Permalink Normal View History

2023-03-26 16:42:00 +02:00
#include <mission/tcs/Max31865PT1000Handler.h>
2021-03-13 14:42:30 +01:00
#include <bitset>
#include <cmath>
2022-01-17 15:58:27 +01:00
#include "fsfw/datapool/PoolReadGuard.h"
2021-10-12 17:55:36 +02:00
Max31865PT1000Handler::Max31865PT1000Handler(object_id_t objectId, object_id_t comIF,
2022-01-17 15:58:27 +01:00
CookieIF *comCookie)
: DeviceHandlerBase(objectId, comIF, comCookie),
2022-05-12 09:48:41 +02:00
sensorDataset(this, MAX31865::REQUEST_RTD),
2022-01-17 15:58:27 +01:00
sensorDatasetSid(sensorDataset.getSid()) {
#if OBSW_VERBOSE_LEVEL >= 1
2022-01-17 15:58:27 +01:00
debugDivider = new PeriodicOperationDivider(10);
#endif
}
2022-01-17 15:58:27 +01:00
Max31865PT1000Handler::~Max31865PT1000Handler() {}
void Max31865PT1000Handler::doStartUp() {
2022-01-17 15:58:27 +01:00
if (internalState == InternalState::NONE) {
internalState = InternalState::WARMUP;
Clock::getUptime(&startTime);
}
if (internalState == InternalState::WARMUP) {
dur_millis_t timeNow = 0;
Clock::getUptime(&timeNow);
if (timeNow - startTime >= 100) {
internalState = InternalState::CONFIGURE;
}
}
if (internalState == InternalState::CONFIGURE) {
if (commandExecuted) {
commandExecuted = false;
internalState = InternalState::REQUEST_CONFIG;
}
}
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) {
internalState = InternalState::CLEAR_FAULT_BYTE;
commandExecuted = false;
}
}
if (internalState == InternalState::CLEAR_FAULT_BYTE) {
if (commandExecuted) {
commandExecuted = false;
internalState = InternalState::RUNNING;
if (instantNormal) {
setMode(MODE_NORMAL);
} else {
setMode(_MODE_TO_ON);
}
}
}
}
void Max31865PT1000Handler::doShutDown() {
2022-01-17 15:58:27 +01:00
commandExecuted = false;
2022-03-22 20:35:37 +01:00
warningSwitch = true;
2022-01-17 15:58:27 +01:00
setMode(_MODE_POWER_DOWN);
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
if (internalState == InternalState::RUNNING) {
*id = MAX31865::REQUEST_RTD;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
} else if (internalState == InternalState::REQUEST_FAULT_BYTE) {
*id = MAX31865::REQUEST_FAULT_BYTE;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
} else if (internalState == InternalState::CLEAR_FAULT_BYTE) {
*id = MAX31865::CLEAR_FAULT_BYTE;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
} else {
return DeviceHandlerBase::NOTHING_TO_SEND;
}
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
switch (internalState) {
case (InternalState::NONE):
case (InternalState::WARMUP):
case (InternalState::RUNNING):
return DeviceHandlerBase::NOTHING_TO_SEND;
case (InternalState::CONFIGURE): {
*id = MAX31865::CONFIG_CMD;
2022-01-17 15:58:27 +01:00
uint8_t config[1] = {DEFAULT_CONFIG};
return buildCommandFromCommand(*id, config, 1);
}
2022-01-17 15:58:27 +01:00
case (InternalState::REQUEST_CONFIG): {
*id = MAX31865::REQUEST_CONFIG;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
}
2022-01-17 15:58:27 +01:00
case (InternalState::CONFIG_HIGH_THRESHOLD): {
*id = MAX31865::WRITE_HIGH_THRESHOLD;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
}
2022-01-17 15:58:27 +01:00
case (InternalState::REQUEST_HIGH_THRESHOLD): {
*id = MAX31865::REQUEST_HIGH_THRESHOLD;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
}
2022-01-17 15:58:27 +01:00
case (InternalState::CONFIG_LOW_THRESHOLD): {
*id = MAX31865::WRITE_LOW_THRESHOLD;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
}
2022-01-17 15:58:27 +01:00
case (InternalState::REQUEST_LOW_THRESHOLD): {
*id = MAX31865::REQUEST_LOW_THRESHOLD;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
}
2022-01-17 15:58:27 +01:00
case (InternalState::CLEAR_FAULT_BYTE): {
*id = MAX31865::CLEAR_FAULT_BYTE;
2022-01-17 15:58:27 +01:00
return buildCommandFromCommand(*id, nullptr, 0);
2021-12-17 14:20:22 +01:00
}
default:
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-01-17 15:58:27 +01:00
sif::error << "Max31865PT1000Handler: Invalid internal state" << std::endl;
#else
2022-01-17 15:58:27 +01:00
sif::printError("Max31865PT1000Handler: Invalid internal state\n");
#endif
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-01-17 15:58:27 +01:00
}
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
switch (deviceCommand) {
case (MAX31865::CONFIG_CMD): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::CONFIG_CMD);
2022-01-17 15:58:27 +01:00
if (commandDataLen == 1) {
commandBuffer[1] = commandData[0];
2022-05-12 11:27:30 +02:00
currentCfg = commandData[0];
DeviceHandlerBase::rawPacketLen = 2;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
} else {
return DeviceHandlerIF::NO_COMMAND_DATA;
}
}
case (MAX31865::CLEAR_FAULT_BYTE): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::CONFIG_CMD);
2022-05-12 11:27:30 +02:00
commandBuffer[1] = currentCfg | MAX31865::CLEAR_FAULT_BIT_VAL;
2022-01-17 15:58:27 +01:00
DeviceHandlerBase::rawPacketLen = 2;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::REQUEST_CONFIG): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_CONFIG);
2022-01-17 15:58:27 +01:00
commandBuffer[1] = 0x00; // dummy byte
DeviceHandlerBase::rawPacketLen = 2;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::WRITE_HIGH_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::WRITE_HIGH_THRESHOLD);
2022-01-17 15:58:27 +01:00
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();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::REQUEST_HIGH_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_HIGH_THRESHOLD);
2022-01-17 15:58:27 +01:00
commandBuffer[1] = 0x00; // dummy byte
commandBuffer[2] = 0x00; // dummy byte
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::WRITE_LOW_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::WRITE_LOW_THRESHOLD);
2022-01-17 15:58:27 +01:00
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();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::REQUEST_LOW_THRESHOLD): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_LOW_THRESHOLD);
2022-01-17 15:58:27 +01:00
commandBuffer[1] = 0x00; // dummy byte
commandBuffer[2] = 0x00; // dummy byte
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::REQUEST_RTD): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_RTD);
2022-01-17 15:58:27 +01:00
// two dummy bytes
commandBuffer[1] = 0x00;
commandBuffer[2] = 0x00;
DeviceHandlerBase::rawPacketLen = 3;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (MAX31865::REQUEST_FAULT_BYTE): {
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_FAULT_BYTE);
2022-01-17 15:58:27 +01:00
commandBuffer[1] = 0x00;
DeviceHandlerBase::rawPacketLen = 2;
DeviceHandlerBase::rawPacket = commandBuffer.data();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
default:
2022-01-17 15:58:27 +01:00
// Unknown DeviceCommand
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
}
void Max31865PT1000Handler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(MAX31865::CONFIG_CMD, 3);
insertInCommandAndReplyMap(MAX31865::REQUEST_CONFIG, 3);
insertInCommandAndReplyMap(MAX31865::WRITE_LOW_THRESHOLD, 3);
insertInCommandAndReplyMap(MAX31865::REQUEST_LOW_THRESHOLD, 3);
insertInCommandAndReplyMap(MAX31865::WRITE_HIGH_THRESHOLD, 3);
insertInCommandAndReplyMap(MAX31865::REQUEST_HIGH_THRESHOLD, 3);
insertInCommandAndReplyMap(MAX31865::REQUEST_RTD, 3, &sensorDataset);
insertInCommandAndReplyMap(MAX31865::REQUEST_FAULT_BYTE, 3);
insertInCommandAndReplyMap(MAX31865::CLEAR_FAULT_BYTE, 3);
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t remainingSize,
DeviceCommandId_t *foundId, size_t *foundLen) {
size_t rtdReplySize = 3;
size_t configReplySize = 2;
2022-01-17 15:58:27 +01:00
if (remainingSize == rtdReplySize and internalState == InternalState::RUNNING) {
*foundId = MAX31865::REQUEST_RTD;
2022-01-17 15:58:27 +01:00
*foundLen = rtdReplySize;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
2022-01-17 15:58:27 +01:00
if (remainingSize == 3) {
switch (internalState) {
case (InternalState::CONFIG_HIGH_THRESHOLD): {
*foundLen = 3;
*foundId = MAX31865::WRITE_HIGH_THRESHOLD;
2022-01-17 15:58:27 +01:00
commandExecuted = true;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (InternalState::REQUEST_HIGH_THRESHOLD): {
*foundLen = 3;
*foundId = MAX31865::REQUEST_HIGH_THRESHOLD;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (InternalState::CONFIG_LOW_THRESHOLD): {
*foundLen = 3;
*foundId = MAX31865::WRITE_LOW_THRESHOLD;
2022-01-17 15:58:27 +01:00
commandExecuted = true;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
case (InternalState::REQUEST_LOW_THRESHOLD): {
*foundLen = 3;
*foundId = MAX31865::REQUEST_LOW_THRESHOLD;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
default: {
sif::debug << "Max31865PT1000Handler::scanForReply: Unknown internal state" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
}
}
if (remainingSize == configReplySize) {
if (internalState == InternalState::CONFIGURE) {
commandExecuted = true;
*foundLen = configReplySize;
*foundId = MAX31865::CONFIG_CMD;
2022-01-17 15:58:27 +01:00
} else if (internalState == InternalState::REQUEST_FAULT_BYTE) {
*foundId = MAX31865::REQUEST_FAULT_BYTE;
2022-01-17 15:58:27 +01:00
*foundLen = 2;
internalState = InternalState::RUNNING;
} else if (internalState == InternalState::CLEAR_FAULT_BYTE) {
*foundId = MAX31865::CLEAR_FAULT_BYTE;
2022-01-17 15:58:27 +01:00
*foundLen = 2;
if (getMode() == _MODE_START_UP) {
2022-01-17 15:58:27 +01:00
commandExecuted = true;
} else {
internalState = InternalState::RUNNING;
}
} else {
*foundId = MAX31865::REQUEST_CONFIG;
2022-01-17 15:58:27 +01:00
*foundLen = configReplySize;
}
2022-01-17 15:58:27 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch (id) {
case (MAX31865::REQUEST_CONFIG): {
2022-01-17 15:58:27 +01:00
if (packet[1] != DEFAULT_CONFIG) {
2022-03-22 20:35:37 +01:00
if (warningSwitch) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-03-22 19:30:10 +01:00
// it propably would be better if we at least try one restart..
sif::warning << "Max31865PT1000Handler: 0x" << std::hex << this->getObjectId()
2022-03-22 20:35:37 +01:00
<< ": Invalid configuration reply" << std::endl;
#else
2022-03-22 19:30:10 +01:00
sif::printWarning("Max31865PT1000Handler: %04x: Invalid configuration reply!\n",
2022-03-22 20:35:37 +01:00
this->getObjectId());
#endif
2022-03-22 19:30:10 +01:00
warningSwitch = false;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
// set to true for invalid configs too for now.
if (internalState == InternalState::REQUEST_CONFIG) {
commandExecuted = true;
} else if (internalState == InternalState::RUNNING) {
// we should propably generate a telemetry with the config byte
// as payload here.
}
break;
}
case (MAX31865::REQUEST_LOW_THRESHOLD): {
2022-01-17 15:58:27 +01:00
uint16_t readLowThreshold = packet[1] << 8 | packet[2];
if (readLowThreshold != LOW_THRESHOLD) {
2021-10-12 17:55:36 +02:00
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-01-17 15:58:27 +01:00
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId() << ": Missmatch between "
<< "written and readback value of low threshold register" << std::endl;
2021-10-12 17:55:36 +02:00
#else
2022-01-17 15:58:27 +01:00
sif::printWarning(
"Max31865PT1000Handler::interpretDeviceReply: Missmatch between "
"written and readback value of low threshold register\n");
2021-10-12 17:55:36 +02:00
#endif
#endif
2022-01-17 15:58:27 +01:00
}
commandExecuted = true;
break;
}
case (MAX31865::REQUEST_HIGH_THRESHOLD): {
2022-05-13 10:27:26 +02:00
uint16_t readHighThreshold = (packet[1] << 8) | packet[2];
2022-01-17 15:58:27 +01:00
if (readHighThreshold != HIGH_THRESHOLD) {
2021-10-12 17:55:36 +02:00
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-01-17 15:58:27 +01:00
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId() << ": Missmatch between "
<< "written and readback value of high threshold register" << std::endl;
2021-10-12 17:55:36 +02:00
#else
2022-01-17 15:58:27 +01:00
sif::printWarning(
"Max31865PT1000Handler::interpretDeviceReply: Missmatch between "
"written and readback value of high threshold register\n");
2021-10-12 17:55:36 +02:00
#endif
#endif
2022-01-17 15:58:27 +01:00
}
commandExecuted = true;
break;
}
case (MAX31865::REQUEST_RTD): {
2022-01-17 15:58:27 +01:00
// first bit of LSB reply byte is the fault bit
2022-05-13 10:27:26 +02:00
bool faultBit = packet[2] & 0b0000'0001;
2022-01-17 15:58:27 +01:00
if (resetFaultBit) {
internalState = InternalState::CLEAR_FAULT_BYTE;
resetFaultBit = false;
2022-05-13 10:27:26 +02:00
} else if (shouldFaultStatusBeRequested(faultBit)) {
2022-01-17 15:58:27 +01:00
// Maybe we should attempt to restart it?
internalState = InternalState::REQUEST_FAULT_BYTE;
resetFaultBit = true;
}
// RTD value consists of last seven bits of the LSB reply byte and
// the MSB reply byte
uint16_t adcCode = ((packet[1] << 8) | packet[2]) >> 1;
2022-05-14 09:41:28 +02:00
// Calculate resistance
float rtdValue = adcCode * EiveMax31855::RTD_RREF_PT1000 / INT16_MAX;
2022-01-17 15:58:27 +01:00
// calculate approximation
float approxTemp = adcCode / 32.0 - 256.0;
2022-04-26 10:37:25 +02:00
if (debugMode) {
#if OBSW_VERBOSE_LEVEL >= 1
2022-04-26 10:37:25 +02:00
if (debugDivider->checkAndIncrement()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-05-13 10:33:35 +02:00
sif::info << "Max31865: " << std::setw(24) << std::left << locString << std::right
<< " | R[Ohm] " << rtdValue << " Ohms | Approx T[C]: " << approxTemp
<< std::endl;
#else
2022-04-26 10:37:25 +02:00
sif::printInfo("Max31685: Measured resistance is %f Ohms\n", rtdValue);
sif::printInfo("Approximated temperature is %f C\n", approxTemp);
#endif
2022-04-26 10:37:25 +02:00
}
2021-10-12 17:55:36 +02:00
#endif
2022-04-26 10:37:25 +02:00
}
2022-01-17 15:58:27 +01:00
PoolReadGuard pg(&sensorDataset);
2022-08-24 17:27:47 +02:00
if (pg.getReadResult() != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
// Configuration error
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-01-17 15:58:27 +01:00
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId() << ": Error reading dataset!" << std::endl;
#else
2022-01-17 15:58:27 +01:00
sif::printWarning(
"Max31865PT1000Handler::interpretDeviceReply: "
"Error reading dataset!\n");
#endif
2022-01-17 15:58:27 +01:00
return pg.getReadResult();
}
if (not sensorDataset.isValid()) {
sensorDataset.setValidity(true, false);
sensorDataset.rtdValue.setValid(true);
sensorDataset.temperatureCelcius.setValid(true);
}
sensorDataset.rtdValue = rtdValue;
sensorDataset.temperatureCelcius = approxTemp;
break;
}
case (MAX31865::REQUEST_FAULT_BYTE): {
2022-05-13 10:27:26 +02:00
currentFaultStatus = packet[1];
bool faultStatusChanged = (currentFaultStatus != lastFaultStatus);
// Spam protection
2022-05-13 10:27:26 +02:00
if (faultStatusChanged or
((currentFaultStatus == lastFaultStatus) and (sameFaultStatusCounter < 3))) {
// TODO: Think about triggering an event here
#if OBSW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
2022-05-13 10:27:26 +02:00
<< this->getObjectId() << ": Fault byte is: 0b"
<< std::bitset<8>(currentFaultStatus) << std::endl;
#else
sif::printWarning(
"Max31865PT1000Handler::interpretDeviceReply: Fault byte"
" is: 0b" BYTE_TO_BINARY_PATTERN "\n",
BYTE_TO_BINARY(faultByte));
#endif
#endif
if (faultStatusChanged) {
sameFaultStatusCounter = 0;
} else {
sameFaultStatusCounter++;
}
2022-01-17 15:58:27 +01:00
}
2022-05-13 10:27:26 +02:00
if (faultStatusChanged) {
lastFaultStatus = currentFaultStatus;
}
PoolReadGuard pg(&sensorDataset);
auto result = pg.getReadResult();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
// Configuration error
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId() << ": Error reading dataset" << std::endl;
#else
sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Error reading dataset\n");
#endif
2022-01-17 15:58:27 +01:00
return result;
}
2022-05-13 10:10:56 +02:00
if (faultStatusChanged) {
sensorDataset.lastErrorByte.setValid(true);
2022-05-13 10:27:26 +02:00
sensorDataset.lastErrorByte = lastFaultStatus;
}
sensorDataset.errorByte.setValid(true);
2022-05-13 10:27:26 +02:00
sensorDataset.errorByte = currentFaultStatus;
2022-05-13 10:27:26 +02:00
if (currentFaultStatus != 0) {
sensorDataset.temperatureCelcius.setValid(false);
}
2022-01-17 15:58:27 +01:00
break;
}
default:
2022-01-17 15:58:27 +01:00
break;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2022-01-17 15:58:27 +01:00
uint32_t Max31865PT1000Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
2022-05-13 10:27:26 +02:00
return 5000;
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::getSwitches(const uint8_t **switches,
uint8_t *numberOfSwitches) {
return DeviceHandlerBase::NO_SWITCH;
}
2022-01-17 15:58:27 +01:00
ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
2022-05-12 11:27:30 +02:00
using namespace MAX31865;
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::RTD_VALUE), new PoolEntry<float>({0}));
2022-05-13 10:10:56 +02:00
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::TEMPERATURE_C), new PoolEntry<float>({0}));
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::LAST_FAULT_BYTE),
new PoolEntry<uint8_t>({0}));
2022-05-12 11:27:30 +02:00
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::FAULT_BYTE), new PoolEntry<uint8_t>({0}));
2022-08-15 11:57:57 +02:00
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(sensorDataset.getSid(), false, 30.0));
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2021-12-17 14:20:22 +01:00
void Max31865PT1000Handler::setInstantNormal(bool instantNormal) {
2022-01-17 15:58:27 +01:00
this->instantNormal = instantNormal;
2021-12-17 14:20:22 +01:00
}
void Max31865PT1000Handler::modeChanged() {
if (getMode() == MODE_OFF) {
2022-05-13 10:27:26 +02:00
lastFaultStatus = 0;
currentFaultStatus = 0;
sameFaultStatusCounter = 0;
2022-01-17 15:58:27 +01:00
internalState = InternalState::NONE;
}
}
2022-03-23 15:02:48 +01:00
void Max31865PT1000Handler::setDeviceInfo(uint8_t idx, std::string locString_) {
deviceIdx = idx;
locString = std::move(locString_);
}
2022-04-26 10:37:25 +02:00
void Max31865PT1000Handler::setDebugMode(bool enable) { this->debugMode = enable; }
2022-05-13 10:27:26 +02:00
bool Max31865PT1000Handler::shouldFaultStatusBeRequested(bool faultBit) {
if ((sameFaultStatusCounter < 3) and faultBit) {
return true;
}
return false;
}