Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: BufferSerial.h
- Revision:
- 6:17e3a28338dc
- Child:
- 7:0bc2bc07f2fe
diff -r aef6f39b9683 -r 17e3a28338dc BufferSerial.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BufferSerial.h Sat Nov 28 07:48:16 2020 +0000
@@ -0,0 +1,49 @@
+#ifndef BUFFER_SERIAL_H
+#define BUHHER_SERIAL_H
+
+// include
+#include "mbed.h"
+
+#ifndef SERIAL_RX_BUFFER_SIZE
+// RX Buffer Max Size
+#define SERIAL_RX_BUFFER_SIZE 128
+#endif
+
+#if (SERIAL_RX_BUFFER_SIZE>256)
+typedef uint16_t rx_buffer_index_t;
+#else
+typedef uint8_t rx_buffer_index_t;
+#endif
+
+class BufferSerial : public RawSerial
+{
+public:
+ // constructor
+ BufferSerial(PinName tx, PinName rx,int baud,int timeout);
+
+ // function of arduino serial
+ int available(void);
+ // return number of bytes available to read.
+ int read(void);
+ // return first byte of incoming data available (or -1 if no data is available)
+ size_t readBytesUntil(char charactor,char *buffer,int length);
+ // return number of bytes placed in the buffer
+
+ unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
+private:
+ // rx buffer array
+ //unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
+ // head index
+ volatile rx_buffer_index_t _rx_buffer_head;
+ volatile rx_buffer_index_t _rx_buffer_tail;
+ int timer_ms;
+ // attach rx
+ void serial_rx(void);
+
+ int timedRead();
+ Timer timer;
+ unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
+ unsigned long _startMillis; // used for timeout measurement
+};
+
+#endif