From 20b79e6b263a4fafec94232cd74796a23f34a36b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 22 Jan 2024 13:33:52 +0100 Subject: [PATCH] Fixed bug in conversion from binary to ascii gcode letting 'G29 G' lines be translated to 'G29G', missing the space --- src/LibBGCode/binarize/meatpack.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/LibBGCode/binarize/meatpack.cpp b/src/LibBGCode/binarize/meatpack.cpp index c5c8952..9fff800 100644 --- a/src/LibBGCode/binarize/meatpack.cpp +++ b/src/LibBGCode/binarize/meatpack.cpp @@ -384,7 +384,7 @@ void unbinarize(const std::vector& src, std::string& dst) // G2, G3 'I', 'J', 'R', // G29 - 'P', 'W', 'H', 'C', 'A' + 'G', 'P', 'W', 'H', 'C', 'A' }; return std::find(parameters.begin(), parameters.end(), c) != parameters.end(); }; @@ -395,12 +395,15 @@ void unbinarize(const std::vector& src, std::string& dst) // GCodeReader::parse_line_internal() is unable to parse a G line where the data are not separated by spaces // so we add them where needed const size_t curr_unbin_buffer_length = std::distance(unbin_buffer.begin(), it_unbin_end); - if (c_unbin[i] == 'G' && (curr_unbin_buffer_length == 0 || *std::prev(it_unbin_end, 1) == '\n')) + bool new_line = false; + if (c_unbin[i] == 'G' && (curr_unbin_buffer_length == 0 || *std::prev(it_unbin_end, 1) == '\n')) { add_space = true; + new_line = true; + } else if (c_unbin[i] == '\n') add_space = false; - if (add_space && (curr_unbin_buffer_length == 0 || *std::prev(it_unbin_end, 1) != ' ') && + if (!new_line && add_space && (curr_unbin_buffer_length == 0 || *std::prev(it_unbin_end, 1) != ' ') && is_gline_parameter(c_unbin[i])) { *it_unbin_end = ' '; ++it_unbin_end;