diff options
Diffstat (limited to 'robot')
-rw-r--r-- | robot/makefile | 4 | ||||
-rw-r--r-- | robot/sim.c | 9 | ||||
-rw-r--r-- | robot/sim.h | 11 |
3 files changed, 20 insertions, 4 deletions
diff --git a/robot/makefile b/robot/makefile index f65552a..11e8509 100644 --- a/robot/makefile +++ b/robot/makefile @@ -6,7 +6,7 @@ MCU ?= atmega168 AVRDUDE_DEVICE ?= m168 PORT ?= /dev/ttyACM0 -# SIM = true +SIM = true CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os LDFLAGS=-Wl,-gc-sections -Wl,-relax @@ -19,7 +19,7 @@ HEADERS := $(filter-out sim.h, $(wildcard *.h)) include ../shared/makefile # simulation -CFLAGS += $(if $(SIM), -DW2_SIM, -mcall-prologues -mmcu=$(MCU)) +CFLAGS += $(if $(SIM), -DW2_SIM -DDBG_ENABLE_COLOR, -mcall-prologues -mmcu=$(MCU)) LDFLAGS += $(if $(SIM), , -lpololu_$(DEVICE)) PREFIX := $(if $(SIM), , avr-) SOURCES += $(if $(SIM), sim.c, ) 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; diff --git a/robot/sim.h b/robot/sim.h index 23b47f1..864a43a 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -24,6 +24,16 @@ extern bool g_w2_sim_headless; #define DBG_BYTES_PER_LINE 16 // debug colors +#define COL_BLK "" +#define COL_RED "" +#define COL_GRN "" +#define COL_YEL "" +#define COL_BLU "" +#define COL_MAG "" +#define COL_CYN "" +#define COL_WHT "" +#define COL_RST "" +#ifdef DBG_ENABLE_COLOR #define COL_BLK "\e[0;30m" #define COL_RED "\e[0;31m" #define COL_GRN "\e[0;32m" @@ -33,6 +43,7 @@ extern bool g_w2_sim_headless; #define COL_CYN "\e[0;36m" #define COL_WHT "\e[0;37m" #define COL_RST "\e[0m" +#endif // debug stdout print macros #define simprintf(message, ...) if (!g_w2_sim_headless) printf(COL_RED "[SIM] " COL_RST message, ##__VA_ARGS__) |