2021-02-02 15:53:28 +00:00
|
|
|
#ifndef KISS_PROCESSOR_H
|
|
|
|
#define KISS_PROCESSOR_H
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2021-10-22 19:09:17 +00:00
|
|
|
#include <DebugLog.h>
|
2021-02-02 15:53:28 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2021-02-12 14:33:25 +00:00
|
|
|
#define CIRCULAR_BUFFER_INT_SAFE
|
|
|
|
#include <CircularBuffer.h>
|
|
|
|
|
2021-02-02 15:53:28 +00:00
|
|
|
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,
|
2021-02-02 15:53:28 +00:00
|
|
|
GetCmd,
|
|
|
|
GetData,
|
|
|
|
GetP,
|
|
|
|
GetSlotTime,
|
|
|
|
Escape
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Cmd {
|
|
|
|
Data = 0x00,
|
2021-05-26 16:11:33 +00:00
|
|
|
TxDelay = 0x01,
|
2021-02-02 15:53:28 +00:00
|
|
|
P = 0x02,
|
|
|
|
SlotTime = 0x03,
|
2021-05-26 16:11:33 +00:00
|
|
|
TxTail = 0x04,
|
2021-02-08 18:30:23 +00:00
|
|
|
SetHardware = 0x06,
|
|
|
|
SignalReport = 0x07,
|
2021-10-20 09:58:43 +00:00
|
|
|
RebootRequested = 0x08,
|
2021-02-02 15:53:28 +00:00
|
|
|
NoCmd = 0x80
|
|
|
|
};
|
|
|
|
|
2021-02-05 16:57:06 +00:00
|
|
|
enum DataType {
|
|
|
|
Raw = 0,
|
2021-10-20 09:58:43 +00:00
|
|
|
Control,
|
|
|
|
Reboot
|
2021-02-05 16:57:06 +00:00
|
|
|
};
|
2021-02-06 13:53:19 +00:00
|
|
|
|
2021-02-12 14:33:25 +00:00
|
|
|
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);
|
|
|
|
static void ICACHE_RAM_ATTR queueRigToSerialIsr(Cmd cmd, const byte *packet, int packetLength);
|
2021-02-12 14:33:25 +00:00
|
|
|
|
2021-02-12 14:43:18 +00:00
|
|
|
void queueSerialToRig(Cmd cmd, const byte *packet, int packetLength);
|
2021-02-12 14:33:25 +00:00
|
|
|
|
|
|
|
bool processRigToSerial();
|
|
|
|
bool processSerialToRig();
|
2021-02-06 13:53:19 +00:00
|
|
|
|
2021-02-02 15:53:28 +00:00
|
|
|
protected:
|
|
|
|
virtual bool onRigTxBegin() = 0;
|
2021-02-02 15:57:36 +00:00
|
|
|
virtual void onRigTx(byte b) = 0;
|
2021-02-02 15:53:28 +00:00
|
|
|
virtual void onRigTxEnd() = 0;
|
2021-02-12 14:33:25 +00:00
|
|
|
virtual void onRigPacket(void *packet, int packetLength) = 0;
|
|
|
|
|
2021-02-02 15:57:36 +00:00
|
|
|
virtual void onSerialTx(byte b) = 0;
|
2021-02-02 15:53:28 +00:00
|
|
|
virtual bool onSerialRxHasData() = 0;
|
2021-02-02 15:57:36 +00:00
|
|
|
virtual bool onSerialRx(byte *b) = 0;
|
2021-02-02 15:53:28 +00:00
|
|
|
|
|
|
|
virtual void onControlCommand(Cmd cmd, byte value) = 0;
|
2021-02-05 16:57:06 +00:00
|
|
|
virtual void onRadioControlCommand(const std::vector<byte> &command) = 0;
|
2021-10-20 09:58:43 +00:00
|
|
|
virtual void onRebootCommand() = 0;
|
2021-02-02 15:53:28 +00:00
|
|
|
|
|
|
|
private:
|
2021-02-05 16:57:06 +00:00
|
|
|
bool receiveByte(byte rxByte);
|
2021-10-26 10:09:43 +00:00
|
|
|
bool receiveByteRaw(byte rxByte);
|
|
|
|
bool receiveByteKiss(byte rxByte);
|
|
|
|
|
2021-02-05 16:57:06 +00:00
|
|
|
void processData(byte rxByte);
|
|
|
|
bool processCommand(byte rxByte);
|
|
|
|
|
2021-10-26 10:09:43 +00:00
|
|
|
protected:
|
|
|
|
bool disableKiss_;
|
|
|
|
|
2021-02-02 15:53:28 +00:00
|
|
|
private:
|
2021-10-26 10:09:43 +00:00
|
|
|
bool isRawIdle_;
|
2021-02-02 15:53:28 +00:00
|
|
|
State state_;
|
2021-02-06 11:45:24 +00:00
|
|
|
DataType dataType_;
|
2021-02-05 16:57:06 +00:00
|
|
|
std::vector<byte> cmdBuffer_;
|
2021-02-12 14:33:25 +00:00
|
|
|
|
|
|
|
static CircularBuffer<uint8_t, CfgSerialToRigQueueSize> serialToRigQueue_;
|
|
|
|
static CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueue_;
|
|
|
|
static CircularBuffer<uint8_t, CfgRigToSerialQueueSize> rigToSerialQueueIndex_;
|
2021-02-02 15:53:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Kiss
|
|
|
|
|
|
|
|
#endif // KISS_PROCESSOR_H
|