⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libipvlbi_board.h

📁 实现ipvlbi数据记录
💻 H
📖 第 1 页 / 共 4 页
字号:
/**************************************************************//*                                                            *//*   俬俹亅倁俴俛俬梡僀儞僋儖乕僪     libipvlbi_board.h       *//*          僒儞僾儔乕儃乕僪娭學                              *//*                                                            *//*      Version:    2002-10-08                                *//*      Version:    2002-10-21                                *//*                                                            *//*      Copyright (c) 2002 T.Kondo/CRL All Right Reserved     *//*                                                            *//**************************************************************//*                                   *//* 俬俹亅倁俴俛俬梡僿僢僟乕僼傽僀儖  *//*    僒儞僾儔乕儃乕僪 娭學          *//*         by T.Kondo 2001.8.26      *//*                    2002.5.26      *//*                    2002.10.21 sampleget傪2Gbytes埲忋偺娤應傪埖偊傞傛偆偵夵廋      *//*                                   */#ifndef _LIBIPVLBI_BOARD_#define _LIBIPVLBI_BOARD_#ifndef FILEMAXSIZE#define FILEMAXSIZE  2000000000   //  File maximum limit size in bytes#endifint ini_sampler(int *fd_in,int sfreq, int adbit, int numch, long int *bitsec);int start_sampler(int *fd_in);int stop_sampler(int *fd_in);int ini_and_start_sampler(int *fd_in,int sfreq, int adbit, int numch, long int *bitsec);int sampleget(char* outfile, int span, int sfreq, int adbit, int numch);int sampleget2(char* outfile, int span, int sfreq, int adbit, int numch, char* dirtemp, int mode);int ip_board_time(unsigned int *day, unsigned int *sec, int *hh, int *mm, int *ss);/* 僒儞僾儔乕儃乕僪弶婜壔 */int ini_sampler(int *fd_in,int sfreq, int adbit, int numch, long int *bitsec){	char dev[] = "/dev/tds0";	//int fd_in;	int rv;	int headbit=64;  // header bit number  for a new sampler board	//int headbit=32;  // header bit number  for a old sampler board	long int allbyte;     // 僒儞僾儕儞僌憤僶僀僩悢	//long int bitsec;       // 侾昩偁偨傝偺價僢僩悢丂乮僿僢僟乕俇係價僢僩傪娷傓乯	long int bytesec;       // 侾昩偁偨傝偺僶僀僩悢丂乮僿僢僟乕俇係價僢僩傪娷傓乯	unsigned int sampling1, freq, width;	int ch;	u_int8_t sfreq_t, sbit_t, numch_t, sampling;	//u_int32_t buf[BUFSIZ * 2];	//printf("BUFSIZ   %d\n",BUFSIZ);   // BUFSIZ偼1024偱偟偨両/*	printf(" span = %d\n",span);    // debug       printf(" sfreq= %d\n",sfreq);   // debug       printf(" adbit= %d\n",adbit);   // debug       printf(" numch= %d\n",numch);   // debug*/	/* sampler open */	*fd_in = open(dev, O_RDONLY);	if (*fd_in == -1) {		perror("ini_sampler : device open() error ");		return -1;	}	/* sampling frequency set */	if      (sfreq ==  40)  { sfreq_t =  TDS_SAMPLING_40KHZ; }	else if (sfreq == 100)  { sfreq_t =  TDS_SAMPLING_100KHZ; }	else if (sfreq == 200)  { sfreq_t =  TDS_SAMPLING_200KHZ; }	else if (sfreq == 500)  { sfreq_t =  TDS_SAMPLING_500KHZ; }	else if (sfreq ==   1)  { sfreq_t =  TDS_SAMPLING_1MHZ; }	else if (sfreq ==   2)  { sfreq_t =  TDS_SAMPLING_2MHZ; }	else if (sfreq ==   4)  { sfreq_t =  TDS_SAMPLING_4MHZ; }	else if (sfreq ==   8)  { sfreq_t =  TDS_SAMPLING_8MHZ; }	else if (sfreq ==  16)  { sfreq_t =  TDS_SAMPLING_16MHZ; }	else { 	   printf(" ini_sampler : parameter sfreq  (sampling frequency) must be either one of followings:\n");	   printf("                40,100,200,500 (for kHz)\n");	   printf("                1,2,4,8,16 (for MHz)\n");          return -1;	}      	/* AD resolution set */	if      (adbit ==  1)  { sbit_t =  TDS_SAMPLING_1BIT; }	else if (adbit ==  2)  { sbit_t =  TDS_SAMPLING_2BIT; }	else if (adbit ==  4)  { sbit_t =  TDS_SAMPLING_4BIT; }	else if (adbit ==  8)  { sbit_t =  TDS_SAMPLING_8BIT; }	else { 	   printf(" parameter adbit (A/D resolution) must be either one of followings:\n");	   printf("              1,2,4,8\n");          return -1;	}	/* number of channels set */	if      (numch ==  1)  { numch_t =  TDS_SAMPLING_1CH; }	else if (numch ==  4)  { numch_t =  TDS_SAMPLING_4CH; }	else { 	   printf(" parameter numch (number of channels) must be either one of followings:\n");	   printf("              1,4\n");          return -1;	}	/* sampling parameters set */	sampling =  sfreq_t | sbit_t | numch_t;		if (sfreq >= 40) { *bitsec=sfreq*1000 ;}	else { *bitsec=sfreq*1000*1000 ;}	*bitsec=(*bitsec*adbit*numch)+headbit;   // bit number per second    bytesec=*bitsec/8;	rv = ioctl(*fd_in, TDSIO_SET_SAMPLING, &sampling);	if (rv == -1) {	   perror("ini_sampler : ioctl() sampling set failed ");	   goto end;	}	else {	   printf("ini_sampler : ioctl() sampling set succeed\n");	}    /* get sampling parameters from a board */	rv = ioctl(*fd_in,TDSIO_GET_SAMPLING,&sampling1);	if (rv == -1) {		perror("ini_sampler : ioctl() get sampling parameter failed ");		goto end;	}	else {		printf("ini_sampler : ioctl() get sampling parameter succeed\n");		freq = TDS_GET_SAMP_FREQ(sampling1);		width = TDS_GET_SAMP_WIDTH(sampling1);		ch = TDS_GET_SAMP_CH(sampling1);		if(freq == TDS_SAMPLING_40KHZ)			freq = 40;		if(freq == TDS_SAMPLING_100KHZ)			freq = 100;		if(freq == TDS_SAMPLING_200KHZ)			freq = 200;		if(freq == TDS_SAMPLING_500KHZ)			freq = 500;		if(freq == TDS_SAMPLING_1MHZ)			freq = 1000;		if(freq == TDS_SAMPLING_2MHZ)			freq = 2000;		if(freq == TDS_SAMPLING_4MHZ)			freq = 4000;		if(freq == TDS_SAMPLING_8MHZ)			freq = 8000;		if(freq == TDS_SAMPLING_16MHZ)			freq = 16000;		if(width == TDS_SAMPLING_1BIT)			width = 1;		if(width == TDS_SAMPLING_2BIT)			width = 2;		if(width == TDS_SAMPLING_4BIT)			width = 4;		if(width == TDS_SAMPLING_8BIT)			width = 8;		if(ch == TDS_SAMPLING_4CH)			ch = 4;		else			ch =1;		printf("ini_sampler : sampling setting is %d kHz %d BIT %d CH\n",freq,width,ch);	}	end:	return rv;}/* 僒儞僾儕儞僌僗僞乕僩 */int start_sampler(int *fd_in){	int rv;       	rv = ioctl(*fd_in, TDSIO_BUFFER_CLEAR);   // 儃乕僪忋偺FIFO偺僋儕傾乕	if (rv == -1) {		perror("start_sampler : ioctl() FIFO clear failed ");		goto end;	}	else {		printf("start_sampler : ioctl() FIFO clear succeed\n");	}    /* sampling start */	rv = ioctl(*fd_in, TDSIO_SAMPLING_START);	if (rv == -1) {		perror("start_sampler : ioctl() start sampling failed ");		printf("                Probably time was not set for the IP-VLBI board.\n");		printf("                Please set time using timesettk and try again.\n");		goto end;	}	else {		printf("start_sampler : ioctl() start sampling succeed\n");	}end:	return rv;}/* 僒儞僾儕儞僌僗僩僢僾 */int stop_sampler(int *fd_in){	int rv;	rv = ioctl(*fd_in, TDSIO_SAMPLING_STOP);	if (rv == -1) {		perror("stop_sampler : ioctl() stop sampling failed ");	} else {		printf("stop_sampler : ioctl() stop sampling succeed\n");	}	close(*fd_in);       	return rv;}/* 僒儞僾儔乕儃乕僪弶婜壔偍傛傃僨乕僞廂廤僩儕僈乕 */int ini_and_start_sampler(int *fd_in,int sfreq, int adbit, int numch, long int *bitsec){	char dev[] = "/dev/tds0";	//int fd_in;	int rv;	//long int bitsec;       // 侾昩偁偨傝偺價僢僩悢丂乮僿僢僟乕俇係價僢僩傪娷傓乯/*	printf(" span = %d\n",span);    // debug       printf(" sfreq= %d\n",sfreq);   // debug       printf(" adbit= %d\n",adbit);   // debug       printf(" numch= %d\n",numch);   // debug*/    rv=ini_sampler(&(*fd_in),sfreq, adbit, numch, &(*bitsec));	if (rv < 0) {		printf("ini_and_start_sampler : sampler initialize error \n");		return rv;	}	rv=start_sampler(&(*fd_in));	if (rv < 0) {		printf("ini_and_start_sampler : start sampling failed ");	}		return rv;}/*  僨乕僞廂廤娭悢   婲摦偐傜幚嵺偵僨乕僞廂廤傑偱俁昩偐偐傞両両    outfile ---- 僨乕僞弌椡僼傽僀儖柤    span    ---- 僨乕僞廂廤帪娫丂乮昩乯    sfreq   ---- 僒儞僾儕儞僌廃攇悢                    40,100,200,500 (for kHz)                    1,2,4,8,16 (for MHz)    adbit   ---- 俙俢價僢僩悢                    1,2,4,8    numch   ---- 僠儍僱儖悢                    1, 4    2002-10-21 2Gbytes埲忋偺娤應傪埖偊傞傛偆偵曄峏*/int sampleget(char* outfile, int span, int sfreq, int adbit, int numch){	char dev[] = "/dev/tds0";	int fd_in;	int fd_out;	mode_t ofilemode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;	int rv;	unsigned int time,day,sec; // 僨僶僀僗偐傜撉傒崬傫偩尰嵼偺帪崗忣曬傪奿擺       int i,h,m,s;       int secforce;       int headbit=64;  // header bit number  for a new sampler board       //int headbit=32;  // header bit number  for a old sampler board       long int allbyte;     // 僒儞僾儕儞僌憤僶僀僩悢       long int bitsec;       // 侾昩偁偨傝偺價僢僩悢丂乮僿僢僟乕俇係價僢僩傪娷傓乯       long int bytesec;       // 侾昩偁偨傝偺僶僀僩悢丂乮僿僢僟乕俇係價僢僩傪娷傓乯       long int c;       unsigned int sampling1, freq, width;       int ch;	   // 2002-10-21	   double dallbyte, dc;	   int f_c;   // file number counter  in case of file exceeds > 2Gbyte	   char cbuf[10];	   char outname2[80]; // for extra output	   // ----------       u_int8_t sfreq_t, sbit_t, numch_t;	u_int8_t sampling;	u_int32_t buf[BUFSIZ * 2];		//printf("BUFSIZ   %d\n",BUFSIZ);   // BUFSIZ偼1024偱偟偨両   /*	printf(" span = %d\n",span);    // debug       printf(" sfreq= %d\n",sfreq);   // debug       printf(" adbit= %d\n",adbit);   // debug       printf(" numch= %d\n",numch);   // debug   */       /* sampling duration check */       if (span <= 0) {          printf(" parameter span (duration in sec) should be positive!\n");          // nothing to do          return -1;       }       /* sampler open */	fd_in = open(dev, O_RDONLY);	//fd_in = open("/dev/tds0", O_RDONLY);	if (fd_in == -1) {		perror("device open() error ");		return -1;	}       /* output file open */	fd_out = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, ofilemode);	if (fd_out == -1) {		perror("output file open() error");		goto end;	}       /* sampling frequency set */       if      (sfreq ==  40)  { sfreq_t =  TDS_SAMPLING_40KHZ; }       else if (sfreq == 100)  { sfreq_t =  TDS_SAMPLING_100KHZ; }       else if (sfreq == 200)  { sfreq_t =  TDS_SAMPLING_200KHZ; }       else if (sfreq == 500)  { sfreq_t =  TDS_SAMPLING_500KHZ; }       else if (sfreq ==   1)  { sfreq_t =  TDS_SAMPLING_1MHZ; }       else if (sfreq ==   2)  { sfreq_t =  TDS_SAMPLING_2MHZ; }       else if (sfreq ==   4)  { sfreq_t =  TDS_SAMPLING_4MHZ; }       else if (sfreq ==   8)  { sfreq_t =  TDS_SAMPLING_8MHZ; }       else if (sfreq ==  16)  { sfreq_t =  TDS_SAMPLING_16MHZ; }       else { 	   printf(" parameter sfreq  (sampling frequency) must be either one of followings:\n");	   printf("              40,100,200,500 (for kHz)\n");	   printf("              1,2,4,8,16 (for MHz)\n");          return -1;       }             /* AD resolution set */       if      (adbit ==  1)  { sbit_t =  TDS_SAMPLING_1BIT; }       else if (adbit ==  2)  { sbit_t =  TDS_SAMPLING_2BIT; }       else if (adbit ==  4)  { sbit_t =  TDS_SAMPLING_4BIT; }       else if (adbit ==  8)  { sbit_t =  TDS_SAMPLING_8BIT; }       else { 	   printf(" parameter adbit (A/D resolution) must be either one of followings:\n");	   printf("              1,2,4,8\n");          return -1;       }       /* number of channels */       if      (numch ==  1)  { numch_t =  TDS_SAMPLING_1CH; }       else if (numch ==  4)  { numch_t =  TDS_SAMPLING_4CH; }       else { 	   printf(" parameter numch (number of channels) must be either one of followings:\n");	   printf("              1,4\n");          return -1;       }       /* sampling parameters set */       sampling =  sfreq_t | sbit_t | numch_t;       //if (sfreq >= 40) { bitsec=sfreq*1000 + headbit ;}          //else { bitsec=sfreq*1000*1000 + headbit ;}       if (sfreq >= 40) { bitsec=sfreq*1000 ;}          //2002-9-15       else { bitsec=sfreq*1000*1000 ;}                 //2002-9-15       //bitsec=bitsec*adbit*numch;   // bit number per second		bitsec=(bitsec*adbit*numch)+headbit;   // bit number per second  !! 2002-9-15       bytesec=bitsec/8;       allbyte=bytesec*span;	   dallbyte=(double)bytesec*(double)span;   // 2002-10-21       /* File maximum bytes check */       //if (allbyte > FILEMAXSIZE){ //      if (dallbyte > (double)FILEMAXSIZE){  // 2002-10-21 //         allbyte= FILEMAXSIZE; //         secforce=allbyte/bytesec; //         printf(" # of bytes force to set to %d Bytes because it exceeds %d Bytes\n",//              allbyte,FILEMAXSIZE);  // debug//          printf(" Obserbasation span (sec) reduced to %d\n",secforce);  // debug//        }       printf(" bitsec  = %d\n",bitsec);  // debug       printf(" bytesec = %d\n",bytesec);  // debug       //printf(" allbyte = %d\n",allbyte);  // debug       printf(" allbyte = %g\n",dallbyte);  // debug	//sampling = TDS_SAMPLING_4MHZ | TDS_SAMPLING_1BIT | TDS_SAMPLING_1CH;	rv = ioctl(fd_in, TDSIO_SET_SAMPLING, &sampling);	if (rv == -1) {	   perror("ioctl() sampling set failed ");	   goto end;	}	else {	   printf("ioctl() sampling set succeed\n");	}       /* get sampling parameters from a board */	rv = ioctl(fd_in,TDSIO_GET_SAMPLING,&sampling1);	if (rv == -1) {		perror("ioctl() get sampling parameter failed ");		goto end;	}	else {		printf("ioctl() get sampling parameter succeed\n");		freq = TDS_GET_SAMP_FREQ(sampling1);		width = TDS_GET_SAMP_WIDTH(sampling1);		ch = TDS_GET_SAMP_CH(sampling1);		if(freq == TDS_SAMPLING_40KHZ)			freq = 40;		if(freq == TDS_SAMPLING_100KHZ)			freq = 100;		if(freq == TDS_SAMPLING_200KHZ)			freq = 200;		if(freq == TDS_SAMPLING_500KHZ)			freq = 500;		if(freq == TDS_SAMPLING_1MHZ)			freq = 1000;		if(freq == TDS_SAMPLING_2MHZ)			freq = 2000;		if(freq == TDS_SAMPLING_4MHZ)			freq = 4000;		if(freq == TDS_SAMPLING_8MHZ)			freq = 8000;		if(freq == TDS_SAMPLING_16MHZ)			freq = 16000;		if(width == TDS_SAMPLING_1BIT)			width = 1;		if(width == TDS_SAMPLING_2BIT)			width = 2;		if(width == TDS_SAMPLING_4BIT)			width = 4;		if(width == TDS_SAMPLING_8BIT)			width = 8;		if(ch == TDS_SAMPLING_4CH)			ch = 4;		else			ch =1;		printf("sampling setting is %d kHz %d BIT %d CH\n",freq,width,ch);	}	       /* board time get */ /*	rv = ioctl(fd_in, TDSIO_GET_TIME, &time);	if (rv == -1) {		perror("ioctl() time get failed ");		return -1;	}       day=TDS_GET_DAYS(time);       sec=TDS_GET_SEC(time);       sec2hms(sec,&h,&m,&s);	//printf("get count day from device [%5d]\n",TDS_GET_DAYS(time));	//printf("get count sec from device [%5d]\n",TDS_GET_SEC(time)); 	printf("%03d %02d:%02d:%02d\n",day,h,m,s); */       	rv = ioctl(fd_in, TDSIO_BUFFER_CLEAR);   // 儃乕僪忋偺FIFO偺僋儕傾乕	if (rv == -1) {		perror("ioctl() FIFO clear failed ");		goto end;	}	else {		printf("ioctl() FIFO clear succeed\n");	}/*       	rv = ioctl(fd_in, TDSIO_SYNC_1PPS);           // 侾俹俹俽傊偺摨婜丅怴儃乕僪(2002.3埲崀)偱偼	if (rv == -1) {                               // 枅夞傗傜側偔偰傕幚尡偺嵟弶偵侾夞傗傟偽椙偄		perror("ioctl() 1pps sync failed ");   //  (枅夞傗傜側偄曽偑椙偄乯		goto end;	}	else {		printf("ioctl() 1pps sync succeed\n");	}*//*	rv = ioctl(fd_in, TDSIO_SYNC_TIME);            // 奜晹帪崗擖椡偼巊梡偟側偄	if (rv == -1) {		perror("ioctl() time sync failed ");		goto end;	}	else {		printf("ioctl() time sync succeed\n");	}*/       /* sampling start */	rv = ioctl(fd_in, TDSIO_SAMPLING_START);	if (rv == -1) {		perror("ioctl() start sampling failed ");              printf("Probably time was not set for the IP-VLBI board.\n");              printf("Please set time using timesettk and try again.\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -