rad sensor change wip

This commit is contained in:
2021-05-03 11:59:33 +02:00
parent b873831645
commit f708a67fa8
14 changed files with 563 additions and 92 deletions

View File

@ -15,6 +15,7 @@ target_sources(${TARGET_NAME} PUBLIC
IMTQHandler.cpp
PlocHandler.cpp
RadiationSensorHandler.cpp
SusHandler.cpp
)

View File

@ -31,25 +31,7 @@ void RadiationSensorHandler::doShutDown(){
ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
switch (communicationStep) {
case CommunicationStep::START_CONVERSION: {
*id = RAD_SENSOR::START_CONVERSION;
communicationStep = CommunicationStep::READ_CONVERSIONS;
break;
}
case CommunicationStep::READ_CONVERSIONS: {
*id = RAD_SENSOR::READ_CONVERSIONS;
// communicationStep = CommunicationStep::START_CONVERSION;
communicationStep = CommunicationStep::READ_CONVERSIONS;
break;
}
default: {
sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication "
<< "step" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
}
*id = RAD_SENSOR::PERFORM_CONVERSION;
return buildCommandFromCommand(*id, nullptr, 0);
}
@ -61,7 +43,7 @@ ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand(
else {
return HasReturnvaluesIF::RETURN_OK;
}
buildCommandFromCommand(*id, nullptr, 0);
return buildCommandFromCommand(*id, nullptr, 0);
}
ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
@ -75,23 +57,17 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
internalState = InternalState::CONFIGURED;
return RETURN_OK;
}
case(RAD_SENSOR::START_CONVERSION): {
case(RAD_SENSOR::PERFORM_CONVERSION): {
/* Dummy bytes are written to remove old values from fifo */
cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION;
rawPacket = cmdBuffer;
rawPacketLen = 1;
return RETURN_OK;
}
case(RAD_SENSOR::READ_CONVERSIONS): {
cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[6] = RAD_SENSOR::DUMMY_BYTE;
rawPacket = cmdBuffer;
rawPacketLen = RAD_SENSOR::READ_SIZE;
return RETURN_OK;
cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE;
rawPacket = cmdBuffer;
rawPacketLen = RAD_SENSOR::READ_SIZE;
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
@ -101,8 +77,7 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
void RadiationSensorHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP);
this->insertInCommandMap(RAD_SENSOR::START_CONVERSION);
this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset,
this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset,
RAD_SENSOR::READ_SIZE);
}
@ -116,7 +91,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start,
ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch (id) {
case RAD_SENSOR::READ_CONVERSIONS: {
case RAD_SENSOR::PERFORM_CONVERSION: {
PoolReadGuard readSet(&dataset);
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3));

View File

@ -0,0 +1,165 @@
#include <fsfw/datapool/PoolReadGuard.h>
#include <mission/devices/SusHandler.h>
#include <OBSWConfig.h>
SusHandler::SusHandler(object_id_t objectId, object_id_t comIF,
CookieIF * comCookie) :
DeviceHandlerBase(objectId, comIF, comCookie), dataset(
this) {
if (comCookie == NULL) {
sif::error << "SusHandler: Invalid com cookie" << std::endl;
}
}
SusHandler::~SusHandler() {
}
void SusHandler::doStartUp(){
if (internalState == InternalState::CONFIGURED) {
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
setMode(MODE_NORMAL);
#else
setMode(_MODE_TO_ON);
#endif
}
}
void SusHandler::doShutDown(){
setMode(_MODE_POWER_DOWN);
}
ReturnValue_t SusHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
switch (communicationStep) {
case CommunicationStep::START_CONVERSION: {
*id = SUS::START_CONVERSION;
communicationStep = CommunicationStep::READ_CONVERSIONS;
break;
}
case CommunicationStep::READ_CONVERSIONS: {
*id = SUS::READ_CONVERSIONS;
// communicationStep = CommunicationStep::START_CONVERSION;
communicationStep = CommunicationStep::READ_CONVERSIONS;
break;
}
default: {
sif::debug << "SusHandler::buildNormalDeviceCommand: Unknwon communication "
<< "step" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
}
return buildCommandFromCommand(*id, nullptr, 0);
}
ReturnValue_t SusHandler::buildTransitionDeviceCommand(
DeviceCommandId_t * id){
if (internalState == InternalState::SETUP) {
*id = SUS::WRITE_SETUP;
}
else {
return HasReturnvaluesIF::RETURN_OK;
}
return buildCommandFromCommand(*id, nullptr, 0);
}
ReturnValue_t SusHandler::buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
size_t commandDataLen) {
switch(deviceCommand) {
case(SUS::WRITE_SETUP): {
cmdBuffer[0] = SUS::SETUP_DEFINITION;
cmdBuffer[1] = SUS::UNIPOLAR_CONFIG;
rawPacket = cmdBuffer;
rawPacketLen = 2;
internalState = InternalState::CONFIGURED;
return RETURN_OK;
}
case(SUS::START_CONVERSION): {
cmdBuffer[0] = SUS::CONVERSION_DEFINITION;
rawPacket = cmdBuffer;
rawPacketLen = 1;
return RETURN_OK;
}
case(SUS::READ_CONVERSIONS): {
cmdBuffer[0] = SUS::DUMMY_BYTE;
cmdBuffer[1] = SUS::DUMMY_BYTE;
cmdBuffer[2] = SUS::DUMMY_BYTE;
cmdBuffer[3] = SUS::DUMMY_BYTE;
cmdBuffer[4] = SUS::DUMMY_BYTE;
cmdBuffer[5] = SUS::DUMMY_BYTE;
cmdBuffer[6] = SUS::DUMMY_BYTE;
cmdBuffer[7] = SUS::DUMMY_BYTE;
cmdBuffer[8] = SUS::DUMMY_BYTE;
rawPacket = cmdBuffer;
rawPacketLen = SUS::READ_SIZE;
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
return HasReturnvaluesIF::RETURN_FAILED;
}
void SusHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(SUS::WRITE_SETUP);
this->insertInCommandMap(SUS::START_CONVERSION);
this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset,
SUS::READ_SIZE);
}
ReturnValue_t SusHandler::scanForReply(const uint8_t *start,
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
*foundId = this->getPendingCommand();
*foundLen = remainingSize;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch (id) {
case SUS::READ_CONVERSIONS: {
PoolReadGuard readSet(&dataset);
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
dataset.diffScanChannel0_1 = (*(packet + 2) << 8 | *(packet + 3));
dataset.diffScanChannel2_3 = (*(packet + 2) << 8 | *(packet + 3));
dataset.diffScanChannel4_5 = (*(packet + 2) << 8 | *(packet + 3));
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: "
<< dataset.temperatureCelcius << " °C" << std::endl;
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 0/1: "
<< dataset.diffScanChannel0_1 << std::endl;
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 2/3: "
<< dataset.diffScanChannel2_3 << std::endl;
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 4/5: "
<< dataset.diffScanChannel4_5 << std::endl;
#endif
break;
}
default: {
sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void SusHandler::setNormalDatapoolEntriesInvalid(){
}
uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
return 5000;
}
ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(SUS::TEMPERATURE_C, new PoolEntry<float>( { 0.0 }));
localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_0_1, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_2_3, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_4_5, new PoolEntry<uint16_t>( { 0 }));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,61 @@
#ifndef MISSION_DEVICES_SUSHANDLER_H_
#define MISSION_DEVICES_SUSHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <mission/devices/devicedefinitions/SusDefinitions.h>
/**
* @brief This is the device handler class for the SUS sensor. The sensor is
* based on the MAX1227 ADC. Details about the SUS electronic can be found at
* https://egit.irs.uni-stuttgart.de/eive/eive_dokumente/src/branch/master/400_Raumsegment/443_SunSensorDocumentation/release
*
* @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf
*
* @author J. Meier
*/
class SusHandler: public DeviceHandlerBase {
public:
SusHandler(object_id_t objectId, object_id_t comIF,
CookieIF * comCookie);
virtual ~SusHandler();
protected:
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override;
void fillCommandAndReplyMap() override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t * commandData,size_t commandDataLen) override;
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;
private:
enum class CommunicationStep {
START_CONVERSION,
READ_CONVERSIONS
};
enum class InternalState {
SETUP,
CONFIGURED
};
SUS::SusDataset dataset;
static const uint8_t MAX_CMD_LEN = SUS::READ_SIZE;
uint8_t cmdBuffer[MAX_CMD_LEN];
InternalState internalState = InternalState::SETUP;
CommunicationStep communicationStep = CommunicationStep::START_CONVERSION;
};
#endif /* MISSION_DEVICES_SUSHANDLER_H_ */

View File

@ -10,11 +10,8 @@ namespace RAD_SENSOR {
* temperature sensor.
*/
static const DeviceCommandId_t WRITE_SETUP = 0x1;
static const DeviceCommandId_t START_CONVERSION = 0x2;
static const DeviceCommandId_t PERFORM_CONVERSION = 0x2;
static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
static const uint32_t MAX1227_DATA_SET_ID = READ_CONVERSIONS;
/**
* @brief This is the configuration byte which will be written to the setup register after
* power on.
@ -37,12 +34,6 @@ namespace RAD_SENSOR {
*/
static const uint8_t CONVERSION_DEFINITION = 0b10001001;
/**
* Unipolar only required for differential measurement. Unipolar or dipolar determines the
* voltage range.
*/
static const uint8_t UNIPOLAR_SETUP = 0b10000000;
static const uint8_t DUMMY_BYTE = 0xFF;
static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS;

View File

@ -0,0 +1,83 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_
namespace SUS {
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
/**
* This command initiates the ADC conversion for all channels including the internal
* temperature sensor.
*/
static const DeviceCommandId_t WRITE_SETUP = 0x1;
static const DeviceCommandId_t START_CONVERSION = 0x2;
static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
/**
* @brief This is the configuration byte which will be written to the setup register after
* power on.
*
* @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b10, following byte will be written to the
* unipolar register to perform differential conversion
* Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b11, external reference differential (AIN6 is REF-)
* Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing
* Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register
*
*/
static const uint8_t SETUP_DEFINITION = 0b01101110;
/**
* @brief This byte will be written to the unipolar register
*
* @details Setting bits 7 - 5 to will configure channels 0/1, 2/3 and 4/5 as differential
* pairs.
*/
static const uint8_t UNIPOLAR_CONFIG = 0b11100000;
/**
* @brief This value will always be written to the ADC conversion register to specify the
* conversions to perform.
* @details Bit0: 1 - Enables temperature conversion
* Bit2 (SCAN1) and Bit1 (SCAN0): 0b00 (channel conversion from 0 to N)
* Bit6 - Bit3 defines N: 0b0001 (N = 4)
* Bit7: Always 1. Tells the ADC that this is the conversion register.
*/
static const uint8_t CONVERSION_DEFINITION = 0b10100001;
static const uint8_t DUMMY_BYTE = 0xFF;
static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS;
/**
* One temperature value, one differential conversion for channels 0/1, one for channels 2/3 and
* one for channels 3/4
*/
static const uint8_t READ_SIZE = 8;
enum Max1227PoolIds: lp_id_t {
TEMPERATURE_C,
DIFF_SCAN_CHANNEL_0_1,
DIFF_SCAN_CHANNEL_2_3,
DIFF_SCAN_CHANNEL_4_5,
};
class SusDataset: public StaticLocalDataSet<sizeof(float)> {
public:
SusDataset(HasLocalDataPoolIF* owner) :
StaticLocalDataSet(owner, SUS_DATA_SET_ID) {
}
SusDataset(object_id_t objectId) :
StaticLocalDataSet(sid_t(objectId, SUS_DATA_SET_ID)) {
}
lp_var_t<float> temperatureCelcius = lp_var_t<float>(sid.objectId, TEMPERATURE_C, this);
lp_var_t<uint16_t> diffScanChannel0_1 = lp_var_t<uint16_t>(sid.objectId, DIFF_SCAN_CHANNEL_0_1, this);
lp_var_t<uint16_t> diffScanChannel2_3 = lp_var_t<uint16_t>(sid.objectId, DIFF_SCAN_CHANNEL_2_3, this);
lp_var_t<uint16_t> diffScanChannel4_5 = lp_var_t<uint16_t>(sid.objectId, DIFF_SCAN_CHANNEL_4_5, this);
};
}
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ */