Skip to content

Commit

Permalink
fix hostuart checking available data
Browse files Browse the repository at this point in the history
  • Loading branch information
d-a-v committed Feb 11, 2024
1 parent 1fd58fb commit 7fbd658
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 /, ,$@)) <----"
Expand Down
13 changes: 4 additions & 9 deletions tests/host/common/ArduinoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/host/common/HostUART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 6 additions & 1 deletion tests/host/common/MockUART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/host/common/mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7fbd658

Please sign in to comment.