tekdefs_h

/*
**	Copyright 1993-2015, Fermi Research Alliance, LLC.  All rights reserved.
*/
/******************************************************************************/
/* tekdefs.h
**
**	This header file contains definitions for tek_xxx and tdsxxx routines.
**
**  MODIFICATION HISTORY:
**
**      R Joshel 	22 Mar 93	Created
**	[@tbs@]...
**
*/
/******************************************************************************/

#ifndef TEKDEFS_H_DEFINED		/* do this only once */
#define	TEKDEFS_H_DEFINED

#include "acnet_callbacks.h"

#define TEK_NUMBIN	800		/* # of bins per trace for TEK3052 */
#define	TEK_MAXTRACE	500		/* max # of traces per waveform */
#define	TEK_ALL_TRACES 	-1		/* get all traces for a waveform */

#define	TEK3052_HOUSE	"02"		/* location of TEK3052 */
#define	TEK3052_MODULE	"GPI3"
#define	TEK3052_NODE	(BOOSTR)	/* see nodedefs.h */
#define	TEK3052_ADDR	4
#define	TEK3052_VME_NODE 0x9D0		/*(ADGP01)	 see nodedefs.h */

#define	TEK_SEQ		0		/* Seq data request form tek3052*/
#define	TEK_VME		1		/* VME mode	*/
#define	TEK_489		2		/* 489 card mode*/

#define	TEK_RUN		0		/* scope mode */
#define	TEK_PAUSE	1		/* scope mode */

#define	TEK_DIR_WFBLK	0		/* Dir for waveform block */
#define	TEK_DIR_SET	1		/* Dir for settings       */
#define	TEK_DIR_WF	2		/* Dir for wavefrom       */
#define	TEK_DIR_PRGM	3		/* Dir for programs       */
#define	TEK_DIR_UTIL	4		/* Dir for utilities      */
#define	TEK_DIR_MACRO	5		/* Dir for macros         */

#define	TEK_WFBLK	0		/* Dir for waveform block */
#define	TEK_SET	 	1		/* Dir for settings       */
#define	TEK_WF		2		/* Dir for wavefrom       */

#define TEK_CHAN1	1      		/* Channel 1 to take data	*/
#define TEK_CHAN2	2      		/* Channel 2 to take data	*/
#define TEK_CHAN3	3      		/* Channel 3 to take data	*/
#define TEK_CHAN4      	4		/* Channel 4 to take data	*/

#define TEK_TX      	20		/* Length of an HP disk file	*/

#define	ENERGY_SLOTS	13		/* Number of energy slots */
const double REV_FREQ =  47713.15 ;     /* Tev Rev Frequency      */
const double MI_REV_FREQ =  89686.09 ;  /* MI Rev Frequency  @ 8Gev?*/
const double E0	     = .938;		/* Proton rest mass       */
const double Boo_cir = 474.38;		/* Circumference booster  */
const double Cvel    = 300000000 ;	/* speed of light         */
#define TEK_CENTRAL_FILES  CBS_FILES:[CNS_WRITE.TEKUTI]

#define SCALE_VAL(zero_ref,bin) ( (zero_ref) - ((float) (bin)) / 32.0 )
#define CONVERT_START(cntr_freq,span) ( (cntr_freq) - ((double)(span)) / 2.0 )
#define CONVERT_STOP(start_freq,span) ( (start_freq) + ((double)(span)) )
#define CONVERT_TUNE(freq)  ( freq/REV_FREQ )
#define TOTAL_ENERGY(pc,E0) (sqrt(pc*pc + E0*E0))
#define BOO_REV_FREQ(pc) (sqrt(1 - (E0*E0/(pc*pc  + E0*E0)))*(Cvel/Boo_cir))


typedef struct				/* waveform header from TEK3052 */
    {
    unsigned char  db_per_div;
    unsigned char  disp_status;
    unsigned short disp_reserved;
    float          disp_reflvl;
    unsigned int  time;
    unsigned int  wfm_status;
    unsigned int  date;
    double         center_freq;
    unsigned int  span;
    float          zero_ref;
    float          weighted_filter;
    unsigned short max_x_value;
    unsigned short min_x_value;
    unsigned short r_value;
    unsigned char  data_compression_mode;
    unsigned char  vertical_mode;
    char           max_input;
    char           marked_frame;
    char           invalid_data;
    char           math;
    float          amplitude_offset;
    double         freq_offset;
    unsigned short total_bins;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ tek_head_t;

typedef struct {
    tek_head_t  data_header ;
    float       time_slice ;
    int         no_traces ;
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ FILE_HEADER ;

typedef struct				/* scaled trace from TEK3052 */
    {
    float	tt_bin[TEK_NUMBIN];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ tek_trace_t;

typedef struct				/* scaled waveform from TEK3052 */
    {
    tek_trace_t	tw_trace[TEK_MAXTRACE];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */tek_waveform_t;

#define	TDS7000_NUM_TRACES		4
#define	TDS7000_NUM_CHANNELS		4

typedef struct TDS7000_CONFIG_CHANNEL_DATA
    {
    int		state;
    double	offset;
    double	range;
    double	vscale;
    } __attribute__((packed)) TDS7000_CONFIG_CHANNEL_DATA;

#define	TDS7000_TRIGGER_TYPE_LEN	6
#define	TDS7000_TRIGGER_MODE_LEN	6
#define	TDS7000_TRIGGER_SOURCE_LEN	9
#define	TDS7000_TRIGGER_COUPLING_LEN	8
#define	TDS7000_TRIGGER_SLOPE_LEN	4

#define	TDS7000_TRIGGER_UNKNOWN		(-1)
#define	TDS7000_TRIGGER_A		0
#define	TDS7000_TRIGGER_B		1

#define	TDS7000_TRIGGER_TYPE_UNKNOWN	(-1)
#define	TDS7000_TRIGGER_TYPE_EDGE	0
#define	TDS7000_TRIGGER_TYPE_PULSE	1
#define	TDS7000_TRIGGER_TYPE_LOGIC	2
#define	TDS7000_TRIGGER_TYPE_COMM	3
#define	TDS7000_TRIGGER_TYPE_SERIAL	4

#define	TDS7000_NUM_TRIGGER_TYPES	5

#define	TDS7000_TRIGGER_MODE_UNKNOWN	(-1)
#define	TDS7000_TRIGGER_MODE_NORMAL	0
#define	TDS7000_TRIGGER_MODE_AUTO	1

#define	TDS7000_NUM_TRIGGER_MODES	2

#define	TDS7000_TRIGGER_SOURCE_UNKNOWN		(-2)
#define	TDS7000_TRIGGER_SOURCE_LINE		(-1)
#define	TDS7000_TRIGGER_SOURCE_AUXILIARY	0
#define	TDS7000_TRIGGER_SOURCE_EXTERNAL		0
#define	TDS7000_TRIGGER_SOURCE_CH1		1
#define	TDS7000_TRIGGER_SOURCE_CH2		2
#define	TDS7000_TRIGGER_SOURCE_CH3		3
#define	TDS7000_TRIGGER_SOURCE_CH4		4

#define	TDS7000_NUM_TRIGGER_SOURCES		6

#define	TDS7000_TRIGGER_COUPLING_UNKNOWN	(-1)
#define	TDS7000_TRIGGER_COUPLING_DC		0
#define	TDS7000_TRIGGER_COUPLING_AC		1
#define	TDS7000_TRIGGER_COUPLING_HF_REJECT	2
#define	TDS7000_TRIGGER_COUPLING_LF_REJECT	3
#define	TDS7000_TRIGGER_COUPLING_NOISE_REJECT	4

#define	TDS7000_NUM_TRIGGER_COUPLINGS		5

#define	TDS7000_TRIGGER_SLOPE_UNKNOWN	(-1)
#define	TDS7000_TRIGGER_SLOPE_RISING	0
#define	TDS7000_TRIGGER_SLOPE_FALLING	1

#define	TDS7000_NUM_TRIGGER_SLOPES	2

#define	TDS7000_PULSE_TRIGGER_CLASS_UNKNOWN	(-1)
#define	TDS7000_PULSE_TRIGGER_CLASS_GLITCH	0
#define	TDS7000_PULSE_TRIGGER_CLASS_RUNT	1
#define	TDS7000_PULSE_TRIGGER_CLASS_WIDTH	2
#define	TDS7000_PULSE_TRIGGER_CLASS_TRANSITION	3
#define	TDS7000_PULSE_TRIGGER_CLASS_TIMEOUT	4

typedef struct TDS7000_CONFIG_DATA		/* configuration data from TDS7000 */
    {
    TDS7000_CONFIG_CHANNEL_DATA	channel_data[TDS7000_NUM_CHANNELS];
    int		trace_length;
    int		num_traces;
    double	horz_increment;
    int		display_position;
    } __attribute__((packed)) TDS7000_CONFIG_DATA;

typedef struct TDS7000_MEASUREMENT_DATA		/* measurement data from TDS7000 */
    {
    double	time_last_measure;		/* time of last trigger - t0 (sec) */
    double	trigger_11th;			/* time at the 11th trigger */
    } __attribute__((packed)) TDS7000_MEASUREMENT_DATA;

typedef struct TDS7000_TRIGGER_CONFIG_DATA		/* trigger configuration data from TDS7000 */
    {
    int		trigger_type;
    int		trigger_mode;
    double	trigger_level;
    } __attribute__((packed)) TDS7000_TRIGGER_CONFIG_DATA;

typedef struct TDS7000_EDGE_TRIGGER_CONFIG_DATA		/* edge trigger configuration data from TDS7000 */
    {
    int		trigger_source;
    int		trigger_coupling;
    int		trigger_slope;
    } __attribute__((packed)) TDS7000_EDGE_TRIGGER_CONFIG_DATA;

#define	RTD720_NUM_TRACES		4
#define	RTD720_NUM_CHANNELS		4

typedef struct RTD720_CONFIG_CHANNEL_DATA
    {
    int		state;
    double	offset;
    double	range;
    double	vscale;
    } __attribute__((packed)) RTD720_CONFIG_CHANNEL_DATA;

typedef struct RTD720_CONFIG_DATA		/* configuration data from an RTD720 scope */
    {
    RTD720_CONFIG_CHANNEL_DATA	channel_data[RTD720_NUM_CHANNELS];
    int		trace_length;
    int		num_traces;
    double	horz_increment;
    int		display_position;
    } __attribute__((packed)) RTD720_CONFIG_DATA;

typedef struct RTD720_MEASUREMENT_DATA		/* measurement data from RTD720 */
    {
    double	time_last_measure;		/* time of last trigger - t0 (sec) */
    double	trigger_11th;			/* time at the 11th trigger */
    } __attribute__((packed)) RTD720_MEASUREMENT_DATA;


/******************************************************************************/
/*
**	shared function prototypes
*/
/******************************************************************************/

extern "C" {
int rtd720_get_config_info(void *connect_info,
			   RTD720_CONFIG_DATA *config_data);
int rtd720_get_id_string_c(void *connect_info, int max_return,
			   char *id_string);
int rtd720_get_string_c(void *connect_info, char const *command_string,
			int max_return, char *data_string);
int rtd720_get_waveform_c(void *connect_info,
			  double *horz_increment,
			  int max_traces, int mpnts_per_trace,
			  int *num_traces, int *pnts_per_trace,
			  double **chan_1=(double **) NULL,
			  double **chan_2=(double **) NULL,
			  double **chan_3=(double **) NULL,
			  double **chan_4=(double **) NULL,
			  unsigned int **timestamps=(unsigned int **) NULL,
			  RTD720_CONFIG_DATA *config_data=(RTD720_CONFIG_DATA *) NULL,
			  RTD720_MEASUREMENT_DATA *measure_data=(RTD720_MEASUREMENT_DATA *) NULL);
int rtd720_is_busy(void *connect_info, int *is_busy);
int rtd720_request_measurement(void *connect_info);
int rtd720_reset_scope(void *connect_info);
int rtd720_set_display_position_c(void *connect_info, int position);
int rtd720_set_num_traces_c(void *connect_info, int num_traces);
int rtd720_set_offset_c(void *connect_info, int channel,
			double offset);
int rtd720_set_range_c(void *connect_info, int channel, double range);
int rtd720_set_sample_rate_c(void *connect_info, double sample_rate);
int rtd720_set_trace_length_c(void *connect_info, int trace_length);
int rtd720_set_trigger_level_c(void *connect_info, double level);
int tds7000_enable_channel_c(void *connect_info, int channel);
int tds7000_get_config_info(void *connect_info,
			    TDS7000_CONFIG_DATA *config_data);
int tds7000_get_edge_trigger_config_info_c(void *connect_info, int trigger,
					   TDS7000_EDGE_TRIGGER_CONFIG_DATA *config_data);
int tds7000_get_id_string_c(void *connect_info, int max_return,
			    char *id_string);
int tds7000_get_string_c(void *connect_info, char const *command_string,
			 int max_return, char *data_string);
int tds7000_get_trigger_config_info_c(void *connect_info, int trigger,
				      TDS7000_TRIGGER_CONFIG_DATA *config_data);
int tds7000_get_trigger_coupling_convert_id(int *convert_id);
int tds7000_get_trigger_mode_convert_id(int *convert_id);
int tds7000_get_trigger_slope_convert_id(int *convert_id);
int tds7000_get_trigger_source_convert_id(int *convert_id);
int tds7000_get_trigger_type_convert_id(int *convert_id);
int tds7000_get_waveform_c(void *connect_info,
			   double *horz_increment,
			   int max_traces, int mpnts_per_trace,
			   int *num_traces, int *pnts_per_trace,
			   double **chan_1=(double **) NULL,
			   double **chan_2=(double **) NULL,
			   double **chan_3=(double **) NULL,
			   double **chan_4=(double **) NULL,
			   unsigned int **timestamps=(unsigned int **) NULL,
			   TDS7000_CONFIG_DATA *config_data=(TDS7000_CONFIG_DATA *) NULL,
			   TDS7000_MEASUREMENT_DATA *measure_data=(TDS7000_MEASUREMENT_DATA *) NULL);
int tds7000_is_busy(void *connect_info, int *is_busy);
int tds7000_request_measurement(void *connect_info);
int tds7000_reset_scope(void *connect_info);
int tds7000_set_display_position_c(void *connect_info, int position);
int tds7000_set_edge_trigger_params_c(void *connect_info, int trigger,
				      int source=CLIB_DEFAULT_ARG,
				      int coupling=CLIB_DEFAULT_ARG,
				      int slope=CLIB_DEFAULT_ARG);
int tds7000_set_num_traces_c(void *connect_info, int num_traces);
int tds7000_set_offset_c(void *connect_info, int channel, double offset);
int tds7000_set_range_c(void *connect_info, int channel, double range);
int tds7000_set_sample_rate_c(void *connect_info, double sample_rate);
int tds7000_set_trace_length_c(void *connect_info, int trace_length);
int tds7000_set_trigger_level_c(void *connect_info, int trigger,
				double level);
int tds7000_set_trigger_type_c(void *connect_info, int trigger,
			       int type=CLIB_DEFAULT_ARG,
			       int mode=CLIB_DEFAULT_ARG);
int tek_get_dir(int,int,int,int,char *) ;
int tek_get_header(tek_head_t **u_header);
int tek_get_mode(int *);
int tek_get_waveform(int,int *,float *,tek_waveform_t **, tek_head_t **,
		     int,int);
int tek_message(char *);
int tek_set_mode(int);
int tek_set_span(int);
int tek_switch_mode(int);
int tek_window_mess(char *,int,int);

int tek3000_get_waveform(float ** trace, int channel, int dev_address,
			int *num_pts);
int tek3000_init(int dev_address,char * id_text);
int tek3000_message(int dev_address,int row,int col,char *text);
void tekuti_clear_statistics(void);
void tekuti_get_acb_statistics(SCOPE_ACB_REPLY *reply);

}

#endif