char monitor_alerttxt[100] = "none\0"; char monitor_header[100] = "ELTEL-Monitor Vers.1.00 ------------ "; MONITORCALLBACK monitorextern = NULL; MONITORCALLBACK monitorexternalert = NULL; void SetMonitorExtern( MONITORCALLBACK cb ){ if(cb != NULL){ monitorextern = cb; } } void SetMonitorExternAlert( MONITORCALLBACK cb ){ if(cb != NULL){ monitorexternalert = cb; } } void monitor_alert( char * txt ) { if(monitor.monitorrun){ if(monitorexternalert != NULL){ if(txt == NULL){ strcpy(monitor_alerttxt,"none\0"); } else { strcpy( monitor_alerttxt,txt); } (*monitorexternalert)(&monitor_alerttxt[0]); return; } SetDefCol; ScrMove(1,24); SetDefCol; if(txt == NULL){ fprintf(stdout,"Errors/Msg : %s", monitor_alerttxt); strcpy(monitor_alerttxt,"none\0"); ScrMove(14,24); } else { fprintf(stdout,"Errors/Msg : %s",txt); strcpy( monitor_alerttxt,txt); ScrMove(14,24); } } else { fprintf(stdout,"\r\n%s\r\n",txt); } } int monitorobjsetobj(char *instr ) { EDBOBJ obj; if( setEDBobjFromStr( &obj, instr ) ) { strcpy( monitor.objname, obj.objname ); strcpy( monitor.objtype, obj.objtype); strcpy(monitor.rastr, obj.rastr); strcpy(monitor.decstr,obj.decstr); return(1); } strcpy( monitor.objname, obj.objname ); strcpy( monitor.objtype, obj.objtype); return(0); } int monitorobjchooseobj( char * filename ) { FILE *f; int pos,ct,key; long fpos,fct,flen; char str[128]; char koors[128]; if( filename == NULL ){ return(0); } f = fopen( filename, "rt" ); if(f == NULL){ monitor_alert("Cannot open objdbfile"); return(0); } fseek( f, 0L, SEEK_END); flen = ftell( f ); rewind(f); if(flen < 10){ fclose(f); return(0); } pos = 0; fpos = 0L; while( f != NULL ) { rewind(f); fct = 0L; while( ( fct < fpos) && ( feof(f) == 0 ) ){ fgets( str, 120, f ); fct++; } ct = 0; ScrClear(); while( ( feof( f ) == 0 ) && (ct < 20) ) { fgets( str, 120, f ); if(str[0] == ';'){ continue; } ScrMove(1, ct + 1 ); if( pos == ct ){ strcpy(koors,str); SetCol6; } else { SetCol3; } fputs( str, stdout ); ct++; } SetDefCol; ScrMove(1,ct + 2); fputs("Choose with up,down keys, and Enter, - or break with any other key",stdout); ScrMove(1,ct + 3); fputs("Use left,right arrowkeys for move inside the file",stdout); key = ReadKey(); if(key == UP){ if( pos > 0 ){ pos = pos - 1; } continue; } if(key == DOWN){ if(pos < ( ct - 1) ) { pos = pos + 1; } continue; } if(key == LEFT){ fpos = fpos - 20; if(fpos < 0L){ fpos = 0L; } continue; } if(key == RIGHT){ fpos = fpos + 20; continue; } if(key == ENTER){ /* set koors to monitor.rastr,monitor.decstr*/ fclose(f); if(monitorobjsetobj( &koors[0] )){ return(1); } monitor_alert("Invalid koordinates"); return( 0 ); } break; } fclose(f); return(0); } char * monitorobjchoosefile(void) { DIR *d; struct dirent * sd; int pos,ct,key; if( monitor.objdbpath[0] == 0 ){ return(NULL); } d = opendir( (const char *)monitor.objdbpath ); if(d == NULL){ monitor_alert("Cannot open objdbpath"); return(NULL); } pos = 0; while( d != NULL ) { ct = 0; rewinddir( d ); ScrClear(); while( ( sd = readdir( d ) ) && (ct < 20) ) { if( sd->d_name[0] == '.'){ continue; } ScrMove(1, ct + 1 ); if( pos == ct ){ sprintf(il_tmptext,"%s/%s\0",monitor.objdbpath, sd->d_name ); SetCol6; } else { SetCol3; } fputs( sd->d_name, stdout ); ct++; } SetDefCol; ScrMove(1,ct + 3); fputs("Choose with arrowkeys, and Enter, - or break with any other key",stdout); key = ReadKey(); if(key == UP){ if( pos > 0 ){ pos = pos - 1; } continue; } if(key == DOWN){ if(pos < ( ct - 1) ) { pos = pos + 1; } continue; } if(key == ENTER){ closedir(d); return( &il_tmptext[0] ); } break; } closedir(d); return(NULL); } int monitorworkflag = 0; int monitorwork(unsigned char event ) { waitTillLoopFree(); if( event == PREVT_MARKRADECKOORS ) { strcpy(prog.rastr,monitor.rastr); strcpy(prog.decstr,monitor.decstr); } doLoopEvent( event ); monitorworkflag = 1; return(1); } int monitorobjects(unsigned char event ) { char *name; name = monitorobjchoosefile(); if( name == NULL){ return(1); } if( monitorobjchooseobj( name ) ) { strcpy(prog.objname,monitor.objname); strcpy(prog.objtype,monitor.objtype); monitorwork( event ); } return(1); } int monitorshow(int pos ) { unsigned char event; struct tm * _tm; time_t _tsec; ScrClear(); SetDefCol; ScrMove(1,1); fputs(monitor_header,stdout); SetCol1; fputs("use key F10 for ending the program.",stdout); SetDefCol; ScrMove(1,2); fputs("Servertype ",stdout); if(server.servertype == SERVERTYPETCP){ fputs("tcp :",stdout); } if(server.servertype == SERVERTYPEFIFO){ fputs("fifo :",stdout); } if(server.servertype == 0){ fputs("none :",stdout); } if(server.serverrun){ fputs("On ",stdout); } else { fputs("Off",stdout); } fputs( " xephemfifo ",stdout); fputs( "in:",stdout); if( ( xephem.fifoinfile[0] != 0 ) && ( xephem.start ) ){ fputs("on ",stdout); } else { fputs("off",stdout); } fputs( " out:",stdout); if(xephem.fifooutfile[0] == 0){ fputs("off",stdout); } else { fputs("on ",stdout); } fputs(" keypad:",stdout); if(prog.keypad){ fputs("on ",stdout); } else { fputs("off",stdout); } fputs(" IF:",stdout); if( prog.iftype == 0 ){ fputs("none",stdout); } if( prog.iftype == IF_SERIAL ){ fputs("-SERIAL",stdout); } if( prog.iftype == IF_PARALLEL ){ if(parsubtype == IF_PARALLELSUBSMC){ fputs("-SMC800",stdout); } else { fputs("PARPORT",stdout); } } SetDefCol; ScrMove(1,4); if(pos == 0 ){ SetCol6; } else { SetCol3; } if( prog.motorrun == MNORUN ){ fputs("STOP (NOT RUNNING).",stdout); } else if(prog.motorrun == MGUIDE){ fputs("STOP (GUIDEING ACTIVE).",stdout); } else if(prog.motorrun == MCORRECTION){ if(prog.motorspeed == SPEED_SLOW){ fputs("STOP (CORRECTION SLOW).",stdout); } else { fputs("STOP (CORRECTION FAST).",stdout); } } else if(prog.motorrun == MGOTO){ fputs("STOP (FAST GOTO).",stdout); } else if(prog.motorrun == MFR){ fputs("STOP (FIELDROTATOR).",stdout); } ScrMove(40,4); if(pos == 1 ){ SetCol6; } else { SetCol3; } fputs(". START GUIDEING",stdout); ScrMove(1,5); if(pos == 2 ){ SetCol6; } else { SetCol3; } fputs("UP -slow- .",stdout); ScrMove(40,5); if(pos == 3 ){ SetCol6; } else { SetCol3; } fputs(". -slow- DOWN",stdout); ScrMove(1,6); if(pos == 4 ){ SetCol6; } else { SetCol3; } fputs("LEFT -slow- .",stdout); ScrMove(40,6); if(pos == 5 ){ SetCol6; } else { SetCol3; } fputs(". -slow- RIGHT",stdout); ScrMove(1,7); if(pos == 6 ){ SetCol6; } else { SetCol3; } fputs("UP -fast- .",stdout); ScrMove(40,7); if(pos == 7 ){ SetCol6; } else { SetCol3; } fputs(". -fast- DOWN",stdout); ScrMove(1,8); if(pos == 8 ){ SetCol6; } else { SetCol3; } fputs("LEFT -fast- .",stdout); ScrMove(40,8); if(pos == 9 ){ SetCol6; } else { SetCol3; } fputs(". -fast- RIGHT",stdout); ScrMove(1,9); if(pos == 10 ){ SetCol6; } else { SetCol3; } fputs("FRLEFT .",stdout); ScrMove(40,9); if(pos == 11 ){ SetCol6; } else { SetCol3; } fputs(". FRRIGHT",stdout); ScrMove(1,10); if(pos == 12 ){ SetCol6; } else { SetCol3; } fputs("GOTO marked obj .",stdout); ScrMove(40,10); if(pos == 13 ){ SetCol6; } else { SetCol3; } fputs(". marked obj ORIGIN",stdout); ScrMove(1,11); if(pos == 14 ){ SetCol6; } else { SetCol3; } fputs("GET KOORDINATES .",stdout); ScrMove(40,11); if(pos == 15 ){ SetCol6; } else { SetCol3; } fputs(". GET KOORS, AND SEND TO XEPHEM",stdout); ScrMove(1,13); if(pos == 16 ){ SetCol6; } else { SetCol3; } fputs("SELECT OBJ .",stdout); ScrMove(40,13); if(pos == 17 ){ SetCol6; } else { SetCol3; } if(scope.calcrefraction){ fputs(". (ON) Toggle, calc. of refract.",stdout); } else { fputs(". (OFF) Toggle, calc. of refract.",stdout); } ScrMove(1,14); if(pos == 18 ){ SetCol6; } else { SetCol3; } if(xephem.keypadspecial){ fputs("Toggle, xe-keypadspecial (ON) .",stdout); } else { fputs("Toggle, xe-keypadspecial (OFF) .",stdout); } ScrMove(40,14); if(pos == 19 ){ SetCol6; } else { SetCol3; } if(xephem.fifooutloop){ if(xephem.fifooutloopbusy){ fputs(". (RUNNING)Toggle, xephemoutloop.",stdout); } else { fputs(". (ON) Toggle, xephemoutloop.",stdout); } } else { fputs(". (OFF) Toggle, xephemoutloop.",stdout); } ScrMove(1,15); if(pos == 20 ){ SetCol6; } else { SetCol3; } if(scope.fruse){ fputs("Toggle, Stop fieldrotator (ON) .",stdout); } else { fputs("Toggle, Init fieldrotator(OFF) .",stdout); } ScrMove(40,15); if(pos == 21 ){ SetCol6; } else { SetCol3; } fputs(". Update FR-Koordinates.",stdout); ScrMove(1,16); if(pos == 22 ){ SetCol6; } else { SetCol3; } if(! exfifo.fiforun){ fputs("Toggle, Follow-Ext (NOT VALID) .",stdout); } else { if(exfifo.follow){ fputs("Toggle, Stop Follow-Ext. (ON) .",stdout); } else { fputs("Toggle, Init Follow-Ext. (OFF) .",stdout); } } ScrMove(40,16); if(pos == 23 ){ SetCol6; } else { SetCol3; } if( encoder.type != NOENCODER ){ if( encoder.active ){ fputs(". (ON) Toggle, using encoders.",stdout); } else { fputs(". (OFF) Toggle, using encoders.",stdout); } } else { fputs(". (NOT VALID) Toggle, encoders.",stdout); } ScrMove(1,17); if(pos == 24 ){ SetCol6; } else { SetCol3; } fputs("Reserved .",stdout); ScrMove(40,17); if(pos == 25 ){ SetCol6; } else { SetCol3; } fputs(". Reserved",stdout); ScrMove(1,19); SetCol4;fputs("AZ : ",stdout); SetCol0;fputs(prog.azstr,stdout); ScrMove(19,19); SetCol4;fputs("ALT: ",stdout); SetCol0;fputs(prog.altstr,stdout); ScrMove(40,19); SetCol4;fputs("RA : ",stdout); SetCol0;fputs(prog.rastr,stdout); ScrMove(59,19); SetCol4;fputs("DEC: ",stdout); SetCol0;fputs(prog.decstr,stdout); ScrMove(1,20); SetCol4;fputs("OBJ: ",stdout); SetCol0;fputs(prog.objname, stdout); ScrMove(40,20); SetCol4;fputs("TYP: ",stdout); SetCol0;fputs(prog.objtype, stdout); ScrMove(1,21); SetCol4;fputs("FR : ",stdout); SetCol0;fputs(prog.frstr,stdout); ScrMove(19,21); SetCol4; fputs("LAST: ",stdout); SetCol1; fprintf(stdout,"%f",LAST); ScrMove(40,21); SetCol4; fputs("TIM: ",stdout); SetCol1; if(prog.motorrun == MGUIDE){ _tsec = cCSTcurseconds; } else { _tsec = time(&_tsec); } _tm = localtime( &_tsec ); fprintf(stdout,"%02d:%02d:%02d",_tm->tm_hour,_tm->tm_min,_tm->tm_sec); ScrMove(59,21); SetCol4; fputs("ATM: ",stdout); SetCol1; if(prog.motorrun == MGUIDE){ _tsec = cCSTadjcurseconds; } else { _tsec = time(&_tsec) + scope.utcadjust; } _tm = localtime( &_tsec ); fprintf(stdout,"%02d:%02d:%02d",_tm->tm_hour,_tm->tm_min,_tm->tm_sec); ScrMove(1,22); SetCol4; fputs("Last event: ",stdout); ScrMove(19,22); SetCol1; fputs(prog.eventstr,stdout); if(prog.debug){ ScrMove(1,23); SetDefCol; fprintf(stdout,"azhs:%.0f alths:%.0f frhs:%.0f guidesec:%ld guidect:%ld", scope.lastazhs,scope.lastalths,scope.lastfrhs, guide.updateseconds, guide.updatecounter); } monitor_alert( NULL ); return(1); } void monitorloop ( char *data ) { int key,pos,x; monitor.monitorrun = 1; pos = 0; x = 0; if(monitorextern != NULL){ (*monitorextern)(NULL); monitorworkflag = 0; while( ( monitor.monitorrun ) && (monitorextern != NULL ) ) { while( (! monitorworkflag ) && ( monitor.monitorrun ) && ( monitorextern != NULL ) ) { ; } if( (monitor.monitorrun ) && (monitorextern != NULL) ){ (*monitorextern)(NULL); monitorworkflag = 0; } } monitor.monitorrun = 0; return; } ScrClear(); while( monitor.monitorrun ) { monitorshow( pos ); key = ReadKey(); switch( key ) { case FN10: monitor.monitorrun = 0; monitorwork( IFEVT_ENDALL ); break; case LEFT: if(x == 1){ x = 0; pos = pos - 1; } break; case RIGHT: if(x == 0){ x = 1; pos = pos + 1; } break; case UP: if(pos > 1 ){ pos = pos - 2; } break; case DOWN: if(pos < 24){ pos = pos + 2; } break; case ENTER: switch(pos){ case 0: monitorwork(IFEVT_STOPMOTORS ); break; case 1: monitorwork(IFEVT_STARTGUIDE ); break; case 2: monitorwork( IFEVT_SLOWUP ); break; case 3: monitorwork( IFEVT_SLOWDOWN ); break; case 4: monitorwork( IFEVT_SLOWLEFT ); break; case 5: monitorwork( IFEVT_SLOWRIGHT ); break; case 6: monitorwork( IFEVT_FASTUP ); break; case 7: monitorwork( IFEVT_FASTDOWN ); break; case 8: monitorwork( IFEVT_FASTLEFT ); break; case 9: monitorwork( IFEVT_FASTRIGHT ); break; case 10: monitorwork( PREVT_FRTURNLEFT ); break; case 11: monitorwork( PREVT_FRTURNRIGHT ); break; case 12: monitorwork( IFEVT_GOTORADECKOORS ); break; case 13: monitorwork( IFEVT_ORIGINRADECKOORS ); break; case 14: monitorwork( IFEVT_GETKOORS ); break; case 15: monitorwork( PREVT_SENDAZALTKOORSTOXEPHEM ); break; case 16: monitorobjects( PREVT_MARKRADECKOORS ); break; case 17: if(scope.calcrefraction){ monitorwork( PREVT_SWITCHOFFVALIDCALCREFRACTION ); } else { monitorwork( PREVT_SWITCHONVALIDCALCREFRACTION ); } break; case 18: if(xephem.keypadspecial){ monitorwork( PREVT_JOYSTICKKEYPADASPECIALOFF ); } else { monitorwork( PREVT_JOYSTICKKEYPADASPECIALON ); } break; case 19: if(xephem.fifooutloop){ monitorwork( PREVT_XEPHEMOUTLOOPOFF ); } else { monitorwork( PREVT_XEPHEMOUTLOOPON ); } break; case 20: if(scope.fruse){ monitorwork( PREVT_STOPFIELDROTATOR ); } else { monitorwork( PREVT_INITFIELDROTATOR ); } break; case 21: monitorwork( PREVT_GETFRKOOR ); break; case 22: if(exfifo.fiforun){ monitorwork( PREVT_TOGGLEEXFIFOFOLLOW ); } break; case 23: if(encoder.type != NOENCODER){ monitorwork( PREVT_TOGGLEENCODERS ); } break; case 24: break; case 25: break; default:break; } default: break; } } ScrClear; SetDefCol; fprintf(stdout,"\r\nELTEL-monitor ends\r\n"); monitor.monitorrun = 0; } int monitorstart ( void ) { sprintf(monitor_header,"ELTEL-Monitor Vers.%s ------------ ",ELASTROVERSION); if( ! monitor.start ) { return(1); } if( pthread_create( &monitor.monitorthread, NULL, (void *)&monitorloop, NULL ) != 0 ){ return( 0 ); } return( 1 ); }