Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

emcpanel.cc

Go to the documentation of this file.
00001 /*
00002   emcpanel.cc
00003 
00004   New, improved EMC text operator interface
00005 
00006   Modification history:
00007 
00008   1-Jun-2001  FMP added printing of debug levels in task, IO
00009   23-May-2001  FMP added display of program units
00010   30-Mar-2000 WPS added ferrorCurrent display.
00011   22-Jan-2000  FMP added "out" for setting axis output
00012   17-Aug-1999  FMP took out EMC_TASK_INTERP_STEPPING
00013   16-Jun-1999  FMP added printing of axis setpoint
00014   21-May-1999  FMP added EMC_LOG_TYPE_TRAJ_POS, changing TRAJ_INPOS,OUTPOS
00015   to AXES_INPOS,OUTPOS
00016   22-Mar-1999  FMP added line to emc_task_plan_run_msg
00017   7-Jan-1999  FMP added -noerror flag for catchErrors
00018   21-Oct-1998  FMP added EMC_COMMAND_TIMEOUT,DELAY instead of
00019   task cycle time ini file var in emcCommandWait()
00020   15-Oct-1998  FMP changed from NML_ERROR to EMC_OPERATOR_ERROR, etc.
00021   25-Jun-1998  FMP added better program line number, program text printing
00022   25-Mar-1998  FMP changed usleep() to esleep()
00023   4-Mar-1998  FMP added command line arg processing for -nml; added
00024   EMC_NMLFILE from emcglb.h
00025   26-Feb-1998  FMP added brake off/on for emctask
00026   24-Feb-1998  FMP added printing of origin in showProgram()
00027   23-Feb-1998  FMP grouped 0 and id matches when peeking together, so
00028   0 reads still update status. This has the effect of re-reading the
00029   serial number, which doesn't change anything but it does make it
00030   consistent with safe programming practice.
00031   20-Feb-1998  FMP added printing of axis enabled flags
00032   19-Feb-1998  FMP added /, // for axis, traj abort
00033   17-Feb-1998  FMP added homing, homed to axis status printing
00034   15-Jan-1998  FMP added null check on emcStatus before printing, in
00035   emcpanelShow()
00036   16-Oct-1997  FMP created
00037 */
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00042 #include <ctype.h>              // isspace()
00043 #include "getinput.h"           // getinput()
00044 
00045 #include "rcs.hh"               // rcs_print_error(), esleep()
00046 #include "emc.hh"               // EMC NML
00047 #include "canon.hh"             // CANON_UNITS
00048 #include "rs274ngc.hh"          // NUM_G_CODES, NUM_M_CODES
00049 #include "nml_mod.hh"           // SO, S1, RCS_DONE
00050 #include "emcglb.h"             // EMC_NMLFILE
00051 
00052 /* ident tag */
00053 #ifndef __GNUC__
00054 #ifndef __attribute__
00055 #define __attribute__(x)
00056 #endif
00057 #endif
00058 
00059 static char __attribute__((unused)) ident[] = "$Id: emcpanel.cc,v 1.7 2001/06/29 20:27:29 wshackle Exp $";
00060 
00061 // the NML channels to the EMC task
00062 static RCS_CMD_CHANNEL *emcCommandBuffer = 0;
00063 static RCS_STAT_CHANNEL *emcStatusBuffer = 0;
00064 EMC_STAT *emcStatus = 0;
00065 
00066 // the NML channels to the EMCIO controller
00067 static RCS_CMD_CHANNEL *emcIoCommandBuffer = 0;
00068 static RCS_STAT_CHANNEL *emcIoStatusBuffer = 0;
00069 EMC_IO_STAT *emcIoStatus = 0;
00070 
00071 // the NML channel for errors
00072 static NML *emcErrorBuffer = 0;
00073 
00074 // the current command numbers, set up updateStatus(), used in main()
00075 static int emcCommandSerialNumber = 0;
00076 static int emcIoCommandSerialNumber = 0;
00077 
00078 // internal params
00079 
00080 // the saved program name
00081 static char programFile[EMC_TASK_FILENAME_LEN] = "";
00082 static int programOpened = 0;
00083 static FILE * programFp = 0;
00084 static int programFpLine = 0;
00085 static int programActiveLine = 0;
00086 static char programLineText[EMC_TASK_COMMAND_LEN] = "";
00087 
00088 // saved log file params
00089 static char saveLogFile[EMC_LOG_FILENAME_LEN] = "emc.log";
00090 static int saveLogType = EMC_LOG_TYPE_AXIS_POS;
00091 static int saveLogSize = 1000;
00092 static int saveLogSkip = 0;
00093 static int saveLogAxis = 0;
00094 
00095 // paths to awk and xgraph, using to plot logs
00096 // fill these in for your system, if these are not in user's path
00097 #define AWK_PATH "awk"
00098 #define XGRAPH_PATH "xgraph"
00099 #define SYSTEM_STRING_LEN 1024
00100 
00101 static int plotLog(const char * logfile, int logtype, int which)
00102 {
00103   char string[SYSTEM_STRING_LEN];
00104   int retval;
00105 
00106   if (logfile == 0)
00107     {
00108       return -1;
00109     }
00110 
00111   switch (logtype)
00112     {
00113     case EMC_LOG_TYPE_AXIS_POS:
00114       sprintf(string, "( %s '{print $1 \" \" $2}' < %s ; echo \"\" ; %s '{print $1 \" \" $3}' < %s ) 2> /dev/null | %s -m 1> /dev/null 2> /dev/null", AWK_PATH, logfile, AWK_PATH, logfile, XGRAPH_PATH);
00115       break;
00116 
00117     case EMC_LOG_TYPE_AXES_INPOS:
00118     case EMC_LOG_TYPE_AXES_OUTPOS:
00119       sprintf(string, "%s '{print $2 \" \" $3}' < %s 2> /dev/null | %s -m 1> /dev/null 2> /dev/null", AWK_PATH, logfile, XGRAPH_PATH);
00120       break;
00121 
00122     default:
00123       return -1;
00124       break;
00125     }
00126 
00127   retval = system(string);
00128 
00129   return retval;
00130 }
00131 
00132 // values for axisSelect, set so they can be used as 'axis' arg in NML
00133 enum {AXIS_X = 0,
00134       AXIS_Y,
00135       AXIS_Z};
00136 
00137 // values for jogSelect
00138 enum {JOG_CONT = 1,
00139       JOG_INCR};
00140 
00141 static int axisSelect = AXIS_X;
00142 static double speedSelect = 1.0;
00143 static double jogIncr = 1.0;
00144 static int jogSelect = JOG_CONT;
00145 
00146 // flag to signify that the prompt should be reprinted
00147 static int printPrompt;
00148 
00149 // size of input buffer
00150 #define INPUTLEN 80
00151 
00152 // microseconds to sleep between calls to getinput()
00153 #define SLEEP_SECS 0.100
00154 
00155 static enum {
00156   DISPLAY_ABS = 1,
00157   DISPLAY_REL
00158 } displayMode = DISPLAY_ABS;
00159 
00160 // takes a string, and returns 0 if all whitespace, 1 otherwise
00161 static int anyprintable(const char *string)
00162 {
00163   int cnt = 0;
00164   char c;
00165 
00166   while (0 != (c = string[cnt++]))
00167     {
00168       if (!isspace(c))
00169         {
00170           return 1;
00171         }
00172     }
00173 
00174   return 0;
00175 }
00176 
00177 static int emcTaskNmlGet()
00178 {
00179   int retval = 0;
00180 
00181   // try to connect to NC cmd
00182   if (emcCommandBuffer == 0)
00183     {
00184       printf("trying emcCommand...");
00185       emcCommandBuffer = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcpanel", EMC_NMLFILE);
00186       if (! emcCommandBuffer->valid())
00187         {
00188           delete emcCommandBuffer;
00189           emcCommandBuffer = 0;
00190           retval = -1;
00191           printf("failed\n");
00192         }
00193       printf("got it\n");
00194     }
00195 
00196   // try to connect to NC status
00197   if (emcStatusBuffer == 0)
00198     {
00199       printf("trying emcStatus...");
00200       emcStatusBuffer = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcpanel", EMC_NMLFILE);
00201       if (! emcStatusBuffer->valid() ||
00202           EMC_STAT_TYPE != emcStatusBuffer->peek())
00203         {
00204           delete emcStatusBuffer;
00205           emcStatusBuffer = 0;
00206           emcStatus = 0;
00207           retval = -1;
00208           printf("failed\n");
00209         }
00210       else
00211         {
00212           emcStatus = (EMC_STAT *) emcStatusBuffer->get_address();
00213           printf("got it\n");
00214         }
00215     }
00216 
00217   return retval;
00218 }
00219 
00220 static int emcErrorNmlGet()
00221 {
00222   int retval = 0;
00223 
00224   if (emcErrorBuffer == 0)
00225     {
00226       printf("trying emcError...");
00227       emcErrorBuffer = new NML(nmlErrorFormat, "emcError", "emcpanel", EMC_NMLFILE);
00228       if (! emcErrorBuffer->valid())
00229         {
00230           rcs_print_error("emcError channel not available\n");
00231           delete emcErrorBuffer;
00232           emcErrorBuffer = 0;
00233           retval = -1;
00234           printf("failed\n");
00235         }
00236       printf("got it\n");
00237     }
00238 
00239   return retval;
00240 }
00241 
00242 static int emcIoNmlGet()
00243 {
00244   int retval = 0;
00245 
00246   if (emcIoCommandBuffer == 0)
00247     {
00248       printf("trying toolCmd...");
00249       emcIoCommandBuffer = new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcpanel", EMC_NMLFILE);
00250       if (! emcIoCommandBuffer->valid())
00251         {
00252           delete emcIoCommandBuffer;
00253           emcIoCommandBuffer = 0;
00254           retval = -1;
00255           printf("failed\n");
00256         }
00257       printf("got it\n");
00258     }
00259 
00260   if (emcIoStatusBuffer == 0)
00261     {
00262       printf("tring toolSts...");
00263       emcIoStatusBuffer = new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcpanel", EMC_NMLFILE);
00264       if (! emcIoStatusBuffer->valid() ||
00265           EMC_IO_STAT_TYPE != emcIoStatusBuffer->peek())
00266         {
00267           delete emcIoStatusBuffer;
00268           emcIoStatusBuffer = 0;
00269           emcIoStatus = 0;
00270           retval = -1;
00271           printf("failed\n");
00272         }
00273       else
00274         {
00275           emcIoStatus = (EMC_IO_STAT *) emcIoStatusBuffer->get_address();
00276           printf("got it\n");
00277         }
00278     }
00279 
00280   return retval;
00281 }
00282 
00283 static int emcpanelQuit()
00284 {
00285   if (emcIoStatusBuffer != 0)
00286     {
00287       delete emcIoStatusBuffer;
00288       emcIoStatusBuffer = 0;
00289       emcIoStatus = 0;
00290     }
00291 
00292   if (emcIoCommandBuffer != 0)
00293     {
00294       delete emcIoCommandBuffer;
00295       emcIoCommandBuffer = 0;
00296     }
00297 
00298   if (emcErrorBuffer != 0)
00299     {
00300       delete emcErrorBuffer;
00301       emcErrorBuffer = 0;
00302     }
00303 
00304   if (emcStatusBuffer != 0)
00305     {
00306       delete emcStatusBuffer;
00307       emcStatusBuffer = 0;
00308       emcStatus = 0;
00309     }
00310 
00311   if (emcCommandBuffer != 0)
00312     {
00313       delete emcCommandBuffer;
00314       emcCommandBuffer = 0;
00315     }
00316 
00317   return 0;
00318 }
00319 
00320 #define STRLEN 80
00321 static char *state_to_string(int state)
00322 {
00323   static char scratch[STRLEN];
00324 
00325   switch (state)
00326     {
00327     case NEW_COMMAND:
00328       return "NEW_COMMAND";
00329     case S0:
00330       return "S0";
00331     case S1:
00332       return "S1";
00333     case S2:
00334       return "S2";
00335     case S3:
00336       return "S3";
00337     case S4:
00338       return "S4";
00339     case S5:
00340       return "S5";
00341     case S6:
00342       return "S6";
00343     case S7:
00344       return "S7";
00345     case S8:
00346       return "S8";
00347     case S9:
00348       return "S9";
00349     case S10:
00350       return "S10";
00351     case S11:
00352       return "S11";
00353     case S12:
00354       return "S12";
00355     default:
00356       sprintf(scratch, "%d", state);
00357       return scratch;
00358     }
00359 }
00360 
00361 static char *status_to_string(int status)
00362 {
00363   static char scratch[STRLEN];
00364 
00365   switch (status)
00366     {
00367     case RCS_DONE:
00368       return "DONE";
00369     case RCS_EXEC:
00370       return "EXEC";
00371     case RCS_ERROR:
00372       return "ERROR";
00373     default:
00374       sprintf(scratch, "%d", status);
00375       return scratch;
00376     }
00377 }
00378 
00379 /*
00380  btostr()
00381 
00382  converts byte to 0-1 style string, in s. Assumes a byte is 8 bits.
00383 */
00384 static int btostr(char * s, unsigned char b)
00385 {
00386   int t;
00387 
00388   for (t = 7; t >= 0; t--)
00389     {
00390       s[t] = b % 2 ? '1' : '0';
00391       b >>= 1;
00392     }
00393   s[8] = 0;                     /* null terminate */
00394 
00395   return 0;
00396 }
00397 
00398 static void showState()
00399 {
00400   if (0 == emcStatus)
00401     {
00402       return;
00403     }
00404 
00405   printf("Heartbeat: \t%lu\n", emcStatus->task.heartbeat);
00406   printf("Debug:     \t%d\n", emcStatus->debug);
00407   printf("State:     \t");
00408   switch (emcStatus->task.state)
00409     {
00410     case EMC_TASK_STATE_OFF:
00411       printf("OFF\n");
00412       break;
00413     case EMC_TASK_STATE_ON:
00414       printf("ON\n");
00415       break;
00416     case EMC_TASK_STATE_ESTOP:
00417       printf("ESTOP\n");
00418       break;
00419     case EMC_TASK_STATE_ESTOP_RESET:
00420       printf("ESTOP RESET\n");
00421       break;
00422     default:
00423       printf("%d (?)\n", emcStatus->task.state);
00424       break;
00425     }
00426 }
00427 
00428 static void showMode()
00429 {
00430   if (0 == emcStatus)
00431     {
00432       return;
00433     }
00434 
00435   printf("Mode:\t\t");
00436   switch (emcStatus->task.mode)
00437     {
00438     case EMC_TASK_MODE_AUTO:
00439       printf("AUTO\n");
00440       break;
00441     case EMC_TASK_MODE_MDI:
00442       printf("MDI\n");
00443       break;
00444     case EMC_TASK_MODE_MANUAL:
00445       printf("MANUAL\n");
00446       break;
00447     default:
00448       printf("%d (?)\n", emcStatus->task.mode);
00449       break;
00450     }
00451 }
00452 
00453 static void showPosition()
00454 {
00455   int axis;
00456 
00457   if (0 == emcStatus)
00458     {
00459       return;
00460     }
00461 
00462   if (displayMode == DISPLAY_ABS)
00463     {
00464       printf("Cmd Pos: \t%f\t%f\t%f\n",
00465              emcStatus->motion.traj.position.tran.x,
00466              emcStatus->motion.traj.position.tran.y,
00467              emcStatus->motion.traj.position.tran.z);
00468       printf("Act Pos: \t%f\t%f\t%f\n",
00469              emcStatus->motion.traj.actualPosition.tran.x,
00470              emcStatus->motion.traj.actualPosition.tran.y,
00471              emcStatus->motion.traj.actualPosition.tran.z);
00472     }
00473   else if (displayMode == DISPLAY_REL)
00474     {
00475       printf("Cmd Pos: \t%f\t%f\t%f\n",
00476              emcStatus->motion.traj.position.tran.x -
00477              emcStatus->task.origin.tran.x,
00478              emcStatus->motion.traj.position.tran.y -
00479              emcStatus->task.origin.tran.y,
00480              emcStatus->motion.traj.position.tran.z -
00481              emcStatus->task.origin.tran.z);
00482       printf("Act Pos: \t%f\t%f\t%f\n",
00483              emcStatus->motion.traj.actualPosition.tran.x -
00484              emcStatus->task.origin.tran.x,
00485              emcStatus->motion.traj.actualPosition.tran.y -
00486              emcStatus->task.origin.tran.y,
00487              emcStatus->motion.traj.actualPosition.tran.z -
00488              emcStatus->task.origin.tran.z);
00489     }
00490   else
00491     {
00492       printf("Position:\t(display mode not abs or rel: %d)\n",
00493              displayMode);
00494     }
00495 
00496   printf("Axes:    ");
00497   for (axis = 0; axis < EMC_AXIS_MAX; axis++) {
00498     printf("\t%f", emcStatus->motion.axis[axis].setpoint);
00499   }
00500   printf("\n");
00501 
00502   printf("Queue:   \t%d\n",
00503          emcStatus->motion.traj.queue);
00504   printf("Inpos:   \t%d\n",
00505          emcStatus->motion.traj.inpos);
00506   printf("V Scale: \t%.2f\n",
00507          emcStatus->motion.traj.scale);
00508 }
00509 
00510 static void showParams()
00511 {
00512   printf("Axis:    \t%s\n",
00513          axisSelect == AXIS_X ? "X" :
00514          axisSelect == AXIS_Y ? "Y" :
00515          axisSelect == AXIS_Z ? "Z" : "?");
00516   printf("Speed:   \t%f\n", speedSelect);
00517   printf("Jog Type:\t%s\n",
00518          jogSelect == JOG_CONT ? "CONT" :
00519          jogSelect == JOG_INCR ? "INCR" : "?");
00520   printf("Jog Incr:\t%f\n", jogIncr);
00521 }
00522 
00523 static void showProgram()
00524 {
00525   if (0 == emcStatus) {
00526     return;
00527   }
00528 
00529   if (! programOpened) {
00530     // print the last one opened, since we'll send this by default
00531     printf("Program: \t%s\n", programFile);
00532   }
00533   else {
00534     // print the one the controller knows about
00535     printf("Program: \t%s\n", emcStatus->task.file);
00536   }
00537 
00538   if (emcStatus->task.currentLine > 0) {
00539     if (emcStatus->task.motionLine > 0 &&
00540         emcStatus->task.motionLine < emcStatus->task.currentLine) {
00541       programActiveLine = emcStatus->task.motionLine;
00542     }
00543     else {
00544       programActiveLine = emcStatus->task.currentLine;
00545     }
00546 
00547     if (programFp != 0) {
00548       if (programFpLine > programActiveLine) {
00549         rewind(programFp);
00550         programFpLine = 0;
00551         programLineText[0] = 0;
00552       }
00553       else {
00554         while (programFpLine < programActiveLine) {
00555           fgets(programLineText, EMC_TASK_COMMAND_LEN, programFp);
00556           programFpLine++;
00557         }
00558       }
00559     }
00560     else {
00561       programLineText[0] = 0;
00562     }
00563   }
00564   else {
00565     programActiveLine = 0;
00566     programLineText[0] = 0;
00567   }
00568 
00569   printf("Units:   \t%s\n", 
00570          emcStatus->task.programUnits == CANON_UNITS_INCHES ? "inches" :
00571          emcStatus->task.programUnits == CANON_UNITS_MM ? "mm" :
00572          emcStatus->task.programUnits == CANON_UNITS_CM ? "cm" : "?");
00573          
00574   printf("Line:    \t%d\n", programActiveLine);
00575   printf("Command: \t%s\n", programLineText);
00576 
00577   printf("Origin:  \t%f\t%f\t%f\n",
00578          emcStatus->task.origin.tran.x,
00579          emcStatus->task.origin.tran.y,
00580          emcStatus->task.origin.tran.z);
00581 }
00582 
00583 static void showEmcTaskExec()
00584 {
00585   if (0 == emcStatus)
00586     {
00587       return;
00588     }
00589 
00590   printf("NML:         \tcmd\tser #\tstatus\n");
00591   printf("             \t%ld\t%d\t%s\n",
00592          emcStatus->command_type, emcStatus->echo_serial_number,
00593          emcStatus->status == RCS_DONE ? "DONE" :
00594          emcStatus->status == RCS_EXEC ? "EXEC" :
00595          emcStatus->status == RCS_ERROR ? "ERROR" : "(?)");
00596 
00597   printf("Exec:         \t%s\n",
00598          emcStatus->task.execState == EMC_TASK_EXEC_ERROR ? "ERROR" :
00599          emcStatus->task.execState == EMC_TASK_EXEC_DONE ? "DONE" :
00600          emcStatus->task.execState == EMC_TASK_EXEC_WAITING_FOR_MOTION ? "MOTION WAIT" :
00601          emcStatus->task.execState == EMC_TASK_EXEC_WAITING_FOR_IO ? "IO WAIT" :
00602          emcStatus->task.execState == EMC_TASK_EXEC_WAITING_FOR_MOTION_QUEUE ? "QUEUE WAIT" :
00603          emcStatus->task.execState == EMC_TASK_EXEC_WAITING_FOR_PAUSE ? "PAUSE WAIT" :
00604          emcStatus->task.execState == EMC_TASK_EXEC_WAITING_FOR_MOTION_AND_IO ? "MOTION AND IO WAIT" :
00605          "?");
00606 
00607   printf("Interp:       \t%s\n",
00608          emcStatus->task.interpState == EMC_TASK_INTERP_IDLE ? "IDLE" :
00609          emcStatus->task.interpState == EMC_TASK_INTERP_READING ? "READING" :
00610          emcStatus->task.interpState == EMC_TASK_INTERP_PAUSED ? "PAUSED" :
00611          emcStatus->task.interpState == EMC_TASK_INTERP_WAITING ? "WAITING" :
00612          "?");
00613 
00614   printf("Motion line:  \t%d\n", emcStatus->task.motionLine);
00615   printf("Current line: \t%d\n", emcStatus->task.currentLine);
00616   printf("Read line:    \t%d\n", emcStatus->task.readLine);
00617 }
00618 
00619 static void showEmcio()
00620 {
00621   int t;
00622   char bits[9];                 // for "11011001\0" bits string
00623 
00624   if (0 == emcIoStatus)
00625     {
00626       return;
00627     }
00628 
00629   printf("emcio status:    %ld %d %s %s %d %d %s\n",
00630          emcIoStatus->command_type,
00631          emcIoStatus->echo_serial_number,
00632          status_to_string(emcIoStatus->status),
00633          state_to_string(emcIoStatus->state),
00634          emcIoStatus->line,
00635          emcIoStatus->source_line,
00636          emcIoStatus->source_file);
00637 
00638   printf("heartbeat:       %lu\n", emcIoStatus->heartbeat);
00639 
00640   printf("debug level:     %d\n", emcIoStatus->debug);
00641 
00642   printf("tools:           pocket\ttool\tlength\t\tdiameter\n");
00643   printf("                 ------\t----\t------\t\t--------\n");
00644   for (t = 0; t < CANON_TOOL_MAX; t++)
00645     {
00646       if (emcIoStatus->tool.toolTable[t].id != 0)
00647         {
00648           printf("                 %d\t%d\t%10.4f\t%10.4f\n",
00649                  t,
00650                  emcIoStatus->tool.toolTable[t].id,
00651                  emcIoStatus->tool.toolTable[t].length,
00652                  emcIoStatus->tool.toolTable[t].diameter);
00653         }
00654     }
00655 
00656   printf("tool prepped:    %d\n",
00657          emcIoStatus->tool.toolPrepped);
00658   printf("tool in spindle: %d\n",
00659          emcIoStatus->tool.toolInSpindle);
00660 
00661   printf("spindle:         %.0f RPM, %s\n",
00662          emcIoStatus->spindle.speed,
00663          emcIoStatus->spindle.brake == 0 ? "free" : "braked");
00664 
00665   printf("mist:            %s\n",
00666          emcIoStatus->coolant.mist == 0 ? "OFF" : "ON");
00667   printf("flood:           %s\n",
00668          emcIoStatus->coolant.flood == 0 ? "OFF" : "ON");
00669 
00670   printf("estop:           %s\n",
00671          emcIoStatus->aux.estop == 0 ? "OFF" : "ESTOPPED");
00672 
00673   printf("lube:            %s\n",
00674          emcIoStatus->lube.on == 0 ? "OFF" : "ON");
00675 
00676   printf("lube level:      %s\n",
00677          emcIoStatus->lube.level == 0 ? "LOW" : "OK");
00678 
00679   printf("digital ins:     ");
00680   for (t = EMC_AUX_MAX_DIN - 1; t >= 0; t--)
00681     {
00682       btostr(bits, emcIoStatus->aux.din[t]);
00683       printf("%s ", bits);
00684     }
00685   printf("\n");
00686 
00687   printf("digital outs:    ");
00688   for (t = EMC_AUX_MAX_DOUT - 1; t >= 0; t--)
00689     {
00690       btostr(bits, emcIoStatus->aux.dout[t]);
00691       printf("%s ", bits);
00692     }
00693   printf("\n");
00694 }
00695 
00696 static void showTools()
00697 {
00698   int t;
00699 
00700   if (0 == emcStatus)
00701     {
00702       return;
00703     }
00704 
00705   printf("pocket\ttool\tlength\tdiameter\n");
00706   printf("------\t----\t------\t--------\n");
00707   for (t = 0; t < CANON_TOOL_MAX; t++)
00708     {
00709       if (emcStatus->io.tool.toolTable[t].id != 0)
00710         {
00711           printf("%d\t%d\t%f\t%f\n",
00712                  t,
00713                  emcStatus->io.tool.toolTable[t].id,
00714                  emcStatus->io.tool.toolTable[t].length,
00715                  emcStatus->io.tool.toolTable[t].diameter);
00716         }
00717     }
00718 }
00719 
00720 static void showAxis()
00721 {
00722   int axis;
00723 
00724   axis = axisSelect;
00725 
00726   printf("axis:\t\t\t%d\n", emcStatus->motion.axis[axis].axis);
00727 
00728   printf("type:\t\t\t%s\n",
00729          emcStatus->motion.axis[axis].axisType == EMC_AXIS_LINEAR ? "LINEAR" :
00730          emcStatus->motion.axis[axis].axisType == EMC_AXIS_ANGULAR ? "ANGULAR" :
00731          "?");
00732   printf("units:\t\t\t%f\n", emcStatus->motion.axis[axis].units);
00733 
00734   printf("P I D FF0 FF1 FF2:\t%.3f %.3f %.3f %.3f %.3f %.3f\n",
00735          emcStatus->motion.axis[axis].p,
00736          emcStatus->motion.axis[axis].i,
00737          emcStatus->motion.axis[axis].d,
00738          emcStatus->motion.axis[axis].ff0,
00739          emcStatus->motion.axis[axis].ff1,
00740          emcStatus->motion.axis[axis].ff2);
00741   printf("cycle time:\t\t%f\n", emcStatus->motion.axis[axis].cycleTime);
00742 
00743   printf("input scale:\t\t%f %f\n",
00744          emcStatus->motion.axis[axis].inputScale,
00745          emcStatus->motion.axis[axis].inputOffset);
00746 
00747   printf("output scale:\t\t%f %f\n",
00748          emcStatus->motion.axis[axis].outputScale,
00749          emcStatus->motion.axis[axis].outputOffset);
00750 
00751   printf("pos limits:\t\t%f %f\n",
00752          emcStatus->motion.axis[axis].minPositionLimit,
00753          emcStatus->motion.axis[axis].maxPositionLimit);
00754 
00755   printf("output limits:\t\t%f %f\n",
00756          emcStatus->motion.axis[axis].minOutputLimit,
00757          emcStatus->motion.axis[axis].maxOutputLimit);
00758 
00759   printf("max ferror:\t\t%f\n", emcStatus->motion.axis[axis].maxFerror);
00760 
00761   printf("polarity:\t\tEN\tLS-\tLS+\tHS\tH\tF\n");
00762   printf("\t\t\t%d\t %d\t %d\t%d\t%d\t%d\n",
00763          (int) emcStatus->motion.axis[axis].enablePolarity,
00764          (int) emcStatus->motion.axis[axis].minLimitSwitchPolarity,
00765          (int) emcStatus->motion.axis[axis].maxLimitSwitchPolarity,
00766          (int) emcStatus->motion.axis[axis].homeSwitchPolarity,
00767          (int) emcStatus->motion.axis[axis].homingPolarity,
00768          (int) emcStatus->motion.axis[axis].faultPolarity);
00769 
00770   printf("setpoint:   \t\t%f\n", emcStatus->motion.axis[axis].setpoint);
00771   printf("ferror:     \t\t%f\n", emcStatus->motion.axis[axis].ferrorCurrent);
00772   printf("ferrorHighMark:     \t\t%f\n", emcStatus->motion.axis[axis].ferrorHighMark);
00773   printf("output:     \t\t%f\n", emcStatus->motion.axis[axis].output);
00774   printf("input:      \t\t%f\n", emcStatus->motion.axis[axis].input);
00775   printf("homing:     \t\t%s\n",
00776          emcStatus->motion.axis[axis].homing == 1 ? "homing" : "done");
00777   printf("homed:      \t\t%s\n",
00778          emcStatus->motion.axis[axis].homed == 1 ? "home" : "not yet");
00779   printf("enabled:    \t\t%s\n",
00780          emcStatus->motion.axis[axis].enabled == 1 ? "ON" : "OFF");
00781 }
00782 
00783 static void showCodes()
00784 {
00785   int t;
00786   int code;
00787 
00788   if (0 == emcStatus)
00789     {
00790       return;
00791     }
00792 
00793   for (t = 1; t < EMC_TASK_ACTIVE_G_CODES; t++)
00794     {
00795       code = emcStatus->task.activeGCodes[t];
00796       if (code == -1)
00797         continue;
00798       if (code % 10)
00799         printf("G%.1f ", (double) code / 10.0);
00800       else
00801         printf("G%d ", code / 10);
00802     }
00803   printf("\n");
00804 }
00805 
00806 static void emcpanelShow(int toPrint)
00807 {
00808   switch (toPrint)
00809     {
00810     case 0:
00811       // show default stuff
00812       showState();
00813       showMode();
00814       showPosition();
00815       showProgram();
00816       showEmcTaskExec();
00817       break;
00818 
00819     case 1:
00820       // show state
00821       showState();
00822       break;
00823 
00824     case 2:
00825       // show mode
00826       showMode();
00827       break;
00828 
00829     case 3:
00830       // show position
00831       showPosition();
00832       break;
00833 
00834     case 4:
00835       // show internal params
00836       showParams();
00837       break;
00838 
00839     case 5:
00840       // show interpreter
00841       showProgram();
00842       break;
00843 
00844     case 6:
00845       // show EMC TASK
00846       showEmcTaskExec();
00847       break;
00848 
00849     case 8:
00850       // show EMC IO
00851       showEmcio();
00852       break;
00853 
00854     case 9:
00855       // show tool table
00856       showTools();
00857       break;
00858 
00859     case 10:
00860       // show axis info
00861       showAxis();
00862       break;
00863 
00864     case 11:
00865       // show active g codes
00866       showCodes();
00867       break;
00868 
00869     default:
00870       // huh?
00871       printf("invalid request to show: %d\n", toPrint);
00872       break;
00873     }
00874 }
00875 
00876 static void printErrors()
00877 {
00878   NMLTYPE type;
00879 
00880   if (0 == emcErrorBuffer ||
00881       ! emcErrorBuffer->valid())
00882     {
00883       return;
00884     }
00885 
00886   switch (type = emcErrorBuffer->read())
00887     {
00888     case 0:
00889       // nothing new
00890       break;
00891 
00892     case -1:
00893       // error reading channel
00894       break;
00895 
00896     case EMC_OPERATOR_ERROR_TYPE:
00897       printf("\nerror: [%d] %s\n",
00898              ((EMC_OPERATOR_ERROR *) (emcErrorBuffer->get_address()))->id,
00899              ((EMC_OPERATOR_ERROR *) (emcErrorBuffer->get_address()))->error);
00900       printPrompt = 1;
00901       break;
00902 
00903     case EMC_OPERATOR_TEXT_TYPE:
00904       printf("\ntext: [%d] %s\n",
00905              ((EMC_OPERATOR_TEXT *) (emcErrorBuffer->get_address()))->id,
00906              ((EMC_OPERATOR_TEXT *) (emcErrorBuffer->get_address()))->text);
00907       printPrompt = 1;
00908       break;
00909 
00910     case EMC_OPERATOR_DISPLAY_TYPE:
00911       printf("\ndisplay: [%d] %s\n",
00912              ((EMC_OPERATOR_DISPLAY *) (emcErrorBuffer->get_address()))->id,
00913              ((EMC_OPERATOR_DISPLAY *) (emcErrorBuffer->get_address()))->display);
00914       printPrompt = 1;
00915       break;
00916 
00917     case NML_ERROR_TYPE:
00918       printf("\nerror: %s\n",
00919              ((NML_ERROR *) (emcErrorBuffer->get_address()))->error);
00920       printPrompt = 1;
00921       break;
00922 
00923     case NML_TEXT_TYPE:
00924       printf("\ntext: %s\n",
00925              ((NML_TEXT *) (emcErrorBuffer->get_address()))->text);
00926       printPrompt = 1;
00927       break;
00928 
00929     case NML_DISPLAY_TYPE:
00930       printf("\ndisplay: %s\n",
00931              ((NML_DISPLAY *) (emcErrorBuffer->get_address()))->display);
00932       printPrompt = 1;
00933       break;
00934 
00935     default:
00936       // unrecognized message
00937       printf("\nunrecognized message in error channel:  %ld\n", type);
00938       printPrompt = 1;
00939       break;
00940     }
00941 }
00942 
00943 // fill in the current status
00944 static int updateStatus()
00945 {
00946   int r1 = 0, r2 = 0;
00947   NMLTYPE type;
00948 
00949   // update EMC TASK
00950   if (0 == emcStatus)
00951     {
00952       // not connected
00953       r1 = -1;
00954     }
00955   else
00956     {
00957       switch (type = emcStatusBuffer->peek())
00958         {
00959         case -1:
00960           // error on CMS channel
00961           printf("error reading emcStatus channel\n");
00962           r1 = -1;
00963           break;
00964 
00965         case 0:                 // no new data
00966         case EMC_STAT_TYPE:     // new data
00967           // new data
00968           // get command serial number
00969           emcCommandSerialNumber = emcStatus->echo_serial_number;
00970           break;
00971 
00972         default:
00973           printf("bad id in emcStatusBuffer: %ld\n", type);
00974           r1 = -1;
00975           break;
00976         }
00977     }
00978 
00979   // update EMCIO
00980   if (0 == emcIoStatus)
00981     {
00982       // not connected
00983       r2 = -1;
00984     }
00985   else
00986     {
00987       switch (type = emcIoStatusBuffer->peek())
00988         {
00989         case -1:
00990           // error on CMS channel
00991           printf("error reading emcioStatus channel\n");
00992           r2 = -1;
00993           break;
00994 
00995         case 0:                 // no new data
00996         case EMC_IO_STAT_TYPE:  // new data
00997           // new data
00998           // get command serial number
00999           emcIoCommandSerialNumber = emcIoStatus->echo_serial_number;
01000           break;
01001 
01002         default:
01003           printf("bad id in emcIoStatusBuffer: %ld\n", type);
01004           r2 = -1;
01005           break;
01006         }
01007     }
01008 
01009   return (r1 != 0 ||
01010           r2 != 0) ? -1 : 0;
01011 }
01012 
01013 /*
01014   waits until the EMC reports that it's got the command with the
01015   indicated serial_number. Sleeps between queries.
01016 */
01017 
01018 #define EMC_COMMAND_TIMEOUT 1.0 // how long to wait until timeout
01019 #define EMC_COMMAND_DELAY   0.1 // how long to sleep between checks
01020 
01021 static int emcCommandWait(int serial_number)
01022 {
01023   double start = etime();
01024 
01025   while (etime() - start < EMC_COMMAND_TIMEOUT)
01026     {
01027       updateStatus();
01028 
01029       if (emcStatus->echo_serial_number == serial_number)
01030         {
01031           return 0;
01032         }
01033 
01034       esleep(EMC_COMMAND_DELAY);
01035     }
01036 
01037   rcs_print_error("timeout sending command\n");
01038 
01039   return -1;
01040 }
01041 
01042 static enum {
01043   SELECT_NONE = 1,
01044   SELECT_EMC_TASK,
01045   SELECT_EMC_IO
01046 } which = SELECT_NONE;
01047 
01048 static int iniLoad(const char *filename)
01049 {
01050   INIFILE inifile;
01051   const char *inistring;
01052 
01053   // open it
01054   if (-1 == inifile.open(filename)) {
01055     return -1;
01056   }
01057 
01058   if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
01059     // copy to global
01060     strcpy(EMC_NMLFILE, inistring);
01061   }
01062   else {
01063     // not found, use default
01064   }
01065 
01066   // close it
01067   inifile.close();
01068 
01069   return 0;
01070 }
01071 
01072 int main(int argc, char *argv[])
01073 {
01074   char input[INPUTLEN];
01075   char cmd[INPUTLEN];
01076   int nchars;                   // how many read from getinput()
01077   double delay;                 // secs until next read
01078   int done;
01079   int lastPrint = 0;            // flag for which status subset to print
01080   int inhibitPrompt = 0;        // flag for inhibiting prompt printing
01081   int valid;
01082   int t;
01083   int catchErrors = 1;          // flag for reading error buffer
01084 
01085   // messages sent out
01086   EMC_AXIS_SET_FERROR emc_axis_set_ferror_msg;
01087   EMC_AXIS_SET_MIN_FERROR emc_axis_set_min_ferror_msg;
01088   EMC_AXIS_JOG emc_axis_jog_msg;
01089   EMC_AXIS_INCR_JOG emc_axis_incr_jog_msg;
01090   EMC_AXIS_ABS_JOG emc_axis_abs_jog_msg;
01091   EMC_AXIS_HOME emc_axis_home_msg;
01092   EMC_AXIS_ABORT emc_axis_abort_msg;
01093   EMC_AXIS_SET_OUTPUT emc_axis_set_output_msg;
01094   EMC_TRAJ_SET_SCALE emc_traj_set_scale_msg;
01095   EMC_TRAJ_ABORT emc_traj_abort_msg;
01096   EMC_TASK_SET_MODE mode_msg;
01097   EMC_TASK_SET_STATE state_msg;
01098   EMC_TASK_ABORT task_abort_msg;
01099   EMC_TASK_PLAN_OPEN task_plan_open_msg;
01100   EMC_TASK_PLAN_RUN task_plan_run_msg;
01101   EMC_TASK_PLAN_EXECUTE task_plan_execute_msg;
01102   EMC_TASK_PLAN_PAUSE task_plan_pause_msg;
01103   EMC_TASK_PLAN_RESUME task_plan_resume_msg;
01104   EMC_TOOL_INIT emc_tool_init_msg;
01105   EMC_TOOL_HALT emc_tool_halt_msg;
01106   EMC_TOOL_PREPARE emc_tool_prepare_msg;
01107   EMC_TOOL_LOAD emc_tool_load_msg;
01108   EMC_TOOL_UNLOAD emc_tool_unload_msg;
01109   EMC_TOOL_LOAD_TOOL_TABLE emc_tool_load_tool_table_msg;
01110   EMC_SPINDLE_ON emc_spindle_on_msg;
01111   EMC_SPINDLE_OFF emc_spindle_off_msg;
01112   EMC_SPINDLE_INCREASE emc_spindle_increase_msg;
01113   EMC_SPINDLE_DECREASE emc_spindle_decrease_msg;
01114   EMC_SPINDLE_CONSTANT emc_spindle_constant_msg;
01115   EMC_SPINDLE_BRAKE_RELEASE emc_spindle_brake_release_msg;
01116   EMC_SPINDLE_BRAKE_ENGAGE emc_spindle_brake_engage_msg;
01117   EMC_COOLANT_MIST_ON emc_coolant_mist_on_msg;
01118   EMC_COOLANT_MIST_OFF emc_coolant_mist_off_msg;
01119   EMC_COOLANT_FLOOD_ON emc_coolant_flood_on_msg;
01120   EMC_COOLANT_FLOOD_OFF emc_coolant_flood_off_msg;
01121   EMC_AUX_DIO_WRITE emc_aux_dio_write_msg;
01122   EMC_AUX_AIO_WRITE emc_aux_aio_write_msg;
01123   EMC_AUX_ESTOP_ON emc_aux_estop_on_msg;
01124   EMC_AUX_ESTOP_OFF emc_aux_estop_off_msg;
01125   EMC_LOG_OPEN emc_log_open_msg;
01126   EMC_LOG_START emc_log_start_msg;
01127   EMC_LOG_STOP emc_log_stop_msg;
01128   EMC_LOG_CLOSE emc_log_close_msg;
01129 
01130   // blank out the annoying RCS version message
01131   rcs_version_printed = 1;
01132 
01133   // process usual command line args
01134   if (0 != emcGetArgs(argc, argv)) {
01135     rcs_print_error("error in argument list\n");
01136     exit(1);
01137   }
01138 
01139   // process our command line args
01140   for (t = 1; t < argc; t++)
01141     {
01142       // try -noerror
01143       if (!strcmp(argv[t], "-noerror"))
01144         {
01145           catchErrors = 0;
01146           continue;
01147         }
01148     }
01149 
01150   // initialize globals
01151   emcInitGlobals();
01152 
01153   // get configuration information
01154   iniLoad(EMC_INIFILE);
01155 
01156   // init NML
01157   emcErrorNmlGet();
01158   if (0 == emcIoNmlGet())
01159     {
01160       which = SELECT_EMC_IO;
01161       lastPrint = 8;
01162     }
01163   if (0 == emcTaskNmlGet())
01164     {
01165       which = SELECT_EMC_TASK;
01166       lastPrint = 0;
01167     }
01168 
01169   // loop on input
01170   done = 0;
01171   printPrompt = 1;
01172   while (! feof(stdin) &&
01173          ! done)
01174     {
01175       // print errors
01176       if (catchErrors)
01177         {
01178           printErrors();
01179         }
01180 
01181       // update status
01182       updateStatus();
01183 
01184       // check if we need to print a prompt
01185       if (printPrompt)
01186         {
01187           if (! inhibitPrompt)
01188             {
01189               if (which == SELECT_EMC_TASK)
01190                 {
01191                   printf("emctask> ");
01192                 }
01193               else if (which == SELECT_EMC_IO)
01194                 {
01195                   printf("emcio> ");
01196                 }
01197               else
01198                 {
01199                   printf("none> ");
01200                 }
01201               fflush(stdout);
01202             }
01203           printPrompt = 0;
01204         }
01205 
01206       // get the next input line
01207       nchars = getinput(input, INPUTLEN);
01208       if (nchars > 0)
01209         {
01210           // got some input-- flag that we'll need to print prompt again
01211           printPrompt = 1;
01212         }
01213       else if (nchars == -1)
01214         {
01215           // no new input-- cycle and try again
01216           esleep(SLEEP_SECS);
01217           continue;             // the while(!feof(stdin)) loop
01218         }
01219       else
01220         {
01221           // nchars == 0, it's EOF
01222           done = 1;
01223           break;
01224         }
01225 
01226       // got input-- process it
01227 
01228       // read first arg in
01229       cmd[0] = 0;
01230       sscanf(input, "%s", cmd);
01231 
01232       // match it in the big if loop
01233       // first handle commands for any selected controller
01234       // then handle emctask, emcio
01235 
01236       // commands for any controller
01237       if (! strcmp(cmd, "help") ||
01238           ! strcmp(cmd, "?"))
01239         {
01240           printf("? or help           -- print help\n");
01241           printf("delay <secs>        -- delay reading next line\n");
01242           printf("< or >              -- turn prompt off or on\n");
01243           printf(";                   -- comment follows\n");
01244           printf("quit                -- quit\n");
01245           printf("show {params} {state} {mode} {pos} -- show status\n");
01246           printf("emctask | emcio          -- select emctask or emcio\n");
01247 
01248           switch (which)
01249             {
01250             case SELECT_EMC_TASK:
01251               printf("estop on | off      -- go into/out of estop\n");
01252               printf("machine on | off    -- enable/disable control\n");
01253               printf("mode manual | auto | mdi -- set program mode\n");
01254               printf("axis x | y | z      -- select axis\n");
01255               printf("speed <pos value>   -- set jog speed\n");
01256               printf("abs | rel           -- set display to abs or rel\n");
01257               printf("cont                -- set continuous jog mode\n");
01258               printf("incr {<pos value>}  -- set incremental jog mode\n");
01259               printf("jog {<abs> | + | -} -- jog absolute, or +/- in cont/incr\n");
01260               printf("home                -- home selected axis\n");
01261               printf("a                   -- abort everything\n");
01262               printf("/                   -- abort selected axis\n");
01263               printf("//                  -- abort traj\n");
01264               printf("feed <0.100>        -- set feed override\n");
01265               printf("open <prog name>    -- open NC program\n");
01266               printf("run                 -- run opened NC program\n");
01267               printf("mdi <NC statement>  -- send manual data input\n");
01268               printf("pause               -- pause motion\n");
01269               printf("resume              -- resume motion\n");
01270               printf("tools {<file>}      -- load tool file\n");
01271               printf("brake on | off      -- turn spindle brake on or off\n");
01272               printf("maxfe <axis> <value>  -- set axis following error\n");
01273               printf("minfe <axis> <value>  -- set axis following error\n");
01274               printf("out <axis> <value>  -- set axis output\n");
01275               break;
01276 
01277             case SELECT_EMC_IO:
01278               printf("init                -- initialize emcio\n");
01279               printf("halt                -- reset emcio\n");
01280               printf("dout <bit> 0 | 1    -- set digital out point\n");
01281               printf("aout <bit> <volts>  -- set analog out point\n");
01282               printf("estop on | off      -- go into/out of estop\n");
01283               printf("prep <tool>         -- prepare tool for loading\n");
01284               printf("load                -- load prepped tool\n");
01285               printf("unload              -- unload tool\n");
01286               printf("spindle <rpm> | off -- set spindle speed\n");
01287               printf("incr                -- increase spindle speed\n");
01288               printf("decr                -- decrease spindle speed\n");
01289               printf("brake on | off      -- turn spindle brake on or off\n");
01290               printf("mist on | off       -- mist coolant\n");
01291               printf("flood on | off      -- flood coolant\n");
01292               break;
01293 
01294             default:
01295               // nothing selected
01296               break;
01297             }
01298         }
01299       else if (! strcmp(cmd, "quit"))
01300         {
01301           done = 1;
01302         }
01303       else if (! strcmp(cmd, "<"))
01304         {
01305           inhibitPrompt = 1;
01306         }
01307       else if (! strcmp(cmd, ">"))
01308         {
01309           inhibitPrompt = 0;
01310         }
01311       else if (! strcmp(cmd, ";"))
01312         {
01313           // comment-- ignore
01314         }
01315       else if (! strcmp(cmd, "delay"))
01316         {
01317           if (1 == sscanf(input, "%*s %lf", &delay))
01318             {
01319               esleep((unsigned int) (delay * 1000000.0));
01320             }
01321           else
01322             {
01323               printf("syntax: delay <secs>\n");
01324             }
01325         }
01326       else if (! strcmp(cmd, "show"))
01327         {
01328           if (1 == sscanf(input, "%*s %s", cmd))
01329             {
01330               if (! strcmp(cmd, "state"))
01331                 {
01332                   lastPrint = 1;
01333                   emcpanelShow(lastPrint);
01334                 }
01335               else if (! strcmp(cmd, "mode"))
01336                 {
01337                   lastPrint = 2;
01338                   emcpanelShow(lastPrint);
01339                 }
01340               else if (! strcmp(cmd, "pos"))
01341                 {
01342                   lastPrint = 3;
01343                   emcpanelShow(lastPrint);
01344                 }
01345               else if (! strcmp(cmd, "params"))
01346                 {
01347                   lastPrint = 4;
01348                   emcpanelShow(lastPrint);
01349                 }
01350               else if (! strcmp(cmd, "program"))
01351                 {
01352                   lastPrint = 5;
01353                   emcpanelShow(lastPrint);
01354                 }
01355               else if (! strcmp(cmd, "exec"))
01356                 {
01357                   lastPrint = 6;
01358                   emcpanelShow(lastPrint);
01359                 }
01360               else if (! strcmp(cmd, "emcio"))
01361                 {
01362                   lastPrint = 8;
01363                   emcpanelShow(lastPrint);
01364                 }
01365               else if (! strcmp(cmd, "tools"))
01366                 {
01367                   lastPrint = 9;
01368                   emcpanelShow(lastPrint);
01369                 }
01370               else if (! strcmp(cmd, "axis"))
01371                 {
01372                   lastPrint = 10;
01373                   emcpanelShow(lastPrint);
01374                 }
01375               else if (! strcmp(cmd, "codes"))
01376                 {
01377                   lastPrint = 11;
01378                   emcpanelShow(lastPrint);
01379                 }
01380               else
01381                 {
01382                   // invalid parameter
01383                   printf("syntax: show {state} {mode} {pos} {params} {program} {exec} {emcio} {tools} {axis} {codes}\n");
01384                 }
01385             }
01386           else
01387             {
01388               // blank "show" typed
01389               if (which == SELECT_EMC_TASK)
01390                 {
01391                   lastPrint = 0;
01392                 }
01393               else if (which == SELECT_EMC_IO)
01394                 {
01395                   lastPrint = 8;
01396                 }
01397 
01398               emcpanelShow(lastPrint);
01399             }
01400         }
01401       else if (!strcmp(cmd, "emctask"))
01402         {
01403           if (0 == emcTaskNmlGet())
01404             {
01405               which = SELECT_EMC_TASK;
01406               lastPrint = 0;
01407             }
01408         }
01409       else if (!strcmp(cmd, "emcio"))
01410         {
01411           if (0 == emcIoNmlGet())
01412             {
01413               which = SELECT_EMC_IO;
01414               lastPrint = 8;
01415             }
01416         } // end of general matches; now handle controller specific ones
01417       else if (which == SELECT_EMC_TASK)
01418         {
01419           if (!strcmp(cmd, "estop"))
01420             {
01421               valid = 0;
01422               if (1 == sscanf(input, "%*s %s", cmd))
01423                 {
01424                   valid = 1;
01425                   if (!strcmp(cmd, "off"))
01426                     {
01427                       // come out of estop
01428                       state_msg.state = EMC_TASK_STATE_ESTOP_RESET;
01429                       state_msg.serial_number = ++emcCommandSerialNumber;
01430                       emcCommandBuffer->write(state_msg);
01431                     }
01432                   else if (!strcmp(cmd, "on"))
01433                     {
01434                       // go into estop
01435                       state_msg.state = EMC_TASK_STATE_ESTOP;
01436                       state_msg.serial_number = ++emcCommandSerialNumber;
01437                       emcCommandBuffer->write(state_msg);
01438                     }
01439                 }
01440               if (!valid)
01441                 {
01442                   printf("syntax: estop off | on\n");
01443                 }
01444             }
01445           else if (!strcmp(cmd, "machine"))
01446             {
01447               valid = 0;
01448               if (1 == sscanf(input, "%*s %s", cmd))
01449                 {
01450                   valid = 1;
01451                   if (!strcmp(cmd, "off"))
01452                     {
01453                       // turn it off
01454                       state_msg.state = EMC_TASK_STATE_OFF;
01455                       state_msg.serial_number = ++emcCommandSerialNumber;
01456                       emcCommandBuffer->write(state_msg);
01457                     }
01458                   else if (!strcmp(cmd, "on"))
01459                     {
01460                       // turn the machine on
01461                       state_msg.state = EMC_TASK_STATE_ON;
01462                       state_msg.serial_number = ++emcCommandSerialNumber;
01463                       emcCommandBuffer->write(state_msg);
01464                     }
01465                 }
01466               if (!valid)
01467                 {
01468                   printf("syntax: machine on | off\n");
01469                 }
01470             }
01471           else if (!strcmp(cmd, "mode"))
01472             {
01473               // a request to change mode
01474               valid = 0;
01475               if (1 == sscanf(input, "%*s %s", cmd))
01476                 {
01477                   if (!strcmp(cmd, "auto"))
01478                     {
01479                       mode_msg.mode = EMC_TASK_MODE_AUTO;
01480                       mode_msg.serial_number = ++emcCommandSerialNumber;
01481                       emcCommandBuffer->write(mode_msg);
01482                       valid = 1;
01483                     }
01484                   else if (!strcmp(cmd, "mdi"))
01485                     {
01486                       mode_msg.mode = EMC_TASK_MODE_MDI;
01487                       mode_msg.serial_number = ++emcCommandSerialNumber;
01488                       emcCommandBuffer->write(mode_msg);
01489                       valid = 1;
01490                     }
01491                   else if (!strcmp(cmd, "manual"))
01492                     {
01493                       mode_msg.mode = EMC_TASK_MODE_MANUAL;
01494                       mode_msg.serial_number = ++emcCommandSerialNumber;
01495                       emcCommandBuffer->write(mode_msg);
01496                       valid = 1;
01497                     }
01498                   else
01499                     {
01500                       valid = 0;
01501                     }
01502                 }
01503               if (!valid)
01504                 {
01505                   printf("syntax: mode auto | mdi | manual\n");
01506                 }
01507             }
01508           else if (!strcmp(cmd, "axis"))
01509             {
01510               valid = 0;
01511               if (1 == sscanf(input, "%*s %s", cmd))
01512                 {
01513                   if (!strcmp(cmd, "x"))
01514                     {
01515                       valid = 1;
01516                       axisSelect = AXIS_X;
01517                     }
01518                   else if (!strcmp(cmd, "y"))
01519                     {
01520                       valid = 1;
01521                       axisSelect = AXIS_Y;
01522                     }
01523                   else if (!strcmp(cmd, "z"))
01524                     {
01525                       valid = 1;
01526                       axisSelect = AXIS_Z;
01527                     }
01528                 }
01529               if (!valid)
01530                 {
01531                   printf("syntax: axis x | y | z\n");
01532                 }
01533             }
01534           else if (!strcmp(cmd, "speed"))
01535             {
01536               double speed;
01537               valid = 0;
01538               if (1 == sscanf(input, "%*s %lf", &speed) &&
01539                   speed > 0.0)
01540                 {
01541                   speedSelect = speed;
01542                   valid = 1;
01543                 }
01544               if (!valid)
01545                 {
01546                   printf("syntax: speed <pos value>\n");
01547                 }
01548             }
01549           else if (!strcmp(cmd, "abs"))
01550             {
01551               displayMode = DISPLAY_ABS;
01552             }
01553           else if (!strcmp(cmd, "rel"))
01554             {
01555               displayMode = DISPLAY_REL;
01556             }
01557           else if (!strcmp(cmd, "cont"))
01558             {
01559               jogSelect = JOG_CONT;
01560             }
01561           else if (!strcmp(cmd, "incr"))
01562             {
01563               double incr;
01564               valid = 0;
01565               // check for optional incr arg
01566               if (1 == sscanf(input, "%*s %s", cmd))
01567                 {
01568                   if (1 == sscanf(cmd, "%lf", &incr) &&
01569                       incr > 0.0)
01570                     {
01571                       jogIncr = incr;
01572                       jogSelect = JOG_INCR;
01573                       valid = 1;
01574                     }
01575                   else
01576                     {
01577                       // arg there, but invalid
01578                       valid = 0;
01579                     }
01580                 }
01581               else
01582                 {
01583                   // no arg
01584                   jogSelect = JOG_INCR;
01585                   valid = 1;
01586                 }
01587               if (!valid)
01588                 {
01589                   printf("syntax: axis x | y | z\n");
01590                 }
01591             }
01592           else if (!strcmp(cmd, "jog"))
01593             {
01594               valid = 0;
01595               // we can have "jog <abs> | + | -"
01596               // check for arg there first
01597               if (1 == sscanf(input, "%*s %s", cmd))
01598                 {
01599                   // there's an arg there
01600                   // check for abs value
01601                   if (1 == sscanf(cmd, "%lf", &emc_axis_abs_jog_msg.pos))
01602                     {
01603                       // got an abs jog value
01604                       emc_axis_abs_jog_msg.serial_number = ++emcCommandSerialNumber;
01605                       emc_axis_abs_jog_msg.axis = axisSelect;
01606                       emc_axis_abs_jog_msg.vel = speedSelect;
01607                       emcCommandBuffer->write(emc_axis_abs_jog_msg);
01608                       valid = 1;
01609                     }
01610                   // else check for +
01611                   else if (cmd[0] == '+')
01612                     {
01613                       // check for cont or incr jog
01614                       if (JOG_CONT == jogSelect)
01615                         {
01616                           emc_axis_jog_msg.serial_number = ++emcCommandSerialNumber;
01617                           emc_axis_jog_msg.axis = axisSelect;
01618                           emc_axis_jog_msg.vel = speedSelect;
01619                           emcCommandBuffer->write(emc_axis_jog_msg);
01620                           valid = 1;
01621                         }
01622                       else if (JOG_INCR == jogSelect)
01623                         {
01624                           emc_axis_incr_jog_msg.serial_number =
01625                             ++emcCommandSerialNumber;
01626                           emc_axis_incr_jog_msg.axis = axisSelect;
01627                           emc_axis_incr_jog_msg.vel = speedSelect;
01628                           emc_axis_incr_jog_msg.incr = jogIncr;
01629                           emcCommandBuffer->write(emc_axis_incr_jog_msg);
01630                           valid = 1;
01631                         }
01632                       else
01633                         {
01634                           // coding error
01635                           printf("bad value for jog select: %d\n", jogSelect);
01636                           valid = 1; // suppress syntax error, since it's not
01637                         }
01638                     }
01639                   // else check for -
01640                   else if (cmd[0] == '-')
01641                     {
01642                       // check for cont or incr jog
01643                       if (JOG_CONT == jogSelect)
01644                         {
01645                           emc_axis_jog_msg.serial_number = ++emcCommandSerialNumber;
01646                           emc_axis_jog_msg.axis = axisSelect;
01647                           emc_axis_jog_msg.vel = - speedSelect;
01648                           emcCommandBuffer->write(emc_axis_jog_msg);
01649                           valid = 1;
01650                         }
01651                       else if (JOG_INCR == jogSelect)
01652                         {
01653                           emc_axis_incr_jog_msg.serial_number =
01654                             ++emcCommandSerialNumber;
01655                           emc_axis_incr_jog_msg.axis = axisSelect;
01656                           emc_axis_incr_jog_msg.vel = - speedSelect;
01657                           emc_axis_incr_jog_msg.incr = jogIncr;
01658                           emcCommandBuffer->write(emc_axis_incr_jog_msg);
01659                           valid = 1;
01660                         }
01661                       else
01662                         {
01663                           // coding error
01664                           printf("bad value for jog select: %d\n", jogSelect);
01665                           valid = 1; // suppress syntax error, since it's not
01666                         }
01667                     }
01668                   else
01669                     {
01670                       // bad arg
01671                       valid = 0;
01672                     }
01673                 }
01674               else
01675                 {
01676                   // no arg there at all
01677                   valid = 0;
01678                 }
01679               if (!valid)
01680                 {
01681                   printf("syntax: jog <abs> | + | -\n");
01682                 }
01683             }
01684           else if (!strcmp(cmd, "home"))
01685             {
01686               emc_axis_home_msg.serial_number = ++emcCommandSerialNumber;
01687               emc_axis_home_msg.axis = axisSelect;
01688               emcCommandBuffer->write(emc_axis_home_msg);
01689             }
01690           else if (!strcmp(cmd, "a"))
01691             {
01692               // do a task abort (abort everything)
01693               task_abort_msg.serial_number = ++emcCommandSerialNumber;
01694               emcCommandBuffer->write(task_abort_msg);
01695             }
01696           else if (!strcmp(cmd, "/"))
01697             {
01698               // do an axis abort
01699               emc_axis_abort_msg.serial_number = ++emcCommandSerialNumber;
01700               emc_axis_abort_msg.axis = axisSelect;
01701               emcCommandBuffer->write(emc_axis_abort_msg);
01702             }
01703           else if (!strcmp(cmd, "//"))
01704             {
01705               // do a traj abort
01706               emc_traj_abort_msg.serial_number = ++emcCommandSerialNumber;
01707               emcCommandBuffer->write(emc_traj_abort_msg);
01708             }
01709           else if (!strcmp(cmd, "feed"))
01710             {
01711               int valid = 0;
01712               if (1 == sscanf(input, "%*s %lf", &emc_traj_set_scale_msg.scale))
01713                 {
01714                   valid = 1;
01715                   emc_traj_set_scale_msg.scale = emc_traj_set_scale_msg.scale / 100.0; // turn percent into a fraction
01716                   emc_traj_set_scale_msg.serial_number = ++emcCommandSerialNumber;
01717                   emcCommandBuffer->write(emc_traj_set_scale_msg);
01718                 }
01719               if (! valid)
01720                 {
01721                   printf("syntax: feed <0..100>\n");
01722                 }
01723             }
01724           else if (!strcmp(cmd, "open"))
01725             {
01726               int valid = 0;
01727               if (1 == sscanf(input, "%*s %s", task_plan_open_msg.file))
01728                 {
01729                   valid = 1;
01730                   task_plan_open_msg.serial_number = ++emcCommandSerialNumber;
01731                   emcCommandBuffer->write(task_plan_open_msg);
01732                   strcpy(programFile, task_plan_open_msg.file);
01733                   programOpened = 1;
01734                   if (programFp != 0)
01735                     {
01736                       fclose(programFp);
01737                     }
01738                   programFp = fopen(programFile, "r");
01739                   programLineText[0] = 0;
01740                   programFpLine = 0;
01741                 }
01742               if (! valid)
01743                 {
01744                   printf("syntax: open <part program>\n");
01745                 }
01746             }
01747           else if (!strcmp(cmd, "run"))
01748             {
01749               if (! programOpened)
01750                 {
01751                   // send a request to open the last one
01752                   strcpy(task_plan_open_msg.file, programFile);
01753                   task_plan_open_msg.serial_number = ++emcCommandSerialNumber;
01754                   emcCommandBuffer->write(task_plan_open_msg);
01755                   emcCommandWait(task_plan_open_msg.serial_number);
01756                 }
01757               task_plan_run_msg.serial_number = ++emcCommandSerialNumber;
01758               task_plan_run_msg.line = 0;
01759               emcCommandBuffer->write(task_plan_run_msg);
01760               programOpened = 0;
01761             }
01762           else if (!strcmp(cmd, "mdi"))
01763             {
01764               int valid = 0;
01765               // check for at least one thing on the line
01766               if (1 == sscanf(input, "%*s %s", cmd))
01767                 {
01768                   valid = 1;
01769                   // copy rest of line after "mdi "
01770                   strcpy(task_plan_execute_msg.command, &input[4]);
01771                   task_plan_execute_msg.serial_number = ++emcCommandSerialNumber;
01772                   emcCommandBuffer->write(task_plan_execute_msg);
01773                 }
01774               if (! valid)
01775                 {
01776                   printf("syntax: mdi <NC statement>\n");
01777                 }
01778             }
01779           else if (!strcmp(cmd, "pause"))
01780             {
01781               task_plan_pause_msg.serial_number = ++emcCommandSerialNumber;
01782               emcCommandBuffer->write(task_plan_pause_msg);
01783             }
01784           else if (!strcmp(cmd, "resume"))
01785             {
01786               task_plan_resume_msg.serial_number = ++emcCommandSerialNumber;
01787               emcCommandBuffer->write(task_plan_resume_msg);
01788             }
01789           else if (!strcmp(cmd, "tools"))
01790             {
01791               // get tool file, if provided
01792               if (1 != sscanf(input, "%*s %s", emc_tool_load_tool_table_msg.file))
01793                 {
01794                   emc_tool_load_tool_table_msg.file[0] = 0;
01795                 }
01796               emc_tool_load_tool_table_msg.serial_number = ++emcCommandSerialNumber;
01797               emcCommandBuffer->write(emc_tool_load_tool_table_msg);
01798             }
01799           else if (!strcmp(cmd, "brake"))
01800             {
01801               valid = 0;
01802               if (1 == sscanf(input, "%*s %s", cmd))
01803                 {
01804                   valid = 1;
01805                   if (!strcmp(cmd, "off"))
01806                     {
01807                       // take brake off
01808                       emc_spindle_brake_release_msg.serial_number = ++emcCommandSerialNumber;
01809                       emcCommandBuffer->write(emc_spindle_brake_release_msg);
01810                     }
01811                   else if (!strcmp(cmd, "on"))
01812                     {
01813                       // go into estop
01814                       emc_spindle_brake_engage_msg.serial_number = ++emcCommandSerialNumber;
01815                       emcCommandBuffer->write(emc_spindle_brake_engage_msg);
01816                     }
01817                 }
01818               if (!valid)
01819                 {
01820                   printf("syntax: brake off | on\n");
01821                 }
01822             }
01823           else if (!strcmp(cmd, "maxfe"))
01824             {
01825               int valid = 0;
01826               if (2 == sscanf(input, "%*s %d %lf",
01827                               &emc_axis_set_ferror_msg.axis,
01828                               &emc_axis_set_ferror_msg.ferror))
01829                 {
01830                   valid = 1;
01831                   emc_axis_set_ferror_msg.serial_number = ++emcCommandSerialNumber;
01832                   emcCommandBuffer->write(emc_axis_set_ferror_msg);
01833                 }
01834               if (! valid)
01835                 {
01836                   printf("syntax: maxfe <axis> <ferror>\n");
01837                 }
01838             }
01839           else if (!strcmp(cmd, "minfe"))
01840             {
01841               int valid = 0;
01842               if (2 == sscanf(input, "%*s %d %lf",
01843                               &emc_axis_set_min_ferror_msg.axis,
01844                               &emc_axis_set_min_ferror_msg.ferror))
01845                 {
01846                   valid = 1;
01847                   emc_axis_set_min_ferror_msg.serial_number = ++emcCommandSerialNumber;
01848                   emcCommandBuffer->write(emc_axis_set_min_ferror_msg);
01849                 }
01850               if (! valid)
01851                 {
01852                   printf("syntax: minfe <axis> <ferror>\n");
01853                 }
01854             }
01855           else if (!strcmp(cmd, "out"))
01856             {
01857               int valid = 0;
01858               if (2 == sscanf(input, "%*s %d %lf",
01859                               &emc_axis_set_output_msg.axis,
01860                               &emc_axis_set_output_msg.output))
01861                 {
01862                   valid = 1;
01863                   emc_axis_set_output_msg.serial_number = ++emcCommandSerialNumber;
01864                   emcCommandBuffer->write(emc_axis_set_output_msg);
01865                 }
01866               if (! valid)
01867                 {
01868                   printf("syntax: minfe <axis> <ferror>\n");
01869                 }
01870             }
01871           else if (!strcmp(cmd, "log"))
01872             {
01873               valid = 0;
01874               if (1 == sscanf(input, "%*s %s", cmd))
01875                 {
01876                   if (!strcmp(cmd, "open"))
01877                     {
01878                       valid = 1;
01879                       if (1 == sscanf(input, "%*s %*s %s", saveLogFile))
01880                         {
01881                           strcpy(emc_log_open_msg.file, saveLogFile);
01882                           emc_log_open_msg.type = saveLogType;
01883                           emc_log_open_msg.size = saveLogSize;
01884                           emc_log_open_msg.skip = saveLogSkip;
01885                           emc_log_open_msg.which = saveLogAxis;
01886                           emc_log_open_msg.serial_number = ++emcCommandSerialNumber;
01887                           emcCommandBuffer->write(emc_log_open_msg);
01888                           emcCommandWait(emcCommandSerialNumber);
01889                         }
01890                     }
01891                   else if (!strcmp(cmd, "start"))
01892                     {
01893                       valid = 1;
01894                       // check for open log file first; if not, and old one saved,
01895                       // open old one
01896                       if (! emcStatus->logOpen)
01897                         {
01898                           if (saveLogFile[0] != 0)
01899                             {
01900                               strcpy(emc_log_open_msg.file, saveLogFile);
01901                               emc_log_open_msg.type = saveLogType;
01902                               emc_log_open_msg.size = saveLogSize;
01903                               emc_log_open_msg.skip = saveLogSkip;
01904                               emc_log_open_msg.which = saveLogAxis;
01905                               emc_log_open_msg.serial_number = ++emcCommandSerialNumber;
01906                               emcCommandBuffer->write(emc_log_open_msg);
01907                               emcCommandWait(emcCommandSerialNumber);
01908                             }
01909                           else
01910                             {
01911                               // log is not opened, and no name saved, so ignore
01912                               break;
01913                             }
01914                         }
01915 
01916                       emc_log_start_msg.serial_number = ++emcCommandSerialNumber;
01917                       emcCommandBuffer->write(emc_log_start_msg);
01918                       emcCommandWait(emcCommandSerialNumber);
01919                     }
01920                   else if (!strcmp(cmd, "stop"))
01921                     {
01922                       valid = 1;
01923                       emc_log_stop_msg.serial_number = ++emcCommandSerialNumber;
01924                       emcCommandBuffer->write(emc_log_stop_msg);
01925                       emcCommandWait(emcCommandSerialNumber);
01926                     }
01927                   else if (!strcmp(cmd, "save"))
01928                     {
01929                       valid = 1;
01930                       emc_log_close_msg.serial_number = ++emcCommandSerialNumber;
01931                       emcCommandBuffer->write(emc_log_close_msg);
01932                       emcCommandWait(emcCommandSerialNumber);
01933                     }
01934                   else if (!strcmp(cmd, "plot"))
01935                     {
01936                       valid = 1;
01937                       if (0 != plotLog(saveLogFile, saveLogType, saveLogAxis))
01938                         {
01939                           printf("can't print log-- check log file manually");
01940                         }
01941                     }
01942                 }
01943               if (!valid)
01944                 {
01945                   printf("syntax: log open <file> | start | stop | save | plot\n");
01946                 }
01947             }
01948           else if (anyprintable(input))
01949             {
01950               printf("?\n");
01951             }
01952           else
01953             {
01954               // blank line was typed
01955               emcpanelShow(lastPrint);
01956             }
01957         } // if (which == SELECT_EMC_TASK)
01958       else                      // default matches SELECT_EMC_IO
01959         {
01960           if (!strcmp(cmd, "init"))
01961             {
01962               emc_tool_init_msg.serial_number = ++emcIoCommandSerialNumber;
01963               emcIoCommandBuffer->write(emc_tool_init_msg);
01964             }
01965           else if (!strcmp(cmd, "halt"))
01966             {
01967               emc_tool_halt_msg.serial_number = ++emcIoCommandSerialNumber;
01968               emcIoCommandBuffer->write(emc_tool_halt_msg);
01969             }
01970           else if (!strcmp(cmd, "dout"))
01971             {
01972               valid = 0;
01973 
01974               if (2 == sscanf(input, "%*s %d %d",
01975                               &emc_aux_dio_write_msg.index,
01976                               &emc_aux_dio_write_msg.value))
01977                 {
01978                   valid = 1;
01979                   emc_aux_dio_write_msg.serial_number = ++emcIoCommandSerialNumber;
01980                   emcIoCommandBuffer->write(emc_aux_dio_write_msg);
01981                 }
01982 
01983               if (!valid)
01984                 {
01985                   printf("syntax: set <bit> 0 | 1\n");
01986                 }
01987             }
01988           else if (!strcmp(cmd, "aout"))
01989             {
01990               valid = 0;
01991 
01992               if (2 == sscanf(input, "%*s %d %lf",
01993                               &emc_aux_aio_write_msg.index,
01994                               &emc_aux_aio_write_msg.value))
01995                 {
01996                   valid = 1;
01997                   emc_aux_aio_write_msg.serial_number = ++emcIoCommandSerialNumber;
01998                   emcIoCommandBuffer->write(emc_aux_aio_write_msg);
01999                 }
02000 
02001               if (!valid)
02002                 {
02003                   printf("syntax: set <bit> 0 | 1\n");
02004                 }
02005             }
02006           else if (!strcmp(cmd, "prep"))
02007             {
02008               valid = 0;
02009 
02010               if (1 == sscanf(input, "%*s %d",
02011                               &emc_tool_prepare_msg.tool))
02012                 {
02013                   valid = 1;
02014                   emc_tool_prepare_msg.serial_number = ++emcIoCommandSerialNumber;
02015                   emcIoCommandBuffer->write(emc_tool_prepare_msg);
02016                 }
02017 
02018               if (!valid)
02019                 {
02020                   printf("syntax: prep <tool>\n");
02021                 }
02022             }
02023           else if (!strcmp(cmd, "load"))
02024             {
02025               emc_tool_load_msg.serial_number = ++emcIoCommandSerialNumber;
02026               emcIoCommandBuffer->write(emc_tool_load_msg);
02027             }
02028           else if (!strcmp(cmd, "unload"))
02029             {
02030               emc_tool_unload_msg.serial_number = ++emcIoCommandSerialNumber;
02031               emcIoCommandBuffer->write(emc_tool_unload_msg);
02032             }
02033           else if (!strcmp(cmd, "spindle"))
02034             {
02035               valid = 0;
02036 
02037               if (1 == sscanf(input, "%*s %s", cmd))
02038                 {
02039                   if (!strcmp(cmd, "off"))
02040                     {
02041                       valid = 1;
02042                       emc_spindle_off_msg.serial_number = ++emcIoCommandSerialNumber;
02043                       emcIoCommandBuffer->write(emc_spindle_off_msg);
02044                     }
02045                   else if (1 == sscanf(cmd, "%lf", &emc_spindle_on_msg.speed))
02046                     {
02047                       valid = 1;
02048                       emc_spindle_on_msg.serial_number = ++emcIoCommandSerialNumber;
02049                       emcIoCommandBuffer->write(emc_spindle_on_msg);
02050                     }
02051                 }
02052 
02053               if (!valid)
02054                 {
02055                   printf("syntax: spindle <rpm> | off\n");
02056                 }
02057             }
02058           else if (!strcmp(cmd, "incr"))
02059             {
02060               emc_spindle_increase_msg.serial_number = ++emcIoCommandSerialNumber;
02061               emcIoCommandBuffer->write(emc_spindle_increase_msg);
02062             }
02063           else if (!strcmp(cmd, "decr"))
02064             {
02065               emc_spindle_decrease_msg.serial_number = ++emcIoCommandSerialNumber;
02066               emcIoCommandBuffer->write(emc_spindle_decrease_msg);
02067             }
02068           else if (!strcmp(cmd, "c"))
02069             {
02070               // make spindle constant
02071               emc_spindle_constant_msg.serial_number = ++emcIoCommandSerialNumber;
02072               emcIoCommandBuffer->write(emc_spindle_constant_msg);
02073             }
02074           else if (!strcmp(cmd, "brake"))
02075             {
02076               valid = 0;
02077 
02078               if (1 == sscanf(input, "%*s %s", cmd))
02079                 {
02080                   if (!strcmp(cmd, "off"))
02081                     {
02082                       valid = 1;
02083                       emc_spindle_brake_release_msg.serial_number = ++emcIoCommandSerialNumber;
02084                       emcIoCommandBuffer->write(emc_spindle_brake_release_msg);
02085                     }
02086                   else if (!strcmp(cmd, "on"))
02087                     {
02088                       valid = 1;
02089                       emc_spindle_brake_engage_msg.serial_number = ++emcIoCommandSerialNumber;
02090                       emcIoCommandBuffer->write(emc_spindle_brake_engage_msg);
02091                     }
02092                 }
02093               if (!valid)
02094                 {
02095                   printf("syntax: brake on | off\n");
02096                 }
02097             }
02098           else if (!strcmp(cmd, "estop"))
02099             {
02100               valid = 0;
02101 
02102               if (1 == sscanf(input, "%*s %s", cmd))
02103                 {
02104                   if (!strcmp(cmd, "off"))
02105                     {
02106                       valid = 1;
02107                       emc_aux_estop_off_msg.serial_number = ++emcIoCommandSerialNumber;
02108                       emcIoCommandBuffer->write(emc_aux_estop_off_msg);
02109                     }
02110                   else if (!strcmp(cmd, "on"))
02111                     {
02112                       valid = 1;
02113                       emc_aux_estop_on_msg.serial_number = ++emcIoCommandSerialNumber;
02114                       emcIoCommandBuffer->write(emc_aux_estop_on_msg);
02115                     }
02116                 }
02117 
02118               if (!valid)
02119                 {
02120                   printf("syntax: estop off | on\n");
02121                 }
02122             }
02123           else if (!strcmp(cmd, "mist"))
02124             {
02125               valid = 0;
02126 
02127               if (1 == sscanf(input, "%*s %s", cmd))
02128                 {
02129                   if (!strcmp(cmd, "off"))
02130                     {
02131                       valid = 1;
02132                       emc_coolant_mist_off_msg.serial_number = ++emcIoCommandSerialNumber;
02133                       emcIoCommandBuffer->write(emc_coolant_mist_off_msg);
02134                     }
02135                   else if (!strcmp(cmd, "on"))
02136                     {
02137                       valid = 1;
02138                       emc_coolant_mist_on_msg.serial_number = ++emcIoCommandSerialNumber;
02139                       emcIoCommandBuffer->write(emc_coolant_mist_on_msg);
02140                     }
02141                 }
02142 
02143               if (!valid)
02144                 {
02145                   printf("syntax: mist on | off");
02146                 }
02147             }
02148           else if (!strcmp(cmd, "flood"))
02149             {
02150               valid = 0;
02151 
02152               if (1 == sscanf(input, "%*s %s", cmd))
02153                 {
02154                   if (!strcmp(cmd, "off"))
02155                     {
02156                       valid = 1;
02157                       emc_coolant_flood_off_msg.serial_number = ++emcIoCommandSerialNumber;
02158                       emcIoCommandBuffer->write(emc_coolant_flood_off_msg);
02159                     }
02160                   else if (!strcmp(cmd, "on"))
02161                     {
02162                       valid = 1;
02163                       emc_coolant_flood_on_msg.serial_number = ++emcIoCommandSerialNumber;
02164                       emcIoCommandBuffer->write(emc_coolant_flood_on_msg);
02165                     }
02166                 }
02167 
02168               if (!valid)
02169                 {
02170                   printf("syntax: flood on | off\n");
02171                 }
02172             }
02173           else if (anyprintable(input))
02174             {
02175               printf("?\n");
02176             }
02177           else
02178             {
02179               // blank line was typed
02180               emcpanelShow(lastPrint);
02181             }
02182         } // end else which == SELECT_EMC_IO
02183     } // end of while stdin
02184 
02185   emcpanelQuit();
02186 
02187   exit(0);
02188 }

Generated on Sun Dec 2 15:27:39 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001