#ifndef _main_c #define _main_c #include "eltel.h" #include "../strutil.c" #include "../util.c" #include "../calc.c" #include "../conv.c" #include "../sectors.c" #include "../keypad.c" #include "../key.c" #include "../vid.c" #include "../edb.c" #include "interface.c" #include "config.c" #include "loop.c" #include "server.c" #include "xephemfifo.c" #include "exfifo.c" #include "monitor.c" #include "test.c" /* all reachable variables ,and datas */ scopevalues scope; guidevalues guide; programvalues prog; servervalues server; xephemfifovalues xephem; monitorvalues monitor; exfifovalues exfifo; encodervalues encoder; /* ################################## */ typedef void ( *sighandler_t)(int); /*###################################*/ char eltel_version[20] = "Vers. 1.01"; /*###################################*/ sighandler_t sighandler_old = SIG_ERR; void sigterminate(int sig) { if(sig != SIGTERM)return; if(sighandler_old != SIG_ERR){ signal(SIGTERM,sighandler_old); sighandler_old = SIG_ERR; } /* clear all */ prog.looprun = 0; if( prog.connection ) { if_StopConnection( ); } server.serverrun = 0; xephem.fifooutloopbusy = 0; xephem.xefiforun = 0; exfifo.fiforun = 0; monitor.monitorrun = 0; parconnection = 0; sleep(1); cRfFreeValues(); exit(0); } void sigrestore(void) { if(sighandler_old == SIG_ERR)return; signal(SIGTERM,sighandler_old); sighandler_old = SIG_ERR; } int sigset(void) { sigrestore(); sighandler_old = signal(SIGTERM,sigterminate); if(sighandler_old == SIG_ERR)return(-1); return(0); } #ifdef EXMAIN pthread_t externthread; void externloop ( char *data ) { loop( ); } int exmain(int argc, char *argv[]) #else int main(int argc, char *argv[]) #endif { int arg; char *pi,*pf; char *cfg; int testmode; pi = NULL; pf = NULL; cfg = NULL; testmode = 0; for ( arg = 1; arg < argc;) { pi = argv[ arg ]; pf = argv[ arg + 1 ]; if( ( pi != NULL ) && ( pf != NULL ) ) { if( strncmp( pi, "-c" , 2 ) == 0 ) { cfg = pf; arg++;arg++; continue; } } arg++; } cfg_init_defaultvalues(); cfg_init_scopevalues(); if( cfg_read_configfile( cfg ) == 0) { fprintf(stderr,"\nInvalid file, or settings\n"); exit(-1); } if(! cfg_check_conditions() ){ fprintf(stderr,"\nUnusable configuration-settings\n"); exit(-1); } for ( arg = 1; arg < argc;) { pi = argv[ arg ]; pf = argv[ arg + 1 ]; if( ( pi != NULL ) && ( pf != NULL ) ) { if( strncmp( pi, "-rf" , 3 ) == 0 ) { if(strncmp( pf,"OFF",3) == 0){ scope.calcrefraction = 0; } arg++;arg++; continue; } if( strncmp( pi, "-t" , 2 ) == 0 ) { scope.temperature = strtod((const char *)pf,NULL); arg++;arg++; continue; } if( strncmp( pi, "-p" , 2 ) == 0 ) { scope.airpressure = strtod((const char *)pf,NULL); arg++;arg++; continue; } } if( pi != NULL){ if(strncmp( pi, "-testck",7) == 0){ testmode = 1; arg++; continue; } if(strncmp( pi, "-skip",5) == 0){ prog.skipstartupmotor = 1; arg++; continue; } } arg++; } fprintf(stdout,"\r\nELTEL START\r\n"); if( sigset() < 0){ fprintf(stdout,"\r\nCannot install signalhandler\r\n"); exit(-1); } prog.pid = getpid(); prog.uid = getuid(); if( prog.keypad || ( prog.iftype == IF_PARALLEL ) || ( encoder.type == JOYSTICKENCODER) || ( encoder.type == PARALLELENCODER) ) { if( testPermissions() == 0 ){ sigrestore(); exit(-1); } } if(testmode == 1 ){ test_CalculatedKoors(); endPermissions(); sigrestore(); exit(1); } if(serverstart( ) == 0 ) { fprintf(stdout,"\r\nCannot start server\r\n"); endPermissions(); sigrestore(); exit(-1); } if(xephemfifostart( ) == 0 ) { fprintf(stdout,"\r\nCannot start xephemfifo\r\n"); server.serverrun = 0; sleep(1); endPermissions(); sigrestore(); exit(-1); } if(exfifostart( ) == 0 ) { fprintf(stdout,"\r\nCannot start exfifo\r\n"); server.serverrun = 0; xephem.xefiforun = 0; sleep(1); endPermissions(); sigrestore(); exit(-1); } if(scope.calcrefraction){ fprintf(stdout,"\r\nCalculates refractionlist, - this may take a while\r\n"); if( cRfInitValues( scope.temperature, scope.airpressure, scope.calcrefraction ) == 0 ) { fprintf(stdout,"\r\nCannot init refractionlist, - perhaps too less memory\r\n"); server.serverrun = 0; xephem.xefiforun = 0; exfifo.fiforun = 0; sleep(1); endPermissions(); sigrestore(); exit(-1); } } #ifdef EXMAIN monitor.start = 1; #endif if(monitorstart() == 0 ) { fprintf(stdout,"\r\nCannot start monitor\r\n"); server.serverrun = 0; xephem.xefiforun = 0; exfifo.fiforun = 0; sleep(1); endPermissions(); sigrestore(); exit(-1); } #ifdef EXMAIN if( pthread_create( &externthread, NULL, (void *)&externloop, NULL ) != 0 ){ fprintf(stdout,"\r\nCannot start loopthread\r\n"); server.serverrun = 0; xephem.xefiforun = 0; exfifo.fiforun = 0; monitor.monitorrun = 0; sleep(1); endPermissions(); sigrestore(); exit(-1); } return(0); } int exend( void ) { #else loop(); #endif parconnection = 0; if( prog.keypad | ( prog.iftype == IF_PARALLEL ) ) { endPermissions(); } prog.looprun = 0; sleep(1); xephem.fifooutloopbusy = 0; server.serverrun = 0; xephem.xefiforun = 0; exfifo.fiforun = 0; monitor.monitorrun = 0; sleep(1); sigrestore(); cRfFreeValues(); DebugCalculation(); fprintf(stdout,"\r\nELTEL END\r\n"); exit(0); } #endif /*_main_c*/