This commit is contained in:
parent
66bd5f8fbf
commit
a1409fbcdf
@ -347,17 +347,17 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI
|
||||
gpioComIF->addGpios(gpioCookieSus);
|
||||
|
||||
SpiCookie* spiCookie =
|
||||
new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, q7s::SPI_DEFAULT_DEV, SUS::MAX_CMD_SIZE,
|
||||
spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler0 =
|
||||
new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_0);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler1 =
|
||||
new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_1);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler2 =
|
||||
new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_2);
|
||||
@ -377,33 +377,32 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI
|
||||
SusHandler* susHandler5 =
|
||||
new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_5);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler6 =
|
||||
new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_6);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler7 =
|
||||
new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_7);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler8 =
|
||||
new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_8);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler9 =
|
||||
new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookie, gpioComIF, gpioIds::CS_SUS_9);
|
||||
|
||||
spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_10, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookie,
|
||||
gpioComIF, gpioIds::CS_SUS_10);
|
||||
|
||||
spiCookie =
|
||||
new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string(q7s::SPI_DEFAULT_DEV),
|
||||
spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, q7s::SPI_DEFAULT_DEV,
|
||||
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ);
|
||||
SusHandler* susHandler11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookie,
|
||||
gpioComIF, gpioIds::CS_SUS_11);
|
||||
@ -419,7 +418,7 @@ void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComI
|
||||
static_cast<void>(susHandler9);
|
||||
static_cast<void>(susHandler10);
|
||||
static_cast<void>(susHandler11);
|
||||
#if OBSW_TEST_SUS == 1
|
||||
#if OBSW_TEST_SUS_HANDLER == 1
|
||||
susHandler0->setStartUpImmediately();
|
||||
susHandler1->setStartUpImmediately();
|
||||
susHandler2->setStartUpImmediately();
|
||||
|
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit 32a9e0c7044665f0265c10108c8d62d45c047769
|
||||
Subproject commit 81f5b0c3bf3e602f5cc459dc39bc1e8885c932a7
|
@ -9,39 +9,11 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCoo
|
||||
LinuxLibgpioIF *gpioComIF, gpioId_t chipSelectId)
|
||||
: DeviceHandlerBase(objectId, comIF, comCookie),
|
||||
divider(5),
|
||||
gpioComIF(gpioComIF),
|
||||
chipSelectId(chipSelectId),
|
||||
dataset(this) {
|
||||
if (comCookie == nullptr) {
|
||||
sif::error << "SusHandler: Invalid com cookie" << std::endl;
|
||||
}
|
||||
if (gpioComIF == nullptr) {
|
||||
sif::error << "SusHandler: Invalid GpioComIF" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
SusHandler::~SusHandler() {}
|
||||
|
||||
ReturnValue_t SusHandler::performOperation(uint8_t counter) {
|
||||
if (counter != FIRST_WRITE) {
|
||||
DeviceHandlerBase::performOperation(counter);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
if (mode != MODE_NORMAL) {
|
||||
DeviceHandlerBase::performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
/* If device is in normale mode the communication sequence is initiated here */
|
||||
if (communicationStep == CommunicationStep::IDLE) {
|
||||
communicationStep = CommunicationStep::WRITE_SETUP;
|
||||
}
|
||||
|
||||
DeviceHandlerBase::performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::initialize() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
@ -49,48 +21,57 @@ ReturnValue_t SusHandler::initialize() {
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
auto spiComIF = dynamic_cast<SpiComIF *>(communicationInterface);
|
||||
if (spiComIF == nullptr) {
|
||||
sif::debug << "SusHandler::initialize: Invalid communication interface" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
spiMutex = spiComIF->getMutex();
|
||||
if (spiMutex == nullptr) {
|
||||
sif::debug << "SusHandler::initialize: Failed to get spi mutex" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void SusHandler::doStartUp() {
|
||||
if (comState == ComStates::IDLE) {
|
||||
comState = ComStates::WRITE_SETUP;
|
||||
}
|
||||
if(comState == ComStates::WRITE_SETUP) {
|
||||
if (commandExecuted) {
|
||||
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
setMode(MODE_NORMAL);
|
||||
#else
|
||||
setMode(_MODE_TO_ON);
|
||||
#endif
|
||||
commandExecuted = false;
|
||||
comState = ComStates::START_CONVERSIONS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SusHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t SusHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
if (communicationStep == CommunicationStep::IDLE) {
|
||||
switch (comState) {
|
||||
case (ComStates::IDLE): {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
if (communicationStep == CommunicationStep::WRITE_SETUP) {
|
||||
case (ComStates::WRITE_SETUP): {
|
||||
*id = SUS::WRITE_SETUP;
|
||||
communicationStep = CommunicationStep::START_CONVERSIONS;
|
||||
} else if (communicationStep == CommunicationStep::START_CONVERSIONS) {
|
||||
*id = SUS::START_CONVERSIONS;
|
||||
communicationStep = CommunicationStep::READ_CONVERSIONS;
|
||||
} else if (communicationStep == CommunicationStep::READ_CONVERSIONS) {
|
||||
*id = SUS::READ_CONVERSIONS;
|
||||
communicationStep = CommunicationStep::IDLE;
|
||||
}
|
||||
comState = ComStates::START_CONVERSIONS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (ComStates::START_CONVERSIONS): {
|
||||
*id = SUS::START_CONVERSIONS;
|
||||
comState = ComStates::READ_CONVERSIONS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (ComStates::READ_CONVERSIONS): {
|
||||
*id = SUS::READ_CONVERSIONS;
|
||||
comState = ComStates::START_CONVERSIONS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
}
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
if (comState == ComStates::WRITE_SETUP) {
|
||||
*id = SUS::WRITE_SETUP;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -99,27 +80,6 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (SUS::WRITE_SETUP): {
|
||||
/**
|
||||
* The sun sensor ADC is shutdown when CS is pulled high, so each time requesting a
|
||||
* measurement the setup has to be rewritten. There must also be a little delay between
|
||||
* the transmission of the setup byte and the first conversion. Thus the conversion
|
||||
* will be performed in an extra step.
|
||||
* Because the chip select is driven manually by the SusHandler the SPI bus must be
|
||||
* protected with a mutex here.
|
||||
*/
|
||||
ReturnValue_t result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||
if (result == MutexIF::MUTEX_TIMEOUT) {
|
||||
sif::error << "SusHandler::buildCommandFromCommand: Mutex timeout" << std::endl;
|
||||
return ERROR_LOCK_MUTEX;
|
||||
} else if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "SusHandler::buildCommandFromCommand: Failed to lock spi mutex" << std::endl;
|
||||
return ERROR_LOCK_MUTEX;
|
||||
}
|
||||
|
||||
result = gpioComIF->pullLow(chipSelectId);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
cmdBuffer[0] = SUS::SETUP;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 1;
|
||||
@ -145,8 +105,8 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
|
||||
}
|
||||
|
||||
void SusHandler::fillCommandAndReplyMap() {
|
||||
this->insertInCommandMap(SUS::WRITE_SETUP);
|
||||
this->insertInCommandMap(SUS::START_CONVERSIONS);
|
||||
this->insertInCommandAndReplyMap(SUS::WRITE_SETUP, 1);
|
||||
this->insertInCommandAndReplyMap(SUS::START_CONVERSIONS, 1);
|
||||
this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, SUS::SIZE_READ_CONVERSIONS);
|
||||
}
|
||||
|
||||
@ -159,6 +119,15 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t remainingSiz
|
||||
|
||||
ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case SUS::WRITE_SETUP: {
|
||||
if (mode == _MODE_START_UP) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case SUS::START_CONVERSIONS: {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case SUS::READ_CONVERSIONS: {
|
||||
PoolReadGuard readSet(&dataset);
|
||||
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
|
||||
@ -170,29 +139,16 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8
|
||||
dataset.ain5 = (*(packet + 12) << 8 | *(packet + 13));
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SUS == 1
|
||||
if (divider.checkAndIncrement()) {
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId()
|
||||
<< ", Temperature: " << dataset.temperatureCelcius << " C" << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: " << std::dec
|
||||
<< dataset.ain0 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: " << std::dec
|
||||
<< dataset.ain1 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN2: " << std::dec
|
||||
<< dataset.ain2 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN3: " << std::dec
|
||||
<< dataset.ain3 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN4: " << std::dec
|
||||
<< dataset.ain4 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: " << std::dec
|
||||
<< dataset.ain5 << std::endl;
|
||||
sif::info << "SUS object ID 0x" << std::hex << this->getObjectId() << ":" << std::endl;
|
||||
sif::info << "Temperature: " << dataset.temperatureCelcius << " C" << std::endl;
|
||||
sif::info << "AIN0: " << std::dec << dataset.ain0 << std::endl;
|
||||
sif::info << "AIN1: " << std::dec << dataset.ain1 << std::endl;
|
||||
sif::info << "AIN2: " << std::dec << dataset.ain2 << std::endl;
|
||||
sif::info << "AIN3: " << std::dec << dataset.ain3 << std::endl;
|
||||
sif::info << "AIN4: " << std::dec << dataset.ain4 << std::endl;
|
||||
sif::info << "AIN5: " << std::dec << dataset.ain5 << std::endl;
|
||||
}
|
||||
#endif
|
||||
/** SUS can now be shutdown and thus the SPI bus released again */
|
||||
gpioComIF->pullHigh(chipSelectId);
|
||||
ReturnValue_t result = spiMutex->unlockMutex();
|
||||
if (result != RETURN_OK) {
|
||||
sif::error << "SusHandler::interpretDeviceReply: Failed to unlock spi mutex" << std::endl;
|
||||
return ERROR_UNLOCK_MUTEX;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -203,8 +159,6 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void SusHandler::setNormalDatapoolEntriesInvalid() {}
|
||||
|
||||
uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 1000; }
|
||||
|
||||
ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
|
@ -28,7 +28,7 @@ class SusHandler : public DeviceHandlerBase {
|
||||
LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId);
|
||||
virtual ~SusHandler();
|
||||
|
||||
virtual ReturnValue_t performOperation(uint8_t counter) override;
|
||||
// virtual ReturnValue_t performOperation(uint8_t counter) override;
|
||||
|
||||
virtual ReturnValue_t initialize() override;
|
||||
void setToGoToNormalMode(bool enable);
|
||||
@ -44,7 +44,7 @@ class SusHandler : public DeviceHandlerBase {
|
||||
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;
|
||||
//void setNormalDatapoolEntriesInvalid() override;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
@ -55,17 +55,18 @@ class SusHandler : public DeviceHandlerBase {
|
||||
static const ReturnValue_t ERROR_UNLOCK_MUTEX = MAKE_RETURN_CODE(0xA0);
|
||||
static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1);
|
||||
|
||||
enum class CommunicationStep { IDLE, WRITE_SETUP, START_CONVERSIONS, READ_CONVERSIONS };
|
||||
enum class ComStates { IDLE, WRITE_SETUP, START_CONVERSIONS, READ_CONVERSIONS };
|
||||
|
||||
PeriodicOperationDivider divider;
|
||||
LinuxLibgpioIF* gpioComIF = nullptr;
|
||||
// LinuxLibgpioIF* gpioComIF = nullptr;
|
||||
bool goToNormalModeImmediately = false;
|
||||
gpioId_t chipSelectId = gpio::NO_GPIO;
|
||||
bool commandExecuted = false;
|
||||
// gpioId_t chipSelectId = gpio::NO_GPIO;
|
||||
|
||||
SUS::SusDataset dataset;
|
||||
|
||||
uint8_t cmdBuffer[SUS::MAX_CMD_SIZE];
|
||||
CommunicationStep communicationStep = CommunicationStep::IDLE;
|
||||
ComStates comState = ComStates::IDLE;
|
||||
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
||||
uint32_t timeoutMs = 20;
|
||||
|
@ -78,7 +78,6 @@ debugging. */
|
||||
|
||||
#define OBSW_TEST_LIBGPIOD 0
|
||||
#define OBSW_TEST_RADIATION_SENSOR_HANDLER 0
|
||||
#define OBSW_TEST_SUS 0
|
||||
#define OBSW_TEST_SUS_HANDLER 0
|
||||
#define OBSW_TEST_PLOC_HANDLER 0
|
||||
#define OBSW_TEST_BPX_BATT 0
|
||||
|
@ -1,7 +1 @@
|
||||
/**
|
||||
* \file logicalAddresses.cpp
|
||||
*
|
||||
* \date 06.11.2019
|
||||
*/
|
||||
|
||||
#include "addresses.h"
|
||||
|
Loading…
Reference in New Issue
Block a user