📄 record.c
字号:
/*---------------------------------------------------------------------------+| || David K. Burton, Entropic Processing, Inc. || || The 'record' program creates an SPS sampled data (sd) file and fills it || with data. || || Syntax: record [options] file || Options: || -g gain || gain is 1, 2, 4, or 8. The analog signal is amplified before || being sampled. || -p range || range is a number of points to capture. || -f range || range is a number of frames to capture (default frame size || = 100) || -w width || changes the frame size || -s range || range is the number of seconds of data to capture. || -r sampling rate || number of samples per second || -c a2d channel || input channel number || -k clock# || the number of the clock unit that drives the conversion || -x debug_level || 0 => no debug; 1 => print debug messages || || Module Name: RECORD || || Written by: David Burton || Checked by: Alan Parker| Modified for SPS by Alan Parker| || Purpose: Digitize analog data using Masscomp || || Secrets: How to digitize data ||| This material contains proprietary software of Entropic Processing, Inc. | Any reproduction, distribution, or publication without the the prior | written permission of Entropic Processing, Inc. is strictly prohibited.| Any public distribution of copies of this work authorized in writing by| Entropic Processing, Inc. must bear the notice | | "Copyright 1986 Entropic Processing, Inc."| +---------------------------------------------------------------------------*/#ifdef SCCS static char *sccsid = "%W% %G%";#endif#include <stdio.h>#include <sps/sps.h>int debug_level = 0;#define FILENAME_LNGTH 14 /* maximum number of characters in .sd file name */#define COMMAND_LNGTH 200 /* maximim number of characters in a command */#define SIXTY 60.0 /* needed because of MASSCOMP bug; should be remove soon */#define PROGRAM "RECORD"#define SOURCE "analog data digitized with an EF-12M at EPIWRL\n"#define SOURCE2 "analog data digitized with an EF-12M at EPIMASS\n"#define MAX_VALUE 2047 /* for 12 bit EF-12M */#define Fprintf (void)fprintf#define Fperror (void)perror#define SYNTAX USAGE \("record [-x debug] [-[spf] range] [-w frame size] [-c a2d channel] [-r sampling rate] [-k clock#] [-g gain] file");main (argc, argv)int argc;char **argv;{ int c; extern optind, debug_level; extern char *optarg; int clkn = 1, a2d_channel = 0, sam_rate = 8000; char dacqcmd[COMMAND_LNGTH], *mktemp(), *strcat(), *strcpy(); char *template = "/usr/tmp/recXXXXXX"; char tmp1[FILENAME_LNGTH]; /* 11 is used because the total file name length must be less than or equal to 14 characters */ FILE *ostrm; FILE *tmpstrm; int s_switch = NO, p_switch = NO, f_switch = NO; int p_value = 0, f_value = 0; double s_value = 0.0, time_out = 0.0; struct header *oh; int fwidth = 100, gflag = 0; int npnts = 0, gain = 1; double atof (); while ((c = getopt (argc, argv, "p:s:k:r:c:w:f:g:x:")) != EOF) { switch (c) { case 'x': debug_level = atoi (optarg); break; case 'g': gflag++; gain = atoi (optarg); break; case 'c': a2d_channel = atoi (optarg); break; case 'k': clkn = atoi (optarg); break; case 'r': sam_rate = atoi (optarg); break; case 'p': p_value = atoi(optarg); p_switch = YES; break; case 'f': f_value = atoi(optarg); f_switch = YES; break; case 'w': fwidth = atoi (optarg); break; case 's': s_value = atof(optarg); s_switch = YES; break; default: SYNTAX; } } if (optind >= argc) SYNTAX;/* Convert range argument to number of sample points *//* Also compute number of seconds to wait before timing out */ /* factor of 60 (SIXTY) in time_out calculation is needed because of MASSCOMP bug */ if (p_switch == YES) { npnts = p_value; time_out = SIXTY * 2.0 * ( (float)npnts / (float)sam_rate ); } else if (f_switch == YES) { npnts = f_value * fwidth; time_out = SIXTY * 2.0 * ( (float)npnts / (float)sam_rate ); } else if (s_switch == YES) { npnts = (int) ( ( (float) sam_rate * s_value ) + .5 ); time_out = SIXTY * 2.0 * s_value; } else { Fprintf(stderr, "record: amount of data to record has not beeen specified\n"); exit(1); } if(debug_level) Fprintf(stderr, "record: npnts is %d, P is %d, F is %d, S is %f\n", npnts, p_value, f_value, s_value);/* convert gain argument to MASSCOMP defined values *//* MASSCOMP convention is not known yet; this is just a place holder */ if (gflag) { if (gain == 1 || gain == 4 || gain == 8 || gain == 16) ; else { Fprintf(stderr, "record: invalid gain specified\n"); exit(1); } }/* Check if sampling rate is > 0 */ if ( sam_rate <= 0 ) { Fprintf(stderr, "record: sampling Rate (%d) Must Be > 0\n", sam_rate); exit(1); } /* Insure that A/D channel # is between 0 and 7 */ if ( a2d_channel < 0 || a2d_channel > 7 ) { Fprintf(stderr, "record: A/D channel (%d) must be between 0 and 7\n", a2d_channel); exit(1); }/* Insure that A/D clock # is between 0 and 4 */ if ( clkn < 0 || clkn > 4 ) { Fprintf(stderr, "record: clock # (%d) must be between 0 and 4\n", clkn); exit(1); }/* Make DACQ command */ /* First make temporary file */ (void)mktemp(template);/* Now build command */ (void) sprintf(dacqcmd, "/usr/bin/dacq -B -D/dev/dacp0/adf0 -TA -cH%d -cd50 -cl%d -d%s -f%d -g%d -i0 -l%d -n1 -A%f\n", sam_rate, clkn, template, a2d_channel, gain, npnts, time_out); if (debug_level) Fprintf(stderr, "%s\n", dacqcmd);/* Prompt user for initiation of data collection */ Fprintf(stdout,"record: when ready to record data, hit RETURN: ");/* Wait for carriage return */ while( (c = getchar()) != '\n') /* wait for return */;/* First open designated data file - if error occurs stop program */ (void)strcat ( tmp1, argv[optind] ); TRYOPEN ( "record", tmp1, "w", ostrm ); /* Now collect data using DACQ in temporay file - if DACQ bombs clean up immeadiately and exit */ if ( system(dacqcmd) != NULL ) { Fperror ( "record cannot start dacq" ); (void)unlink(template); exit(1); }/* First reopen the temporary file */ if( (tmpstrm = fopen(template,"r")) == NULL) CANTOPEN("record", template); /* Then make and write header in file */fflush(stderr); oh = new_header (FT_SD); oh->common.ndrec = npnts; oh->common.tag = NO; set_sd_type(oh,SHORT); oh->hd.sd->sf = (float)sam_rate; oh->hd.sd->src_sf = 0; oh->hd.sd->synt_method = NONE; oh->hd.sd->q_method = NONE; oh->hd.sd->equip = EF12M; /* EPIWRL masscomp */ oh->hd.sd->max_value = MAX_VALUE; /* EPIWRL masscomp */ oh->hd.sd->scale = 1; oh->hd.sd->nchan = 1; (void)strcpy(oh->common.prog, PROGRAM);#ifdef SCCS (void)strcpy(oh->common.vers, "%I%");#else (void)strcpy(oh->common.vers, "debug");#endif (void) add_comment(oh,SOURCE); write_header(oh, ostrm);/* Then copy binary data into file */ while( (c = getc(tmpstrm)) != EOF ) (void)putc(c,ostrm); /* Then clean up */ (void)fclose(tmpstrm); (void)unlink(template); (void)fclose(ostrm); (void)putsym_s("filename",argv[optind]); (void)putsym_s("prog","record"); (void)putsym_i("start",1); (void)putsym_i("nan",npnts); exit(0); /* NOTREACHED */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -