Skip to content

Commit 3286536

Browse files
committed
Call $G during handshake, process $$, $G, $# in communicator
1 parent 7eb96ba commit 3286536

4 files changed

Lines changed: 28 additions & 32 deletions

File tree

src/gpilot/core/communicator/communicator.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,17 @@ Communicator::Communicator(
6969
const QString& data,
7070
const QStringList& lines
7171
) -> bool {
72-
// Store current coordinate system
72+
// Store device configuration and state from query responses
73+
if (command == "$$" && status.ok) {
74+
processDeviceConfiguration(lines);
75+
}
76+
7377
if (command == "$G" && status.ok) {
74-
auto modal = ModalStateParser::parse(lines[0]);
75-
if (modal) {
76-
qDebug() << "[Communicator] Detected coordinate system: " << modal->coordinateSystem;
77-
}
78+
processGCodeParserState(attrs, lines[0]);
79+
}
80+
81+
if (command == "$#" && status.ok) {
82+
processOffsetsVars(lines);
7883
}
7984

8085
if (attrs.source == CommandSource::Communicator) {

src/gpilot/core/state_behavior/handshakebehavior.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,39 @@ AbstractStateBehavior::Result HandshakeBehavior::onCommandResponse(
6565

6666
// Retry on EEPROM-not-ready error before main handling.
6767
if (!cmdStatus.ok && cmdStatus.errorCode == GRBL_ERROR_EEPROM_READ_FAIL) {
68-
if (command == "$$" || command == "$#") {
68+
if (command == "$$" || command == "$G" || command == "$#") {
6969
qDebug() << "[Behavior][Handshake] EEPROM not ready for" << command << "— requeuing.";
7070

7171
return Result::ReturnCommandToQueue;
7272
}
7373
}
7474

75+
// Responses for all commands are handled in Communicator callback, do not handle it here.
76+
7577
if (command == "$$") {
76-
if (cmdStatus.ok) {
77-
m_communicator->processDeviceConfiguration(fullResponse);
78-
} else {
78+
if (!cmdStatus.ok) {
7979
qDebug() << "[Behavior][Handshake] Failed to receive device settings (error" << cmdStatus.errorCode << "). Continuing.";
8080
}
8181

82+
m_communicator->sendCommand(CommandSource::System, "$G", TABLE_INDEX_UTIL1);
83+
m_stage = QueryingGcodeState;
84+
85+
return Result::Ok;
86+
}
87+
88+
if (command == "$G") {
89+
if (!cmdStatus.ok) {
90+
qDebug() << "[Behavior][Handshake] Failed to receive gcode parser state (error" << cmdStatus.errorCode << "). Continuing.";
91+
}
92+
8293
m_communicator->sendCommand(CommandSource::System, "$#", TABLE_INDEX_UTIL1);
8394
m_stage = QueryingOffsets;
8495

8596
return Result::Ok;
8697
}
8798

8899
if (command == "$#") {
89-
if (cmdStatus.ok) {
90-
m_communicator->processOffsetsVars(fullResponse);
91-
} else {
100+
if (!cmdStatus.ok) {
92101
qDebug() << "[Behavior][Handshake] Failed to receive coordinate offsets (error" << cmdStatus.errorCode << "). Continuing.";
93102
}
94103

src/gpilot/core/state_behavior/handshakebehavior.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// 1. Queries current machine state (?).
1111
// 2. If the machine is actively running an external process (Run/Jog/Check),
1212
// transitions immediately to ExternalProcessBehavior.
13-
// 3. Otherwise queries device settings ($$) and coordinate offsets ($#).
13+
// 3. Otherwise queries device settings ($$), gcode state ($G), and coordinate offsets ($#).
1414
// 4. Transitions to the appropriate behavior based on the initial machine state.
1515
class HandshakeBehavior : public AbstractStateBehavior
1616
{
@@ -33,6 +33,7 @@ class HandshakeBehavior : public AbstractStateBehavior
3333
enum Stage {
3434
QueryingState,
3535
QueryingSettings,
36+
QueryingGcodeState,
3637
QueryingOffsets,
3738
Completed
3839
};

src/gpilot/core/state_behavior/idlebehavior.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@ AbstractStateBehavior::Result IdleBehavior::onCommandResponse(QString command, C
3535

3636
qDebug() << "[Behavior][Idle] Command Response:" << command << response;
3737

38-
if (command == "$G") {
39-
m_communicator->processGCodeParserState(commandAttributes, response);
40-
41-
return Result::Ok;
42-
}
43-
44-
if (command == "$$") {
45-
if (!cmdStatus.ok) {
46-
qDebug() << "[Behavior][Idle] Error receiving device configuration.";
47-
48-
return Result::Ok;
49-
}
50-
51-
qDebug() << "[Behavior][Idle] Processing device configuration.";
52-
m_communicator->processDeviceConfiguration(fullResponse);
53-
54-
return Result::Ok;
55-
}
56-
5738
return Result::Unhandled;
5839
}
5940

0 commit comments

Comments
 (0)