forest-all-around/osc/lib/OSC/SLIPEncodedSerial.h
Dooho Yi fa1acde77b rename osc8266/ -> osc/
+ (planned) add support for esp32
2022-05-04 15:50:38 +09:00

60 lines
1 KiB
C++

/*
Extends the Serial class to encode SLIP over serial
*/
#ifndef SLIPEncodedSerial_h
#define SLIPEncodedSerial_h
#include "Arduino.h"
#include <Stream.h>
#ifdef ARDUINO_API_VERSION
#include <api/HardwareSerial.h>
#else
#include <HardwareSerial.h>
#endif
class SLIPEncodedSerial: public Stream{
private:
enum erstate {CHAR, FIRSTEOT, SECONDEOT, SLIPESC } rstate;
//the serial port used
HardwareSerial * serial;
public:
//the serial port used
SLIPEncodedSerial(HardwareSerial & );
int available();
int read();
int peek();
void flush();
//same as Serial.begin
void begin(unsigned long);
//SLIP specific method which begins a transmitted packet
void beginPacket();
//SLIP specific method which ends a transmittedpacket
void endPacket();
// SLIP specific method which indicates that an EOT was received
bool endofPacket();
//overrides the Stream's write function to encode SLIP
size_t write(uint8_t b);
size_t write(const uint8_t *buffer, size_t size);
//using Print::write;
};
#endif