// issues command immediately
static int emcTaskIssueCommand(NMLmsg * cmd) 解释器执行
// interpreter commands
case EMC_TASK_PLAN_OPEN_TYPE:
open_msg = (EMC_TASK_PLAN_OPEN *) cmd;
retval = emcTaskPlanOpen(open_msg->file);
if (retval > INTERP_MIN_ERROR) {
retval = -1;
}
if (-1 == retval) {
emcOperatorError(0, _("can't open %s"), open_msg->file);
} else {
strcpy(emcStatus->task.file, open_msg->file);
retval = 0;
}
break;
case EMC_TASK_PLAN_EXECUTE_TYPE:
stepping = 0;
steppingWait = 0;
execute_msg = (EMC_TASK_PLAN_EXECUTE *) cmd;
if (!all_homed() && !no_force_homing) { //!no_force_homing = force homing before MDI
emcOperatorError(0, _("Can't issue MDI command when not homed"));
retval = -1;
break;
}
if (emcStatus->task.mode != EMC_TASK_MODE_MDI) {
emcOperatorError(0, _("Must be in MDI mode to issue MDI command"));
retval = -1;
break;
}
// track interpState also during MDI - it might be an oword sub call
emcStatus->task.interpState = EMC_TASK_INTERP_READING;
if (execute_msg->command[0] != 0) {
char * command = execute_msg->command;
if (command[0] == (char) 0xff) {
// Empty command recieved. Consider it is NULL
command = NULL;
} else {
// record initial MDI command
strcpy(emcStatus->task.command, execute_msg->command);
}
int level = emcTaskPlanLevel();
if (emcStatus->task.mode == EMC_TASK_MODE_MDI) {
if (mdi_execute_level < 0)
mdi_execute_level = level;
}
execRetval = emcTaskPlanExecute(command, 0);
level = emcTaskPlanLevel();
if (emcStatus->task.mode == EMC_TASK_MODE_MDI) {
if (mdi_execute_level == level) {
mdi_execute_level = -1;
} else if (level > 0) {
// Still insude call. Need another execute(0) call
// but only if we didnt encounter an error
if (execRetval == INTERP_ERROR) {
mdi_execute_next = 0;
} else {
mdi_execute_next = 1;
}
}
}
switch (execRetval) {
case INTERP_EXECUTE_FINISH:
// Flag MDI wait
mdi_execute_wait = 1;
// need to flush execution, so signify no more reading
// until all is done
emcTaskPlanSetWait();
// and resynch the interpreter WM
emcTaskQueueCommand(&taskPlanSynchCmd);
// it's success, so retval really is 0
retval = 0;
break;
case INTERP_ERROR:
// emcStatus->task.interpState = EMC_TASK_INTERP_WAITING;
interp_list.clear();
// abort everything
emcTaskAbort();
emcIoAbort(EMC_ABORT_INTERPRETER_ERROR_MDI);
emcSpindleAbort();
mdi_execute_abort(); // sets emcStatus->task.interpState to EMC_TASK_INTERP_IDLE
emcAbortCleanup(EMC_ABORT_INTERPRETER_ERROR_MDI, "interpreter error during MDI");
retval = -1;
break;
case INTERP_EXIT:
case INTERP_ENDFILE:
case INTERP_FILE_NOT_OPEN:
// this caused the error msg on M2 in MDI mode - execRetval == INTERP_EXIT which is would be ok (I think). mah
retval = -1;
break;
default:
// other codes are OK
retval = 0;
}
}
break;
case EMC_TASK_PLAN_RUN_TYPE:
if (!all_homed() && !no_force_homing) { //!no_force_homing = force homing before Auto
emcOperatorError(0, _("Can't run a program when not homed"));
retval = -1;
break;
}
stepping = 0;
steppingWait = 0;
if (!taskplanopen && emcStatus->task.file[0] != 0) {
emcTaskPlanOpen(emcStatus->task.file);
}
run_msg = (EMC_TASK_PLAN_RUN *) cmd;
programStartLine = run_msg->line;
emcStatus->task.interpState = EMC_TASK_INTERP_READING;
emcStatus->task.task_paused = 0;
retval = 0;
break;
case EMC_TASK_PLAN_PAUSE_TYPE:
emcTrajPause();
if (emcStatus->task.interpState != EMC_TASK_INTERP_PAUSED) {
interpResumeState = emcStatus->task.interpState;
}
emcStatus->task.interpState = EMC_TASK_INTERP_PAUSED;
emcStatus->task.task_paused = 1;
retval = 0;
break;
case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE:
if (GET_OPTIONAL_PROGRAM_STOP() == ON) {
emcTrajPause();
if (emcStatus->task.interpState != EMC_TASK_INTERP_PAUSED) {
interpResumeState = emcStatus->task.interpState;
}
emcStatus->task.interpState = EMC_TASK_INTERP_PAUSED;
emcStatus->task.task_paused = 1;
}
retval = 0;
break;
case EMC_TASK_PLAN_RESUME_TYPE:
emcTrajResume();
emcStatus->task.interpState =
(enum EMC_TASK_INTERP_ENUM) interpResumeState;
emcStatus->task.task_paused = 0;
stepping = 0;
steppingWait = 0;
retval = 0;
break;
case EMC_TASK_PLAN_END_TYPE:
retval = 0;
break;
case EMC_TASK_PLAN_INIT_TYPE:
retval = emcTaskPlanInit();
if (retval > INTERP_MIN_ERROR) {
retval = -1;
}
break;
case EMC_TASK_PLAN_SYNCH_TYPE:
retval = emcTaskPlanSynch();
if (retval > INTERP_MIN_ERROR) {
retval = -1;
}
break;
case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE:
os_msg = (EMC_TASK_PLAN_SET_OPTIONAL_STOP *) cmd;
emcTaskPlanSetOptionalStop(os_msg->state);
retval = 0;
break;
case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE:
bd_msg = (EMC_TASK_PLAN_SET_BLOCK_DELETE *) cmd;
emcTaskPlanSetBlockDelete(bd_msg->state);
retval = 0;
break;
case EMC_EXEC_PLUGIN_CALL_TYPE:
retval = emcPluginCall( (EMC_EXEC_PLUGIN_CALL *) cmd);
break;
case EMC_IO_PLUGIN_CALL_TYPE:
retval = emcIoPluginCall( (EMC_IO_PLUGIN_CALL *) cmd);
break;