/* 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: 01/24/11 Port to CentOS: static definitions added. */ /* Display rates as formed in rate (arcs/s) or planet (arcs/hr). */ /* |RRH|: Change "Astrometric J1950" to "Mean Equinox of Date". */ /* JSW: 04/11/11 Accomodate "dome " command: Change tinfo->dome_enc */ /* & tinfo->dome_on; Use tinfo->dome_des_pos for "". */ /* JSW: 10/22/13 Display ACU data at bottom of screen. Move and /* label Cass focus readout. /* 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 modeout(unsigned long long modein); void listout(int row, int column, lpchar cptr); void cchrout(int row, int column, lpchar cptr); 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); } /* mode output */ void modeout(unsigned long long modein) { int row, column; unsigned long long nfundamode, nsubmode, ndomemode; char fundamode[20], submode[20], domemode[20]; if ( !printall && (modeval == modein) ) /* Need to reprint? */ { return; } modeval = modein; modein = modein/100; ndomemode = modein%100; modein = modein/100000; nsubmode = modein%100; nfundamode = modein/100; switch(ndomemode) { case 70: strcpy(domemode, "STOP "); break; case 71: strcpy(domemode, "POS DESIGNATE "); break; case 72: strcpy(domemode, "STOW "); break; case 73: strcpy(domemode, "SLAVE "); break; case 53: strcpy(domemode, "MAINTENANCE "); break; case 13: strcpy(domemode, "TABLE TRACK "); break; default: strcpy(domemode, "(?) "); break; } strcpy(tinfo->vrsi_dome_mode, domemode); switch(nsubmode) { case 00: strcpy(submode, "RESET "); break; case 01: strcpy(submode, "TRANSITION "); break; case 02: strcpy(submode, "ACTIVE "); break; case 03: strcpy(submode, "OFF TARGET "); break; case 04: strcpy(submode, "STOP "); break; case 05: strcpy(submode, "DISABLED "); break; case 06: strcpy(submode, "PENDING "); break; case 07: strcpy(submode, "WAIT TO START "); break; case 8: strcpy(submode, "FINISHED "); break; case 9: strcpy(submode, "POS HOLD "); break; default: strcpy(submode, "(?) "); break; } strcpy(tinfo->vrsi_sub_mode, submode); switch(nfundamode) { case 00: strcpy(fundamode, "STOP "); break; case 01: strcpy(fundamode, "POS DESIGNATE "); break; case 02: strcpy(fundamode, "PRESET POS "); break; case 06: strcpy(fundamode, "MAINTENANCE "); break; case 8: strcpy(fundamode, "MAN POS "); break; case 9: strcpy(fundamode, "STOW "); break; case 12: strcpy(fundamode, "STAR TRACK "); break; case 23: strcpy(fundamode, "SUN TRACK "); break; case 24: strcpy(fundamode, "MOON TRACK "); break; case 29: strcpy(fundamode, "POS HOLD "); break; default: strcpy(fundamode, "(?) "); break; } strcpy(tinfo->vrsi_funda_mode, fundamode); cchrout(17, 14, fundamode); cchrout(18, 14, submode); cchrout(19, 14, domemode); } /* list output */ void listout(int row, int column, lpchar cptr) { int i,j,k,m,n; char tempval[26]; char cstr[2]; if ( !printall && (0==strcmp(cptr,listval[listindx]))) /* Need to reprint? */ { listindx++; return; } strcpy(listval[listindx++],cptr); for (i=0; i<=7; ) { strcpy(tempval, ""); for (j=0; j<=24; ) { if (cptr[27*i]==03) { for (k=i; k<=7; k=k+1) { chrout(row+k, column, " "); if (i==0) chrout(row, column+8, "(none)"); } i=8; j=25; } else { n = 27*i+j; sprintf(cstr, "%c", cptr[n]); strcat(tempval, cstr); } j++; } cchrout(row+i, column, tempval); i++; } } /* 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:"); if ((FOCUS > -2.) && (FOCUS < 2.)) chrout(13, 60, "FOCUS:"); chrout( 5, 1, "ACTUAL"); chrout( 6, 1, "DESIRED"); chrout( 7, 1, "Mean Equinox of Date"); chrout( 9, 1, "OFFSET"); chrout(10, 1, " NOD"); chrout(11, 1, " COL"); chrout(12, 1, " DIAL"); chrout(13, 1, " RATES"); chrout(14, 1, "ERRORS"); chrout(15, 1, "_____________________________________________________\ ___________________________"); chrout(16, 8, "ACU MODES"); chrout(17, 1, "FUNDAMENTAL:"); chrout(18, 5, "SUBMODE:"); chrout(19, 3, "DOME MODE:"); chrout(16, 35, "ACU FAULTS"); chrout(16, 62, "ACU STATUS"); } /************************* 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; listindx = 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, 71, 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 arcs/s if NON_SOLAR and arcs/hr if SOLAR. */ /* The RA rates are really only this at DEC=0. */ hmsout(13, 10, 12, 1, ( V_RA * 15. * cos(PI * DES_DEC / 180.))); hmsout(13, 23, 12, 1, V_DEC); if (tinfo->motion_type == NON_SOLAR) cchrout( 13, 45, "arcs/s "); else if (tinfo->motion_type == SOLAR) cchrout( 13, 45, "arcs/hr"); else cchrout( 13, 45, " "); 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); } if ((FOCUS > -2.) && (FOCUS < 2.)) dblout(13, 71, 6, 3, FOCUS); modeout(tinfo->vrsi_mode); listout(17, 29, tinfo->vrsi_faults); listout(17, 56, tinfo->vrsi_status); 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