|
1 | | -// This file is a part of "G-Pilot GCode Sender" application. |
2 | | -// Copyright 2015-2021 Hayrullin Denis Ravilevich |
3 | | -// Copyright 2024 BTS |
4 | | - |
5 | | -#ifndef MACHINESTATUS_H |
6 | | -#define MACHINESTATUS_H |
7 | | - |
8 | | -#include <QVector3D> |
9 | | -#include <QString> |
10 | | -#include <QDebug> |
11 | | -#include "core/globals.h" |
12 | | - |
13 | | -struct PinState |
14 | | -{ |
15 | | - bool limitX = false; |
16 | | - bool limitY = false; |
17 | | - bool limitZ = false; |
18 | | - bool limitA = false; |
19 | | - bool limitB = false; |
20 | | - bool probe = false; |
21 | | - bool door = false; |
22 | | - bool feedHold = false; |
23 | | - bool reset = false; |
24 | | - bool cycleStart = false; |
25 | | - |
26 | | - QString raw; |
27 | | - |
28 | | - static PinState parse(const QString& s) |
29 | | - { |
30 | | - PinState p; |
31 | | - p.raw = s; |
32 | | - for (QChar c : s) { |
33 | | - switch (c.toLatin1()) { |
34 | | - case 'X': p.limitX = true; break; |
35 | | - case 'Y': p.limitY = true; break; |
36 | | - case 'Z': p.limitZ = true; break; |
37 | | - case 'A': p.limitA = true; break; |
38 | | - case 'B': p.limitB = true; break; |
39 | | - case 'P': p.probe = true; break; |
40 | | - case 'D': p.door = true; break; |
41 | | - case 'H': p.feedHold = true; break; |
42 | | - case 'R': p.reset = true; break; |
43 | | - case 'S': p.cycleStart = true; break; |
44 | | - } |
45 | | - } |
46 | | - |
47 | | - return p; |
48 | | - } |
49 | | - |
50 | | - const QString& toString() const |
51 | | - { |
52 | | - return raw; |
53 | | - } |
54 | | -}; |
55 | | - |
56 | | -struct MachineStatusReport |
57 | | -{ |
58 | | - // Main state |
59 | | - MachineState state = MachineState::Unknown; |
60 | | - |
61 | | - // Position data |
62 | | - QVector3D machinePos; |
63 | | - QVector3D workPos; |
64 | | - QVector3D workOffset; |
65 | | - bool hasMachinePos = false; |
66 | | - bool hasWorkPos = false; |
67 | | - bool hasWorkOffset = false; |
68 | | - |
69 | | - // Feed and spindle |
70 | | - int feedRate = 0; |
71 | | - int spindleSpeed = 0; |
72 | | - bool hasFeedSpindleSpeed = false; |
73 | | - |
74 | | - // Overrides |
75 | | - int feedOverride = 100; |
76 | | - int rapidOverride = 100; |
77 | | - int spindleOverride = 100; |
78 | | - bool hasOverrides = false; |
79 | | - |
80 | | - // Buffer status |
81 | | - int bufferAvailable = 0; |
82 | | - int bufferSize = 0; |
83 | | - bool hasBufferStatus = false; |
84 | | - |
85 | | - // Pin states |
86 | | - PinState pinStates; |
87 | | - bool hasPinStates = false; |
88 | | - |
89 | | - // Accessory states (spindle, flood, mist) |
90 | | - bool spindleEnabled = false; |
91 | | - bool spindleCW = false; |
92 | | - bool floodEnabled = false; |
93 | | - bool mistEnabled = false; |
94 | | - bool hasAccessoryState = false; |
95 | | - |
96 | | - // Raw line for debugging |
97 | | - QString rawLine; |
98 | | - |
99 | | - QString toMarkdown() const |
100 | | - { |
101 | | - static const QMap<MachineState, QString> stateNames = { |
102 | | - { MachineState::Unknown, "Unknown" }, |
103 | | - { MachineState::Idle, "Idle" }, |
104 | | - { MachineState::Alarm, "Alarm" }, |
105 | | - { MachineState::Run, "Run" }, |
106 | | - { MachineState::Home, "Home" }, |
107 | | - { MachineState::Hold0, "Hold:0" }, |
108 | | - { MachineState::Hold1, "Hold:1" }, |
109 | | - { MachineState::Queue, "Queue" }, |
110 | | - { MachineState::Check, "Check" }, |
111 | | - { MachineState::Door0, "Door" }, |
112 | | - { MachineState::Door1, "Door (open)" }, |
113 | | - { MachineState::Door2, "Door (hold)" }, |
114 | | - { MachineState::Door3, "Door (resume)" }, |
115 | | - { MachineState::Jog, "Jog" }, |
116 | | - { MachineState::Sleep, "Sleep" }, |
117 | | - }; |
118 | | - |
119 | | - QStringList lines; |
120 | | - |
121 | | - // Line 1: state |
122 | | - lines << QString("**%1**").arg(stateNames.value(state, "Unknown")); |
123 | | - |
124 | | - // Line 2: positions |
125 | | - QStringList pos; |
126 | | - if (hasWorkPos) { |
127 | | - pos << QString("*WPos:* %1, %2, %3") |
128 | | - .arg(workPos.x(), 0, 'f', 3) |
129 | | - .arg(workPos.y(), 0, 'f', 3) |
130 | | - .arg(workPos.z(), 0, 'f', 3); |
131 | | - } |
132 | | - if (hasMachinePos) { |
133 | | - pos << QString("*MPos:* %1, %2, %3") |
134 | | - .arg(machinePos.x(), 0, 'f', 3) |
135 | | - .arg(machinePos.y(), 0, 'f', 3) |
136 | | - .arg(machinePos.z(), 0, 'f', 3); |
137 | | - } |
138 | | - if (!pos.isEmpty()) { lines << pos.join(" "); } |
139 | | - else { lines << "*No position data*"; } |
140 | | - |
141 | | - // Line 3: feed/spindle + accessories |
142 | | - QStringList motion; |
143 | | - if (hasFeedSpindleSpeed) { |
144 | | - motion << QString("*F:* %1 *S:* %2").arg(feedRate).arg(spindleSpeed); |
145 | | - } |
146 | | - if (hasAccessoryState) { |
147 | | - if (spindleEnabled) { motion << (spindleCW ? "Spindle CW" : "Spindle CCW"); } |
148 | | - if (floodEnabled) { motion << "Flood"; } |
149 | | - if (mistEnabled) { motion << "Mist"; } |
150 | | - } |
151 | | - if (hasBufferStatus) { |
152 | | - motion << QString("*Bf:* %1/%2").arg(bufferAvailable).arg(bufferSize); |
153 | | - } |
154 | | - if (!motion.isEmpty()) { lines << motion.join(" "); } |
155 | | - else { lines << "*No feed/spindle data*"; } |
156 | | - |
157 | | - // Line 4: overrides + pins |
158 | | - QStringList extras; |
159 | | - if (hasPinStates && !pinStates.raw.isEmpty()) { |
160 | | - extras << QString("*Pins:* `%1`").arg(pinStates.toString()); |
161 | | - } else { |
162 | | - extras << QString("*Pins:* none"); |
163 | | - } |
164 | | - if (hasOverrides) { |
165 | | - extras << QString("*Ov:* %1% / %2% / %3%").arg(feedOverride).arg(rapidOverride).arg(spindleOverride); |
166 | | - } |
167 | | - if (!extras.isEmpty()) { lines << extras.join(" "); } |
168 | | - else { lines << "*No overrides/pin data*"; } |
169 | | - |
170 | | - return lines.join("<br/>"); |
171 | | - } |
172 | | -}; |
173 | | - |
174 | | -inline QDebug operator<<(QDebug debug, const MachineStatusReport &status) |
175 | | -{ |
176 | | - QDebugStateSaver saver(debug); |
177 | | - debug.nospace() << "MachineStatus("; |
178 | | - debug << "state=" << static_cast<int>(status.state); |
179 | | - |
180 | | - if (status.hasMachinePos) { |
181 | | - debug << ", MPos=" << status.machinePos; |
182 | | - } |
183 | | - if (status.hasWorkPos) { |
184 | | - debug << ", WPos=" << status.workPos; |
185 | | - } |
186 | | - if (status.hasWorkOffset) { |
187 | | - debug << ", WCO=" << status.workOffset; |
188 | | - } |
189 | | - if (status.hasFeedSpindleSpeed) { |
190 | | - debug << ", F=" << status.feedRate << ", S=" << status.spindleSpeed; |
191 | | - } |
192 | | - if (status.hasOverrides) { |
193 | | - debug << ", Ov=" << status.feedOverride << "/" << status.rapidOverride << "/" << status.spindleOverride; |
194 | | - } |
195 | | - if (status.hasBufferStatus) { |
196 | | - debug << ", Bf=" << status.bufferAvailable << "/" << status.bufferSize; |
197 | | - } |
198 | | - if (status.hasPinStates) { |
199 | | - debug << ", Pn=" << status.pinStates.toString(); |
200 | | - } |
201 | | - if (status.hasAccessoryState) { |
202 | | - debug << ", A:"; |
203 | | - if (status.spindleEnabled) debug << (status.spindleCW ? "S" : "C"); |
204 | | - if (status.floodEnabled) debug << "F"; |
205 | | - if (status.mistEnabled) debug << "M"; |
206 | | - } |
207 | | - |
208 | | - debug << ")"; |
209 | | - |
210 | | - return debug; |
211 | | -} |
212 | | - |
213 | | -#endif // MACHINESTATUS_H |
| 1 | +// Moved to core/machine/machinestatus.h |
0 commit comments