Пример #1
0
stat_t gc_gcode_parser(char_t *block)
{
	char_t *str = block;					// gcode command or NUL string
	char_t none = NUL;
	char_t *com = &none;					// gcode comment or NUL string
	char_t *msg = &none;					// gcode message or NUL string
	uint8_t block_delete_flag;

	// don't process Gcode blocks if in alarmed state
	if (cm.machine_state == MACHINE_ALARM) return (STAT_MACHINE_ALARMED);

	_normalize_gcode_block(str, &com, &msg, &block_delete_flag);

	// Block delete omits the line if a / char is present in the first space
	// For now this is unconditional and will always delete
//	if ((block_delete_flag == true) && (cm_get_block_delete_switch() == true)) {
	if (block_delete_flag == true) {
		return (STAT_NOOP);
	}

	// queue a "(MSG" response
	if (*msg != NUL) {
		(void)cm_message(msg);				// queue the message
	}

	return(_parse_gcode_block(block));
}
Пример #2
0
static void _normalize_gcode_block(char *block) 
{
	char c;
	char *comment=0;	// comment pointer - first char past opening paren
	uint8_t i=0; 		// index for incoming characters
	uint8_t j=0;		// index for normalized characters

	if (block[0] == '/') {					// discard deleted blocks
		block[0] = NUL;
		return;
	}
	if (block[0] == '?') {					// trap and return ? command
		return;
	}
	// normalize the command block & mark the comment(if any)
	while ((c = toupper(block[i++])) != NUL) {
		if ((isupper(c)) || (isdigit(c))) {	// capture common chars
		 	block[j++] = c; 
			continue;
		}
		if (c == '(') {						// detect & handle comments
			block[j] = NUL;
			comment = &block[i]; 
			break;
		}
		if (c <= ' ') continue;				// toss controls & whitespace
		if (c == DEL) continue;				// toss DELETE (0x7F)
		if (strchr("!$%,;:?@^_~`\'\"", c))	// toss invalid punctuation
			continue;
		block[j++] = c;
	}
	block[j] = NUL;							// terminate the command
	if (comment != 0) {
		if ((toupper(comment[0]) == 'M') && 
			(toupper(comment[1]) == 'S') &&
			(toupper(comment[2]) == 'G')) {
			i=0;
			while ((c = comment[i++]) != NUL) {// remove trailing parenthesis
				if (c == ')') {
					comment[--i] = NUL;
					break;
				}
			}
			(void)cm_message(comment+3);
		}
	}
}