grbl-LPC-CoreXY/serial_protocol.c

81 lines
2.3 KiB
C
Raw Normal View History

2009-01-25 00:48:56 +01:00
/*
serial_protocol.c - the serial protocol master control unit
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
2009-01-25 00:48:56 +01:00
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include "serial_protocol.h"
#include "gcode.h"
#include "wiring_serial.h"
2011-02-05 00:45:41 +01:00
#include "settings.h"
#include "config.h"
2009-01-25 00:48:56 +01:00
#include <math.h>
#include "nuts_bolts.h"
2010-03-07 23:10:41 +01:00
#include <avr/pgmspace.h>
#define LINE_BUFFER_SIZE 50
2009-01-25 00:48:56 +01:00
2011-01-25 23:33:19 +01:00
static char line[LINE_BUFFER_SIZE];
static uint8_t char_counter;
2009-01-25 00:48:56 +01:00
void status_message(int status_code) {
if (status_code) {
switch(status_code) {
case GCSTATUS_BAD_NUMBER_FORMAT:
printPgmString(PSTR("error: Bad number format\n\r")); break;
case GCSTATUS_EXPECTED_COMMAND_LETTER:
printPgmString(PSTR("error: Expected command letter\n\r")); break;
case GCSTATUS_UNSUPPORTED_STATEMENT:
printPgmString(PSTR("error: Unsupported statement\n\r")); break;
case GCSTATUS_FLOATING_POINT_ERROR:
printPgmString(PSTR("error: Floating point error\n\r")); break;
}
}
}
2009-01-25 00:48:56 +01:00
void prompt() {
2010-03-07 23:10:41 +01:00
printPgmString(PSTR("ok\r\n"));
2009-01-25 00:48:56 +01:00
}
void sp_init()
{
beginSerial(BAUD_RATE);
2010-03-07 23:10:41 +01:00
printPgmString(PSTR("\r\nGrbl "));
printPgmString(PSTR(GRBL_VERSION));
2010-03-07 23:10:41 +01:00
printPgmString(PSTR("\r\n"));
2009-01-25 00:48:56 +01:00
prompt();
}
void sp_process()
{
char c;
while((c = serialRead()) != -1)
{
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
line[char_counter] = 0; // treminate string
status_message(gc_execute_line(line));
char_counter = 0; // reset line buffer index
2009-01-25 00:48:56 +01:00
prompt();
} else if (c <= ' ') { // Throw away whitepace and control characters
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
2010-03-03 13:04:51 +01:00
line[char_counter++] = c-'a'+'A';
2009-01-25 00:48:56 +01:00
} else {
2010-03-03 13:04:51 +01:00
line[char_counter++] = c;
2009-01-25 00:48:56 +01:00
}
}
}