initcam.c

00001 /*
00002  * initcam.c -- initialize the device driver, camera and
00003  * PCI DV board for the camera (or simulator) in use
00004  * 
00005  * (C) 1997-2000 Engineering Design Team, Inc.
00006  */
00007 #include "edtinc.h"
00008 
00009 static void    usage(char *progname);
00010 
00011 #ifdef NO_MAIN
00012 #include "opt_util.h"
00013 char *argument ;
00014 int option ;
00015 initcam(char *command_line)
00016 #else
00017 int
00018 main(int argc, char *argv[])
00019 #endif
00020 {
00021     int     ret;
00022     int     unit = 0;
00023     int     timeoutval = 10;
00024     int     verbose = 1;
00025     int     no_bitload = 0;
00026     int     exitval = 0;
00027     char    cfgname[256];
00028     char    bitdir[256];
00029     char    edt_devname[256];
00030     char    errstr[64];
00031     char   *progname = "initcam" ;
00032     char    logname[256];
00033     EdtDev *edt_p = NULL;
00034     Edtinfo edtinfo;
00035     char   *unitstr = "0";
00036     int     channel = 0 ;
00037     static char *debug_env = NULL;
00038     Dependent *dd_p;
00039     int     pdv_debug = 0;
00040 #ifdef NO_FS
00041     int     nofs_cfg = 0;
00042 #endif
00043     int     level;
00044 #ifdef NO_MAIN
00045     char **argv  = 0 ;
00046     int argc = 0 ;
00047     opt_create_argv("initcam",command_line,&argc,&argv);
00048 #endif
00049 
00050     *cfgname = '\0';
00051     *edt_devname = '\0';
00052     *bitdir = '\0';
00053     *logname = '\0';
00054 
00055     /* process arguments */
00056     --argc;
00057     ++argv;
00058     while (argc && argv[0][0] == '-')
00059     {
00060         switch (argv[0][1])
00061         {
00062         case 'u':               /* unit (board) number */
00063             ++argv;
00064             --argc;
00065             if (argc < 1) {
00066                     fprintf(stderr, "Error: option 'u' requires argument\n");
00067                     usage(progname);
00068                     exit(1);
00069             }
00070             unitstr = argv[0];
00071             break;
00072 
00073         case 'c':               /* channel number for multi-channel devices */
00074             ++argv;
00075             --argc;
00076             if (argc < 1) {
00077                     fprintf(stderr, "Error: option 'c' requires argument\n");
00078                     usage(progname);
00079                     exit(1);
00080             }
00081             channel = atoi(argv[0]);
00082             break;
00083 
00084         case 'O':               /* logfile name */
00085             ++argv;
00086             --argc;
00087             if (argc < 1) {
00088                     fprintf(stderr, "Error: option 'O' requires file argument\n");
00089                     usage(progname);
00090                     exit(1);
00091             }
00092             strcpy(logname, argv[0]);
00093             break;
00094 
00095         case 'q':               /* quiet mode */
00096             verbose = 0;
00097             break;
00098 
00099         case 'v':               /* verbose mode */
00100             verbose = 1;
00101             break;
00102 
00103         case 'V':               /* really verbose mode */
00104             verbose = 2;
00105             break;
00106 
00107         case 'f':               /* config filename */
00108             ++argv;
00109             --argc;
00110             if (argc < 1) {
00111                     fprintf(stderr, "Error: option 'f' requires argument\n");
00112                     usage(progname);
00113                     exit(1);
00114             }
00115             strcpy(cfgname, argv[0]);
00116 #ifdef NO_FS
00117             strcpy(bitdir, "_NOFS_");
00118             nofs_cfg = 1;
00119 #endif
00120             break;
00121 
00122         case 'e':               /* no file system embedded bitfile name */
00123 #ifdef NO_FS
00124             ++argv;
00125             --argc;
00126             if (argc < 1) {
00127                     fprintf(stderr, "Error: option 'e' requires argument\n");
00128                     usage(progname);
00129                     exit(1);
00130             }
00131             strcpy(cfgname, argv[0]);
00132             strcpy(bitdir, "_NOFS_");
00133             nofs_cfg = 1;
00134 #else
00135              fprintf(stdout, "\n-e specified but not compiled with nofs configs.\nrecompile with -DNO_FS and try again\n\n");
00136              usage(progname);
00137              exit(1);
00138 #endif
00139             break;
00140 
00141         case 'B':               /* don't load bitfile */
00142             no_bitload = 1;
00143             break;
00144 
00145         case 'b':
00146         case 'd':               /* compat */
00147             ++argv;
00148             --argc;
00149             if (argc < 1) {
00150                     fprintf(stderr, "Error: options 'b' or 'd' require argument\n");
00151                     usage(progname);
00152                     exit(1);
00153             }
00154             strcpy(bitdir, argv[0]);
00155             break;
00156 
00157         case 'h':               /* help */
00158             usage(progname);
00159             exit(0);
00160             break;
00161 
00162         case '-':
00163             if (strcmp(argv[0], "--help") == 0) {
00164                     usage(progname);
00165                     exit(0);
00166             } else {
00167                     fprintf(stderr, "unknown option: %s\n", argv[0]);
00168                     usage(progname);
00169                     exit(1);
00170             }
00171             break;
00172 
00173         default:
00174             fprintf(stdout, "unknown flag -'%c'\n", argv[0][1]);
00175             usage(progname);
00176             exit(1);
00177         }
00178         argc--;
00179         argv++;
00180     }
00181 
00182     if (!(*cfgname))
00183     {
00184         usage(progname);
00185         exit(1);
00186     }
00187 
00188     /*
00189      * not using pdv_open to open, but still using pdvlib calls, so force
00190      * debug if -v or -V or PDVDEBUG envvar
00191      */
00192     if (debug_env == NULL
00193         && ((debug_env = (char *) getenv("PDVDEBUG")) != NULL)
00194         && *debug_env != '0')
00195             pdv_debug = atoi(debug_env);
00196 
00197     /*
00198      * normally the pdvlib error handle gets initialized in pdv_open, but
00199      * initcam is a special case since it calls edt_open but also uses
00200      * pdvlib calls -- see edt_msg library.
00201      */
00202     level = edt_msg_default_level();
00203 
00204     if ((verbose > 1) && (pdv_debug < verbose))
00205         pdv_debug = verbose;
00206 
00207     if ((!verbose) && (!pdv_debug))
00208         level = 0;
00209     else
00210     {
00211         if (verbose > 0)
00212         {
00213             level |= EDTAPP_MSG_INFO_1;
00214             level |= PDVLIB_MSG_INFO_1;
00215             level |= PDVLIB_MSG_WARNING;
00216             level |= PDVLIB_MSG_FATAL;
00217         }
00218         if (verbose > 1)
00219             level |= EDTAPP_MSG_INFO_2;
00220         if (pdv_debug > 1)
00221             level |= PDVLIB_MSG_INFO_2;
00222     }
00223 
00224     edt_msg_set_level(edt_msg_default_handle(), level);
00225     if (*logname)
00226         edt_msg_set_name(edt_msg_default_handle(), logname);
00227 
00228     /* kind of kludgy... since pdv_setdebug doesn't actually USE edt_p,
00229      * its okay that it hasn't been opened yet , hence the NULL pointer
00230      */
00231     if (pdv_debug)
00232         pdv_setdebug(NULL, pdv_debug);
00233 
00234     /*
00235      * if porting this code to an application, be sure to free this 
00236      * and reallocate if you call pdv_initcam multiple times.
00237      */
00238     if ((dd_p = pdv_alloc_dependent()) == NULL)
00239     {
00240         edt_msg(PDVLIB_MSG_FATAL, "alloc_dependent FAILED -- exiting\n");
00241         exit(1);
00242     }
00243 
00244 #ifdef NO_FS
00245     if (nofs_cfg)
00246         ret = pdv_readcfg_emb(cfgname, dd_p, &edtinfo);
00247     else
00248 #endif
00249     if (pdv_readcfg(cfgname, dd_p, &edtinfo) != 0)
00250     {
00251         edt_msg(PDVLIB_MSG_FATAL, "readcfg FAILED -- exiting\n");
00252         exit(1);
00253     }
00254 
00255     if (no_bitload)
00256         strcpy(dd_p->rbtfile, "_SKIPPED_");
00257 
00258     /*
00259      * open the device
00260      */
00261     unit = edt_parse_unit_channel(unitstr, edt_devname, "pdv", &channel);
00262     edt_msg(EDTAPP_MSG_INFO_1, "opening %s unit %d....\n", edt_devname, unit);
00263     if ((edt_p = edt_open_channel(edt_devname, unit, channel)) == NULL)
00264     {
00265         sprintf(errstr, "edt_open(%s%d)", edt_devname, unit);
00266         edt_perror(errstr);
00267         return (1);
00268     }
00269 
00270     if (edt_p->devid == PDVFOI_ID)
00271     {
00272 #ifdef _FOI_SUPPORTED
00273         pdv_initcam_set_rci(edt_p, channel) ;
00274 #else
00275         edt_msg(EDTAPP_MSG_FATAL,"FOI not supported after pkg v4.1.5.9\n");
00276         edt_close(edt_p);
00277         exit(1);
00278 #endif
00279     }
00280 
00281     if (pdv_initcam(edt_p, dd_p, unit, &edtinfo, cfgname, bitdir,
00282                                                 pdv_debug) != 0)
00283     {
00284         edt_msg(EDTAPP_MSG_FATAL,"initcam failed. Run with '-V' to see complete debugging output\n");
00285         edt_close(edt_p);
00286         exit(1);
00287     }
00288 
00289     edt_close(edt_p);
00290     edt_msg(EDTAPP_MSG_FATAL, "done\n");
00291 #ifdef NO_MAIN
00292     return(0) ;
00293 #else
00294     exit(0);
00295 #endif
00296 }
00297 
00298 void
00299 usage(char *progname)
00300 {
00301 #ifdef NO_FS
00302     printf("usage: %s [options] [-e <cfg_name> | -f <cfg_path>]\n", progname);
00303 #else
00304     printf("usage: %s [options] -f <cfg_path>\n", progname);
00305 #endif
00306     printf("     -b <bit_dir>  alternate bitfiles directory\n");
00307     printf("     -B            don't load the bitfile\n");
00308     printf("     -f <cfg_path> config file pathname (required)\n");
00309     printf("     -e <cfg_name> embedded config (for no-filesystem operation -- must be compiled with -DNO_FS)\n");
00310     printf("     -u <unit>     pdv unit number (default 0). A full device pathname\n");
00311     printf("                   or filename can be substituted \n");
00312     printf("     -c <channel>  channel #, for multi-channel boards\n");
00313 #ifdef _FOI_SUPPORTED
00314     printf("     -F <foiunit>  FOI (RCI) unit number, when multiple RCI units exist\n");
00315 #endif
00316     printf("                   (usually -F and -c are used together, with both specifying the same #)\n");
00317     printf("     -v, -V        verbose, and really verbose\n");
00318     printf("     -O logfile    output log file, will redirect any console output to specified file\n");
00319     printf("     -q            quiet; no output\n");
00320                 printf("     -h, --help    this help message\n");
00321     printf("\n");
00322 }
00323 

Generated on Mon May 12 16:38:53 2008 by  doxygen 1.5.1