new RTD handler working
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
2022-05-14 09:41:28 +02:00
parent 8715683d6b
commit 1c9f411e75
11 changed files with 116 additions and 176 deletions

View File

@ -49,16 +49,15 @@ bool Max31865RtdReader::periodicInitHandling() {
return false;
}
bool someRtdOn = false;
for (auto& rtd : rtds) {
if (rtd == nullptr) {
continue;
}
if ((rtd->on or rtd->active) and not rtd->configured) {
if (rtd->cd.hasTimedOut()) {
uint8_t cfg =
(Bias::OFF << CfgBitPos::BIAS_SEL) | (Wires::FOUR_WIRE << CfgBitPos::WIRE_SEL) |
(ConvMode::NORM_OFF << CfgBitPos::CONV_MODE) | (1 << CfgBitPos::FAULTY_STATUS_CLEAR);
uint8_t cfg = (Bias::OFF << CfgBitPos::BIAS_SEL) |
(Wires::FOUR_WIRE << CfgBitPos::WIRE_SEL) |
(ConvMode::NORM_OFF << CfgBitPos::CONV_MODE);
result = writeCfgReg(rtd->spiCookie, cfg);
if (result != HasReturnvaluesIF::RETURN_OK) {
handleSpiError(rtd, result, "writeCfgReg");
@ -84,14 +83,14 @@ bool Max31865RtdReader::periodicInitHandling() {
handleSpiError(rtd, result, "clearFaultStatus");
}
}
someRtdOn = true;
rtd->configured = true;
rtd->db.configured = true;
if (rtd->active) {
rtd->db.active = true;
}
}
}
}
if (not someRtdOn) {
return false;
}
bool someRtdUsable = false;
for (auto& rtd : rtds) {
if (rtd == nullptr) {
@ -126,6 +125,10 @@ void Max31865RtdReader::periodicReadReqHandling() {
}
currentCfg |= (1 << CfgBitPos::ONE_SHOT);
result = writeCfgReg(rtd->spiCookie, currentCfg);
if (result != RETURN_OK) {
handleSpiError(rtd, result, "writeCfgReg");
continue;
}
}
}
}
@ -154,7 +157,7 @@ void Max31865RtdReader::periodicReadHandling() {
if (faultBitSet) {
rtd->db.faultBitSet = faultBitSet;
}
rtd->db.rtdVal = rtdVal;
rtd->db.adcCode = rtdVal;
}
}
for (auto& rtd : rtds) {
@ -182,6 +185,10 @@ ReturnValue_t Max31865RtdReader::initializeInterface(CookieIF* cookie) {
throw std::invalid_argument("Invalid RTD index");
}
rtds[rtdCookie->idx] = rtdCookie;
MutexGuard mg(readerMutex);
if (dbLen == 0) {
dbLen = rtdCookie->db.getSerializedSize();
}
return RETURN_OK;
}
@ -299,14 +306,13 @@ ReturnValue_t Max31865RtdReader::readReceivedMessage(CookieIF* cookie, uint8_t**
return RETURN_FAILED;
}
*buffer = reinterpret_cast<uint8_t*>(rtdCookie->exchangeBuf.data());
*size = rtdCookie->db.getSerializedSize();
*size = serLen;
return RETURN_OK;
}
ReturnValue_t Max31865RtdReader::writeCfgReg(SpiCookie* cookie, uint8_t cfg) {
using namespace MAX31865;
uint8_t cmd = cfg;
return writeNToReg(cookie, CONFIG, 1, &cmd, nullptr);
return writeNToReg(cookie, CONFIG, 1, &cfg, nullptr);
}
ReturnValue_t Max31865RtdReader::writeBiasSel(MAX31865::Bias bias, SpiCookie* cookie) {
@ -388,7 +394,7 @@ ReturnValue_t Max31865RtdReader::writeNToReg(SpiCookie* cookie, uint8_t reg, siz
for (size_t idx = 0; idx < n; idx++) {
cmdBuf[idx + 1] = cmd[idx];
}
return comIF->sendMessage(cookie, cmd, 2);
return comIF->sendMessage(cookie, cmdBuf.data(), n + 1);
}
ReturnValue_t Max31865RtdReader::readRtdVal(SpiCookie* cookie, uint16_t& val, bool& faultBitSet) {
@ -416,18 +422,19 @@ ReturnValue_t Max31865RtdReader::readNFromReg(SpiCookie* cookie, uint8_t reg, si
reg &= ~WRITE_BIT;
cmdBuf[0] = reg;
std::memset(cmdBuf.data() + 1, 0, n);
ReturnValue_t result = comIF->sendMessage(cookie, cmdBuf.data(), n);
ReturnValue_t result = comIF->sendMessage(cookie, cmdBuf.data(), n + 1);
if (result != RETURN_OK) {
return RETURN_FAILED;
}
uint8_t* replyPtr = replyBuf.data();
size_t dummyLen = 0;
uint8_t* replyPtr = nullptr;
result = comIF->readReceivedMessage(cookie, &replyPtr, &dummyLen);
if (result != RETURN_OK) {
return result;
}
if (reply != nullptr) {
*reply = replyBuf.data() + 1;
*reply = replyPtr + 1;
}
return RETURN_OK;
}