diff options
Diffstat (limited to 'robot')
| -rw-r--r-- | robot/- | 0 | ||||
| -rw-r--r-- | robot/makefile | 4 | ||||
| -rw-r--r-- | robot/readme.md | 9 | ||||
| -rw-r--r-- | robot/sim.c | 9 | ||||
| -rw-r--r-- | robot/sim.h | 14 | 
5 files changed, 30 insertions, 6 deletions
| diff --git a/robot/- b/robot/- deleted file mode 100644 index e69de29..0000000 --- a/robot/- +++ /dev/null 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/readme.md b/robot/readme.md index e6ab294..8995dfb 100644 --- a/robot/readme.md +++ b/robot/readme.md @@ -22,7 +22,14 @@ SIM = true`, the robot code can be compiled for desktop debugging instead. all  used pololu functions must be manually implemented in sim.c for this to work,  but it allows easier debugging. *it's important that the `orangutan_shim.h`  header is used instead of including `<pololu/orangutan.h>` directly for this to -keep working!* +keep working!* if you want to use the simulation robot code with the client, +compile the sim like normal, and use `socat` to create a pseudo-tty and foward +stdio. this pseudo-tty can be used as the com port argument for the client. +here's an example command that creates a tty device in this folder: + +``` +./a.out headless | socat pty,raw,echo=0,link=tty - +```  ## module hierarchy 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 249414d..5dbd936 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -18,12 +18,13 @@ extern bool g_w2_sim_headless;  #define DBG_ENABLE_CYCLEINFO (0)  #define DBG_ENABLE_SERIAL (1) -#define DBG_MAX_CYCLES (10) +#define DBG_MAX_CYCLES (-1)  // debug print options  #define DBG_BYTES_PER_LINE 16  // debug colors +#ifdef DBG_ENABLE_COLOR  #define COL_BLK "\e[0;30m"  #define COL_RED "\e[0;31m"  #define COL_GRN "\e[0;32m" @@ -33,6 +34,17 @@ extern bool g_w2_sim_headless;  #define COL_CYN "\e[0;36m"  #define COL_WHT "\e[0;37m"  #define COL_RST "\e[0m" +#else +#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 "" +#endif  // debug stdout print macros  #define simprintf(message, ...) if (!g_w2_sim_headless) printf(COL_RED "[SIM] " COL_RST message, ##__VA_ARGS__) |