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

View File

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

View File

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

View File

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