44#include < Arduino.h>
55#include < DebugLog.h>
66#include < memory>
7+ #include < vector>
78
89#define CIRCULAR_BUFFER_INT_SAFE
910#include < CircularBuffer.h>
@@ -13,13 +14,15 @@ namespace Kiss {
1314class Processor {
1415
1516protected:
17+ // Enum to represent special KISS markers
1618 enum Marker {
1719 Fend = 0xc0 ,
1820 Fesc = 0xdb ,
1921 Tfend = 0xdc ,
2022 Tfesc = 0xdd
2123 };
2224
25+ // Enum to represent the state of the processor
2326 enum State {
2427 GetStart = 0 ,
2528 GetEnd,
@@ -30,6 +33,7 @@ class Processor {
3033 Escape
3134 };
3235
36+ // Enum to represent KISS commands
3337 enum Cmd {
3438 Data = 0x00 ,
3539 TxDelay = 0x01 ,
@@ -43,64 +47,77 @@ class Processor {
4347 NoCmd = 0x80
4448 };
4549
50+ // Enum to represent the type of data being processed
4651 enum DataType {
4752 Raw = 0 ,
4853 Control,
4954 Reboot,
5055 None = 0x80
5156 };
5257
53- static const int CfgToSerialDelayMs = 10 ;
54- static const int CfgSerialToRigQueueSize = 4096 ;
55- static const int CfgRigToSerialQueueSize = 4096 ;
58+ // Compile-time constants for configuration
59+ static constexpr int CfgToSerialDelayMs = 10 ;
60+ static constexpr int CfgSerialToRigQueueSize = 4096 ;
61+ static constexpr int CfgRigToSerialQueueSize = 4096 ;
5662
5763public:
5864 Processor ();
59-
65+ virtual ~Processor () = default ; // Add virtual destructor
66+
67+ // Sends data from rig to serial with a specific command
6068 void sendRigToSerial (Cmd cmd, const byte *packet, int packetLength);
69+
70+ // Queues data for transmission from rig to serial
6171 void queueRigToSerial (Cmd cmd, const byte *packet, int packetLength);
72+
73+ // Queues data for transmission from serial to rig
6274 void queueSerialToRig (Cmd cmd, const byte *packet, int packetLength);
6375
76+ // Processes queued data for transmission from rig to serial
6477 bool processRigToSerial ();
78+
79+ // Processes queued data for transmission from serial to rig
6580 bool processSerialToRig ();
6681
6782protected:
83+ // Virtual methods to be implemented by derived classes
6884 virtual bool onRigTxBegin () = 0;
6985 virtual void onRigTx (byte b) = 0;
7086 virtual void onRigTxEnd () = 0;
7187 virtual void onRigPacket (void *packet, int packetLength) = 0;
72-
7388 virtual void onSerialTx (byte b) = 0;
7489 virtual bool onSerialRxHasData () = 0;
7590 virtual bool onSerialRx (byte *b) = 0;
76-
7791 virtual void onControlCommand (Cmd cmd, byte value) = 0;
7892 virtual void onRadioControlCommand (const std::vector<byte> &command) = 0;
7993 virtual void onRebootCommand () = 0;
8094
8195private:
96+ // Processes a received byte
8297 bool receiveByte (byte rxByte);
8398 bool receiveByteRaw (byte rxByte);
8499 bool receiveByteKiss (byte rxByte);
85100
101+ // Processes data and commands
86102 void processData (byte rxByte);
87103 bool processCommand (byte rxByte);
88104
89105protected:
90- bool disableKiss_;
91- bool usePrefix3_;
106+ bool disableKiss_; // Flag to disable KISS mode
107+ bool usePrefix3_; // Flag to use a 3-byte prefix
92108
93109private:
94- bool isRawIdle_;
95- State state_;
96- DataType dataType_;
97- std::vector<byte> cmdBuffer_;
110+ bool isRawIdle_; // Indicates if raw mode is idle
111+ State state_; // Current state of the processor
112+ DataType dataType_;// Current data type being processed
113+ std::vector<byte> cmdBuffer_; // Buffer for commands
98114
115+ // Circular buffers for data queues
99116 CircularBuffer<uint8_t , CfgSerialToRigQueueSize> serialToRigQueue_;
100117 CircularBuffer<uint8_t , CfgRigToSerialQueueSize> rigToSerialQueue_;
101118 CircularBuffer<uint8_t , CfgRigToSerialQueueSize> rigToSerialQueueIndex_;
102119};
103-
120+
104121} // Kiss
105122
106123#endif // KISS_PROCESSOR_H
0 commit comments