diff --git a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp index ebf369d83..a663b1421 100644 --- a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp +++ b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp @@ -232,6 +232,10 @@ GCodeCheckResult GCodeChecker::parse_command(GCodeLine& gcode_line) ret = parse_M104_M109(gcode_line); break; } // Set to nozzle temperature + case 1020: { + ret = parse_M1020(gcode_line); + break; + } default: { break; } } break; @@ -469,6 +473,46 @@ GCodeCheckResult GCodeChecker::parse_M104_M109(const GCodeLine &gcode_line) return GCodeCheckResult::Success; } +GCodeCheckResult GCodeChecker::parse_M1020(const GCodeLine& gcode_line) +{ + const char* c = gcode_line.m_raw.c_str(); + const char* rs = strchr(c, 'S'); + + if (rs != nullptr) { + std::string str = rs; + str = str.substr(1); + for (int i = 0; i < str.size(); i++) { + if (str[i] == ' ') + str = str.substr(0, i); + } + + try { + int value = std::stoi(str); + if (value >= 0 && value <= filament_flow_ratio.size() - 1) { + filament_id = value; + flow_ratio = filament_flow_ratio[value]; + return GCodeCheckResult::Success; + } + else { + return GCodeCheckResult::ParseFailed; + } + } + catch (std::invalid_argument&) { + std::cout << "Invalid argument: not a valid integer" << std::endl; + return GCodeCheckResult::ParseFailed; + } + catch (std::out_of_range&) { + std::cout << "Out of range: number is too large" << std::endl; + return GCodeCheckResult::ParseFailed; + } + } + else + { + std::cout << "Missing 'S' character in the G-code line!" << std::endl; + return GCodeCheckResult::ParseFailed; + } +} + double GCodeChecker::calculate_G1_width(const std::array& source, const std::array& target, double e, double height, bool is_bridge) const diff --git a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h index 31bfe259c..3838a9111 100644 --- a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h +++ b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h @@ -109,6 +109,7 @@ private: GCodeCheckResult parse_M82(const GCodeLine& gcode_line); GCodeCheckResult parse_M83(const GCodeLine& gcode_line); GCodeCheckResult parse_M104_M109(const GCodeLine &gcode_line); + GCodeCheckResult parse_M1020(const GCodeLine& gcode_line); GCodeCheckResult parse_comment(GCodeLine& gcode_line);