// Process a received string of gcodes void Webserver::LoadGcodeBuffer(const char* gc) { char gcodeTempBuf[GCODE_LENGTH]; uint16_t gtp = 0; bool inComment = false; for (;;) { char c = *gc++; if (c == 0) { gcodeTempBuf[gtp] = 0; ProcessGcode(gcodeTempBuf); return; } if (c == '\n') { gcodeTempBuf[gtp] = 0; ProcessGcode(gcodeTempBuf); gtp = 0; inComment = false; } else { if (c == ';') { inComment = true; } if (gtp == ARRAY_UPB(gcodeTempBuf)) { // gcode is too long, we haven't room for another character and a null if (c != ' ' && !inComment) { platform->Message(HOST_MESSAGE, "Webserver: GCode local buffer overflow.\n"); HandleReply("Webserver: GCode local buffer overflow", true); return; } // else we're either in a comment or the current character is a space. // If we're in a comment, we'll silently truncate it. // If the current character is a space, we'll wait until we see a non-comment character before reporting an error, // in case the next character is end-of-line or the start of a comment. } else { gcodeTempBuf[gtp++] = c; } } } }
// Process a received string of gcodes void Display::LoadGcodeBuffer(const char* gc, bool convertWeb) { char gcodeTempBuf[GCODE_LENGTH]; uint16_t gtp = 0; bool inComment = false; for (;;) { char c = *gc++; if(c == 0) { gcodeTempBuf[gtp] = 0; ProcessGcode(gcodeTempBuf); return; } if(c == '+' && convertWeb) { c = ' '; } else if(c == '%' && convertWeb) { c = *gc++; if(c != 0) { unsigned char uc; if(isalpha(c)) { uc = 16*(c - 'A' + 10); } else { uc = 16*(c - '0'); } c = *gc++; if(c != 0) { if(isalpha(c)) { uc += c - 'A' + 10; } else { uc += c - '0'; } c = uc; } } } if (c == '\n') { gcodeTempBuf[gtp] = 0; ProcessGcode(gcodeTempBuf); gtp = 0; inComment = false; } else { if (c == ';') { inComment = true; } if(gtp == ARRAY_SIZE(gcodeTempBuf) - 1) { // gcode is too long, we haven't room for another character and a null if (c != ' ' && !inComment) { platform->Message(BOTH_ERROR_MESSAGE, "Display: GCode local buffer overflow.\n"); return; } // else we're either in a comment or the current character is a space. // If we're in a comment, we'll silently truncate it. // If the current character is a space, we'll wait until we see a non-comment character before reporting an error, // in case the next character is end-of-line or the start of a comment. } else { gcodeTempBuf[gtp++] = c; } } } }