Skip to content

Commit

Permalink
task/ui: make sure errorChannel isnt overrun
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Michael Haberler committed Mar 8, 2011
1 parent 0d1e9cf commit f9c032f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
4 changes: 0 additions & 4 deletions nc_files/roparams.ngc
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
(DEBUG, _imperial: = #<_imperial>)
(DEBUG, _absolute: = #<_absolute>)
(DEBUG, _incremental: = #<_incremental>)
g4 p2
(DEBUG, _inverse_time: = #<_inverse_time>)
(DEBUG, _units_per_minute: = #<_units_per_minute>)
(DEBUG, _units_per_rev: = #<_units_per_rev>)
(DEBUG, _coord_system: = #<_coord_system>)
(DEBUG, _tool_offset: = #<_tool_offset>)
(DEBUG, _retract_r_plane: = #<_retract_r_plane>)
(DEBUG, _retract_old_z: = #<_retract_old_z>)
g4 p2
(DEBUG, _spindle_rpm_mode: = #<_spindle_rpm_mode>)
(DEBUG, _spindle_css_mode: = #<_spindle_css_mode>)
(DEBUG, _ijk_absolute_mode: = #<_ijk_absolute_mode>)
(DEBUG, _lathe_diameter_mode: = #<_lathe_diameter_mode>)
(DEBUG, _lathe_radius_mode: = #<_lathe_radius_mode>)
(DEBUG, _spindle_on: = #<_spindle_on>)
(DEBUG, _spindle_cw: = #<_spindle_cw>)
g4 p2
(DEBUG, _mist: = #<_mist>)
(DEBUG, _flood: = #<_flood>)
(DEBUG, _speed_override: = #<_speed_override>)
Expand All @@ -33,7 +30,6 @@ g4 p2
(DEBUG, _feed_hold: = #<_feed_hold>)
(DEBUG, _feed: = #<_feed>)
(DEBUG, _rpm: = #<_rpm>)
g4p2
(DEBUG, _x: = #<_x>)
(DEBUG, _y: = #<_y>)
(DEBUG, _z: = #<_z>)
Expand Down
54 changes: 42 additions & 12 deletions src/emc/task/emctaskmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ fpu_control_t __fpu_control = _FPU_IEEE & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_M
#include "nml_oi.hh"
#include "task.hh" // emcTaskCommand etc

/* time after which the user interface is declared dead
* because it would'nt read any more messages
*/
#define DEFAULT_EMC_UI_TIMEOUT 5.0


// command line args-- global so that other modules can access
int Argc;
char **Argv;
Expand Down Expand Up @@ -150,16 +156,46 @@ static void emctask_quit(int sig)
signal(sig, emctask_quit);
}

/* make sure at least space bytes are available on
* error channel; wait a bit to drain if needed
*/
int emcErrorBufferOKtoWrite(int space, const char *caller)
{
// check channel for validity
if (emcErrorBuffer == NULL)
return -1;
if (!emcErrorBuffer->valid())
return -1;

double send_errorchan_timout = etime() + DEFAULT_EMC_UI_TIMEOUT;

while (etime() < send_errorchan_timout) {
if (emcErrorBuffer->get_space_available() < space) {
esleep(0.01);
continue;
} else {
break;
}
}
if (etime() >= send_errorchan_timout) {
if (EMC_DEBUG & EMC_DEBUG_TASK_ISSUE) {
rcs_print("timeout waiting for error channel to drain, caller=`%s' request=%d\n", caller,space);
}
return -1;
} else {
// printf("--- %d bytes available after %f seconds\n", space, etime() - send_errorchan_timout + DEFAULT_EMC_UI_TIMEOUT);
}
return 0;
}


// implementation of EMC error logger
int emcOperatorError(int id, const char *fmt, ...)
{
EMC_OPERATOR_ERROR error_msg;
va_list ap;

// check channel for validity
if (emcErrorBuffer == NULL)
return -1;
if (!emcErrorBuffer->valid())
if ( emcErrorBufferOKtoWrite(sizeof(error_msg) * 2, "emcOperatorError"))
return -1;

if (NULL == fmt) {
Expand Down Expand Up @@ -191,10 +227,7 @@ int emcOperatorText(int id, const char *fmt, ...)
EMC_OPERATOR_TEXT text_msg;
va_list ap;

// check channel for validity
if (emcErrorBuffer == NULL)
return -1;
if (!emcErrorBuffer->valid())
if ( emcErrorBufferOKtoWrite(sizeof(text_msg) * 2, "emcOperatorText"))
return -1;

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

// check channel for validity
if (emcErrorBuffer == NULL)
return -1;
if (!emcErrorBuffer->valid())
if ( emcErrorBufferOKtoWrite(sizeof(display_msg) * 2, "emcOperatorDisplay"))
return -1;

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

0 comments on commit f9c032f

Please sign in to comment.