Line | |
---|
1 | #include "Stream.h"
|
---|
2 | #include "trace.h"
|
---|
3 | #include <iostream>
|
---|
4 | #include <Arduino.h>
|
---|
5 |
|
---|
6 | Stream::Stream() {
|
---|
7 | this->expectBuffer = new Buffer();
|
---|
8 | this->_error = false;
|
---|
9 | this->_written = 0;
|
---|
10 | }
|
---|
11 |
|
---|
12 | size_t Stream::write(uint8_t b) {
|
---|
13 | this->_written++;
|
---|
14 | TRACE(std::hex << (unsigned int)b);
|
---|
15 | if (this->expectBuffer->available()) {
|
---|
16 | uint8_t expected = this->expectBuffer->next();
|
---|
17 | if (expected != b) {
|
---|
18 | this->_error = true;
|
---|
19 | TRACE("!=" << (unsigned int)expected);
|
---|
20 | }
|
---|
21 | } else {
|
---|
22 | this->_error = true;
|
---|
23 | }
|
---|
24 | TRACE("\n"<< std::dec);
|
---|
25 | return 1;
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | bool Stream::error() {
|
---|
30 | return this->_error;
|
---|
31 | }
|
---|
32 |
|
---|
33 | void Stream::expect(uint8_t *buf, size_t size) {
|
---|
34 | this->expectBuffer->add(buf,size);
|
---|
35 | }
|
---|
36 |
|
---|
37 | uint16_t Stream::length() {
|
---|
38 | return this->_written;
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.