Documentation, small refactoring

master
sh123 2025-04-11 14:38:34 +03:00
rodzic f48def5cab
commit f0d7caa6f2
2 zmienionych plików z 31 dodań i 14 usunięć

Wyświetl plik

@ -4,6 +4,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <DebugLog.h> #include <DebugLog.h>
#include <memory> #include <memory>
#include <vector>
#define CIRCULAR_BUFFER_INT_SAFE #define CIRCULAR_BUFFER_INT_SAFE
#include <CircularBuffer.h> #include <CircularBuffer.h>
@ -13,6 +14,7 @@ namespace Kiss {
class Processor { class Processor {
protected: protected:
// Enum to represent special KISS markers
enum Marker { enum Marker {
Fend = 0xc0, Fend = 0xc0,
Fesc = 0xdb, Fesc = 0xdb,
@ -20,6 +22,7 @@ protected:
Tfesc = 0xdd Tfesc = 0xdd
}; };
// Enum to represent the state of the processor
enum State { enum State {
GetStart = 0, GetStart = 0,
GetEnd, GetEnd,
@ -30,6 +33,7 @@ protected:
Escape Escape
}; };
// Enum to represent KISS commands
enum Cmd { enum Cmd {
Data = 0x00, Data = 0x00,
TxDelay = 0x01, TxDelay = 0x01,
@ -43,6 +47,7 @@ protected:
NoCmd = 0x80 NoCmd = 0x80
}; };
// Enum to represent the type of data being processed
enum DataType { enum DataType {
Raw = 0, Raw = 0,
Control, Control,
@ -50,52 +55,64 @@ protected:
None = 0x80 None = 0x80
}; };
static const int CfgToSerialDelayMs = 10; // Compile-time constants for configuration
static const int CfgSerialToRigQueueSize = 4096; static constexpr int CfgToSerialDelayMs = 10;
static const int CfgRigToSerialQueueSize = 4096; static constexpr int CfgSerialToRigQueueSize = 4096;
static constexpr int CfgRigToSerialQueueSize = 4096;
public: public:
Processor(); Processor();
virtual ~Processor() = default; // Add virtual destructor
// Sends data from rig to serial with a specific command
void sendRigToSerial(Cmd cmd, const byte *packet, int packetLength); void sendRigToSerial(Cmd cmd, const byte *packet, int packetLength);
// Queues data for transmission from rig to serial
void queueRigToSerial(Cmd cmd, const byte *packet, int packetLength); void queueRigToSerial(Cmd cmd, const byte *packet, int packetLength);
// Queues data for transmission from serial to rig
void queueSerialToRig(Cmd cmd, const byte *packet, int packetLength); void queueSerialToRig(Cmd cmd, const byte *packet, int packetLength);
// Processes queued data for transmission from rig to serial
bool processRigToSerial(); bool processRigToSerial();
// Processes queued data for transmission from serial to rig
bool processSerialToRig(); bool processSerialToRig();
protected: protected:
// Virtual methods to be implemented by derived classes
virtual bool onRigTxBegin() = 0; virtual bool onRigTxBegin() = 0;
virtual void onRigTx(byte b) = 0; virtual void onRigTx(byte b) = 0;
virtual void onRigTxEnd() = 0; virtual void onRigTxEnd() = 0;
virtual void onRigPacket(void *packet, int packetLength) = 0; virtual void onRigPacket(void *packet, int packetLength) = 0;
virtual void onSerialTx(byte b) = 0; virtual void onSerialTx(byte b) = 0;
virtual bool onSerialRxHasData() = 0; virtual bool onSerialRxHasData() = 0;
virtual bool onSerialRx(byte *b) = 0; virtual bool onSerialRx(byte *b) = 0;
virtual void onControlCommand(Cmd cmd, byte value) = 0; virtual void onControlCommand(Cmd cmd, byte value) = 0;
virtual void onRadioControlCommand(const std::vector<byte> &command) = 0; virtual void onRadioControlCommand(const std::vector<byte> &command) = 0;
virtual void onRebootCommand() = 0; virtual void onRebootCommand() = 0;
private: private:
// Processes a received byte
bool receiveByte(byte rxByte); bool receiveByte(byte rxByte);
bool receiveByteRaw(byte rxByte); bool receiveByteRaw(byte rxByte);
bool receiveByteKiss(byte rxByte); bool receiveByteKiss(byte rxByte);
// Processes data and commands
void processData(byte rxByte); void processData(byte rxByte);
bool processCommand(byte rxByte); bool processCommand(byte rxByte);
protected: protected:
bool disableKiss_; bool disableKiss_; // Flag to disable KISS mode
bool usePrefix3_; bool usePrefix3_; // Flag to use a 3-byte prefix
private: private:
bool isRawIdle_; bool isRawIdle_; // Indicates if raw mode is idle
State state_; State state_; // Current state of the processor
DataType dataType_; DataType dataType_;// Current data type being processed
std::vector<byte> cmdBuffer_; std::vector<byte> cmdBuffer_; // Buffer for commands
// Circular buffers for data queues
CircularBuffer<uint8_t, CfgSerialToRigQueueSize> serialToRigQueue_; CircularBuffer<uint8_t, CfgSerialToRigQueueSize> serialToRigQueue_;
CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueue_; CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueue_;
CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueueIndex_; CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueueIndex_;

Wyświetl plik

@ -135,7 +135,7 @@ private:
} __attribute__((packed)); } __attribute__((packed));
private: private:
const String CfgLoraprsVersion = "LoRAPRS 1.0.15"; const String CfgLoraprsVersion = "LoRAPRS 1.0.16";
// processor config // processor config
const int CfgConnRetryMs = 500; // connection retry delay, e.g. wifi const int CfgConnRetryMs = 500; // connection retry delay, e.g. wifi