rad sensor change wip

This commit is contained in:
Jakob Meier 2021-05-03 11:59:33 +02:00
parent b708028c61
commit 8d2993f88d
14 changed files with 563 additions and 92 deletions

View File

@ -26,11 +26,13 @@
#include <mission/devices/GyroL3GD20Handler.h>
#include <mission/devices/PlocHandler.h>
#include <mission/devices/RadiationSensorHandler.h>
#include <mission/devices/SusHandler.h>
#include <mission/devices/devicedefinitions/GomspaceDefinitions.h>
#include <mission/devices/devicedefinitions/SyrlinksDefinitions.h>
#include <mission/devices/devicedefinitions/PlocDefinitions.h>
#include <mission/devices/devicedefinitions/RadSensorDefinitions.h>
#include <mission/devices/devicedefinitions/SusDefinitions.h>
#include <mission/devices/devicedefinitions/Max31865Definitions.h>
#include <mission/utility/TmFunnel.h>
@ -106,14 +108,8 @@ void ObjectFactory::produce(){
#endif
/* Temperature sensors */
Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler(
objects::TMP1075_HANDLER_1, objects::I2C_COM_IF,
i2cCookieTmp1075tcs1);
// tmp1075Handler_1->setStartUpImmediately();
Tmp1075Handler* tmp1075Handler_2 = new Tmp1075Handler(
objects::TMP1075_HANDLER_2, objects::I2C_COM_IF,
i2cCookieTmp1075tcs2);
// tmp1075Handler_2->setStartUpImmediately();
new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1);
new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2);
GpioCookie* heaterGpiosCookie = new GpioCookie;
@ -151,6 +147,98 @@ void ObjectFactory::produce(){
(void) pdu2handler;
(void) acuhandler;
/* Adding gpios for chip select decoding to the gpioComIf */
gpioCallbacks::initSpiCsDecoder(gpioComIF);
GpioCookie* gpioCookieSus = new GpioCookie();
GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 2"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 3"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 4"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 5"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 6"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 7"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 8"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 9"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 10"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 11"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 12"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_12, susgpio);
susgpio = new GpioCallback(std::string("Chip select SUS 13"), gpio::OUT, 1,
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
gpioCookieSus->addGpio(gpioIds::CS_SUS_13, susgpio);
gpioComIF->addGpios(gpioCookieSus);
SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1,
std::string("/dev/spidev2.0"), SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE,
spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"),
SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1);
(void) sus1;
// sus1->setStartUpImmediately();
new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2);
new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3);
new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4);
new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5);
new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6);
new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7);
new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8);
new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9);
new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10);
new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11);
new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12);
new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13);
#if OBSW_ADD_ACS_BOARD == 1
GpioCookie* gpioCookieAcsBoard = new GpioCookie();
GpiodRegular* gpio = nullptr;
@ -287,54 +375,53 @@ void ObjectFactory::produce(){
#if Q7S_ADD_RTD_DEVICES == 1
GpioCookie* rtdGpioCookie = new GpioCookie;
gpioCallbacks::initTcsBoardDecoder(gpioComIF);
GpioCallback* gpioRtdIc3 = new GpioCallback(std::string("Chip select RTD IC3"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC3, gpioRtdIc3);
GpioCallback* gpioRtdIc4 = new GpioCallback(std::string("Chip select RTD IC4"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC4, gpioRtdIc4);
GpioCallback* gpioRtdIc5 = new GpioCallback(std::string("Chip select RTD IC5"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC5, gpioRtdIc5);
GpioCallback* gpioRtdIc6 = new GpioCallback(std::string("Chip select RTD IC6"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC6, gpioRtdIc6);
GpioCallback* gpioRtdIc7 = new GpioCallback(std::string("Chip select RTD IC7"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC7, gpioRtdIc7);
GpioCallback* gpioRtdIc8 = new GpioCallback(std::string("Chip select RTD IC8"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC8, gpioRtdIc8);
GpioCallback* gpioRtdIc9 = new GpioCallback(std::string("Chip select RTD IC9"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC9, gpioRtdIc9);
GpioCallback* gpioRtdIc10 = new GpioCallback(std::string("Chip select RTD IC10"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC10, gpioRtdIc10);
GpioCallback* gpioRtdIc11 = new GpioCallback(std::string("Chip select RTD IC11"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC11, gpioRtdIc11);
GpioCallback* gpioRtdIc12 = new GpioCallback(std::string("Chip select RTD IC12"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC12, gpioRtdIc12);
GpioCallback* gpioRtdIc13 = new GpioCallback(std::string("Chip select RTD IC13"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC13, gpioRtdIc13);
GpioCallback* gpioRtdIc14 = new GpioCallback(std::string("Chip select RTD IC14"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC14, gpioRtdIc14);
GpioCallback* gpioRtdIc15 = new GpioCallback(std::string("Chip select RTD IC15"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC15, gpioRtdIc15);
GpioCallback* gpioRtdIc16 = new GpioCallback(std::string("Chip select RTD IC16"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC16, gpioRtdIc16);
GpioCallback* gpioRtdIc17 = new GpioCallback(std::string("Chip select RTD IC17"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC17, gpioRtdIc17);
GpioCallback* gpioRtdIc18 = new GpioCallback(std::string("Chip select RTD IC18"), gpio::OUT, 1,
&gpioCallbacks::tcsBoardDecoderCallback, gpioComIF);
&gpioCallbacks::spiCsDecoderCallback, gpioComIF);
rtdGpioCookie->addGpio(gpioIds::RTD_IC18, gpioRtdIc18);
gpioComIF->addGpios(rtdGpioCookie);

View File

@ -10,12 +10,12 @@ namespace gpioCallbacks {
GpioIF* gpioComInterface;
void initTcsBoardDecoder(GpioIF* gpioComIF) {
void initSpiCsDecoder(GpioIF* gpioComIF) {
ReturnValue_t result;
if (gpioComIF == nullptr) {
sif::debug << "initTcsBoardDecoder: Invalid gpioComIF" << std::endl;
sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl;
return;
}
@ -48,13 +48,13 @@ void initTcsBoardDecoder(GpioIF* gpioComIF) {
result = gpioComInterface->addGpios(spiMuxGpios);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "initTcsBoardDecoder: Failed to add mux bit gpios to gpioComIF"
sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF"
<< std::endl;
return;
}
}
void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value,
void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value,
void* args) {
if (gpioComInterface == nullptr) {
@ -161,27 +161,83 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va
}
case(gpioIds::CS_SUS_2): {
enableDecoderInterfaceBoardIc21();
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
selectY1();
break;
}
case(gpioIds::CS_SUS_3): {
enableDecoderInterfaceBoardIc21();
selectY2();
break;
}
case(gpioIds::CS_SUS_4): {
enableDecoderInterfaceBoardIc21();
selectY3();
break;
}
case(gpioIds::CS_SUS_5): {
enableDecoderInterfaceBoardIc21();
selectY4();
break;
}
case(gpioIds::CS_SUS_6): {
enableDecoderInterfaceBoardIc21();
selectY5();
break;
}
case(gpioIds::CS_SUS_7): {
enableDecoderInterfaceBoardIc21();
selectY6();
break;
}
case(gpioIds::CS_SUS_8): {
enableDecoderInterfaceBoardIc22();
selectY0();
break;
}
case(gpioIds::CS_SUS_9): {
enableDecoderInterfaceBoardIc22();
selectY1();
break;
}
case(gpioIds::CS_SUS_10): {
enableDecoderInterfaceBoardIc22();
selectY2();
break;
}
case(gpioIds::CS_SUS_11): {
enableDecoderInterfaceBoardIc22();
selectY3();
break;
}
case(gpioIds::CS_SUS_12): {
enableDecoderInterfaceBoardIc22();
selectY4();
break;
}
case(gpioIds::CS_SUS_13): {
enableDecoderInterfaceBoardIc22();
selectY5();
break;
}
default:
sif::debug << "tcsBoardDecoderCallback: Invalid gpioid " << gpioId << std::endl;
sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl;
}
}
else {
sif::debug << "tcsBoardDecoderCallback: Invalid value. Must be 0 or 1" << std::endl;
sif::debug << "spiCsDecoderCallback: Invalid value. Must be 0 or 1" << std::endl;
}
}
void enableDecoderTcsIc1() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
}
void enableDecoderTcsIc2() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
}
void enableDecoderInterfaceBoardIc21() {
@ -191,7 +247,9 @@ void enableDecoderInterfaceBoardIc21() {
}
void enableDecoderInterfaceBoardIc22() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
}
void selectY0() {

View File

@ -9,15 +9,15 @@ namespace gpioCallbacks {
/**
* @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on
* the TCS Board.
* the TCS Board and the interface board.
*/
void initTcsBoardDecoder(GpioIF* gpioComIF);
void initSpiCsDecoder(GpioIF* gpioComIF);
/**
* @brief This function implements the decoding to multiply gpios by using the two decoder
* chips SN74LVC138APWR on the TCS board.
* @brief This function implements the decoding to multiply gpios by using the decoder
* chips SN74LVC138APWR on the TCS board and the interface board.
*/
void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args);
void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args);
/**
* @brief This function sets mux bits 1-3 to a state which will only enable the decoder

View File

@ -30,7 +30,8 @@ debugging. */
#define ACU_DEBUG 0
#define SYRLINKS_DEBUG 0
#define IMQT_DEBUG 0
#define DEBUG_RAD_SENSOR 1
#define DEBUG_RAD_SENSOR 1
#define DEBUG_SUS 1
#include "OBSWVersion.h"

View File

@ -21,6 +21,20 @@ namespace addresses {
RAD_SENSOR = objects::RAD_SENSOR,
SUS_1 = objects::SUS_1,
SUS_2 = objects::SUS_2,
SUS_3 = objects::SUS_3,
SUS_4 = objects::SUS_4,
SUS_5 = objects::SUS_5,
SUS_6 = objects::SUS_6,
SUS_7 = objects::SUS_7,
SUS_8 = objects::SUS_8,
SUS_9 = objects::SUS_9,
SUS_10 = objects::SUS_10,
SUS_11 = objects::SUS_11,
SUS_12 = objects::SUS_12,
SUS_13 = objects::SUS_13,
/* Dummy and Test Addresses */
DUMMY_ECHO = 129,
DUMMY_GPS0 = 130,

View File

@ -44,6 +44,20 @@ namespace gpioIds {
RTD_IC17,
RTD_IC18,
CS_SUS_1,
CS_SUS_2,
CS_SUS_3,
CS_SUS_4,
CS_SUS_5,
CS_SUS_6,
CS_SUS_7,
CS_SUS_8,
CS_SUS_9,
CS_SUS_10,
CS_SUS_11,
CS_SUS_12,
CS_SUS_13,
SPI_MUX_BIT_1,
SPI_MUX_BIT_2,
SPI_MUX_BIT_3,

View File

@ -84,6 +84,20 @@ namespace objects {
RAD_SENSOR = 0x54000050,
SUS_1 = 0x54000051,
SUS_2 = 0x54000052,
SUS_3 = 0x54000053,
SUS_4 = 0x54000054,
SUS_5 = 0x54000055,
SUS_6 = 0x54000056,
SUS_7 = 0x54000057,
SUS_8 = 0x54000058,
SUS_9 = 0x54000059,
SUS_10 = 0x5400005A,
SUS_11 = 0x5400005B,
SUS_12 = 0x5400005C,
SUS_13 = 0x5400005D,
/* 0x54 ('T') for test handlers */
TEST_TASK = 0x54694269,
LIBGPIOD_TEST = 0x54123456,

View File

@ -150,6 +150,13 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence)
thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ);
/* Sun sensor 1 */
thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK;
}

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_ */