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

inimot.cc

Go to the documentation of this file.
00001 /*
00002   inimot.c
00003 
00004   Initialize motion controller from INI file
00005 
00006   Modification history:
00007 
00008   22-Jul-1999  FMP looped on [TRAJ] AXES from ini file, rather than
00009   EMCMOT_MAX_AXES
00010   15-Oct-1998  FMP changed emcLogError to emcOperatorError per change
00011   in emc.hh
00012   2-Sep-1998  FMP added local implementation of emcLogError()
00013   6-Jul-1998 FMP changed BASE_ADDRESS to SHMEM_BASE_ADDRESS
00014   1-Jul-1998  FMP added -ini, -shm, -base
00015   15-Jun-1998  FMP added emcStatus global since logging functions in
00016   interface code reference this
00017 */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 
00023 
00024 #include "emc.hh"
00025 #include "emcmot.h"
00026 #include "usrmotintf.h"
00027 #include "initraj.hh"
00028 #include "iniaxis.hh"
00029 #include "emcglb.h"             // EMC_INIFILE
00030 #include "emcmotglb.h"          // SHMEM_KEY, SHMEM_BASE_ADDRESS
00031 #include "emcmotcfg.h"          // EMCMOT_MAX_AXIS
00032 
00033 // global EMC status-- some interface functions fill this in
00034 static EMC_STAT emcStatusStruct;
00035 EMC_STAT * emcStatus = 0;       // declared in emc.hh
00036 
00037 // implementation of EMC error logger
00038 int emcOperatorError(int id, const char *fmt, ...)
00039 {
00040   char errorString[EMC_OPERATOR_ERROR_LEN];
00041   va_list ap;
00042 
00043   // prepend error code
00044   sprintf(errorString, "[%d] ", id);
00045 
00046   // append error string
00047   va_start(ap, fmt);
00048   vsprintf(&errorString[strlen(errorString)], fmt, ap);
00049   va_end(ap);
00050 
00051   // force a NULL at the end for safety
00052   errorString[EMC_OPERATOR_ERROR_LEN-1] = 0;
00053 
00054   // print it
00055   printf("%s\n", errorString);
00056 
00057   return 0;
00058 }
00059 
00060 static int numAxes = 0;         // [TRAJ] AXES from ini file, for looping
00061 #define DEFAULT_NUM_AXES 3      // how many to try if it's not in ini file
00062 
00063 static int iniLoad(const char *filename)
00064 {
00065   INIFILE inifile;
00066   const char *inistring;
00067 
00068   // open it
00069   if (-1 == inifile.open(filename)) {
00070     return -1;
00071   }
00072 
00073   if (NULL != (inistring = inifile.find("AXES", "TRAJ"))) {
00074     if (1 != sscanf(inistring, "%d", &numAxes)) {
00075       numAxes = DEFAULT_NUM_AXES;
00076     }
00077   }
00078   else {
00079     // not found, use default
00080     numAxes = DEFAULT_NUM_AXES;
00081   }
00082 
00083   // close it
00084   inifile.close();
00085 
00086   return 0;
00087 }
00088 
00089 int main(int argc, char *argv[])
00090 {
00091   int retval = 0;
00092   int axis;
00093 
00094   emcStatus = &emcStatusStruct;
00095 
00096   // process command line args
00097   if (0 != emcGetArgs(argc, argv))
00098     {
00099       printf("error in argument list\n");
00100       exit(1);
00101     }
00102 
00103   // get some ini file params for us
00104   if (0 != iniLoad(EMC_INIFILE)) {
00105     printf("can't read INI file\n");
00106     exit(1);
00107   }
00108 
00109   // check ini file for emcmot params
00110   if (0 != usrmotIniLoad(EMC_INIFILE)) {
00111     printf("can't read motion control INI file\n");
00112     exit(1);
00113   }
00114 
00115   if (0 != usrmotInit()) {
00116     printf("can't initialize motion control interface\n");
00117     exit(1);
00118   }
00119 
00120   for (axis = 0; axis < numAxes; axis++) {
00121     printf("initing axis %d...", axis);
00122     fflush(stdout);
00123     if (0 == iniAxis(axis, EMC_INIFILE)) {
00124       printf("done\n");
00125     }
00126     else {
00127       printf("error\n");
00128       retval = 1;
00129     }
00130   }
00131 
00132   // initialize parameters from ini file
00133   printf("initing traj...");
00134   fflush(stdout);
00135   if (0 == iniTraj(EMC_INIFILE)) {
00136     printf("done\n");
00137   }
00138   else {
00139     printf("error\n");
00140     retval = 1;
00141   }
00142 
00143   usrmotExit();
00144 
00145   exit(retval);
00146 }

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