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

📄 monit.c

📁 实现ipvlbi数据记录
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************//*                                                            *//*   Program Name :  monit                                    *//*                                                            *//*      Version:  0.00  2002-05-26                            *//*                2.01  2002-10-03                            *//*                                                            *//*      Copyright (c) 2002 T.Kondo/CRL All Right Reserved     *//*                                                            *//**************************************************************//* 俬俹亅倁俴俛俬擖椡儗儀儖儌僯僞乕僾儘僌儔儉        乮帪崗僙僢僩偼暿偺僜僼僩偱峴偆乯         by T.Kondo 2002.5.26                       2002.10.03   remove 1pps sync     憱傜偣曽  monit numch         偙偙偱 numch  僠儍僱儖悢                        1 (default), 4  */#include <stdio.h>#include <signal.h> #include <errno.h>#include <fcntl.h>#include <unistd.h>#include <math.h>#include <sys/stat.h>#ifdef linux#include <sys/time.h>#else#include <time.h>#endif#include <sys/tdsio.h>#include "libipvlbi.h"  // IP-VLBI梡娭悢孮(by T.Kondo)/* set global variables */char dev[] = "/dev/tds0";  // IP-VLBI BOARD control variableint fd_in;                 // IP-VLBI BOARD control variable/* set interrupt handler */void Handler(int n);void SetHandler(void){    if(signal(SIGINT, Handler) == SIG_ERR){        printf("Signal handler set up failure!\n");        abort();    }}void Handler(int n){     static int x=0;     int rv;     printf("Interrupt occurred !!\n");     /* sampling stop */     rv = ioctl(fd_in, TDSIO_SAMPLING_STOP);     if (rv == -1) {	 perror("stop sampling failed, anyway stop ");	 goto end;     }     else {        printf("Stop sampling!\n");     }     //close(fd_out); end:     close(fd_in);     exit(0);}/*  僨乕僞廂廤娭悢丂丂丂丂婲摦偐傜幚嵺偵僨乕僞廂廤傑偱俁昩偐偐傞両両    outfile ---- 僨乕僞弌椡僼傽僀儖柤    span    ---- 僨乕僞廂廤帪娫丂乮昩乯丂丂sfreq   ---- 僒儞僾儕儞僌廃攇悢丂丂丂丂丂丂丂丂丂丂丂40,100,200,500 (for kHz)丂丂丂丂丂丂丂丂丂丂丂1,2,4,8,16 (for MHz)丂丂adbit   ---- 俙俢價僢僩悢丂丂丂丂丂丂丂丂丂丂丂1,2,4,8    numch   ---- 僠儍僱儖悢                    1, 4*/int sampleget_monit(char* outfile, int span, int sfreq, int adbit, int numch){	//char outfile[] = "./tds.data";	//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 ihist[4][8];       int hmax[4];       char iline[70];       char* lev0="          ";       char* lev1="*         ";       char* lev2="**        ";       char* lev3="***       ";       char* lev4="****      ";       char* lev5="*****     ";       char* lev6="******    ";       char* lev7="*******   ";       char* lev8="********  ";       char* lev9="********* ";       char* lev10="**********";       char* levd="<         ";       char* levu="         >";       int w1,w2,w3,mm;       //int span, sfreq;       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,k;       unsigned int sampling1, freq, width, stat;       int ch, pos;       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偱偟偨両       int xdata[BUFSIZ * 16];  // 僨乕僞暘夝屻偺僨乕僞廂擺梡	//printf(" span = %d\n",span);    // debug       //printf(" sfreq= %d\n",sfreq);   // 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;	}       /* board status check */ 	rv = ioctl(fd_in, TDSIO_GET_STATUS, &stat);	if (rv == -1) {		perror("ioctl() status get failed ");		goto end;	}	else {              /* satatus get again just in case */ 	       rv = ioctl(fd_in, TDSIO_GET_STATUS, &stat);	       if (rv == -1) {		    perror("ioctl() status get failed ");		    goto end;	       }	       //printf("ioctl() status get succeed\n");             // printf(" status = %X\n",stat);              if((stat & 1) != 1){                  printf("Warning! 10MHz signal is not supplied. \n");              }              if((stat & 2) != 2){                  printf("Warning! 1PPS signal is not supplied. \n");              }              if((stat & 3) != 3){                  printf("Check above signal connection and try again!\n");                  goto end;              }	}             /* 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 ;}       bitsec=bitsec*adbit*numch;   // bit number per second       bytesec=bitsec/8;       allbyte=bytesec*span;       if (allbyte > 2000000000)       {          allbyte= 2000000000;          secforce=allbyte/bytesec;          printf(" # of bytes force to set to 2GB because it exceeds 2GB\n");  // 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	//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)

⌨️ 快捷键说明

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