From 573dbfe576de6887a74fc1220d5cfbc009a2060d Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Tue, 14 Jul 2015 15:48:35 -0400 Subject: [PATCH] Simulator: record serial data as comments, not as G-code. We cheated before and sent the serial data in the simulator into the G-code reporter so it could be line-buffered and then recorded as comments in the trace-log. But this confuses the simulator console output and is harder to manage. Revert to sending serial-out data directly to the comment engine. Also be less chatty about startup when connecting to a UART. --- simulator/data_recorder.c | 14 ++++++++++++++ simulator/serial_sim.c | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/simulator/data_recorder.c b/simulator/data_recorder.c index 44109cd..7880675 100644 --- a/simulator/data_recorder.c +++ b/simulator/data_recorder.c @@ -79,6 +79,20 @@ void record_pin(int pin, int32_t state, uint64_t t) { values[pin] = state; } +static char cmt[300]; +static char *pcmt=cmt; +void record_comment_stream(char ch) { + if (ch == '\r' || ch == '\n') { + record_comment(cmt); + pcmt = cmt; + *pcmt = 0; + } + else if (ch && pcmt < cmt+sizeof(cmt)-1) { + *pcmt++ = ch; + *pcmt = 0; + } +} + void record_comment(const char * msg) { if (!file) return; fprintf(file, "# %s\n", msg); diff --git a/simulator/serial_sim.c b/simulator/serial_sim.c index d9331ef..29e8948 100644 --- a/simulator/serial_sim.c +++ b/simulator/serial_sim.c @@ -60,7 +60,6 @@ static void open_tty(const char *devname) sim_assert(serial_fd != -1, "couldn't open serial port"); sim_assert(isatty(serial_fd), "not a TTY"); - sim_info("configuring port"); // Get the current options for the port if (tcgetattr(serial_fd, &options) != 0) { sim_error("tcgetattr"); @@ -125,7 +124,7 @@ uint8_t serial_popchar(void) { // send one character void serial_writechar(uint8_t data) { sim_assert(serial_initialised, "serial interface not initialised"); - sim_gcode_ch(data); + record_comment_stream((char)data); if (serial_fd) { ssize_t count; count = write(serial_fd, &data, 1); @@ -137,7 +136,7 @@ void serial_writechar(uint8_t data) { void serial_writestr(uint8_t *data) { const char *str = (char *)data; sim_assert(serial_initialised, "serial interface not initialised"); - sim_gcode(str); + record_comment(str); if (serial_fd) { ssize_t count; count = write(serial_fd, str, strlen(str));