esp32_loraprs/include/kiss_processor.h

107 wiersze
2.2 KiB
C
Czysty Zwykły widok Historia

#ifndef KISS_PROCESSOR_H
#define KISS_PROCESSOR_H
#include <Arduino.h>
#include <DebugLog.h>
#include <memory>
#define CIRCULAR_BUFFER_INT_SAFE
#include <CircularBuffer.h>
namespace Kiss {
class Processor {
protected:
enum Marker {
Fend = 0xc0,
Fesc = 0xdb,
Tfend = 0xdc,
Tfesc = 0xdd
};
enum State {
2021-02-06 11:45:24 +00:00
GetStart = 0,
GetEnd,
GetCmd,
GetData,
GetP,
GetSlotTime,
Escape
};
enum Cmd {
Data = 0x00,
2021-05-26 16:11:33 +00:00
TxDelay = 0x01,
P = 0x02,
SlotTime = 0x03,
2021-05-26 16:11:33 +00:00
TxTail = 0x04,
SetHardware = 0x06,
SignalReport = 0x07,
2021-10-20 09:58:43 +00:00
RebootRequested = 0x08,
2022-12-17 22:01:33 +00:00
Telemetry = 0x09,
NoCmd = 0x80
};
enum DataType {
Raw = 0,
2021-10-20 09:58:43 +00:00
Control,
Reboot,
None = 0x80
};
2021-02-06 13:53:19 +00:00
2023-11-17 13:49:48 +00:00
static const int CfgToSerialDelayMs = 10;
static const int CfgSerialToRigQueueSize = 4096;
static const int CfgRigToSerialQueueSize = 4096;
2021-02-06 13:53:19 +00:00
public:
Processor();
2021-02-12 14:43:18 +00:00
void sendRigToSerial(Cmd cmd, const byte *packet, int packetLength);
void queueRigToSerial(Cmd cmd, const byte *packet, int packetLength);
2021-02-12 14:43:18 +00:00
void queueSerialToRig(Cmd cmd, const byte *packet, int packetLength);
bool processRigToSerial();
bool processSerialToRig();
2021-02-06 13:53:19 +00:00
protected:
virtual bool onRigTxBegin() = 0;
2021-02-02 15:57:36 +00:00
virtual void onRigTx(byte b) = 0;
virtual void onRigTxEnd() = 0;
virtual void onRigPacket(void *packet, int packetLength) = 0;
2021-02-02 15:57:36 +00:00
virtual void onSerialTx(byte b) = 0;
virtual bool onSerialRxHasData() = 0;
2021-02-02 15:57:36 +00:00
virtual bool onSerialRx(byte *b) = 0;
virtual void onControlCommand(Cmd cmd, byte value) = 0;
virtual void onRadioControlCommand(const std::vector<byte> &command) = 0;
2021-10-20 09:58:43 +00:00
virtual void onRebootCommand() = 0;
private:
bool receiveByte(byte rxByte);
2022-12-17 22:01:33 +00:00
bool receiveByteRaw(byte rxByte);
bool receiveByteKiss(byte rxByte);
void processData(byte rxByte);
bool processCommand(byte rxByte);
protected:
bool disableKiss_;
2022-12-11 17:06:00 +00:00
bool usePrefix3_;
private:
bool isRawIdle_;
State state_;
2021-02-06 11:45:24 +00:00
DataType dataType_;
std::vector<byte> cmdBuffer_;
CircularBuffer<uint8_t, CfgSerialToRigQueueSize> serialToRigQueue_;
CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueue_;
CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueueIndex_;
};
} // Kiss
#endif // KISS_PROCESSOR_H