/* * 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 configvalues cfg = { "/dev/video", 0, "./", "img", 0, 100, 0, 0, 10,10,1, 0, 0, 0, 0, 0, 1 }; void correctCfgValues( void ) { if(cfg.calcstart < 3){ cfg.calcstart = 3; } if(cfg.calcstart > 255 ){ cfg.calcstart = 255; } if(cfg.coltolerance < 0){ cfg.coltolerance = 0; } if(cfg.coltolerance > 255){ cfg.coltolerance = 255; } if(cfg.seeing < 0 ){ cfg.seeing = 0; } if(cfg.seeing > 19 ){ cfg.seeing = 19; } 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.control > 1 ){ cfg.control = 1; } if(cfg.control < 0 ){ cfg.control = 0; } } void help( void ) { fprintf( stdout,"\n\n"); #ifdef VIEW fprintf( stdout,"elctrcamw (co.) E.Benninghaus, Rottweil, Germany\n"); fprintf( stdout,"usage: elctrcamw -options\n\n"); #else fprintf( stdout,"elctrcam (co.) E.Benninghaus, Rottweil, Germany\n"); fprintf( stdout,"usage: elctrcam -options\n\n"); #endif fprintf( stdout,"-d (file) device for videodev, default /dev/video\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 comparison\n"); fprintf( stdout,"-s (0- 19) seeing in pixel, where 0 is best\n"); #ifdef VIEW fprintf( stdout,"-showcross view of koordinates is on at start.\n"); fprintf( stdout,"-view view is on at startup\n"); #endif fprintf( stdout,"-test output to stdout, instead steering, (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],"-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],"-s")==0) && ( argv[arg + 1] != NULL) ) { cfg.seeing = 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],"-ctrl")==0 ) { cfg.control = 1; arg++; continue; } if( strcmp(argv[arg],"-test")==0 ) { cfg.test = 1; arg++; continue; } arg++; } correctCfgValues(); return(1); } int readconfigfile( char *filename ) { size_t len; double d; long l; int i; unsigned short us; FILE *fp; char *s,*p; s = &il_tmptext[0]; sprintf(s,"./%s",filename); fp = fopen(s,"rt"); if(fp == NULL){ p = getenv("HOME"); if(p != NULL){ sprintf(s,"%s/.%s",p,filename); fp = fopen(s,"rt"); } } if(fp == NULL){ sprintf(s,"/etc/%s",filename); fp = fopen(s,"rt"); } if(fp == NULL){ ctrcfgalert("Cannot find, - or open configfile", fp); return( 0 ); } rewind(fp); while ( ! feof( fp ) ) { fgets( s , 252 , fp ); strCleanStr( s, 254 ); strEatBytes(0x20 , s ,254, 1); if( ( s[0] == ';' ) || ( s[0] == '#' ) ){ continue; } p = strchr(s, '=' ); if( p == NULL ){ continue; } p[0] = 0;p++; if(strcmp(s,"INTERFACE" ) == 0){ if(strcmp( p, "SERIAL") == 0 ){ elctr.iftype = IF_SERIAL; continue; } if(strcmp( p, "PARALLELSMC") == 0 ){ elctr.iftype = IF_PARALLEL; parsubtype = IF_PARALLELSUBSMC; continue; } if(strcmp( p, "PARALLELRAW") == 0 ){ elctr.iftype = IF_PARALLEL; parsubtype = IF_PARALLELSUBRAW; continue; } ctrcfgalert("No valid interface defined for INTERFACE", fp); return(0); } if(strcmp(s,"SERIALPORT" ) == 0){ len = strlen(p); if( len < 3 ){ ctrcfgalert("No valid portstring for SERIALPORT", fp); return(0); } if( len >= 128 ){ ctrcfgalert("portstring for SERIALPORT is too long", fp); return(0); } strcpy( &serialport[0], p ); continue; } if(strcmp(s,"JOYSTICKPORT" ) == 0){ if( strTestPtrHex( p ) == 1 ){ sscanf(p, "%x", &i ); } else { i = atoi( p ); } us = ( unsigned short ) i; if( us <= 0 ){ ctrcfgalert("Invalid value for JOYSTICKPORT",fp); return(0); } setJoystickPort( us ); continue; } if(strcmp(s,"PARALLELPORT" ) == 0){ if( strTestPtrHex( p ) == 1 ){ sscanf(p, "%x", &i ); } else { i = atoi( p ); } us = ( unsigned short ) i; if( us <= 0 ){ ctrcfgalert("Invalid value for PARALLELPORT",fp); return(0); } setParallelPort( us ); continue; } if(strcmp(s,"INPUTTYPE" ) == 0){ if(strcmp( p, "SERIAL") == 0 ){ elctr.inputiftype = IF_INPUTSERIAL; continue; } if(strcmp( p, "PARALLEL") == 0 ){ elctr.inputiftype = IF_INPUTPARALLEL; continue; } if(strcmp( p, "JOYSTICK") == 0 ){ elctr.inputiftype = IF_INPUTJOYSTICK; continue; } ctrcfgalert("No valid interface defined for INPUTTYPE", fp); return(0); } if(strcmp(s,"INPUTPORT" ) == 0){ if( strTestPtrHex( p ) == 1 ){ sscanf(p, "%x", &i ); } else { i = atoi( p ); } us = ( unsigned short ) i; if( us <= 0 ){ ctrcfgalert("Invalid value for INPUTPORT",fp); return(0); } if(elctr.inputiftype == IF_INPUTPARALLEL){ setParallelPort2( us ); continue; } if(elctr.inputiftype == IF_INPUTJOYSTICK){ setJoystickPort2( us ); continue; } if(elctr.inputiftype == IF_INPUTSERIAL){ continue; } ctrcfgalert("No valid INPUTTYPE for setting of port", fp); return(0); } if(strcmp(s,"JOYSTICKKEYPAD" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.keypad = KEYPADTYPE_JOYSTICK; } continue; } if(strcmp(s,"PARALLELKEYPAD" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.keypad = KEYPADTYPE_PARALLEL; } continue; } if(strcmp(s,"TIMERINTCTGOTO" ) == 0){ d = strtod((const char *)p,NULL); if( d < 0.0 ){ ctrcfgalert("No valid value defined for TIMERINTCTGOTO", fp); return(0); } elctr.timerintct_goto = d; continue; } if(strcmp(s,"TIMERINTCTCORRECTION" ) == 0){ d = strtod((const char *)p,NULL); if( d < 0.0 ){ ctrcfgalert("No valid value defined for TIMERINTCTCORRECTION", fp); return(0); } elctr.timerintct_correction = d; continue; } if(strcmp(s,"AZGOTOSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for AZGOTOSPEED", fp); return(0); } elctr.az_gotospeed = d; continue; } if(strcmp(s,"ALTGOTOSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTGOTOSPEED", fp); return(0); } elctr.alt_gotospeed = d; continue; } if(strcmp(s,"FRGOTOSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for FRGOTOSPEED", fp); return(0); } elctr.fr_gotospeed = d; continue; } if(strcmp(s,"AZCORRECTIONSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for AZCORRECTIONSPEED", fp); return(0); } elctr.az_correctionspeed = d; continue; } if(strcmp(s,"ALTCORRECTIONSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTCORRECTIONSPEED", fp); return(0); } elctr.alt_correctionspeed = d; continue; } if(strcmp(s,"FRCORRECTIONSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for FRCORRECTIONSPEED", fp); return(0); } elctr.fr_correctionspeed = d; continue; } if(strcmp(s,"AZHS360" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for AZHS360", fp); return(0); } elctr.hs_az360 = d; continue; } if(strcmp(s,"ALTHS90" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTHS90", fp); return(0); } elctr.hs_alt90 = d; continue; } if(strcmp(s,"FRHS360" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for FRHS360", fp); return(0); } elctr.hs_fr360 = d; continue; } if(strcmp(s,"ALTHSHORIZONTLIMIT" ) == 0){ d = strtod((const char *)p,NULL); if( d < 0.0 ){ ctrcfgalert("No valid value defined for ALTHSHORIZONTLIMIT", fp); return(0); } elctr.hs_altlb = d; continue; } if(strcmp(s,"ALTHSZENITLIMIT" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTHSZENITLIMIT", fp); return(0); } elctr.hs_altub = d; continue; } if(strcmp(s,"FRUSE" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.fruse = 1; } continue; } if(strcmp(s,"FRLEFT" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.frleft = 1; } continue; } if(strcmp(s,"DEBUG" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.debug = 1; } continue; } /* ############## Settings for elctrcam ############ */ if(strcmp(s,"VIDEODEVICE" ) == 0){ len = strlen(p); if( len < 3 ){ ctrcfgalert("No valid string for VIDEODEVICE", fp); return(0); } if( len > 82 ){ ctrcfgalert("String for VIDEODEVICE is too long", fp); return(0); } strcpy( cfg.devicefile, p ); continue; } if(strcmp(s,"SNAP" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.snap = 1; } continue; } if(strcmp(s,"SNAPDIR" ) == 0){ len = strlen(p); if( len < 1 ){ ctrcfgalert("No valid string for SNAPDIR", fp); return(0); } if( len > 182 ){ ctrcfgalert("String for SNAPDIR is too long", fp); return(0); } strcpy( cfg.snapdir, p ); continue; } if(strcmp(s,"SNAPPREFIX" ) == 0){ len = strlen(p); if( len < 1 ){ ctrcfgalert("No valid string for SNAPPREFIX", fp); return(0); } if( len > 82 ){ ctrcfgalert("String for SNAPPREFIX is too long", fp); return(0); } strcpy( cfg.snapprefix, p ); continue; } if(strcmp(s,"MAXSNAP" ) == 0){ l = atol((const char *)p ); if( l < 0 ){ ctrcfgalert("No valid value defined for MAXSNAP", fp); return(0); } cfg.maxsnap = l; continue; } if(strcmp(s,"SNAPQUALITY" ) == 0){ i = atoi((const char *)p ); if( ( i < 1 ) || ( i > 100 ) ){ ctrcfgalert("No valid value defined for SNAPQUALITY", fp); return(0); } cfg.snapquality = i; continue; } if(strcmp(s,"SNAPSIZE" ) == 0){ i = atoi((const char *)p ); if( ( i < 0 ) || ( i > 4 ) ){ ctrcfgalert("No valid value defined for SNAPSIZE", fp); return(0); } cfg.snapsize = i; continue; } if(strcmp(s,"COTOLERANCE" ) == 0){ i = atoi((const char *)p ); if( ( i < 0 ) || ( i > 255 ) ){ ctrcfgalert("No valid value defined for COLTOLERANCE", fp); return(0); } cfg.coltolerance = i; continue; } if(strcmp(s,"CALCSTART" ) == 0){ l = atol((const char *)p ); if( (l < 3) || ( l > 255 ) ){ ctrcfgalert("No valid value defined for CALCSTART", fp); return(0); } cfg.calcstart = l; continue; } if(strcmp(s,"SEEING" ) == 0){ i = atoi((const char *)p ); if( ( i < 0 ) || ( i > 19 ) ){ ctrcfgalert("No valid value defined for SEEING", fp); return(0); } cfg.seeing = i; continue; } if(strcmp(s,"CONTROL" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.control = 1; } continue; } if(strcmp(s,"TEST" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.test = 1; } continue; } if(strcmp(s,"AUTOGUIDE" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.guide = 1; } continue; } #ifdef VIEW if(strcmp(s,"VIEW" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.view = 1; } continue; } if(strcmp(s,"SHOWCROSS" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.showcross = 1; } continue; } if(strcmp(s,"REAL" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { cfg.savebuf = 1; } continue; } #endif } fclose( fp ); correctCfgValues(); return( ctrcorrectvalues() ); } #ifdef __cplusplus } #endif #endif /*_config_c*/