|
26 | 26 | class Stream : public Print |
27 | 27 | { |
28 | 28 | public: |
29 | | - Stream() : _timeout(1000), read_error(0) {} |
30 | | - virtual int available() = 0; |
31 | | - virtual int read() = 0; |
32 | | - virtual int peek() = 0; |
33 | | - virtual void flush() = 0; |
| 29 | + constexpr Stream() : _timeout(1000), read_error(0) {} |
| 30 | + virtual int available() = 0; |
| 31 | + virtual int read() = 0; |
| 32 | + virtual int peek() = 0; |
34 | 33 |
|
35 | | - void setTimeout(unsigned long timeout); |
36 | | - bool find(const char *target); |
37 | | - bool find(const uint8_t *target) { return find ((const char *)target); } |
38 | | - bool find(const char *target, size_t length); |
39 | | - bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); } |
40 | | - bool findUntil(const char *target, char *terminator); |
41 | | - bool findUntil(const uint8_t *target, char *terminator) { return findUntil((const char *)target, terminator); } |
42 | | - bool findUntil(const char *target, size_t targetLen, char *terminate, size_t termLen); |
43 | | - bool findUntil(const uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); } |
44 | | - long parseInt(); |
45 | | - long parseInt(char skipChar); |
46 | | - float parseFloat(); |
47 | | - float parseFloat(char skipChar); |
48 | | - size_t readBytes(char *buffer, size_t length); |
49 | | - size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); } |
50 | | - size_t readBytesUntil(char terminator, char *buffer, size_t length); |
51 | | - size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); } |
52 | | - String readString(size_t max = 120); |
53 | | - String readStringUntil(char terminator, size_t max = 120); |
54 | | - int getReadError() { return read_error; } |
55 | | - void clearReadError() { setReadError(0); } |
| 34 | + void setTimeout(unsigned long timeout); |
| 35 | + bool find(const char *target); |
| 36 | + |
| 37 | + bool find(const uint8_t *target) |
| 38 | + { |
| 39 | + return find ((const char *)target); |
| 40 | + } |
| 41 | + |
| 42 | + bool find(const String &target) |
| 43 | + { |
| 44 | + return find(target.c_str()); |
| 45 | + } |
| 46 | + |
| 47 | + bool find(const char *target, size_t length); |
| 48 | + |
| 49 | + bool find(const uint8_t *target, size_t length) |
| 50 | + { |
| 51 | + return find ((const char *)target, length); |
| 52 | + } |
| 53 | + |
| 54 | + bool find(const String &target, size_t length) |
| 55 | + { |
| 56 | + return find(target.c_str(), length); |
| 57 | + } |
| 58 | + |
| 59 | + bool findUntil(const char *target, const char *terminator); |
| 60 | + |
| 61 | + bool findUntil(const uint8_t *target, const char *terminator) |
| 62 | + { |
| 63 | + return findUntil((const char *)target, terminator); |
| 64 | + } |
| 65 | + |
| 66 | + bool findUntil(const String &target, const char *terminator) |
| 67 | + { |
| 68 | + return findUntil(target.c_str(), terminator); |
| 69 | + } |
| 70 | + |
| 71 | + bool findUntil(const char *target, const String &terminator) |
| 72 | + { |
| 73 | + return findUntil(target, terminator.c_str()); |
| 74 | + } |
| 75 | + |
| 76 | + bool findUntil(const String &target, const String &terminator) |
| 77 | + { |
| 78 | + return findUntil(target.c_str(), terminator.c_str()); |
| 79 | + } |
| 80 | + |
| 81 | + bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); |
| 82 | + |
| 83 | + bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) |
| 84 | + { |
| 85 | + return findUntil((const char *)target, targetLen, terminate, termLen); |
| 86 | + } |
| 87 | + |
| 88 | + bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); |
| 89 | + bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); |
| 90 | + bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); |
| 91 | + |
| 92 | + long parseInt(); |
| 93 | + long parseInt(char skipChar); |
| 94 | + |
| 95 | + float parseFloat(); |
| 96 | + float parseFloat(char skipChar); |
| 97 | + |
| 98 | + size_t readBytes(char *buffer, size_t length); |
| 99 | + |
| 100 | + size_t readBytes(uint8_t *buffer, size_t length) |
| 101 | + { |
| 102 | + return readBytes((char *)buffer, length); |
| 103 | + } |
| 104 | + |
| 105 | + size_t readBytesUntil(char terminator, char *buffer, size_t length); |
| 106 | + |
| 107 | + size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) |
| 108 | + { |
| 109 | + return readBytesUntil(terminator, (char *)buffer, length); |
| 110 | + } |
| 111 | + |
| 112 | + //////////////////////////////////////////////////////////// |
| 113 | + String readString(size_t max = 512); |
| 114 | + String readStringUntil(char terminator, size_t max = 512); |
| 115 | + |
| 116 | + // KH, to not use String |
| 117 | + char* readCharsUntil(char terminator, size_t max = 512); |
| 118 | + //////////////////////////////////////////////////////////// |
| 119 | + |
| 120 | + int getReadError() |
| 121 | + { |
| 122 | + return read_error; |
| 123 | + } |
| 124 | + |
| 125 | + void clearReadError() |
| 126 | + { |
| 127 | + setReadError(0); |
| 128 | + } |
| 129 | + |
56 | 130 | protected: |
57 | | - void setReadError(int err = 1) { read_error = err; } |
58 | | - unsigned long _timeout; |
59 | | - |
60 | | - // KH |
61 | | - int timedRead(); |
62 | | - ////// |
63 | | - |
| 131 | + void setReadError(int err = 1) |
| 132 | + { |
| 133 | + read_error = err; |
| 134 | + } |
| 135 | + |
| 136 | + unsigned long _timeout; |
| 137 | + |
| 138 | + // KH |
| 139 | + int timedRead(); |
| 140 | + int timedPeek(); |
| 141 | + int peekNextDigit(); |
| 142 | + ////// |
| 143 | + |
64 | 144 | private: |
65 | | - char read_error; |
66 | | - |
67 | | - //int timedRead(); |
68 | | - |
69 | | - int timedPeek(); |
70 | | - int peekNextDigit(); |
| 145 | + char read_error; |
71 | 146 | }; |
72 | 147 |
|
73 | | -#endif |
| 148 | +#endif |
| 149 | + |
0 commit comments