readcfg.c

Go to the documentation of this file.
00001 
00011 #include "edtinc.h"
00012 #include "initcam.h"
00013 
00014 #define COMPARE(str1, str2) (strcasecmp(str1, str2) == 0)
00015 
00016 /* shorthand debug level */
00017 #define DEBUG0 PDVLIB_MSG_FATAL
00018 #define DEBUG1 PDVLIB_MSG_INFO_1
00019 #define DEBUG2 PDVLIB_MSG_INFO_2
00020 
00021 u_char *xilinx;                 /* pointer to programmable Xilinx area */
00022 static char xilinx_file[512];
00023 static char xilinx_link[512];
00024 int     nser = 0;
00025 
00026 void clear_dependent(Dependent * dd_p);
00027 int check_method_param(char *s, Dependent * dd_p, Edtinfo * ei_p, char *cfgfile);
00028 int check_other_param(char *s, Dependent * dd_p, char *cfgfile);
00029 int check_xilinx_param(char *s, Dependent * dd_p, char *cfgfile);
00030 int check_cls_param(char *s, Dependent * dd_p, char *cfgfile);
00031 int is_method(char *method_type, char *name);
00032 void strip_ctrlm(char *s);
00033 void strip_extra_whitespace(char *s);
00034 int resolve_cameratype(Dependent *dd_p);
00035 
00036 
00037 /* utility routine for embedded (nofs) config file arrays -- copies and changes '\"' to '"'*/
00038 char *
00039 get_next_string(int nofs_cfg, FILE *cfg_fp, char *ss, char *ds)
00040 {
00041     char *dp = ds;
00042 #ifdef NO_FS
00043     char *sp ;
00044 #endif
00045 
00046 #ifdef NO_FS
00047     if (nofs_cfg)
00048     {
00049         sp = ss;
00050         if (!*sp)
00051             return 0;
00052 
00053         while(*sp)
00054         {
00055             if ((*sp == '\\') && (*(sp+1) == '\"'))
00056                 ++sp;
00057             *dp++ = *sp++;
00058         }
00059         *dp = '\0';
00060 
00061         return 1;
00062     }
00063     else
00064 #endif
00065     
00066     return fgets(ds, 255, cfg_fp);
00067 }
00068 
00069 
00070 #ifdef NO_FS
00071 /*
00072  * embedded config files, for 
00073  */
00074 #include "nofs_config.h"
00075 #endif
00076 
00077 
00078 char *dmy_cfg[] = {""};
00079 
00080 void
00081 dep_set_default(PdvDependent * dd_p)
00082 
00083 {
00084     int i;
00085 
00086    /*
00087      * clear dependent struct and set defaults to nonsense values
00088      */
00089     clear_dependent(dd_p);
00090     dd_p->rbtfile[0] = '\0';
00091     dd_p->cameratype[0] = '\0';
00092     dd_p->shutter_speed = NOT_SET;
00093     dd_p->default_shutter_speed = NOT_SET;
00094     dd_p->default_gain = NOT_SET;
00095     dd_p->default_offset = NOT_SET;
00096     dd_p->default_aperture = NOT_SET;
00097     dd_p->binx = 1;
00098     dd_p->biny = 1;
00099     dd_p->byteswap = NOT_SET;
00100     dd_p->serial_timeout = 1000;
00101     dd_p->serial_response[0] = '\r';
00102     dd_p->xilinx_rev = NOT_SET;
00103     dd_p->timeout = NOT_SET;
00104     dd_p->user_timeout = NOT_SET;
00105     dd_p->mode_cntl_norm = NOT_SET;
00106     dd_p->mc4 = 0;
00107     dd_p->pulnix = 0;
00108     dd_p->dbl_trig = 0;
00109     dd_p->shift = NOT_SET;
00110     dd_p->mask = 0xffff;
00111     dd_p->mode16 = NOT_SET;
00112     dd_p->serial_baud = NOT_SET;
00113     dd_p->serial_waitc = NOT_SET ;
00114     dd_p->serial_format = SERIAL_ASCII;
00115     strcpy(dd_p->serial_term, "\r");    /* term for most ASCII exc. ES4.0 */
00116     
00117     dd_p->kbs_red_row_first = 1;
00118     dd_p->kbs_green_pixel_first = 0;
00119   
00120 
00121     dd_p->htaps = 1;
00122     dd_p->vtaps = 1;
00123 
00124     dd_p->cameralink = 0;
00125     dd_p->start_delay = 0;
00126     dd_p->frame_period = NOT_SET;
00127     dd_p->frame_timing = NOT_SET;
00128 
00129     dd_p->strobe_enabled = NOT_SET;
00130     dd_p->register_wrap = 0;
00131     dd_p->serial_init_delay = NOT_SET;
00132 
00133 
00134     /*
00135      * xregwrite registers can be 0-ff. We need a way to flag the
00136      * end of the array, so just waste ff and call that "not set"
00137      */
00138     for (i=0; i<32; i++)
00139         dd_p->xilinx_flag[i] = 0xff;
00140 
00141 }
00142 
00143 int
00144 readcfg(char *cfgfile, Dependent * dd_p, Edtinfo * ei_p, int nofs_cfg)
00145 {
00146 
00147 
00148     int     pdv_unit = 0;
00149     int     ret;
00150     char    **vx_p = dmy_cfg;
00151     FILE   *cfg_fp;
00152     char    s[256];
00153     char    *sp;
00154     int     lineno = 0;
00155 #ifdef NO_FS
00156     char    *cf;
00157 #endif
00158 
00159     edt_msg(DEBUG2, "Reading/processing config file %s:\n\n", cfgfile);
00160 
00161     if (!nofs_cfg)
00162     {
00163         /*
00164          * Read and process the configuration file for this camera.
00165          */
00166         if ((cfg_fp = fopen(cfgfile, "r")) == NULL)
00167         {
00168             perror(cfgfile);
00169             return -1;
00170         }
00171     }
00172 
00173     dep_set_default(dd_p);
00174 
00175     ei_p->startdma = NOT_SET;
00176     ei_p->enddma = NOT_SET;
00177     ei_p->flushdma = NOT_SET;
00178 
00179      dd_p->startdma = NOT_SET;
00180     dd_p->enddma = NOT_SET;
00181     dd_p->flushdma = NOT_SET;
00182    
00183 
00184     strncpy(dd_p->cfgname, cfgfile, sizeof(dd_p->cfgname) - 1);
00185  
00186 #ifdef NO_FS
00187     if (nofs_cfg)
00188     {
00189         char *p;
00190 
00191         if ((cf = strrchr(cfgfile, '/')) != NULL)
00192             ++cf;
00193         else cf = cfgfile;
00194         p = cf;
00195 
00196         if ((strlen(cf) > 4) && (strcasecmp(&cf[strlen(cf)-4], ".cfg") == 0))
00197             cf[strlen(cf)-4] = '\0';
00198 
00199         /*
00200          * change dashes to underscores in name, to match variable names
00201          */
00202         do
00203         {
00204             if (*p == '-')
00205                 (*p = '_');
00206         } while(*(++p));
00207         MAPCONFIG(cf, vx_p); /* macro in nofs_config.h */
00208 
00209         if (vx_p == NULL)
00210         {
00211             printf("embedded specified, but no header file for '%s' included in source (nofs_config.h)\n", cf);
00212             exit(1);
00213         }
00214     }
00215 #endif
00216 
00217     while (get_next_string(nofs_cfg, cfg_fp, *vx_p, s))
00218     {
00219         char tmpstr[256];
00220         if (nofs_cfg)
00221             ++vx_p;
00222 
00223         lineno++;
00224 
00225         /* debug string printf */
00226         if (s[strlen(s)-1] == '\n')
00227             strcpy(tmpstr, s);
00228         else sprintf(tmpstr, "%s\n", s);
00229         edt_msg(DEBUG2, tmpstr);
00230 
00231         if (*s == '#' || *s == '\n' || *s == '\r')
00232             continue;
00233 
00234         strip_ctrlm(s);
00235         strip_extra_whitespace(s);
00236 
00237         if (*s == '#' || *s == '\n' || *s == '\r')
00238             continue;
00239 
00240         if ((ret = check_method_param(s, dd_p, ei_p, cfgfile)) < 0)
00241             return -1;
00242         if (ret == 1)
00243             continue;
00244 
00245         if ((ret = check_xilinx_param(s, dd_p, cfgfile)) < 0)
00246             return -1;
00247         if (ret == 1)
00248             continue;
00249 
00250         if ((ret = check_other_param(s, dd_p, cfgfile)) < 0)
00251             return -1;
00252 
00253         if (ret == 1)
00254             continue;
00255 
00256         if ((ret = check_cls_param(s, dd_p, cfgfile)) < 0)
00257             return -1;
00258 
00259         if (ret == 1)
00260             continue;
00261 
00262         {
00263             char    kw[256];
00264 
00265             sscanf(s, "%s", kw);
00266             edt_msg(DEBUG0, "WARNING: unrecognized argument \"%s\" line %d (ignored)\n", kw, lineno);
00267         }
00268     }
00269 
00270 #ifndef NO_FS
00271     fclose(cfg_fp);
00272 #endif
00273 
00274     /*
00275      * the cameratype directive (not the parameter though) is obsolete
00276      * so make it up from class and model if they are present (should be!)
00277      */
00278     resolve_cameratype(dd_p);
00279 
00280     /*
00281      * pdv uses .bit files, not .rbt files, but some older config
00282      * might still reference the old extension
00283      */
00284     if (dd_p->rbtfile[0])
00285     {
00286         if ((sp = strrchr(dd_p->rbtfile, '.')) == NULL)
00287             sp = strchr(dd_p->rbtfile, '\0');
00288         if ((sp != NULL) && ((strcmp(sp, ".rbt") == 0) || (*sp == '\0')))
00289             sprintf(sp, ".bit");
00290     }
00291 
00292     return 0;
00293 }
00294 
00312 int
00313 pdv_readcfg(char *cfgfile, Dependent * dd_p, Edtinfo *ei_p)
00314 {
00315     return readcfg(cfgfile, dd_p, ei_p, 0);
00316 }
00317 
00318 int
00319 pdv_readcfg_emb(char *cfgfile, Dependent * dd_p, Edtinfo *ei_p)
00320 {
00321     return readcfg(cfgfile, dd_p, ei_p, 1);
00322 }
00323 
00324 
00325 translate_method_arg(char *method_arg, int *method_number)
00326 {
00327     /* Translate the method_arg to a method number */
00328     if (COMPARE(method_arg, "AIA_MCL_100US"))
00329         *method_number = AIA_MCL_100US;
00330     else if (COMPARE(method_arg, "AIA_MCL"))
00331         *method_number = AIA_MCL;
00332     else if (COMPARE(method_arg, "AIA_TRIG"))
00333         *method_number = AIA_TRIG;
00334     else if (COMPARE(method_arg, "KODAK_AIA_MCL"))
00335         *method_number = KODAK_AIA_MCL;
00336     else if (COMPARE(method_arg, "AIA_MC4"))
00337         *method_number = AIA_MC4;
00338     else if (COMPARE(method_arg, "HAMAMATSU_4880_8X"))
00339         *method_number = HAM_4880_8X;
00340     else if (COMPARE(method_arg, "HAMAMATSU_4880_SER"))
00341         *method_number = HAM_4880_SER;
00342     else if (COMPARE(method_arg, "SU320_SERIAL"))
00343         *method_number = SU320_SERIAL;
00344     else if (COMPARE(method_arg, "BASLER202K_SERIAL"))
00345         *method_number = BASLER202K_SERIAL;
00346     else if (COMPARE(method_arg, "ADIMEC_SERIAL"))
00347         *method_number = ADIMEC_SERIAL;
00348     else if (COMPARE(method_arg, "TIMC1001_SERIAL"))
00349         *method_number = TIMC1001_SERIAL;
00350     else if (COMPARE(method_arg, "PTM6710_SERIAL"))
00351         *method_number = PTM6710_SERIAL;
00352     else if (COMPARE(method_arg, "PTM1020_SERIAL"))
00353         *method_number = PTM1020_SERIAL;
00354     else if (COMPARE(method_arg, "PULNIX_TM1000"))
00355         *method_number = PULNIX_TM1000;
00356     else if (COMPARE(method_arg, "PULNIX_TM9700"))
00357         *method_number = PULNIX_TM9700;
00358     else if (COMPARE(method_arg, "IRC_160"))
00359         *method_number = IRC_160;
00360     else if (COMPARE(method_arg, "KODAK_AIA_SER_CTRL"))
00361         *method_number = KODAK_AIA_SER_CTRL;
00362     else if (COMPARE(method_arg, "AIA_SER_CTRL"))
00363         *method_number = AIA_SER_CTRL;
00364     else if (COMPARE(method_arg, "KODAK_AIA_SER"))
00365         *method_number = KODAK_AIA_SER;
00366     else if (COMPARE(method_arg, "SMD_SERIAL"))
00367         *method_number = SMD_SERIAL;
00368     else if (COMPARE(method_arg, "AIA_SER_ES40"))
00369         *method_number = AIA_SERIAL_ES40;
00370     else if (COMPARE(method_arg, "AIA_SER"))
00371         *method_number = AIA_SERIAL;
00372     else if (COMPARE(method_arg, "KODAK_SER_14I"))
00373         *method_number = KODAK_SER_14I;
00374     else if (COMPARE(method_arg, "SER_14I"))
00375         *method_number = KODAK_SER_14I;
00376     else if (COMPARE(method_arg, "SPECINST_SERIAL"))
00377         *method_number = SPECINST_SERIAL;
00378     else if (COMPARE(method_arg, "KODAK_XHF_INTLC"))
00379         *method_number = PDV_BYTE_INTLV;
00380     else if (COMPARE(method_arg, "BYTE_INTLV"))
00381         *method_number = PDV_BYTE_INTLV;
00382     else if (COMPARE(method_arg, "FIELD_INTLC"))
00383         *method_number = PDV_FIELD_INTLC;
00384     else if (COMPARE(method_arg, "BYTE_TEST1"))
00385         *method_number = PDV_BYTE_TEST1;
00386     else if (COMPARE(method_arg, "BYTE_TEST2"))
00387         *method_number = PDV_BYTE_TEST2;
00388     else if (COMPARE(method_arg, "BYTE_TEST3"))
00389         *method_number = PDV_BYTE_TEST3;
00390     else if (COMPARE(method_arg, "WORD_INTLV_HILO"))
00391         *method_number = PDV_WORD_INTLV_HILO;
00392     else if (COMPARE(method_arg, "WORD_INTLV_ODD"))
00393         *method_number = PDV_WORD_INTLV_ODD;
00394     else if (COMPARE(method_arg, "ES10_WORD_INTLC"))
00395         *method_number = PDV_WORD_INTLV;
00396     else if (COMPARE(method_arg, "WORD_INTLV"))
00397         *method_number = PDV_WORD_INTLV;
00398     else if (COMPARE(method_arg, "DALSA_4CH_INTLV"))
00399         *method_number = PDV_DALSA_4CH_INTLV;
00400     else if (COMPARE(method_arg, "PIRANHA_4CH_INTLV"))
00401         *method_number = PDV_PIRANHA_4CH_INTLV;
00402     else if (COMPARE(method_arg, "PIRANHA_4CH_HWINTLV"))
00403         *method_number = PDV_PIRANHA_4CH_HWINTLV;
00404     else if (COMPARE(method_arg, "SPECINST_4PORT_INTLV"))
00405         *method_number = PDV_SPECINST_4PORT_INTLV;
00406     else if (COMPARE(method_arg, "ILLUNIS_INTLV"))
00407         *method_number = PDV_ILLUNIS_INTLV;
00408     else if (COMPARE(method_arg, "ES10_BGGR_INTLV"))
00409         *method_number = PDV_ES10_BGGR;
00410     else if (COMPARE(method_arg, "ES10_WORD_BGGR_INTLV"))
00411         *method_number = PDV_ES10_WORD_BGGR;
00412     else if (COMPARE(method_arg, "ES10_WORD_ODD_BGGR_INTLV"))
00413         *method_number = PDV_ES10_WORD_ODD_BGGR;
00414     else if (COMPARE(method_arg, "ILLUNIS_BGGR"))
00415         *method_number = PDV_ILLUNIS_BGGR;
00416     else if (COMPARE(method_arg, "QUADRANT_INTLV"))
00417         *method_number = PDV_QUADRANT_INTLV;
00418     else if (COMPARE(method_arg, "DALSA_2CH_INTLV"))
00419         *method_number = PDV_DALSA_2CH_INTLV;
00420     else if (COMPARE(method_arg, "INVERT_RIGHT_INTLV_24_12"))
00421         *method_number = PDV_INV_RT_INTLV_24_12;
00422     else if (COMPARE(method_arg, "INTLV_24_12"))
00423         *method_number = PDV_INTLV_24_12;
00424    else if (COMPARE(method_arg, "INTLV_1_8_MSB7"))
00425         *method_number = PDV_INTLV_1_8_MSB7;
00426    else if (COMPARE(method_arg, "INTLV_1_8_MSB0"))
00427         *method_number = PDV_INTLV_1_8_MSB0;
00428     else if (COMPARE(method_arg, "INVERT_RIGHT_INTLV"))
00429         *method_number = PDV_INVERT_RIGHT_INTLV;
00430     else if (COMPARE(method_arg, "INVERT_RIGHT_BGGR_INTLV"))
00431         *method_number = PDV_INVERT_RIGHT_BGGR_INTLV;
00432     else if (COMPARE(method_arg, "DALSA_2M30_INTLV"))
00433         *method_number = PDV_DALSA_2M30_INTLV;
00434     else if (COMPARE(method_arg, "EVEN_RIGHT_INTLV"))
00435         *method_number = PDV_EVEN_RIGHT_INTLV;
00436     else if (COMPARE(method_arg, "BGGR_DUAL"))
00437         *method_number = PDV_BGGR_DUAL;
00438     else if (COMPARE(method_arg, "BGGR_WORD"))
00439         *method_number = PDV_BGGR_WORD;
00440     else if (COMPARE(method_arg, "BGGR"))
00441         *method_number = PDV_BGGR;
00442     else if (COMPARE(method_arg, "BGR_2_RGB"))
00443         *method_number = PDV_INTLV_BGR_2_RGB;
00444     else if (COMPARE(method_arg, "KODAK_XHF_SKIP"))
00445         *method_number = PDV_BYTE_INTLV_SKIP;
00446     else if (COMPARE(method_arg, "BYTE_INTLV_SKIP"))
00447         *method_number = PDV_BYTE_INTLV_SKIP;
00448     else if (COMPARE(method_arg, "HW_ONLY"))
00449         *method_number = HW_ONLY;
00450     else if (COMPARE(method_arg, "FMRATE_ENABLE"))
00451         *method_number = PDV_FMRATE_ENABLE;
00452     else if (COMPARE(method_arg, "FVAL_ADJUST"))
00453         *method_number = PDV_FVAL_ADJUST;
00454     else if (COMPARE(method_arg, "BASLER_202K"))
00455         *method_number = BASLER_202K;
00456     else if (COMPARE(method_arg, "DUNCAN_2131"))
00457         *method_number = DUNCAN_2131;
00458 
00459     else if (COMPARE(method_arg, "FOI_REMOTE_AIA"))
00460         *method_number = FOI_REMOTE_AIA;
00461 
00462     else if (COMPARE(method_arg, "DALSA_CONTINUOUS"))
00463         *method_number = DALSA_CONTINUOUS;
00464 
00465     else if (COMPARE(method_arg, "EDT_ACT_NEVER"))
00466         *method_number = EDT_ACT_NEVER;
00467     else if (COMPARE(method_arg, "EDT_ACT_ONCE"))
00468         *method_number = EDT_ACT_ONCE;
00469     else if (COMPARE(method_arg, "EDT_ACT_ALWAYS"))
00470         *method_number = EDT_ACT_ALWAYS;
00471     else if (COMPARE(method_arg, "EDT_ACT_ONELEFT"))
00472         *method_number = EDT_ACT_ONELEFT;
00473     else if (COMPARE(method_arg, "EDT_ACT_CYCLE"))
00474         *method_number = EDT_ACT_CYCLE;
00475     else if (COMPARE(method_arg, "EDT_ACT_KBS"))
00476         *method_number = EDT_ACT_KBS;
00477 
00478     else if (COMPARE(method_arg, "BINARY"))
00479         *method_number = SERIAL_BINARY;
00480     else if (COMPARE(method_arg, "ASCII_HEX"))
00481         *method_number = SERIAL_ASCII_HEX;
00482     else if (COMPARE(method_arg, "ASCII"))
00483         *method_number = SERIAL_ASCII;
00484     else if (COMPARE(method_arg, "PULNIX_1010"))
00485         *method_number = SERIAL_PULNIX_1010;
00486     else if (COMPARE(method_arg, "DALSA_LS"))
00487         *method_number = PDV_DALSA_LS;
00488     else if (COMPARE(method_arg, "HEADER_BEFORE"))
00489         *method_number = PDV_HEADER_BEFORE;
00490     else if (COMPARE(method_arg, "HEADER_AFTER"))
00491         *method_number = PDV_HEADER_AFTER;
00492     else if (COMPARE(method_arg, "HEADER_WITHIN"))
00493         *method_number = PDV_HEADER_WITHIN;
00494     else if (COMPARE(method_arg, "DDCAM"))
00495         *method_number = PDV_DDCAM;
00496     else if (COMPARE(method_arg, "RS232"))
00497         *method_number = PDV_SERIAL_RS232;
00498     else if (COMPARE(method_arg, "BASLER_FRAMING"))
00499         *method_number = SERIAL_BASLER_FRAMING;
00500     else if (COMPARE(method_arg, "DUNCAN_FRAMING"))
00501         *method_number = SERIAL_DUNCAN_FRAMING;
00502     else
00503         return 0;
00504 
00505     return 1;
00506 }
00507 
00508 check_label(char *str, char *label)
00509 {
00510     char    tmplabel[64];
00511 
00512     sprintf(tmplabel, "%s:", label);
00513     if (strncmp(str, tmplabel, strlen(tmplabel)) == 0)
00514         return 1;
00515     return 0;
00516 }
00517 
00518 set_method(Dependent * dd_p, Edtinfo * ei_p, char *method_type, int method_number)
00519 {
00520     /* new for speed only */
00521     if (is_method(method_type, "camera_shutter_speed"))
00522         dd_p->camera_shutter_speed = method_number;
00523 
00524     /* ALERT: OBSOLETE */
00525     else if (is_method(method_type, "shutter_speed"))
00526         dd_p->camera_shutter_timing = method_number;
00527 
00528     else if (is_method(method_type, "camera_shutter_timing"))
00529         dd_p->camera_shutter_timing = method_number;
00530 
00531     else if (is_method(method_type, "lock_shutter"))
00532         dd_p->lock_shutter = method_number;
00533 
00534     else if (is_method(method_type, "camera_continuous"))
00535         dd_p->camera_continuous = method_number;
00536 
00537     else if (is_method(method_type, "camera_binning"))
00538         dd_p->camera_binning = method_number;
00539 
00540     else if (is_method(method_type, "camera_data_rate"))
00541         dd_p->camera_data_rate = method_number;
00542 
00543     else if (is_method(method_type, "pixelclock_speed")) /* alias */
00544         dd_p->camera_data_rate = method_number;
00545 
00546     else if (is_method(method_type, "camera_download"))
00547         dd_p->camera_download = method_number;
00548 
00549     else if (is_method(method_type, "get_gain"))
00550         dd_p->get_gain = method_number;
00551 
00552     else if (is_method(method_type, "get_offset"))
00553         dd_p->get_offset = method_number;
00554 
00555     else if (is_method(method_type, "set_gain"))
00556         dd_p->set_gain = method_number;
00557 
00558     else if (is_method(method_type, "set_offset"))
00559         dd_p->set_offset = method_number;
00560 
00561     else if (is_method(method_type, "first_open"))
00562         dd_p->first_open = method_number;
00563 
00564     else if (is_method(method_type, "last_close"))
00565         dd_p->last_close = method_number;
00566 
00567     else if (is_method(method_type, "interlace"))
00568     {
00569         if (method_number == PDV_PIRANHA_4CH_HWINTLV) /* special case hardware methods */
00570             dd_p->hwinterlace = method_number;
00571         else dd_p->swinterlace = method_number;
00572     }
00573     else if (is_method(method_type, "pingpong_varsize"))
00574         dd_p->pingpong_varsize = method_number;
00575 
00576     else if (is_method(method_type, "serial_format"))
00577         dd_p->serial_format = method_number;
00578 
00579     else if (is_method(method_type, "serial_mode"))
00580         dd_p->serial_mode = method_number;
00581 
00582     else if (is_method(method_type, "frame_timing"))
00583         dd_p->frame_timing = method_number;
00584 
00585     else if (is_method(method_type, "startdma"))
00586     {
00587         ei_p->startdma = method_number;
00588         dd_p->startdma = method_number;
00589     }
00590     else if (is_method(method_type, "enddma"))
00591     {
00592         ei_p->enddma = method_number;
00593         dd_p->enddma = method_number;
00594     }
00595 
00596     else if (is_method(method_type, "flushdma"))
00597     {
00598         ei_p->flushdma = method_number;
00599         dd_p->flushdma = method_number;
00600      }
00601 
00602     else if (is_method(method_type, "header_position"))
00603         dd_p->header_position = method_number;
00604 
00605 
00606 
00607     else
00608     {
00609         edt_msg(DEBUG0, "WARNING: unknown method direcive \"%s\" (ignored)\n", method_type);
00610         return 0;
00611     }
00612     return 1;
00613 }
00614 
00615 int
00616 is_method(char *method_type, char *name)
00617 {
00618     char    method_name[64];
00619 
00620     sprintf(method_name, "method_%s", name);
00621     if (COMPARE(method_name, method_type))
00622         return 1;
00623     return 0;
00624 }
00625 
00626 /*
00627  * clear dependent struct
00628  */
00629 void
00630 clear_dependent(Dependent * dd_p)
00631 {
00632     memset(dd_p, 0, sizeof(Dependent));
00633 }
00634 
00635 
00636 /*
00637  * check_xx_method return 1 if found, 0 if not found, -1 (and print msg) if
00638  * error.
00639  */
00640 int
00641 check_int_method(char *line, char *label, int *arg, char *cfgfile)
00642 {
00643     char    format[32];
00644     int     ret = 0;
00645     int     n;
00646 
00647     if (check_label(line, label))
00648     {
00649         sprintf(format, "%s: %%d", label);
00650         if ((n = sscanf(line, format, arg)) != 1)
00651         {
00652             edt_msg(DEBUG2,
00653                     "Error in parsing %s.\nExpected:\n\n\t%s: <parameter>\n",
00654                     cfgfile, label);
00655             edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00656             ret = -1;
00657         }
00658         else
00659             ret = 1;
00660     }
00661 
00662     return ret;
00663 }
00664 
00665 int
00666 check_ulong_method(char *line, char *label, u_long * arg, char *cfgfile)
00667 {
00668     char    format[32];
00669     int     ret = 0;
00670     int     n;
00671 
00672     if (check_label(line, label))
00673     {
00674         sprintf(format, "%s: %%lu", label);
00675         if ((n = sscanf(line, format, arg)) != 1)
00676         {
00677             edt_msg(DEBUG2,
00678                     "Error in parsing %s.\nExpected:\n\n\t%s: <parameter>\n",
00679                     cfgfile, label);
00680             edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00681             ret = -1;
00682         }
00683         else
00684             ret = 1;
00685     }
00686 
00687     return ret;
00688 }
00689 
00690 int
00691 check_float_method(char *line, char *label, float * arg, char *cfgfile)
00692 {
00693     char    format[32];
00694     int     ret = 0;
00695     int     n;
00696 
00697     if (check_label(line, label))
00698     {
00699         sprintf(format, "%s: %%f", label);
00700         if ((n = sscanf(line, format, arg)) != 1)
00701         {
00702             edt_msg(DEBUG2,
00703                     "Error in parsing %s.\nExpected:\n\n\t%s: <parameter>\n",
00704                     cfgfile, label);
00705             edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00706             ret = -1;
00707         }
00708         else
00709             ret = 1;
00710     }
00711 
00712     return ret;
00713 }
00714 
00715 int
00716 check_ushort_method(char *line, char *label, u_short * arg, char *cfgfile)
00717 {
00718     char    format[32];
00719     int     ret = 0;
00720     int     n;
00721     int     v;
00722 
00723     if (check_label(line, label))
00724     {
00725         sprintf(format, "%s: %%u", label);
00726         if ((n = sscanf(line, format, &v)) != 1)
00727         {
00728             edt_msg(DEBUG2,
00729                     "Error in parsing %s.\nExpected:\n\n\t%s: <parameter>\n",
00730                     cfgfile, label);
00731             edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00732             ret = -1;
00733         }
00734         else
00735         {
00736             *arg = v;
00737             ret = 1;
00738         }
00739     }
00740 
00741     return ret;
00742 }
00743 
00744 int
00745 check_byte_method(char *line, char *label, u_short * arg, char *cfgfile)
00746 {
00747     char    format[32];
00748     int     ret = 0;
00749     int     n;
00750     int     v;
00751 
00752     if (check_label(line, label))
00753     {
00754         sprintf(format, "%s: %%u", label);
00755         if ((n = sscanf(line, format, &v)) != 1)
00756         {
00757             edt_msg(DEBUG2,
00758                     "Error in parsing %s.\nExpected:\n\n\t%s: <parameter>\n",
00759                     cfgfile, label);
00760             edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00761             ret = -1;
00762         }
00763         else
00764         {
00765             *arg = v;
00766             ret = 1;
00767         }
00768     }
00769 
00770     return ret;
00771 }
00772 
00773 /*
00774  * parse a hex string -- 2 digit bytes separated by spaces, put into
00775  * char buffer
00776  */
00777 parse_hex_str(char *str, char *buf)
00778 {
00779     int i = 0;
00780     u_int ibyte;
00781     char *sp = str;
00782 
00783     while ((*(sp+2) == ' ') || (*(sp+2) == '\0'))
00784     {
00785         sscanf(sp, "%02x ", &ibyte);
00786         buf[i++] = (char)ibyte;
00787         if (*(sp+2) == '\0')
00788             break;
00789         sp += 3;
00790     }
00791     buf[i] = '\0';
00792     return 1;
00793 }
00794 
00795 /*
00796  * check string method -- return 0 on failure, 1 on success
00797  */
00798 check_str_method(char *line, char *label, char *arg, int max, char *cfgfile)
00799 {
00800     int     ret = 1;
00801     char   *p = NULL;
00802     char   *sp = NULL;
00803     char   *ep;
00804     char    endchar;
00805     char    tmp_arg[MAXINIT];
00806 
00807     p = strchr(line, ':');
00808     if (!p)
00809         return (0);
00810 
00811     if ((sp = strchr(p, '"')) != NULL)
00812         endchar = '"';
00813     else if ((sp = strchr(p, '<')) != NULL)
00814         endchar = '>';
00815     else return 0;
00816 
00817     ep = strrchr(sp, endchar);
00818 
00819     if (!check_label(line, label))
00820         return 0;
00821 
00822     if ((int) strlen(sp) > max)
00823     {
00824         edt_msg(DEBUG0,
00825                 "WARNING parsing %s: '%s' arg exceeds %d char max (truncating)\n",
00826                 cfgfile, label, max - 3);
00827     }
00828 
00829     if ((p == NULL)
00830         || (sp == NULL)
00831         || (ep == NULL)
00832         || (ep == p))
00833 
00834     {
00835         edt_msg(DEBUG2,
00836                 "Error in parsing %s.\nExpected:\n\n\t%s: \"command\" (up to %d chars);\n",
00837                 cfgfile, label, max - 2);
00838         if (sp)
00839             edt_msg(DEBUG2, "\nGot:\n\n\t%s, %d chars\n", sp, strlen(sp));
00840         else
00841             edt_msg(DEBUG2, "\nGot: Nothing\n");
00842         return 0;
00843     }
00844 
00845     strcpy(tmp_arg, ++sp);
00846     if ((int) strlen(sp) > max)
00847         tmp_arg[max-1] = '\0';
00848 
00849     /*
00850      * find last double quote, get rid of it
00851      */
00852     if ((ep = strrchr(tmp_arg, endchar)) != NULL)
00853         *ep = '\0';
00854 
00855     if (endchar == '>')
00856         ret = parse_hex_str(tmp_arg, arg);
00857     else strncpy(arg, tmp_arg, max);
00858 
00859     return ret;
00860 }
00861 
00862 
00863 check_path_method(char *line, char *label, char *arg, char *cfgfile)
00864 {
00865     int     ret = 0;
00866     int     n;
00867     char    format[32];
00868 
00869     if (check_label(line, label))
00870     {
00871         sprintf(format, "%s: %%s", label);
00872         if ((n = sscanf(line, format, arg)) != 1)
00873         {
00874             edt_msg(DEBUG2,
00875                     "Error in parsing %s.\nExpected:\n\n\t%s: <parameter>\n",
00876                     cfgfile, label);
00877             edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00878             ret = -1;
00879         }
00880         else
00881             ret = 1;
00882     }
00883 
00884     return ret;
00885 }
00886 
00887 
00888 /* ALERT: check if this is same as check_foi_init -- hopefully so */
00889 check_serial_init_method(char *line, char *label, char *cmd, char *cfgfile)
00890 {
00891     int     ret = 0;
00892     char   *p = NULL;
00893     char   *sp = NULL;
00894     char   *ep;
00895     char    tmp_arg[128];
00896 
00897     p = strchr(line, ':');
00898     if (!p)
00899         return 0;
00900     sp = strchr(p, '"');
00901     if (!sp)
00902         return 0;
00903     if (!check_label(line, label))
00904         return 0;
00905 
00906     if ((p == NULL)
00907         || (*(p + 1) == '\0')
00908         || (sp == NULL)
00909         || (strlen(sp) > (MAXINIT - 2))
00910         || ((ep = strrchr(sp, '"')) == NULL))
00911 
00912     {
00913         edt_msg(DEBUG2,
00914                 "Error in parsing %s.\nExpected:\n\n\t%s: \"command\" (up to %d chars);\n",
00915                 cfgfile, label, MAXINIT - 2);
00916         if (sp)
00917             edt_msg(DEBUG2, "\nGot:\n\n\t%s, %d chars\n", sp, strlen(sp));
00918         else edt_msg(DEBUG2, "\nGot: Nothing\n");
00919         return 0;
00920     }
00921 
00922     strcpy(tmp_arg, ++sp);
00923 
00924     /* find last double quote, get rid of it  */
00925     /* also tack on trailing ':' if not there  */
00926     ep = strrchr(tmp_arg, '"');
00927     if ((*(ep - 1) != ':') || (*(ep - 2) == '\\'))
00928         *ep++ = ':';
00929     *ep = '\0';
00930 
00931     strncpy(cmd, tmp_arg, MAXINIT);
00932     return 1;
00933 }
00934 
00935 /*
00936  * return 1 on success, 0 on failure.
00937  */
00938 check_hex_method(char *line, char *label, u_int * method, char *cfgfile)
00939 {
00940     char    format[32];
00941     char    hexstr[32];
00942 
00943     if (!check_label(line, label))
00944         return 0;
00945 
00946     sprintf(format, "%s: %%s", label);
00947     if (sscanf(line, format, hexstr) != 1)
00948     {
00949         edt_msg(DEBUG2, "Error in parsing %s.  Expected:\n\n\t%s: <hex_parameter>\n", cfgfile, label);
00950         edt_msg(DEBUG2, "\nGot:\n\n\t%s\n", line);
00951         return 0;
00952     }
00953     *method = strtol(hexstr, NULL, 16);
00954     return 1;
00955 }
00956 
00957 /*
00958  * check int, long, hex, string methods
00959  * 
00960  * return 1 if found, 0 if not found, -1 if error
00961  */
00962 check_other_param(char *s, Dependent * dd_p, char *cfgfile)
00963 {
00964     int     ret;
00965     int     tr;
00966     char    tmpstr[256];
00967 
00968     /*
00969      * integer methods
00970      */
00971     if (ret = check_int_method(s, "width", &dd_p->width, cfgfile))
00972         return ret;
00973     if (ret = check_int_method(s, "height", &dd_p->height, cfgfile))
00974         return ret;
00975     if (ret = check_int_method(s, "cam_width", &dd_p->cam_width, cfgfile))
00976         return ret;
00977     if (ret = check_int_method(s, "cam_height", &dd_p->cam_height, cfgfile))
00978         return ret;
00979     if (ret = check_int_method(s, "depth", &dd_p->depth, cfgfile))
00980         return ret;
00981     if (ret = check_int_method(s, "extdepth", &dd_p->extdepth, cfgfile))
00982         return ret;
00983     if (ret = check_int_method(s, "slop", &dd_p->slop, cfgfile))
00984         return ret;
00985     if (ret = check_int_method(s, "hwpad", &dd_p->hwpad, cfgfile))
00986         return ret;
00987     /* rgb 30 bit overloaded on hwpad register bits if PIR */
00988     if (ret = check_int_method(s, "rgb30", &dd_p->hwpad, cfgfile))
00989         return ret;
00990     if (ret = check_int_method(s, "irris_strip", &dd_p->hwpad, cfgfile))
00991         return ret;
00992     if (ret = check_int_method(s, "byteswap", &dd_p->byteswap, cfgfile))
00993         return ret;
00994     if (ret = check_int_method(s, "shortswap", &dd_p->shortswap, cfgfile))
00995         return ret;
00996     if (ret = check_int_method(s, "skip", &dd_p->skip, cfgfile))
00997         return ret;
00998     if (ret = check_int_method(s, "gendata", &dd_p->gendata, cfgfile))
00999         return ret;
01000     if (ret = check_int_method(s, "skipfrm", &dd_p->gendata, cfgfile))
01001         return ret;
01002     if (ret = check_int_method(s, "fixedlen", &dd_p->fixedlen, cfgfile))
01003         return ret;
01004     if (ret = check_int_method(s, "interlace", &dd_p->interlace, cfgfile))
01005         return ret;
01006     if (ret = check_int_method(s, "pdv_type", &dd_p->pdv_type, cfgfile))
01007         return ret;
01008     if (ret = check_int_method(s, "simulator_speed", &dd_p->sim_speed, cfgfile))
01009         return ret;
01010     if (ret = check_int_method(s, "cameratest", &dd_p->cameratest, cfgfile))
01011         return ret;
01012     if (ret = check_int_method(s, "genericsim", &dd_p->genericsim, cfgfile))
01013         return ret;
01014     if (ret = check_int_method(s, "disable_mdout", &dd_p->disable_mdout, cfgfile))
01015         return ret;
01016     if (ret = check_int_method(s, "sim_width", &dd_p->sim_width, cfgfile))
01017         return ret;
01018     if (ret = check_int_method(s, "sim_height", &dd_p->sim_height, cfgfile))
01019         return ret;
01020     if (ret = check_int_method(s, "sim_ctl", (int *) (&dd_p->sim_ctl), cfgfile))
01021         return ret;
01022     if (ret = check_int_method(s, "line_delay", &dd_p->line_delay, cfgfile))
01023         return ret;
01024     if (ret = check_int_method(s, "frame_delay", &dd_p->frame_delay, cfgfile))
01025         return ret;
01026     if (ret = check_int_method(s, "frame_height", &dd_p->frame_height, cfgfile))
01027         return ret;
01028     if (ret = check_int_method(s, "fv_once", &dd_p->fv_once, cfgfile))
01029         return ret;
01030     if (ret = check_int_method(s, "fval_once", &dd_p->fv_once, cfgfile)) /* alias */
01031         return ret;
01032     if (ret = check_int_method(s, "fval_done", &dd_p->fval_done, cfgfile))
01033         return ret;
01034     if (ret = check_int_method(s, "fv_done", &dd_p->fval_done, cfgfile)) /* alias */
01035         return ret;
01036     if (ret = check_int_method(s, "pingpong_varsize", &dd_p->pingpong_varsize, cfgfile))
01037         return ret;
01038     if (ret = check_int_method(s, "continuous", &dd_p->continuous, cfgfile))
01039         return ret;
01040     if (ret = check_int_method(s, "clr_continuous_end", &dd_p->clr_cont_end, cfgfile))
01041         return ret;
01042     if (ret = check_int_method(s, "clr_continuous_start", &dd_p->clr_cont_start,
01043                                cfgfile))
01044         return ret;
01045     if (ret = check_int_method(s, "cnt_continuous", (int *) (&dd_p->cnt_continuous), cfgfile))
01046         return ret;
01047 
01048     if (ret = check_int_method(s, "shutter_speed_frontp", &dd_p->shutter_speed_frontp, cfgfile))
01049         return ret;
01050     if (ret = check_int_method(s, "shutter_speed", &dd_p->shutter_speed, cfgfile))
01051         return ret;
01052     if (ret = check_int_method(s, "shutter_speed_min", &dd_p->shutter_speed_min, cfgfile))
01053         return ret;
01054     if (ret = check_int_method(s, "shutter_speed_max", &dd_p->shutter_speed_max, cfgfile))
01055         return ret;
01056 
01057     if (ret = check_int_method(s, "aperture_min", &dd_p->aperture_min, cfgfile))
01058         return ret;
01059     if (ret = check_int_method(s, "aperture_max", &dd_p->aperture_max, cfgfile))
01060         return ret;
01061     if (ret = check_int_method(s, "default_shutter_speed", &dd_p->default_shutter_speed, cfgfile))
01062         return ret;
01063     if (ret = check_int_method(s, "default_exposure", &dd_p->default_shutter_speed, cfgfile))
01064         return ret;
01065     if (ret = check_int_method(s, "default_aperture", &dd_p->default_aperture, cfgfile))
01066         return ret;
01067 
01068     if (ret = check_int_method(s, "gain_min", &dd_p->gain_min, cfgfile))
01069         return ret;
01070     if (ret = check_int_method(s, "gain_max", &dd_p->gain_max, cfgfile))
01071         return ret;
01072     if (ret = check_int_method(s, "default_gain", &dd_p->default_gain, cfgfile))
01073         return ret;
01074     if (ret = check_int_method(s, "gain_frontp", &dd_p->gain_frontp, cfgfile))
01075         return ret;
01076 
01077     if (ret = check_int_method(s, "offset_min", &dd_p->offset_min, cfgfile))
01078         return ret;
01079     if (ret = check_int_method(s, "offset_max", &dd_p->offset_max, cfgfile))
01080         return ret;
01081     if (ret = check_int_method(s, "offset_frontp", &dd_p->offset_frontp, cfgfile))
01082         return ret;
01083     if (ret = check_int_method(s, "default_offset", &dd_p->default_offset, cfgfile))
01084         return ret;
01085     if (ret = check_int_method(s, "serial_baud", &dd_p->serial_baud, cfgfile))
01086         return ret;
01087     if (ret = check_int_method(s, "DUAL_CHANNEL", &dd_p->dual_channel, cfgfile))
01088         return ret;
01089     if (ret = check_int_method(s, "DOUBLE_RATE", &dd_p->double_rate, cfgfile))
01090         return ret;
01091     if (ret =