From 7fbd65830bfb636d4883bb09ba2bbad808365383 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Sun, 11 Feb 2024 01:06:37 +0100 Subject: [PATCH] fix hostuart checking available data --- tests/host/Makefile | 2 +- tests/host/common/ArduinoMain.cpp | 13 ++++--------- tests/host/common/HostUART.cpp | 2 +- tests/host/common/MockUART.cpp | 7 ++++++- tests/host/common/mock.h | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index 299ad4d584..e6eaa18553 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -400,7 +400,7 @@ ifeq ($(INO),) else %: %.ino.cpp.o $(BINDIR)/fullcore.a FORCE - $(VERBLD) $(CXX) $(LDFLAGS) $< $(BINDIR)/fullcore.a $(LIBSSL) -o $@ + $(VERBLD) $(CXX) $(LDFLAGS) $< $(BINDIR)/fullcore.a $(LIBSSL) -o $@ $(ENDLDFLAGS) mkdir -p $(BINDIR)/$(lastword $(subst /, ,$@)) ln -sf $@ $(BINDIR)/$(lastword $(subst /, ,$@)) @echo "----> $(BINDIR)/$(lastword $(subst /, ,$@))/$(lastword $(subst /, ,$@)) <----" diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index bda231418e..bc00aead14 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -116,14 +116,8 @@ static int mock_stop_uart(void) static uint8_t mock_read_uart(void) { - uint8_t ch = 0; - int ret = read(STDIN, &ch, 1); - if (ret == -1) - { - perror("read(STDIN,1)"); - return 0; - } - return (ret == 1) ? ch : 0; + uint8_t ch = 0; + return (read(STDIN, &ch, 1) == 1) ? ch : 0; } void help(const char* argv0, int exitcode) @@ -225,7 +219,7 @@ int main(int argc, char* const argv[]) for (;;) { - int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:1s:B:U:", options, NULL); + int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:1B:U:", options, NULL); if (n < 0) break; switch (n) @@ -343,6 +337,7 @@ int main(int argc, char* const argv[]) if (!fast) usleep(1000); // not 100% cpu, max 1000 loops per second loop(); + loop_end(); check_incoming_udp(); if (run_once) diff --git a/tests/host/common/HostUART.cpp b/tests/host/common/HostUART.cpp index 626da1ce45..96d9b775e7 100644 --- a/tests/host/common/HostUART.cpp +++ b/tests/host/common/HostUART.cpp @@ -83,7 +83,7 @@ size_t hostsp_write(const void* data, size_t len) return len; } -size_t hostsp_read() +char hostsp_read() { char c; spcheck("read(1)", sp_blocking_read(hostPort, &c, 1, timeout_ms)); diff --git a/tests/host/common/MockUART.cpp b/tests/host/common/MockUART.cpp index f00909f3a5..aea7a1acc0 100644 --- a/tests/host/common/MockUART.cpp +++ b/tests/host/common/MockUART.cpp @@ -192,7 +192,12 @@ extern "C" size_t uart_read(uart_t* uart, char* userbuffer, size_t usersize) { if (hostBaudrate) - return hostsp_read(); + { + if (!hostsp_available()) + return 0; + *userbuffer = hostsp_read(); + return 1; + } if (uart == NULL || !uart->rx_enabled) return 0; diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index 27b1c0e7cf..9a2a3f1a7f 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -189,7 +189,7 @@ void hostsp_open(const char* port, int baud = 9600, int bit = 8, int parit int control = 0); size_t hostsp_write(char c); size_t hostsp_write(const void* data, size_t len); -size_t hostsp_read(); +char hostsp_read(); size_t hostsp_read(void* data, size_t len); size_t hostsp_availableForWrite(); size_t hostsp_available(); // for read