#define EXTERN extern #include #include #include #include #include #include #include #include #include /* #include "common.h" #include "ic_common.h" #include "go_common.h" #include "socket_help.h" */ char tcshostname[100]; char buf[100]; int tcs_com(char *command, char *reply, int reply_size, char *tcshostname); int set_tcshaslew(float ha, float dec) { int hasign, hah, ham, decsign, decd, decm; int rc; float has, decs; hasign = 1; if (ha < 0.) { hasign = -1; ha = fabs(ha); } hah = (int)ha; ha = (ha - hah) * 60.; ham = (int)ha; has = (ha - ham) * 60.; decsign = 1; if (dec < 0.) { decsign = -1; dec = fabs(dec); } decd = (int)dec; dec = (dec - decd) * 60.; decm = (int)dec; decs = (dec - decm) * 60.; sprintf(buf,"%c%02d:%02d:%05.2f %c%02d:%02d:%04.1f HA/SLEW",(hasign<0?'-':' '),hah,ham,has,(decsign<0?'-':' '),decd,decm,decs); rc = tcs_com(buf,buf,sizeof(buf),"vtcshost"); return rc; } int set_tcsoffset(float offsetr, float offsetd) { int rc; /* get hostname to tcs */ /* P( sem_spl ); strxcpy( tcshostname, Spl->pr.tcshostname, sizeof(tcshostname)); V( sem_spl ); */ sprintf(buf,"1 %5.1f %5.1f 0 C.SCN",offsetr,offsetd); rc = tcs_com(buf,buf,sizeof(buf),"vtcshost"); return(rc); } int set_tcserror(float errorr, float errord) { int rc; /* get hostname to tcs */ /* P( sem_spl ); strxcpy( tcshostname, Spl->pr.tcshostname, sizeof(tcshostname)); V( sem_spl ); */ sprintf(buf,"1 %5.1f %5.1f 1 C.AUTOG",errorr,errord); rc = tcs_com(buf,buf,sizeof(buf),"vtcshost"); sprintf(buf,"1 0.0 0.0 -1 C.AUTOG"); rc = tcs_com(buf,buf,sizeof(buf),"vtcshost"); return(rc); } int get_tcsaltaz(double *altitude, double *azimuth) { int rc, iscan; double dome; if ((rc=tcs_com("?AZ/EL", buf, sizeof(buf), "vtcshost")) == ERR_NONE) { iscan = sscanf(buf,"Tele Azimuth =%lf Dome Azimuth =%lf Elevation =%lf",azimuth, &dome, altitude); } return rc; } int get_tcspos(double *pixra, double *pixdec) { int rh, rm, dsn, dd, dm; double rs, ds; char *token; int rc; /* get hostname to tcs */ /* P( sem_spl ); strxcpy( tcshostname, Spl->pr.tcshostname, sizeof(tcshostname)); V( sem_spl ); */ rc = tcs_com( "0 TPD", buf, sizeof(buf), "vtcshost"); if (rc == ERR_NONE) { /* RA */ token = strtok(buf,":"); rh = atoi(token); token = strtok(NULL,":"); rm = atoi(token); token = strtok(NULL," "); rs = atof(token); /* DEC */ token = strtok(NULL,":"); dd = abs(atoi(token)); if (strchr(token,'-') != NULL) dsn = -1; else dsn = 1; token = strtok(NULL,":"); dm = atoi(token); token = strtok(NULL," "); ds = atof(token); *pixra = M_PI*(rh+(rm+(rs/60.))/60.)/12.; *pixdec = M_PI*dsn*(dd+(dm+(ds/60.))/60.)/180.; } return (rc); } int get_tcsoffset(double *pixra, double *pixdec) { int rc; /* get hostname to tcs */ /* P( sem_spl ); strxcpy( tcshostname, Spl->pr.tcshostname, sizeof(tcshostname)); V( sem_spl ); */ rc = tcs_com( "?DISP", buf, sizeof(buf), "vtcshost"); if (rc == ERR_NONE) { sscanf(buf,"%lf %lf",pixra,pixdec); *pixra = M_PI*(*pixra)/648000.; *pixdec = M_PI*(*pixdec)/648000.; } return (rc); } /************************************************************************* Routines for tcs communications *************************************************************************/ /*---------------------------------------------------------------------------- ** tcs_com() - basic routine for communicating with TCS. **---------------------------------------------------------------------------- */ int tcs_com( char *command, char *reply, int reply_size, char *tcshostname ) { int connect_fd, rc; char msgbuf[SOCKET_MSG_LEN+1]; rc = ERR_NONE; if( (connect_fd = sock_open( tcshostname, TCS_MSG_PORT)) < 0) return ERR_SOCKET_ERR; else { /* Send command to socket */ rc = (sock_write_msg( connect_fd, command, TRUE) < 0) ? ERR_SOCKET_ERR : ERR_NONE; /* Get reply from socket */ if( rc == ERR_NONE ) rc = (sock_read_msg( connect_fd, msgbuf, TRUE) < 0 ) ? ERR_SOCKET_ERR : ERR_NONE; /* Close socket */ shutdown( connect_fd, 2 ); /* Close socket */ close( connect_fd ); /* Copy reply to caller */ if( rc == ERR_NONE ) strxcpy( reply, msgbuf, reply_size); } return rc; }