new RTD reader module handling all RTD SPI Communication
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:
@ -93,13 +93,13 @@ void Max31865PT1000Handler::doShutDown() {
|
||||
|
||||
ReturnValue_t Max31865PT1000Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
if (internalState == InternalState::RUNNING) {
|
||||
*id = Max31865Definitions::REQUEST_RTD;
|
||||
*id = MAX31865::REQUEST_RTD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
} else if (internalState == InternalState::REQUEST_FAULT_BYTE) {
|
||||
*id = Max31865Definitions::REQUEST_FAULT_BYTE;
|
||||
*id = MAX31865::REQUEST_FAULT_BYTE;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
} else if (internalState == InternalState::CLEAR_FAULT_BYTE) {
|
||||
*id = Max31865Definitions::CLEAR_FAULT_BYTE;
|
||||
*id = MAX31865::CLEAR_FAULT_BYTE;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
} else {
|
||||
return DeviceHandlerBase::NOTHING_TO_SEND;
|
||||
@ -113,32 +113,32 @@ ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand(DeviceCommandI
|
||||
case (InternalState::RUNNING):
|
||||
return DeviceHandlerBase::NOTHING_TO_SEND;
|
||||
case (InternalState::CONFIGURE): {
|
||||
*id = Max31865Definitions::CONFIG_CMD;
|
||||
*id = MAX31865::CONFIG_CMD;
|
||||
uint8_t config[1] = {DEFAULT_CONFIG};
|
||||
return buildCommandFromCommand(*id, config, 1);
|
||||
}
|
||||
case (InternalState::REQUEST_CONFIG): {
|
||||
*id = Max31865Definitions::REQUEST_CONFIG;
|
||||
*id = MAX31865::REQUEST_CONFIG;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (InternalState::CONFIG_HIGH_THRESHOLD): {
|
||||
*id = Max31865Definitions::WRITE_HIGH_THRESHOLD;
|
||||
*id = MAX31865::WRITE_HIGH_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (InternalState::REQUEST_HIGH_THRESHOLD): {
|
||||
*id = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
|
||||
*id = MAX31865::REQUEST_HIGH_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (InternalState::CONFIG_LOW_THRESHOLD): {
|
||||
*id = Max31865Definitions::WRITE_LOW_THRESHOLD;
|
||||
*id = MAX31865::WRITE_LOW_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (InternalState::REQUEST_LOW_THRESHOLD): {
|
||||
*id = Max31865Definitions::REQUEST_LOW_THRESHOLD;
|
||||
*id = MAX31865::REQUEST_LOW_THRESHOLD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (InternalState::CLEAR_FAULT_BYTE): {
|
||||
*id = Max31865Definitions::CLEAR_FAULT_BYTE;
|
||||
*id = MAX31865::CLEAR_FAULT_BYTE;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
@ -156,8 +156,8 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t d
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (Max31865Definitions::CONFIG_CMD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::CONFIG_CMD);
|
||||
case (MAX31865::CONFIG_CMD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::CONFIG_CMD);
|
||||
if (commandDataLen == 1) {
|
||||
commandBuffer[1] = commandData[0];
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
@ -167,54 +167,54 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t d
|
||||
return DeviceHandlerIF::NO_COMMAND_DATA;
|
||||
}
|
||||
}
|
||||
case (Max31865Definitions::CLEAR_FAULT_BYTE): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::CONFIG_CMD);
|
||||
commandBuffer[1] = Max31865Definitions::CLEAR_FAULT_BIT_VAL;
|
||||
case (MAX31865::CLEAR_FAULT_BYTE): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::CONFIG_CMD);
|
||||
commandBuffer[1] = MAX31865::CLEAR_FAULT_BIT_VAL;
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_CONFIG): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_CONFIG);
|
||||
case (MAX31865::REQUEST_CONFIG): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_CONFIG);
|
||||
commandBuffer[1] = 0x00; // dummy byte
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::WRITE_HIGH_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::WRITE_HIGH_THRESHOLD);
|
||||
case (MAX31865::WRITE_HIGH_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::WRITE_HIGH_THRESHOLD);
|
||||
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();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_HIGH_THRESHOLD);
|
||||
case (MAX31865::REQUEST_HIGH_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_HIGH_THRESHOLD);
|
||||
commandBuffer[1] = 0x00; // dummy byte
|
||||
commandBuffer[2] = 0x00; // dummy byte
|
||||
DeviceHandlerBase::rawPacketLen = 3;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::WRITE_LOW_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::WRITE_LOW_THRESHOLD);
|
||||
case (MAX31865::WRITE_LOW_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::WRITE_LOW_THRESHOLD);
|
||||
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();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_LOW_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_LOW_THRESHOLD);
|
||||
case (MAX31865::REQUEST_LOW_THRESHOLD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_LOW_THRESHOLD);
|
||||
commandBuffer[1] = 0x00; // dummy byte
|
||||
commandBuffer[2] = 0x00; // dummy byte
|
||||
DeviceHandlerBase::rawPacketLen = 3;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_RTD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_RTD);
|
||||
case (MAX31865::REQUEST_RTD): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_RTD);
|
||||
// two dummy bytes
|
||||
commandBuffer[1] = 0x00;
|
||||
commandBuffer[2] = 0x00;
|
||||
@ -222,8 +222,8 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t d
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_FAULT_BYTE): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_FAULT_BYTE);
|
||||
case (MAX31865::REQUEST_FAULT_BYTE): {
|
||||
commandBuffer[0] = static_cast<uint8_t>(MAX31865::REQUEST_FAULT_BYTE);
|
||||
commandBuffer[1] = 0x00;
|
||||
DeviceHandlerBase::rawPacketLen = 2;
|
||||
DeviceHandlerBase::rawPacket = commandBuffer.data();
|
||||
@ -236,15 +236,15 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t d
|
||||
}
|
||||
|
||||
void Max31865PT1000Handler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(Max31865Definitions::CONFIG_CMD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_CONFIG, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::WRITE_LOW_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_LOW_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::WRITE_HIGH_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_HIGH_THRESHOLD, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3, &sensorDataset);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3);
|
||||
insertInCommandAndReplyMap(Max31865Definitions::CLEAR_FAULT_BYTE, 3);
|
||||
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);
|
||||
}
|
||||
|
||||
ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t remainingSize,
|
||||
@ -253,7 +253,7 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t r
|
||||
size_t configReplySize = 2;
|
||||
|
||||
if (remainingSize == rtdReplySize and internalState == InternalState::RUNNING) {
|
||||
*foundId = Max31865Definitions::REQUEST_RTD;
|
||||
*foundId = MAX31865::REQUEST_RTD;
|
||||
*foundLen = rtdReplySize;
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -262,24 +262,24 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t r
|
||||
switch (internalState) {
|
||||
case (InternalState::CONFIG_HIGH_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::WRITE_HIGH_THRESHOLD;
|
||||
*foundId = MAX31865::WRITE_HIGH_THRESHOLD;
|
||||
commandExecuted = true;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case (InternalState::REQUEST_HIGH_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
|
||||
*foundId = MAX31865::REQUEST_HIGH_THRESHOLD;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case (InternalState::CONFIG_LOW_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::WRITE_LOW_THRESHOLD;
|
||||
*foundId = MAX31865::WRITE_LOW_THRESHOLD;
|
||||
commandExecuted = true;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case (InternalState::REQUEST_LOW_THRESHOLD): {
|
||||
*foundLen = 3;
|
||||
*foundId = Max31865Definitions::REQUEST_LOW_THRESHOLD;
|
||||
*foundId = MAX31865::REQUEST_LOW_THRESHOLD;
|
||||
return RETURN_OK;
|
||||
}
|
||||
default: {
|
||||
@ -293,13 +293,13 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t r
|
||||
if (internalState == InternalState::CONFIGURE) {
|
||||
commandExecuted = true;
|
||||
*foundLen = configReplySize;
|
||||
*foundId = Max31865Definitions::CONFIG_CMD;
|
||||
*foundId = MAX31865::CONFIG_CMD;
|
||||
} else if (internalState == InternalState::REQUEST_FAULT_BYTE) {
|
||||
*foundId = Max31865Definitions::REQUEST_FAULT_BYTE;
|
||||
*foundId = MAX31865::REQUEST_FAULT_BYTE;
|
||||
*foundLen = 2;
|
||||
internalState = InternalState::RUNNING;
|
||||
} else if (internalState == InternalState::CLEAR_FAULT_BYTE) {
|
||||
*foundId = Max31865Definitions::CLEAR_FAULT_BYTE;
|
||||
*foundId = MAX31865::CLEAR_FAULT_BYTE;
|
||||
*foundLen = 2;
|
||||
if (mode == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
@ -307,7 +307,7 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t r
|
||||
internalState = InternalState::RUNNING;
|
||||
}
|
||||
} else {
|
||||
*foundId = Max31865Definitions::REQUEST_CONFIG;
|
||||
*foundId = MAX31865::REQUEST_CONFIG;
|
||||
*foundLen = configReplySize;
|
||||
}
|
||||
}
|
||||
@ -318,7 +318,7 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t r
|
||||
ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case (Max31865Definitions::REQUEST_CONFIG): {
|
||||
case (MAX31865::REQUEST_CONFIG): {
|
||||
if (packet[1] != DEFAULT_CONFIG) {
|
||||
if (warningSwitch) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
@ -342,7 +342,7 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_LOW_THRESHOLD): {
|
||||
case (MAX31865::REQUEST_LOW_THRESHOLD): {
|
||||
uint16_t readLowThreshold = packet[1] << 8 | packet[2];
|
||||
if (readLowThreshold != LOW_THRESHOLD) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
@ -360,7 +360,7 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
commandExecuted = true;
|
||||
break;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
|
||||
case (MAX31865::REQUEST_HIGH_THRESHOLD): {
|
||||
uint16_t readHighThreshold = packet[1] << 8 | packet[2];
|
||||
if (readHighThreshold != HIGH_THRESHOLD) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
@ -378,7 +378,7 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
commandExecuted = true;
|
||||
break;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_RTD): {
|
||||
case (MAX31865::REQUEST_RTD): {
|
||||
// first bit of LSB reply byte is the fault bit
|
||||
uint8_t faultBit = packet[2] & 0b0000'0001;
|
||||
if (resetFaultBit) {
|
||||
@ -403,9 +403,9 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
if (debugDivider->checkAndIncrement()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "Max31865: ObjID " << std::hex << this->getObjectId() << " | RTD "
|
||||
<< std::dec << static_cast<int>(deviceIdx) << ": R[Ohm] " << rtdValue
|
||||
<< " Ohms | Approx T[C]: " << approxTemp << std::endl;
|
||||
sif::info << "Max31865: " << std::setw(28) << std::left << locString << std::right
|
||||
<< " | R[Ohm] " << rtdValue << " Ohms | Approx T[C]: " << approxTemp
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printInfo("Max31685: Measured resistance is %f Ohms\n", rtdValue);
|
||||
sif::printInfo("Approximated temperature is %f C\n", approxTemp);
|
||||
@ -438,7 +438,7 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
sensorDataset.temperatureCelcius = approxTemp;
|
||||
break;
|
||||
}
|
||||
case (Max31865Definitions::REQUEST_FAULT_BYTE): {
|
||||
case (MAX31865::REQUEST_FAULT_BYTE): {
|
||||
faultByte = packet[1];
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
@ -512,10 +512,9 @@ ReturnValue_t Max31865PT1000Handler::getSwitches(const uint8_t **switches,
|
||||
|
||||
ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(Max31865Definitions::PoolIds::RTD_VALUE, new PoolEntry<float>({0}));
|
||||
localDataPoolMap.emplace(Max31865Definitions::PoolIds::TEMPERATURE_C,
|
||||
new PoolEntry<float>({0}, 1, true));
|
||||
localDataPoolMap.emplace(Max31865Definitions::PoolIds::FAULT_BYTE, new PoolEntry<uint8_t>({0}));
|
||||
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}));
|
||||
poolManager.subscribeForPeriodicPacket(sensorDataset.getSid(), false, 30.0, false);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -530,6 +529,9 @@ void Max31865PT1000Handler::modeChanged() {
|
||||
}
|
||||
}
|
||||
|
||||
void Max31865PT1000Handler::setDeviceIdx(uint8_t idx) { deviceIdx = idx; }
|
||||
void Max31865PT1000Handler::setDeviceInfo(uint8_t idx, const std::string &locString_) {
|
||||
deviceIdx = idx;
|
||||
locString = locString_;
|
||||
}
|
||||
|
||||
void Max31865PT1000Handler::setDebugMode(bool enable) { this->debugMode = enable; }
|
||||
|
Reference in New Issue
Block a user