/* * config.c * * * * Copyright (C) 2002 - 2002 Benninghaus, Rottweil * EMail: el@eb-themen.de * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _config_c #define _config_c #ifdef __cplusplus extern "C" { #endif typedef struct configvalues { char devicefile[84]; int tcpport; int snap; /*0,1*/ char snapdir[130]; char snapprefix[84]; long maxsnap; /*0 ...*/ int snapquality; /*1-100*/ int snapsize; /*0-4*/ int savebuf; /*0,1*/ int coltolerance; /*0 - 255*/ long calcstart; /*1-255*/ int maxcalckoor; /*1-100*/ int percentcorrect; /*0-100*/ int seeing; /*0-19*/ int strategy; /*0-2*/ int koortype; /*0,1*/ int xraster; /*1-20*/ int yraster; /*1-20*/ int showcross; /*0,1*/ int ecif; /*0,1*/ int fifo; /*0,1*/ char fifofile[84]; int view; /*0,1*/ int control; /*0,1*/ long coverinterval; /*0...*/ int test; /*0,1*/ } configvalues; configvalues cfg = { "/dev/video", 23500, 0, "./", "img", 0, 100, 0, 0, 10,10,10,100,1, 0, 1, 6,6, 0, 0, 0, "/tmp/elcam_fifoout", 0, 0, 0, 0 }; void correctCfgValues( void ) { if(cfg.calcstart < 1){ cfg.calcstart = 1; } if(cfg.calcstart > 255 ){ cfg.calcstart = 255; } if(cfg.maxcalckoor < 1){ cfg.maxcalckoor = 1; } if(cfg.maxcalckoor > 100){ cfg.maxcalckoor = 100; } if(cfg.coltolerance < 0){ cfg.coltolerance = 0; } if(cfg.coltolerance > 255){ cfg.coltolerance = 255; } if(cfg.percentcorrect < 0){ cfg.percentcorrect = 0; } if(cfg.percentcorrect > 100){ cfg.percentcorrect = 100; } if(cfg.seeing < 0 ){ cfg.seeing = 0; } if(cfg.seeing > 19 ){ cfg.seeing = 19; } if(cfg.strategy > 2 ){ cfg.strategy = 2; } if(cfg.strategy < 0 ){ cfg.strategy = 0; } if(cfg.koortype > 1 ){ cfg.koortype = 1; } if(cfg.koortype < 0 ){ cfg.koortype = 0; } if(cfg.xraster > 20 ){ cfg.xraster = 20; } if(cfg.xraster < 1 ){ cfg.xraster = 1; } if(cfg.yraster > 20 ){ cfg.yraster = 20; } if(cfg.yraster < 1 ){ cfg.yraster = 1; } if(cfg.showcross > 1 ){ cfg.showcross = 1; } if(cfg.showcross < 0 ){ cfg.showcross = 0; } if(cfg.maxsnap < 0 ){ cfg.maxsnap = 0; } if(cfg.snapquality > 100 ){ cfg.snapquality = 100; } if(cfg.snapquality < 1 ){ cfg.snapquality = 1; } if(cfg.snapsize > 4 ){ cfg.snapsize = 4; } if(cfg.snapsize < 0 ){ cfg.snapsize = 0; } if(cfg.tcpport <= 0 ){ cfg.tcpport = 23500; } if(cfg.ecif > 1 ){ cfg.ecif = 1; } if(cfg.ecif < 0 ){ cfg.ecif = 0; } if(cfg.control > 1 ){ cfg.control = 1; } if(cfg.control < 0 ){ cfg.control = 0; } if(cfg.coverinterval < 0 ){ cfg.coverinterval = 0; } if(! cfg.fifo ){ cfg.control = 0; } } void help( void ) { fprintf( stdout,"\n\n"); #ifdef VIEW fprintf( stdout,"elcamw (co.) E.Benninghaus, Rottweil, Germany\n"); fprintf( stdout,"usage: elcamw -options\n"); #else fprintf( stdout,"elcam (co.) E.Benninghaus, Rottweil, Germany\n"); fprintf( stdout,"usage: elcam -options\n\n"); #endif fprintf( stdout,"-d (file) device for videodev, default /dev/video\n"); fprintf( stdout,"-i (nr) portnumber for tcpserver, default 23500\n"); fprintf( stdout,"-sp snapping of pictures on\n"); fprintf( stdout,"-spdir (dir) directory, where pictues will be stored, default ./\n"); fprintf( stdout,"-spfil (fil) prefix for autom. numbered images, default img\n"); fprintf( stdout,"-spmax (nr) maximal number of pictures to snap, 0 no limit\n"); fprintf( stdout,"-spq (1-100) quality / compression for snapped jpeg\n"); fprintf( stdout,"-sps (0- 4) 0=160x120,1=176x144,2=320x240,3=352x288,4=640x480\n"); #ifdef VIEW fprintf( stdout,"-real realview on at startup\n"); #endif fprintf( stdout,"-c (0-255) add. tolerance of brightness\n"); fprintf( stdout,"-u (1-255) pictures get before start of test\n"); fprintf( stdout,"-m (1-100) max. koordinates to test (only spread)\n"); fprintf( stdout,"-p (0-100) percent of correct koordinates (spread,cover)\n"); fprintf( stdout,"-s (0- 19) seeing in pixel, where 0 is best\n"); fprintf( stdout,"-iv(0....) nr of pict. till reloop ( only cover ), 0 means off\n"); fprintf( stdout,"-spot strategy spot (planets, stars), ( default)\n"); fprintf( stdout,"-spread strategy spread (sensitive configurable)\n"); fprintf( stdout,"-cover strategy cover (simple compare with matrix)\n"); fprintf( stdout,"-cross a cross is used for tested koors. ( default )\n"); fprintf( stdout,"-rect a rectangle is used for testing\n"); fprintf( stdout,"-x (1- 20) raster x (spread, cover)\n"); fprintf( stdout,"-y (1- 20) raster y (spread, cover)\n"); #ifdef VIEW fprintf( stdout,"-showcross view of koordinates is on at start. (spot,spread)\n"); fprintf( stdout,"-view view is on at startup\n"); #endif fprintf( stdout,"-tcp tcpserver is used\n"); fprintf( stdout,"-fifo fifoout is used\n"); fprintf( stdout,"-f (file) path/name of fifooutfile, default /tmp/elcam_fifoout\n"); fprintf( stdout,"-ctrl this enables the output of fifo, (default off)\n"); fprintf( stdout,"-test output to stdout, instead to fifo, (default off)\n"); fprintf( stdout,"\n"); } int parsecommandline(int argc, char * argv[]) { int arg; char *p; for (arg = 1; arg < argc;) { if(strcmp(argv[arg],"-h")==0){ help(); return(0); } if( ( strcmp(argv[arg],"-d")==0) && ( argv[arg + 1] != NULL) ) { if(strlen(argv[arg + 1]) > 82){ fprintf(stderr,"len of string for devicefile exceeds max. 82 chars\n"); return(0); } strcpy(cfg.devicefile,argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-i")==0) && ( argv[arg + 1] != NULL) ) { cfg.tcpport = atoi(argv[arg + 1]); arg++;arg++; continue; } if( strcmp(argv[arg],"-sp")==0 ) { cfg.snap = 1; arg++; continue; } if( ( strcmp(argv[arg],"-spdir")==0) && ( argv[arg + 1] != NULL) ) { if(strlen(argv[arg + 1]) > 128){ fprintf(stderr,"len of string for snapdirectory exceeds max. 128 chars\n"); return(0); } strcpy(cfg.snapdir,argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-spfil")==0) && ( argv[arg + 1] != NULL) ) { if(strlen(argv[arg + 1]) > 82){ fprintf(stderr,"len of string for snapprefix exceeds max. 82 chars\n"); return(0); } strcpy(cfg.snapprefix,argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-spmax")==0) && ( argv[arg + 1] != NULL) ) { cfg.maxsnap = atol(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-spq")==0) && ( argv[arg + 1] != NULL) ) { cfg.snapquality = atoi(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-sps")==0) && ( argv[arg + 1] != NULL) ) { cfg.snapsize = atoi(argv[arg + 1]); arg++;arg++; continue; } #ifdef VIEW if( strcmp(argv[arg],"-real")==0 ) { cfg.savebuf = 1; arg++; continue; } #endif if( ( strcmp(argv[arg],"-c")==0) && ( argv[arg + 1] != NULL) ) { cfg.coltolerance = atoi(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-u")==0) && ( argv[arg + 1] != NULL) ) { cfg.calcstart = atol(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-m")==0) && ( argv[arg + 1] != NULL) ) { cfg.maxcalckoor = atoi(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-p")==0) && ( argv[arg + 1] != NULL) ) { cfg.percentcorrect = atoi(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-s")==0) && ( argv[arg + 1] != NULL) ) { cfg.seeing = atoi(argv[arg + 1]); arg++;arg++; continue; } if( strcmp(argv[arg],"-spot")==0 ) { cfg.strategy = 0; arg++; continue; } if( strcmp(argv[arg],"-spread")==0 ) { cfg.strategy = 1; arg++; continue; } if( strcmp(argv[arg],"-cover")==0 ) { cfg.strategy = 2; arg++; continue; } if( strcmp(argv[arg],"-cross")==0 ) { cfg.koortype = 1; arg++; continue; } if( ( strcmp(argv[arg],"-iv")==0) && ( argv[arg + 1] != NULL) ) { cfg.coverinterval = atol(argv[arg + 1]); arg++;arg++; continue; } if( strcmp(argv[arg],"-rect")==0 ) { cfg.koortype = 0; arg++; continue; } if( ( strcmp(argv[arg],"-x")==0) && ( argv[arg + 1] != NULL) ) { cfg.xraster = atoi(argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-y")==0) && ( argv[arg + 1] != NULL) ) { cfg.yraster = atoi(argv[arg + 1]); arg++;arg++; continue; } #ifdef VIEW if( strcmp(argv[arg],"-showcross")==0 ) { cfg.showcross = 1; arg++; continue; } if( strcmp(argv[arg],"-view")==0 ) { cfg.view = 1; arg++; continue; } #endif if( strcmp(argv[arg],"-tcp")==0 ) { cfg.ecif = 1; arg++; continue; } if( strcmp(argv[arg],"-fifo")==0 ) { cfg.fifo = 1; arg++; continue; } if( ( strcmp(argv[arg],"-f")==0) && ( argv[arg + 1] != NULL) ) { if(strlen(argv[arg + 1]) > 82){ fprintf(stderr,"len of string for fifooutfile exceeds max. 82 chars\n"); return(0); } strcpy(cfg.fifofile,argv[arg + 1]); arg++;arg++; continue; } if( strcmp(argv[arg],"-ctrl")==0 ) { cfg.control = 1; arg++; continue; } if( strcmp(argv[arg],"-test")==0 ) { cfg.test = 1; arg++; continue; } arg++; } correctCfgValues(); return(1); } #ifdef __cplusplus } #endif #endif /*_config_c*/