updated protocol to use better ascii chars
This commit is contained in:
@@ -18,15 +18,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class SerialConnection
|
||||
{
|
||||
private:
|
||||
int serialBufferSize = 512;
|
||||
char serialBuffer[512];
|
||||
char serialData[512] = {0};
|
||||
|
||||
const char packetStartMarker = '<';
|
||||
const char packetEndMarker = '>';
|
||||
int serialBufferSize = 265;
|
||||
char serialBuffer[265];
|
||||
|
||||
// Receiving a new packet
|
||||
boolean newSerialData = false;
|
||||
@@ -41,34 +39,21 @@ class SerialConnection
|
||||
Stream *serialRefrence;
|
||||
|
||||
public:
|
||||
void init(int serialIndex, unsigned long serialBaud);
|
||||
void send(char * data);
|
||||
const char packetStartMarker = 180;
|
||||
const char packetMidMarker = 196;
|
||||
const char packetEndMarker = 195;
|
||||
|
||||
void init(HardwareSerial &serialHandle, unsigned long serialBaud);
|
||||
void send(char* data);
|
||||
char* handle();
|
||||
char* getPacketMarker(int type);
|
||||
int getBufferSize();
|
||||
|
||||
};
|
||||
|
||||
void SerialConnection::init(int serialIndex, unsigned long serialBaud) {
|
||||
if (serialIndex == 0) {
|
||||
Serial.begin(serialBaud);
|
||||
serialRefrence = &Serial;
|
||||
}
|
||||
|
||||
else if (serialIndex == 1) {
|
||||
Serial1.begin(serialBaud);
|
||||
serialRefrence = &Serial1;
|
||||
}
|
||||
|
||||
else if (serialIndex == 2) {
|
||||
Serial2.begin(serialBaud);
|
||||
serialRefrence = &Serial2;
|
||||
}
|
||||
|
||||
else if (serialIndex == 3) {
|
||||
Serial3.begin(serialBaud);
|
||||
serialRefrence = &Serial3;
|
||||
}
|
||||
void SerialConnection::init(HardwareSerial &serialHandle, unsigned long serialBaud) {
|
||||
// serialBuffer[serialBufferSize] = {0};
|
||||
serialRefrence = &serialHandle;
|
||||
serialHandle.begin(serialBaud);
|
||||
};
|
||||
|
||||
char* SerialConnection::handle() {
|
||||
@@ -105,18 +90,10 @@ char* SerialConnection::handle() {
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void SerialConnection::send(char * data) {
|
||||
void SerialConnection::send(char* data) {
|
||||
serialRefrence->println(data);
|
||||
};
|
||||
|
||||
char* SerialConnection::getPacketMarker(int type) {
|
||||
if (type == 0) {
|
||||
return "<";
|
||||
} else {
|
||||
return ">";
|
||||
}
|
||||
};
|
||||
|
||||
int SerialConnection::getBufferSize() {
|
||||
return (int)serialBufferSize;
|
||||
};
|
Reference in New Issue
Block a user