snap_h

/*
**	Copyright 2000-2018, Fermi Research Alliance, LLC.  All rights reserved.
*/
/*+
 SNAP.H defines the data structures used in the detatched snapshot plot
 manager process of the ACNET Save/Restore system.
-*/

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

/*
 system constants
 */
#define	DSNAP_SYS_LINAC		0		/* Linac */
#define	DSNAP_SYS_BOOSTER	1		/* Booster */
#define	DSNAP_SYS_MI		2		/* Main Injector */
#define	DSNAP_SYS_TEVATRON	3		/* Tevatron */
#define	DSNAP_SYS_SY		4		/* Switchyard */
#define	DSNAP_SYS_PBAR		5		/* Pbar */
#define	DSNAP_SYS_CRYO		6		/* Cryogenics */
#define	DSNAP_SYS_CDF		7		/* CDF */
#define	DSNAP_SYS_RECYCLER	8		/* Recycler */
#define	DSNAP_SYS_STORE		9		/* Store */
#define	DSNAP_SYS_GLOBAL	10		/* Global */
#define	DSNAP_SYS_SCRATCH	11		/* Scratch */
#define	DSNAP_SYS_CREW		12		/* Crew */
#define	DSNAP_SYS_CONTROLS	13		/* Controls */
#define	DSNAP_SYS_NUMI		14		/* NuMI */
#define	DSNAP_SYS_MISC		15		/* Misc */
#define	DSNAP_SYS_SPARE9	16		/* Spare 9 */
#define	DSNAP_SYS_SPARE8	17		/* Spare 8 */
#define	DSNAP_SYS_SPARE7	18		/* Spare 7 */
#define	DSNAP_SYS_SPARE6	19		/* Spare 6 */
#define	DSNAP_SYS_SPARE5	20		/* Spare 5 */
#define	DSNAP_SYS_SPARE4	21		/* Spare 4 */
#define	DSNAP_SYS_SPARE3	22		/* Spare 3 */
#define	DSNAP_SYS_SPARE2	23		/* Spare 2 */
#define	DSNAP_SYS_SPARE		24		/* Spare */

/*
 Miscellaneous constants
*/

#define	SR_FTD_ONESHOT	0		/* FTD of zero */
#define SR_FTD_NOSHOT	2		/* FTD - no front end read */
#define SDA_FTD_ONESHOT 0x4001		/* FTD - one shot SDA only */
#define DP_FACILITY	17		/* data pool facility number */
#define DB_FACILITY	16		/* data base facility number */
#define SR_PENDING	0x0111		/* pending (17,1) */

#define ARM_ON_EVENTS 		0x02	/* AS bits for trigger */
#define ARM_ON_EXTERNAL		0x03	/* AS bits for trigger */
#define DIGITIZE_AFTER_ARM   	0xC0	/* PM bits for collection */
#define DIGITIZE_CONTINUOUS	0xE0	/* PM bits for collection */
#define MAX_DELAY		0x7fffffff /* int delay time */

/* filters for fprintf to the log file */
#define EVENTBUG	1	/*  01 EVENT	*/
#define ERRBUG		2	/*  02 ERR	*/
#define SNAPBUG		4	/*  04 SNAP	*/
#define DELAYBUG	8	/*  08 DELAY	*/
#define FILEBUG		16	/*  10 FILE	*/
#define SEARCHBUG	32	/*  20 SEARCH	*/
#define NETBUG		64	/*  40 NET	*/
#define RMSBUG		128	/*  80 RMS	*/
#define COLLECTBUG	256	/* 100 COLLECT	*/
#define READBUG		512	/* 200 READ 	*/

#define NET_TC_SSNR	101		/* subsystem names request */
#define NET_TC_SSDR	102		/* subsystem directory request */
#define NET_TC_ASTR	103		/* active subsystems total request */
#define	NET_TC_ADLR	104		/* list active devices by subsystem */
#define	NET_TC_ADIR	105		/* insert devices by subsystem */
#define	NET_TC_ADDR	106		/* delete devices by subsystem */
#define NET_TC_FDDR	107		/* full device directory request */
#define NET_TC_SDDR	108		/* single device directory request */
#define NET_TC_FSTR	109		/* file subsystems total request */
#define NET_TC_UKEYID	110		/* simple user key id support */
#define	NET_TC_SADR	111		/* single active device request */
#define	NET_TC_FRLR	112		/* frig nodes list request */
#define	NET_TC_FRSR	113		/* frig nodes set request */
#define NET_TC_BUGS	114		/* set debug flags */
#define NET_TC_PING	115		/* heartbeat request */

/* compatability typecodes supported by Save/Restore and SDA */
#define NET_SR_ALL	1		/* request packet - no len/offset */
#define NET_SR_DATA	2		/* request packet - len/offset */
#define NET_SR_FILES	3		/* file directory request */
#define NET_SR_QUOTA	4		/* disk quota request */
#define NET_SR_ERRS	5		/* device errors request */
#define NET_SR_MOD	6		/* modify device data request */
#define NET_SR_SDA	7		/* most recent SDA file request */
#define NET_SR_DONE	21		/* disconnect retrieval stream */
#define NET_SR_PLOT	22		/* plot data request packet */
#define NET_SR_FILEP	23		/* set file protection */

#define SUBSYSTEM_MAX			25	/* upper limit of defined subsystems */
#define DSNAP_SUBSYSTEM_MAX		25	/* upper limit of defined subsystems */
#define	DSNAP_NUM_SYSTEMS		25	/* number of detached snapshot manager systems */
#define NUM_SUBSYSTEM_NAMES		13	/* current limit of defined subsystems */
#define DSNAP_NUM_SUBSYSTEM_NAMES	13	/* current limit of defined subsystems */

#define TRIGGERMODE_EVENTS	0	/* trigger off Tevatron clock events */
#define TRIGGERMODE_EXTERNAL	1	/* trigger off device */


/*
  support for the presentation of subsystem names that may change or grow
  with time.  if the number of subsystems grows to more than 25, I'll
  contact any affected party.
*/

#define	DSNAP_SUBSYSTEM_NAME_LENGTH	11
#define	DSNAP_SYSTEM_NAME_LENGTH	11

struct SSNR {				/* subsystem names request */
      	uword 	ssnr_w_tc;		/* typecode NET_TC_SSNR */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct SSNP {				/* subsystem names reply */
	uword 	ssnp_w_status;		/* status of request */
	word	ssnp_w_numsubsystems;	/* number of subsystems returned */
	char	ssnp_names[DSNAP_SUBSYSTEM_MAX][DSNAP_SUBSYSTEM_NAME_LENGTH];	/* names to return */
	char	unused;     	    	/* padding */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
  support for the determination of active (or file) subsystem totals.
  don't bother to ask (ADLR) for subsytems that have no entries.
*/
struct ASTR {				/* active subsystem total request */
      	uword astr_w_tc;		/* typecode NET_TC_ASTR */
      					/* typecode NET_TC_FSTR */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct ASTP {				/* active subsystem total reply */
	uword astp_w_status;		/* status of request */
	uword astp_w_subsystem[25];	/* totals for 25 subsystems */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
  support for the presentation of directories by subsystem id.
*/
struct SSDR {				/* subsystem directory request */
        uword	ssdr_w_tc;		/* typecode NET_TC_SSDR */
	uword	ssdr_w_subsystem;	/* subsystem id */
	uword	ssdr_w_offset;		/* 0, SSDP_MAX, SSDP_MAX * 2, ... */
	} __attribute__((packed));

struct DSNAP_SSDE {			/* subsystem directory entry */
	char	ssde_b_name[8];		/* name of device */
	ulong	ssde_l_di;		/* Device Index */
	uword	ssde_w_recordnum;	/* record number */
	uword	ssde_w_subsystem;	/* subsystem id */
	ulong	ssde_l_time;		/* ctime of sample */
	uword	ssde_w_userid;		/* user key id */
	uword	ssde_w_userkey1;	/* user defined key */
	uword	ssde_w_userkey2;	/* user defined key */
	word	ssde_w_error;		/* Acnet standard error code */
	} __attribute__((packed));

struct SSDP {				/* subsystem directory reply */
	uword 	ssdp_w_status;		/* status of request */
	word	ssdp_w_numentries;	/* number of snapshot entries found */
	struct DSNAP_SSDE ssdp_ssde[1];	/* directory entry packets */
	} __attribute__((packed));
#define SSDP_MAX (ACNET_PACKET_SIZE-sizeof(struct SSDP))/(sizeof(struct SSDP))

/*
  support for the additon/deletion/listing of active devices.
*/

struct DSNAP_ADE {
	ulong	ade_l_di;		/* Device Index */
	char	ade_b_name[8];		/* device name */
	uword	ade_w_subsystem;	/* subsystem id */
	uword	ade_w_userid;		/* user key id */
	uword	ade_w_userkey1;		/* user defined key */
	uword	ade_w_userkey2;		/* user defined key */
	int	ade_l_rearmdelay;	/* rearm delay in secs or -1:oneshot*/
	uword	ade_w_maxhour;		/* max snapshots/hour */
	uword	ade_w_handlercode;	/* special handler code */
	int	ade_l_rate;		/* collection rate in Hz */
	ubyte	ade_b_armevent[8];	/* arming event FTD */
	word	ade_w_delay;		/* delay from arm event (ms) */
	float	ade_r_duration;		/* collection time in 1/100's of sec */
	uword	ade_w_node;		/* front end node number */
	char	ade_b_triggermode;	/* trigger mode; see sur-> */
	char	ade_b_unused;		/* alignment */
	char	ade_b_trigger[8];	/* trigger device name */
	uword	ade_aw_trigssdn[4];	/* trigger subsystem's device number */
	ulong	ade_l_mask;		/* trigger mask */
	} __attribute__((packed));

struct ADLR {				/* active device list request */
      	uword 	adlr_w_tc;		/* typecode NET_TC_ADLR */
	uword	adlr_w_subsystem;	/* subsystem id */
	uword	adlr_w_offset;		/* 0, ADLP_MAX, ADLP_MAX * 2, ... */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct ADLP {				/* active device list reply */
	uword 	adlp_w_status;		/* status of request */
	word	adlp_w_numentries;	/* number of snapshot entries found */
	struct DSNAP_ADE adlp_ade[1];	/* active entry packets */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
#define ADLP_MAX (ACNET_PACKET_SIZE-sizeof(struct ADLP))/(sizeof(struct DSNAP_ADE))
struct SADR {				/* single active device request */
      	uword 	sadr_w_tc;		/* typecode NET_TC_SADR */
	int	sadr_l_di;		/* device index */
	uword	sadr_w_offset;		/* 0, SADP_MAX, SADP_MAX * 2, ... */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct SADP {				/* single active device reply */
	uword 	sadp_w_status;		/* status of request */
	word	sadp_w_numentries;	/* number of snapshot entries found */
	struct DSNAP_ADE sadp_ade[1];	/* active entry packets */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
#define SADP_MAX (ACNET_PACKET_SIZE-sizeof(struct SADP))/(sizeof(struct DSNAP_ADE))
#define	NET_TC_SADR	111		/* single active device request */

struct DSNAP_ADIR {			/* insert device list request */
      	uword 	adir_w_tc;		/* typecode NET_TC_ADIR */
	word	adir_w_numentries;	/* number to insert */
	struct DSNAP_ADE adir_ade[1];	/* insert entry packets */
	} __attribute__((packed));
struct DSNAP_ADIP {			/* insert device list reply */
      	uword 	adip_w_status[1];	/* status of insert(s) */
	} __attribute__((packed));
struct DSNAP_ADDR {			/* delete device list request */
      	uword 	addr_w_tc;		/* typecode NET_TC_ADDR */
	word	addr_w_numentries;	/* number to delete */
	struct DSNAP_ADE addr_ade[1];	/* delete entry packets */
	} __attribute__((packed));
struct DSNAP_ADDP {			/* delete device list reply */
      	uword 	addp_w_status[1];	/* status of delete(s) */
	} __attribute__((packed));

/*
  support for the retrieval of plot data.
*/
struct SRPR {				/* plot request */
      	uword 	srpr_w_tc;		/* typecode NET_SR_DATA */
	ulong	srpr_l_dipi;		/* device/property index */
	uword	srpr_w_userid;		/* user id */
	uword	srpr_w_length;		/* length in bytes */
	uword	srpr_w_offset;		/* offset in bytes */
	uword	srpr_w_subsystem_uk1;	/* subsystem or userkey 1 */
	uword	srpr_w_record_uk2;	/* record # or userkey 2 */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct SRPP {				/* plot reply */
      	word 	srpp_w_len_error;	/* length or error */
	uword	srpp_w_dataptr;		/* byte offset to data */
					/* repeats 'entries' times */
					/* data follows */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

struct SRPLOT {				/* plot data request */
      	uword 	srplot_w_tc;		/* typecode NET_SR_PLOT */
	uword	srplot_w_replylen;	/* max expected reply length */
	uword	srplot_w_entries;	/* number of entries (packets) */
	struct  SRPR srplot_srpr[1];	/* request packets */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
  support for user keys.
*/
/*
  store keyid is 1.  On program startup, SNAP places this key's devices on the
  'forever deferred' queue.  When a 'UKEY_ENABLE' action is received, userkey1
  contains the current shore number, userkey2 is reset to 0, 0xDB events cause
  the devices to move from the 'forever deferred' queue to the active queue.
  Each 0xDB event increments userkey2.  A 'UKEY_DISABLE' causes devices to
  be moved to the 'forever deferred' queue and 0xDB events to be ignored.
*/
#define NET_TC_UKEYID	110		/* simple user key id support */
/*
  support for user code 1:
*/
struct UKEY {				/* user code 1 */
      	uword 	ukey_w_tc;		/* typecode NET_TC_UKEYID */
	uword	ukey_w_userid;		/* user key id */
#define UKEY_STORE	1			/* keyid for stote data */
	uword	ukey_w_userkey1;	/* user defined key */
	uword	ukey_w_userkey2;	/* user defined key */
	uword	ukey_w_action;		/* action */
#define UKEY_ENABLE	0
#define UKEY_DISABLE	1
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*  one word of status is the reply */
struct BUGS {				/* single active device request */
      	uword 	bugs_w_tc;		/* typecode NET_TC_BUGS */
	int	bugs_l_bugs;		/* debug flags */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
  support for requesting the directory information on a single device -
  used by the plotting interface.  Returned structures are ordered by
  decreasing time.  i.e. the lastest is returned 1st so that a menu of
  choices will have the most recent choice on top.
*/
struct SDDR {				/* single device directory request */
      	uword 	sddr_w_tc;		/* typecode NET_TC_SDDR */
	ulong	sddr_l_di;		/* device index */
	} __attribute__((packed));
struct DSNAP_SDDE {			/* single device directory entry */
	uword	sdde_w_subsystem;	/* subsystem id */
	uword	sdde_w_recordnum;	/* record number */
	ulong	sdde_l_time;		/* ctime of sample */
	uword	sdde_w_userid;		/* user key id */
	uword	sdde_w_userkey1;	/* user defined key */
	uword	sdde_w_userkey2;	/* user defined key */
	word	sdde_w_error;		/* Acnet standard error code */
	} __attribute__((packed));
struct SDDP {				/* single device directory reply */
	uword 	sddp_w_status;		/* status of request */
	word	sddp_w_numentries;	/* number of entries returned */
	struct DSNAP_SDDE sddp_sdde[1];	/* device directory entries */
	} __attribute__((packed));
#define SDDP_MAX 200			/* max number device/dir */

#ifdef DELETE_ME
/*
  Define structures for the support of FRIG
  (These were last used on the VAX in 2004.)
*/
struct SFRIG {
	char	frig_b_name[8];		/* ACNET node name */
	uword	frig_w_node;		/* ACNET node and trunk */
	char	frig_b_extname[8];	/* external trigger device name */
	uword	frig_w_extssdn[4];	/* SSDN of external device */
	int	frig_l_mask;		/* mask to apply to external device */
	char	frig_b_mode;		/* current mode */
#define FRIGMODE_NOTFRIG	0	/* trigger off device */
#define FRIGMODE_EXTERNAL	1	/* trigger off device */
#define FRIGMODE_EVENTS		2	/* trigger off clock events */
	char	frig_b_unused;		/* expansion */
	ubyte	frig_b_arm[8];		/* arm clock events */
	word	frig_w_delay;		/* delay from clock event */
	int	frig_l_rearmdelay;	/* rearm delay in secs or -1:oneshot*/
	uword	frig_w_maxhour;		/* max snapshots/hour */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
  support for requesting the list of FRIG nodes.
*/
struct FRLR {				/* frig node list request */
      	uword 	frlr_w_tc;		/* typecode NET_TC_FRLR */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct FRLP {				/* frig node list reply */
	uword 	frlp_w_status;		/* status of request */
	word	frlp_w_numentries;	/* number of frig nodes returned */
	struct SFRIG frlp_sfrig[1];	/* frig node entries */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
  support for setting a FRIG node.
*/
struct FRSR {				/* frig node set request */
      	uword 	frsr_w_tc;		/* typecode NET_TC_FRSR */
	struct SFRIG frsr_sfrig;	/* frig node entry */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct FRSP {				/* frig node set reply */
	uword 	frsp_w_status;		/* status of request */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
#endif


/*
 NGT defines the Network request general typecode
*/
struct NGT {
	uword	ngt_w_typecode;		/* typecode */
	uword	ngt_w_word2;		/* second word */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
 STAT defines a network statistics return.  The requests consists of a
 single word of typecode [5].
*/
struct STAT {
	uword	stat_w_status;		/* status of save */
	char	stat_c_timestart[24];	/* time of save start */
	char	stat_c_timestop[24];	/* time of save stop */
	char	stat_c_seqdone[24];	/* sequences done */
	uword	stat_w_filenumber;	/* save file number */
	word	stat_w_curseq;		/* current sequence */
	uword	stat_w_filesize;	/* save file size in blocks */
	uword	stat_w_totaldi;		/* total number of DIs to save */
	uword	stat_w_numsavdi;	/* number of saved DIs */
	uword	stat_w_numsavdipi;	/* number of saved DI/PIs */
	uword	stat_w_numsavdierr;	/* number of saved DIs in error */
	uword	stat_w_numsavdipierr;	/* number of saved DI/PIs in error */
	uword	stat_w_snapshots;	/* number of saved snapshots */
	uword	stat_w_snapshotserr;	/* number of saved snapshots in error */
	uword	stat_w_rscalars;	/* number of remaining scalars */
	uword	stat_w_rsnaps;		/* number of remaining snapshots */
	uword	stat_w_fe1[12];		/* front end statistics */
	uword	stat_w_fe2[12];		/* front end statistics */
	uword	stat_w_fe3[12];		/* front end statistics */
	uword	stat_w_fe4[12];		/* front end statistics */
	uword	stat_w_fe5[12];		/* front end statistics */
	uword	stat_w_fe6[12];		/* front end statistics */
	uword	stat_w_fe7[12];		/* front end statistics */
	uword	stat_w_fe8[12];		/* front end statistics */
	uword	stat_w_fe9[12];		/* front end statistics */
	uword	stat_w_fe10[12];	/* front end statistics */
	uword	stat_w_fe11[12];	/* front end statistics */
	uword	stat_w_times[32];	/* elapsed time of sequences */
	unsigned char	stat_c_waitevents[2];	/* scalar,snap waiting events */
	uword	stat_w_waitdelays[2];	/* scalar,snap waiting delays */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

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

#ifdef __cplusplus
extern "C" {
#endif

int detached_snapshot_add_plot_setup_c(DSNAP_ADE *plot_setup,
				       unsigned int options=0);
int detached_snapshot_delete_plot_setup_c(int system, int device_index,
					  unsigned int options=0);
int detached_snapshot_find_device_c(int device_index, unsigned int *num_found,
				    DSNAP_ADE **found_plots,
				    unsigned int options=0);
int detached_snapshot_get_device_files_c(int device_index,
					 unsigned int *num_found,
					 DSNAP_SDDE **found_files,
					 unsigned int options=0);
int detached_snapshot_get_plot_setup_c(int system, int device_index,
				       DSNAP_ADE *plot_setup,
				       unsigned int options=0);
int detached_snapshot_get_plot_setups_c(int system, unsigned int *num_found,
					DSNAP_ADE **found_plots,
					unsigned int options=0);
int detached_snapshot_get_system_files_c(int system, unsigned int *num_found,
					 DSNAP_SSDE **found_files,
					 unsigned int options=0);
int detached_snapshot_reinit_plot_c(int system, int device_index,
				    unsigned int options=0);
int detached_snapshot_system_name_to_id_c(char *system_name, int *id,
					  int name_length=0);
int detached_snapshot_system_names_c(int max_return, int *num_systems,
				     char *system_names);
void dump_snapq(char *title);
void dump_header(char *title);
short get_detached_snapshot_server_node(int *status=(int *) NULL);

#ifdef __cplusplus
}
    #endif

#endif