@@ -80,6 +80,12 @@ fpu_control_t __fpu_control = _FPU_IEEE & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_M
80
80
#include " nml_oi.hh"
81
81
#include " task.hh" // emcTaskCommand etc
82
82
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
+
83
89
// command line args-- global so that other modules can access
84
90
int Argc;
85
91
char **Argv;
@@ -150,16 +156,46 @@ static void emctask_quit(int sig)
150
156
signal (sig, emctask_quit);
151
157
}
152
158
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
+
153
192
// implementation of EMC error logger
154
193
int emcOperatorError (int id, const char *fmt, ...)
155
194
{
156
195
EMC_OPERATOR_ERROR error_msg;
157
196
va_list ap;
158
197
159
- // check channel for validity
160
- if (emcErrorBuffer == NULL )
161
- return -1 ;
162
- if (!emcErrorBuffer->valid ())
198
+ if ( emcErrorBufferOKtoWrite (sizeof (error_msg) * 2 , " emcOperatorError" ))
163
199
return -1 ;
164
200
165
201
if (NULL == fmt) {
@@ -191,10 +227,7 @@ int emcOperatorText(int id, const char *fmt, ...)
191
227
EMC_OPERATOR_TEXT text_msg;
192
228
va_list ap;
193
229
194
- // check channel for validity
195
- if (emcErrorBuffer == NULL )
196
- return -1 ;
197
- if (!emcErrorBuffer->valid ())
230
+ if ( emcErrorBufferOKtoWrite (sizeof (text_msg) * 2 , " emcOperatorText" ))
198
231
return -1 ;
199
232
200
233
// write args to NML message (ignore int text code)
@@ -214,10 +247,7 @@ int emcOperatorDisplay(int id, const char *fmt, ...)
214
247
EMC_OPERATOR_DISPLAY display_msg;
215
248
va_list ap;
216
249
217
- // check channel for validity
218
- if (emcErrorBuffer == NULL )
219
- return -1 ;
220
- if (!emcErrorBuffer->valid ())
250
+ if ( emcErrorBufferOKtoWrite (sizeof (display_msg) * 2 , " emcOperatorDisplay" ))
221
251
return -1 ;
222
252
223
253
// write args to NML message (ignore int display code)
0 commit comments