ESP32_ChinaDieselHeater_Con.../Arduino/SenderTrial2/BluetoothAbstract.h
rljonesau b128e51880 Converted to class based Bluetooth management. HC-05 tested on ESP32.
Cannot test the inbuilt ESP32 bluetooth - we blow the FLASH size!
2018-11-01 05:57:21 +11:00

48 lines
1 KiB
C++

#include <Arduino.h>
class CProtocol;
extern void Command_Interpret(const char* pLine); // decodes received command lines, implemented in main .ino file!
struct sRxLine {
char Line[64];
int Len;
sRxLine() {
clear();
}
bool append(char val) {
if(Len < (sizeof(Line) - 1)) {
Line[Len++] = val;
Line[Len] = 0;
return true;
}
return false;
}
void clear() {
Line[0] = 0;
Len = 0;
}
};
class CBluetoothAbstract {
protected:
sRxLine _rxLine;
public:
virtual void init() {};
virtual void sendFrame(const char* pHdr, const CProtocol& Frame, bool lineterm=true) {
DebugPort.print(millis());
DebugPort.print("ms ");
DebugReportFrame(pHdr, Frame, lineterm ? "\r\n" : " ");
};
virtual void check() {};
virtual void collectRxData(char rxVal) {
if(isControl(rxVal)) { // "End of Line"
Command_Interpret(_rxLine.Line);
_rxLine.clear();
}
else {
_rxLine.append(rxVal); // append new char to our Rx buffer
}
};
};