2009-01-25 00:48:56 +01:00
|
|
|
/*
|
|
|
|
serial_protocol.c - the serial protocol master control unit
|
|
|
|
Part of Grbl
|
|
|
|
|
2011-01-14 16:45:18 +01:00
|
|
|
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"
|
2011-02-05 00:55:37 +01:00
|
|
|
#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>
|
2010-03-14 23:45:31 +01:00
|
|
|
#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
|
|
|
|
2011-02-05 00:39:34 +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()
|
|
|
|
{
|
2011-01-22 23:29:02 +01:00
|
|
|
beginSerial(BAUD_RATE);
|
2010-03-07 23:10:41 +01:00
|
|
|
printPgmString(PSTR("\r\nGrbl "));
|
2011-02-05 00:55:37 +01:00
|
|
|
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)
|
|
|
|
{
|
2010-07-02 23:23:32 +02:00
|
|
|
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
|
2011-02-05 00:39:34 +01:00
|
|
|
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();
|
2010-03-02 08:19:21 +01:00
|
|
|
} else if (c <= ' ') { // Throw away whitepace and control characters
|
2009-02-04 14:01:24 +01:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|