continued low level MAX31865 handler
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
parent
23f209fb07
commit
6b9e49e632
@ -5,7 +5,7 @@ if(EIVE_BUILD_GPSD_GPS_HANDLER)
|
||||
endif()
|
||||
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
Max31865RtdReader.cpp
|
||||
Max31865RtdLowlevelHandler.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(ploc)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Max31865RtdLowlevelHandler.h"
|
||||
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <linux/devices/Max31865RtdReader.h>
|
||||
|
||||
Max31865RtdReader::Max31865RtdReader(object_id_t objectId, SpiComIF* comIF)
|
||||
: SystemObject(objectId), rtds(EiveMax31855::NUM_RTDS), comIF(comIF) {
|
||||
@ -44,7 +45,7 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
MutexGuard mg(readerMutex);
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
if (mg.getLockResult() != RETURN_OK) {
|
||||
// TODO: Emit warning, return
|
||||
sif::warning << "Max31865RtdReader::periodicInitHandling: Mutex lock failed" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -60,7 +61,28 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
(ConvMode::NORM_OFF << CfgBitPos::CONV_MODE) | (1 << CfgBitPos::FAULTY_STATUS_CLEAR);
|
||||
result = writeCfgReg(rtd->spiCookie, cfg);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// TODO: Check retval
|
||||
handleSpiError(rtd, result, "writeCfgReg");
|
||||
}
|
||||
bool additionalCfg = false;
|
||||
if (rtd->writeLowThreshold) {
|
||||
additionalCfg = true;
|
||||
result = writeLowThreshold(rtd->spiCookie, rtd->lowThreshold);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
handleSpiError(rtd, result, "writeLowThreshold");
|
||||
}
|
||||
}
|
||||
if (rtd->writeHighThreshold) {
|
||||
additionalCfg = true;
|
||||
result = writeHighThreshold(rtd->spiCookie, rtd->highThreshold);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
handleSpiError(rtd, result, "writeHighThreshold");
|
||||
}
|
||||
}
|
||||
if (additionalCfg) {
|
||||
result = clearFaultStatus(rtd->spiCookie);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
handleSpiError(rtd, result, "clearFaultStatus");
|
||||
}
|
||||
}
|
||||
someRtdOn = true;
|
||||
rtd->configured = true;
|
||||
@ -77,7 +99,7 @@ bool Max31865RtdReader::periodicInitHandling() {
|
||||
}
|
||||
if (rtdIsActive(rtd->idx)) {
|
||||
someRtdUsable = true;
|
||||
result = biasSel(Bias::ON, rtd->spiCookie);
|
||||
result = writeBiasSel(Bias::ON, rtd->spiCookie);
|
||||
}
|
||||
}
|
||||
return someRtdUsable;
|
||||
@ -87,7 +109,7 @@ void Max31865RtdReader::periodicReadReqHandling() {
|
||||
using namespace MAX31865;
|
||||
MutexGuard mg(readerMutex);
|
||||
if (mg.getLockResult() != RETURN_OK) {
|
||||
// TODO: Emit warning, return
|
||||
sif::warning << "Max31865RtdReader::periodicReadReqHandling: Mutex lock failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
// Now request one shot config for all active RTDs
|
||||
@ -99,7 +121,7 @@ void Max31865RtdReader::periodicReadReqHandling() {
|
||||
uint8_t currentCfg = 0;
|
||||
auto result = readCfgReg(rtd->spiCookie, currentCfg);
|
||||
if (result != RETURN_OK) {
|
||||
// TODO: Emit warning, FDIR?
|
||||
handleSpiError(rtd, result, "readCfgReg");
|
||||
continue;
|
||||
}
|
||||
currentCfg |= (1 << CfgBitPos::ONE_SHOT);
|
||||
@ -113,7 +135,7 @@ void Max31865RtdReader::periodicReadHandling() {
|
||||
auto result = RETURN_OK;
|
||||
MutexGuard mg(readerMutex);
|
||||
if (mg.getLockResult() != RETURN_OK) {
|
||||
// TODO: Emit warning, return
|
||||
sif::warning << "Max31865RtdReader::periodicReadReqHandling: Mutex lock failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
// Now read the RTD values
|
||||
@ -126,7 +148,7 @@ void Max31865RtdReader::periodicReadHandling() {
|
||||
bool faultBitSet = false;
|
||||
result = readRtdVal(rtd->spiCookie, rtdVal, faultBitSet);
|
||||
if (result != RETURN_OK) {
|
||||
// TODO: Emit warning, FDIR?
|
||||
handleSpiError(rtd, result, "readRtdVal");
|
||||
continue;
|
||||
}
|
||||
if (faultBitSet) {
|
||||
@ -142,7 +164,7 @@ void Max31865RtdReader::periodicReadHandling() {
|
||||
// Even if a device was made inactive, turn off the bias here. If it was turned off, not
|
||||
// necessary anymore..
|
||||
if (rtd->on) {
|
||||
result = biasSel(Bias::OFF, rtd->spiCookie);
|
||||
result = writeBiasSel(Bias::OFF, rtd->spiCookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,20 +190,29 @@ ReturnValue_t Max31865RtdReader::sendMessage(CookieIF* cookie, const uint8_t* se
|
||||
if (cookie == nullptr) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
// Empty command.. don't fail for now
|
||||
if (sendLen < 1) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
MutexGuard mg(readerMutex);
|
||||
if (mg.getLockResult() != RETURN_OK) {
|
||||
// TODO: Emit warning, return
|
||||
sif::warning << "Max31865RtdReader::sendMessage: Mutex lock failed" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
auto* rtdCookie = dynamic_cast<Max31865ReaderCookie*>(cookie);
|
||||
uint8_t cmdRaw = sendData[0];
|
||||
if (cmdRaw > 2) {
|
||||
// TODO: Emit warning, invalid command
|
||||
return RETURN_OK;
|
||||
if (cmdRaw > EiveMax31855::RtdCommands::NUM_CMDS) {
|
||||
sif::warning << "Max31865RtdReader::sendMessage: Invalid command" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
auto thresholdHandler = [](Max31865ReaderCookie* rtdCookie, const uint8_t* sendData) {
|
||||
rtdCookie->lowThreshold = (sendData[1] << 8) | sendData[2];
|
||||
rtdCookie->highThreshold = (sendData[3] << 8) | sendData[4];
|
||||
rtdCookie->writeLowThreshold = true;
|
||||
rtdCookie->writeHighThreshold = true;
|
||||
};
|
||||
|
||||
auto cmd = static_cast<EiveMax31855::RtdCommands>(sendData[0]);
|
||||
switch (cmd) {
|
||||
case (EiveMax31855::RtdCommands::ON): {
|
||||
@ -191,6 +222,9 @@ ReturnValue_t Max31865RtdReader::sendMessage(CookieIF* cookie, const uint8_t* se
|
||||
rtdCookie->on = true;
|
||||
rtdCookie->active = false;
|
||||
rtdCookie->configured = false;
|
||||
if (sendLen == 5) {
|
||||
thresholdHandler(rtdCookie, sendData);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -204,6 +238,9 @@ ReturnValue_t Max31865RtdReader::sendMessage(CookieIF* cookie, const uint8_t* se
|
||||
} else {
|
||||
rtdCookie->active = true;
|
||||
}
|
||||
if (sendLen == 5) {
|
||||
thresholdHandler(rtdCookie, sendData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (EiveMax31855::RtdCommands::OFF): {
|
||||
@ -212,8 +249,24 @@ ReturnValue_t Max31865RtdReader::sendMessage(CookieIF* cookie, const uint8_t* se
|
||||
rtdCookie->configured = false;
|
||||
break;
|
||||
}
|
||||
case (EiveMax31855::RtdCommands::HIGH_TRESHOLD):
|
||||
case (EiveMax31855::RtdCommands::LOW_THRESHOLD):
|
||||
case (EiveMax31855::RtdCommands::HIGH_TRESHOLD): {
|
||||
if (sendLen == 3) {
|
||||
rtdCookie->highThreshold = (sendData[1] << 8) | sendData[2];
|
||||
rtdCookie->writeHighThreshold = true;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (EiveMax31855::RtdCommands::LOW_THRESHOLD): {
|
||||
if (sendLen == 3) {
|
||||
rtdCookie->lowThreshold = (sendData[1] << 8) | sendData[2];
|
||||
rtdCookie->writeLowThreshold = true;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (EiveMax31855::RtdCommands::CFG):
|
||||
default: {
|
||||
// TODO: Only implement if needed
|
||||
@ -252,11 +305,11 @@ ReturnValue_t Max31865RtdReader::readReceivedMessage(CookieIF* cookie, uint8_t**
|
||||
|
||||
ReturnValue_t Max31865RtdReader::writeCfgReg(SpiCookie* cookie, uint8_t cfg) {
|
||||
using namespace MAX31865;
|
||||
uint8_t cmd[2] = {REG_CONFIG | WRITE_BIT, cfg};
|
||||
return comIF->sendMessage(cookie, cmd, 2);
|
||||
uint8_t cmd = cfg;
|
||||
return writeNToReg(cookie, CONFIG, 1, &cmd, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::biasSel(MAX31865::Bias bias, SpiCookie* cookie) {
|
||||
ReturnValue_t Max31865RtdReader::writeBiasSel(MAX31865::Bias bias, SpiCookie* cookie) {
|
||||
using namespace MAX31865;
|
||||
uint8_t currentCfg = 0;
|
||||
auto result = readCfgReg(cookie, currentCfg);
|
||||
@ -271,42 +324,118 @@ ReturnValue_t Max31865RtdReader::biasSel(MAX31865::Bias bias, SpiCookie* cookie)
|
||||
return writeCfgReg(cookie, currentCfg);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::readCfgReg(SpiCookie* cookie, uint8_t& cfg) {
|
||||
ReturnValue_t Max31865RtdReader::clearFaultStatus(SpiCookie* cookie) {
|
||||
using namespace MAX31865;
|
||||
uint8_t cmd[2] = {REG_CONFIG, 0};
|
||||
ReturnValue_t result = comIF->sendMessage(cookie, cmd, 2);
|
||||
if (result != RETURN_OK) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
uint8_t reply[2] = {};
|
||||
uint8_t* replyPtr = reply;
|
||||
size_t dummyLen = 0;
|
||||
result = comIF->readReceivedMessage(cookie, &replyPtr, &dummyLen);
|
||||
// Read back the current configuration to avoid overwriting it when clearing te fault status
|
||||
uint8_t currentCfg = 0;
|
||||
auto result = readCfgReg(cookie, currentCfg);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
cfg = reply[1];
|
||||
return RETURN_OK;
|
||||
currentCfg |= (1 << CfgBitPos::FAULTY_STATUS_CLEAR);
|
||||
return writeCfgReg(cookie, currentCfg);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::readCfgReg(SpiCookie* cookie, uint8_t& cfg) {
|
||||
using namespace MAX31865;
|
||||
uint8_t* replyPtr = nullptr;
|
||||
auto result = readNFromReg(cookie, CONFIG, 1, &replyPtr);
|
||||
if (result == RETURN_OK) {
|
||||
cfg = replyPtr[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::writeLowThreshold(SpiCookie* cookie, uint16_t val) {
|
||||
using namespace MAX31865;
|
||||
uint8_t cmd[2] = {static_cast<uint8_t>((val >> 8) & 0xff), static_cast<uint8_t>(val & 0xff)};
|
||||
return writeNToReg(cookie, LOW_THRESHOLD, 2, cmd, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::writeHighThreshold(SpiCookie* cookie, uint16_t val) {
|
||||
using namespace MAX31865;
|
||||
uint8_t cmd[2] = {static_cast<uint8_t>((val >> 8) & 0xff), static_cast<uint8_t>(val & 0xff)};
|
||||
return writeNToReg(cookie, HIGH_THRESHOLD, 2, cmd, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::readLowThreshold(SpiCookie* cookie, uint16_t& lowThreshold) {
|
||||
using namespace MAX31865;
|
||||
uint8_t* replyPtr = nullptr;
|
||||
auto result = readNFromReg(cookie, LOW_THRESHOLD, 2, &replyPtr);
|
||||
if (result == RETURN_OK) {
|
||||
lowThreshold = (replyPtr[0] << 8) | replyPtr[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::readHighThreshold(SpiCookie* cookie, uint16_t& highThreshold) {
|
||||
using namespace MAX31865;
|
||||
uint8_t* replyPtr = nullptr;
|
||||
auto result = readNFromReg(cookie, HIGH_THRESHOLD, 2, &replyPtr);
|
||||
if (result == RETURN_OK) {
|
||||
highThreshold = (replyPtr[0] << 8) | replyPtr[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::writeNToReg(SpiCookie* cookie, uint8_t reg, size_t n, uint8_t* cmd,
|
||||
uint8_t** reply) {
|
||||
using namespace MAX31865;
|
||||
if (n > cmdBuf.size() - 1) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
cmdBuf[0] = reg | WRITE_BIT;
|
||||
for (size_t idx = 0; idx < n; idx++) {
|
||||
cmdBuf[idx + 1] = cmd[idx];
|
||||
}
|
||||
return comIF->sendMessage(cookie, cmd, 2);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::readRtdVal(SpiCookie* cookie, uint16_t& val, bool& faultBitSet) {
|
||||
using namespace MAX31865;
|
||||
uint8_t cmd[3] = {REG_RTD, 0, 0};
|
||||
auto result = comIF->sendMessage(cookie, cmd, 3);
|
||||
uint8_t* replyPtr = nullptr;
|
||||
auto result = readNFromReg(cookie, RTD, 2, &replyPtr);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (replyPtr[1] & 0b0000'0001) {
|
||||
faultBitSet = true;
|
||||
}
|
||||
// Shift 1 to the right to remove fault bit
|
||||
val = ((replyPtr[0] << 8) | replyPtr[1]) >> 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::readNFromReg(SpiCookie* cookie, uint8_t reg, size_t n,
|
||||
uint8_t** reply) {
|
||||
using namespace MAX31865;
|
||||
if (n > 4) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
// Clear write bit in any case
|
||||
reg &= ~WRITE_BIT;
|
||||
cmdBuf[0] = reg;
|
||||
std::memset(cmdBuf.data() + 1, 0, n);
|
||||
ReturnValue_t result = comIF->sendMessage(cookie, cmdBuf.data(), n);
|
||||
if (result != RETURN_OK) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
uint8_t reply[3] = {};
|
||||
uint8_t* replyPtr = reply;
|
||||
uint8_t* replyPtr = replyBuf.data();
|
||||
size_t dummyLen = 0;
|
||||
result = comIF->readReceivedMessage(cookie, &replyPtr, &dummyLen);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (reply[2] & 0b0000'0001) {
|
||||
faultBitSet = true;
|
||||
if (reply != nullptr) {
|
||||
*reply = replyBuf.data() + 1;
|
||||
}
|
||||
// Shift 1 to the right to remove fault bit
|
||||
val = ((reply[1] << 8) | reply[2]) >> 1;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865RtdReader::handleSpiError(Max31865ReaderCookie* cookie, ReturnValue_t result,
|
||||
const char* ctx) {
|
||||
cookie->db.spiErrorCount.value += 1;
|
||||
sif::warning << "Max31865RtdReader::handleSpiError: " << ctx << " | Failed with result " << result
|
||||
<< std::endl;
|
||||
return result;
|
||||
}
|
@ -24,6 +24,10 @@ struct Max31865ReaderCookie {
|
||||
bool on = false;
|
||||
bool configured = false;
|
||||
bool active = false;
|
||||
bool writeLowThreshold = false;
|
||||
bool writeHighThreshold = false;
|
||||
uint16_t lowThreshold = 0;
|
||||
uint16_t highThreshold = 0;
|
||||
SpiCookie* spiCookie = nullptr;
|
||||
|
||||
// Exchange data buffer struct
|
||||
@ -35,12 +39,13 @@ class Max31865RtdReader : public SystemObject,
|
||||
public DeviceCommunicationIF {
|
||||
public:
|
||||
Max31865RtdReader(object_id_t objectId, SpiComIF* comIF);
|
||||
void addRtd(Max31865ReaderCookie rtdCookie);
|
||||
|
||||
[[noreturn]] ReturnValue_t performOperation(uint8_t operationCode) override;
|
||||
|
||||
private:
|
||||
std::vector<Max31865ReaderCookie*> rtds;
|
||||
std::array<uint8_t, 4> cmdBuf = {};
|
||||
std::array<uint8_t, 4> replyBuf = {};
|
||||
MutexIF* readerMutex;
|
||||
|
||||
void rtdMainLoop();
|
||||
@ -50,9 +55,18 @@ class Max31865RtdReader : public SystemObject,
|
||||
|
||||
bool rtdIsActive(uint8_t idx);
|
||||
ReturnValue_t writeCfgReg(SpiCookie* cookie, uint8_t cfg);
|
||||
ReturnValue_t biasSel(MAX31865::Bias bias, SpiCookie* cookie);
|
||||
ReturnValue_t writeBiasSel(MAX31865::Bias bias, SpiCookie* cookie);
|
||||
ReturnValue_t readCfgReg(SpiCookie* cookie, uint8_t& cfg);
|
||||
ReturnValue_t readRtdVal(SpiCookie* cookie, uint16_t& val, bool& faultBitSet);
|
||||
ReturnValue_t writeLowThreshold(SpiCookie* cookie, uint16_t val);
|
||||
ReturnValue_t writeHighThreshold(SpiCookie* cookie, uint16_t val);
|
||||
ReturnValue_t readLowThreshold(SpiCookie* cookie, uint16_t& val);
|
||||
ReturnValue_t readHighThreshold(SpiCookie* cookie, uint16_t& val);
|
||||
ReturnValue_t clearFaultStatus(SpiCookie* cookie);
|
||||
|
||||
ReturnValue_t readNFromReg(SpiCookie* cookie, uint8_t reg, size_t n, uint8_t** reply);
|
||||
ReturnValue_t writeNToReg(SpiCookie* cookie, uint8_t reg, size_t n, uint8_t* cmd,
|
||||
uint8_t** reply);
|
||||
|
||||
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||
@ -60,6 +74,8 @@ class Max31865RtdReader : public SystemObject,
|
||||
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||
|
||||
ReturnValue_t handleSpiError(Max31865ReaderCookie* cookie, ReturnValue_t result, const char* ctx);
|
||||
|
||||
SpiComIF* comIF;
|
||||
};
|
||||
|
@ -124,9 +124,10 @@ uint32_t Max31865EiveHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeT
|
||||
|
||||
ReturnValue_t Max31865EiveHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
localDataPoolMap.emplace(MAX31865::PoolIds::RTD_VALUE, new PoolEntry<float>({0}));
|
||||
localDataPoolMap.emplace(MAX31865::PoolIds::TEMPERATURE_C, new PoolEntry<float>({0}));
|
||||
localDataPoolMap.emplace(MAX31865::PoolIds::FAULT_BYTE, new PoolEntry<uint8_t>({0}));
|
||||
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}));
|
||||
localDataPoolMap.emplace(static_cast<lp_id_t>(PoolIds::FAULT_BYTE), new PoolEntry<uint8_t>({0}));
|
||||
poolManager.subscribeForPeriodicPacket(sensorDataset.getSid(), false, 30.0, false);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t d
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::CONFIG_CMD);
|
||||
if (commandDataLen == 1) {
|
||||
commandBuffer[1] = commandData[0];
|
||||
currentCfg = commandData[0];
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -169,7 +170,7 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t d
|
||||
}
|
||||
case (MAX31865::CLEAR_FAULT_BYTE): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::CONFIG_CMD);
|
||||
commandBuffer[1] = MAX31865::CLEAR_FAULT_BIT_VAL;
|
||||
commandBuffer[1] = currentCfg | MAX31865::CLEAR_FAULT_BIT_VAL;
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -512,9 +513,11 @@ ReturnValue_t Max31865PT1000Handler::getSwitches(const uint8_t **switches,
|
||||
|
||||
ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(MAX31865::PoolIds::RTD_VALUE, new PoolEntry<float>({0}));
|
||||
localDataPoolMap.emplace(MAX31865::PoolIds::TEMPERATURE_C, new PoolEntry<float>({0}, 1, true));
|
||||
localDataPoolMap.emplace(MAX31865::PoolIds::FAULT_BYTE, new PoolEntry<uint8_t>({0}));
|
||||
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));
|
||||
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;
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ class Max31865PT1000Handler : public DeviceHandlerBase {
|
||||
|
||||
bool resetFaultBit = false;
|
||||
dur_millis_t startTime = 0;
|
||||
uint8_t currentCfg = 0;
|
||||
std::string locString;
|
||||
uint8_t faultByte = 0;
|
||||
uint8_t deviceIdx = 0;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace MAX31865 {
|
||||
|
||||
enum PoolIds : lp_id_t { RTD_VALUE, TEMPERATURE_C, FAULT_BYTE };
|
||||
enum class PoolIds : lp_id_t { RTD_VALUE, TEMPERATURE_C, FAULT_BYTE };
|
||||
enum Wires : unsigned int { TWO_WIRE = 0, THREE_WIRE = 1, FOUR_WIRE = 0 };
|
||||
|
||||
enum ConvMode : unsigned int { NORM_OFF = 0, AUTO = 1 };
|
||||
@ -30,26 +30,30 @@ enum CfgBitPos {
|
||||
|
||||
static constexpr uint32_t WARMUP_MS = 100;
|
||||
|
||||
static constexpr uint8_t WRITE_BIT = 0b10000000;
|
||||
|
||||
enum Regs : uint8_t {
|
||||
CONFIG = 0x00,
|
||||
RTD = 0x01,
|
||||
HIGH_THRESHOLD = 0x03,
|
||||
LOW_THRESHOLD = 0x05,
|
||||
FAULT_BYTE = 0x07
|
||||
};
|
||||
|
||||
static constexpr DeviceCommandId_t CONFIG_CMD = 0x80;
|
||||
static constexpr DeviceCommandId_t WRITE_HIGH_THRESHOLD = 0x83;
|
||||
static constexpr DeviceCommandId_t WRITE_LOW_THRESHOLD = 0x85;
|
||||
|
||||
static constexpr DeviceCommandId_t REQUEST_CONFIG = 0x00;
|
||||
static constexpr DeviceCommandId_t REQUEST_RTD = 0x01;
|
||||
static constexpr DeviceCommandId_t REQUEST_HIGH_THRESHOLD = 0x03;
|
||||
static constexpr DeviceCommandId_t REQUEST_LOW_THRESHOLD = 0x05;
|
||||
static constexpr DeviceCommandId_t REQUEST_FAULT_BYTE = 0x07;
|
||||
|
||||
static constexpr DeviceCommandId_t REQUEST_CONFIG = CONFIG;
|
||||
static constexpr DeviceCommandId_t REQUEST_RTD = RTD;
|
||||
static constexpr DeviceCommandId_t REQUEST_HIGH_THRESHOLD = HIGH_THRESHOLD;
|
||||
static constexpr DeviceCommandId_t REQUEST_LOW_THRESHOLD = LOW_THRESHOLD;
|
||||
static constexpr DeviceCommandId_t REQUEST_FAULT_BYTE = FAULT_BYTE;
|
||||
static constexpr DeviceCommandId_t CLEAR_FAULT_BYTE = 0x08;
|
||||
|
||||
static constexpr uint32_t MAX31865_SET_ID = REQUEST_RTD;
|
||||
static constexpr uint8_t CLEAR_FAULT_BIT_VAL = 0b0000'0010;
|
||||
|
||||
static constexpr uint8_t WRITE_BIT = 0b10000000;
|
||||
|
||||
static constexpr uint8_t REG_CONFIG = 0x00;
|
||||
static constexpr uint8_t REG_RTD = 0x01;
|
||||
|
||||
static constexpr size_t MAX_REPLY_SIZE = 5;
|
||||
|
||||
class Max31865Set : public StaticLocalDataSet<3> {
|
||||
@ -67,9 +71,12 @@ class Max31865Set : public StaticLocalDataSet<3> {
|
||||
*/
|
||||
Max31865Set(object_id_t objectId, uint32_t setId) : StaticLocalDataSet(sid_t(objectId, setId)) {}
|
||||
|
||||
lp_var_t<float> rtdValue = lp_var_t<float>(sid.objectId, PoolIds::RTD_VALUE, this);
|
||||
lp_var_t<float> temperatureCelcius = lp_var_t<float>(sid.objectId, PoolIds::TEMPERATURE_C, this);
|
||||
lp_var_t<uint8_t> errorByte = lp_var_t<uint8_t>(sid.objectId, PoolIds::FAULT_BYTE, this);
|
||||
lp_var_t<float> rtdValue =
|
||||
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> errorByte =
|
||||
lp_var_t<uint8_t>(sid.objectId, static_cast<lp_id_t>(PoolIds::FAULT_BYTE), this);
|
||||
};
|
||||
|
||||
} // namespace MAX31865
|
||||
@ -86,7 +93,7 @@ enum RtdCommands : DeviceCommandId_t {
|
||||
HIGH_TRESHOLD = 4,
|
||||
OFF = 5,
|
||||
CFG = 6,
|
||||
|
||||
NUM_CMDS
|
||||
};
|
||||
|
||||
class ReadOutStruct : public SerialLinkedListAdapter<SerializeIF> {
|
||||
|
Loading…
Reference in New Issue
Block a user