G-code parser: check for end of line in the parser.
This raises abstraction and even makes the binary a bit smaller (2 bytes without SD, 14 bytes with SD). A G-code file with 16'384 lines of comments, 64 bytes per line ( = 1 MB file size), is read and parsed from SD card in 2:47 minutes, or at a speed of 5924 bytes/second.
This commit is contained in:
parent
cb1b9b3feb
commit
53dfab3be3
|
|
@ -100,9 +100,16 @@ void gcode_init(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/// Character Received - add it to our command
|
||||
/// \param c the next character to process
|
||||
void gcode_parse_char(uint8_t c) {
|
||||
/** Character received - add it to our command.
|
||||
|
||||
\param c The next character to process.
|
||||
|
||||
\return Wether end of line was reached.
|
||||
|
||||
This parser operates character by character, so there's no need for a
|
||||
buffer holding the entire line of G-code.
|
||||
*/
|
||||
uint8_t gcode_parse_char(uint8_t c) {
|
||||
uint8_t checksum_char = c;
|
||||
|
||||
// uppercase
|
||||
|
|
@ -401,6 +408,8 @@ void gcode_parse_char(uint8_t c) {
|
|||
if (next_target.option_all_relative || next_target.option_e_relative) {
|
||||
next_target.target.axis[E] = 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef SD
|
||||
|
|
@ -417,6 +426,8 @@ void gcode_parse_char(uint8_t c) {
|
|||
}
|
||||
}
|
||||
#endif /* SD */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***************************************************************************\
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ extern GCODE_COMMAND next_target;
|
|||
void gcode_init(void);
|
||||
|
||||
/// accept the next character and process it
|
||||
void gcode_parse_char(uint8_t c);
|
||||
uint8_t gcode_parse_char(uint8_t c);
|
||||
|
||||
// uses the global variable next_target.N
|
||||
void request_resend(void);
|
||||
|
|
|
|||
10
mendel.c
10
mendel.c
|
|
@ -271,14 +271,14 @@ int main (void)
|
|||
{
|
||||
// if queue is full, no point in reading chars- host will just have to wait
|
||||
if (queue_full() == 0) {
|
||||
uint8_t c;
|
||||
uint8_t c, line_done;
|
||||
|
||||
if (( ! gcode_active || gcode_active & GCODE_SOURCE_SERIAL) &&
|
||||
serial_rxchars() != 0) {
|
||||
gcode_active = GCODE_SOURCE_SERIAL;
|
||||
c = serial_popchar();
|
||||
gcode_parse_char(c);
|
||||
if (c == '\r' || c == '\n')
|
||||
line_done = gcode_parse_char(c);
|
||||
if (line_done)
|
||||
gcode_active = 0;
|
||||
}
|
||||
|
||||
|
|
@ -294,8 +294,8 @@ int main (void)
|
|||
}
|
||||
else {
|
||||
gcode_active = GCODE_SOURCE_SD;
|
||||
gcode_parse_char(c);
|
||||
if (c == '\r' || c == '\n')
|
||||
line_done = gcode_parse_char(c);
|
||||
if (line_done)
|
||||
gcode_active = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue