v1.10.0 #220

Merged
meierj merged 592 commits from develop into main 2022-04-22 07:42:20 +02:00
4 changed files with 125 additions and 59 deletions
Showing only changes of commit 938c361097 - Show all commits

View File

@ -1,20 +1,17 @@
#include "SusHandler.h"
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/globalfunctions/arrayprinter.h>
#include <fsfw_hal/linux/spi/SpiComIF.h>
#include "OBSWConfig.h"
SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie,
LinuxLibgpioIF *gpioComIF, gpioId_t chipSelectId)
: DeviceHandlerBase(objectId, comIF, comCookie),
divider(5),
dataset(this) {
}
: DeviceHandlerBase(objectId, comIF, comCookie), divider(5), dataset(this) {}
SusHandler::~SusHandler() {}
ReturnValue_t SusHandler::initialize() {
ReturnValue_t result = RETURN_OK;
result = DeviceHandlerBase::initialize();
@ -27,8 +24,9 @@ ReturnValue_t SusHandler::initialize() {
void SusHandler::doStartUp() {
if (comState == ComStates::IDLE) {
comState = ComStates::WRITE_SETUP;
commandExecuted = false;
}
if(comState == ComStates::WRITE_SETUP) {
if (comState == ComStates::WRITE_SETUP) {
if (commandExecuted) {
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
setMode(MODE_NORMAL);
@ -36,7 +34,11 @@ void SusHandler::doStartUp() {
setMode(_MODE_TO_ON);
#endif
commandExecuted = false;
comState = ComStates::START_CONVERSIONS;
if (clkMode == Modes::INT_CLOCKED) {
comState = ComStates::START_INT_CLOCKED_CONVERSIONS;
} else {
comState = ComStates::EXT_CLOCKED_CONVERSIONS;
}
}
}
}
@ -50,17 +52,20 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
}
case (ComStates::WRITE_SETUP): {
*id = SUS::WRITE_SETUP;
comState = ComStates::START_CONVERSIONS;
return buildCommandFromCommand(*id, nullptr, 0);
}
case (ComStates::START_CONVERSIONS): {
*id = SUS::START_CONVERSIONS;
comState = ComStates::READ_CONVERSIONS;
case (ComStates::EXT_CLOCKED_CONVERSIONS): {
*id = SUS::READ_EXT_TIMED_CONVERSIONS;
return buildCommandFromCommand(*id, nullptr, 0);
}
case (ComStates::READ_CONVERSIONS): {
*id = SUS::READ_CONVERSIONS;
comState = ComStates::START_CONVERSIONS;
case (ComStates::START_INT_CLOCKED_CONVERSIONS): {
*id = SUS::START_INT_TIMED_CONVERSIONS;
comState = ComStates::READ_INT_CLOCKED_CONVERSIONS;
return buildCommandFromCommand(*id, nullptr, 0);
}
case (ComStates::READ_INT_CLOCKED_CONVERSIONS): {
*id = SUS::READ_INT_TIMED_CONVERSIONS;
comState = ComStates::START_INT_CLOCKED_CONVERSIONS;
return buildCommandFromCommand(*id, nullptr, 0);
}
}
@ -80,22 +85,37 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
size_t commandDataLen) {
switch (deviceCommand) {
case (SUS::WRITE_SETUP): {
cmdBuffer[0] = SUS::SETUP;
if (clkMode == Modes::INT_CLOCKED) {
cmdBuffer[0] = SUS::SETUP_INT_CLOKED;
} else {
cmdBuffer[0] = SUS::SETUP_EXT_CLOCKED;
}
rawPacket = cmdBuffer;
rawPacketLen = 1;
return RETURN_OK;
}
case (SUS::START_CONVERSIONS): {
case (SUS::START_INT_TIMED_CONVERSIONS): {
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
cmdBuffer[0] = SUS::CONVERSION;
rawPacket = cmdBuffer;
rawPacketLen = 2;
return RETURN_OK;
}
case (SUS::READ_CONVERSIONS): {
case (SUS::READ_INT_TIMED_CONVERSIONS): {
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
rawPacket = cmdBuffer;
rawPacketLen = SUS::SIZE_READ_CONVERSIONS;
rawPacketLen = SUS::SIZE_READ_INT_CONVERSIONS;
return RETURN_OK;
}
case (SUS::READ_EXT_TIMED_CONVERSIONS): {
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
rawPacket = cmdBuffer;
for (uint8_t idx = 0; idx < 6; idx++) {
cmdBuffer[idx * 2] = buildConvByte(ScanModes::N_ONCE, 0, false);
cmdBuffer[idx * 2 + 1] = 0;
}
rawPacketLen = SUS::SIZE_READ_EXT_CONVERSIONS;
return RETURN_OK;
}
default:
@ -106,8 +126,11 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman
void SusHandler::fillCommandAndReplyMap() {
this->insertInCommandAndReplyMap(SUS::WRITE_SETUP, 1);
this->insertInCommandAndReplyMap(SUS::START_CONVERSIONS, 1);
this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, SUS::SIZE_READ_CONVERSIONS);
this->insertInCommandAndReplyMap(SUS::START_INT_TIMED_CONVERSIONS, 1);
this->insertInCommandAndReplyMap(SUS::READ_INT_TIMED_CONVERSIONS, 1, &dataset,
SUS::SIZE_READ_INT_CONVERSIONS);
this->insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_CONVERSIONS, 1, &dataset,
SUS::SIZE_READ_EXT_CONVERSIONS);
}
ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t remainingSize,
@ -119,16 +142,16 @@ 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: {
case SUS::WRITE_SETUP: {
if (mode == _MODE_START_UP) {
commandExecuted = true;
}
return HasReturnvaluesIF::RETURN_OK;
}
case SUS::START_INT_TIMED_CONVERSIONS: {
return HasReturnvaluesIF::RETURN_OK;
}
case SUS::READ_INT_TIMED_CONVERSIONS: {
PoolReadGuard readSet(&dataset);
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
dataset.ain0 = (*(packet + 2) << 8 | *(packet + 3));
@ -137,18 +160,18 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8
dataset.ain3 = (*(packet + 8) << 8 | *(packet + 9));
dataset.ain4 = (*(packet + 10) << 8 | *(packet + 11));
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() << ":" << 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
printDataset();
break;
}
case (SUS::READ_EXT_TIMED_CONVERSIONS): {
PoolReadGuard readSet(&dataset);
dataset.ain0 = (packet[1] << 8) | packet[2];
dataset.ain1 = (packet[3] << 8) | packet[4];
dataset.ain2 = (packet[5] << 8) | packet[6];
dataset.ain3 = (packet[7] << 8) | packet[8];
dataset.ain4 = (packet[9] << 8) | packet[10];
dataset.ain5 = (packet[11] << 8) | packet[12];
printDataset();
break;
}
default: {
@ -159,7 +182,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8
return HasReturnvaluesIF::RETURN_OK;
}
uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 1000; }
uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 2000; }
ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
@ -174,3 +197,22 @@ ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool &localData
}
void SusHandler::setToGoToNormalMode(bool enable) { this->goToNormalModeImmediately = enable; }
uint8_t SusHandler::buildConvByte(ScanModes scanMode, uint8_t channel, bool readTemp) {
return (1 << 7) | (channel << 3) | (scanMode << 1) | readTemp;
}
void SusHandler::printDataset() {
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SUS == 1
if (divider.checkAndIncrement()) {
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
}

View File

@ -22,6 +22,15 @@
*/
class SusHandler : public DeviceHandlerBase {
public:
enum Modes { INT_CLOCKED, EXT_CLOCKED };
enum ScanModes : uint8_t {
CHANNELS_0_TO_N = 0b00,
CHANNEL_N_TO_HIGHEST = 0b01,
N_REPEATEDLY = 0b10,
N_ONCE = 0b11
};
static const uint8_t FIRST_WRITE = 7;
SusHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
@ -44,32 +53,42 @@ 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;
uint8_t buildConvByte(ScanModes scanMode, uint8_t channel, bool readTemp);
private:
static const uint8_t INTERFACE_ID = CLASS_ID::SUS_HANDLER;
static const ReturnValue_t ERROR_UNLOCK_MUTEX = MAKE_RETURN_CODE(0xA0);
static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1);
enum class ComStates { IDLE, WRITE_SETUP, START_CONVERSIONS, READ_CONVERSIONS };
enum class ComStates {
IDLE,
WRITE_SETUP,
EXT_CLOCKED_CONVERSIONS,
START_INT_CLOCKED_CONVERSIONS,
READ_INT_CLOCKED_CONVERSIONS
};
PeriodicOperationDivider divider;
// LinuxLibgpioIF* gpioComIF = nullptr;
// gpioId_t chipSelectId = gpio::NO_GPIO;
bool goToNormalModeImmediately = false;
bool commandExecuted = false;
// gpioId_t chipSelectId = gpio::NO_GPIO;
SUS::SusDataset dataset;
Modes clkMode = Modes::INT_CLOCKED;
uint8_t cmdBuffer[SUS::MAX_CMD_SIZE];
ComStates comState = ComStates::IDLE;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
uint32_t timeoutMs = 20;
void printDataset();
MutexIF* spiMutex = nullptr;
};

View File

@ -21,12 +21,14 @@ static const DeviceCommandId_t WRITE_SETUP = 0x1;
* This command initiates the ADC conversion for all channels including the internal
* temperature sensor.
*/
static const DeviceCommandId_t START_CONVERSIONS = 0x2;
static const DeviceCommandId_t START_INT_TIMED_CONVERSIONS = 0x2;
/**
* This command reads the internal fifo which holds the temperature and the channel
* conversions.
*/
static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
static constexpr DeviceCommandId_t READ_INT_TIMED_CONVERSIONS = 0x3;
static constexpr DeviceCommandId_t READ_EXT_TIMED_CONVERSIONS = 0x4;
/**
* @brief This is the configuration byte which will be written to the setup register after
@ -39,7 +41,8 @@ static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
* written to the setup register
*
*/
static const uint8_t SETUP = 0b01101000;
static constexpr uint8_t SETUP_INT_CLOKED = 0b01101000;
static constexpr uint8_t SETUP_EXT_CLOCKED = 0b01111000;
/**
* @brief This values will always be written to the ADC conversion register to specify the
@ -51,12 +54,14 @@ static const uint8_t SETUP = 0b01101000;
*/
static const uint8_t CONVERSION = 0b10101001;
static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS;
static const uint8_t SUS_DATA_SET_ID = READ_EXT_TIMED_CONVERSIONS;
/** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */
static const uint8_t SIZE_READ_CONVERSIONS = 14;
static const uint8_t SIZE_READ_INT_CONVERSIONS = 14;
// 6 * conv byte, 6 * 0 and one trailing zero
static constexpr uint8_t SIZE_READ_EXT_CONVERSIONS = 13;
static const uint8_t MAX_CMD_SIZE = SIZE_READ_CONVERSIONS;
static const uint8_t MAX_CMD_SIZE = 16;
static const uint8_t POOL_ENTRIES = 7;

View File

@ -177,19 +177,19 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
if (addSus0) {
/* Write setup */
thisSequence->addSlot(objects::SUS_0, length * 0.933, DeviceHandlerIF::PERFORM_OPERATION);
//thisSequence->addSlot(objects::SUS_0, length * 0.933, SusHandler::FIRST_WRITE);
// thisSequence->addSlot(objects::SUS_0, length * 0.933, SusHandler::FIRST_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.933, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.933, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.933, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::SUS_0, length * 0.933, DeviceHandlerIF::GET_READ);
/* Start ADC conversions */
//thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::PERFORM_OPERATION);
// thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::SUS_0, length * 0.934, DeviceHandlerIF::GET_READ);
/* Read ADC conversions */
//thisSequence->addSlot(objects::SUS_0, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION);
// thisSequence->addSlot(objects::SUS_0, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::SUS_0, length * 0.935, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.935, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_0, length * 0.935, DeviceHandlerIF::SEND_READ);
@ -341,7 +341,7 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
if (addSus8) {
/* Write setup */
thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::PERFORM_OPERATION);
//thisSequence->addSlot(objects::SUS_8, length * 0.921, SusHandler::FIRST_WRITE);
// thisSequence->addSlot(objects::SUS_8, length * 0.921, SusHandler::FIRST_WRITE);
thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::SEND_READ);
@ -363,19 +363,19 @@ ReturnValue_t pst::pstSpi(FixedTimeslotTaskIF *thisSequence) {
if (addSus9) {
/* Write setup */
thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::PERFORM_OPERATION);
//thisSequence->addSlot(objects::SUS_9, length * 0.924, SusHandler::FIRST_WRITE);
// thisSequence->addSlot(objects::SUS_9, length * 0.924, SusHandler::FIRST_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_READ);
/* Start ADC conversions */
//thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION);
// thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::GET_READ);
/* Read ADC conversions */
//thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION);
// thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::SEND_READ);