/* tscreen.c July 29, 1991 Robert R. Howell */ /* Modified to run in a NeXT window; 6 Sept 91 esp */ /* July 12, 1994 R. Howell Eliminated output of Dec Dial. It is not meaningful. */ /* RRH: 08/15/94 Added nod indicator */ /* JSW: 02/18/00 Added tscreen_add() */ /* JSW: 04/11/11 Change dome_enc and dome_on. */ /* I need to avoid excess output, and only have it output variables */ /* which have changed. To do this, I will keep a copy of each */ /* output variable, and examine it for a change before outputing */ /* it. Note that I'm not going to spend the time checking rounding */ /* before doing this. Therefore, any change, even if it does not */ /* result in a change in visible characters, will result in output. */ typedef char * lpchar; /* long pointer to character */ #include #include #include #include #include #include "wirotypes.h" #include "track.h" #include "wtrack.h" /* This must come before wiro */ #include "wiro.h" extern struct wiro_memory *tinfo; /* Pointer to shared tracking info */ int scount=0; /* Count calls to screen routine. */ int number_terminals=0; /* the number of active tracker screens */ FILE *screen_stream[10]; /* up to 20 active tracker screens are possible */ /* Prototypes of the local functions */ void clear_screen(void); void temit(char c); void ttype(char *cptr); void cursor(int row, int column); void get_cursor(int *row, int *column); void dblout(int row, int column, int fld, int dpl, double x); void hmsout(int row, int column, int fld, int dpl, double x); void intout(int row, int column, int fld, int i); void chrout(int row, int column, lpchar cptr); /* Initialize serial port */ int register_port(char* name); /* open a stream to write screen data too */ void serial_snd(unsigned char); /* Send serial data */ int serial_ocount(void); /* # of chr. waiting for output */ unsigned char serial_rcv(void); /* Get serial data */ unsigned int tsrsize; int ibusy = 0; /* True if interrupt routine is busy */ int orow, ocolumn; /* Cursor position when routine starts. */ int tmp; char serial_buffer[2048]; /* Buffer for serial port data. */ void serial_snd(unsigned char a) { int i; for (i=0; i 80) fld = 80; cursor(row, column); strncpy(hmsstr, hr_hms(x, fld, dpl), fld+1); ttype(hmsstr); } /* 32 bit integer output */ void intout(int row, int column, int fld, int i) { char format[80]; char outstr[80]; if ( !printall && (ival[iindx] == i) ) /* Need to reprint? */ { iindx++; return; } ival[iindx++] = i; cursor(row, column); sprintf(format, "%c%uld", '%', fld); sprintf(outstr, format, i); ttype(outstr); } /* string output */ void cchrout(int row, int column, lpchar cptr) { if ( !printall && (0==strcmp(cptr,strval[strindx]))) /* Need to reprint? */ { strindx++; return; } strcpy(strval[strindx++],cptr); cursor(row, column); ttype(cptr); } /* character output */ void chrout(int row, int column, lpchar cptr) { cursor(row, column); ttype(cptr); } /****************** Set up the tracker screen *****************************/ void tscreen_init( void ) { int i; clear_screen(); printall = 1; /* Print everything */ chrout( 1, 1, "OBJECT"); /* Output labels */ chrout( 1, 60, "UT"); chrout( 1, 40, "LST"); chrout( 1, 73, "DATE"); chrout( 4, 26, "R.A."); chrout( 4, 39, "DEC"); chrout( 4, 49, "H.A."); chrout( 4, 60, "DOME"); chrout( 4, 70, "AIRMASS"); chrout( 8, 16, "H.A."); chrout( 8, 29, "DEC"); chrout( 9, 60, "TELESCOPE:"); chrout(10, 60, "DOME:"); chrout( 5, 1, "ACTUAL J(date)"); chrout( 6, 1, "DESIRED J(date)"); chrout( 7, 1, "Astrometric J1950"); chrout( 9, 1, "OFFSET"); chrout(10, 1, " NOD"); chrout(11, 1, " COL"); chrout(12, 1, " DIAL"); chrout(13, 1, " RATES"); chrout(14, 1, "ERRORS"); } /************************* Add a tracking screen ****************************/ void tscreen_add( void ) { screen_stream[ number_terminals++ ] = fopen( tinfo->new_tscreen, "w" ); if( screen_stream[ number_terminals-1 ] == NULL ) { number_terminals--; printf( "Unable to open terminal %s.\n", tinfo->new_tscreen ); } else { tscreen_init(); } } /****************** Update the tracker screen ******************************/ void tminn( void ) { int i; /* loop index. */ int posi; char posc[5]; float ftmp; iindx = 0; /* Indices for reprint? tests */ dindx = 0; strindx =0; hmsout( 5, 20, 13, 2, RA); /* actual position */ hmsout( 5, 33, 12, 1, DEC); hmsout( 5, 46, 11, 1, HA / 15. ); hmsout( 9, 10, 12, 1, OFFSET_HA ); /* Offsets in " */ hmsout( 9, 23, 12, 1, OFFSET_DEC ); if (NODDED) { /* Has telescope been nodded? */ hmsout(10, 10, 12, 1, NOD_HA ); hmsout(10, 23, 12, 1, NOD_DEC ); cchrout(10, 45, "B Beam"); } else{ hmsout(10, 10, 12, 1, 0. ); hmsout(10, 23, 12, 1, 0. ); cchrout(10, 45, "A Beam"); } hmsout(14, 10, 12, 1, DES_HA - HA ); /* Errors */ hmsout(14, 23, 12, 1, DEC - DES_DEC ); /* USE DD:MM:SS for both */ if ( fabs(DES_HA - HA) > 5.0 / 3600. ) { cchrout( 9, 36, "XXXXXXXX"); cchrout(10, 36, "XXXXXXXX"); } else if ( fabs(DES_HA - HA) > 1.0 / 3600. ) { cchrout( 9, 36, "........"); cchrout(10, 36, "........"); } else { cchrout( 9, 36, " "); cchrout(10, 36, " "); } if ( fabs(DES_DEC - DEC) > 5.0 / 3600. ) { cchrout(12, 36, "XXXXXXXX"); cchrout(13, 36, "XXXXXXXX"); } else if ( fabs(DES_DEC - DEC ) > 1.0 / 3600. ) { cchrout(12, 36, "........"); cchrout(13, 36, "........"); } else { cchrout(12, 36, " "); cchrout(13, 36, " "); } hmsout( 2, 34, 11, 1, LST); hmsout( 2, 54, 11, 1, UT_TIME); intout( 2, 69, 4, YEAR); intout( 2, 74, 2, MONTH); intout( 2, 77, 2, DAY); cchrout(16, 1, USER_STR[0]); cchrout(17, 1, USER_STR[1]); cchrout(18, 1, USER_STR[2]); cchrout(19, 1, USER_STR[3]); cchrout(20, 1, USER_STR[4]); cchrout(21, 1, USER_STR[5]); cchrout(22, 1, USER_STR[6]); /* for (i=0; i<20; i++) if ( OBJECT_NAME[i] == NULL ) OBJECT_NAME[i]=' '; */ strcat(OBJECT_NAME," "); OBJECT_NAME[20] = 0; cchrout( 2, 6, OBJECT_NAME); /* for(i=strlen(OBJECT_NAME); i<20; i++) temit(' '); */ /* Now output actual dome position */ tmp = (int) (tinfo->dome_enc+0.5); intout( 5, 60, 4, tmp); hmsout( 6, 20, 13, 2, DES_RA); /* wanted */ hmsout( 6, 33, 12, 1, DES_DEC); hmsout( 6, 46, 11, 1, DES_HA / 15.); if (tinfo->dome_on != 2) intout( 6, 60, 4, (int) (AZI+0.5) ); else intout( 6, 60, 4, (int) (tinfo->dome_des_pos+0.5) ); ftmp = sin( RAD( ALT ) ); if (ftmp == 0) ftmp = 0.001; ftmp = 1/ftmp; dblout( 6, 72, 5, 2, ( ftmp ) ); /* more elaborate later? */ hmsout(11, 10, 12, 1, COL_HA ); /* Col */ hmsout(11, 23, 12, 1, COL_DEC); hmsout(12, 10, 12, 1, tinfo->dial_ha); /* Dial */ /* hmsout(12, 23, 12, 1, tinfo->dial_dec); */ /* Print rates as arcseconds/second. The RA rates are really only */ /* this at DEC=0. The printed numbers are actually 15 * (s/s) */ hmsout(13, 10, 12, 1, ( V_RA * cos( rad( DEC ) ) * 15./3600. ) ); hmsout(13, 23, 12, 1, ( V_DEC / 3600. ) ); if (tinfo->no_motion) /* Drives enabled? */ cchrout( 9, 72, "OFF"); /* Logic is opposite of dome_on */ else cchrout( 9, 72, "ON "); if (tinfo->dome_on==1) /* Dome enabled */ cchrout(10, 72, "ON "); else if (tinfo->dome_on==0) cchrout(10, 72, "OFF"); else { posi = (int) (tinfo->dome_des_pos+0.5); sprintf(posc, "%3d", posi); cchrout(10, 72, posc); } printall = 0; } /**************** Clear the screen ******************/ void clear_screen() { /* Erase ANSI terminal */ { serial_snd( 27); serial_snd('['); serial_snd('2'); serial_snd('J'); } } /*************** Emit a character to the tracker screen ******************/ /* either the console or the terminal. *******/ void temit(char chr) { int i; for (i=0; i