From bf9f40aad3376e85ae519c6ecf92c097cd69f529 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Feb 2022 20:20:14 +0100 Subject: [PATCH 1/5] update rad sensor --- mission/devices/RadiationSensorHandler.cpp | 17 +++++++++++------ mission/devices/RadiationSensorHandler.h | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 83720b53..c5148c84 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -14,11 +14,13 @@ RadiationSensorHandler::~RadiationSensorHandler() {} void RadiationSensorHandler::doStartUp() { if (internalState == InternalState::CONFIGURED) { -#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 - setMode(MODE_NORMAL); -#else - setMode(_MODE_TO_ON); -#endif + if (goToNormalMode) { + setMode(MODE_NORMAL); + } + + else { + setMode(_MODE_TO_ON); + } } } @@ -124,7 +126,8 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, case RAD_SENSOR::READ_CONVERSIONS: { uint8_t offset = 0; PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet + offset) << 8 | *(packet + offset + 1)) * 0.125; + int16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1]; + dataset.temperatureCelcius = tempRaw * 0.125; offset += 2; dataset.ain0 = (*(packet + offset) << 8 | *(packet + offset + 1)); offset += 2; @@ -175,3 +178,5 @@ ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPoo localDataPoolMap.emplace(RAD_SENSOR::AIN7, new PoolEntry({0})); return HasReturnvaluesIF::RETURN_OK; } + +void RadiationSensorHandler::setToGoToNormalModeImmediately() { this->goToNormalMode = true; } diff --git a/mission/devices/RadiationSensorHandler.h b/mission/devices/RadiationSensorHandler.h index fe4e4264..0fed2c83 100644 --- a/mission/devices/RadiationSensorHandler.h +++ b/mission/devices/RadiationSensorHandler.h @@ -16,6 +16,7 @@ class RadiationSensorHandler : public DeviceHandlerBase { public: RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie); virtual ~RadiationSensorHandler(); + void setToGoToNormalModeImmediately(); protected: void doStartUp() override; @@ -42,6 +43,7 @@ class RadiationSensorHandler : public DeviceHandlerBase { static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; + bool goToNormalMode = false; uint8_t cmdBuffer[MAX_CMD_LEN]; InternalState internalState = InternalState::SETUP; CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; -- 2.43.0 From 0b215bf7e0947bfbcd522ef0781b23c5ddad54bd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Feb 2022 11:47:32 +0100 Subject: [PATCH 2/5] use radfet enable pin now --- bsp_q7s/boardconfig/busConf.h | 1 + bsp_q7s/core/ObjectFactory.cpp | 15 +++++++++--- bsp_q7s/simple/simple.cpp | 1 - linux/fsfwconfig/devices/gpioIds.h | 1 + .../pollingSequenceFactory.cpp | 5 ++-- mission/devices/RadiationSensorHandler.cpp | 24 ++++++++----------- mission/devices/RadiationSensorHandler.h | 8 ++++--- mission/devices/SusHandler.cpp | 3 ++- 8 files changed, 33 insertions(+), 25 deletions(-) diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index 2083ac6b..ef0f7eff 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -67,6 +67,7 @@ static constexpr char EN_RW_3[] = "enable_rw_3"; static constexpr char EN_RW_4[] = "enable_rw_4"; static constexpr char GNSS_MUX_SELECT[] = "gnss_mux_select"; static constexpr char RAD_SENSOR_CHIP_SELECT[] = "rad_sensor_chip_select"; +static constexpr char ENABLE_RADFET[] = "enable_radfet"; static constexpr char PAPB_BUSY_SIGNAL_VC0[] = "papb_busy_signal_vc0"; static constexpr char PAPB_EMPTY_SIGNAL_VC0[] = "papb_empty_signal_vc0"; static constexpr char PAPB_BUSY_SIGNAL_VC1[] = "papb_busy_signal_vc1"; diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index cbd0021b..86448d6d 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -44,8 +44,6 @@ #include "linux/csp/CspComIF.h" #include "linux/csp/CspCookie.h" #include "linux/devices/SolarArrayDeploymentHandler.h" -#include "mission/devices/SusHandler.h" -#include "mission/devices/devicedefinitions/SusDefinitions.h" #include "mission/core/GenericFactory.h" #include "mission/devices/ACUHandler.h" #include "mission/devices/BpxBatteryHandler.h" @@ -61,6 +59,7 @@ #include "mission/devices/PlocMPSoCHandler.h" #include "mission/devices/RadiationSensorHandler.h" #include "mission/devices/RwHandler.h" +#include "mission/devices/SusHandler.h" #include "mission/devices/SyrlinksHkHandler.h" #include "mission/devices/Tmp1075Handler.h" #include "mission/devices/devicedefinitions/GomspaceDefinitions.h" @@ -68,6 +67,7 @@ #include "mission/devices/devicedefinitions/PlocMPSoCDefinitions.h" #include "mission/devices/devicedefinitions/RadSensorDefinitions.h" #include "mission/devices/devicedefinitions/RwDefinitions.h" +#include "mission/devices/devicedefinitions/SusDefinitions.h" #include "mission/devices/devicedefinitions/SyrlinksDefinitions.h" #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" @@ -295,12 +295,21 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { GpiodRegularByLineName* gpio = new GpiodRegularByLineName( q7s::gpioNames::RAD_SENSOR_CHIP_SELECT, consumer.str(), gpio::DIR_OUT, gpio::HIGH); gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, gpio); + gpio = new GpiodRegularByLineName(q7s::gpioNames::ENABLE_RADFET, consumer.str(), gpio::DIR_OUT, + gpio::LOW); + gpioCookieRadSensor->addGpio(gpioIds::ENABLE_RADFET, gpio); gpioComIF->addGpios(gpioCookieRadSensor); SpiCookie* spiCookieRadSensor = new SpiCookie( addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string(q7s::SPI_DEFAULT_DEV), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); + auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, + spiCookieRadSensor, gpioComIF); + static_cast(radSensor); +#if OBSW_TEST_RAD_SENSOR == 1 + radSensor->setStartUpImmediately(); + radSensor->setToGoToNormalModeImmediately(); +#endif } void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF) { diff --git a/bsp_q7s/simple/simple.cpp b/bsp_q7s/simple/simple.cpp index a86fd459..1362ef23 100644 --- a/bsp_q7s/simple/simple.cpp +++ b/bsp_q7s/simple/simple.cpp @@ -1,7 +1,6 @@ #include "simple.h" #include "iostream" - #include "q7sConfig.h" #if Q7S_SIMPLE_ADD_FILE_SYSTEM_TEST == 1 diff --git a/linux/fsfwconfig/devices/gpioIds.h b/linux/fsfwconfig/devices/gpioIds.h index 46717569..d4adadf6 100644 --- a/linux/fsfwconfig/devices/gpioIds.h +++ b/linux/fsfwconfig/devices/gpioIds.h @@ -76,6 +76,7 @@ enum gpioId_t { SPI_MUX_BIT_6, CS_RAD_SENSOR, + ENABLE_RADFET, PAPB_BUSY_N, PAPB_EMPTY, diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 38717c37..e301f301 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -1,13 +1,12 @@ #include "pollingSequenceFactory.h" -#include "OBSWConfig.h" -#include "objects/systemObjectList.h" #include #include #include #include - +#include "OBSWConfig.h" +#include "objects/systemObjectList.h" ReturnValue_t pst::pstGpio(FixedTimeslotTaskIF *thisSequence) { // Length of a communication cycle diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index c5148c84..75649967 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -1,11 +1,12 @@ #include +#include #include #include RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, - CookieIF *comCookie) - : DeviceHandlerBase(objectId, comIF, comCookie), dataset(this) { - if (comCookie == NULL) { + CookieIF *comCookie, GpioIF *gpioIF) + : DeviceHandlerBase(objectId, comIF, comCookie), dataset(this), gpioIF(gpioIF) { + if (comCookie == nullptr) { sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; } } @@ -68,6 +69,7 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t return RETURN_OK; } case (RAD_SENSOR::START_CONVERSION): { + gpioIF->pullHigh(gpioIds::ENABLE_RADFET); /* First the fifo will be reset here */ cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; @@ -82,14 +84,6 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t rawPacketLen = RAD_SENSOR::READ_SIZE; return RETURN_OK; } - // case(RAD_SENSOR::AIN0_AND_TMP_CONVERSION): { - // /* First the fifo will be reset here */ - // cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; - // cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; - // rawPacket = cmdBuffer; - // rawPacketLen = 2; - // return RETURN_OK; - // } default: return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } @@ -111,6 +105,10 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t case RAD_SENSOR::START_CONVERSION: case RAD_SENSOR::WRITE_SETUP: return IGNORE_REPLY_DATA; + case RAD_SENSOR::READ_CONVERSIONS: { + gpioIF->pullLow(gpioIds::ENABLE_RADFET); + break; + } default: break; } @@ -141,7 +139,7 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, offset += 2; dataset.ain7 = (*(packet + offset) << 8 | *(packet + offset + 1)); -#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_RAD_SENSOR +#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_RAD_SENSOR == 1 sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C" << std::endl; sif::info << "Radiation sensor ADC value channel 0: " << dataset.ain0 << std::endl; @@ -161,8 +159,6 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, return HasReturnvaluesIF::RETURN_OK; } -void RadiationSensorHandler::setNormalDatapoolEntriesInvalid() {} - uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 5000; } diff --git a/mission/devices/RadiationSensorHandler.h b/mission/devices/RadiationSensorHandler.h index 0fed2c83..5aeb4add 100644 --- a/mission/devices/RadiationSensorHandler.h +++ b/mission/devices/RadiationSensorHandler.h @@ -4,6 +4,8 @@ #include #include +class GpioIF; + /** * @brief This is the device handler class for radiation sensor on the OBC IF Board. The * sensor is based on the MAX1227 ADC converter. @@ -14,7 +16,8 @@ */ class RadiationSensorHandler : public DeviceHandlerBase { public: - RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie); + RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, + GpioIF *gpioIF); virtual ~RadiationSensorHandler(); void setToGoToNormalModeImmediately(); @@ -29,7 +32,6 @@ class RadiationSensorHandler : public DeviceHandlerBase { ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) override; ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; - void setNormalDatapoolEntriesInvalid() override; uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) override; @@ -40,8 +42,8 @@ class RadiationSensorHandler : public DeviceHandlerBase { enum class InternalState { SETUP, CONFIGURED }; RAD_SENSOR::RadSensorDataset dataset; - static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; + GpioIF *gpioIF = nullptr; bool goToNormalMode = false; uint8_t cmdBuffer[MAX_CMD_LEN]; diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 9c55409e..602e0a20 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -214,7 +214,8 @@ void SusHandler::setToGoToNormalMode(bool enable) { this->goToNormalModeImmediat void SusHandler::printDataset() { if (periodicPrintout) { if (divider.checkAndIncrement()) { - sif::info << "SUS ADC " << static_cast(susIdx) << " hex [" << std::setfill('0') << std::hex; + sif::info << "SUS ADC " << static_cast(susIdx) << " hex [" << std::setfill('0') + << std::hex; for (uint8_t idx = 0; idx < 6; idx++) { sif::info << std::setw(3) << dataset.channels[idx]; if (idx < 6 - 1) { -- 2.43.0 From e56532367fa689fee24265506158a6bc2c3960f8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Feb 2022 11:55:06 +0100 Subject: [PATCH 3/5] check returnvalue --- mission/devices/RadiationSensorHandler.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 75649967..57714d03 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -69,7 +69,14 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t return RETURN_OK; } case (RAD_SENSOR::START_CONVERSION): { - gpioIF->pullHigh(gpioIds::ENABLE_RADFET); + ReturnValue_t result = gpioIF->pullHigh(gpioIds::ENABLE_RADFET); + if (result != HasReturnvaluesIF::RETURN_OK) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::warning << "RadiationSensorHandler::buildCommandFromCommand; Pulling RADFET Enale pin " + "high failed" + << std::endl; +#endif + } /* First the fifo will be reset here */ cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; @@ -106,7 +113,14 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t case RAD_SENSOR::WRITE_SETUP: return IGNORE_REPLY_DATA; case RAD_SENSOR::READ_CONVERSIONS: { - gpioIF->pullLow(gpioIds::ENABLE_RADFET); + ReturnValue_t result = gpioIF->pullLow(gpioIds::ENABLE_RADFET); + if (result != HasReturnvaluesIF::RETURN_OK) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::warning << "RadiationSensorHandler::buildCommandFromCommand; Pulling RADFET Enale pin " + "low failed" + << std::endl; +#endif + } break; } default: -- 2.43.0 From 768bb14842a1f6f5fafc027b5a055e6af3a52620 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Feb 2022 11:57:35 +0100 Subject: [PATCH 4/5] minor tweaks --- bsp_q7s/core/ObjectFactory.cpp | 4 ++-- linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 86448d6d..d5106bbe 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -44,6 +44,8 @@ #include "linux/csp/CspComIF.h" #include "linux/csp/CspCookie.h" #include "linux/devices/SolarArrayDeploymentHandler.h" +#include "mission/devices/devicedefinitions/SusDefinitions.h" +#include "mission/devices/SusHandler.h" #include "mission/core/GenericFactory.h" #include "mission/devices/ACUHandler.h" #include "mission/devices/BpxBatteryHandler.h" @@ -59,7 +61,6 @@ #include "mission/devices/PlocMPSoCHandler.h" #include "mission/devices/RadiationSensorHandler.h" #include "mission/devices/RwHandler.h" -#include "mission/devices/SusHandler.h" #include "mission/devices/SyrlinksHkHandler.h" #include "mission/devices/Tmp1075Handler.h" #include "mission/devices/devicedefinitions/GomspaceDefinitions.h" @@ -67,7 +68,6 @@ #include "mission/devices/devicedefinitions/PlocMPSoCDefinitions.h" #include "mission/devices/devicedefinitions/RadSensorDefinitions.h" #include "mission/devices/devicedefinitions/RwDefinitions.h" -#include "mission/devices/devicedefinitions/SusDefinitions.h" #include "mission/devices/devicedefinitions/SyrlinksDefinitions.h" #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index e301f301..3ade9dfc 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -1,13 +1,12 @@ #include "pollingSequenceFactory.h" +#include "OBSWConfig.h" +#include "objects/systemObjectList.h" #include #include #include #include -#include "OBSWConfig.h" -#include "objects/systemObjectList.h" - ReturnValue_t pst::pstGpio(FixedTimeslotTaskIF *thisSequence) { // Length of a communication cycle uint32_t length = thisSequence->getPeriodMs(); -- 2.43.0 From 3edf7572b6447866b12cb506606df7ed494bfe24 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Feb 2022 11:58:11 +0100 Subject: [PATCH 5/5] order --- bsp_q7s/core/ObjectFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index d5106bbe..2a286169 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -44,8 +44,8 @@ #include "linux/csp/CspComIF.h" #include "linux/csp/CspCookie.h" #include "linux/devices/SolarArrayDeploymentHandler.h" -#include "mission/devices/devicedefinitions/SusDefinitions.h" #include "mission/devices/SusHandler.h" +#include "mission/devices/devicedefinitions/SusDefinitions.h" #include "mission/core/GenericFactory.h" #include "mission/devices/ACUHandler.h" #include "mission/devices/BpxBatteryHandler.h" -- 2.43.0