Esempio n. 1
0
void sim_gcode_ch(char ch) {
  // Got CR, LF or buffer full
  if ( gcode_buffer_index == sizeof(gcode_buffer)-1 ||
       ch == '\r' || ch == '\n' || ch == 0 ) {

    // Terminate string, reset buffer, emit gcode
    if (gcode_buffer_index) {
      gcode_buffer[gcode_buffer_index] = 0;
      gcode_buffer_index = 0;

      if (trace_gcode) {
        clearline();
        fyellow();
        printf("%s\n", gcode_buffer);
        fbreset();
        fflush(stdout);
      }

      // Send gcode to data_recorder
      record_comment(gcode_buffer);
    }

    if (ch == '\r' || ch == '\n' || ch == 0)
      return;
  }

  // Acumulate char from stream
  gcode_buffer[gcode_buffer_index++] = ch;
}
Esempio n. 2
0
// read/write many characters
void serial_writestr(uint8_t *data) {
  const char *str = (char *)data;
  sim_assert(serial_initialised, "serial interface not initialised");
  record_comment(str);
  if (serial_fd) {
    ssize_t count;
    count = write(serial_fd, str, strlen(str));
    sim_assert(count == strlen(str), "could not write to serial port");
  }
}