| 177 | } |
| 178 | |
| 179 | size_t SerialPort::readBytes(u8* buffer, size_t length) { |
| 180 | if (!buffer || length == 0) { |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | size_t count = 0; |
| 185 | u32 startTime = fl::millis(); |
| 186 | |
| 187 | while (count < length && (fl::millis() - startTime < mTimeoutMs)) { |
| 188 | if (available() > 0) { |
| 189 | int c = read(); |
| 190 | if (c != -1) { |
| 191 | buffer[count++] = static_cast<u8>(c); |
| 192 | startTime = fl::millis(); // Reset timeout on successful read |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return count; |
| 198 | } |
| 199 | |
| 200 | size_t SerialPort::readBytesUntil(char delimiter, u8* buffer, size_t length) { |
| 201 | if (!buffer || length == 0) { |