auxlib_misc_h

/*
**	Copyright 1991-2017, Fermi Research Alliance, LLC.  All rights reserved.
*/
/******************************************************************************/
/******************************************************************************/
/* auxlib_misc.h
**  
**	function prototypes and defined constants for argument values for
**	miscellaneous routines in user library UL_CBSAUX
**
*/
/******************************************************************************/

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

#include "vaxtypes.h"
#include "cnsparam.h"
#include "cns_data_structs.h"
#include "nodedefs.h"
#include "machine.h"
#include "tclk_events.h"

/******************************************************************************/
/* 
**	defined constants for argument values and structure definitions
*/
/******************************************************************************/

/*
** abort ...
*/
#define	ABORT_TEST		(-1)		/* Test system */
#define	ABORT_TEVATRON		0		/* Tevatron */
#define	ABORT_SWYD		1		/* Switchyard */
#define	ABORT_MAINRING		2		/* Main Ring */
#define	ABORT_BOOSTER		3		/* Booster */
#define	ABORT_PBAR		4		/* P-bar source */
#define	ABORT_MUON		4		/* Muon campus */
#define	ABORT_MAIN_INJECTOR	(MACHINE_MAIN_INJECTOR)	/* Main Injector */
#define	ABORT_P1_LINE		(MACHINE_P1_LINE)	/* P1 line */
#define	ABORT_P2_LINE		(MACHINE_P2_LINE)	/* P2 line */
#define	ABORT_P3_LINE		(MACHINE_P3_LINE)	/* P3 line */
#define	ABORT_RECYCLER		(MACHINE_RECYCLER)	/* Recycler */
#define	ABORT_MINIBOONE		(MACHINE_MINIBOONE)	/* MiniBoone experiment */
#define	ABORT_NUMI		(MACHINE_NUMI)	/* NUMI experiment */

#define	ABORT_MAX_MODULES	50		/* maximum number of abort modules per system */

#define	ABORT_MAX_NAME_LENGTH	(DEVICE_NAME_LEN)	/* maximum abort module name length */

#define	ABORT_ALL_INPUTS	0		/* do all abort inputs */
#define	ABORT_NO_INPUTS		-1		/* do no abort inputs */

#define	ABORT_MIN_INPUT_NUMBER	1		/* minimum abort input number */
#define	ABORT_MAX_INPUT_NUMBER	8		/* maximum abort input number */

#define	ABORT_INPUTS_PER_MODULE	8		/* abort inputs per module */

#define	ABORT_NO_MASK		0		/* unmask this input */
#define	ABORT_UNMASK_IT		0		/* unmask this input */
#define	ABORT_MASK_IT		1		/* mask this input */

#define	ABORT_SOURCE_OFF	0		/* turn off this current source */
#define	ABORT_SOURCE_ON		1		/* turn on this current source */

#define	ABORT_BLM		0		/* BLM abort group */
#define	ABORT_DFG		1		/* DFG abort group */
#define	ABORT_RFSUM		2		/* RF sum abort group */
#define	ABORT_KICKER_C0		3		/* C0 abort kicker group */
#define	ABORT_SVX		4		/* SVX group */
#define	ABORT_SY		5		/* SY input group */
#define	ABORT_SY_INPUT		5		/* SY input group */
#define	ABORT_EXTRACT		6		/* EXTRACTION group */
#define	ABORT_KICKER_A0		7		/* A0 abort kicker group */
#define	ABORT_RING_QPM		8		/* normal ring QPMS */
#define	ABORT_VACUUM		9		/* vacuum group */
#define	ABORT_D48_KICKER	10		/* D48 Kicker group */
#define	ABORT_ALL_TEV		11		/* Tevatron group */
#define	ABORT_ALL_MR		12		/* Main Ring group */
#define	ABORT_ALL_SY		13		/* Switchyard group */
#define	ABORT_ALL_PBAR		14		/* P-bar group */
#define	ABORT_ALL_MUON		14		/* Muon campus group */
#define	ABORT_ALL_BOOSTER	15		/* Booster group */
#define	ABORT_E17_KICKER	16		/* E17 Kicker group */
#define	ABORT_ALL_MI		17		/* Main Injector group */
#define	ABORT_ALL_RECYCLER	18		/* Recycler group */
#define	ABORT_ALL_P1		19		/* P1 line group */
#define	ABORT_ALL_P2		20		/* P2 line group */
#define	ABORT_ALL_P3		21		/* P3 line group */
#define	ABORT_P3_LINE_INPUT	22		/* P3 line input group */
#define	ABORT_PBAR_SOFTWARE_ABORT	23	/* Pbar software abort group */
#define	ABORT_MUON_SOFTWARE_ABORT	23	/* Muon campus software abort group */
#define	ABORT_AP1_8_GEV_PS	24		/* AP1 line 8 GeV power supply group */
#define	ABORT_AP1_120_GEV_PS	25		/* AP1 line 120 GeV power supply group */
#define ABORT_ALL_MINIBOONE	26		/* MiniBooNE group */
#define ABORT_ALL_NUMI		27		/* NuMI group */
#define	ABORT_AP1_120_C204	28		/* AP1 line 120 GeV analog (C204) group */

#define	ABORT_MODULE_TYPE_UNKNOWN	(-1)	/* unknown abort module type */
#define	ABORT_MODULE_TYPE_C200		0	/* CAMAC 200 abort module */
#define	ABORT_MODULE_TYPE_IP		1	/* IP abort module */

#define	ABORT_MODULE_DB_NAME_LENGTH	32	/* database module name length */

typedef struct ABORT_MODULE_DATA
    {
    int		entry_number;
    char	name[ABORT_MODULE_DB_NAME_LENGTH];
    int		name_length;
    char	alt_name[ABORT_MODULE_DB_NAME_LENGTH];
    int		alt_name_length;
    int		device_index;
    int		module_type;
    int		event_device_index;
    int		comm_device_index;
    int		survey_row;
    int		survey_column;
    int		link_row;
    int		link_column;
    int		module_id;
    } __attribute__((packed)) ABORT_MODULE_DATA;

typedef struct ABORT_INPUT_STATUS
    {
    short	status;
    short	inputs[ABORT_INPUTS_PER_MODULE];
    } __attribute__((packed)) ABORT_INPUT_STATUS;

typedef struct ABORT_INPUT_TYPE
    {
    short	status;
    unsigned char	inputs[ABORT_INPUTS_PER_MODULE];
    } __attribute__((packed)) ABORT_INPUT_TYPE;

typedef struct ABORT_CURRENT_SOURCE
    {
    short	status;
    unsigned char	inputs[ABORT_INPUTS_PER_MODULE];
    } __attribute__((packed)) ABORT_CURRENT_SOURCE;

typedef struct ABORT_INPUT_MASK
    {
    short	status;
    unsigned char	inputs[ABORT_INPUTS_PER_MODULE];
    } __attribute__((packed)) ABORT_INPUT_MASK;

typedef struct ABORT_LINK_STATUS
    {
    short	status;
    unsigned char	abort_present;
    unsigned char	upstream_permit;
    unsigned char	tclk_present;
    unsigned char	beam_gate_on;
    unsigned char	high_level_permit;
    unsigned char	fifo_data_present;
    unsigned char	fifo_full;
    unsigned char	unused;
    } __attribute__((packed)) ABORT_LINK_STATUS;

/*
** BSSB ...
*/
#define	BSSB_PERMIT_LINAC		1		/* Linac */
#define	BSSB_PERMIT_BOOSTER		2		/* Booster */
#define	BSSB_PERMIT_RECYCLER		3		/* Recycler */
#define	BSSB_PERMIT_MAIN_INJECTOR	4		/* Main Injector */
#define	BSSB_PERMIT_SWYD		5		/* Switchyard */
#define	BSSB_PERMIT_P1_LINE		6		/* P1 line */
#define	BSSB_PERMIT_P2_LINE		7		/* P2 line */
#define	BSSB_PERMIT_BOONE		9		/* BooNE experiment */
#define	BSSB_PERMIT_NUMI		10		/* NUMI experiment */
#define	BSSB_PERMIT_MUON		11		/* Muon campus */
#define	BSSB_PERMIT_MTA			12		/* MTA */
#define	BSSB_PERMIT_LBNF		13		/* LBNF experiment */

/*
** get_ramp_times ...
*/
#define	RMPEV_42		0		/* Tev start of ramp */
#define	RMPEV_43		1		/* Tev start of front porch */
#define	RMPEV_44		2		/* Tev end of front porch */
#define	RMPEV_45		3		/* Tev start of flattop */
#define	RMPEV_46		4		/* Tev end of flattop */
#define	RMPEV_31		5		/* Switchyard reset */
#define	RMPEV_60		6		/* Tev DFG new event */
#define	RMPEV_61		7		/* Tev DFG start event */
#define	RMPEV_62		8		/* Tev DFG stop event */
#define	RMPEV_63		9		/* Tev DFG continue event */

/*
** camac_io ...
*/
#define	CAMAC_ERROR_TEXT_LEN	21		/* maximum length of a CAMAC error message */

#define	CAMAC_OK		0		/* success */
#define	CAMAC_NO_Q		-1		/* no Q */
#define	CAMAC_NO_X		-2		/* no X */
#define	CAMAC_ARBCON		-3		/* arbitration conflict (obsolete) */
#define	CAMAC_NO_SRP		-4		/* no SRP */
#define	CAMAC_TIMEOUT		-5		/* timeout */
#define	CAMAC_PROTERR		-6		/* protocol error */
#define	CAMAC_ECHOCHK		-7		/* echo check */
/* #define	CAMAC_LINKERR		-8 */		/* link error (obsolete meaning) */
#define	CAMAC_PARITYERR		-8		/* parity error */
/* #define	CAMAC_BUSY		-9 */		/* busy (obsolete meaning) */
#define	CAMAC_SLC_TIMEOUT	-9		/* serial link controller timeout */
#define	CAMAC_REJECT		-10		/* reject */
#define	CAMAC_BAD_NAF		-125		/* invalid NAF requested */
#define	CAMAC_PORTA_XERROR	-126		/* port A transmit error */
#define	CAMAC_BADARB		-127		/* block transfer arbitration error */
#define	CAMAC_CC_BADSTATUS	-128		/* invalid status from crate controller */

/*
** rampcard_shaper ...
*/
typedef struct RAMPCARD_EDIT_DATA
    {
    float	*x_coords;		/* array of X coordinate values */
    float	*y_coords;		/* array of Y coordinate values */
    int		max_table_len;		/* maximum possible number of points in table */
    int		table_len;		/* present number of points in table */
    } __attribute__((packed)) RAMPCARD_EDIT_DATA;

typedef struct RAMPCARD_LIMIT_DATA
    {
    float	minimum_x;		/* for axes or data range */
    float	minimum_y;
    float	maximum_x;
    float	maximum_y;
    } __attribute__((packed)) RAMPCARD_LIMIT_DATA;

#define	RAMPCARD_INITIAL_DATA	11	/* original (passed in) data values */
#define	RAMPCARD_EDITED_DATA	12	/* edited (modified) data values */

typedef struct RAMPCARD_TABLE_DATA
    {
    float	*x;			/* X coordinate data buffer */
    float	*y;			/* Y coordinate data buffer */
    int		max_table_len;		/* maximum possible number of points in table */
    int		table_len;		/* actual number of points in table */
    int		data_type;		/* type of data (initial or edited) */
    } __attribute__((packed)) RAMPCARD_TABLE_DATA;

/* typedef void (*rs_user_function)(RAMPCARD_EDIT_DATA *ramp_data,
				void *function_data); */	/* rampcard shaper user function */

typedef void (*rs_load_function)(RAMPCARD_TABLE_DATA *table_data,
				 void *function_data);	/* rampcard shaper load/restore function */

typedef struct RAMPCARD_EXT_USR_FNS_TYP
    {
    int		rcs_intern_fn_idx;	/* index for selecting rcs internal function */
    rs_load_function	ext_usr_fn;	/* pointer to external user function */
    void	*ext_usr_fn_data;	/* pointer to external user function data array */
    } __attribute__((packed)) RAMPCARD_EXT_USR_FNS_TYP;

typedef struct RAMPCARD_CONTROL_WINDOW_TYP
    {
    int		control_win_active;	/* switch to activate pop-up window */
    int		load_fn_active;		/* switch to activate the load function */
    int		restore_fn_active;	/* switch to activate the restore function */
    RAMPCARD_EXT_USR_FNS_TYP	*ext_usr_fn_struc;	/* pointer to external user function structures */
    char	*edit_win_txt_con_win_line;	/* text string for the control window line in the edit window */
    int		control_win_line;	/* row for locating control window */
    int		control_win_col;	/* column for locating control window */
    int		control_win_nitems;	/* number of menu items in the control window */
    char	**control_win_menu_txt;	/* text strings for the control window menu items */
    char	*control_win_title;	/* text string for the control window title */
    } __attribute__((packed)) RAMPCARD_CONTROL_WINDOW_TYP;

/*
**  Curve Editor
*/
typedef struct CURVE_POINT
    {
    float	x;
    float	y;
    } __attribute__((packed)) CURVE_POINT;

typedef struct CURVE_LIMIT_DATA
    {
    float	minimum_x;		/* for axes or data range */
    float	minimum_y;
    float	maximum_x;
    float	maximum_y;
    } __attribute__((packed)) CURVE_LIMIT_DATA;

#define	CURVE_INITIAL_DATA	11	/* original (passed in) data values */
#define	CURVE_EDITED_DATA	12	/* edited (modified) data values */

typedef struct CURVE_EDIT_DATA
    {
    float	*x;			/* X coordinate data buffer */
    float	*y;			/* Y coordinate data buffer */
    int		max_table_len;		/* maximum possible number of points in table */
    int		table_len;		/* actual number of points in table */
    int		data_type;		/* type of data (initial or edited) */
    } __attribute__((packed)) CURVE_EDIT_DATA;

typedef int (*curve_edit_user_function)(CURVE_EDIT_DATA *curve_data,
					void *function_data, int curve_number);	/* curve editor user function */

typedef struct CURVE_PHASE_LIMIT_DATA
    {
    float	minimum_y;
    float	maximum_y;
    float	warp_tolerance;
    } __attribute__((packed)) CURVE_PHASE_LIMIT_DATA;

typedef struct CURVE_EDITOR_MARKER_DATA
    {
    int		plane;
    int		color;
    double	coordinate;
    } __attribute__((packed)) CURVE_EDITOR_MARKER_DATA;

#define	CURVE_EDITOR_MAX_WAVEFORMS	4

typedef struct CURVE_EDITOR_WAVEFORM_DATA
    {
    char	*name;
    int		num_points;
    int		max_points;
    CURVE_POINT	*points;
    char	*x_axis_label;
    char	*y_axis_label;
    CURVE_LIMIT_DATA	*plot_limit_data;
    CURVE_LIMIT_DATA	*limit_data;
    int		num_markers;
    CURVE_EDITOR_MARKER_DATA	*marker_data;
    CURVE_PHASE_LIMIT_DATA	*phase_limit_data;
    } __attribute__((packed)) CURVE_EDITOR_WAVEFORM_DATA;

typedef int (*ce_auto_scale_function)(CURVE_LIMIT_DATA *limit_data);	/* curve editor auto scale function */

typedef void (*ce_range_bounds_function)(CURVE_LIMIT_DATA *limit_data);	/* curve editor range bounds function */

typedef int (*ce_is_phase_mode_function)(CURVE_PHASE_LIMIT_DATA *limit_data);	/* curve editor is phase mode function */

typedef int (*ce_marker_function)(int *num_markers,
				  CURVE_EDITOR_MARKER_DATA **marker_data);	/* curve editor marker function */

typedef int (*ce_restore_function)(CURVE_EDIT_DATA *curve_data,
				   void *function_data, int curve_number);	/* curve editor restore function */

/*
**  Function pointer for read_tagged_value_file
*/
typedef void (*tag_file_function)(char *tag, char *value, void *func_data);

/*
**  Function pointer for rampcard_shaper.cpp
*/
/*typedef void (*void_empty_function)( ); see in cns_data_structs.h*/
typedef void (*void_void_function)(void *);
typedef int (*rs_table_query_function)(int , int, int *,int *,int *,int *);
typedef int (*rs_auto_scale_function)(void *);
typedef void (*rs_range_bounds_function)(void *);
typedef int  (*rs_alt_query_function)();
typedef void (*void_int_function)(int);
typedef void (*rampcard_shaper_user_function)(struct RAMPCARD_EDIT_DATA *, void *);

#define	CURVE_OPT_NONE		0		/* no options selected */
#define	CURVE_OPT_Y_MOVE_ONLY	1		/* only move points in the Y plane */
#define	CURVE_OPT_X_MOVE_ONLY	2		/* only move points in the X plane */
#define	CURVE_OPT_CLEAN_UP	4		/* clean up the screen upon exit */
#define	CURVE_OPT_NO_INSERT_DELETE	8	/* don't allow insertion or deletion of points */

/*
**  ACL routines
*/
#define	ACL_EDIT_OPT_CLEAR		0	/* start with an empty edit window */
#define	ACL_EDIT_OPT_EDIT_EXISTING	1	/* display the current file and edit it */
#define	ACL_EDIT_OPT_EDIT_FILE		0	/* allow file editing (default) */
#define	ACL_EDIT_OPT_DISPLAY_ONLY	2	/* don't allow editing, just display the file */
#define	ACL_EDIT_OPT_NO_CREATE_DIALOG	4	/* don't display a dialog asking the user if he wants to create a file */

#define	ACL_OPT_ALLOW_NEW	4		/* allow for a new file */

/*
**  Database routines
*/
/* These are the data types returned by sp_columns (db_column_info_c). */

#define	DB_COL_TYPE_CHAR	1		/* char data type */
#define	DB_COL_TYPE_NUMERIC	2		/* numeric data type */
#define	DB_COL_TYPE_DECIMAL	3		/* decimal data type */
#define	DB_COL_TYPE_INT		4		/* int data type */
#define	DB_COL_TYPE_SMALLINT	5		/* smallint data type */
#define	DB_COL_TYPE_FLOAT	6		/* float data type */
#define	DB_COL_TYPE_REAL	7		/* real data type */
#define	DB_COL_TYPE_DOUBLE	8		/* double data type */
#define	DB_COL_TYPE_DATETIME	11		/* datetime data type */
#define	DB_COL_TYPE_VARCHAR	12		/* varchar data type */
#define	DB_COL_TYPE_BINARY	-2		/* binary data type */
#define	DB_COL_TYPE_VARBINARY	-3		/* varbinary data type */
#define	DB_COL_TYPE_TINYINT	-6		/* tinyint data type */

#define	DB_OPT_NONE		0		/* no options selected */
#define	DB_OPT_USE_PASSED_HANDLE	1	/* use passed database handle */
#define	DB_OPT_RETURN_HANDLE	2		/* return database handle */
#define	DB_OPT_CLOSE_CONNECTION	4		/* close present database connection */

/*
**  Logger routines
*/
#define	LOGGER_OPT_NONE			0	/* no options selected */
#define	LOGGER_OPT_SAME_TIMESTAMP	1	/* use the same timestamp */

/*
**  Wait routines
*/
#define	WAIT_FOR_ON			1	/* wait for on status */
#define	WAIT_FOR_OFF			2	/* wait for off status */
#define	WAIT_FOR_READY			4	/* wait for ready status */
#define	WAIT_FOR_TRIPPED		8	/* wait for tripped status */
#define	WAIT_FOR_REMOTE			0x10	/* wait for remote status */
#define	WAIT_FOR_LOCAL			0x20	/* wait for local status */
#define	WAIT_FOR_POSITIVE		0x40	/* wait for positive status */
#define	WAIT_FOR_NEGATIVE		0x80	/* wait for negative status */
#define	WAIT_FOR_RAMP			0x100	/* wait for ramp status */
#define	WAIT_FOR_DC			0x200	/* wait for DC status */

typedef void (*wait_update_function)(void *callback_data, float reading,
				     int status);	/* wait_for_device(_status) user supplied function */

/*
**  Sequencer routines
*/
#define	SEQ_MODE_NAME_LEN		30	/* maximum length of a Sequencer mode name */
#define	SEQ_FILE_NAME_LEN		80	/* maximum length of a Sequencer file name */
#define	SEQ_FILE_ACTION_NAME_LEN	32	/* maximum length of a Sequencer file action name */

#define	SEQ_MODE_COLLIDER		1	/* Collider Sequencer */
#define	SEQ_MODE_PBAR			2	/* Pbar Sequencer */
#define	SEQ_MODE_STUDIES		3	/* Studies Sequencer */
#define	SEQ_MODE_OP_TRAINING		4	/* Operator Training Sequencer */
#define	SEQ_MODE_PBAR_STUDIES		5	/* Pbar Studies Sequencer */
#define	SEQ_MODE_BOOSTER		6	/* Booster Sequencer */
#define	SEQ_MODE_TEV_MODE_CHANGER	7	/* Tev Mode Changer Sequencer */
#define	SEQ_MODE_COLLIDER_BACKUP	8	/* Collider Backup Sequencer */
#define	SEQ_MODE_SWITCHYARD_BACKUP	9	/* Switchyard Backup Sequencer */
#define	SEQ_MODE_PBAR_BACKUP		10	/* Pbar Backup Sequencer */
#define	SEQ_MODE_SCHEDULER		11	/* Scheduler Sequencer */
#define	SEQ_MODE_RECYCLER		12	/* Recycler Sequencer */
#define	SEQ_MODE_MAIN_INJECTOR		13	/* Main Injector Sequencer */
#define	SEQ_MODE_MINIBOONE		14	/* MiniBooNE Sequencer */
#define	SEQ_MODE_NUMI			15	/* NuMI Sequencer */
#define	SEQ_MODE_RECYCLER_BACKUP	16	/* Recycler Backup Sequencer */
#define	SEQ_MODE_PBAR_ANNEX		17	/* Pbar Annex Sequencer */
#define	SEQ_MODE_ELECTRON_COOLING	18	/* Electron Cooling Sequencer */
#define	SEQ_MODE_PBAR_OPS		19	/* Pbar Ops Sequencer */
#define	SEQ_MODE_RF_TEST		20	/* RF Test Sequencer */
#define	SEQ_MODE_CDF			21	/* CDF Sequencer */
#define	SEQ_MODE_CMTF			22	/* CMTF Sequencer */
#define	SEQ_MODE_NML			23	/* NML Sequencer */
#define	SEQ_MODE_PHOTO_INJECTOR		24	/* Photo Injector Sequencer */
#define	SEQ_MODE_SWITCHYARD		25	/* Switchyard Sequencer */
#define	SEQ_MODE_MTA			26	/* MTA Sequencer */
#define	SEQ_MODE_MUON			27	/* Muon Sequencer */
#define	SEQ_MODE_LINAC			28	/* Linac Sequencer */
#define	SEQ_MODE_PXIE_ION_SOURCE	29	/* PXIE Ion Source Sequencer */
#define	SEQ_MODE_PXIE_RFQ		30	/* PXIE RFQ Sequencer */
#define	SEQ_MODE_PXIE_BUNCHER		31	/* PXIE Buncher Sequencer */
#define	SEQ_MODE_CMTS1			32	/* CMTS1 Sequencer */

#define	SEQ_MODE_MAX			32	/* maximum Sequencer mode */

#define	SEQ_OPT_NONE			0	/* no options selected */
#define	SEQ_OPT_ABORT_IF_BYPASSED	1	/* abort execution if there are bypassed commands */
#define	SEQ_OPT_SUPPRESS_SETTINGS	2	/* suppress settings */
#define	SEQ_OPT_SUPPRESS_ACTIONS	4	/* suppress all actions */

#define	SEQ_SR_FILE_NONE		(-1)	/* null Save/Restore file */

typedef struct SEQUENCER_FILE_FOUND_DEVICE_DATA
    {
    int		mode_id;		/* Sequencer mode ID */
    char	mode_name[SEQ_MODE_NAME_LEN+2];	/* Sequencer mode name */
    int		file_number;		/* file number */
    char	file_name[SEQ_FILE_NAME_LEN+2];	/* file name */
    int		entry_number;		/* file entry number */
    short	property;		/* device property */
    int		array_index;		/* device array index */
    short	action;			/* desired action */
    char	action_name[SEQ_FILE_ACTION_NAME_LEN+2];	/* desired action name */
    } __attribute__((packed)) SEQUENCER_FILE_FOUND_DEVICE_DATA;

#define	SEQ_FILE_NUM_DEVICE_VALUES	2	/* number of values for a device in a Sequencer file */
#define	SEQ_FILE_DEVICE_BINARY_VALUE_SIZE	8	/* binary value size for a device in a Sequencer file */

typedef struct SEQUENCER_FILE_DEVICE_DATA
    {
    int		entry_number;		/* file entry number */
    int		device_index;		/* device index */
    short	property;		/* device property */
    int		array_index;		/* device array index */
    short	action;			/* desired action */
    char	action_name[SEQ_FILE_ACTION_NAME_LEN+2];	/* desired action name */
    int		last_status;		/* last execution status */
    float	value[SEQ_FILE_NUM_DEVICE_VALUES];	/* float values */
    int		int_value[SEQ_FILE_NUM_DEVICE_VALUES];	/* integer values */
    unsigned char	binary_value[SEQ_FILE_DEVICE_BINARY_VALUE_SIZE];	/* binary values */
    } __attribute__((packed)) SEQUENCER_FILE_DEVICE_DATA;

typedef struct SEQUENCER_FILE_HEADER_DATA
    {
    int		file_number;			/* file number */
    char	file_name[SEQ_FILE_NAME_LEN+2];	/* file name */
    int		num_bypassed;			/* number of bypassed commands */
    char	modify_date[DATE_STRING_LEN];	/* desired action name */
    } __attribute__((packed)) SEQUENCER_FILE_HEADER_DATA;

/*
**  MJY file handling routines
*/
#define	MJY_DIGITIZER_TYPE_DEFAULT	0
#define	MJY_DIGITIZER_TYPE_WAVERUNNER	1
#define	MJY_DIGITIZER_TYPE_VXI11	2

#define	MJY_FILE_OPT_NONE		0
#define	MJY_FILE_OPT_DOUBLE_VALUES	1

#define	MJY_FILE_TITLE_LEN		60

typedef struct MJY_FILE_HEADER_DATA
    {
    char	title[MJY_FILE_TITLE_LEN+2];	/* file title */
    unsigned int	date;			/* time and date at data acquisition */
    int		trigger_event;			/* trigger clock event number */
    int		trigger_delay;			/* trigger clock event delay (t0=usec) */
    int		turns_per_trigger;		/* measured number of turns between triggers */
    double	time_last_measurement;		/* time of last trigger - t0 (sec) */
    double	trigger_11th;			/* time at the 11th trigger */
    int		num_channels;			/* number of active channels */
    int		scope_type;
    } __attribute__((packed)) MJY_FILE_HEADER_DATA;

#define	MJY_FILE_MAX_CHANNELS	4
#define	MJY_CHANNEL_LABEL_LEN	41

typedef struct MJY_FILE_CHANNEL_DATA
    {
    char	label[MJY_CHANNEL_LABEL_LEN+2];	/* channel label */
    int		channel_present;		/* data present flag */
    double	trace_offset;			/* trace time offset in nsec */
    } __attribute__((packed)) MJY_FILE_CHANNEL_DATA;

typedef struct MJY_FILE_WRITE_HEADER_DATA
    {
    char	title[MJY_FILE_TITLE_LEN+2];	/* file title */
    unsigned int	date;			/* time and date at data acquisition */
    int		trigger_event;			/* trigger clock event number */
    int		trigger_delay;			/* trigger clock event delay (t0=usec) */
    int		azimuthal_delay;		/* azimuthal delay (nsec) */
    int		turns_per_trigger;		/* number of turns between triggers */
    double	time_last_measurement;		/* time of last trigger - t0 (sec) */
    double	trigger_11th;			/* time at the 11th trigger */
    int		scope_type;
    } __attribute__((packed)) MJY_FILE_WRITE_HEADER_DATA;

typedef struct MJY_FILE_WRITE_CHANNEL_DATA
    {
    char	label[MJY_CHANNEL_LABEL_LEN+2];	/* channel label */
    int		channel_present;		/* data present flag */
    int		polarity;
    double	vscale;
    double	voffset;
    double	trace_offset;			/* trace time offset in nsec */
    } __attribute__((packed)) MJY_FILE_WRITE_CHANNEL_DATA;

/*
** Beam Permit System (BPS) log handling routines
*/

#define	BPSLOG_SYSTEM_NAME_LEN		16
#define	BPSLOG_PERMIT_STATUS_LEN	18
#define	BPSLOG_MODULE_NAME_LEN		18
#define	BPSLOG_NUM_INPUTS_PER_MODULE	8
#define	BPSLOG_MESSAGE_LEN		80

typedef struct BPSLOG_DATA
    {
    char	timestamp[DATE_STRING_LEN];	/* timestamp */
    unsigned int	trip_entry;
    int		module_entry;
    char	system_name[BPSLOG_SYSTEM_NAME_LEN+2];	/* system name */
    short	system_id;
    char	module_name[BPSLOG_MODULE_NAME_LEN+2];	/* module name */
    int		module_id;			/* module ID */
    char	permit_status[BPSLOG_PERMIT_STATUS_LEN+2];	/* permit status */
    char	input_status[BPSLOG_NUM_INPUTS_PER_MODULE];
    char	mask_values[BPSLOG_NUM_INPUTS_PER_MODULE];
    char	message[BPSLOG_MESSAGE_LEN+2];	/* message */
    } __attribute__((packed)) BPSLOG_DATA;


/******************************************************************************/
/*
**	function prototypes for miscellaneous routines in the
**	UL_CBSAUX library
*/
/******************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

int abort_blm_mask_c(int machine, int mask_it);
int abort_curr_source_control_c(int command, int *device_indices,
				int *inputs, short *errs, int numdev=1);
int abort_get_device_c(int *machines, char *names, int *device_indices,
		       short *errors, int num_devices=1,
		       int *module_types=(int *) NULL);
int abort_get_maximum_name_lengths(int *system_length,
				   int *module_length=(int *) NULL,
				   int *input_length=(int *) NULL,
				   int *source_length=(int *) NULL,
				   int *main_input_length=(int *) NULL);
int abort_get_permit_log_max_system_length(int *system_length);
int abort_loop_is_up_c(int machine, char const *data_event, int *is_up);
int abort_mask_control_c(int mask_it, int *device_indices, int *inputs,
			 short *errors, int numdev=1);
int abort_mask_group_c(int mask_it, int group);
int abort_read_max_permit_log_entry_number(unsigned int *max_entry);
int abort_read_permit_log_entries_c(unsigned int start_entry,
				    unsigned int end_entry,
				    int *num_entries,
				    BPSLOG_DATA **entries=(BPSLOG_DATA **) NULL);
int abort_read_permit_log_entries_by_date_c(unsigned int start_time,
					    unsigned int end_time,
					    int *num_entries,
					    BPSLOG_DATA **entries=(BPSLOG_DATA **) NULL);
int abort_read_single_module_c(int device_index, char const *data_event,
			       ABORT_INPUT_STATUS *input_status,
			       ABORT_INPUT_TYPE *input_type,
			       ABORT_INPUT_MASK *input_mask,
			       ABORT_CURRENT_SOURCE *current_source,
			       ABORT_LINK_STATUS *link_status,
			       int module_type=0);
int abort_read_single_module_by_name_c(int machine, char const *module_name,
				       char const *data_event,
				       ABORT_INPUT_STATUS *input_status,
				       ABORT_INPUT_TYPE *input_type,
				       ABORT_INPUT_MASK *input_mask,
				       ABORT_CURRENT_SOURCE *current_source,
				       ABORT_LINK_STATUS *link_status,
				       int module_type=0);
int abort_system_devices_c(int machine, int *num_modules, int *device_indices,
			   int *module_types=(int *) NULL);
int abort_system_display_coords_c(int machine, int *num_modules,
				  int *display_rows,
				  int *display_columns, int config_id=0);
int abort_system_get_id_c(int machine, int *system_id);
int abort_system_info_c(int machine, int *num_modules, char *module_names,
			int *name_length, int *device_indices,
			int config_id=0, int *module_types=(int *) NULL);
int abort_system_module_data_c(int machine, int *num_modules,
			       ABORT_MODULE_DATA *module_data);
int abort_system_num_modules_c(int machine, int *num_modules, int config_id=0);
int abort_system_reset_c(int machine);
int acl_file_edit_c(int top_row, int left_column,
		    char *file_name, int file_type, int num_rows,
		    int num_columns, unsigned int options,
		    char *path);
int acl_file_menu_c(int top_row, int left_column, char *title,
		    unsigned int filter, unsigned int options,
		    char *file_name, int file_type, char *path);
int bssb_permit_status_c(int system, int *is_present,
			 char const *data_event=(char *) NULL);
int bssb_permit_status_list_c(int num_systems, int const *systems,
			      int *is_present,
			      char const *data_event=(char *) NULL);
int check_power_leads_c(int location, int type);
int cns_set_is_enabled(void);
int cns_flag_set_enable(void);
void curve_editor_init(int (*auto_scale)(CURVE_LIMIT_DATA*),
		       void (*range_bounds)(CURVE_LIMIT_DATA*),
		       ce_is_phase_mode_function is_phase_mode=(ce_is_phase_mode_function) NULL,
		       ce_marker_function marker_func=(ce_marker_function) NULL,
		       ce_restore_function restore_func=(ce_restore_function) NULL,
		       void *restore_func_data=(void *) NULL);
int curve_editor(int num_points, CURVE_POINT *points, int max_points,
		 char *x_axis_label, char *y_axis_label,
		 unsigned int options,
		 curve_edit_user_function user_function=(curve_edit_user_function) NULL,
		 void *function_data=(void *) NULL,
		 curve_edit_user_function switch_function=(curve_edit_user_function) NULL,
		 void *switch_function_data=(void *) NULL,
		 char *switch_label=(char *) NULL,
		 char *title=(char *) NULL);
int curve_editor_multiple_waveforms_c(int num_waveforms,
				      CURVE_EDITOR_WAVEFORM_DATA *waveform_data,
				      unsigned int options,
				      curve_edit_user_function user_func=(curve_edit_user_function) NULL,
				      void *function_data=(void *) NULL,
				      curve_edit_user_function switch_function=(curve_edit_user_function) NULL,
				      void *switch_function_data=(void *) NULL,
				      char *switch_label=(char *) NULL,
				      char *title=(char *) NULL);
int db_column_info_c(char *server, char *table_name,
		     int *num_columns, DB_COLUMN_INFO *column_info);
int db_ctime_to_db_date_c(unsigned int seconds, DB_DATETIME_DATA *db_date);
int db_retrieve_rows_c(char *select_string,
		       unsigned int bytes_per_row,
		       unsigned int options, db_handle_t **handle,
		       char *server, void **rows,
		       unsigned int *num_rows);
int db_table_name_parse_c(char *source_string, int source_length,
			  char *database_string, int database_length,
			  char *owner_string, int owner_length,
			  char *table_string, int table_length,
			  unsigned int options);
int delete_file(char *file_name);
int display_camac_crate(int fe, int crate, int screen, int interactive);
int emitt_dp_tev(float *sigmas, int step, int plane, float *emittance,
		 float *dp);
int is_valid_dabbel_user(char *user_name);
int logger_client_log_values_c(int node, int num_devices,
			       int *device_indices, float *values,
			       unsigned int *timestamps,
			       unsigned int options);
int logger_menu(int row, int col, char **log_name, char *your_item,
		int order_by_node=FALSE);
int logger_menu_items(char **item_list, int *item_len, int **node_table,
		      int **hist_id, char *user_item,
		      int order_by_node=FALSE);
int logger_node_id(int to_id, int *node, int *hist_id, char **log_name);
int power_leads_off_c(int location, int type, int check_tev=TRUE);
int power_leads_on_c(int location, int type, int check_tev=FALSE);
int print_file(char *file_name, char *queue);
int print_file_detached(char *file_name, char *queue);
void qpm_hscode(char *house_name, short *house_code,
		short *translation, short *node=(short *) NULL,
		short *ret_status=(short *) NULL);
int rampcard_shaper(int device_index, int table_type, float *data,
		    rampcard_shaper_user_function user_function=(rampcard_shaper_user_function) NULL,
		    void *f_data=(void *) NULL,
		    RAMPCARD_CONTROL_WINDOW_TYP *ld_rs=(RAMPCARD_CONTROL_WINDOW_TYP *) NULL);
void rampcard_shaper_init(int (*alt_query)(), int (*auto_scale)(void *),
			  void (*range_bounds)(void *));
int read_mjy_data_file_c(char *file_name, MJY_FILE_HEADER_DATA *header_data,
			 MJY_FILE_CHANNEL_DATA *channel_data,
			 double *horz_increment=(double *) NULL,
			 int max_traces=0, int mpnts_per_trace=0,
			 int *num_traces=(int *) NULL,
			 int *pnts_per_trace=(int *) NULL,
			 unsigned int options=MJY_FILE_OPT_NONE,
			 unsigned int **timestamps=(unsigned int **) NULL,
			 void **channel_1=(void **) NULL,
			 void **channel_2=(void **) NULL,
			 void **channel_3=(void **) NULL,
			 void **channel_4=(void **) NULL);
int read_num_booster_turns_c(int reset_event, float *num_turns);
int read_tagged_value_file(char *file_name, tag_file_function tag_file_func,
			   void *func_data);
int rempgm_sequence_check(int *tc, int *fileno, int *store_num);
int sequencer_file_execute_c(int sequencer_mode, int file_number,
			     int sr_file, unsigned int options=SEQ_OPT_NONE,
			     int *num_entries=(int *) NULL,
			     SEQUENCER_FILE_DEVICE_DATA **entry_data=(SEQUENCER_FILE_DEVICE_DATA **) NULL,
			     int *num_bypassed=(int *) NULL,
			     char *file_name=(char *) NULL);
int sequencer_file_find_device_c(int device_index,
				 int *num_entries,
				 SEQUENCER_FILE_FOUND_DEVICE_DATA **device_data=(SEQUENCER_FILE_FOUND_DEVICE_DATA **) NULL);
int sequencer_file_get_directory_info_c(int sequencer_mode,
					int *num_files,
					SEQUENCER_FILE_HEADER_DATA **entry_data=(SEQUENCER_FILE_HEADER_DATA **) NULL);
int sequencer_file_get_entries_c(int seq_mode, int file_number,
				 int *num_entries,
				 SEQUENCER_FILE_DEVICE_DATA **entry_data=(SEQUENCER_FILE_DEVICE_DATA **) NULL,
				 char *file_name=(char *) NULL);
int sequencer_file_has_sr_restore_commands_c(int sequencer_mode,
					     int file_number);
int sequencer_file_name_to_number_c(int sequencer_mode,
				    char const *file_name,
				    int *file_number);
int sequencer_file_num_bypassed_commands_c(int sequencer_mode, int file_number,
					   int *num_bypassed);
int sequencer_file_number_exists_c(int sequencer_mode, int file_number);
int sequencer_maximum_mode_number(void);
int sequencer_mode_to_name_c(int mode, char *sequencer_name);
int sequencer_name_to_mode(char const *sequencer_name, int *mode);
int set_num_booster_turns_c(int reset_event, float num_turns);
int tclk_event_times_c(float *times, int max_times, int event = EVENT_NULL);
int tev_ramp_times_c(int event, float *time);
int wait_for_device(int *device_index, double *minimum, double *maximum,
		    int *wait, int *num_tries=(int *) NULL,
		    wait_update_function update_func=(wait_update_function) NULL,
		    void *func_data=(void *) NULL);
int wait_for_device_c(int device_index, double minimum, double maximum,
		      int wait, int num_tries=1,
		      wait_update_function update_func=(wait_update_function) NULL,
		      void *func_data=(void *) NULL);
int wait_for_device_status_c(int device_index, int status_value,
			     int wait, int num_tries=1,
			     wait_update_function update_func=(wait_update_function) NULL,
			     void *func_data=(void *) NULL);
int wait_time_c(int wait_secs, int row=0, int col=0,
		char *user_text=(char *) NULL);
int who_what_why_c(int top_row, int left_column, char *log_file,
		   char *message_text);
int write_mjy_data_file_c(char const *file_name,
			  MJY_FILE_WRITE_HEADER_DATA const *header_info,
			  int num_channels,
			  MJY_FILE_WRITE_CHANNEL_DATA const *channel_info,
			  double horz_increment, int num_traces,
			  int pnts_per_trace, unsigned int options,
			  unsigned int *timestamps=(unsigned int *) NULL,
			  void const *chan_1=(void *) NULL,
			  void const *chan_2=(void *) NULL,
			  void const *chan_3=(void *) NULL,
			  void const *chan_4=(void *) NULL);

#ifdef __cplusplus
}
#endif


/******************************************************************************/
/*
**	equivalent name definitions
*/
/******************************************************************************/

#define	ABORT_BLM_MASK_C		abort_blm_mask_c
#define	ABORT_CURR_SOURCE_CONTROL_C	abort_curr_source_control_c
#define	ABORT_GET_DEVICE_C		abort_get_device_c
#define	ABORT_GET_MAXIMUM_NAME_LENGTHS	abort_get_maximum_name_lengths
#define	ABORT_GET_PERMIT_LOG_MAX_SYSTEM_LENGTH	abort_get_permit_log_max_system_length
#define	ABORT_LOOP_IS_UP_C		abort_loop_is_up_c
#define	ABORT_MASK_CONTROL_C		abort_mask_control_c
#define	ABORT_MASK_GROUP_C		abort_mask_group_c
#define	ABORT_READ_MAX_PERMIT_LOG_ENTRY_NUMBER	abort_read_max_permit_log_entry_number
#define	ABORT_READ_PERMIT_LOG_ENTRIES_C	abort_read_permit_log_entries_c
#define	ABORT_READ_PERMIT_LOG_ENTRIES_BY_DATE_C	abort_read_permit_log_entries_by_date_c
#define	ABORT_READ_SINGLE_MODULE_C	abort_read_single_module_c
#define	ABORT_READ_SINGLE_MODULE_BY_NAME_C	abort_read_single_module_by_name_c
#define	ABORT_SYSTEM_DEVICES_C		abort_system_devices_c
#define	ABORT_SYSTEM_DISPLAY_COORDS_C	abort_system_display_coords_c
#define	ABORT_SYSTEM_GET_ID_C		abort_system_get_id_c
#define	ABORT_SYSTEM_INFO_C		abort_system_info_c
#define	ABORT_SYSTEM_MODULE_DATA_C	abort_system_module_data_c
#define	ABORT_SYSTEM_NUM_MODULES_C	abort_system_num_modules_c
#define	ABORT_SYSTEM_RESET_C		abort_system_reset_c
#define	ACL_FILE_EDIT_C			acl_file_edit_c
#define	ACL_FILE_MENU_C			acl_file_menu_c
#define	BSSB_PERMIT_STATUS_C		bssb_permit_status_c
#define	BSSB_PERMIT_STATUS_LIST_C	bssb_permit_status_list_c
#define	CHECK_POWER_LEADS_C		check_power_leads_c
#define	CNS_SET_IS_ENABLED		cns_set_is_enabled
#define	CNS_FLAG_SET_ENABLE		cns_flag_set_enable
#define	CURVE_EDITOR			curve_editor
#define	CURVE_EDITOR_INIT		curve_editor_init
#define	CURVE_EDITOR_MULTIPLE_WAVEFORMS_C	curve_editor_multiple_waveforms_c
#define	DB_COLUMN_INFO_C		db_column_info_c
#define	DB_CTIME_TO_DB_DATE_C		db_ctime_to_db_date_c
#define	DB_RETRIEVE_ROWS_C		db_retrieve_rows_c
#define	DB_TABLE_NAME_PARSE_C		db_table_name_parse_c
#define	DELETE_FILE			delete_file
#define DISPLAY_CAMAC_CRATE		display_camac_crate
#define	EMITT_DP_TEV			emitt_dp_tev
#define	IS_VALID_DABBEL_USER		is_valid_dabbel_user
#define	LOGGER_CLIENT_LOG_VALUES_C	logger_client_log_values_c
#define	LOGGER_MENU			logger_menu
#define	LOGGER_MENU_ITEMS		logger_menu_items
#define	LOGGER_NODE_ID			logger_node_id
#define	POWER_LEADS_OFF_C		power_leads_off_c
#define	POWER_LEADS_ON_C		power_leads_on_c
#define	PRINT_FILE			print_file
#define	PRINT_FILE_DETACHED		print_file_detached
#define	QPM_HSCODE			qpm_hscode
#define	RAMPCARD_SHAPER			rampcard_shaper
#define	RAMPCARD_SHAPER_INIT		rampcard_shaper_init
#define	READ_MJY_DATA_FILE_C		read_mjy_data_file_c
#define	READ_NUM_BOOSTER_TURNS_C	read_num_booster_turns_c
#define	READ_TAGGED_VALUE_FILE		read_tagged_value_file
#define	REMPGM_SEQUENCE_CHECK		rempgm_sequence_check
#define	SEQUENCER_FILE_EXECUTE_C	sequencer_file_execute_c
#define	SEQUENCER_FILE_FIND_DEVICE_C	sequencer_file_find_device_c
#define	SEQUENCER_FILE_GET_DIRECTORY_INFO_C	sequencer_file_get_directory_info_c
#define	SEQUENCER_FILE_GET_ENTRIES_C	sequencer_file_get_entries_c
#define	SEQUENCER_FILE_HAS_SR_RESTORE_COMMANDS_C	sequencer_file_has_sr_restore_commands_c
#define	SEQUENCER_FILE_NAME_TO_NUMBER_C	sequencer_file_name_to_number_c
#define	SEQUENCER_FILE_NUM_BYPASSED_COMMANDS_C	sequencer_file_num_bypassed_commands_c
#define	SEQUENCER_FILE_NUMBER_EXISTS_C	sequencer_file_number_exists_c
#define	SEQUENCER_MAXIMUM_MODE_NUMBER	sequencer_maximum_mode_number
#define	SEQUENCER_MODE_TO_NAME_C	sequencer_mode_to_name_c
#define	SEQUENCER_NAME_TO_MODE		sequencer_name_to_mode
#define	SET_NUM_BOOSTER_TURNS_C		set_num_booster_turns_c
#define	TCLK_EVENT_TIMES_C		tclk_event_times_c
#define	TEV_RAMP_TIMES_C		tev_ramp_times_c
#define	WAIT_FOR_DEVICE			wait_for_device
#define	WAIT_FOR_DEVICE_C		wait_for_device_c
#define	WAIT_FOR_DEVICE_STATUS_C	wait_for_device_status_c
#define	WAIT_TIME_C			wait_time_c
#define	WHO_WHAT_WHY_C			who_what_why_c
#define	WRITE_MJY_DATA_FILE_C		write_mjy_data_file_c

#endif