From c683097635f5162b9de540734d1cc0ab939a3ca2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Feb 2022 16:57:16 +0100 Subject: [PATCH] continued pl pcdu handler --- bsp_q7s/core/ObjectFactory.cpp | 4 +- linux/boardtest/SpiTestClass.cpp | 52 +++---- linux/devices/GPSHyperionLinuxController.h | 2 +- linux/devices/SusHandler.cpp | 2 +- linux/fsfwconfig/OBSWConfig.h.in | 2 + .../pollingSequenceFactory.cpp | 4 +- mission/devices/PayloadPcduHandler.cpp | 140 +++++++++++------- mission/devices/PayloadPcduHandler.h | 4 + .../payloadPcduDefinitions.h | 18 +-- mission/devices/max1227.h | 4 +- 10 files changed, 127 insertions(+), 105 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index d4be4c33..8abf2b2b 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -44,11 +44,9 @@ #include "linux/csp/CspComIF.h" #include "linux/csp/CspCookie.h" #include "linux/devices/GPSHyperionLinuxController.h" -#include "linux/devices/PayloadPcduHandler.h" #include "linux/devices/SolarArrayDeploymentHandler.h" #include "linux/devices/SusHandler.h" #include "linux/devices/devicedefinitions/SusDefinitions.h" -#include "linux/devices/devicedefinitions/payloadPcduDefinitions.h" #include "mission/core/GenericFactory.h" #include "mission/devices/ACUHandler.h" #include "mission/devices/BpxBatteryHandler.h" @@ -60,6 +58,7 @@ #include "mission/devices/PCDUHandler.h" #include "mission/devices/PDU1Handler.h" #include "mission/devices/PDU2Handler.h" +#include "mission/devices/PayloadPcduHandler.h" #include "mission/devices/PlocMPSoCHandler.h" #include "mission/devices/RadiationSensorHandler.h" #include "mission/devices/RwHandler.h" @@ -71,6 +70,7 @@ #include "mission/devices/devicedefinitions/RadSensorDefinitions.h" #include "mission/devices/devicedefinitions/RwDefinitions.h" #include "mission/devices/devicedefinitions/SyrlinksDefinitions.h" +#include "mission/devices/devicedefinitions/payloadPcduDefinitions.h" #include "mission/tmtc/CCSDSHandler.h" #include "mission/tmtc/VirtualChannel.h" #include "mission/utility/TmFunnel.h" diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index e1af31e6..d5aee5bf 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -296,35 +296,29 @@ void SpiTestClass::performOneShotMax1227Test() { adcCfg.testRadSensorExtConvWithDelay = false; adcCfg.testRadSensorIntConv = false; - adcCfg.testSus[0].doTest = true; - adcCfg.testSus[0].intConv = true; - adcCfg.testSus[6].doTest = true; - adcCfg.testSus[6].intConv = true; + bool setAllSusOn = false; + bool susIntConv = false; + bool susExtConv = false; + if (setAllSusOn) { + for (uint8_t idx = 0; idx < 12; idx++) { + adcCfg.testSus[idx].doTest = true; + } + } else { + for (uint8_t idx = 0; idx < 12; idx++) { + adcCfg.testSus[idx].doTest = false; + } + } - adcCfg.testSus[1].doTest = true; - adcCfg.testSus[1].intConv = true; - adcCfg.testSus[7].doTest = true; - adcCfg.testSus[7].intConv = true; - - adcCfg.testSus[10].doTest = true; - adcCfg.testSus[10].intConv = true; - adcCfg.testSus[4].doTest = true; - adcCfg.testSus[4].intConv = true; - - adcCfg.testSus[11].doTest = true; - adcCfg.testSus[11].intConv = true; - adcCfg.testSus[5].doTest = true; - adcCfg.testSus[5].intConv = true; - - adcCfg.testSus[2].doTest = true; - adcCfg.testSus[2].intConv = true; - adcCfg.testSus[3].doTest = true; - adcCfg.testSus[3].intConv = true; - - adcCfg.testSus[8].doTest = true; - adcCfg.testSus[8].intConv = true; - adcCfg.testSus[9].doTest = true; - adcCfg.testSus[9].intConv = true; + if (susIntConv) { + for (uint8_t idx = 0; idx < 12; idx++) { + adcCfg.testSus[idx].intConv = true; + } + } + if (susExtConv) { + for (uint8_t idx = 0; idx < 12; idx++) { + adcCfg.testSus[idx].extConv = true; + } + } adcCfg.plPcduAdcExtConv = false; adcCfg.plPcduAdcIntConv = true; @@ -334,7 +328,7 @@ void SpiTestClass::performOneShotMax1227Test() { void SpiTestClass::performPeriodicMax1227Test() { using namespace max1227; adcCfg.testRadSensorExtConvWithDelay = false; - adcCfg.testRadSensorIntConv = false; + adcCfg.testRadSensorIntConv = true; adcCfg.plPcduAdcExtConv = false; adcCfg.plPcduAdcIntConv = false; diff --git a/linux/devices/GPSHyperionLinuxController.h b/linux/devices/GPSHyperionLinuxController.h index a39ee9ac..3615cebd 100644 --- a/linux/devices/GPSHyperionLinuxController.h +++ b/linux/devices/GPSHyperionLinuxController.h @@ -1,10 +1,10 @@ #ifndef MISSION_DEVICES_GPSHYPERIONHANDLER_H_ #define MISSION_DEVICES_GPSHYPERIONHANDLER_H_ -#include "mission/devices/devicedefinitions/GPSDefinitions.h" #include "fsfw/FSFW.h" #include "fsfw/controller/ExtendedControllerBase.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h" +#include "mission/devices/devicedefinitions/GPSDefinitions.h" #ifdef FSFW_OSAL_LINUX #include diff --git a/linux/devices/SusHandler.cpp b/linux/devices/SusHandler.cpp index bfd5516b..2dc41cdd 100644 --- a/linux/devices/SusHandler.cpp +++ b/linux/devices/SusHandler.cpp @@ -226,7 +226,7 @@ ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool &localData void SusHandler::setToGoToNormalMode(bool enable) { this->goToNormalModeImmediately = enable; } void SusHandler::printDataset() { - if(periodicPrintout) { + if (periodicPrintout) { if (divider.checkAndIncrement()) { sif::info << "SUS " << std::setw(2) << std::dec << static_cast(susIdx) << " ID " << std::hex << "0x" << this->getObjectId() << " [" << std::hex << std::setw(3); diff --git a/linux/fsfwconfig/OBSWConfig.h.in b/linux/fsfwconfig/OBSWConfig.h.in index 569818f0..75334d45 100644 --- a/linux/fsfwconfig/OBSWConfig.h.in +++ b/linux/fsfwconfig/OBSWConfig.h.in @@ -85,6 +85,8 @@ debugging. */ #define OBSW_DEBUG_RTD 0 #define OBSW_TEST_RAD_SENSOR 0 #define OBSW_DEBUG_RAD_SENSOR 0 +#define OBSW_TEST_PL_PCDU 0 +#define OBSW_DEBUG_PL_PCDU 0 #define OBSW_TEST_LIBGPIOD 0 #define OBSW_TEST_PLOC_HANDLER 0 #define OBSW_TEST_BPX_BATT 0 diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 0c7fcd9c..83c26ecc 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -360,8 +360,8 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) { #endif #if OBSW_ADD_ACS_BOARD == 1 && OBSW_ADD_ACS_HANDLERS == 1 - bool enableAside = true; - bool enableBside = false; + bool enableAside = false; + bool enableBside = true; if (enableAside) { // A side thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0, diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 980439d1..627f9efd 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -1,5 +1,7 @@ -#include #include "PayloadPcduHandler.h" + +#include + #include "devices/gpioIds.h" PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, @@ -34,14 +36,14 @@ void PayloadPcduHandler::doStartUp() { void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (mode == _MODE_TO_NORMAL) { - if(adcState == AdcStates::BOOT_DELAY) { + if (adcState == AdcStates::BOOT_DELAY) { if (adcCountdown.hasTimedOut()) { adcState = AdcStates::SEND_SETUP; adcCmdExecuted = false; } } - if(adcState == AdcStates::SEND_SETUP) { - if(adcCmdExecuted) { + if (adcState == AdcStates::SEND_SETUP) { + if (adcCmdExecuted) { adcState = AdcStates::NORMAL; adcCmdExecuted = false; } @@ -138,26 +140,26 @@ void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { void PayloadPcduHandler::doShutDown() {} ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { - switch(adcState) { - case(AdcStates::SEND_SETUP): { - *id = plpcdu::SETUP_CMD; - buildCommandFromCommand(*id, nullptr, 0); - break; - } - case(AdcStates::NORMAL): { - *id = plpcdu::READ_WITH_TEMP; - buildCommandFromCommand(*id, nullptr, 0); - break; - } - default: { - break; - } + switch (adcState) { + case (AdcStates::SEND_SETUP): { + *id = plpcdu::SETUP_CMD; + buildCommandFromCommand(*id, nullptr, 0); + break; + } + case (AdcStates::NORMAL): { + *id = plpcdu::READ_WITH_TEMP; + buildCommandFromCommand(*id, nullptr, 0); + break; + } + default: { + break; + } } return NOTHING_TO_SEND; } ReturnValue_t PayloadPcduHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { - if(adcState == AdcStates::SEND_SETUP) { + if (adcState == AdcStates::SEND_SETUP) { *id = plpcdu::SETUP_CMD; buildCommandFromCommand(*id, nullptr, 0); } @@ -174,30 +176,30 @@ void PayloadPcduHandler::fillCommandAndReplyMap() { ReturnValue_t PayloadPcduHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData, size_t commandDataLen) { - switch(deviceCommand) { - case(plpcdu::SETUP_CMD): { - cmdBuf[0] = plpcdu::SETUP_BYTE; - rawPacket = cmdBuf.data(); - rawPacketLen = 1; - break; - } - case(plpcdu::READ_CMD): { - max1227::prepareExternallyClockedRead0ToN(cmdBuf.data(), plpcdu::CHANNEL_N, rawPacketLen); - rawPacket = cmdBuf.data(); - break; - } - case(plpcdu::READ_TEMP): { - max1227::prepareExternallyClockedTemperatureRead(cmdBuf.data(), rawPacketLen); - rawPacket = cmdBuf.data(); - break; - } - case(plpcdu::READ_WITH_TEMP): { - size_t sz = 0; - max1227::prepareExternallyClockedRead0ToN(cmdBuf.data(), plpcdu::CHANNEL_N, sz); - max1227::prepareExternallyClockedTemperatureRead(cmdBuf.data() + sz, sz); - rawPacketLen = sz; - rawPacket = cmdBuf.data(); - } + switch (deviceCommand) { + case (plpcdu::SETUP_CMD): { + cmdBuf[0] = plpcdu::SETUP_BYTE; + rawPacket = cmdBuf.data(); + rawPacketLen = 1; + break; + } + case (plpcdu::READ_CMD): { + max1227::prepareExternallyClockedRead0ToN(cmdBuf.data(), plpcdu::CHANNEL_N, rawPacketLen); + rawPacket = cmdBuf.data(); + break; + } + case (plpcdu::READ_TEMP): { + max1227::prepareExternallyClockedTemperatureRead(cmdBuf.data(), rawPacketLen); + rawPacket = cmdBuf.data(); + break; + } + case (plpcdu::READ_WITH_TEMP): { + size_t sz = 0; + max1227::prepareExternallyClockedRead0ToN(cmdBuf.data(), plpcdu::CHANNEL_N, sz); + max1227::prepareExternallyClockedTemperatureRead(cmdBuf.data() + sz, sz); + rawPacketLen = sz; + rawPacket = cmdBuf.data(); + } } return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } @@ -213,22 +215,42 @@ ReturnValue_t PayloadPcduHandler::scanForReply(const uint8_t* start, size_t rema ReturnValue_t PayloadPcduHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) { using namespace plpcdu; - switch(id) { - case(SETUP_CMD): { - break; - } - case(READ_WITH_TEMP): { - PoolReadGuard pg(&adcSet); - if(pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { - return pg.getReadResult(); + switch (id) { + case (SETUP_CMD): { + break; } - for(uint8_t idx = 0; idx < 12; idx ++) { - adcSet.channels[idx] = packet[idx * 2 + 1] << 8 | packet[idx * 2 + 2]; + case (READ_TEMP): { + uint8_t tempStartIdx = TEMP_REPLY_SIZE - 2; + adcSet.tempC.value = + max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 2]); + break; + } + case (READ_CMD): { + PoolReadGuard pg(&adcSet); + if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { + return pg.getReadResult(); + } + for (uint8_t idx = 0; idx < 12; idx++) { + adcSet.channels[idx] = packet[idx * 2 + 1] << 8 | packet[idx * 2 + 2]; + } + break; + } + case (READ_WITH_TEMP): { + PoolReadGuard pg(&adcSet); + if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { + return pg.getReadResult(); + } + for (uint8_t idx = 0; idx < 12; idx++) { + adcSet.channels[idx] = packet[idx * 2 + 1] << 8 | packet[idx * 2 + 2]; + } + uint8_t tempStartIdx = ADC_REPLY_SIZE + TEMP_REPLY_SIZE - 2; + adcSet.tempC.value = + max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 2]); + break; + } + default: { + break; } - uint8_t tempStartIdx = ADC_REPLY_SIZE + TEMP_REPLY_SIZE - 2; - adcSet.tempC.value = max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 2]); - } - } return HasReturnvaluesIF::RETURN_OK; } @@ -244,3 +266,7 @@ ReturnValue_t PayloadPcduHandler::initializeLocalDataPool(localpool::DataPool& l localDataPoolMap.emplace(plpcdu::PlPcduPoolIds::TEMP, &tempC); return HasReturnvaluesIF::RETURN_OK; } + +void PayloadPcduHandler::setToGoToNormalModeImmediately(bool enable) { + this->goToNormalMode = enable; +} diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index 64b71be4..919df391 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -3,6 +3,7 @@ #include #include + #include "devicedefinitions/payloadPcduDefinitions.h" #include "fsfw_hal/common/gpio/GpioIF.h" @@ -24,6 +25,8 @@ class PayloadPcduHandler : DeviceHandlerBase { public: PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF); + void setToGoToNormalModeImmediately(bool enable); + private: enum class States { PCDU_OFF, @@ -50,6 +53,7 @@ class PayloadPcduHandler : DeviceHandlerBase { enum class AdcStates { OFF, BOOT_DELAY, SEND_SETUP, NORMAL } adcState = AdcStates::OFF; + bool goToNormalMode = false; plpcdu::PlPcduAdcSet adcSet; std::array cmdBuf = {}; // This variable is tied to DRO +6 V voltage. Voltages, currents are monitored and the experiment diff --git a/mission/devices/devicedefinitions/payloadPcduDefinitions.h b/mission/devices/devicedefinitions/payloadPcduDefinitions.h index 9029fad7..a5de3a12 100644 --- a/mission/devices/devicedefinitions/payloadPcduDefinitions.h +++ b/mission/devices/devicedefinitions/payloadPcduDefinitions.h @@ -3,17 +3,16 @@ #include #include -#include "mission/devices/max1227.h" + #include +#include "mission/devices/max1227.h" + namespace plpcdu { using namespace max1227; -enum PlPcduPoolIds: uint32_t { - CHANNEL_VEC = 0, - TEMP = 1 -}; +enum PlPcduPoolIds : uint32_t { CHANNEL_VEC = 0, TEMP = 1 }; static constexpr size_t MAX_ADC_REPLY_SIZE = 64; @@ -27,8 +26,8 @@ static constexpr size_t ADC_REPLY_SIZE = 25; // Conversion byte + 24 * zero static constexpr size_t TEMP_REPLY_SIZE = 25; -static constexpr uint8_t SETUP_BYTE = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, - RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); +static constexpr uint8_t SETUP_BYTE = + max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0); static constexpr uint32_t ADC_SET_ID = READ_CMD; static constexpr uint8_t CHANNELS_NUM = 12; @@ -40,13 +39,12 @@ class PlPcduAdcSet : public StaticLocalDataSet { public: PlPcduAdcSet(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, ADC_SET_ID) {} - PlPcduAdcSet(object_id_t objectId) - : StaticLocalDataSet(sid_t(objectId, ADC_SET_ID)) {} + PlPcduAdcSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, ADC_SET_ID)) {} lp_vec_t channels = lp_vec_t(sid.objectId, CHANNEL_VEC, this); lp_var_t tempC = lp_var_t(sid.objectId, TEMP, this); }; -} +} // namespace plpcdu #endif /* LINUX_DEVICES_DEVICEDEFINITIONS_PAYLOADPCDUDEFINITIONS_H_ */ diff --git a/mission/devices/max1227.h b/mission/devices/max1227.h index 9d29b38c..1a6082fb 100644 --- a/mission/devices/max1227.h +++ b/mission/devices/max1227.h @@ -40,9 +40,7 @@ enum DiffSel : uint8_t { BIPOLAR_CFG = 0b11 }; -constexpr uint8_t buildResetByte(bool fifoOnly) { - return (1 << 4) | (fifoOnly << 3); -} +constexpr uint8_t buildResetByte(bool fifoOnly) { return (1 << 4) | (fifoOnly << 3); } constexpr uint8_t buildConvByte(ScanModes scanMode, uint8_t channel, bool readTemp) { return (1 << 7) | (channel << 3) | (scanMode << 1) | readTemp;