From 0587f408744ceeb44c7d92b6c79de74ae0286e9b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 18 Jul 2023 09:44:44 +0200 Subject: [PATCH] add rad sensor dummy --- bsp_q7s/objectFactory.cpp | 2 +- dummies/RadSensorDummy.cpp | 53 ++++++++++++++++++ dummies/RadSensorDummy.h | 37 ++++++++++++ fsfw | 2 +- mission/payload/RadiationSensorHandler.cpp | 65 +++++++++++----------- mission/payload/RadiationSensorHandler.h | 4 +- mission/payload/radSensorDefinitions.h | 4 +- 7 files changed, 128 insertions(+), 39 deletions(-) create mode 100644 dummies/RadSensorDummy.cpp create mode 100644 dummies/RadSensorDummy.h diff --git a/bsp_q7s/objectFactory.cpp b/bsp_q7s/objectFactory.cpp index 326ba8ef..04da40a9 100644 --- a/bsp_q7s/objectFactory.cpp +++ b/bsp_q7s/objectFactory.cpp @@ -249,7 +249,7 @@ ReturnValue_t ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF, createRadSensorChipSelect(gpioComIF); SpiCookie* spiCookieRadSensor = - new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, RAD_SENSOR::READ_SIZE, + new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, radSens::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); spiCookieRadSensor->setMutexParams(MutexIF::TimeoutType::WAITING, spi::RAD_SENSOR_CS_TIMEOUT); auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF, diff --git a/dummies/RadSensorDummy.cpp b/dummies/RadSensorDummy.cpp new file mode 100644 index 00000000..c48efb58 --- /dev/null +++ b/dummies/RadSensorDummy.cpp @@ -0,0 +1,53 @@ +#include "RadSensorDummy.h" + +RadSensorDummy::RadSensorDummy(object_id_t objectId, object_id_t comif, CookieIF *comCookie) + : DeviceHandlerBase(objectId, comif, comCookie), sensorSet(this) {} + +RadSensorDummy::~RadSensorDummy() {} + +void RadSensorDummy::doStartUp() { setMode(MODE_ON); } + +void RadSensorDummy::doShutDown() { setMode(MODE_OFF); } + +ReturnValue_t RadSensorDummy::buildNormalDeviceCommand(DeviceCommandId_t *id) { + return NOTHING_TO_SEND; +} + +ReturnValue_t RadSensorDummy::buildTransitionDeviceCommand(DeviceCommandId_t *id) { + return NOTHING_TO_SEND; +} + +ReturnValue_t RadSensorDummy::buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t *commandData, + size_t commandDataLen) { + return returnvalue::OK; +} + +ReturnValue_t RadSensorDummy::scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) { + return returnvalue::OK; +} + +ReturnValue_t RadSensorDummy::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { + return returnvalue::OK; +} + +void RadSensorDummy::fillCommandAndReplyMap() {} + +uint32_t RadSensorDummy::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; } + +ReturnValue_t RadSensorDummy::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(radSens::TEMPERATURE_C, new PoolEntry({0.0})); + localDataPoolMap.emplace(radSens::AIN0, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN1, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN4, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN5, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN6, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN7, new PoolEntry({0})); + poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(sensorSet.getSid(), false, 20.0)); + return returnvalue::OK; + + return returnvalue::OK; +} diff --git a/dummies/RadSensorDummy.h b/dummies/RadSensorDummy.h new file mode 100644 index 00000000..c38d35a1 --- /dev/null +++ b/dummies/RadSensorDummy.h @@ -0,0 +1,37 @@ +#ifndef DUMMIES_SUSDUMMY_H_ +#define DUMMIES_SUSDUMMY_H_ + +#include + +#include "mission/payload/radSensorDefinitions.h" + +class RadSensorDummy : public DeviceHandlerBase { + public: + static const DeviceCommandId_t SIMPLE_COMMAND = 1; + static const DeviceCommandId_t PERIODIC_REPLY = 2; + + static const uint8_t SIMPLE_COMMAND_DATA = 1; + static const uint8_t PERIODIC_REPLY_DATA = 2; + + RadSensorDummy(object_id_t objectId, object_id_t comif, CookieIF *comCookie); + virtual ~RadSensorDummy(); + + protected: + radSens::RadSensorDataset sensorSet; + + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override; + ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId, + size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; + void fillCommandAndReplyMap() override; + uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; +}; + +#endif /* DUMMIES_SUSDUMMY_H_ */ diff --git a/fsfw b/fsfw index d575da85..8e62143a 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit d575da85407e029dabecaffa5368f0c9f1034941 +Subproject commit 8e62143ac87a35ce2d9c4e40ae3b52a73cbe11c5 diff --git a/mission/payload/RadiationSensorHandler.cpp b/mission/payload/RadiationSensorHandler.cpp index d18fcb2c..2a87e730 100644 --- a/mission/payload/RadiationSensorHandler.cpp +++ b/mission/payload/RadiationSensorHandler.cpp @@ -53,12 +53,12 @@ void RadiationSensorHandler::doShutDown() { ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { switch (communicationStep) { case CommunicationStep::START_CONVERSION: { - *id = RAD_SENSOR::START_CONVERSION; + *id = radSens::START_CONVERSION; communicationStep = CommunicationStep::READ_CONVERSIONS; break; } case CommunicationStep::READ_CONVERSIONS: { - *id = RAD_SENSOR::READ_CONVERSIONS; + *id = radSens::READ_CONVERSIONS; communicationStep = CommunicationStep::START_CONVERSION; break; } @@ -73,7 +73,7 @@ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) { if (internalState == InternalState::SETUP) { - *id = RAD_SENSOR::WRITE_SETUP; + *id = radSens::WRITE_SETUP; } else { return NOTHING_TO_SEND; } @@ -84,14 +84,14 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t const uint8_t *commandData, size_t commandDataLen) { switch (deviceCommand) { - case (RAD_SENSOR::WRITE_SETUP): { - cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; + case (radSens::WRITE_SETUP): { + cmdBuffer[0] = radSens::SETUP_DEFINITION; rawPacket = cmdBuffer; rawPacketLen = 1; internalState = InternalState::CONFIGURED; return returnvalue::OK; } - case (RAD_SENSOR::START_CONVERSION): { + case (radSens::START_CONVERSION): { ReturnValue_t result = gpioIF->pullHigh(gpioIds::ENABLE_RADFET); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 @@ -102,25 +102,25 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t #endif } /* First the fifo will be reset here */ - cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; - cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; + cmdBuffer[0] = radSens::RESET_DEFINITION; + cmdBuffer[1] = radSens::CONVERSION_DEFINITION; rawPacket = cmdBuffer; rawPacketLen = 2; return returnvalue::OK; } - case (RAD_SENSOR::READ_CONVERSIONS): { - cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; - std::memset(cmdBuffer, RAD_SENSOR::DUMMY_BYTE, RAD_SENSOR::READ_SIZE); + case (radSens::READ_CONVERSIONS): { + cmdBuffer[0] = radSens::DUMMY_BYTE; + std::memset(cmdBuffer, radSens::DUMMY_BYTE, radSens::READ_SIZE); rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; + rawPacketLen = radSens::READ_SIZE; return returnvalue::OK; } - case RAD_SENSOR::ENABLE_DEBUG_OUTPUT: { + case radSens::ENABLE_DEBUG_OUTPUT: { printPeriodicData = true; rawPacketLen = 0; return returnvalue::OK; } - case RAD_SENSOR::DISABLE_DEBUG_OUTPUT: { + case radSens::DISABLE_DEBUG_OUTPUT: { rawPacketLen = 0; printPeriodicData = false; return returnvalue::OK; @@ -132,12 +132,11 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t } void RadiationSensorHandler::fillCommandAndReplyMap() { - this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); - this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); - this->insertInCommandMap(RAD_SENSOR::ENABLE_DEBUG_OUTPUT); - this->insertInCommandMap(RAD_SENSOR::DISABLE_DEBUG_OUTPUT); - this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, - RAD_SENSOR::READ_SIZE); + this->insertInCommandMap(radSens::WRITE_SETUP); + this->insertInCommandMap(radSens::START_CONVERSION); + this->insertInCommandMap(radSens::ENABLE_DEBUG_OUTPUT); + this->insertInCommandMap(radSens::DISABLE_DEBUG_OUTPUT); + this->insertInCommandAndReplyMap(radSens::READ_CONVERSIONS, 1, &dataset, radSens::READ_SIZE); } ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t remainingSize, @@ -145,11 +144,11 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t *foundId = this->getPendingCommand(); switch (*foundId) { - case RAD_SENSOR::START_CONVERSION: - case RAD_SENSOR::WRITE_SETUP: + case radSens::START_CONVERSION: + case radSens::WRITE_SETUP: *foundLen = remainingSize; return IGNORE_REPLY_DATA; - case RAD_SENSOR::READ_CONVERSIONS: { + case radSens::READ_CONVERSIONS: { ReturnValue_t result = gpioIF->pullLow(gpioIds::ENABLE_RADFET); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 @@ -160,8 +159,8 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t } break; } - case RAD_SENSOR::ENABLE_DEBUG_OUTPUT: - case RAD_SENSOR::DISABLE_DEBUG_OUTPUT: + case radSens::ENABLE_DEBUG_OUTPUT: + case radSens::DISABLE_DEBUG_OUTPUT: sif::info << "RadiationSensorHandler::scanForReply: " << remainingSize << std::endl; break; default: @@ -176,7 +175,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case RAD_SENSOR::READ_CONVERSIONS: { + case radSens::READ_CONVERSIONS: { uint8_t offset = 0; PoolReadGuard readSet(&dataset); uint16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1]; @@ -220,13 +219,13 @@ uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t mo ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(RAD_SENSOR::TEMPERATURE_C, new PoolEntry({0.0})); - localDataPoolMap.emplace(RAD_SENSOR::AIN0, new PoolEntry({0})); - localDataPoolMap.emplace(RAD_SENSOR::AIN1, new PoolEntry({0})); - localDataPoolMap.emplace(RAD_SENSOR::AIN4, new PoolEntry({0})); - localDataPoolMap.emplace(RAD_SENSOR::AIN5, new PoolEntry({0})); - localDataPoolMap.emplace(RAD_SENSOR::AIN6, new PoolEntry({0})); - localDataPoolMap.emplace(RAD_SENSOR::AIN7, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::TEMPERATURE_C, new PoolEntry({0.0})); + localDataPoolMap.emplace(radSens::AIN0, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN1, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN4, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN5, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN6, new PoolEntry({0})); + localDataPoolMap.emplace(radSens::AIN7, new PoolEntry({0})); poolManager.subscribeForRegularPeriodicPacket( subdp::RegularHkPeriodicParams(dataset.getSid(), false, 20.0)); return returnvalue::OK; diff --git a/mission/payload/RadiationSensorHandler.h b/mission/payload/RadiationSensorHandler.h index de9bcc93..2e8ca7f2 100644 --- a/mission/payload/RadiationSensorHandler.h +++ b/mission/payload/RadiationSensorHandler.h @@ -43,8 +43,8 @@ class RadiationSensorHandler : public DeviceHandlerBase { enum class InternalState { OFF, POWER_SWITCHING, SETUP, CONFIGURED }; bool printPeriodicData = false; - RAD_SENSOR::RadSensorDataset dataset; - static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; + radSens::RadSensorDataset dataset; + static const uint8_t MAX_CMD_LEN = radSens::READ_SIZE; GpioIF *gpioIF = nullptr; Stack5VHandler &stackHandler; diff --git a/mission/payload/radSensorDefinitions.h b/mission/payload/radSensorDefinitions.h index 8f6b9f0b..3262c23c 100644 --- a/mission/payload/radSensorDefinitions.h +++ b/mission/payload/radSensorDefinitions.h @@ -1,7 +1,7 @@ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ -namespace RAD_SENSOR { +namespace radSens { static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending @@ -78,6 +78,6 @@ class RadSensorDataset : public StaticLocalDataSet { lp_var_t ain6 = lp_var_t(sid.objectId, AIN6, this); lp_var_t ain7 = lp_var_t(sid.objectId, AIN7, this); }; -} // namespace RAD_SENSOR +} // namespace radSens #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ */