eive-obsw/linux/acs/ImtqPollingTask.h

74 lines
2.8 KiB
C
Raw Normal View History

2023-02-19 12:25:26 +01:00
#ifndef LINUX_DEVICES_IMTQPOLLINGTASK_H_
#define LINUX_DEVICES_IMTQPOLLINGTASK_H_
#include <fsfw/tasks/SemaphoreIF.h>
#include <fsfw_hal/linux/i2c/I2cCookie.h>
2023-04-02 20:12:24 +02:00
#include <mission/acs/acsBoardPolling.h>
2023-02-19 12:25:26 +01:00
2023-03-21 17:37:39 +01:00
#include <atomic>
2023-02-19 12:25:26 +01:00
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
2023-03-24 20:50:33 +01:00
#include "mission/acs/imtqHelpers.h"
2023-02-19 12:25:26 +01:00
class ImtqPollingTask : public SystemObject,
public ExecutableObjectIF,
public DeviceCommunicationIF {
public:
2023-03-13 09:49:35 +01:00
ImtqPollingTask(object_id_t imtqPollingTask, std::atomic_uint16_t& i2cFatalErrors);
2023-02-19 12:25:26 +01:00
ReturnValue_t performOperation(uint8_t operationCode) override;
ReturnValue_t initialize() override;
private:
static constexpr ReturnValue_t NO_REPLY_AVAILABLE = returnvalue::makeCode(2, 0);
2023-03-24 01:01:29 +01:00
enum class InternalState { IDLE, IS_BUSY } state = InternalState::IDLE;
2023-02-19 12:25:26 +01:00
SemaphoreIF* semaphore;
ReturnValue_t comStatus = returnvalue::OK;
MutexIF* ipcLock;
MutexIF* bufLock;
2023-03-13 09:49:35 +01:00
std::atomic_uint16_t& i2cFatalErrors;
2023-02-19 12:25:26 +01:00
I2cCookie* i2cCookie = nullptr;
const char* i2cDev = nullptr;
address_t i2cAddr = 0;
uint32_t currentIntegrationTimeMs = 10;
2023-03-04 17:06:23 +01:00
// Required in addition to integration time, otherwise old data might be read.
2023-04-03 10:12:19 +02:00
static constexpr uint32_t MGM_READ_BUFFER_TIME_MS = 6;
2023-02-20 02:32:48 +01:00
bool ignoreNextActuateRequest = false;
2023-04-02 20:12:24 +02:00
bool performStartup = false;
imtq::Request currentRequest{};
2023-02-19 12:25:26 +01:00
std::array<uint8_t, 32> cmdBuf;
std::array<uint8_t, 524> replyBuf;
std::array<uint8_t, 524> replyBufActuation;
std::array<uint8_t, 524> exchangeBuf;
size_t cmdLen = 0;
// DeviceCommunicationIF overrides
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;
void ccToReplyPtrMeasure(ImtqRepliesDefault& replies, imtq::CC::CC cc, uint8_t** replyBuf,
size_t& replyLen);
void ccToReplyPtrActuate(ImtqRepliesWithTorque& replies, imtq::CC::CC cc, uint8_t** replyBuf,
size_t& replyLen);
2023-02-20 02:32:48 +01:00
void clearReadFlagsDefault(ImtqRepliesDefault& replies);
void clearReadFlagsWithTorque(ImtqRepliesWithTorque& replies);
2023-02-19 12:25:26 +01:00
size_t getExchangeBufLen(imtq::SpecialRequest specialRequest);
void buildDipoleCommand();
2023-02-20 02:32:48 +01:00
void handleMeasureStep();
void handleActuateStep();
ReturnValue_t i2cCmdExecDefault(imtq::CC::CC cc, uint8_t* replyPtr, size_t replyLen,
ReturnValue_t comErrIfFails);
2023-02-19 12:25:26 +01:00
ReturnValue_t performI2cFullRequest(uint8_t* reply, size_t replyLen);
};
#endif /* LINUX_DEVICES_IMTQPOLLINGTASK_H_ */