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