forked from sparkfun/WiFly-Shield
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ParsedStream.h
58 lines (38 loc) · 831 Bytes
/
ParsedStream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Based on ring buffer implementation in `HardwareSerial`.
// TODO: Do proper license stuff
#ifndef __PARSED_STREAM_H__
#define __PARSED_STREAM_H__
#define RX_BUFFER_SIZE 64
#include <string.h>
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
//#include "SpiUart.h"
struct ring_buffer {
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
};
const static char *MATCH_TOKEN = "*CLOS*";
class ParsedStream {
private:
ring_buffer _rx_buffer;
void getByte();
void storeByte(unsigned char c);
unsigned int bytes_matched;
uint8_t available(bool raw);
int freeSpace();
bool _closed;
Stream* _uart;
public:
ParsedStream();
void begin(Stream* theUart);
uint8_t available(void);
int read(void);
int peek(void);
bool closed();
void reset();
};
#endif