From a4a5800cbaa141995392abdb59539c17e4529888 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 18 Jul 2023 11:01:53 +0200 Subject: [PATCH 1/4] that should do the job --- mission/payload/RadiationSensorHandler.cpp | 48 ++++++++++++++-------- mission/payload/RadiationSensorHandler.h | 3 ++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/mission/payload/RadiationSensorHandler.cpp b/mission/payload/RadiationSensorHandler.cpp index 2a87e730..7471d9cf 100644 --- a/mission/payload/RadiationSensorHandler.cpp +++ b/mission/payload/RadiationSensorHandler.cpp @@ -51,6 +51,9 @@ void RadiationSensorHandler::doShutDown() { } ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { + if (measurementCd.isBusy()) { + return NOTHING_TO_SEND; + } switch (communicationStep) { case CommunicationStep::START_CONVERSION: { *id = radSens::START_CONVERSION; @@ -177,22 +180,24 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, switch (id) { case radSens::READ_CONVERSIONS: { uint8_t offset = 0; - PoolReadGuard readSet(&dataset); - uint16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1]; - dataset.temperatureCelcius = max1227::getTemperature(tempRaw); - offset += 2; - dataset.ain0 = (*(packet + offset) << 8) | *(packet + offset + 1); - offset += 2; - dataset.ain1 = (*(packet + offset) << 8) | *(packet + offset + 1); - offset += 6; - dataset.ain4 = (*(packet + offset) << 8) | *(packet + offset + 1); - offset += 2; - dataset.ain5 = (*(packet + offset) << 8) | *(packet + offset + 1); - offset += 2; - dataset.ain6 = (*(packet + offset) << 8) | *(packet + offset + 1); - offset += 2; - dataset.ain7 = (*(packet + offset) << 8) | *(packet + offset + 1); - dataset.setValidity(true, true); + { + PoolReadGuard readSet(&dataset); + uint16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1]; + dataset.temperatureCelcius = max1227::getTemperature(tempRaw); + offset += 2; + dataset.ain0 = (*(packet + offset) << 8) | *(packet + offset + 1); + offset += 2; + dataset.ain1 = (*(packet + offset) << 8) | *(packet + offset + 1); + offset += 6; + dataset.ain4 = (*(packet + offset) << 8) | *(packet + offset + 1); + offset += 2; + dataset.ain5 = (*(packet + offset) << 8) | *(packet + offset + 1); + offset += 2; + dataset.ain6 = (*(packet + offset) << 8) | *(packet + offset + 1); + offset += 2; + dataset.ain7 = (*(packet + offset) << 8) | *(packet + offset + 1); + dataset.setValidity(true, true); + } if (printPeriodicData) { sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C" << std::dec << std::endl; @@ -203,6 +208,12 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, sif::info << "Radiation sensor ADC value channel 6: " << dataset.ain6 << std::endl; sif::info << "Radiation sensor ADC value channel 7: " << dataset.ain7 << std::endl; } + ReturnValue_t result = + getHkManagerHandle()->generateHousekeepingPacket(dataset.getSid(), &dataset, true); + if (result != returnvalue::OK) { + // TODO: Maybe add event? + sif::error << "Generating HK set for radiation sensor failed" << std::endl; + } break; } default: { @@ -226,8 +237,11 @@ ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPoo localDataPoolMap.emplace(radSens::AIN5, new PoolEntry({0})); localDataPoolMap.emplace(radSens::AIN6, new PoolEntry({0})); localDataPoolMap.emplace(radSens::AIN7, new PoolEntry({0})); + // It should normally not be necessary to enable this set, as a sample TM will be generated + // after a measurement. If this is still enabled, sample with double the measurement frequency + // to ensure we get all measurements. poolManager.subscribeForRegularPeriodicPacket( - subdp::RegularHkPeriodicParams(dataset.getSid(), false, 20.0)); + subdp::RegularHkPeriodicParams(dataset.getSid(), false, DEFAULT_MEASUREMENT_CD_MS / 2)); return returnvalue::OK; } diff --git a/mission/payload/RadiationSensorHandler.h b/mission/payload/RadiationSensorHandler.h index 2e8ca7f2..429cda79 100644 --- a/mission/payload/RadiationSensorHandler.h +++ b/mission/payload/RadiationSensorHandler.h @@ -38,12 +38,15 @@ class RadiationSensorHandler : public DeviceHandlerBase { LocalDataPoolManager &poolManager) override; private: + static constexpr uint32_t DEFAULT_MEASUREMENT_CD_MS = 30 * 60 * 1000; + enum class CommunicationStep { START_CONVERSION, READ_CONVERSIONS }; enum class InternalState { OFF, POWER_SWITCHING, SETUP, CONFIGURED }; bool printPeriodicData = false; radSens::RadSensorDataset dataset; + Countdown measurementCd = Countdown(DEFAULT_MEASUREMENT_CD_MS); static const uint8_t MAX_CMD_LEN = radSens::READ_SIZE; GpioIF *gpioIF = nullptr; Stack5VHandler &stackHandler; From b2d2c38c5866581c71412960340d21d447d92bd1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 18 Jul 2023 18:24:36 +0200 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e65685..aa969d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ will consitute of a breaking change warranting a new major release: - STR missed reply handling is now moved to DHB rather than the COM interface. The COM IF will still trigger an event if a reply is taking too long, and FDIR should still work via reply timeouts. +- Rad sensor is now only polled every 30 minutes instead of every device cycle to reduce wear of + the RADFET electronics. ## Added From 910addc27a4c6ea2399c980c82010e6aadfbf8e5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 18 Jul 2023 18:26:57 +0200 Subject: [PATCH 3/4] reset the timer --- mission/payload/RadiationSensorHandler.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mission/payload/RadiationSensorHandler.cpp b/mission/payload/RadiationSensorHandler.cpp index 7471d9cf..5151fb2b 100644 --- a/mission/payload/RadiationSensorHandler.cpp +++ b/mission/payload/RadiationSensorHandler.cpp @@ -15,6 +15,8 @@ RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t if (comCookie == nullptr) { sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; } + // Time out immediately so we get an immediate measurement at device startup. + measurementCd.timeOut(); } RadiationSensorHandler::~RadiationSensorHandler() {} @@ -160,6 +162,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t << std::endl; #endif } + measurementCd.resetTimer(); break; } case radSens::ENABLE_DEBUG_OUTPUT: From a52d116857f29068310b8ec63a3f1c785f290189 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 19 Jul 2023 15:36:06 +0200 Subject: [PATCH 4/4] move CD reset --- mission/payload/RadiationSensorHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mission/payload/RadiationSensorHandler.cpp b/mission/payload/RadiationSensorHandler.cpp index 5151fb2b..e20d7308 100644 --- a/mission/payload/RadiationSensorHandler.cpp +++ b/mission/payload/RadiationSensorHandler.cpp @@ -162,7 +162,6 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t << std::endl; #endif } - measurementCd.resetTimer(); break; } case radSens::ENABLE_DEBUG_OUTPUT: @@ -183,6 +182,7 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, switch (id) { case radSens::READ_CONVERSIONS: { uint8_t offset = 0; + measurementCd.resetTimer(); { PoolReadGuard readSet(&dataset); uint16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1];