Skip to content

Commit f9c032f

Browse files
author
Michael Haberler
committed
task/ui: make sure errorChannel isnt overrun
before sending a (DEBUG ..), (PRINT ..) or error message to the user interface, make sure there's sufficient space in the errorChannel queue towards the UI add #define for UI error channel timeout (DEFAULT_EMC_UI_TIMEOUT) backout wait commands from nc_files/roparams.ngc
1 parent 0d1e9cf commit f9c032f

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

nc_files/roparams.ngc

-4
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,20 @@
88
(DEBUG, _imperial: = #<_imperial>)
99
(DEBUG, _absolute: = #<_absolute>)
1010
(DEBUG, _incremental: = #<_incremental>)
11-
g4 p2
1211
(DEBUG, _inverse_time: = #<_inverse_time>)
1312
(DEBUG, _units_per_minute: = #<_units_per_minute>)
1413
(DEBUG, _units_per_rev: = #<_units_per_rev>)
1514
(DEBUG, _coord_system: = #<_coord_system>)
1615
(DEBUG, _tool_offset: = #<_tool_offset>)
1716
(DEBUG, _retract_r_plane: = #<_retract_r_plane>)
1817
(DEBUG, _retract_old_z: = #<_retract_old_z>)
19-
g4 p2
2018
(DEBUG, _spindle_rpm_mode: = #<_spindle_rpm_mode>)
2119
(DEBUG, _spindle_css_mode: = #<_spindle_css_mode>)
2220
(DEBUG, _ijk_absolute_mode: = #<_ijk_absolute_mode>)
2321
(DEBUG, _lathe_diameter_mode: = #<_lathe_diameter_mode>)
2422
(DEBUG, _lathe_radius_mode: = #<_lathe_radius_mode>)
2523
(DEBUG, _spindle_on: = #<_spindle_on>)
2624
(DEBUG, _spindle_cw: = #<_spindle_cw>)
27-
g4 p2
2825
(DEBUG, _mist: = #<_mist>)
2926
(DEBUG, _flood: = #<_flood>)
3027
(DEBUG, _speed_override: = #<_speed_override>)
@@ -33,7 +30,6 @@ g4 p2
3330
(DEBUG, _feed_hold: = #<_feed_hold>)
3431
(DEBUG, _feed: = #<_feed>)
3532
(DEBUG, _rpm: = #<_rpm>)
36-
g4p2
3733
(DEBUG, _x: = #<_x>)
3834
(DEBUG, _y: = #<_y>)
3935
(DEBUG, _z: = #<_z>)

src/emc/task/emctaskmain.cc

+42-12
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ fpu_control_t __fpu_control = _FPU_IEEE & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_M
8080
#include "nml_oi.hh"
8181
#include "task.hh" // emcTaskCommand etc
8282

83+
/* time after which the user interface is declared dead
84+
* because it would'nt read any more messages
85+
*/
86+
#define DEFAULT_EMC_UI_TIMEOUT 5.0
87+
88+
8389
// command line args-- global so that other modules can access
8490
int Argc;
8591
char **Argv;
@@ -150,16 +156,46 @@ static void emctask_quit(int sig)
150156
signal(sig, emctask_quit);
151157
}
152158

159+
/* make sure at least space bytes are available on
160+
* error channel; wait a bit to drain if needed
161+
*/
162+
int emcErrorBufferOKtoWrite(int space, const char *caller)
163+
{
164+
// check channel for validity
165+
if (emcErrorBuffer == NULL)
166+
return -1;
167+
if (!emcErrorBuffer->valid())
168+
return -1;
169+
170+
double send_errorchan_timout = etime() + DEFAULT_EMC_UI_TIMEOUT;
171+
172+
while (etime() < send_errorchan_timout) {
173+
if (emcErrorBuffer->get_space_available() < space) {
174+
esleep(0.01);
175+
continue;
176+
} else {
177+
break;
178+
}
179+
}
180+
if (etime() >= send_errorchan_timout) {
181+
if (EMC_DEBUG & EMC_DEBUG_TASK_ISSUE) {
182+
rcs_print("timeout waiting for error channel to drain, caller=`%s' request=%d\n", caller,space);
183+
}
184+
return -1;
185+
} else {
186+
// printf("--- %d bytes available after %f seconds\n", space, etime() - send_errorchan_timout + DEFAULT_EMC_UI_TIMEOUT);
187+
}
188+
return 0;
189+
}
190+
191+
153192
// implementation of EMC error logger
154193
int emcOperatorError(int id, const char *fmt, ...)
155194
{
156195
EMC_OPERATOR_ERROR error_msg;
157196
va_list ap;
158197

159-
// check channel for validity
160-
if (emcErrorBuffer == NULL)
161-
return -1;
162-
if (!emcErrorBuffer->valid())
198+
if ( emcErrorBufferOKtoWrite(sizeof(error_msg) * 2, "emcOperatorError"))
163199
return -1;
164200

165201
if (NULL == fmt) {
@@ -191,10 +227,7 @@ int emcOperatorText(int id, const char *fmt, ...)
191227
EMC_OPERATOR_TEXT text_msg;
192228
va_list ap;
193229

194-
// check channel for validity
195-
if (emcErrorBuffer == NULL)
196-
return -1;
197-
if (!emcErrorBuffer->valid())
230+
if ( emcErrorBufferOKtoWrite(sizeof(text_msg) * 2, "emcOperatorText"))
198231
return -1;
199232

200233
// write args to NML message (ignore int text code)
@@ -214,10 +247,7 @@ int emcOperatorDisplay(int id, const char *fmt, ...)
214247
EMC_OPERATOR_DISPLAY display_msg;
215248
va_list ap;
216249

217-
// check channel for validity
218-
if (emcErrorBuffer == NULL)
219-
return -1;
220-
if (!emcErrorBuffer->valid())
250+
if ( emcErrorBufferOKtoWrite(sizeof(display_msg) * 2, "emcOperatorDisplay"))
221251
return -1;
222252

223253
// write args to NML message (ignore int display code)

0 commit comments

Comments
 (0)