forked from ExpressLRS/ExpressLRS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock_serial.h
More file actions
25 lines (21 loc) · 743 Bytes
/
mock_serial.h
File metadata and controls
25 lines (21 loc) · 743 Bytes
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
#pragma once
#include <Arduino.h>
#include "msp.h"
// Mock the serial port using a string stream class
// This will allow us to assert what gets sent on the serial port
class StringStream : public Stream
{
public:
StringStream(String &s) : string(s), position(0) { }
// Stream methods
virtual int available() { return string.length() - position; }
virtual int read() { return position < string.length() ? string[position++] : -1; }
virtual int peek() { return position < string.length() ? string[position] : -1; }
virtual void flush() { };
// Print methods
virtual size_t write(uint8_t c) { string += (char)c; return 1; };
private:
String &string;
unsigned int length;
unsigned int position;
};