moved some more code to mission folder
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
target_sources(${OBSW_NAME} PRIVATE
|
||||
SolarArrayDeploymentHandler.cpp
|
||||
SusHandler.cpp
|
||||
PayloadPcduHandler.cpp
|
||||
)
|
||||
|
||||
if(EIVE_BUILD_GPSD_GPS_HANDLER)
|
||||
|
@ -1,445 +0,0 @@
|
||||
#include "PayloadPcduHandler.h"
|
||||
|
||||
#include <fsfw/src/fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfw_hal/linux/UnixFileGuard.h>
|
||||
#include <fsfw_hal/linux/spi/SpiComIF.h>
|
||||
#include <fsfw_hal/linux/spi/SpiCookie.h>
|
||||
#include <fsfw_hal/linux/utility.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "devices/gpioIds.h"
|
||||
|
||||
PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie,
|
||||
GpioIF* gpioIF, bool periodicPrintout)
|
||||
: DeviceHandlerBase(objectId, comIF, cookie),
|
||||
adcSet(this),
|
||||
periodicPrintout(periodicPrintout),
|
||||
gpioIF(gpioIF) {}
|
||||
|
||||
void PayloadPcduHandler::doStartUp() {
|
||||
if ((state != States::PCDU_OFF) and (state != States::ON_TRANS_SSR)) {
|
||||
// Config error
|
||||
sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl;
|
||||
}
|
||||
if (state == States::PCDU_OFF) {
|
||||
// Switch on relays here
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
|
||||
state = States::ON_TRANS_SSR;
|
||||
transitionOk = true;
|
||||
}
|
||||
if (state == States::ON_TRANS_SSR) {
|
||||
// If necessary, check whether a certain amount of time has elapsed
|
||||
if (transitionOk) {
|
||||
transitionOk = false;
|
||||
// We are now in ON mode
|
||||
startTransition(MODE_NORMAL, 0);
|
||||
adcState = AdcStates::BOOT_DELAY;
|
||||
// The ADC can now be read. If the values are not close to zero, we should not allow
|
||||
// transition
|
||||
monMode = MonitoringMode::CLOSE_TO_ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||
if (mode == _MODE_TO_NORMAL) {
|
||||
stateMachineToNormal();
|
||||
}
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::doShutDown() {}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||
switch (adcState) {
|
||||
case (AdcStates::SEND_SETUP): {
|
||||
*id = plpcdu::SETUP_CMD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (AdcStates::NORMAL): {
|
||||
*id = plpcdu::READ_WITH_TEMP_EXT;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
||||
if (adcState == AdcStates::SEND_SETUP) {
|
||||
*id = plpcdu::SETUP_CMD;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(plpcdu::READ_CMD, 2, &adcSet);
|
||||
insertInCommandAndReplyMap(plpcdu::READ_TEMP_EXT, 1, &adcSet);
|
||||
insertInCommandAndReplyMap(plpcdu::READ_WITH_TEMP_EXT, 1, &adcSet);
|
||||
insertInCommandAndReplyMap(plpcdu::SETUP_CMD, 1);
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case (plpcdu::SETUP_CMD): {
|
||||
cmdBuf[0] = plpcdu::SETUP_BYTE;
|
||||
rawPacket = cmdBuf.data();
|
||||
rawPacketLen = 1;
|
||||
break;
|
||||
}
|
||||
case (plpcdu::READ_CMD): {
|
||||
max1227::prepareExternallyClockedRead0ToN(cmdBuf.data(), plpcdu::CHANNEL_N, rawPacketLen);
|
||||
rawPacket = cmdBuf.data();
|
||||
break;
|
||||
}
|
||||
case (plpcdu::READ_TEMP_EXT): {
|
||||
max1227::prepareExternallyClockedTemperatureRead(cmdBuf.data(), rawPacketLen);
|
||||
rawPacket = cmdBuf.data();
|
||||
break;
|
||||
}
|
||||
case (plpcdu::READ_WITH_TEMP_EXT): {
|
||||
size_t sz = 0;
|
||||
max1227::prepareExternallyClockedRead0ToN(cmdBuf.data(), plpcdu::CHANNEL_N, sz);
|
||||
max1227::prepareExternallyClockedTemperatureRead(cmdBuf.data() + sz, sz);
|
||||
rawPacketLen = sz;
|
||||
rawPacket = cmdBuf.data();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||
// SPI is full duplex
|
||||
*foundId = getPendingCommand();
|
||||
*foundLen = remainingSize;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t* packet) {
|
||||
using namespace plpcdu;
|
||||
switch (id) {
|
||||
case (SETUP_CMD): {
|
||||
if (mode == _MODE_TO_NORMAL) {
|
||||
adcCmdExecuted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (READ_TEMP_EXT): {
|
||||
uint8_t tempStartIdx = TEMP_REPLY_SIZE - 2;
|
||||
adcSet.tempC.value =
|
||||
max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 1]);
|
||||
break;
|
||||
}
|
||||
case (READ_CMD): {
|
||||
PoolReadGuard pg(&adcSet);
|
||||
if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return pg.getReadResult();
|
||||
}
|
||||
handleExtConvRead(packet);
|
||||
handlePrintout();
|
||||
break;
|
||||
}
|
||||
case (READ_WITH_TEMP_EXT): {
|
||||
PoolReadGuard pg(&adcSet);
|
||||
if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return pg.getReadResult();
|
||||
}
|
||||
handleExtConvRead(packet);
|
||||
uint8_t tempStartIdx = ADC_REPLY_SIZE + TEMP_REPLY_SIZE - 2;
|
||||
adcSet.tempC.value =
|
||||
max1227::getTemperature(packet[tempStartIdx] << 8 | packet[tempStartIdx + 1]);
|
||||
handlePrintout();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t PayloadPcduHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
||||
// 20 minutes transition delay is allowed
|
||||
return 20 * 60 * 60;
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
localDataPoolMap.emplace(plpcdu::PlPcduPoolIds::CHANNEL_VEC, &channelValues);
|
||||
localDataPoolMap.emplace(plpcdu::PlPcduPoolIds::TEMP, &tempC);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::setToGoToNormalModeImmediately(bool enable) {
|
||||
this->goToNormalMode = enable;
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::handleExtConvRead(const uint8_t* bufStart) {
|
||||
for (uint8_t idx = 0; idx < 12; idx++) {
|
||||
adcSet.channels[idx] = bufStart[idx * 2 + 1] << 8 | bufStart[idx * 2 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::handlePrintout() {
|
||||
if (periodicPrintout) {
|
||||
if (opDivider.checkAndIncrement()) {
|
||||
sif::info << "PL PCDU ADC hex [" << std::setfill('0') << std::hex;
|
||||
for (uint8_t idx = 0; idx < 12; idx++) {
|
||||
sif::info << std::setw(3) << adcSet.channels[idx];
|
||||
if (idx < 11) {
|
||||
sif::info << ",";
|
||||
}
|
||||
}
|
||||
sif::info << "] | T[C] " << std::dec << adcSet.tempC.value << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::enablePeriodicPrintout(bool enable, uint8_t divider) {
|
||||
this->periodicPrintout = enable;
|
||||
opDivider.setDivider(divider);
|
||||
}
|
||||
|
||||
void PayloadPcduHandler::stateMachineToNormal() {
|
||||
if (adcState == AdcStates::BOOT_DELAY) {
|
||||
if (adcCountdown.hasTimedOut()) {
|
||||
adcState = AdcStates::SEND_SETUP;
|
||||
adcCmdExecuted = false;
|
||||
}
|
||||
}
|
||||
if (adcState == AdcStates::SEND_SETUP) {
|
||||
if (adcCmdExecuted) {
|
||||
adcState = AdcStates::NORMAL;
|
||||
setMode(MODE_NORMAL, plpcdu::NORMAL_ADC_ONLY);
|
||||
adcCmdExecuted = false;
|
||||
}
|
||||
}
|
||||
if (submode == plpcdu::NORMAL_ALL_ON) {
|
||||
if (state == States::ON_TRANS_ADC_CLOSE_ZERO) {
|
||||
if (not commandExecuted) {
|
||||
countdown.resetTimer();
|
||||
commandExecuted = true;
|
||||
}
|
||||
// ADC values are ok, 5 seconds have elapsed
|
||||
if (transitionOk and countdown.hasTimedOut()) {
|
||||
state = States::ON_TRANS_DRO;
|
||||
// Now start monitoring for negative voltages instead
|
||||
monMode = MonitoringMode::NEGATIVE;
|
||||
countdown.resetTimer();
|
||||
commandExecuted = false;
|
||||
transitionOk = false;
|
||||
}
|
||||
}
|
||||
if (state == States::ON_TRANS_DRO) {
|
||||
if (not commandExecuted) {
|
||||
// Switch on DRO and start monitoring for negative voltagea
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO);
|
||||
commandExecuted = true;
|
||||
}
|
||||
// ADC values are ok, 5 seconds have elapsed
|
||||
if (transitionOk and countdown.hasTimedOut()) {
|
||||
state = States::ON_TRANS_X8;
|
||||
countdown.resetTimer();
|
||||
commandExecuted = false;
|
||||
transitionOk = false;
|
||||
}
|
||||
}
|
||||
if (state == States::ON_TRANS_X8) {
|
||||
if (not commandExecuted) {
|
||||
// Switch on X8
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8);
|
||||
commandExecuted = true;
|
||||
}
|
||||
// ADC values are ok, 5 seconds have elapsed
|
||||
if (transitionOk and countdown.hasTimedOut()) {
|
||||
state = States::ON_TRANS_TX;
|
||||
countdown.resetTimer();
|
||||
commandExecuted = false;
|
||||
transitionOk = false;
|
||||
}
|
||||
}
|
||||
if (state == States::ON_TRANS_TX) {
|
||||
if (not commandExecuted) {
|
||||
// Switch on TX
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX);
|
||||
commandExecuted = true;
|
||||
}
|
||||
// ADC values are ok, 5 seconds have elapsed
|
||||
if (transitionOk and countdown.hasTimedOut()) {
|
||||
state = States::ON_TRANS_MPA;
|
||||
countdown.resetTimer();
|
||||
commandExecuted = false;
|
||||
transitionOk = false;
|
||||
}
|
||||
}
|
||||
if (state == States::ON_TRANS_MPA) {
|
||||
if (not commandExecuted) {
|
||||
// Switch on MPA
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA);
|
||||
commandExecuted = true;
|
||||
}
|
||||
// ADC values are ok, 5 seconds have elapsed
|
||||
if (transitionOk and countdown.hasTimedOut()) {
|
||||
state = States::ON_TRANS_HPA;
|
||||
countdown.resetTimer();
|
||||
commandExecuted = false;
|
||||
transitionOk = false;
|
||||
}
|
||||
}
|
||||
if (state == States::ON_TRANS_HPA) {
|
||||
if (not commandExecuted) {
|
||||
// Switch on HPA
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA);
|
||||
commandExecuted = true;
|
||||
}
|
||||
// ADC values are ok, 5 seconds have elapsed
|
||||
if (transitionOk and countdown.hasTimedOut()) {
|
||||
state = States::PCDU_ON;
|
||||
setMode(MODE_NORMAL, plpcdu::NORMAL_ALL_ON);
|
||||
countdown.resetTimer();
|
||||
commandExecuted = false;
|
||||
transitionOk = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::extConvAsTwoCallback(SpiComIF* comIf, SpiCookie* cookie,
|
||||
const uint8_t* sendData, size_t sendLen,
|
||||
void* args) {
|
||||
auto handler = reinterpret_cast<PayloadPcduHandler*>(args);
|
||||
if (handler == nullptr) {
|
||||
sif::error << "GyroADIS16507Handler::spiSendCallback: Passed handler pointer is invalid!"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
DeviceCommandId_t currentCommand = handler->getPendingCommand();
|
||||
switch (currentCommand) {
|
||||
case (plpcdu::READ_WITH_TEMP_EXT): {
|
||||
return transferAsTwo(comIf, cookie, sendData, sendLen, false);
|
||||
}
|
||||
case (plpcdu::READ_TEMP_EXT): {
|
||||
return transferAsTwo(comIf, cookie, sendData, sendLen, true);
|
||||
}
|
||||
default: {
|
||||
return comIf->performRegularSendOperation(cookie, sendData, sendLen);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cookie,
|
||||
const uint8_t* sendData, size_t sendLen,
|
||||
bool tempOnly) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
int retval = 0;
|
||||
// Prepare transfer
|
||||
int fileDescriptor = 0;
|
||||
std::string device = cookie->getSpiDevice();
|
||||
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
|
||||
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
return SpiComIF::OPENING_FILE_FAILED;
|
||||
}
|
||||
spi::SpiModes spiMode = spi::SpiModes::MODE_0;
|
||||
uint32_t spiSpeed = 0;
|
||||
cookie->getSpiParameters(spiMode, spiSpeed, nullptr);
|
||||
comIf->setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed);
|
||||
cookie->assignWriteBuffer(sendData);
|
||||
size_t transferLen = plpcdu::TEMP_REPLY_SIZE;
|
||||
if (not tempOnly) {
|
||||
transferLen += plpcdu::ADC_REPLY_SIZE;
|
||||
}
|
||||
cookie->setTransferSize(transferLen);
|
||||
|
||||
gpioId_t gpioId = cookie->getChipSelectPin();
|
||||
GpioIF* gpioIF = comIf->getGpioInterface();
|
||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
|
||||
uint32_t timeoutMs = 0;
|
||||
MutexIF* mutex = comIf->getMutex(&timeoutType, &timeoutMs);
|
||||
if (mutex == nullptr or gpioIF == nullptr) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::warning << "GyroADIS16507Handler::spiSendCallback: "
|
||||
"Mutex or GPIO interface invalid"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (gpioId != gpio::NO_GPIO) {
|
||||
result = mutex->lockMutex(timeoutType, timeoutMs);
|
||||
if (result != RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
}
|
||||
spi_ioc_transfer* transferStruct = cookie->getTransferStructHandle();
|
||||
uint64_t origTx = transferStruct->tx_buf;
|
||||
uint64_t origRx = transferStruct->rx_buf;
|
||||
if (tempOnly) {
|
||||
transferLen = 1;
|
||||
} else {
|
||||
transferLen = plpcdu::ADC_REPLY_SIZE + 1;
|
||||
}
|
||||
transferStruct->len = transferLen;
|
||||
// Pull SPI CS low. For now, no support for active high given
|
||||
if (gpioId != gpio::NO_GPIO) {
|
||||
gpioIF->pullLow(gpioId);
|
||||
}
|
||||
|
||||
// Execute transfer
|
||||
// Initiate a full duplex SPI transfer.
|
||||
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), cookie->getTransferStructHandle());
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
||||
result = SpiComIF::FULL_DUPLEX_TRANSFER_FAILED;
|
||||
}
|
||||
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||
comIf->performSpiWiretapping(cookie);
|
||||
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
||||
|
||||
if (gpioId != gpio::NO_GPIO) {
|
||||
gpioIF->pullHigh(gpioId);
|
||||
}
|
||||
|
||||
transferStruct->tx_buf += transferLen;
|
||||
transferStruct->rx_buf += transferLen;
|
||||
transferStruct->len = plpcdu::TEMP_REPLY_SIZE - 1;
|
||||
if (gpioId != gpio::NO_GPIO) {
|
||||
gpioIF->pullLow(gpioId);
|
||||
}
|
||||
|
||||
// Execute transfer
|
||||
// Initiate a full duplex SPI transfer.
|
||||
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), cookie->getTransferStructHandle());
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
||||
result = SpiComIF::FULL_DUPLEX_TRANSFER_FAILED;
|
||||
}
|
||||
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||
comIf->performSpiWiretapping(cookie);
|
||||
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
||||
|
||||
if (gpioId != gpio::NO_GPIO) {
|
||||
gpioIF->pullHigh(gpioId);
|
||||
}
|
||||
|
||||
transferStruct->tx_buf = origTx;
|
||||
transferStruct->rx_buf = origRx;
|
||||
if (gpioId != gpio::NO_GPIO) {
|
||||
mutex->unlockMutex();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
#ifndef LINUX_DEVICES_PLPCDUHANDLER_H_
|
||||
#define LINUX_DEVICES_PLPCDUHANDLER_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
||||
#include <fsfw/timemanager/Countdown.h>
|
||||
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
#include "mission/devices/devicedefinitions/payloadPcduDefinitions.h"
|
||||
|
||||
class SpiComIF;
|
||||
class SpiCookie;
|
||||
|
||||
/**
|
||||
* @brief Device handler for the EIVE Payload PCDU
|
||||
* @details
|
||||
* Documentation:
|
||||
* https://egit.irs.uni-stuttgart.de/eive/eive_dokumente/src/branch/master/400_Raumsegment/412_PayloaPCDUDocumentation/release/EIVE-D-421-001_PLPCDU_Documentation.pdf
|
||||
*
|
||||
* Important components:
|
||||
* - SSR - Solid State Relay: Decouples voltages from battery
|
||||
* - DRO - Dielectric Resonsant Oscillator: Generates modulation signal
|
||||
* - X8: Frequency X8 Multiplicator
|
||||
* - TX: Transmitter/Sender module. Modulates data onto carrier signal
|
||||
* - MPA - Medium Power Amplifier
|
||||
* - HPA - High Power Amplifier
|
||||
*/
|
||||
class PayloadPcduHandler : public DeviceHandlerBase {
|
||||
public:
|
||||
PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF,
|
||||
bool periodicPrintout);
|
||||
|
||||
void setToGoToNormalModeImmediately(bool enable);
|
||||
void enablePeriodicPrintout(bool enable, uint8_t divider);
|
||||
|
||||
static ReturnValue_t extConvAsTwoCallback(SpiComIF* comIf, SpiCookie* cookie,
|
||||
const uint8_t* sendData, size_t sendLen, void* args);
|
||||
static ReturnValue_t transferAsTwo(SpiComIF* comIf, SpiCookie* cookie, const uint8_t* sendData,
|
||||
size_t sendLen, bool tempOnly);
|
||||
|
||||
private:
|
||||
enum class States {
|
||||
PCDU_OFF,
|
||||
// Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on
|
||||
// the ADC
|
||||
ON_TRANS_SSR,
|
||||
ON_TRANS_ADC_CLOSE_ZERO,
|
||||
// Enable Dielectric Resonant Oscillator and start monitoring voltages as
|
||||
// soon as DRO voltage reaches 6V
|
||||
ON_TRANS_DRO,
|
||||
// Switch on X8 compoennt and monitor voltages for 5 seconds
|
||||
ON_TRANS_X8,
|
||||
// Switch on TX component and monitor voltages for 5 seconds
|
||||
ON_TRANS_TX,
|
||||
// Switch on MPA component and monitor voltages for 5 seconds
|
||||
ON_TRANS_MPA,
|
||||
// Switch on HPA component and monitor voltages for 5 seconds
|
||||
ON_TRANS_HPA,
|
||||
// All components of the experiment are on
|
||||
PCDU_ON,
|
||||
} state = States::PCDU_OFF;
|
||||
|
||||
enum class AdcMode { EXT_CONV, INT_CONV } adcMode = AdcMode::INT_CONV;
|
||||
|
||||
enum class MonitoringMode { NONE, CLOSE_TO_ZERO, NEGATIVE } monMode = MonitoringMode::NONE;
|
||||
|
||||
enum class AdcStates { OFF, BOOT_DELAY, SEND_SETUP, NORMAL } adcState = AdcStates::OFF;
|
||||
|
||||
bool goToNormalMode = false;
|
||||
plpcdu::PlPcduAdcSet adcSet;
|
||||
std::array<uint8_t, plpcdu::MAX_ADC_REPLY_SIZE> cmdBuf = {};
|
||||
// This variable is tied to DRO +6 V voltage. Voltages, currents are monitored and the experiment
|
||||
// is shut down immediately if there is a negative voltage.
|
||||
bool transitionOk = false;
|
||||
bool commandExecuted = false;
|
||||
bool adcCmdExecuted = false;
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider opDivider = PeriodicOperationDivider(5);
|
||||
uint8_t tempReadDivisor = 1;
|
||||
Countdown countdown = Countdown(5000);
|
||||
Countdown adcCountdown = Countdown(50);
|
||||
GpioIF* gpioIF;
|
||||
|
||||
PoolEntry<uint16_t> channelValues = PoolEntry<uint16_t>({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
||||
PoolEntry<float> tempC = PoolEntry<float>({0.0});
|
||||
|
||||
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
||||
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;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
void handleExtConvRead(const uint8_t* bufStart);
|
||||
void handlePrintout();
|
||||
void stateMachineToNormal();
|
||||
};
|
||||
|
||||
#endif /* LINUX_DEVICES_PLPCDUHANDLER_H_ */
|
@ -1,210 +0,0 @@
|
||||
#include "SolarArrayDeploymentHandler.h"
|
||||
|
||||
#include <devices/gpioIds.h>
|
||||
#include <devices/powerSwitcherList.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include <fsfw_hal/common/gpio/GpioCookie.h>
|
||||
|
||||
SolarArrayDeploymentHandler::SolarArrayDeploymentHandler(object_id_t setObjectId_,
|
||||
object_id_t gpioDriverId_,
|
||||
CookieIF* gpioCookie_,
|
||||
object_id_t mainLineSwitcherObjectId_,
|
||||
uint8_t mainLineSwitch_, gpioId_t deplSA1,
|
||||
gpioId_t deplSA2, uint32_t burnTimeMs)
|
||||
: SystemObject(setObjectId_),
|
||||
gpioDriverId(gpioDriverId_),
|
||||
gpioCookie(gpioCookie_),
|
||||
mainLineSwitcherObjectId(mainLineSwitcherObjectId_),
|
||||
mainLineSwitch(mainLineSwitch_),
|
||||
deplSA1(deplSA1),
|
||||
deplSA2(deplSA2),
|
||||
burnTimeMs(burnTimeMs),
|
||||
actionHelper(this, nullptr) {
|
||||
auto mqArgs = MqArgs(setObjectId_, static_cast<void*>(this));
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(
|
||||
cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
||||
}
|
||||
|
||||
SolarArrayDeploymentHandler::~SolarArrayDeploymentHandler() {}
|
||||
|
||||
ReturnValue_t SolarArrayDeploymentHandler::performOperation(uint8_t operationCode) {
|
||||
if (operationCode == DeviceHandlerIF::PERFORM_OPERATION) {
|
||||
handleStateMachine();
|
||||
return RETURN_OK;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SolarArrayDeploymentHandler::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
gpioInterface = ObjectManager::instance()->get<GpioIF>(gpioDriverId);
|
||||
if (gpioInterface == nullptr) {
|
||||
sif::error << "SolarArrayDeploymentHandler::initialize: Invalid Gpio interface." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
result = gpioInterface->addGpios(dynamic_cast<GpioCookie*>(gpioCookie));
|
||||
if (result != RETURN_OK) {
|
||||
sif::error << "SolarArrayDeploymentHandler::initialize: Failed to initialize Gpio interface"
|
||||
<< std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
if (mainLineSwitcherObjectId != objects::NO_OBJECT) {
|
||||
mainLineSwitcher = ObjectManager::instance()->get<PowerSwitchIF>(mainLineSwitcherObjectId);
|
||||
if (mainLineSwitcher == nullptr) {
|
||||
sif::error
|
||||
<< "SolarArrayDeploymentHandler::initialize: Main line switcher failed to fetch object"
|
||||
<< "from object ID." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
result = actionHelper.initialize(commandQueue);
|
||||
if (result != RETURN_OK) {
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void SolarArrayDeploymentHandler::handleStateMachine() {
|
||||
switch (stateMachine) {
|
||||
case WAIT_ON_DELOYMENT_COMMAND:
|
||||
readCommandQueue();
|
||||
break;
|
||||
case SWITCH_8V_ON:
|
||||
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_ON);
|
||||
mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs());
|
||||
stateMachine = WAIT_ON_8V_SWITCH;
|
||||
break;
|
||||
case WAIT_ON_8V_SWITCH:
|
||||
performWaitOn8VActions();
|
||||
break;
|
||||
case SWITCH_DEPL_GPIOS:
|
||||
switchDeploymentTransistors();
|
||||
break;
|
||||
case WAIT_ON_DEPLOYMENT_FINISH:
|
||||
handleDeploymentFinish();
|
||||
break;
|
||||
case WAIT_FOR_MAIN_SWITCH_OFF:
|
||||
if (mainLineSwitcher->getSwitchState(mainLineSwitch) == PowerSwitchIF::SWITCH_OFF) {
|
||||
stateMachine = WAIT_ON_DELOYMENT_COMMAND;
|
||||
} else if (mainSwitchCountdown.hasTimedOut()) {
|
||||
triggerEvent(MAIN_SWITCH_OFF_TIMEOUT);
|
||||
sif::error << "SolarArrayDeploymentHandler::handleStateMachine: Failed to switch main"
|
||||
<< " switch off" << std::endl;
|
||||
stateMachine = WAIT_ON_DELOYMENT_COMMAND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Invalid state" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SolarArrayDeploymentHandler::performWaitOn8VActions() {
|
||||
if (mainLineSwitcher->getSwitchState(mainLineSwitch) == PowerSwitchIF::SWITCH_ON) {
|
||||
stateMachine = SWITCH_DEPL_GPIOS;
|
||||
} else {
|
||||
if (mainSwitchCountdown.hasTimedOut()) {
|
||||
triggerEvent(MAIN_SWITCH_ON_TIMEOUT);
|
||||
actionHelper.finish(false, rememberCommanderId, DEPLOY_SOLAR_ARRAYS,
|
||||
MAIN_SWITCH_TIMEOUT_FAILURE);
|
||||
stateMachine = WAIT_ON_DELOYMENT_COMMAND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SolarArrayDeploymentHandler::switchDeploymentTransistors() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = gpioInterface->pullHigh(deplSA1);
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
|
||||
" array deployment switch 1 high "
|
||||
<< std::endl;
|
||||
/* If gpio switch high failed, state machine is reset to wait for a command reinitiating
|
||||
* the deployment sequence. */
|
||||
stateMachine = WAIT_ON_DELOYMENT_COMMAND;
|
||||
triggerEvent(DEPL_SA1_GPIO_SWTICH_ON_FAILED);
|
||||
actionHelper.finish(false, rememberCommanderId, DEPLOY_SOLAR_ARRAYS, SWITCHING_DEPL_SA2_FAILED);
|
||||
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF);
|
||||
}
|
||||
result = gpioInterface->pullHigh(deplSA2);
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
|
||||
" array deployment switch 2 high "
|
||||
<< std::endl;
|
||||
stateMachine = WAIT_ON_DELOYMENT_COMMAND;
|
||||
triggerEvent(DEPL_SA2_GPIO_SWTICH_ON_FAILED);
|
||||
actionHelper.finish(false, rememberCommanderId, DEPLOY_SOLAR_ARRAYS, SWITCHING_DEPL_SA2_FAILED);
|
||||
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF);
|
||||
}
|
||||
deploymentCountdown.setTimeout(burnTimeMs);
|
||||
stateMachine = WAIT_ON_DEPLOYMENT_FINISH;
|
||||
}
|
||||
|
||||
void SolarArrayDeploymentHandler::handleDeploymentFinish() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
if (deploymentCountdown.hasTimedOut()) {
|
||||
actionHelper.finish(true, rememberCommanderId, DEPLOY_SOLAR_ARRAYS, RETURN_OK);
|
||||
result = gpioInterface->pullLow(deplSA1);
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
|
||||
" array deployment switch 1 low "
|
||||
<< std::endl;
|
||||
}
|
||||
result = gpioInterface->pullLow(deplSA2);
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << "SolarArrayDeploymentHandler::handleStateMachine: Failed to pull solar"
|
||||
" array deployment switch 2 low "
|
||||
<< std::endl;
|
||||
}
|
||||
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF);
|
||||
mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs());
|
||||
stateMachine = WAIT_FOR_MAIN_SWITCH_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
void SolarArrayDeploymentHandler::readCommandQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result != RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
result = actionHelper.handleActionMessage(&command);
|
||||
if (result == RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SolarArrayDeploymentHandler::executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) {
|
||||
ReturnValue_t result;
|
||||
if (stateMachine != WAIT_ON_DELOYMENT_COMMAND) {
|
||||
sif::error << "SolarArrayDeploymentHandler::executeAction: Received command while not in"
|
||||
<< "waiting-on-command-state" << std::endl;
|
||||
return DEPLOYMENT_ALREADY_EXECUTING;
|
||||
}
|
||||
if (actionId != DEPLOY_SOLAR_ARRAYS) {
|
||||
sif::error << "SolarArrayDeploymentHandler::executeAction: Received invalid command"
|
||||
<< std::endl;
|
||||
result = COMMAND_NOT_SUPPORTED;
|
||||
} else {
|
||||
stateMachine = SWITCH_8V_ON;
|
||||
rememberCommanderId = commandedBy;
|
||||
result = RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MessageQueueId_t SolarArrayDeploymentHandler::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_SOLARARRAYDEPLOYMENT_H_
|
||||
#define MISSION_DEVICES_SOLARARRAYDEPLOYMENT_H_
|
||||
|
||||
#include <fsfw/action/HasActionsIF.h>
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/power/PowerSwitchIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <fsfw/timemanager/Countdown.h>
|
||||
#include <fsfw_hal/common/gpio/GpioIF.h>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
/**
|
||||
* @brief This class is used to control the solar array deployment.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class SolarArrayDeploymentHandler : public ExecutableObjectIF,
|
||||
public SystemObject,
|
||||
public HasReturnvaluesIF,
|
||||
public HasActionsIF {
|
||||
public:
|
||||
static const DeviceCommandId_t DEPLOY_SOLAR_ARRAYS = 0x5;
|
||||
|
||||
/**
|
||||
* @brief constructor
|
||||
*
|
||||
* @param setObjectId The object id of the SolarArrayDeploymentHandler.
|
||||
* @param gpioDriverId The id of the gpio com if.
|
||||
* @param gpioCookie GpioCookie holding information about the gpios used to switch the
|
||||
* transistors.
|
||||
* @param mainLineSwitcherObjectId The object id of the object responsible for switching
|
||||
* the 8V power source. This is normally the PCDU.
|
||||
* @param mainLineSwitch The id of the main line switch. This is defined in
|
||||
* powerSwitcherList.h.
|
||||
* @param deplSA1 gpioId of the GPIO controlling the deployment 1 transistor.
|
||||
* @param deplSA2 gpioId of the GPIO controlling the deployment 2 transistor.
|
||||
* @param burnTimeMs Time duration the power will be applied to the burn wires.
|
||||
*/
|
||||
SolarArrayDeploymentHandler(object_id_t setObjectId, object_id_t gpioDriverId,
|
||||
CookieIF* gpioCookie, object_id_t mainLineSwitcherObjectId,
|
||||
uint8_t mainLineSwitch, gpioId_t deplSA1, gpioId_t deplSA2,
|
||||
uint32_t burnTimeMs);
|
||||
|
||||
virtual ~SolarArrayDeploymentHandler();
|
||||
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const override;
|
||||
virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) override;
|
||||
virtual ReturnValue_t initialize() override;
|
||||
|
||||
private:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SA_DEPL_HANDLER;
|
||||
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA0);
|
||||
static const ReturnValue_t DEPLOYMENT_ALREADY_EXECUTING = MAKE_RETURN_CODE(0xA1);
|
||||
static const ReturnValue_t MAIN_SWITCH_TIMEOUT_FAILURE = MAKE_RETURN_CODE(0xA2);
|
||||
static const ReturnValue_t SWITCHING_DEPL_SA1_FAILED = MAKE_RETURN_CODE(0xA3);
|
||||
static const ReturnValue_t SWITCHING_DEPL_SA2_FAILED = MAKE_RETURN_CODE(0xA4);
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SA_DEPL_HANDLER;
|
||||
static const Event MAIN_SWITCH_ON_TIMEOUT = MAKE_EVENT(0, severity::LOW);
|
||||
static const Event MAIN_SWITCH_OFF_TIMEOUT = MAKE_EVENT(1, severity::LOW);
|
||||
static const Event DEPLOYMENT_FAILED = MAKE_EVENT(2, severity::HIGH);
|
||||
static const Event DEPL_SA1_GPIO_SWTICH_ON_FAILED = MAKE_EVENT(3, severity::HIGH);
|
||||
static const Event DEPL_SA2_GPIO_SWTICH_ON_FAILED = MAKE_EVENT(4, severity::HIGH);
|
||||
|
||||
enum StateMachine {
|
||||
WAIT_ON_DELOYMENT_COMMAND,
|
||||
SWITCH_8V_ON,
|
||||
WAIT_ON_8V_SWITCH,
|
||||
SWITCH_DEPL_GPIOS,
|
||||
WAIT_ON_DEPLOYMENT_FINISH,
|
||||
WAIT_FOR_MAIN_SWITCH_OFF
|
||||
};
|
||||
|
||||
StateMachine stateMachine = WAIT_ON_DELOYMENT_COMMAND;
|
||||
|
||||
/**
|
||||
* This countdown is used to check if the PCDU sets the 8V line on in the intended time.
|
||||
*/
|
||||
Countdown mainSwitchCountdown;
|
||||
|
||||
/**
|
||||
* This countdown is used to wait for the burn wire being successful cut.
|
||||
*/
|
||||
Countdown deploymentCountdown;
|
||||
|
||||
/**
|
||||
* The message queue id of the component commanding an action will be stored in this variable.
|
||||
* This is necessary to send later the action finish replies.
|
||||
*/
|
||||
MessageQueueId_t rememberCommanderId = 0;
|
||||
|
||||
/** Size of command queue */
|
||||
size_t cmdQueueSize = 20;
|
||||
|
||||
/** The object ID of the GPIO driver which switches the deployment transistors */
|
||||
object_id_t gpioDriverId;
|
||||
|
||||
CookieIF* gpioCookie;
|
||||
|
||||
/** Object id of the object responsible to switch the 8V power input. Typically the PCDU. */
|
||||
object_id_t mainLineSwitcherObjectId;
|
||||
|
||||
/** Switch number of the 8V power switch */
|
||||
uint8_t mainLineSwitch;
|
||||
|
||||
gpioId_t deplSA1;
|
||||
gpioId_t deplSA2;
|
||||
|
||||
GpioIF* gpioInterface = nullptr;
|
||||
|
||||
/** Time duration switches are active to cut the burn wire */
|
||||
uint32_t burnTimeMs;
|
||||
|
||||
/** Queue to receive messages from other objects. */
|
||||
MessageQueueIF* commandQueue = nullptr;
|
||||
|
||||
/**
|
||||
* After initialization this pointer will hold the reference to the main line switcher object.
|
||||
*/
|
||||
PowerSwitchIF* mainLineSwitcher = nullptr;
|
||||
|
||||
ActionHelper actionHelper;
|
||||
|
||||
void readCommandQueue();
|
||||
|
||||
/**
|
||||
* @brief This function performs actions dependent on the current state.
|
||||
*/
|
||||
void handleStateMachine();
|
||||
|
||||
/**
|
||||
* @brief This function polls the 8V switch state and changes the state machine when the
|
||||
* switch has been enabled.
|
||||
*/
|
||||
void performWaitOn8VActions();
|
||||
|
||||
/**
|
||||
* @brief This functions handles the switching of the solar array deployment transistors.
|
||||
*/
|
||||
void switchDeploymentTransistors();
|
||||
|
||||
/**
|
||||
* @brief This function performs actions to finish the deployment. Essentially switches
|
||||
* are turned of after the burn time has expired.
|
||||
*/
|
||||
void handleDeploymentFinish();
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_SOLARARRAYDEPLOYMENT_H_ */
|
@ -1,247 +0,0 @@
|
||||
#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, uint8_t susIdx, object_id_t comIF, CookieIF *comCookie,
|
||||
LinuxLibgpioIF *gpioComIF, gpioId_t chipSelectId)
|
||||
: DeviceHandlerBase(objectId, comIF, comCookie), divider(5), dataset(this), susIdx(susIdx) {}
|
||||
|
||||
SusHandler::~SusHandler() {}
|
||||
|
||||
ReturnValue_t SusHandler::initialize() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = DeviceHandlerBase::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void SusHandler::doStartUp() {
|
||||
if (comState == ComStates::IDLE) {
|
||||
comState = ComStates::WRITE_SETUP;
|
||||
commandExecuted = false;
|
||||
}
|
||||
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;
|
||||
if (clkMode == ClkModes::INT_CLOCKED) {
|
||||
comState = ComStates::START_INT_CLOCKED_CONVERSIONS;
|
||||
} else {
|
||||
comState = ComStates::EXT_CLOCKED_CONVERSIONS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SusHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t SusHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
switch (comState) {
|
||||
case (ComStates::IDLE): {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
case (ComStates::WRITE_SETUP): {
|
||||
*id = SUS::WRITE_SETUP;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
case (ComStates::EXT_CLOCKED_CONVERSIONS): {
|
||||
*id = SUS::READ_EXT_TIMED_CONVERSIONS;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
case (ComStates::EXT_CLOCKED_TEMP): {
|
||||
*id = SUS::READ_EXT_TIMED_TEMPS;
|
||||
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;
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
using namespace max1227;
|
||||
switch (deviceCommand) {
|
||||
case (SUS::WRITE_SETUP): {
|
||||
if (clkMode == ClkModes::INT_CLOCKED) {
|
||||
cmdBuffer[0] = SUS::SETUP_INT_CLOKED;
|
||||
} else {
|
||||
cmdBuffer[0] = SUS::SETUP_EXT_CLOCKED;
|
||||
}
|
||||
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 1;
|
||||
break;
|
||||
}
|
||||
case (SUS::START_INT_TIMED_CONVERSIONS): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
cmdBuffer[0] = max1227::buildResetByte(true);
|
||||
cmdBuffer[1] = SUS::CONVERSION;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 2;
|
||||
break;
|
||||
}
|
||||
case (SUS::READ_INT_TIMED_CONVERSIONS): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = SUS::SIZE_READ_INT_CONVERSIONS;
|
||||
break;
|
||||
}
|
||||
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, idx, false);
|
||||
cmdBuffer[idx * 2 + 1] = 0;
|
||||
}
|
||||
cmdBuffer[12] = 0x00;
|
||||
rawPacketLen = SUS::SIZE_READ_EXT_CONVERSIONS;
|
||||
break;
|
||||
}
|
||||
case (SUS::READ_EXT_TIMED_TEMPS): {
|
||||
cmdBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, true);
|
||||
std::memset(cmdBuffer + 1, 0, 24);
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 25;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void SusHandler::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(SUS::WRITE_SETUP, 1);
|
||||
insertInCommandAndReplyMap(SUS::START_INT_TIMED_CONVERSIONS, 1);
|
||||
insertInCommandAndReplyMap(SUS::READ_INT_TIMED_CONVERSIONS, 1, &dataset,
|
||||
SUS::SIZE_READ_INT_CONVERSIONS);
|
||||
insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_CONVERSIONS, 1, &dataset,
|
||||
SUS::SIZE_READ_EXT_CONVERSIONS);
|
||||
insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_TEMPS, 1);
|
||||
}
|
||||
|
||||
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::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 = static_cast<int16_t>((packet[0] << 8) | packet[1]) * 0.125;
|
||||
dataset.ain0 = (*(packet + 2) << 8 | *(packet + 3));
|
||||
dataset.ain1 = (*(packet + 4) << 8 | *(packet + 5));
|
||||
dataset.ain2 = (*(packet + 6) << 8 | *(packet + 7));
|
||||
dataset.ain3 = (*(packet + 8) << 8 | *(packet + 9));
|
||||
dataset.ain4 = (*(packet + 10) << 8 | *(packet + 11));
|
||||
dataset.ain5 = (*(packet + 12) << 8 | *(packet + 13));
|
||||
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];
|
||||
// Read temperature in next read cycle
|
||||
if (clkMode == ClkModes::EXT_CLOCKED_WITH_TEMP) {
|
||||
comState = ComStates::EXT_CLOCKED_TEMP;
|
||||
}
|
||||
printDataset();
|
||||
break;
|
||||
}
|
||||
case (SUS::READ_EXT_TIMED_TEMPS): {
|
||||
PoolReadGuard readSet(&dataset);
|
||||
dataset.temperatureCelcius =
|
||||
static_cast<int16_t>(((packet[23] & 0x0f) << 8) | packet[24]) * 0.125;
|
||||
comState = ComStates::EXT_CLOCKED_CONVERSIONS;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl;
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 2000; }
|
||||
|
||||
ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(SUS::TEMPERATURE_C, new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(SUS::AIN0, new PoolEntry<uint16_t>({0}));
|
||||
localDataPoolMap.emplace(SUS::AIN1, new PoolEntry<uint16_t>({0}));
|
||||
localDataPoolMap.emplace(SUS::AIN2, new PoolEntry<uint16_t>({0}));
|
||||
localDataPoolMap.emplace(SUS::AIN3, new PoolEntry<uint16_t>({0}));
|
||||
localDataPoolMap.emplace(SUS::AIN4, new PoolEntry<uint16_t>({0}));
|
||||
localDataPoolMap.emplace(SUS::AIN5, new PoolEntry<uint16_t>({0}));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void SusHandler::setToGoToNormalMode(bool enable) { this->goToNormalModeImmediately = enable; }
|
||||
|
||||
void SusHandler::printDataset() {
|
||||
if (periodicPrintout) {
|
||||
if (divider.checkAndIncrement()) {
|
||||
sif::info << "SUS " << std::setw(2) << std::dec << static_cast<int>(susIdx) << " ID "
|
||||
<< std::hex << "0x" << this->getObjectId() << " [" << std::hex << std::setw(3);
|
||||
sif::info << dataset.ain0 << ",";
|
||||
sif::info << dataset.ain1 << ",";
|
||||
sif::info << dataset.ain2 << ",";
|
||||
sif::info << dataset.ain3 << ",";
|
||||
sif::info << dataset.ain4 << ",";
|
||||
sif::info << dataset.ain5 << "] ";
|
||||
sif::info << "T[C] " << dataset.temperatureCelcius << " C" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SusHandler::enablePeriodicPrintout(bool enable, uint8_t divider) {
|
||||
this->periodicPrintout = enable;
|
||||
this->divider.setDivider(divider);
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_SUSHANDLER_H_
|
||||
#define MISSION_DEVICES_SUSHANDLER_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <fsfw_hal/linux/gpio/LinuxLibgpioIF.h>
|
||||
|
||||
#include "devicedefinitions/SusDefinitions.h"
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#include "mission/devices/max1227.h"
|
||||
|
||||
/**
|
||||
* @brief This is the device handler class for the SUS sensor based on the MAX1227 ADC.
|
||||
*
|
||||
* @details
|
||||
* Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf
|
||||
* 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
|
||||
*
|
||||
* @note When adding a SusHandler to the polling sequence table make sure to add a slot with
|
||||
* the executionStep FIRST_WRITE. Otherwise the communication sequence will never be
|
||||
* started.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class SusHandler : public DeviceHandlerBase {
|
||||
public:
|
||||
enum ClkModes { INT_CLOCKED, EXT_CLOCKED, EXT_CLOCKED_WITH_TEMP };
|
||||
|
||||
static const uint8_t FIRST_WRITE = 7;
|
||||
|
||||
SusHandler(object_id_t objectId, uint8_t susIdx, object_id_t comIF, CookieIF* comCookie,
|
||||
LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId);
|
||||
virtual ~SusHandler();
|
||||
|
||||
void enablePeriodicPrintout(bool enable, uint8_t divider);
|
||||
|
||||
virtual ReturnValue_t initialize() override;
|
||||
void setToGoToNormalMode(bool enable);
|
||||
|
||||
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;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
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,
|
||||
EXT_CLOCKED_CONVERSIONS,
|
||||
EXT_CLOCKED_TEMP,
|
||||
START_INT_CLOCKED_CONVERSIONS,
|
||||
READ_INT_CLOCKED_CONVERSIONS
|
||||
};
|
||||
|
||||
bool periodicPrintout = false;
|
||||
PeriodicOperationDivider divider;
|
||||
bool goToNormalModeImmediately = false;
|
||||
bool commandExecuted = false;
|
||||
|
||||
SUS::SusDataset dataset;
|
||||
// Read temperature in each alternating communication step when using
|
||||
// externally clocked mode
|
||||
ClkModes clkMode = ClkModes::INT_CLOCKED;
|
||||
|
||||
uint8_t susIdx = 0;
|
||||
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;
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_SUSHANDLER_H_ */
|
@ -1,90 +0,0 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_
|
||||
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace SUS {
|
||||
|
||||
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
|
||||
|
||||
static const DeviceCommandId_t WRITE_SETUP = 1;
|
||||
/**
|
||||
* This command initiates the ADC conversion for all channels including the internal
|
||||
* temperature sensor.
|
||||
*/
|
||||
static const DeviceCommandId_t START_INT_TIMED_CONVERSIONS = 2;
|
||||
/**
|
||||
* This command reads the internal fifo which holds the temperature and the channel
|
||||
* conversions.
|
||||
*/
|
||||
static constexpr DeviceCommandId_t READ_INT_TIMED_CONVERSIONS = 3;
|
||||
|
||||
static constexpr DeviceCommandId_t READ_EXT_TIMED_CONVERSIONS = 4;
|
||||
|
||||
static constexpr DeviceCommandId_t READ_EXT_TIMED_TEMPS = 5;
|
||||
|
||||
/**
|
||||
* @brief This is the configuration byte which will be written to the setup register after
|
||||
* power on.
|
||||
*
|
||||
* @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte
|
||||
* Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, Internal reference, no wake-up delay
|
||||
* Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, Internally clocked
|
||||
* Bit7 - Bit6: 0b01, Tells MAX1227 that this byte should be
|
||||
* written to the setup register
|
||||
*
|
||||
*/
|
||||
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
|
||||
* conversions to perform.
|
||||
* @details Bit0: 1 - Enables temperature conversion
|
||||
* Bit2 (SCAN1) and Bit1 (SCAN0): 0b00, Scans channels 0 through N
|
||||
* Bit6 - Bit3 defines N: 0b0101 (N = 5)
|
||||
* Bit7: Always 1. Tells the ADC that this is the conversion register.
|
||||
*/
|
||||
static const uint8_t CONVERSION = 0b10101001;
|
||||
|
||||
static const uint8_t SUS_DATA_SET_ID = READ_INT_TIMED_CONVERSIONS;
|
||||
|
||||
/** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */
|
||||
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 = 32;
|
||||
|
||||
static const uint8_t POOL_ENTRIES = 7;
|
||||
|
||||
enum Max1227PoolIds : lp_id_t {
|
||||
TEMPERATURE_C,
|
||||
AIN0,
|
||||
AIN1,
|
||||
AIN2,
|
||||
AIN3,
|
||||
AIN4,
|
||||
AIN5,
|
||||
};
|
||||
|
||||
class SusDataset : public StaticLocalDataSet<POOL_ENTRIES> {
|
||||
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> ain0 = lp_var_t<uint16_t>(sid.objectId, AIN0, this);
|
||||
lp_var_t<uint16_t> ain1 = lp_var_t<uint16_t>(sid.objectId, AIN1, this);
|
||||
lp_var_t<uint16_t> ain2 = lp_var_t<uint16_t>(sid.objectId, AIN2, this);
|
||||
lp_var_t<uint16_t> ain3 = lp_var_t<uint16_t>(sid.objectId, AIN3, this);
|
||||
lp_var_t<uint16_t> ain4 = lp_var_t<uint16_t>(sid.objectId, AIN4, this);
|
||||
lp_var_t<uint16_t> ain5 = lp_var_t<uint16_t>(sid.objectId, AIN5, this);
|
||||
};
|
||||
} // namespace SUS
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ */
|
@ -6,7 +6,7 @@
|
||||
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "linux/devices/SusHandler.h"
|
||||
#include "mission/devices/SusHandler.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
ReturnValue_t pst::pstGpio(FixedTimeslotTaskIF *thisSequence) {
|
||||
|
Reference in New Issue
Block a user