diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 66fb4a3a..750ebe9c 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -299,8 +299,8 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) { 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); - auto radSensor = - 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(); diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index b6444a74..d1c1c401 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -5,9 +5,6 @@ #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(); diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 83720b53..57714d03 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; } } @@ -14,11 +15,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); + } } } @@ -66,6 +69,14 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t return RETURN_OK; } case (RAD_SENSOR::START_CONVERSION): { + 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; @@ -80,14 +91,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; } @@ -109,6 +112,17 @@ 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: { + 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: break; } @@ -124,7 +138,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; @@ -138,7 +153,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; @@ -158,8 +173,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; } @@ -175,3 +188,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..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,8 +16,10 @@ */ 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(); protected: void doStartUp() override; @@ -28,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; @@ -39,9 +42,10 @@ 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]; InternalState internalState = InternalState::SETUP; CommunicationStep communicationStep = CommunicationStep::START_CONVERSION;