simulator: record g-codes in datalog
Add comment stream to datalog output so we can store g-codes and other events that occur during simulation.
This commit is contained in:
parent
18c68b5fe4
commit
2b8a5d3b5a
|
|
@ -14,6 +14,9 @@
|
||||||
#include "sersendf.h"
|
#include "sersendf.h"
|
||||||
|
|
||||||
#include "gcode_process.h"
|
#include "gcode_process.h"
|
||||||
|
#ifdef SIMULATOR
|
||||||
|
#include "simulator.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/// current or previous gcode word
|
/// current or previous gcode word
|
||||||
/// for working out what to do with data just received
|
/// for working out what to do with data just received
|
||||||
|
|
@ -102,7 +105,9 @@ void gcode_parse_char(uint8_t c) {
|
||||||
// uppercase
|
// uppercase
|
||||||
if (c >= 'a' && c <= 'z')
|
if (c >= 'a' && c <= 'z')
|
||||||
c &= ~32;
|
c &= ~32;
|
||||||
|
#ifdef SIMULATOR
|
||||||
|
record_comment_stream(c);
|
||||||
|
#endif
|
||||||
// process previous field
|
// process previous field
|
||||||
if (last_field) {
|
if (last_field) {
|
||||||
// check if we're seeing a new field or end of line
|
// check if we're seeing a new field or end of line
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "simulator/data_recorder.h"
|
||||||
|
|
||||||
#define PROGMEM
|
#define PROGMEM
|
||||||
#define PGM_P const char *
|
#define PGM_P const char *
|
||||||
|
|
|
||||||
|
|
@ -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
|
// Naive format: each line contains all values, beginning with the time
|
||||||
fprintf(file, "%u", t);
|
fprintf(file, "%u", t);
|
||||||
for (int i = 0; i < pin_count; i++)
|
for (int i = 0; i < pin_count; i++)
|
||||||
fprintf(file, "\t%u", values[i]);
|
fprintf(file, " %u", values[i]);
|
||||||
fprintf(file, "\n");
|
fprintf(file, "\n");
|
||||||
fflush(file);
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,7 @@
|
||||||
void recorder_init(const char* filename);
|
void recorder_init(const char* filename);
|
||||||
void record_pin(int pin, bool state, uint32_t time);
|
void record_pin(int pin, bool state, uint32_t time);
|
||||||
void add_trace_var(const char* name, int pin);
|
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_ */
|
#endif /* DATA_RECORDER_H_ */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue