Robin Mueller
50c363fb6f
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
93 lines
3.0 KiB
C++
93 lines
3.0 KiB
C++
#ifndef LINUX_DEVICES_MAX31865RTDREADER_H_
|
|
#define LINUX_DEVICES_MAX31865RTDREADER_H_
|
|
|
|
#include <fsfw/ipc/MutexIF.h>
|
|
#include <fsfw/tasks/ExecutableObjectIF.h>
|
|
#include <fsfw_hal/linux/spi/SpiComIF.h>
|
|
#include <fsfw_hal/linux/spi/SpiCookie.h>
|
|
|
|
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
|
|
#include "mission/devices/devicedefinitions/Max31865Definitions.h"
|
|
|
|
static constexpr uint8_t NUM_RTDS = 16;
|
|
|
|
enum RtdCommands : uint8_t { ON = 0, OFF = 1, CFG = 2 };
|
|
|
|
class ReadOutStruct : public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
ReadOutStruct() { setLinks(); }
|
|
ReadOutStruct(uint32_t spiErrCnt, bool faultBitSet, uint8_t faultVal, uint16_t rtdVal)
|
|
: spiErrorCount(spiErrCnt), faultBitSet(faultBitSet), faultValue(faultVal), rtdVal(rtdVal) {
|
|
setLinks();
|
|
}
|
|
|
|
SerializeElement<uint32_t> spiErrorCount = 0;
|
|
SerializeElement<bool> faultBitSet = false;
|
|
SerializeElement<uint8_t> faultValue = 0;
|
|
SerializeElement<uint16_t> rtdVal = 0;
|
|
|
|
private:
|
|
void setLinks() {
|
|
setStart(&spiErrorCount);
|
|
spiErrorCount.setNext(&faultBitSet);
|
|
faultBitSet.setNext(&faultValue);
|
|
faultValue.setNext(&rtdVal);
|
|
};
|
|
};
|
|
|
|
struct Max31865ReaderCookie {
|
|
Max31865ReaderCookie(){};
|
|
Max31865ReaderCookie(object_id_t handlerId_, uint8_t idx_, const std::string& locString_,
|
|
SpiCookie* spiCookie_)
|
|
: idx(idx_), handlerId(handlerId_), locString(locString_), spiCookie(spiCookie_) {}
|
|
|
|
uint8_t idx = 0;
|
|
object_id_t handlerId = objects::NO_OBJECT;
|
|
|
|
std::string locString = "";
|
|
std::array<uint8_t, 12> exchangeBuf{};
|
|
bool active = false;
|
|
|
|
bool configured = false;
|
|
|
|
SpiCookie* spiCookie = nullptr;
|
|
|
|
// Exchange data buffer struct
|
|
ReadOutStruct db;
|
|
};
|
|
|
|
class Max31865RtdReader : public SystemObject,
|
|
public ExecutableObjectIF,
|
|
public DeviceCommunicationIF {
|
|
public:
|
|
Max31865RtdReader(object_id_t objectId, SpiComIF* comIF);
|
|
void addRtd(Max31865ReaderCookie rtdCookie);
|
|
|
|
[[noreturn]] ReturnValue_t performOperation(uint8_t operationCode) override;
|
|
|
|
private:
|
|
std::vector<Max31865ReaderCookie*> rtds;
|
|
MutexIF* readerMutex;
|
|
|
|
void rtdMainLoop();
|
|
bool periodicInitHandling();
|
|
void periodicReadReqHandling();
|
|
void periodicReadHandling();
|
|
|
|
bool rtdCanBeUsed(uint8_t idx);
|
|
ReturnValue_t writeCfgReg(SpiCookie* cookie, uint8_t cfg);
|
|
ReturnValue_t biasSel(MAX31865::Bias bias, SpiCookie* cookie);
|
|
ReturnValue_t readCfgReg(SpiCookie* cookie, uint8_t& cfg);
|
|
ReturnValue_t readRtdVal(SpiCookie* cookie, uint16_t& val, bool& faultBitSet);
|
|
|
|
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
|
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
|
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
|
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
|
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
|
|
|
SpiComIF* comIF;
|
|
};
|
|
|
|
#endif /* LINUX_DEVICES_MAX31865RTDREADER_H_ */
|