grbl-LPC-CoreXY/protocol.c

78 lines
2.3 KiB
C
Raw Normal View History

2009-01-25 00:48:56 +01:00
/*
2011-02-18 22:11:53 +01:00
protocol.c - the serial protocol master control unit
2009-01-25 00:48:56 +01:00
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>
2011-02-18 22:11:53 +01:00
#include "protocol.h"
2009-01-25 00:48:56 +01:00
#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) {
2011-02-17 10:14:27 +01:00
switch(status_code) {
case GCSTATUS_OK:
printPgmString(PSTR("ok\n\r")); break;
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;
default:
printPgmString(PSTR("error: "));
printInteger(status_code);
printPgmString(PSTR("\n\r"));
}
}
2009-01-25 00:48:56 +01:00
void sp_init()
{
beginSerial(BAUD_RATE);
printPgmString(PSTR("\r\nGrbl " GRBL_VERSION));
2010-03-07 23:10:41 +01:00
printPgmString(PSTR("\r\n"));
2009-01-25 00:48:56 +01:00
}
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
} 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
}
}
}