Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/grblplugin.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 43 | { | |||
---|---|---|---|---|---|
44 | if (lastMessage.contains(QStringLiteral("ok"))) { | 44 | if (lastMessage.contains(QStringLiteral("ok"))) { | ||
45 | emit readyForCommand(); | 45 | emit readyForCommand(); | ||
46 | } | 46 | } | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | QByteArray GrblPlugin::translate(const QString &command) | 49 | QByteArray GrblPlugin::translate(const QString &command) | ||
50 | { | 50 | { | ||
51 | QString temp = command; | 51 | QString temp = command; | ||
52 | //Match all G and M Commands up until the start of the next G/M command or the end of the string. | 52 | //Match all G and M commands followed by one or more digits up to and include the space, | ||
53 | //if thats followed by a letter capture any non G or M starting text | ||||
54 | //else just grab the digits that follow. | ||||
53 | //ex: G28 X Y M1 would capture "G28 X Y" and "M1" | 55 | //ex: G28 X Y M1 would capture "G28 X Y" and "M1" | ||
54 | static const auto regEx = QRegularExpression(QStringLiteral("[GM]\\d+.[^GM]+")); | 56 | static const auto regEx = QRegularExpression(QStringLiteral("[GM]\\d+.(?(?=\\D)[^GM]+|\\d+)?")); | ||
57 | | ||||
55 | QRegularExpressionMatch secondCommand = regEx.match(temp, 1); | 58 | QRegularExpressionMatch secondCommand = regEx.match(temp, 1); | ||
56 | 59 | | |||
57 | if (secondCommand.hasMatch()) { | 60 | if (secondCommand.hasMatch()) { | ||
58 | QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(temp); | 61 | QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(temp); | ||
59 | temp.clear(); | 62 | temp.clear(); | ||
60 | while (commandMatch.hasNext()) { | 63 | while (commandMatch.hasNext()) { | ||
61 | QRegularExpressionMatch t = commandMatch.next(); | 64 | QRegularExpressionMatch t = commandMatch.next(); | ||
62 | temp.append(t.captured()); | 65 | temp.append(t.captured().simplified()); | ||
63 | if (commandMatch.hasNext()) { | 66 | if (commandMatch.hasNext()) { | ||
64 | temp = temp.simplified(); | | |||
65 | temp.append(QStringLiteral("\r\n")); | 67 | temp.append(QStringLiteral("\r\n")); | ||
66 | } | 68 | } | ||
67 | } | 69 | } | ||
68 | } | 70 | } | ||
69 | return temp.toLocal8Bit(); | 71 | return temp.toLocal8Bit(); | ||
70 | } | 72 | } |