refactor: make cel_serial_read non-blocking
Drop timeout_ms; read now returns immediately with whatever data is available (0 if none), so callers don't block the rest of their loop waiting on serial I/O. telemetry's poll loop now sleeps interval_ms itself between empty reads via a small sleep_ms helper.
This commit is contained in:
+2
-3
@@ -37,12 +37,11 @@ void cel_serial_close(cel_serial_port* port) {
|
||||
free(port);
|
||||
}
|
||||
|
||||
size_t cel_serial_read(cel_serial_port* port, uint8_t* buf, size_t len, int timeout_ms) {
|
||||
size_t cel_serial_read(cel_serial_port* port, uint8_t* buf, size_t len) {
|
||||
(void)port;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
(void)timeout_ms;
|
||||
/* TODO: platform-specific read */
|
||||
/* TODO: platform-specific non-blocking read */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -15,8 +15,9 @@ cel_serial_port* cel_serial_open(char const* path, int baud_rate);
|
||||
/* Close and free the serial port */
|
||||
void cel_serial_close(cel_serial_port* port);
|
||||
|
||||
/* Read up to len bytes. Returns bytes read, 0 on timeout/error. */
|
||||
size_t cel_serial_read(cel_serial_port* port, uint8_t* buf, size_t len, int timeout_ms);
|
||||
/* Read up to len bytes without blocking.
|
||||
* Returns bytes read immediately available, or 0 if none/error. */
|
||||
size_t cel_serial_read(cel_serial_port* port, uint8_t* buf, size_t len);
|
||||
|
||||
/* Write data. Returns bytes written, 0 on error. */
|
||||
size_t cel_serial_write(cel_serial_port* port, uint8_t const* buf, size_t len);
|
||||
|
||||
Reference in New Issue
Block a user