add rad sensor dummy
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-07-18 09:44:44 +02:00
parent 320b460179
commit 0587f40874
Signed by: muellerr
GPG Key ID: A649FB78196E3849
7 changed files with 128 additions and 39 deletions

View File

@ -249,7 +249,7 @@ ReturnValue_t ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF,
createRadSensorChipSelect(gpioComIF); createRadSensorChipSelect(gpioComIF);
SpiCookie* spiCookieRadSensor = 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); spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
spiCookieRadSensor->setMutexParams(MutexIF::TimeoutType::WAITING, spi::RAD_SENSOR_CS_TIMEOUT); spiCookieRadSensor->setMutexParams(MutexIF::TimeoutType::WAITING, spi::RAD_SENSOR_CS_TIMEOUT);
auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF, auto radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_MAIN_COM_IF,

View File

@ -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<float>({0.0}));
localDataPoolMap.emplace(radSens::AIN0, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(radSens::AIN1, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(radSens::AIN4, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(radSens::AIN5, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(radSens::AIN6, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(radSens::AIN7, new PoolEntry<uint16_t>({0}));
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(sensorSet.getSid(), false, 20.0));
return returnvalue::OK;
return returnvalue::OK;
}

37
dummies/RadSensorDummy.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef DUMMIES_SUSDUMMY_H_
#define DUMMIES_SUSDUMMY_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#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_ */

2
fsfw

@ -1 +1 @@
Subproject commit d575da85407e029dabecaffa5368f0c9f1034941 Subproject commit 8e62143ac87a35ce2d9c4e40ae3b52a73cbe11c5

View File

@ -53,12 +53,12 @@ void RadiationSensorHandler::doShutDown() {
ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
switch (communicationStep) { switch (communicationStep) {
case CommunicationStep::START_CONVERSION: { case CommunicationStep::START_CONVERSION: {
*id = RAD_SENSOR::START_CONVERSION; *id = radSens::START_CONVERSION;
communicationStep = CommunicationStep::READ_CONVERSIONS; communicationStep = CommunicationStep::READ_CONVERSIONS;
break; break;
} }
case CommunicationStep::READ_CONVERSIONS: { case CommunicationStep::READ_CONVERSIONS: {
*id = RAD_SENSOR::READ_CONVERSIONS; *id = radSens::READ_CONVERSIONS;
communicationStep = CommunicationStep::START_CONVERSION; communicationStep = CommunicationStep::START_CONVERSION;
break; break;
} }
@ -73,7 +73,7 @@ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(DeviceCommandId_t
ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
if (internalState == InternalState::SETUP) { if (internalState == InternalState::SETUP) {
*id = RAD_SENSOR::WRITE_SETUP; *id = radSens::WRITE_SETUP;
} else { } else {
return NOTHING_TO_SEND; return NOTHING_TO_SEND;
} }
@ -84,14 +84,14 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t
const uint8_t *commandData, const uint8_t *commandData,
size_t commandDataLen) { size_t commandDataLen) {
switch (deviceCommand) { switch (deviceCommand) {
case (RAD_SENSOR::WRITE_SETUP): { case (radSens::WRITE_SETUP): {
cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; cmdBuffer[0] = radSens::SETUP_DEFINITION;
rawPacket = cmdBuffer; rawPacket = cmdBuffer;
rawPacketLen = 1; rawPacketLen = 1;
internalState = InternalState::CONFIGURED; internalState = InternalState::CONFIGURED;
return returnvalue::OK; return returnvalue::OK;
} }
case (RAD_SENSOR::START_CONVERSION): { case (radSens::START_CONVERSION): {
ReturnValue_t result = gpioIF->pullHigh(gpioIds::ENABLE_RADFET); ReturnValue_t result = gpioIF->pullHigh(gpioIds::ENABLE_RADFET);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
@ -102,25 +102,25 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t
#endif #endif
} }
/* First the fifo will be reset here */ /* First the fifo will be reset here */
cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; cmdBuffer[0] = radSens::RESET_DEFINITION;
cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; cmdBuffer[1] = radSens::CONVERSION_DEFINITION;
rawPacket = cmdBuffer; rawPacket = cmdBuffer;
rawPacketLen = 2; rawPacketLen = 2;
return returnvalue::OK; return returnvalue::OK;
} }
case (RAD_SENSOR::READ_CONVERSIONS): { case (radSens::READ_CONVERSIONS): {
cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[0] = radSens::DUMMY_BYTE;
std::memset(cmdBuffer, RAD_SENSOR::DUMMY_BYTE, RAD_SENSOR::READ_SIZE); std::memset(cmdBuffer, radSens::DUMMY_BYTE, radSens::READ_SIZE);
rawPacket = cmdBuffer; rawPacket = cmdBuffer;
rawPacketLen = RAD_SENSOR::READ_SIZE; rawPacketLen = radSens::READ_SIZE;
return returnvalue::OK; return returnvalue::OK;
} }
case RAD_SENSOR::ENABLE_DEBUG_OUTPUT: { case radSens::ENABLE_DEBUG_OUTPUT: {
printPeriodicData = true; printPeriodicData = true;
rawPacketLen = 0; rawPacketLen = 0;
return returnvalue::OK; return returnvalue::OK;
} }
case RAD_SENSOR::DISABLE_DEBUG_OUTPUT: { case radSens::DISABLE_DEBUG_OUTPUT: {
rawPacketLen = 0; rawPacketLen = 0;
printPeriodicData = false; printPeriodicData = false;
return returnvalue::OK; return returnvalue::OK;
@ -132,12 +132,11 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(DeviceCommandId_t
} }
void RadiationSensorHandler::fillCommandAndReplyMap() { void RadiationSensorHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); this->insertInCommandMap(radSens::WRITE_SETUP);
this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); this->insertInCommandMap(radSens::START_CONVERSION);
this->insertInCommandMap(RAD_SENSOR::ENABLE_DEBUG_OUTPUT); this->insertInCommandMap(radSens::ENABLE_DEBUG_OUTPUT);
this->insertInCommandMap(RAD_SENSOR::DISABLE_DEBUG_OUTPUT); this->insertInCommandMap(radSens::DISABLE_DEBUG_OUTPUT);
this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, this->insertInCommandAndReplyMap(radSens::READ_CONVERSIONS, 1, &dataset, radSens::READ_SIZE);
RAD_SENSOR::READ_SIZE);
} }
ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t remainingSize, 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(); *foundId = this->getPendingCommand();
switch (*foundId) { switch (*foundId) {
case RAD_SENSOR::START_CONVERSION: case radSens::START_CONVERSION:
case RAD_SENSOR::WRITE_SETUP: case radSens::WRITE_SETUP:
*foundLen = remainingSize; *foundLen = remainingSize;
return IGNORE_REPLY_DATA; return IGNORE_REPLY_DATA;
case RAD_SENSOR::READ_CONVERSIONS: { case radSens::READ_CONVERSIONS: {
ReturnValue_t result = gpioIF->pullLow(gpioIds::ENABLE_RADFET); ReturnValue_t result = gpioIF->pullLow(gpioIds::ENABLE_RADFET);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
@ -160,8 +159,8 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t
} }
break; break;
} }
case RAD_SENSOR::ENABLE_DEBUG_OUTPUT: case radSens::ENABLE_DEBUG_OUTPUT:
case RAD_SENSOR::DISABLE_DEBUG_OUTPUT: case radSens::DISABLE_DEBUG_OUTPUT:
sif::info << "RadiationSensorHandler::scanForReply: " << remainingSize << std::endl; sif::info << "RadiationSensorHandler::scanForReply: " << remainingSize << std::endl;
break; break;
default: default:
@ -176,7 +175,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, size_t
ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) { const uint8_t *packet) {
switch (id) { switch (id) {
case RAD_SENSOR::READ_CONVERSIONS: { case radSens::READ_CONVERSIONS: {
uint8_t offset = 0; uint8_t offset = 0;
PoolReadGuard readSet(&dataset); PoolReadGuard readSet(&dataset);
uint16_t tempRaw = ((packet[offset] & 0x0f) << 8) | packet[offset + 1]; 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, ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) { LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(RAD_SENSOR::TEMPERATURE_C, new PoolEntry<float>({0.0})); localDataPoolMap.emplace(radSens::TEMPERATURE_C, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RAD_SENSOR::AIN0, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(radSens::AIN0, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(RAD_SENSOR::AIN1, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(radSens::AIN1, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(RAD_SENSOR::AIN4, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(radSens::AIN4, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(RAD_SENSOR::AIN5, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(radSens::AIN5, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(RAD_SENSOR::AIN6, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(radSens::AIN6, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(RAD_SENSOR::AIN7, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(radSens::AIN7, new PoolEntry<uint16_t>({0}));
poolManager.subscribeForRegularPeriodicPacket( poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(dataset.getSid(), false, 20.0)); subdp::RegularHkPeriodicParams(dataset.getSid(), false, 20.0));
return returnvalue::OK; return returnvalue::OK;

View File

@ -43,8 +43,8 @@ class RadiationSensorHandler : public DeviceHandlerBase {
enum class InternalState { OFF, POWER_SWITCHING, SETUP, CONFIGURED }; enum class InternalState { OFF, POWER_SWITCHING, SETUP, CONFIGURED };
bool printPeriodicData = false; bool printPeriodicData = false;
RAD_SENSOR::RadSensorDataset dataset; radSens::RadSensorDataset dataset;
static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; static const uint8_t MAX_CMD_LEN = radSens::READ_SIZE;
GpioIF *gpioIF = nullptr; GpioIF *gpioIF = nullptr;
Stack5VHandler &stackHandler; Stack5VHandler &stackHandler;

View File

@ -1,7 +1,7 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_
#define 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 static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
@ -78,6 +78,6 @@ class RadSensorDataset : public StaticLocalDataSet<DATASET_ENTRIES> {
lp_var_t<uint16_t> ain6 = lp_var_t<uint16_t>(sid.objectId, AIN6, this); lp_var_t<uint16_t> ain6 = lp_var_t<uint16_t>(sid.objectId, AIN6, this);
lp_var_t<uint16_t> ain7 = lp_var_t<uint16_t>(sid.objectId, AIN7, this); lp_var_t<uint16_t> ain7 = lp_var_t<uint16_t>(sid.objectId, AIN7, this);
}; };
} // namespace RAD_SENSOR } // namespace radSens
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ */ #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ */