Exemplo n.º 1
0
int main(int argc, char **argv)
{
    FILE       *fp_raw_data, *fp_raw_data2;
    union 	ad_union amp_vvm[10], pha_vvm[10];
    union 	ad_union amp_vvm2[10], pha_vvm2[10];
    char	command[35],file_name[80],file_name2[80],*cfreq,c;
    int		j, k, l, ant_scn, ant_scn2, ref_ant, n_size, n_start, offsetunit=0;
    int antennas[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    long	i, i_delay, n_delay;
    int 	adc0_fd, adc1_fd, adc0_rd, adc1_rd, count;
    int 	adc2_fd, adc3_fd, adc2_rd, adc3_rd;
    int 	OFLAG;
    int		istatus,icount;
    int		amp_read[2000],phase_read[2000],truetime2ms[20000];
    int		amp_read2[2000],phase_read2[2000];
    int         ant;
    time_t      start_time,cur_time,Start_time,time1[2000],time2[2000],time3[2000],time4[2000];
    float       az_step, el_step, azoff, eloff, freq,az_bore,el_bore, az_bore2, el_bore2; 
    float       az_off,el_off, az_ref, el_ref;
    float       contDet_a1[2], contDet_a2[2], contDet_ar[2];
    float       contDet1_a1, contDet1_a2, contDet1_ar;
    double      az_enc,el_enc,az_enc2, el_enc2;
    double      az_read[2000],el_read[2000], az_read2[2000], el_read2[2000];
    int rm_status, antlist[RM_ARRAY_SIZE];/*variables for encoderClient*/
    short	currentAzoff, currentAzoff2;
    short	handshake;
    struct tm	ts;	
    double      currentAzoffD;
    unsigned short m1009,m1010;
    smapoptContext optCon;
    struct  smapoptOption optionsTable[] = {
	    {"help",'h',SMAPOPT_ARG_NONE,0,'h'},
	    {"primary antenna",'a',SMAPOPT_ARG_INT,&ant_scn,'a'}, 
	    {"secondary antenna",'d',SMAPOPT_ARG_INT,&ant_scn2,'d'}, 
/*	    {"antennas", 'a', SMAPOPT_ARG_ANTENNAS, &antennas[0], 0, "Specify a list of antennas to move"},*/
	    {"refant",'r',SMAPOPT_ARG_INT,&ref_ant,'r'},
	    {"frequency",'f',SMAPOPT_ARG_STRING,&cfreq,'f'},
	    {"map_size",'m',SMAPOPT_ARG_INT,&n_size,'m'},
	    {"scan_speed",'s',SMAPOPT_ARG_INT,&offsetunit,'s'},
	    {"line_start",'l',SMAPOPT_ARG_INT,&n_start,'l'},
	    {NULL,0,0,NULL,0}
    };
/*     ant_scn=0;
     ant_scn2=0;
     for (ant = 0; ant < N_ANTENNAS; ant++){
	printf ("antennas[ant] %d\n", antennas[ant]);
     }
     for (ant = 0; ant < N_ANTENNAS; ant++){
        if (antennas[ant]){
          printf("%d ", ant);
        if (ant_scn == 0){
        ant_scn = ant;
	}
	else {
	ant_scn2 = ant;
	}
	}
	}
*/
	printf ("antennas: %d %d \n", ant_scn, ant_scn2);

/**********get command line arguments and initializations**************/

	count=2; /* set how many counts we read from A/D board device */
	n_start=0; /* start from the beginning as default setting */

	if(argc<7) usage(-1,"Insufficient number of arguments","");
	optCon = smapoptGetContext("holon", argc, argv, optionsTable,0);

	while ((c = smapoptGetNextOpt(optCon)) >= 0) {
	switch(c) {
		case 'h':
		usage(0,NULL,NULL);
		break;
	}
	}
	if(c<-1) {
	fprintf(stderr, "%s: %s\n",
		smapoptBadOption(optCon, SMAPOPT_BADOPTION_NOALIAS),
		smapoptStrerror(c));
	}

	if(ant_scn<1||ant_scn>8)
	{
	printf("ant should be 1-8\n");
	exit(0);
	}

	if(ref_ant<1||ref_ant>8)
	{
	printf("reference ant should be 1-8\n");
	exit(0);
	}

	freq=atof(cfreq);
	if(freq<50.0||freq>700.0)
	{
	printf("200 < freq < 700\n");
	exit(0);
	}

	if(n_size<n_start)
	{
	printf("n_start is larger than n_size.\n");
	exit(0);
	}

	if(offsetunit<1)
	{
	printf("scan_speed should be larger than 1.\n");
	exit(0);
	}

	if(freq < 500.0) n_delay=(long) 8e7/offsetunit;
	else n_delay=(long) 4e7/offsetunit;
	az_step=7734.0/freq;el_step=az_step; /*23.3 for 332 GHz, and 33.3 for 232.4 GHz*/
printf("ant_scn=%d ref_ant=%d freq=%f size=%d scanspeed=%d n_delay=%ld step=%f\n",ant_scn,ref_ant,freq,n_size,offsetunit,n_delay,az_step);
/* Dual */
printf("ant_scn=%d ref_ant=%d freq=%f size=%d scanspeed=%d n_delay=%ld step=%f\n",ant_scn2,ref_ant,freq,n_size,offsetunit,n_delay,az_step);
	azoff=0.; eloff=0.;
    	start_time = time(NULL);
	ts = *localtime(&start_time);
	sprintf(file_name, "/data/engineering/holo/ant%1d/%02d%02d_%02d%02d.holo%1d",ant_scn,ts.tm_mon+1,ts.tm_mday,ts.tm_hour,ts.tm_min,ant_scn);
	printf("freq=%4.1fGHz grid=%4.1f:%4.1f filename %s\n",freq,az_step,el_step,file_name);
/* Dual */
	sprintf(file_name2, "/data/engineering/holo/ant%1d/%02d%02d_%02d%02d.holo%1d",ant_scn2,ts.tm_mon+1,ts.tm_mday,ts.tm_hour,ts.tm_min,ant_scn2);
	printf("freq=%4.1fGHz grid=%4.1f:%4.1f filename %s\n",freq,az_step,el_step,file_name2);

	if(ant_scn==1){
		if(freq < 500.0){
			az_bore=AZ_BORE1;
			el_bore=EL_BORE1;
		}
		else{
			az_bore=AZ_BORE1H;
			el_bore=EL_BORE1H;
		}
	}

	if(ant_scn==2){
		if(freq < 500.0){
			az_bore=AZ_BORE2;
			el_bore=EL_BORE2;
		}
		else{
			az_bore=AZ_BORE2H;
			el_bore=EL_BORE2H;
		}
	}
	else if(ant_scn==3){
		if(freq < 500.0){
			az_bore=AZ_BORE3;
			el_bore=EL_BORE3;
		}
		else{
			az_bore=AZ_BORE3H;
			el_bore=EL_BORE3H;
		}
	}
	else if(ant_scn==4){
		if(freq < 500.0){
			az_bore=AZ_BORE4;
			el_bore=EL_BORE4;
		}
		else{
			az_bore=AZ_BORE4H;
			el_bore=EL_BORE4H;
		}
	}
	else if(ant_scn==5){
		if(freq < 500.0){
			az_bore=AZ_BORE5;
			el_bore=EL_BORE5;
		}
		else{
			az_bore=AZ_BORE5H;
			el_bore=EL_BORE5H;
		}
	}
	else if(ant_scn==6){
		if(freq < 500.0){
			az_bore=AZ_BORE6;
			el_bore=EL_BORE6;
		}
		else{
			az_bore=AZ_BORE6H;
			el_bore=EL_BORE6H;
		}
	}
	else if(ant_scn==7){
		if(freq < 500.0){
			az_bore=AZ_BORE7;
			el_bore=EL_BORE7;
		}
		else{
			az_bore=AZ_BORE7H;
			el_bore=EL_BORE7H;
		}
	}
	else if(ant_scn==8){
		if(freq < 500.0){
			az_bore=AZ_BORE8;
			el_bore=EL_BORE8;
		}
		else{
			az_bore=AZ_BORE8H;
			el_bore=EL_BORE8H;
		}
	}
	else if(ant_scn==0){ /* for debug */
		az_bore=AZ_BORE0;
		el_bore=EL_BORE0;
		ant_scn=4;
	}
/* Dual */
	if(ant_scn2==1){
		if(freq < 500.0){
			az_bore2=AZ_BORE1;
			el_bore2=EL_BORE1;
		}
		else{
			az_bore2=AZ_BORE1H;
			el_bore2=EL_BORE1H;
		}
	}

	if(ant_scn2==2){
		if(freq < 500.0){
			az_bore2=AZ_BORE2;
			el_bore2=EL_BORE2;
		}
		else{
			az_bore2=AZ_BORE2H;
			el_bore2=EL_BORE2H;
		}
	}
	else if(ant_scn2==3){
		if(freq < 500.0){
			az_bore2=AZ_BORE3;
			el_bore2=EL_BORE3;
		}
		else{
			az_bore2=AZ_BORE3H;
			el_bore2=EL_BORE3H;
		}
	}
	else if(ant_scn2==4){
		if(freq < 500.0){
			az_bore2=AZ_BORE4;
			el_bore2=EL_BORE4;
		}
		else{
			az_bore2=AZ_BORE4H;
			el_bore2=EL_BORE4H;
		}
	}
	else if(ant_scn2==5){
		if(freq < 500.0){
			az_bore2=AZ_BORE5;
			el_bore2=EL_BORE5;
		}
		else{
			az_bore2=AZ_BORE5H;
			el_bore2=EL_BORE5H;
		}
	}
	else if(ant_scn2==6){
		if(freq < 500.0){
			az_bore2=AZ_BORE6;
			el_bore2=EL_BORE6;
		}
		else{
			az_bore2=AZ_BORE6H;
			el_bore2=EL_BORE6H;
		}
	}
	else if(ant_scn2==7){
		if(freq < 500.0){
			az_bore2=AZ_BORE7;
			el_bore2=EL_BORE7;
		}
		else{
			az_bore2=AZ_BORE7H;
			el_bore2=EL_BORE7H;
		}
	}
	else if(ant_scn2==8){
		if(freq < 500.0){
			az_bore2=AZ_BORE8;
			el_bore2=EL_BORE8;
		}
		else{
			az_bore2=AZ_BORE8H;
			el_bore2=EL_BORE8H;
		}
	}
	else if(ant_scn2==0){ /* for debug */
		az_bore2=AZ_BORE0;
		el_bore2=EL_BORE0;
		ant_scn2=2;
	}
/* Dual End */

	if(ref_ant==1){
		if(freq < 500.0){
			az_ref=AZ_BORE1;
			el_ref=EL_BORE1;
		}
		else{
			az_ref=AZ_BORE1H;
			el_ref=EL_BORE1H;
		}
	}

	if(ref_ant==2){
		if(freq < 500.0){
			az_ref=AZ_BORE2;
			el_ref=EL_BORE2;
		}
		else{
			az_ref=AZ_BORE2H;
			el_ref=EL_BORE2H;
		}
	}
	else if(ref_ant==3){
		if(freq < 500.0){
			az_ref=AZ_BORE3;
			el_ref=EL_BORE3;
		}
		else{
			az_ref=AZ_BORE3H;
			el_ref=EL_BORE3H;
		}
	}
	else if(ref_ant==4){
		if(freq < 500.0){
			az_ref=AZ_BORE4;
			el_ref=EL_BORE4;
		}
		else{
			az_ref=AZ_BORE4H;
			el_ref=EL_BORE4H;
		}
	}
	else if(ref_ant==5){
		if(freq < 500.0){
			az_ref=AZ_BORE5;
			el_ref=EL_BORE5;
		}
		else{
			az_ref=AZ_BORE5H;
			el_ref=EL_BORE5H;
		}
	}
	else if(ref_ant==6){
		if(freq < 500.0){
			az_ref=AZ_BORE6;
			el_ref=EL_BORE6;
		}
		else{
			az_ref=AZ_BORE6H;
			el_ref=EL_BORE6H;
		}
	}
	else if(ref_ant==7){
		if(freq < 500.0){
			az_ref=AZ_BORE7;
			el_ref=EL_BORE7;
		}
		else{
			az_ref=AZ_BORE7H;
			el_ref=EL_BORE7H;
		}
	}
	else if(ref_ant==8){
		if(freq < 500.0){
			az_ref=AZ_BORE8;
			el_ref=EL_BORE8;
		}
		else{
			az_ref=AZ_BORE8H;
			el_ref=EL_BORE8H;
		}
	}
	else if(ref_ant==0){ /* for debug */
		az_ref=AZ_BORE0;
		el_ref=EL_BORE0;
		ref_ant=5;
	}

	fp_raw_data = fopen(file_name,"w");
	if(fp_raw_data==NULL){
		printf("cannot open the data file\n");
		exit(1);
	}
/* Dual */
	fp_raw_data2 = fopen(file_name2,"w");
	if(fp_raw_data2==NULL){
		printf("cannot open the data file 2\n");
		exit(1);
	}
/* End Dual */

/* initializing ref. mem. */
	rm_status=rm_open(antlist);
	if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_open()");
		exit(1);
	}

/* configure for interrupt through RM */
 	rm_status=rm_monitor(ant_scn,"RM_HOLO_ENC_HNDSHK_S");
	if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_monitor()");
		exit(1);
	}
/* Dual */
 	rm_status=rm_monitor(ant_scn2,"RM_HOLO_ENC_HNDSHK_S");
	if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_monitor()");
		exit(1);
	}
/* */
	printf("checking the encoderServer status\n");

	handshake = 0;

	rm_status=rm_write_notify(ant_scn,"RM_HOLO_ENC_HNDSHK_S",&handshake);
		if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_write_notify()");
		exit(1);
		} 

	sleep(1);

	rm_status=rm_read(ant_scn,"RM_HOLO_ENC_HNDSHK_S",&handshake);
		if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_read()");
		exit(1);
		}  

/*	if (handshake==0) 
	{
	printf("encoder Server is not running on acc%1d!\n",ant_scn);
	exit(-1);
	}
*/

/* Dual */
/* Should check encoderServer for ant_scn2 here */

/* open Device tables */
	OFLAG=O_RDWR|O_NDELAY;
	adc0_fd = open("/dev/xVME564-0", OFLAG, 0); 
	if(adc0_fd<0){printf("cannot open device 0\n");exit(1);}
	adc1_fd = open("/dev/xVME564-1", OFLAG, 0); 
	if(adc1_fd<0){printf("cannot open device 1\n");exit(1);}
/* Dual */
	adc2_fd = open("/dev/xVME564-2", OFLAG, 0); 
	if(adc2_fd<0){printf("cannot open device 0\n");exit(1);}
	adc3_fd = open("/dev/xVME564-3", OFLAG, 0);
	if(adc3_fd<0){printf("cannot open device 1\n");exit(1);}
/* */
/*********************Get the antenna ready for*************************/
/* go to starting position  */
/* numbers for ant6 frozen in for now 30 Jul 2002 
	printf("frozen az_bore & el_bore for ant6\n");
	az_bore=48.25;
	el_bore=18.60; */
	printf ("Going to bore-sight position \n");
	sprintf(command, "azoff -a %d -s 0", ant_scn);
	system (command);
	sprintf(command, "eloff -a %d -s 0", ant_scn);
	system (command);
	sprintf(command, "azel -a %d -z %f -e %f", ref_ant, az_ref, el_ref);
	printf ("command: %s \n", command);
	system (command);
	sprintf(command, "azel -a %d -z %f -e %f", ant_scn, az_bore, el_bore);
	printf ("command: %s \n", command);
	system (command);
	sleep(1);
	sprintf(command, "offsetUnit -a %d -s %d", ant_scn, -offsetunit); 
	printf ("command: %s \n", command);
	system (command);
	sleep(1);
	sprintf(command, "resume -a %d", ant_scn); 
	system (command);

/* Dual */
	printf ("Going to bore-sight position \n");
	sprintf(command, "azoff -a %d -s 0", ant_scn2);
	system (command);
	sprintf(command, "eloff -a %d -s 0", ant_scn2);
	system (command);
	sprintf(command, "azel -a %d -z %f -e %f", ref_ant, az_ref, el_ref);
	printf ("command: %s \n", command);
	system (command);
	sprintf(command, "azel -a %d -z %f -e %f", ant_scn2, az_bore2, el_bore2);
	printf ("command: %s \n", command);
	system (command);
	sleep(1);
	sprintf(command, "offsetUnit -a %d -s %d", ant_scn2, -offsetunit); 
	printf ("command: %s \n", command);
	system (command);
	sleep(1);
	sprintf(command, "resume -a %d", ant_scn2); 
	system (command);
/* */
/*	printf ("Make sure encoderServer is running on acc%1d.\n",ant_scn); */
/* Dual */
	printf ("Make sure encoderServer is running on acc%1d and acc%1d\n",ant_scn,ant_scn2);
	printf ("Hit Return to continue:");
	fgetc(stdin);
	printf ("Starting raster on antennas %d and %d\n", ant_scn, ant_scn2);
	azoff=((float)n_size/2.+1.)*az_step;
	eloff=((float)n_size/2.)*el_step - n_start*el_step;
/*	sprintf(command, "azoff -a %d -s %f", ant_scn, azoff+offsetunit*3); */
/* Dual */
	sprintf(command, "azoff -a %d,%d -s %f", ant_scn, ant_scn2,azoff+offsetunit*3); 
/* */
	printf ("command: %s ", command);
	system (command);
	sleep(1);
/*	sprintf(command, "eloff -a %d -s %f", ant_scn, eloff);  */
/* Dual */
	sprintf(command, "eloff -a %d,%d -s %f", ant_scn, ant_scn2, eloff); 
/* */
	printf ("%s \n", command);
	system (command);
	sleep(5);

	
	/* The following is from Bob's ttsubs.c main */
        ttime.timeout_ticks = 2;        /* This margin should be safe */
        ttfd = open("/dev/vme_sg_simple", O_RDWR, 0);
        if(ttfd <= 0) {
            fprintf(stderr, "Error opening TrueTime - /dev/vme_sg_simple\n");
            exit(SYSERR_RTN);
        }


/*********************Start taking data*************************/
	printf ("Start raster! \n");
    	start_time = time(NULL);
	Start_time = start_time;

/* Elevation Loop */
	for (j=n_start; j<n_size; j++){  /*do one row*/ 
		sprintf(command, "azel -a %d -z %f -e %f", ref_ant, az_ref, el_ref);
		printf ("%s \n", command);
		system (command);
		i=0; 
	currentAzoff=0;
    		start_time = time(NULL);
/*		sprintf(command, "azscan -a %d", ant_scn);*/
/* Dual */
		sprintf(command, "azscan -a %d,%d", ant_scn, ant_scn2);
/* */
		printf ("%s \n", command);
		sleep(1);
		istatus=system (command);

		printf("%6d %6d  %6f\n",istatus,currentAzoff,azoff);
		printf("%6d  %6f \n",currentAzoff,azoff); fflush(stdout);
/*		while((1.0*currentAzoff)>-azoff){ */
/*		while((1.0*currentAzoff)>(-(azoff+offsetunit))){ */
/* Dual */
		while(((1.0*currentAzoff)>(-(azoff+offsetunit)))||((1.0*currentAzoff2)>(-(azoff+offsetunit)))){
/* */

/*			 for (i_delay=1; i_delay<n_delay; i_delay++){} */ /*  delay using GetPosTime() from ttsubs.c- using interrupts from TrueTime */
                        cur_time=time(NULL);
                        time1[i]=cur_time-Start_time;

			GetPosTime();
/*
            printf("Day %d, msec %d\n", day, msec);
*/
			truetime2ms[i]=msec;
                        cur_time=time(NULL);
                        time2[i]=cur_time-Start_time;
			adc0_rd=read(adc0_fd, amp_vvm[1].byte, count);
			if(adc0_rd<=0){
				printf("cannot read device 0\n");
				exit(1);
				close(adc0_fd);
				close(adc1_fd);
			} 
/* Read total power values 10 May 2010 */
			rm_status=rm_read(ant_scn,"RM_CONT_DET_MUWATT_V2_F",&contDet_a1);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
       			}/*if end*/
			rm_status=rm_read(ant_scn2,"RM_CONT_DET_MUWATT_V2_F",&contDet_a2);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
       			}/*if end*/
			rm_status=rm_read(ref_ant,"RM_CONT_DET_MUWATT_V2_F",&contDet_ar);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
       			}/*if end*/
 /* usleep(1); */
			adc1_rd=read(adc1_fd, pha_vvm[1].byte, count);
			if(adc1_rd<=0){
				printf("cannot read device 1\n");
				exit(1);
				close(adc0_fd);
				close(adc1_fd);
			}
/* Dual */
			adc2_rd=read(adc2_fd, amp_vvm2[1].byte, count);
			if(adc2_rd<=0){
				printf("cannot read device 2\n");
				exit(1);
				close(adc2_fd);
				close(adc3_fd);
			} 
 /* usleep(1); */
			adc3_rd=read(adc3_fd, pha_vvm2[1].byte, count);
			if(adc3_rd<=0){
				printf("cannot read device 3\n");
				exit(1);
				close(adc2_fd);
				close(adc3_fd);
			}
/* End Dual */
                        cur_time=time(NULL);
                        time3[i]=cur_time-Start_time;
/* read encoders using encoderClient */
			encoderClient(ant_scn,&az_enc,&el_enc,&m1009,&m1010); 
/*		        printf("First read done\n %f %f %f\n", az_enc, el_enc, currentAzoffD); */
/* Dual */
			encoderClient(ant_scn2,&az_enc2,&el_enc2,&m1009,&m1010); 
/*		        printf("Second read done\n %f %f %f\n", az_enc2, el_enc2, currentAzoffD); */
/* */
                        cur_time=time(NULL);
                        time4[i]=cur_time-Start_time;

			az_read[i]=az_enc;el_read[i]=el_enc;
			amp_read[i]=amp_vvm[1].word;
			phase_read[i]=pha_vvm[1].word;
/* Dual */
			az_read2[i]=az_enc2;el_read2[i]=el_enc2;
			amp_read2[i]=amp_vvm2[1].word;
			phase_read2[i]=pha_vvm2[1].word;
/* End Dual */
/* adding time stamping of samples: 01 Nov 04 */

			rm_status=rm_read(ant_scn,"RM_AZOFF_D",&currentAzoffD);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
       			}/*if end*/
			currentAzoff=(short)currentAzoffD;
/* Dual */
			rm_status=rm_read(ant_scn2,"RM_AZOFF_D",&currentAzoffD);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
       			}/*if end*/
			currentAzoff2=(short)currentAzoffD;
/* End Dual */
/* printf("line# %3d %3d %4d %6.2f %6.2f %6.2f %5d %d\n",j,i,currentAzoff,azoff,az_enc,el_enc,amp_read[i],icount); fflush(stdout); */

			i++;
		}/*while end*/

/*		sprintf(command, "stopScan -a %d", ant_scn); */
/* Dual */
		sprintf(command, "stopScan -a %d,%d", ant_scn, ant_scn2);
/* */
	      	system (command);
		sleep(1); 
		printf ("command: %s \n", command); 
	/*	system (command);
		usleep(10); */
		eloff = eloff - el_step;
/*		sprintf(command, "eloff -a %d -s %f", ant_scn, eloff); */
/* Dual */
		sprintf(command, "eloff -a %d,%d -s %f", ant_scn, ant_scn2, eloff); 
/* */
		system (command);
		sleep(1);
		printf ("command: %s ", command);fflush(stdout);
	/*	system (command);
		usleep(10); */
/*		sprintf(command, "azoff -a %d -s %f", ant_scn, azoff+offsetunit*3); */
/* Dual */
		sprintf(command, "azoff -a %d,%d -s %f", ant_scn, ant_scn2, azoff+offsetunit*3); 
/* */
		system (command);
		sleep(1);
		printf ("command: %s ", command);fflush(stdout);
	/*	system (command); */
/* write out also the total powers 10 May 2010 */
		for(k=1;k<i;k++){
			fprintf(fp_raw_data,"%10.6f %10.6f %6d %6d %6.4f %3d %d %d %d %d %d\n" ,\
			el_read[k],az_read[k],amp_read[k],phase_read[k],contDet_a1[0],j,time1[k],time2[k],time3[k],time4[k],truetime2ms[k]);
			fflush(fp_raw_data);
    		}/*for end*/
/* Dual */
		for(k=1;k<i;k++){
			fprintf(fp_raw_data2,"%10.6f %10.6f %6d %6d %6.4f %3d %d %d %d %d %d\n" ,\
			el_read2[k],az_read2[k],amp_read2[k],phase_read2[k],contDet_a2[0],j,time1[k],time2[k],time3[k],time4[k],truetime2ms[k]);
			fflush(fp_raw_data2);
    		}/*for end*/
/* End Dual */
		/* Place for including online dispaly command */
		printf ("Flush the data\n"); 
    		cur_time=time(NULL);
    		printf ("%3dth line: Stop time: %d time taken: %d secs samples: %d\n", \
		j, cur_time, cur_time-start_time, i);
		sleep(4);
/*		sprintf(command, "azoff -a %d -s %f", ant_scn, azoff);
		printf ("command: %s ", command);fflush(stdout);
		system (command);
		usleep(10);
		sprintf(command, "eloff -a %d -s %f", ant_scn, eloff);
		printf ("command: %s ", command);fflush(stdout);
		system (command);
		usleep(10);*/
    	} 
/* for end; El loop done */

	printf ("Start: %d Stop: %d Time taken: %d secs\n", Start_time, cur_time, cur_time - Start_time);
/*	sprintf(command, "azoff -a %d -s 0", ant_scn); */
/* Dual */
	sprintf(command, "azoff -a %d,%d -s 0", ant_scn,ant_scn2); 
/* */
	system (command);
	sleep(10);
	printf ("command: %s ", command);
/*	sprintf(command, "eloff -a %d -s 0", ant_scn); */
/* Dual */
	sprintf(command, "eloff -a %d,%d -s 0", ant_scn,ant_scn2);
/* */
	system (command);
	sleep(10);
	printf ("command: %s\n", command);

/*********************clear up everything*************************/
	fclose(fp_raw_data);
	close(adc0_fd);
	close(adc1_fd);
/* Dual */
	fclose(fp_raw_data2);
	close(adc2_fd);
	close(adc3_fd);
/* End Dual */
/* release the RM interrupt waiting */
	rm_status=rm_clear_monitor();
	if(rm_status != RM_SUCCESS) {
	rm_error_message(rm_status,"rm_clear()");
	}
	printf ("DONE!\n");
	exit(0);
}				/* end main */
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	float Azoff_avg,Eloff_avg,Az_avg,El_avg,Azerr_avg,Elerr_avg,Azmod_avg,Elmod_avg,Data_avg;
	float xx[20000],yy[20000],zz[20000],azyy[20000],elyy[20000],azp[20000],elp[20000],xx2[20000],yy2[20000];
	int i,j,iavg;
	char c,*t,*s,*curtim,file_n1[50],source[40];
	time_t new_time,old_time,cur_time;
	FILE *fp;
	int rm_status, antlist[RM_ARRAY_SIZE];/*variables for encoderClient*/
	float az_deg,el_deg,az_err,el_err,az_mod,el_mod,chop_angle,chop_x,chop_y,chop_z;
	double output, az_off, el_off;
	smapoptContext optCon;
	struct  smapoptOption optionsTable[] = {
		{"help",'h',SMAPOPT_ARG_NONE,0,'h'},
		{"antennas",'a',SMAPOPT_ARG_INT,&ant_num,'a'},
		{"print",'p',SMAPOPT_ARG_NONE,0,'p'},
		{NULL,0,0,NULL,0}
	};

	if(argc<2) usage(-1,"Insufficient number of arguments","");
	optCon = smapoptGetContext("chartu", argc, argv, optionsTable,0);

	while ((c = smapoptGetNextOpt(optCon)) >= 0) {
	switch(c) {
		case 'h':
		usage(0,NULL,NULL);
		break;

		case 'p':
		flag=1;
		break;
	}
	}

	if((ant_num < 1) || (ant_num > 8)){
		printf("ant %d? ant 1-8\n",ant_num);
		exit(1);
	}

	/* initializing ref. mem. */
	rm_status=rm_open(antlist);
	if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_open()");
		exit(1);
	}

	chart_stat.saveflg=0;
	chart_stat.scanflg=1; /* Az scan */
	chart_stat.chopflg=0;
	chart_stat.integtime=1;
	chart_stat.quitflg=0;

	if(-1==pthread_create(&write_statusTID, NULL , write_status, (void *) &ant_num)){
		perror("main: pthread_create CommandHandler");
		exit(-1);	
	}
	pthread_detach(write_statusTID);
	sleep(1);


	while(0==chart_stat.quitflg){
 
		if(-1==pthread_create(&read_statusTID, NULL , read_status, (void *) &ant_num)){
		perror("main: pthread_create CommandHandler");
		exit(-1);	
		}
		pthread_detach(read_statusTID);

		i=0;
		while(chart_stat.saveflg==1){
			Az_avg=0;El_avg=0;Azerr_avg=0;Elerr_avg=0;iavg=1;
			Azoff_avg=0;Eloff_avg=0;Azmod_avg;Elmod_avg=0;
			old_time=time(NULL);new_time=time(NULL);
			while((new_time-old_time)<chart_stat.integtime){
				rm_status=rm_read(ant_num,"RM_ACTUAL_AZ_DEG_F",&az_deg);
		   		if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
		   		exit(1);
				}
		   		rm_status=rm_read(ant_num,"RM_ACTUAL_EL_DEG_F",&el_deg);
				if(rm_status != RM_SUCCESS) {
		   		rm_error_message(rm_status,"rm_read()");
				exit(1);
		   		}
				rm_status=rm_read(ant_num,"RM_AZ_TRACKING_ERROR_F",&az_err);
	   			if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
	   			exit(1);
				}
		   		rm_status=rm_read(ant_num,"RM_EL_TRACKING_ERROR_F",&el_err);
				if(rm_status != RM_SUCCESS) {
		   		rm_error_message(rm_status,"rm_read()");
				exit(1);
	   			}
				rm_status=rm_read(ant_num,"RM_PMDAZ_F",&az_mod);
	   			if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
				exit(1);
				}
				rm_status=rm_read(ant_num,"RM_PMDEL_F",&el_mod);
				if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
				exit(1);
				}
				rm_status=rm_read(ant_num,"RM_CHART_AZOFF_ARCSEC_D",&az_off);
				if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
				exit(1);
				}
				rm_status=rm_read(ant_num,"RM_CHART_ELOFF_ARCSEC_D",&el_off);
				if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
				exit(1);
				}
				if(chart_stat.chopflg) rm_status=rm_read(ant_num,"RM_SYNCDET_VOLTS_D",&output);
				else rm_status=rm_read(ant_num,"RM_CHART_TOTAL_POWER_VOLTS_D",&output);
				if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
				exit(1);
				}
				Az_avg=((iavg-1)*Az_avg+az_deg)/iavg;
				El_avg=((iavg-1)*El_avg+el_deg)/iavg;
				Azoff_avg=((iavg-1)*Azoff_avg+az_off)/iavg;
				Eloff_avg=((iavg-1)*Eloff_avg+el_off)/iavg;
				Azerr_avg=((iavg-1)*Azerr_avg+az_err)/iavg;
				Elerr_avg=((iavg-1)*Elerr_avg+el_err)/iavg;
				Azmod_avg=((iavg-1)*Azmod_avg+az_mod)/iavg;
				Elmod_avg=((iavg-1)*Elmod_avg+el_mod)/iavg;
				Data_avg=((iavg-1)*Data_avg+output)/iavg;
				rm_status=rm_read(ant_num,"RM_SOURCE_C34",&source);
				if(rm_status != RM_SUCCESS) {
				rm_error_message(rm_status,"rm_read()");
				exit(1);
				}
				usleep(10000);
				iavg++;
				new_time=time(NULL);
			}
/*			printf("Ant%1d %s %3d Aoff %4.1f Eoff %4.1f Aerr%4.1f Eerr%4.1f Azmod%4.1f Elmod%4.1f Data%7.4f\n",ant_num,source,iavg,Azoff_avg,Eloff_avg,Azerr_avg,Elerr_avg,Azmod_avg,Elmod_avg,Data_avg);*/

			/* store data for fitting */
			azyy[i]=Az_avg;
			elyy[i]=El_avg;
			xx[i]=Azoff_avg;
			xx2[i]=Eloff_avg;
			zz[i]=Data_avg;
			yy[i]=Azerr_avg;
			yy2[i]=Elerr_avg;
			azp[i]=Azmod_avg;
			elp[i]=Elmod_avg;
			i++;

		if(-1==pthread_create(&read_statusTID, NULL , read_status, (void *) &ant_num)){
		perror("main: pthread_create CommandHandler");
		exit(-1);	
		}
		pthread_detach(read_statusTID);
		} /* end while save flag is on */

		if(i){	/*if there are data*/
			sprintf(file_n1,"/common/data/rpoint/ant%1d/tmp.dat",ant_num);
/*			printf("filename=%s\n",file_n1);*/
			if ((fp=fopen(file_n1,"w"))==NULL){
				printf("cannot open data file\n");
				exit(1);
			}

			rm_status=rm_read(ant_num,"RM_CHOPPER_ANGLE_F",&chop_angle);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
			}
			rm_status=rm_read(ant_num,"RM_CHOPPER_X_MM_F",&chop_x);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
			}
			rm_status=rm_read(ant_num,"RM_CHOPPER_Y_MM_F",&chop_y);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
			}
			rm_status=rm_read(ant_num,"RM_CHOPPER_Z_MM_F",&chop_z);
			if(rm_status != RM_SUCCESS) {
			rm_error_message(rm_status,"rm_read()");
			exit(1);
			}
	
			t=ctime(&new_time);
			fprintf(fp,"#%s#%s scnflg %1d chpflg %1d itgtime %1d %5.3f %5.3f %5.3f %5.3f\n",t, source,chart_stat.scanflg,chart_stat.chopflg,chart_stat.integtime,chop_angle,chop_x,chop_y,chop_z);
			for(j=0;j<i-1;j++){
				fprintf(fp,"%10.5f %10.5f %7.2f %7.2f %7.4f %7.4f %7.2f %7.2f %7.2f\n",azyy[j],elyy[j],xx[j],xx2[j],zz[j],yy[j],yy2[j],azp[j],elp[j]);
			}
			fclose(fp);
		}

		cur_time=time(NULL);
		curtim=ctime(&cur_time);
/*		printf("type 'chartuCommand -a %1d -q' to quit %s",ant_num,curtim);*/
		sleep(1);
	} /* end while */

	printf("\n");

	/* close ref. mem. */
	rm_status=rm_close(); 
	if(rm_status != RM_SUCCESS) {
		rm_error_message(rm_status,"rm_close()");
		exit(1);
	}
}
int main(int argc, char *argv[])  {

	char c,command_n[30];

	short pmac_command_flag=0;
	int dsm_status;
	smapoptContext optCon;
	int i ;

        int trackStatus=0;
        int tracktimestamp,timestamp;
	time_t dsmtimestamp;

	 struct  smapoptOption optionsTable[] = {
                {"help",'h',SMAPOPT_ARG_NONE,0,'h'},
                {NULL,0,0,NULL,0}
        };


        optCon = smapoptGetContext("stop", argc, argv, optionsTable,0);
 
        while ((c = smapoptGetNextOpt(optCon)) >= 0) {
 
            switch(c) {
                    case 'h':
                    usage(0,NULL,NULL);
                    break;
            }
        }


	for(i=0;i<30;i++) {
        command_n[i]=0x0;
        };
	command_n[0]='@'; /* send the command */
        pmac_command_flag=0;

 
        if(c<-1) {
        fprintf(stderr, "%s: %s\n",
                smapoptBadOption(optCon, SMAPOPT_BADOPTION_NOALIAS),
                smapoptStrerror(c));
        }
         smapoptFreeContext(optCon);
 
              /* initializing DSM */
        dsm_status=dsm_open();
        if(dsm_status != DSM_SUCCESS) {
                dsm_error_message(dsm_status,"dsm_open()");
                exit(1);
        }


#if 0
          /* check if track is running on this antenna */

        dsm_status=dsm_read(DSM_HOST,"DSM_UNIX_TIME_L",&timestamp,&dsmtimestamp);
	dsm_status=dsm_read(DSM_HOST,"DSM_TRACK_TIMESTAMP_L",&tracktimestamp,&dsmtimestamp);
        if(abs(tracktimestamp-timestamp)>3L) {
        trackStatus=0;
        printf("Track is not running.\n");
        }
        if(abs(tracktimestamp-timestamp)<=3L) trackStatus=1;

        if(trackStatus==1) {
        dsm_status=dsm_write(DSM_HOST,"DSM_COMMANDED_TRACK_COMMAND_C30",
                                        &command_n);
        if(dsm_status != DSM_SUCCESS) {
                dsm_error_message(dsm_status,"dsm_write()");
                exit(1);
        }
#endif
 
        dsm_status=dsm_write(DSM_HOST,"DSM_COMMANDED_TRACK_COMMAND_C30",
                                        &command_n);
        if(dsm_status != DSM_SUCCESS) {
                dsm_error_message(dsm_status,"dsm_write()");
                exit(1);
        }
 
/* the following dsm_write should actually be dsm_write_notify- but due 
to a bug in gltTrack, dsm_write_notify does not work */
     dsm_status=dsm_write(DSM_HOST,"DSM_COMMAND_FLAG_S",
                                        &pmac_command_flag);
 
     if(dsm_status != DSM_SUCCESS) {
                dsm_error_message(dsm_status,"dsm_write()");
                exit(1);
        }
 
#if 0
 
	} /* if track is running */
#endif

	return 0;
 
}