Skip to content
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

Reading from serial port always takes the full timeout of 1000 ms #12

Open
madMAx43v3r opened this issue Jan 25, 2018 · 4 comments
Open

Comments

@madMAx43v3r
Copy link

len = serial_port_->read(buffer, MAX_NOUT_SIZE);

What the hell dude? This line waits for 5000 frickin bytes to be read before processing the data!!! No wonder there is always a huge delay, it always hits the timeout of 1000 ms!

@henniah
Copy link

henniah commented Jan 25, 2018 via email

@sfowlr
Copy link
Member

sfowlr commented Jan 25, 2018

Not necessarily. The serial_port is initialized with the inter-byte timeout set to 100ms, so you'll be waiting up to, but not always 1000ms.

serial::Timeout my_timeout(100, 1000, 0, 1000, 0);

As long as there is no traffic on the serial port for at least the inter-byte timeout value, the function will return. This is typically the case as long as your baud rate is substantially high enough to accommodate a 100ms delay between u-blox serial message bursts.

If you're running a fast position update rate, you could reduce the 100ms inter-byte timeout to a smaller value if there's not at least 100ms between fix updates (if you're running at 10Hz, for example).

@madMAx43v3r
Copy link
Author

I'm running at 1 Hz, even at 10 Hz I got all 10 messages at the same time. This is a serious design flaw in the serial library, why would you ever want to read a specific number of bytes? Just take what's there and process it, there's no need for any timeouts whatsoever.
I got a little angry yesterday because I've been battling this issue for weeks now. I've just set MAX_NOUT_SIZE to 1 now and it works like a charm, ~60 ms delay instead of randomly between 0 and 1000 ms, depending on when you start your program. And who cares about performance, it's still less than 1% on a 1 GHz ARM.

@madMAx43v3r
Copy link
Author

Besides, looking at the code you can see that the inter-byte timeout has no effect whatsoever:
Serial::SerialImpl::read (uint8_t *buf, size_t size) { while (bytes_read < size) { if (waitReadable(timeout)) { ... } } }
It will just keep looping until bytes_read >= size or timeout_remaining_ms <= 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants