diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-29 13:15:58 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-29 13:15:58 +0200 |
commit | 529f067e65b0146c5afa150103809ba5e09869b7 (patch) | |
tree | 80fa7a44ce8f5d43b2cc04dc1d0fd1fb79eb254e /robot/sim.c | |
parent | dbd005573295293d35647dc0e9feb2beec48a31c (diff) |
client/robot sim connected
Diffstat (limited to 'robot/sim.c')
-rw-r--r-- | robot/sim.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/robot/sim.c b/robot/sim.c index 6283694..34e4932 100644 --- a/robot/sim.c +++ b/robot/sim.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <unistd.h> #include <termios.h> +#include <fcntl.h> #include "sim.h" #include "../shared/consts.h" @@ -78,10 +79,11 @@ void serial_send(char* message, unsigned int length) { if (g_w2_sim_headless) { for (unsigned int byte = 0; byte < length; byte++) putc(message[byte] & 0xff, stdout); + fflush(stdout); return; } - if (DBG_ENABLE_PRINTFUNC) simprintfunc("serial_send", "<%u byte%s>", length, length == 1 ? "" : "s"); + simprintfunc("serial_send", "0x%02x", (uint8_t) message[0]); } void serial_receive_ring(char* buffer, unsigned char size) { @@ -98,11 +100,12 @@ void w2_sim_setup(int argc, char **argv) { g_w2_sim_headless = true; // disable echo and enable raw mode + fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); struct termios term; tcgetattr(STDIN_FILENO, &term); term.c_lflag &= ~(ECHO | ICANON); term.c_cc[VTIME] = 0; - term.c_cc[VMIN] = 0; + term.c_cc[VMIN] = 1; tcsetattr(STDIN_FILENO, 0, &term); // debug error @@ -110,6 +113,8 @@ void w2_sim_setup(int argc, char **argv) { } void w2_sim_cycle_begin() { + fflush(stdout); + // read bytes from stdin while(read(STDIN_FILENO, (g_w2_serial_buffer + sizeof(char) * g_w2_serial_buffer_head), 1) > 0) g_w2_serial_buffer_head = (g_w2_serial_buffer_head + 1) % W2_SERIAL_READ_BUFFER_SIZE; |