Skip to content

Commit 74f2278

Browse files
author
etet100
committed
Parse / log modal state
1 parent 67ae093 commit 74f2278

6 files changed

Lines changed: 53 additions & 28 deletions

File tree

src/gpilot/core/communicator/communicator_processing_response.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -458,35 +458,37 @@ void Communicator::processGCodeParserState(CommandAttributes commandAttributes,
458458
}
459459

460460
// Process GCore parser state
461-
if (commandAttributes.tableIndex == TABLE_INDEX_UTIL2) {
462-
// @TODO what is this ; for? is it '; ok'?
463-
m_lastParserState = response.left(response.indexOf("; "));
464-
465-
auto modal = ModalStateParser::parse(m_lastParserState);
461+
// if (commandAttributes.tableIndex == TABLE_INDEX_UTIL2) {
462+
auto modal = ModalStateParser::parse(response);
466463
if (modal) {
467464
m_deviceContext.setModalState(*modal);
468-
}
465+
emit log(modal->toString());
469466

470-
// Update status in visualizer window
471-
emit parserStateReceived(m_lastParserState);
467+
// Update status in visualizer window
468+
emit parserStateReceived(modal->raw);
472469

473-
// Store parser status
474-
if ((m_senderState == SenderState::Transferring) || (m_senderState == SenderState::Stopping)) {
475-
storeParserState();
476-
}
470+
// Store parser status
471+
if ((m_senderState == SenderState::Transferring) || (m_senderState == SenderState::Stopping)) {
472+
storeParserState();
473+
}
477474

478-
// Spindle speed
479-
// @TODO what is the difference between this and processFeedSpindleSpeed??
480-
static QRegularExpression rx(".*S([\\d\\.]+)");
475+
if (modal->spindleSpeed != -1) {
476+
emit spindleSpeedReceived(modal->spindleSpeed);
477+
}
478+
479+
// Spindle speed
480+
// @TODO what is the difference between this and processFeedSpindleSpeed??
481+
// static QRegularExpression rx(".*S([\\d\\.]+)");
481482

482-
match = rx.match(response);
483-
if (match.hasMatch()) {
484-
double spindleSpeed = match.captured(1).toDouble();
485-
emit spindleSpeedReceived(spindleSpeed);
483+
// match = rx.match(response);
484+
// if (match.hasMatch()) {
485+
// double spindleSpeed = match.captured(1).toDouble();
486+
// emit spindleSpeedReceived(spindleSpeed);
487+
// }
486488
}
487489

488490
m_updateParserState = true;
489-
}
491+
// }
490492
}
491493

492494
// processCommandResponse was moved to CommandBuffer::processResponse()

src/gpilot/core/machine/modalstateparser.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
std::optional<ModalState> ModalStateParser::parse(const QString &line)
88
{
9-
if (!line.startsWith('[') || !line.endsWith(']')) {
9+
if (!line.startsWith("[GC:") || !line.endsWith(']')) {
1010
return std::nullopt;
1111
}
1212

13-
const QString inner = line.mid(1, line.length() - 2);
13+
const QString inner = line.mid(4, line.length() - 5);
1414
const QStringList tokens = inner.split(' ', Qt::SkipEmptyParts);
1515

1616
ModalState state;
17+
state.raw = inner;
1718

1819
for (const QString &token : tokens) {
1920
if (token.startsWith('G')) {
@@ -55,3 +56,21 @@ std::optional<ModalState> ModalStateParser::parse(const QString &line)
5556

5657
return state;
5758
}
59+
60+
QString ModalState::toString() const
61+
{
62+
QString sep = "————————————";
63+
QString result;
64+
result += sep + "\n";
65+
result += QString("Coord: %1\n").arg(coordinateSystem);
66+
result += QString("Plane: %1\n").arg(workPlane);
67+
result += QString("Units: %1\n").arg(units == "G20" ? "inches" : units == "G21" ? "mm" : units);
68+
result += QString("Motion: %1\n").arg(motionMode == "G90" ? "absolute" : motionMode == "G91" ? "relative" : motionMode);
69+
result += QString("Feed mode: %1\n").arg(feedMode);
70+
result += QString("Feed: %1\n").arg(feedRate);
71+
result += QString("Spindle: %1\n").arg(spindleMode == "M3" ? "CW" : spindleMode == "M4" ? "CCW" : spindleMode == "M5" ? "off" : spindleMode);
72+
result += QString("Speed: %1\n").arg(spindleSpeed);
73+
result += sep;
74+
75+
return result;
76+
}

src/gpilot/core/machine/modalstateparser.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ struct ModalState {
2121
// Spindle mode (M3 = CW, M4 = CCW, M5 = off)
2222
QString spindleMode;
2323

24-
int feedRate = 0;
25-
int spindleSpeed = 0;
24+
int feedRate = -1;
25+
int spindleSpeed = -1;
26+
27+
QString raw;
28+
29+
QString toString() const;
2630
};
2731

2832
// Parses a modal state line like [G54 G17 G21 G90 G94 M5 M9 T0 F0 S0].

src/gpilot/ui/forms/frmmain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ void FrmMain::onPinStateReceived(PinState state)
18781878

18791879
void FrmMain::onFeedSpindleSpeedReceived(int feedRate, int spindleSpeed)
18801880
{
1881-
ui->visualizer->setSpeedState((QString(tr("F/S: %1 / %2")).arg(feedRate, spindleSpeed)));
1881+
ui->visualizer->setSpeedState(feedRate, spindleSpeed);
18821882
}
18831883

18841884
void FrmMain::onSpindleSpeedReceived(int spindleSpeed)

src/gpilot/ui/forms/partials/main/partmainvisualizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ void PartMainVisualizer::setPinState(QString state)
579579
ui->visualizer->setPinState(state);
580580
}
581581

582-
void PartMainVisualizer::setSpeedState(QString state)
582+
void PartMainVisualizer::setSpeedState(int feedRate, int spindleSpeed)
583583
{
584-
ui->visualizer->setSpeedState(state);
584+
ui->visualizer->setSpeedState(QString("F/S: %1 / %2").arg(feedRate).arg(spindleSpeed));
585585
}
586586

587587
bool PartMainVisualizer::isIgnoreZ() const

src/gpilot/ui/forms/partials/main/partmainvisualizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class PartMainVisualizer : public QWidget
5353

5454
void setParserState(QString state);
5555
void setPinState(QString state);
56-
void setSpeedState(QString state);
56+
void setSpeedState(int feedRate, int spindleSpeed);
5757

5858
void close();
5959

0 commit comments

Comments
 (0)