added object id in printouts of rtds

This commit is contained in:
2021-10-19 16:13:56 +02:00
parent 65b0376f69
commit 811fe96557
2 changed files with 405 additions and 399 deletions

View File

@ -6,11 +6,11 @@
#include <cmath> #include <cmath>
Max31865PT1000Handler::Max31865PT1000Handler(object_id_t objectId, object_id_t comIF, Max31865PT1000Handler::Max31865PT1000Handler(object_id_t objectId, object_id_t comIF,
CookieIF *comCookie) : CookieIF *comCookie):
DeviceHandlerBase(objectId, comIF, comCookie), sensorDataset(this), sensorDatasetSid( DeviceHandlerBase(objectId, comIF, comCookie), sensorDataset(this),
sensorDataset.getSid()) { sensorDatasetSid(sensorDataset.getSid()) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
debugDivider = new PeriodicOperationDivider(0); debugDivider = new PeriodicOperationDivider(0);
#endif #endif
} }
@ -18,477 +18,483 @@ Max31865PT1000Handler::~Max31865PT1000Handler() {
} }
void Max31865PT1000Handler::doStartUp() { void Max31865PT1000Handler::doStartUp() {
// if (internalState == InternalState::NONE) { if(internalState == InternalState::NONE) {
// internalState = InternalState::WARMUP; internalState = InternalState::WARMUP;
// Clock::getUptime(&startTime); Clock::getUptime(&startTime);
// } }
//
// if (internalState == InternalState::WARMUP) { if(internalState == InternalState::WARMUP) {
// dur_millis_t timeNow = 0; dur_millis_t timeNow = 0;
// Clock::getUptime(&timeNow); Clock::getUptime(&timeNow);
// if (timeNow - startTime >= 100) { if(timeNow - startTime >= 100) {
// internalState = InternalState::CONFIGURE; internalState = InternalState::CONFIGURE;
// } }
// } }
//
// if (internalState == InternalState::CONFIGURE) { if(internalState == InternalState::CONFIGURE) {
// if (commandExecuted) { if(commandExecuted) {
// commandExecuted = false; commandExecuted = false;
// internalState = InternalState::REQUEST_CONFIG; internalState = InternalState::REQUEST_CONFIG;
// } }
// } }
//
// if (internalState == InternalState::REQUEST_CONFIG) { if(internalState == InternalState::REQUEST_CONFIG) {
// if (commandExecuted) { if (commandExecuted) {
// commandExecuted = false; commandExecuted = false;
// internalState = InternalState::CONFIG_HIGH_THRESHOLD; internalState = InternalState::CONFIG_HIGH_THRESHOLD;
// } }
// } }
//
// if (internalState == InternalState::CONFIG_HIGH_THRESHOLD) { if(internalState == InternalState::CONFIG_HIGH_THRESHOLD) {
// if (commandExecuted) { if(commandExecuted) {
// internalState = InternalState::REQUEST_HIGH_THRESHOLD; internalState = InternalState::REQUEST_HIGH_THRESHOLD;
// commandExecuted = false; commandExecuted = false;
// } }
// } }
//
// if (internalState == InternalState::REQUEST_HIGH_THRESHOLD) { if(internalState == InternalState::REQUEST_HIGH_THRESHOLD) {
// if (commandExecuted) { if(commandExecuted) {
// internalState = InternalState::CONFIG_LOW_THRESHOLD; internalState = InternalState::CONFIG_LOW_THRESHOLD;
// commandExecuted = false; commandExecuted = false;
// } }
// } }
//
// if (internalState == InternalState::CONFIG_LOW_THRESHOLD) { if(internalState == InternalState::CONFIG_LOW_THRESHOLD) {
// if (commandExecuted) { if(commandExecuted) {
// internalState = InternalState::REQUEST_LOW_THRESHOLD; internalState = InternalState::REQUEST_LOW_THRESHOLD;
// commandExecuted = false; commandExecuted = false;
// } }
// } }
//
// if (internalState == InternalState::REQUEST_LOW_THRESHOLD) { if(internalState == InternalState::REQUEST_LOW_THRESHOLD) {
// if (commandExecuted) { if(commandExecuted) {
// setMode(MODE_ON); setMode(MODE_ON);
// setMode(MODE_NORMAL); setMode(MODE_NORMAL);
// internalState = InternalState::RUNNING; internalState = InternalState::RUNNING;
// commandExecuted = false; commandExecuted = false;
// } }
// } }
setMode(MODE_NORMAL);
} }
void Max31865PT1000Handler::doShutDown() { void Max31865PT1000Handler::doShutDown() {
commandExecuted = false; commandExecuted = false;
setMode(_MODE_POWER_DOWN); setMode(_MODE_POWER_DOWN);
} }
ReturnValue_t Max31865PT1000Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t Max31865PT1000Handler::buildNormalDeviceCommand(
// if (internalState == InternalState::RUNNING) { DeviceCommandId_t *id) {
// *id = Max31865Definitions::REQUEST_RTD; if(internalState == InternalState::RUNNING) {
// return buildCommandFromCommand(*id, nullptr, 0); *id = Max31865Definitions::REQUEST_RTD;
// } else if (internalState == InternalState::REQUEST_FAULT_BYTE) { return buildCommandFromCommand(*id, nullptr, 0);
// *id = Max31865Definitions::REQUEST_FAULT_BYTE; }
// return buildCommandFromCommand(*id, nullptr, 0); else if(internalState == InternalState::REQUEST_FAULT_BYTE) {
// } else { *id = Max31865Definitions::REQUEST_FAULT_BYTE;
// return DeviceHandlerBase::NOTHING_TO_SEND; return buildCommandFromCommand(*id, nullptr, 0);
// } }
else {
if (internalState == InternalState::CONFIGURE) { return DeviceHandlerBase::NOTHING_TO_SEND;
*id = Max31865Definitions::CONFIG_CMD; }
uint8_t config[1] = { DEFAULT_CONFIG };
return buildCommandFromCommand(*id, config, 1);
} else if (internalState == InternalState::REQUEST_CONFIG) {
*id = Max31865Definitions::REQUEST_CONFIG;
//internalState = InternalState::NONE;
return buildCommandFromCommand(*id, nullptr, 0);
} else {
return DeviceHandlerBase::NOTHING_TO_SEND;
}
} }
ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand(
switch (internalState) { DeviceCommandId_t *id) {
case (InternalState::NONE): switch(internalState) {
case (InternalState::WARMUP): case(InternalState::NONE):
case (InternalState::RUNNING): case(InternalState::WARMUP):
return DeviceHandlerBase::NOTHING_TO_SEND; case(InternalState::RUNNING):
case (InternalState::CONFIGURE): { return DeviceHandlerBase::NOTHING_TO_SEND;
*id = Max31865Definitions::CONFIG_CMD; case(InternalState::CONFIGURE): {
uint8_t config[1] = { DEFAULT_CONFIG }; *id = Max31865Definitions::CONFIG_CMD;
return buildCommandFromCommand(*id, config, 1); uint8_t config[1] = {DEFAULT_CONFIG};
} return buildCommandFromCommand(*id, config, 1);
case (InternalState::REQUEST_CONFIG): { }
*id = Max31865Definitions::REQUEST_CONFIG; case(InternalState::REQUEST_CONFIG): {
return buildCommandFromCommand(*id, nullptr, 0); *id = Max31865Definitions::REQUEST_CONFIG;
} return buildCommandFromCommand(*id, nullptr, 0);
case (InternalState::CONFIG_HIGH_THRESHOLD): { }
*id = Max31865Definitions::WRITE_HIGH_THRESHOLD; case(InternalState::CONFIG_HIGH_THRESHOLD): {
return buildCommandFromCommand(*id, nullptr, 0); *id = Max31865Definitions::WRITE_HIGH_THRESHOLD;
} return buildCommandFromCommand(*id, nullptr, 0);
case (InternalState::REQUEST_HIGH_THRESHOLD): { }
*id = Max31865Definitions::REQUEST_HIGH_THRESHOLD; case(InternalState::REQUEST_HIGH_THRESHOLD): {
return buildCommandFromCommand(*id, nullptr, 0); *id = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
} return buildCommandFromCommand(*id, nullptr, 0);
case (InternalState::CONFIG_LOW_THRESHOLD): { }
*id = Max31865Definitions::WRITE_LOW_THRESHOLD; case(InternalState::CONFIG_LOW_THRESHOLD): {
return buildCommandFromCommand(*id, nullptr, 0); *id = Max31865Definitions::WRITE_LOW_THRESHOLD;
} return buildCommandFromCommand(*id, nullptr, 0);
case (InternalState::REQUEST_LOW_THRESHOLD): { }
*id = Max31865Definitions::REQUEST_LOW_THRESHOLD; case(InternalState::REQUEST_LOW_THRESHOLD): {
return buildCommandFromCommand(*id, nullptr, 0); *id = Max31865Definitions::REQUEST_LOW_THRESHOLD;
} return buildCommandFromCommand(*id, nullptr, 0);
}
default: default:
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Max31865PT1000Handler: Invalid internal state" << std::endl; sif::error << "Max31865PT1000Handler: Invalid internal state" << std::endl;
#else #else
sif::printError("Max31865PT1000Handler: Invalid internal state\n"); sif::printError("Max31865PT1000Handler: Invalid internal state\n");
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand(
const uint8_t *commandData, size_t commandDataLen) { DeviceCommandId_t deviceCommand, const uint8_t *commandData,
switch (deviceCommand) { size_t commandDataLen) {
case (Max31865Definitions::CONFIG_CMD): { switch(deviceCommand) {
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::CONFIG_CMD); case(Max31865Definitions::CONFIG_CMD) : {
if (commandDataLen == 1) { commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::CONFIG_CMD);
commandBuffer[1] = commandData[0]; if(commandDataLen == 1) {
DeviceHandlerBase::rawPacketLen = 2; commandBuffer[1] = commandData[0];
DeviceHandlerBase::rawPacket = commandBuffer.data(); DeviceHandlerBase::rawPacketLen = 2;
return HasReturnvaluesIF::RETURN_OK; DeviceHandlerBase::rawPacket = commandBuffer.data();
} else { return HasReturnvaluesIF::RETURN_OK;
return DeviceHandlerIF::NO_COMMAND_DATA; }
} else {
} return DeviceHandlerIF::NO_COMMAND_DATA;
case (Max31865Definitions::REQUEST_CONFIG): { }
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_CONFIG); }
commandBuffer[1] = 0x00; // dummy byte case(Max31865Definitions::REQUEST_CONFIG): {
DeviceHandlerBase::rawPacketLen = 2; commandBuffer[0] = static_cast<uint8_t>(
DeviceHandlerBase::rawPacket = commandBuffer.data(); Max31865Definitions::REQUEST_CONFIG);
return HasReturnvaluesIF::RETURN_OK; commandBuffer[1] = 0x00; // dummy byte
} DeviceHandlerBase::rawPacketLen = 2;
case (Max31865Definitions::WRITE_HIGH_THRESHOLD): { DeviceHandlerBase::rawPacket = commandBuffer.data();
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::WRITE_HIGH_THRESHOLD); return HasReturnvaluesIF::RETURN_OK;
commandBuffer[1] = static_cast<uint8_t>(HIGH_THRESHOLD >> 8); }
commandBuffer[2] = static_cast<uint8_t>(HIGH_THRESHOLD & 0xFF); case(Max31865Definitions::WRITE_HIGH_THRESHOLD): {
DeviceHandlerBase::rawPacketLen = 3; commandBuffer[0] = static_cast<uint8_t>(
DeviceHandlerBase::rawPacket = commandBuffer.data(); Max31865Definitions::WRITE_HIGH_THRESHOLD);
return HasReturnvaluesIF::RETURN_OK; commandBuffer[1] = static_cast<uint8_t>(HIGH_THRESHOLD >> 8);
} commandBuffer[2] = static_cast<uint8_t>(HIGH_THRESHOLD & 0xFF);
case (Max31865Definitions::REQUEST_HIGH_THRESHOLD): { DeviceHandlerBase::rawPacketLen = 3;
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_HIGH_THRESHOLD); DeviceHandlerBase::rawPacket = commandBuffer.data();
commandBuffer[1] = 0x00; //dummy byte return HasReturnvaluesIF::RETURN_OK;
commandBuffer[2] = 0x00; //dummy byte }
DeviceHandlerBase::rawPacketLen = 3; case(Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
DeviceHandlerBase::rawPacket = commandBuffer.data(); commandBuffer[0] = static_cast<uint8_t>(
return HasReturnvaluesIF::RETURN_OK; Max31865Definitions::REQUEST_HIGH_THRESHOLD);
} commandBuffer[1] = 0x00; //dummy byte
case (Max31865Definitions::WRITE_LOW_THRESHOLD): { commandBuffer[2] = 0x00; //dummy byte
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::WRITE_LOW_THRESHOLD); DeviceHandlerBase::rawPacketLen = 3;
commandBuffer[1] = static_cast<uint8_t>(LOW_THRESHOLD >> 8); DeviceHandlerBase::rawPacket = commandBuffer.data();
commandBuffer[2] = static_cast<uint8_t>(LOW_THRESHOLD & 0xFF); return HasReturnvaluesIF::RETURN_OK;
DeviceHandlerBase::rawPacketLen = 3; }
DeviceHandlerBase::rawPacket = commandBuffer.data(); case(Max31865Definitions::WRITE_LOW_THRESHOLD): {
return HasReturnvaluesIF::RETURN_OK; commandBuffer[0] = static_cast<uint8_t>(
} Max31865Definitions::WRITE_LOW_THRESHOLD);
case (Max31865Definitions::REQUEST_LOW_THRESHOLD): { commandBuffer[1] = static_cast<uint8_t>(LOW_THRESHOLD >> 8);
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_LOW_THRESHOLD); commandBuffer[2] = static_cast<uint8_t>(LOW_THRESHOLD & 0xFF);
commandBuffer[1] = 0x00; //dummy byte DeviceHandlerBase::rawPacketLen = 3;
commandBuffer[2] = 0x00; //dummy byte DeviceHandlerBase::rawPacket = commandBuffer.data();
DeviceHandlerBase::rawPacketLen = 3; return HasReturnvaluesIF::RETURN_OK;
DeviceHandlerBase::rawPacket = commandBuffer.data(); }
return HasReturnvaluesIF::RETURN_OK; case(Max31865Definitions::REQUEST_LOW_THRESHOLD): {
} commandBuffer[0] = static_cast<uint8_t>(
case (Max31865Definitions::REQUEST_RTD): { Max31865Definitions::REQUEST_LOW_THRESHOLD);
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_RTD); commandBuffer[1] = 0x00; //dummy byte
// two dummy bytes commandBuffer[2] = 0x00; //dummy byte
commandBuffer[1] = 0x00; DeviceHandlerBase::rawPacketLen = 3;
commandBuffer[2] = 0x00; DeviceHandlerBase::rawPacket = commandBuffer.data();
DeviceHandlerBase::rawPacketLen = 3; return HasReturnvaluesIF::RETURN_OK;
DeviceHandlerBase::rawPacket = commandBuffer.data(); }
return HasReturnvaluesIF::RETURN_OK; case(Max31865Definitions::REQUEST_RTD): {
} commandBuffer[0] = static_cast<uint8_t>(
case (Max31865Definitions::REQUEST_FAULT_BYTE): { Max31865Definitions::REQUEST_RTD);
commandBuffer[0] = static_cast<uint8_t>(Max31865Definitions::REQUEST_FAULT_BYTE); // two dummy bytes
commandBuffer[1] = 0x00; commandBuffer[1] = 0x00;
DeviceHandlerBase::rawPacketLen = 2; commandBuffer[2] = 0x00;
DeviceHandlerBase::rawPacket = commandBuffer.data(); DeviceHandlerBase::rawPacketLen = 3;
return HasReturnvaluesIF::RETURN_OK; DeviceHandlerBase::rawPacket = commandBuffer.data();
} return HasReturnvaluesIF::RETURN_OK;
default: }
//Unknown DeviceCommand case(Max31865Definitions::REQUEST_FAULT_BYTE): {
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; commandBuffer[0] = static_cast<uint8_t>(
} Max31865Definitions::REQUEST_FAULT_BYTE);
commandBuffer[1] = 0x00;
DeviceHandlerBase::rawPacketLen = 2;
DeviceHandlerBase::rawPacket = commandBuffer.data();
return HasReturnvaluesIF::RETURN_OK;
}
default:
//Unknown DeviceCommand
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
} }
void Max31865PT1000Handler::fillCommandAndReplyMap() { void Max31865PT1000Handler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(Max31865Definitions::CONFIG_CMD, 3); insertInCommandAndReplyMap(Max31865Definitions::CONFIG_CMD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_CONFIG, 3); insertInCommandAndReplyMap(Max31865Definitions::REQUEST_CONFIG, 3);
insertInCommandAndReplyMap(Max31865Definitions::WRITE_LOW_THRESHOLD, 3); insertInCommandAndReplyMap(Max31865Definitions::WRITE_LOW_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_LOW_THRESHOLD, 3); insertInCommandAndReplyMap(Max31865Definitions::REQUEST_LOW_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::WRITE_HIGH_THRESHOLD, 3); insertInCommandAndReplyMap(Max31865Definitions::WRITE_HIGH_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_HIGH_THRESHOLD, 3); insertInCommandAndReplyMap(Max31865Definitions::REQUEST_HIGH_THRESHOLD, 3);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3, &sensorDataset); insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3,
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3); &sensorDataset);
insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3);
} }
ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, size_t remainingSize, ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start,
DeviceCommandId_t *foundId, size_t *foundLen) { size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
size_t rtdReplySize = 3; size_t rtdReplySize = 3;
size_t configReplySize = 2; size_t configReplySize = 2;
if (remainingSize == rtdReplySize and internalState == InternalState::RUNNING) { if(remainingSize == rtdReplySize and
*foundId = Max31865Definitions::REQUEST_RTD; internalState == InternalState::RUNNING) {
*foundLen = rtdReplySize; *foundId = Max31865Definitions::REQUEST_RTD;
return RETURN_OK; *foundLen = rtdReplySize;
} return RETURN_OK;
}
if (remainingSize == 3) { if(remainingSize == 3) {
switch (internalState) { switch(internalState) {
case (InternalState::CONFIG_HIGH_THRESHOLD): { case(InternalState::CONFIG_HIGH_THRESHOLD): {
*foundLen = 3; *foundLen = 3;
*foundId = Max31865Definitions::WRITE_HIGH_THRESHOLD; *foundId = Max31865Definitions::WRITE_HIGH_THRESHOLD;
commandExecuted = true; commandExecuted = true;
return RETURN_OK; return RETURN_OK;
} }
case (InternalState::REQUEST_HIGH_THRESHOLD): { case(InternalState::REQUEST_HIGH_THRESHOLD): {
*foundLen = 3; *foundLen = 3;
*foundId = Max31865Definitions::REQUEST_HIGH_THRESHOLD; *foundId = Max31865Definitions::REQUEST_HIGH_THRESHOLD;
return RETURN_OK; return RETURN_OK;
} }
case (InternalState::CONFIG_LOW_THRESHOLD): { case(InternalState::CONFIG_LOW_THRESHOLD): {
*foundLen = 3; *foundLen = 3;
*foundId = Max31865Definitions::WRITE_LOW_THRESHOLD; *foundId = Max31865Definitions::WRITE_LOW_THRESHOLD;
commandExecuted = true; commandExecuted = true;
return RETURN_OK; return RETURN_OK;
} }
case (InternalState::REQUEST_LOW_THRESHOLD): { case(InternalState::REQUEST_LOW_THRESHOLD): {
*foundLen = 3; *foundLen = 3;
*foundId = Max31865Definitions::REQUEST_LOW_THRESHOLD; *foundId = Max31865Definitions::REQUEST_LOW_THRESHOLD;
return RETURN_OK; return RETURN_OK;
} }
default: { default: {
sif::debug << "Max31865PT1000Handler::scanForReply: Unknown internal state" sif::debug << "Max31865PT1000Handler::scanForReply: Unknown internal state"
<< std::endl; << std::endl;
return RETURN_OK; return RETURN_OK;
} }
} }
} }
if (remainingSize == configReplySize) { if(remainingSize == configReplySize) {
if (internalState == InternalState::CONFIGURE) { if(internalState == InternalState::CONFIGURE) {
commandExecuted = true; commandExecuted = true;
*foundLen = configReplySize; *foundLen = configReplySize;
*foundId = Max31865Definitions::CONFIG_CMD; *foundId = Max31865Definitions::CONFIG_CMD;
internalState = InternalState::REQUEST_CONFIG; }
} else if (internalState == InternalState::REQUEST_FAULT_BYTE) { else if(internalState == InternalState::REQUEST_FAULT_BYTE) {
*foundId = Max31865Definitions::REQUEST_FAULT_BYTE; *foundId = Max31865Definitions::REQUEST_FAULT_BYTE;
*foundLen = 2; *foundLen = 2;
// internalState = InternalState::RUNNING; internalState = InternalState::RUNNING;
} else { }
*foundId = Max31865Definitions::REQUEST_CONFIG; else {
*foundLen = configReplySize; *foundId = Max31865Definitions::REQUEST_CONFIG;
internalState = InternalState::CONFIGURE; *foundLen = configReplySize;
} }
} }
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(DeviceCommandId_t id, ReturnValue_t Max31865PT1000Handler::interpretDeviceReply(
const uint8_t *packet) { DeviceCommandId_t id, const uint8_t *packet) {
switch (id) { switch(id) {
case (Max31865Definitions::REQUEST_CONFIG): { case(Max31865Definitions::REQUEST_CONFIG): {
if (packet[1] != DEFAULT_CONFIG) { if(packet[1] != DEFAULT_CONFIG) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
// it propably would be better if we at least try one restart.. // it propably would be better if we at least try one restart..
sif::error << "Max31865PT1000Handler: Object ID: " << std::hex << this->getObjectId() sif::error << "Max31865PT1000Handler: Object ID: " << std::hex << this->getObjectId()
<< ": Invalid configuration reply!" << std::endl; << ": Invalid configuration reply!" << std::endl;
#else #else
sif::printError("Max31865PT1000Handler: Invalid configuration reply!\n"); sif::printError("Max31865PT1000Handler: Invalid configuration reply!\n");
#endif #endif
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
else { // set to true for invalid configs too for now.
sif::debug << "Max31865PT1000Handler: Object ID: " << std::hex << this->getObjectId() if(internalState == InternalState::REQUEST_CONFIG) {
<< ": Config readback successful!" << std::endl; commandExecuted = true;
} }
// set to true for invalid configs too for now. else if(internalState == InternalState::RUNNING) {
if (internalState == InternalState::REQUEST_CONFIG) { // we should propably generate a telemetry with the config byte
commandExecuted = true; // as payload here.
} else if (internalState == InternalState::RUNNING) { }
// we should propably generate a telemetry with the config byte break;
// as payload here. }
} case(Max31865Definitions::REQUEST_LOW_THRESHOLD): {
break; uint16_t readLowThreshold = packet[1] << 8 | packet[2];
} if(readLowThreshold != LOW_THRESHOLD) {
case (Max31865Definitions::REQUEST_LOW_THRESHOLD): {
uint16_t readLowThreshold = packet[1] << 8 | packet[2];
if (readLowThreshold != LOW_THRESHOLD) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Missmatch between " sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " <<
<< "written and readback value of low threshold register" << std::endl; std::hex << this->getObjectId() << ": Missmatch between " <<
"written and readback value of low threshold register" << std::endl;
#else #else
sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Missmatch between " sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Missmatch between "
"written and readback value of low threshold register\n"); "written and readback value of low threshold register\n");
#endif #endif
#endif #endif
} }
commandExecuted = true; commandExecuted = true;
break; break;
} }
case (Max31865Definitions::REQUEST_HIGH_THRESHOLD): { case(Max31865Definitions::REQUEST_HIGH_THRESHOLD): {
uint16_t readHighThreshold = packet[1] << 8 | packet[2]; uint16_t readHighThreshold = packet[1] << 8 | packet[2];
if (readHighThreshold != HIGH_THRESHOLD) { if(readHighThreshold != HIGH_THRESHOLD) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Missmatch between " sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: "
<< "written and readback value of high threshold register" << std::endl; << std::hex << this->getObjectId() << ": Missmatch between " <<
"written and readback value of high threshold register" << std::endl;
#else #else
sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Missmatch between " sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Missmatch between "
"written and readback value of high threshold register\n"); "written and readback value of high threshold register\n");
#endif #endif
#endif #endif
} }
commandExecuted = true; commandExecuted = true;
break; break;
} }
case (Max31865Definitions::REQUEST_RTD): { case(Max31865Definitions::REQUEST_RTD): {
// first bit of LSB reply byte is the fault bit // first bit of LSB reply byte is the fault bit
uint8_t faultBit = packet[2] & 0b0000'0001; uint8_t faultBit = packet[2] & 0b0000'0001;
if (faultBit == 1) { if(faultBit == 1) {
// Maybe we should attempt to restart it? // Maybe we should attempt to restart it?
internalState = InternalState::REQUEST_FAULT_BYTE; internalState = InternalState::REQUEST_FAULT_BYTE;
} }
// RTD value consists of last seven bits of the LSB reply byte and // RTD value consists of last seven bits of the LSB reply byte and
// the MSB reply byte // the MSB reply byte
uint16_t adcCode = ((packet[1] << 8) | packet[2]) >> 1; uint16_t adcCode = ((packet[1] << 8) | packet[2]) >> 1;
// do something with rtd value, will propably be stored in // do something with rtd value, will propably be stored in
// dataset. // dataset.
float rtdValue = adcCode * RTD_RREF_PT1000 / INT16_MAX; float rtdValue = adcCode * RTD_RREF_PT1000 / INT16_MAX;
// calculate approximation // calculate approximation
float approxTemp = adcCode / 32.0 - 256.0; float approxTemp = adcCode / 32.0 - 256.0;
#if OBSW_DEBUG_RTD == 1 #if OBSW_DEBUG_RTD == 1
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
if (debugDivider->checkAndIncrement()) { if(debugDivider->checkAndIncrement()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Max31865: Object ID: " << std::hex << this->getObjectId() sif::info << "Max31865: Object ID: " << std::hex << this->getObjectId()
<< "Measured resistance is " << rtdValue << " Ohms." << std::endl; << ": Measured resistance is " << rtdValue << " Ohms." << std::endl;
sif::info << "Approximated temperature is " << approxTemp << " C" << std::endl; sif::info << "Approximated temperature is " << approxTemp << " C" << std::endl;
#else #else
sif::printInfo("Max31685: Measured resistance is %f Ohms\n", rtdValue); sif::printInfo("Max31685: Measured resistance is %f Ohms\n", rtdValue);
sif::printInfo("Approximated temperature is %f C\n", approxTemp); sif::printInfo("Approximated temperature is %f C\n", approxTemp);
#endif #endif
} }
#endif #endif
#endif #endif
PoolReadGuard pg(&sensorDataset); PoolReadGuard pg(&sensorDataset);
if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { if(pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
// Configuration error // Configuration error
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Error reading dataset!" sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: "
<< std::endl; << std::hex << this->getObjectId() << ": Error reading dataset!"
<< std::endl;
#else #else
sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: " sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: "
"Error reading dataset!\n"); "Error reading dataset!\n");
#endif #endif
return pg.getReadResult(); return pg.getReadResult();
} }
if (not sensorDataset.isValid()) { if(not sensorDataset.isValid()) {
sensorDataset.setValidity(true, false); sensorDataset.setValidity(true, false);
sensorDataset.rtdValue.setValid(true); sensorDataset.rtdValue.setValid(true);
sensorDataset.temperatureCelcius.setValid(true); sensorDataset.temperatureCelcius.setValid(true);
} }
sensorDataset.rtdValue = rtdValue; sensorDataset.rtdValue = rtdValue;
sensorDataset.temperatureCelcius = approxTemp; sensorDataset.temperatureCelcius = approxTemp;
break; break;
} }
case (Max31865Definitions::REQUEST_FAULT_BYTE): { case(Max31865Definitions::REQUEST_FAULT_BYTE): {
faultByte = packet[1]; faultByte = packet[1];
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Fault byte" sif::warning << "Max31865PT1000Handler::interpretDeviceReply: Object ID: "
" is: 0b" << std::bitset < 8 > (faultByte) << std::endl; << std::hex << this->getObjectId() << ": Fault byte"
" is: 0b" << std::bitset<8>(faultByte) << std::endl;
#else #else
sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Fault byte" sif::printWarning("Max31865PT1000Handler::interpretDeviceReply: Fault byte"
" is: 0b" BYTE_TO_BINARY_PATTERN "\n", BYTE_TO_BINARY(faultByte)); " is: 0b" BYTE_TO_BINARY_PATTERN "\n", BYTE_TO_BINARY(faultByte));
#endif #endif
#endif #endif
ReturnValue_t result = sensorDataset.read(); ReturnValue_t result = sensorDataset.read();
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: " sif::debug << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
"Error reading dataset!" << std::endl; << this->getObjectId() << ":"
"Error reading dataset!" << std::endl;
#else #else
sif::printDebug("Max31865PT1000Handler::interpretDeviceReply: " sif::printDebug("Max31865PT1000Handler::interpretDeviceReply: "
"Error reading dataset!\n"); "Error reading dataset!\n");
#endif #endif
return result; return result;
} }
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(); result = sensorDataset.commit();
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: " sif::debug << "Max31865PT1000Handler::interpretDeviceReply: Object ID: " << std::hex
"Error commiting dataset!" << std::endl; << this->getObjectId() << ": Error commiting dataset!" << std::endl;
#else #else
sif::printDebug("Max31865PT1000Handler::interpretDeviceReply: " sif::printDebug("Max31865PT1000Handler::interpretDeviceReply: "
"Error commiting dataset!\n"); "Error commiting dataset!\n");
#endif #endif
return result; return result;
} }
break; break;
} }
default: default:
break; break;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void Max31865PT1000Handler::debugInterface(uint8_t positionTracker, object_id_t objectId, void Max31865PT1000Handler::debugInterface(uint8_t positionTracker,
uint32_t parameter) { object_id_t objectId, uint32_t parameter) {
} }
uint32_t Max31865PT1000Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { uint32_t Max31865PT1000Handler::getTransitionDelayMs(
return 25000; Mode_t modeFrom, Mode_t modeTo) {
return 25000;
} }
ReturnValue_t Max31865PT1000Handler::getSwitches(const uint8_t **switches, ReturnValue_t Max31865PT1000Handler::getSwitches(
uint8_t *numberOfSwitches) { const uint8_t **switches, uint8_t *numberOfSwitches) {
return DeviceHandlerBase::NO_SWITCH; return DeviceHandlerBase::NO_SWITCH;
} }
void Max31865PT1000Handler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { void Max31865PT1000Handler::doTransition(Mode_t modeFrom,
DeviceHandlerBase::doTransition(modeFrom, subModeFrom); Submode_t subModeFrom) {
DeviceHandlerBase::doTransition(modeFrom, subModeFrom);
} }
ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) { LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(Max31865Definitions::PoolIds::RTD_VALUE, new PoolEntry<float>( { 0 })); localDataPoolMap.emplace(Max31865Definitions::PoolIds::RTD_VALUE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(Max31865Definitions::PoolIds::TEMPERATURE_C, localDataPoolMap.emplace(Max31865Definitions::PoolIds::TEMPERATURE_C,
new PoolEntry<float>( { 0 }, 1, true)); new PoolEntry<float>({0}, 1, true));
localDataPoolMap.emplace(Max31865Definitions::PoolIds::FAULT_BYTE, localDataPoolMap.emplace(Max31865Definitions::PoolIds::FAULT_BYTE,
new PoolEntry<uint8_t>( { 0 })); new PoolEntry<uint8_t>({0}));
// poolManager.subscribeForPeriodicPacket(sensorDatasetSid, // poolManager.subscribeForPeriodicPacket(sensorDatasetSid,
// false, 4.0, false); // false, 4.0, false);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void Max31865PT1000Handler::modeChanged() { void Max31865PT1000Handler::modeChanged() {
// internalState = InternalState::NONE; internalState = InternalState::NONE;
} }

View File

@ -37,7 +37,7 @@ public:
// 1. 1 for V_BIAS enabled, 0 for disabled // 1. 1 for V_BIAS enabled, 0 for disabled
// 2. 1 for Auto-conversion, 0 for off // 2. 1 for Auto-conversion, 0 for off
// 3. 1 for 1-shot enabled, 0 for disabled (self-clearing bit) // 3. 1 for 1-shot enabled, 0 for disabled (self-clearing bit)
// 4. 1 for 3-wire disabled, 0 for disabled // 4. 1 for 3-wire enabled, 0 for disabled (two and four wired RTD)
// 5./6. Fault detection: 00 for no action, 01 for automatic delay, 1 // 5./6. Fault detection: 00 for no action, 01 for automatic delay, 1
// 0 for run fault detection with manual delay, // 0 for run fault detection with manual delay,
// 11 for finish fault detection with manual delay // 11 for finish fault detection with manual delay
@ -99,7 +99,7 @@ private:
REQUEST_FAULT_BYTE REQUEST_FAULT_BYTE
}; };
InternalState internalState = InternalState::CONFIGURE; InternalState internalState = InternalState::NONE;
bool commandExecuted = false; bool commandExecuted = false;
dur_millis_t startTime = 0; dur_millis_t startTime = 0;