diff --git a/gcode_parse.c b/gcode_parse.c index 1eb4eb0..16c4992 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -14,6 +14,9 @@ #include "sersendf.h" #include "gcode_process.h" +#ifdef SIMULATOR + #include "simulator.h" +#endif /// current or previous gcode word /// for working out what to do with data just received @@ -102,7 +105,9 @@ void gcode_parse_char(uint8_t c) { // uppercase if (c >= 'a' && c <= 'z') c &= ~32; - +#ifdef SIMULATOR + record_comment_stream(c); +#endif // process previous field if (last_field) { // check if we're seeing a new field or end of line diff --git a/simulator.h b/simulator.h index 13d254d..33830d2 100644 --- a/simulator.h +++ b/simulator.h @@ -45,6 +45,7 @@ #include #include +#include "simulator/data_recorder.h" #define PROGMEM #define PGM_P const char * diff --git a/simulator/data_recorder.c b/simulator/data_recorder.c index b181dc9..c0d6170 100644 --- a/simulator/data_recorder.c +++ b/simulator/data_recorder.c @@ -50,7 +50,31 @@ void record_pin(int pin, bool state, uint32_t t) { // Naive format: each line contains all values, beginning with the time fprintf(file, "%u", t); for (int i = 0; i < pin_count; i++) - fprintf(file, "\t%u", values[i]); + fprintf(file, " %u", values[i]); fprintf(file, "\n"); fflush(file); } + +static char comment_buffer[300]; +static int comment_buffer_index; +void record_comment_stream(char ch) { + // Got CR, LF or buffer full + if ( comment_buffer_index == sizeof(comment_buffer)-1 || + ch == '\r' || ch == '\n' || ch == 0 ) { + + // Terminate string, reset buffer, emit comment + comment_buffer[comment_buffer_index] = 0; + comment_buffer_index = 0; + record_comment(comment_buffer); + if (ch == '\r' || ch == '\n') + return; + } + + // Acumulate char from stream + comment_buffer[comment_buffer_index++] = ch; +} + +void record_comment(const char * msg) { + fprintf(file, "; %s\n", msg); + fflush(file); +} diff --git a/simulator/data_recorder.h b/simulator/data_recorder.h index cf20acf..067cdb6 100644 --- a/simulator/data_recorder.h +++ b/simulator/data_recorder.h @@ -8,5 +8,7 @@ void recorder_init(const char* filename); void record_pin(int pin, bool state, uint32_t time); void add_trace_var(const char* name, int pin); +void record_comment(const char * msg); +void record_comment_stream(char ch); #endif /* DATA_RECORDER_H_ */