cleaning up, better fault status handling
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-05-13 10:10:02 +02:00
parent fd0de9426f
commit 6b54a4dea9
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 42 additions and 47 deletions

View File

@ -55,7 +55,6 @@ bool Max31865RtdReader::periodicInitHandling() {
continue;
}
if ((rtd->on or rtd->active) and not rtd->configured) {
sif::debug << "crap1" << std::endl;
if (rtd->cd.hasTimedOut()) {
uint8_t cfg =
(Bias::OFF << CfgBitPos::BIAS_SEL) | (Wires::FOUR_WIRE << CfgBitPos::WIRE_SEL) |
@ -118,9 +117,7 @@ void Max31865RtdReader::periodicReadReqHandling() {
if (rtd == nullptr) {
continue;
}
sif::debug << "crap2" << std::endl;
if (rtdIsActive(rtd->idx)) {
sif::debug << "crap3" << std::endl;
uint8_t currentCfg = 0;
auto result = readCfgReg(rtd->spiCookie, currentCfg);
if (result != RETURN_OK) {
@ -154,9 +151,6 @@ void Max31865RtdReader::periodicReadHandling() {
handleSpiError(rtd, result, "readRtdVal");
continue;
}
if(rtd->idx == 0) {
sif::debug << "Read RAW rtd val 0: " << rtdVal << std::endl;
}
if (faultBitSet) {
rtd->db.faultBitSet = faultBitSet;
}

View File

@ -441,56 +441,51 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
}
case (MAX31865::REQUEST_FAULT_BYTE): {
faultByte = packet[1];
//#if OBSW_VERBOSE_LEVEL >= 1
//#if FSFW_CPP_OSTREAM_ENABLED == 1
// sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
// << this->getObjectId()
// << ": Fault byte"
// " is: 0b"
// << std::bitset<8>(faultByte) << std::endl;
//#else
// sif::printWarning(
// "Max31865PT1000Handler::interpretDeviceReply: Fault byte"
// " is: 0b" BYTE_TO_BINARY_PATTERN "\n",
// BYTE_TO_BINARY(faultByte));
//#endif
//#endif
ReturnValue_t result = sensorDataset.read();
bool faultStatusChanged = (faultByte != lastFaultStatus);
// Spam protection
if (faultStatusChanged or ((faultByte == 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
<< this->getObjectId() << ": Fault byte is: 0b" << std::bitset<8>(faultByte)
<< 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++;
}
}
lastFaultStatus = faultByte;
PoolReadGuard pg(&sensorDataset);
auto result = pg.getReadResult();
if (result != HasReturnvaluesIF::RETURN_OK) {
// Configuration error
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId()
<< ":"
"Error reading dataset!"
<< std::endl;
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId() << ": Error reading dataset" << std::endl;
#else
sif::printDebug(
"Max31865PT1000Handler::interpretDeviceReply: "
"Error reading dataset!\n");
sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Error reading dataset\n");
#endif
return result;
}
if(faultStatusChanged) {
sensorDataset.lastErrorByte.setValid(true);
sensorDataset.lastErrorByte = faultByte;
}
sensorDataset.errorByte.setValid(true);
sensorDataset.errorByte = faultByte;
if (faultByte != 0) {
sensorDataset.temperatureCelcius.setValid(false);
}
result = sensorDataset.commit();
if (result != HasReturnvaluesIF::RETURN_OK) {
// Configuration error
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
<< this->getObjectId() << ": Error commiting dataset!" << std::endl;
#else
sif::printDebug(
"Max31865PT1000Handler::interpretDeviceReply: "
"Error commiting dataset!\n");
#endif
return result;
}
break;
}
default:
@ -516,7 +511,9 @@ ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool
using namespace MAX31865;
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::RTD_VALUE), new PoolEntry<float>({0}));
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::TEMPERATURE_C),
new PoolEntry<float>({0}, 1, true));
new PoolEntry<float>({0}));
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::LAST_FAULT_BYTE),
new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::FAULT_BYTE), new PoolEntry<uint8_t>({0}));
poolManager.subscribeForPeriodicPacket(sensorDataset.getSid(), false, 30.0, false);
return HasReturnvaluesIF::RETURN_OK;

View File

@ -110,6 +110,8 @@ class Max31865PT1000Handler : public DeviceHandlerBase {
bool resetFaultBit = false;
dur_millis_t startTime = 0;
uint8_t currentCfg = 0;
uint8_t lastFaultStatus = 0;
uint16_t sameFaultStatusCounter = 0;
std::string locString;
uint8_t faultByte = 0;
uint8_t deviceIdx = 0;

View File

@ -9,7 +9,7 @@
namespace MAX31865 {
enum class PoolIds : lp_id_t { RTD_VALUE, TEMPERATURE_C, FAULT_BYTE };
enum class PoolIds : lp_id_t { RTD_VALUE, TEMPERATURE_C, LAST_FAULT_BYTE, FAULT_BYTE };
enum Wires : unsigned int { TWO_WIRE = 0, THREE_WIRE = 1, FOUR_WIRE = 0 };
enum ConvMode : unsigned int { NORM_OFF = 0, AUTO = 1 };
@ -56,7 +56,7 @@ static constexpr uint8_t CLEAR_FAULT_BIT_VAL = 0b0000'0010;
static constexpr size_t MAX_REPLY_SIZE = 5;
class Max31865Set : public StaticLocalDataSet<3> {
class Max31865Set : public StaticLocalDataSet<4> {
public:
/**
* Constructor used by owner and data creators like device handlers.
@ -75,6 +75,8 @@ class Max31865Set : public StaticLocalDataSet<3> {
lp_var_t<float>(sid.objectId, static_cast<lp_id_t>(PoolIds::RTD_VALUE), this);
lp_var_t<float> temperatureCelcius =
lp_var_t<float>(sid.objectId, static_cast<lp_id_t>(PoolIds::TEMPERATURE_C), this);
lp_var_t<uint8_t> lastErrorByte =
lp_var_t<uint8_t>(sid.objectId, static_cast<lp_id_t>(PoolIds::LAST_FAULT_BYTE), this);
lp_var_t<uint8_t> errorByte =
lp_var_t<uint8_t>(sid.objectId, static_cast<lp_id_t>(PoolIds::FAULT_BYTE), this);
};