makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / test / msp_native / mock_serial.h
blob970a12d586315e576f6ff01abbbfcf84c3b6bea2
1 #pragma once
3 #include <string>
4 #include "msp.h"
6 // Mock the serial port using a string stream class
7 // This will allow us to assert what gets sent on the serial port
8 class StringStream : public Stream
10 public:
11 StringStream(std::string &s) : buf(s), position(0) { }
13 // Stream methods
14 int available() { return buf.length() - position; }
15 int read() { return position < buf.length() ? buf[position++] : -1; }
16 int peek() { return position < buf.length() ? buf[position] : -1; }
17 void flush() { }
19 // Print methods
20 size_t write(uint8_t c)
22 buf += (char)c; return 1;
24 size_t write(uint8_t *c, int l)
26 for (int i=0; i<l ; buf += *c, i++, c++);
27 return l;
30 private:
31 std::string &buf;
32 unsigned int length;
33 unsigned int position;