SLIPEncodedSerial.h 971 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Extends the Serial class to encode SLIP over serial
  3. */
  4. #ifndef SLIPEncodedSerial_h
  5. #define SLIPEncodedSerial_h
  6. #include "Arduino.h"
  7. #include <Stream.h>
  8. #include <HardwareSerial.h>
  9. class SLIPEncodedSerial: public Stream{
  10. private:
  11. enum erstate {CHAR, FIRSTEOT, SECONDEOT, SLIPESC } rstate;
  12. //the serial port used
  13. HardwareSerial * serial;
  14. public:
  15. //the serial port used
  16. SLIPEncodedSerial(HardwareSerial & );
  17. int available();
  18. int read();
  19. int peek();
  20. void flush();
  21. //same as Serial.begin
  22. void begin(unsigned long);
  23. //SLIP specific method which begins a transmitted packet
  24. void beginPacket();
  25. //SLIP specific method which ends a transmittedpacket
  26. void endPacket();
  27. // SLIP specific method which indicates that an EOT was received
  28. bool endofPacket();
  29. //overrides the Stream's write function to encode SLIP
  30. size_t write(uint8_t b);
  31. size_t write(const uint8_t *buffer, size_t size);
  32. //using Print::write;
  33. };
  34. #endif