2022-06-21 16:44:14 +02:00
|
|
|
#pragma once
|
2022-04-08 19:12:21 +02:00
|
|
|
|
|
|
|
#include <fsfw/container/DynamicFIFO.h>
|
|
|
|
#include <fsfw/container/SimpleRingBuffer.h>
|
|
|
|
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
|
|
|
#include <fsfw/globalfunctions/DleEncoder.h>
|
2022-03-25 17:48:38 +01:00
|
|
|
#include <fsfw/objectmanager/SystemObject.h>
|
|
|
|
#include <fsfw/tasks/ExecutableObjectIF.h>
|
2022-04-08 19:12:21 +02:00
|
|
|
#include <fsfw/timemanager/Countdown.h>
|
2023-03-26 16:42:00 +02:00
|
|
|
#include <linux/payload/ScexDleParser.h>
|
2022-04-08 19:12:21 +02:00
|
|
|
#include <termios.h> // Contains POSIX terminal control definitions
|
2022-03-25 17:48:38 +01:00
|
|
|
|
2022-04-08 19:12:21 +02:00
|
|
|
class SemaphoreIF;
|
|
|
|
class MutexIF;
|
2022-03-25 17:48:38 +01:00
|
|
|
|
2022-10-10 17:36:01 +02:00
|
|
|
class ScexUartReader : public SystemObject,
|
2022-04-08 19:12:21 +02:00
|
|
|
public ExecutableObjectIF,
|
|
|
|
public DeviceCommunicationIF {
|
|
|
|
friend class UartTestClass;
|
2022-03-25 17:48:38 +01:00
|
|
|
|
2022-04-08 19:12:21 +02:00
|
|
|
public:
|
|
|
|
enum class States { NOT_READY, IDLE, RUNNING, FINISH };
|
|
|
|
ScexUartReader(object_id_t objectId);
|
|
|
|
|
2022-10-04 23:04:50 +02:00
|
|
|
void reset();
|
2022-04-08 19:12:21 +02:00
|
|
|
ReturnValue_t finish();
|
|
|
|
void setDebugMode(bool enable);
|
|
|
|
|
|
|
|
private:
|
|
|
|
SemaphoreIF *semaphore;
|
|
|
|
bool debugMode = false;
|
|
|
|
MutexIF *lock;
|
|
|
|
int serialPort = 0;
|
|
|
|
States state = States::IDLE;
|
|
|
|
struct termios tty = {};
|
|
|
|
bool doFinish = false;
|
|
|
|
DleEncoder dleEncoder = DleEncoder();
|
2022-04-09 14:43:06 +02:00
|
|
|
SimpleRingBuffer decodeRingBuf;
|
|
|
|
|
2022-04-08 19:12:21 +02:00
|
|
|
std::array<uint8_t, 256> cmdbuf = {};
|
2022-04-27 16:46:11 +02:00
|
|
|
std::array<uint8_t, 4096> recBuf = {};
|
2022-04-09 14:43:06 +02:00
|
|
|
std::array<uint8_t, 4096> encodedBuf = {};
|
|
|
|
std::array<uint8_t, 4096> decodedBuf = {};
|
2022-04-08 19:12:21 +02:00
|
|
|
std::array<uint8_t, 4096> ipcBuffer = {};
|
2022-04-09 14:43:06 +02:00
|
|
|
SimpleRingBuffer ipcRingBuf;
|
|
|
|
DynamicFIFO<size_t> ipcQueue;
|
|
|
|
ScexDleParser dleParser;
|
|
|
|
|
2022-04-09 15:38:09 +02:00
|
|
|
static void foundDlePacketHandler(const DleParser::Context &ctx);
|
2022-04-09 14:43:06 +02:00
|
|
|
void handleFoundDlePacket(uint8_t *packet, size_t len);
|
2022-10-04 23:04:50 +02:00
|
|
|
ReturnValue_t tryDleParsing();
|
2022-04-08 19:12:21 +02:00
|
|
|
|
|
|
|
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
|
|
|
|
|
|
|
// DeviceCommunicationIF implementation
|
|
|
|
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;
|
|
|
|
};
|