-
Notifications
You must be signed in to change notification settings - Fork 7.6k
RFQ: make TimedRead and TimedPeek virtual #11236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Hello imwhocodes, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Test Results 76 files 76 suites 12m 49s ⏱️ Results for commit 9401f23. |
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
@imwhocodes - I have a question: Currently, ESP32 Stream Class has Both are not virtual, but implemented in ESP32 HardwareSerial + CDC Classes has the Stream Class implementation by Inheritance. Therefore, with the current code, it is possible to execute Stream methods: // It should be tested within an ESP32-S3 using UART, HW CDC and OTG CDC
char buffer[100];
void setup() {
Serial.setTimeout(10000); // reading Stream methods timeout - 10 seconds
Serial.begin(115200);
}
void loop() {
Serial.println("===============================================================");
size_t numBytesRead = 0;
buffer[0] = '\0';
Serial.println("Send some text with up to 10 bytes using the Serial Monitor");
numBytesRead = Serial.readBytes(buffer, 10);
buffer[numBytesRead] = '\0';
Serial.printf("Got %d bytes [%s]\r\n", numBytesRead, buffer);
buffer[0] = '\0';
Serial.println("Send some text with a '#' that will terminate the Bytes reading");
numBytesRead = Serial.readBytesUntil('#', buffer, 10);
buffer[numBytesRead] = '\0';
Serial.printf("Got %d bytes [%s]\r\n", numBytesRead, buffer);
Serial.println("Send some text with a '#' that will terminate the String reading");
String Sbuffer = Serial.readStringUntil('#');
Serial.printf("Got %d bytes [%s]\r\n", Sbuffer.length() , Sbuffer.c_str());
} OUTPUT - respects the timeout correctly
@imwhocodes - Have you found an example that does work correctly? |
This is a request for comment / proof of concept
Right now
Stream::TimedRead()
andStream::TimedPeek()
are concrete functions insideStream
This mean that when a function that can wait up to a timeout (like
Stream::readBytes
,Stream::readBytesUntil
,Stream::readStringUntil
ecc) and there is nothing in the RX buffer the default implementation simply keep spinning in a tight/busy loop calling eitherChildClass::read()
orChildClass::peek()
This PR keep the default implementation of the two function but add virtual to it so each concrete child class (like
HardwareSerial
,HWCDC
) can implement an optimised version that relay on the FreeRTOS scheduler and not on busy-polling the interfaceIn this PR there is implementation for two interfaces