char exfifoinbuffer[1024] = "\0"; FILE *exfifoin = NULL; exfifo_alert( char * txt ) { monitor_alert(txt); } int exfifoworkevent( unsigned char event ) { waitTillLoopFree( ); doLoopEvent( event ); return(1); } void exfifowork( void ) { int az,azdir,alt,altdir; if( prog.motorrun == MGUIDE ){ if(exfifoinbuffer[0] == 'o'){ return; } if(strlen(exfifoinbuffer) < 7 ){ return; } if( ! exfifo.invert ) { if( exfifoinbuffer[0] == '1' ){ if_gazcorrectionhs = if_gazcorrectionhs - exfifo.azsteps; } if( exfifoinbuffer[2] == '1' ){ if_gazcorrectionhs = if_gazcorrectionhs + exfifo.azsteps; } if( exfifoinbuffer[4] == '1' ){ if_galtcorrectionhs = if_galtcorrectionhs + exfifo.altsteps; } if( exfifoinbuffer[6] == '1' ){ if_galtcorrectionhs = if_galtcorrectionhs - exfifo.altsteps; } } else { if( exfifoinbuffer[0] == '1' ){ if_gazcorrectionhs = if_gazcorrectionhs + exfifo.azsteps; } if( exfifoinbuffer[2] == '1' ){ if_gazcorrectionhs = if_gazcorrectionhs - exfifo.azsteps; } if( exfifoinbuffer[4] == '1' ){ if_galtcorrectionhs = if_galtcorrectionhs - exfifo.altsteps; } if( exfifoinbuffer[6] == '1' ){ if_galtcorrectionhs = if_galtcorrectionhs + exfifo.altsteps; } } return; } if(! exfifo.follow ){ return; } if( ( prog.motorrun == MNORUN ) || ( prog.motorrun == MCORRECTION ) ){ if(exfifoinbuffer[0] == 'o'){ exfifoworkevent(IFEVT_STOPMOTORS); return; } if(strlen(exfifoinbuffer) < 7 ){ return; } az = 0; azdir = 0; alt = 0; altdir = 0; if( ! exfifo.invert ) { if( exfifoinbuffer[0] == '1' ){ azdir = 1; az = 1; } if( exfifoinbuffer[2] == '1' ){ azdir = 0; az = 1; } if( exfifoinbuffer[4] == '1' ){ altdir = 0; alt = 1; } if( exfifoinbuffer[6] == '1' ){ altdir = 1; alt = 1; } } else { if( exfifoinbuffer[0] == '1' ){ azdir = 0; az = 1; } if( exfifoinbuffer[2] == '1' ){ azdir = 1; az = 1; } if( exfifoinbuffer[4] == '1' ){ altdir = 1; alt = 1; } if( exfifoinbuffer[6] == '1' ){ altdir = 0; alt = 1; } } if( az || alt ){ waitTillLoopFree( ); if_Move( SPEED_SLOW ,az, azdir, alt, altdir, 0, 0 ); } } } void exfifoloop ( char *data ) { int len; exfifo.fiforun = 1; while( exfifo.fiforun ) { exfifoin = fopen(exfifo.fifoinfile,"rt"); if( exfifoin == NULL ){ exfifo_alert("Cannot open ex - fifoin"); exfifo.fiforun = 0; continue; } len = fread( &exfifoinbuffer[0], 128 , 1 , exfifoin); fclose(exfifoin); exfifowork(); } } int exfifostart( void ) { if( ! exfifo.start ) { return(1); } if( exfifo.fifoinfile[0] == 0 ) { exfifo_alert("EXFIFO is on, but no inputfile defined"); return(0); } if( pthread_create( &exfifo.exfifothread, NULL, (void *)&exfifoloop, NULL ) != 0 ){ return( 0 ); } return(1); }