PX4-Autopilot icon indicating copy to clipboard operation
PX4-Autopilot copied to clipboard

serial: add txSpaceAvailable function

Open dakejahl opened this issue 4 weeks ago • 1 comments

Solved Problem

Adds a txSpaceAvailable() function to the Serial abstraction

Changelog Entry

For release notes:

serial: add txSpaceAvailable function

Context

I will be using this in an upcoming GPS driver PR to ensure the TX buffer is not full before injecting RTCM data.

dakejahl avatar Dec 09 '25 21:12 dakejahl

Just a quick comment: I think this functionality is good to have.

Just my 2 cent on the RTCM injection topic @dakejahl: I would propose one POLLIN fd and one POLLOUT fd on the uart instead. This way you would sleep until some work needs to be done (either reading from the UART as the buffer contains data, or writing to the UART as the buffer has space). Then there is no blocking logic at all: Wait until there is some work to do, do it, back to sleep.

alexcekay avatar Dec 09 '25 23:12 alexcekay

I've made some changes. The bytesAvailable function now returns -1 when there's an error and sets errno = EBADF when the device is not open. The posix/qurt txSpaceAvailable sets errno to ENOSYS which means Function not implemented and returns -1.

We might want to consider errno = EBADF for all of the other if (!_open) { return -1; } cases, although I don't think any code makes use of the errno.

dakejahl avatar Dec 12 '25 04:12 dakejahl