snap_h

/*
**	Copyright 2000-2015, 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 */


/*
 SUR defines a snapshot user request structure 
*/
struct SUR {
	list_link_t sur_links;		/* queue links */
	ulong	sur_l_di;		/* Device Index */
	char	sur_b_name[8];		/* device name */
	uword	sur_w_subsystem;	/* subsystem id */
	uword	sur_w_userid;		/* user key id */
	uword	sur_w_userkey1;		/* user defined key */
	uword	sur_w_userkey2;		/* user defined key */
	uword	sur_w_handlercode;	/* special handler code */
	uword	sur_w_oks;		/* count of ok snapshots */
	uword	sur_w_attempts;		/* count of attempts */
	int	sur_l_rearmdelay;	/* rearm delay in seconds */
	uword	sur_w_maxhour;		/* max snapshots attempts/hour */
	int	sur_l_rate;		/* collection rate in Hz */
	ubyte	sur_b_armevent[8];	/* arming event FTD */
	int	sur_l_delay;		/* delay from arm event (ms) */
	float	sur_r_duration;		/* collection time in 1/100's of sec */
	uword 	sur_w_len;		/* default length of a reading */
	uword	sur_w_node;		/* front end node number */
	uword	sur_aw_ssdn[4];		/* subsystem's device number */	
	char	sur_b_frigmode;		/* frig flags - see frig */
#define TRIGGERMODE_EVENTS	0	/* trigger off Tevatron clock events */
#define TRIGGERMODE_EXTERNAL	1	/* trigger off device */
	char	sur_b_triggermode;	/* trigger mode */
	char	sur_b_trigger[8];	/* trigger device name */
	uword	sur_aw_trigssdn[4];	/* trigger subsystem's device number */	
	ulong	sur_l_mask;		/* trigger mask */
        ubyte   sur_b_tre[4];           /* sample trigger clock events */
        ulong   sur_l_npts;             /* number of points */
        ulong   sur_l_eadipi;           /* device arm DI/PI */
        ulong   sur_l_eavalu;           /* device arm value */
        uword   sur_w_eaoff;            /* device arm offset */
        uword   sur_w_classcode;        /* class code */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
 SF defines the save data file record entries.  These structures are hung off
 the front end snapshot (FSG) structure.
*/
struct SF {
	list_link_t sf_links;		/* queue links */
	ulong	sf_l_length;		/* length of allocated block */
					/* start of RMS record ?? correct RAB*/
		/* key used for circular overwrites and dir/date within subs */
		/* msw subsystem and lsw recordnum are a unique key */
	uword	sf_w_recordnum;		/* record number */
	uword	sf_w_subsystem;		/* subsystem id */
		/* key used for plot selections */
	ulong	sf_l_time;		/* ctime of sample */
	ulong	sf_l_di;		/* Device Index */
		/* not a real key, helps users match devices/dates */
		/* msw userkey1/userkey2/di lsw are a unique key */
	uword	sf_w_userkey2;		/* user defined key */
	uword	sf_w_userkey1;		/* user defined key */
	uword	sf_w_userid;		/* user key id */
	char	sf_b_name[8];		/* name of device */
	uword	sf_w_handlercode;	/* special handler code */
	uword	sf_w_node;		/* front end node number */
	word	sf_w_error;		/* Acnet standard error code */
	uword	sf_w_unused[5];		/* unused */
	uword	sf_w_datasize;		/* datasize: 2 or 4 bytes */
	uword	sf_w_numpoints;		/* number of points - BACK TO USER */
	uword	sf_w_ats;		/* arm and trigger selection */
	uword	sf_w_smp;		/* data sample period in 10 uS units */
	word	sf_w_adl;		/* arm delay (ms or sample periods) */
	ubyte	sf_ab_arm[8];		/* arm clock events */
	ubyte	sf_ab_tre[8];		/* trigger clock events */
 	char	sf_ab_time[24];		/* arm event */
	word	sf_w_dtimes[3];		/* delta times in seconds from arm 
					    till ready, till collection started,
					    till collection finished */
	uword	sf_w_uid;		/* for plot: userid */
	uword	sf_w_ssk1;		/* for plot: subsystem or userkey 1 */
	uword	sf_w_rnk2;		/* for plot: record # or userkey 2 */
	uword	sf_w_classcode;		/* plot class code */
	int	sf_l_rate;		/* rate in hz */
	uword	sf_w_data[1];		/* start of data and times */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
#define SF_SNAP_OVERHEAD 66		/* snapshot overhead before data */
#define SF_OVERHEAD_ERR 14		/* snapshot overhead before data */
#define LARGEST_RECORD 8382		/* maximum record size */
#define SAV_M_READING	1		/* match S/R defintions */

/*
 RPCI defines a request plot class request packet
*/
struct RPCIP {
	int	rpcip_l_dipi;		/* device index / property index */
	uword	rpcip_aw_ssdn[4];	/* subsystem device number */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 RPCI defines a request plot class information request
*/
struct RPCI {
	uword	rpci_w_tc;		/* typecode = 1 (class info) */
	uword	rpci_w_ndev;		/* number of devices */
	struct RPCIP rpci_rpcip[1];	/* class request packet */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 RRPCIP defines a reply plot class packet
*/
struct RRPCIP {
	word	rrpcip_w_error;		/* returned status */
	uword	rrpcip_w_ftpclass;	/* FTP class code */
	uword	rrpcip_w_snapclass;	/* SNP class code */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 RRPCI defines a plot class information reply
*/
struct RRPCI {
	word	rrpci_w_error;		/* returned status */
	struct RRPCIP rrpci_rrpcip[1];	/* class reply packet */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 SQP defines a snapshot request packet structure 
*/
struct SQP {
	int	sqp_l_dipi;		/* device index / property index */
	uword	sqp_aw_ssdn[4];		/* subsystem device number */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 SQ defines a snapshot request structure 
*/
struct SQ {
	uword	sq_w_tc;		/* typecode = 3 (setup snapshot) */
	int	sq_l_r50;		/* requesting taskname (RAD50) */
	word	sq_w_ndev;		/* number of devices requested */
	uword	sq_w_ats;		/* arm and trigger selection */
	uword	sq_w_smp;		/* data sample period in 10 uS units */
	word	sq_w_adl;		/* arm delay (ms or sample periods) */
	ubyte	sq_ab_arm[8];		/* arm clock events */
	ubyte	sq_ab_tre[8];		/* trigger clock events */
	struct	SQP sq_sqp[1];		/* snapshot request packet */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 SSQP defines a snapshot request packet structure 
*/
struct SSQP {
	int	ssqp_l_dipi;		/* device index / property index */
	ulong	ssqp_l_off;		/* device offset in bytes */
	uword	ssqp_aw_ssdn[4];	/* subsystem device number */
	uword	ssqp_aw_unused[2];	/* expansion */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 SSQ defines a snapshot setup request structure, typecode 7
*/
struct SSQ {
	uword	ssq_w_tc;		/* typecode = 7 (setup snapshot) */
	int	ssq_l_r50;		/* requesting taskname (RAD50) */
	word	ssq_w_ndev;		/* number of devices requested */
	uword	ssq_w_ats;		/* arm and trigger selection */
	uword	ssq_w_prio;		/* priority */
	ulong	ssq_l_smp;		/* data sample rate in Hz */
	ulong	ssq_l_adl;		/* arm delay (microsecs or sample periods) */
	ubyte	ssq_ab_arm[8];		/* arm clock events */
	ubyte	ssq_ab_tre[4];		/* trigger clock events */
	ulong	ssq_l_npts;		/* number of points */
	ulong	ssq_l_eadi;		/* device arm DI/PI */
	ulong	ssq_l_eaoff;		/* device arm offset */
	uword	ssq_aw_eassdn[4];	/* device arm SSDN */	
	ulong	ssq_l_eamask;		/* device arm mask */
	ulong	ssq_l_eavalu;		/* device arm value */
	uword	ssq_aw_spare[4];	/* zeros for expansion */
	struct	SSQP ssq_sqp[1];	/* snapshot request packet */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 SSRP defines a snapshot setup reply packet structure, typecode 7
*/
struct SSRP {
	word	ssrp_w_error;		/* returned status */
	int	ssrp_l_refernce;	/* reference point number (pre-triggered) */
	int	ssrp_l_armtime;		/* arm time (secs, 1970) */
	int	ssrp_l_armnano;		/* arm time (+nanoseconds) */
	uword	ssrp_w_unused[2];	/* expansion */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
/*
 SSR defines a snapshot setup reply structure, typecode 7
*/
struct SSR {
	word	ssr_w_error;		/* returned status */
	uword	ssr_w_ats;		/* arm and trigger selection */
	ulong	ssr_l_smp;		/* data sample rate in Hz */
	ulong	ssr_l_adl;		/* arm delay (microsecs or sample periods) */
	ubyte	ssr_ab_arm[8];		/* arm clock events */
	ulong	ssr_l_npts;		/* number of points */
	struct	SSRP ssr_ssrp[1];	/* snapshot request packet */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
 SDQ defines a snapshot data retrieval request structure 
*/
struct SDQ {
	uword	sdq_w_tc;		/* typecode = 4 (get snapshot data) */
	int 	sdq_l_r50;		/* requesting taskname (RAD50) */
	word	sdq_w_itm;		/* item number of device */
	uword	sdq_w_cnt;		/* number points requested (512 max) */
	int	sdq_w_num;		/* next point number, -1 for sequential */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
 FSG defines a front end snapshot group structure.  There is a singly linked
 grounded list of these structures for each sequence.  The list is built at
 initialization.
*/
struct FSG {
	list_link_t fsg_links;		/* queue links */
	struct SQ *fsg_l_sqptr;		/* snapshot request pointer */
	struct SSQ *fsg_l_ssqptr;	/* snapshot request pointer */
	struct SF *fsg_l_sfptr;		/* save struct pointer */
	list_link_t fsg_surq;		/* snapshot user request queue */
	ulong 	fsg_l_saved;		/* saved/overwritten words */
	ulong	fsg_l_time[4];		/* times (see flags) */
	word	fsg_w_ierr[125];	/* up to 125 device errors */
	word	fsg_w_item;		/* item number of device to collect */
	word	fsg_w_count;		/* count of points remaining to get */
	word	fsg_w_sought;		/* number points sought last get */
	word	fsg_w_error;		/* error */
	uword	fsg_w_mltreqid;		/* multiple reply network request id */
	uword	fsg_w_reqid;		/* collection network request id */
	uword	fsg_w_node;		/* front end node number */
	word	fsg_w_numpoints;	/* number of points each device */
	word	fsg_w_readytime;	/* ready in ... seconds */
	uword	fsg_w_handlercode;	/* special handler code */
	int	fsg_l_rearmdelay;	/* seconds of delay before rearming */
	uword	fsg_w_maxhour;		/* max snapshots/hour */
	uword	fsg_w_attempts;		/* count of attempts */
	uword	fsg_w_flags;		/* flags */
#define FSG_ARMED 	0	/* armed and waiting for collection */
#define FSG_READY	1	/* data should be ready */
#define FSG_COLLECT	2	/* data collection in progress */
#define FSG_FINISH	3	/* data collection finished */
#define FSG_INACTIVE	4	/* no outstanding req/rpy */
#define FSG_MULTREQ	5	/* mult request is outstanding */
#define FSG_MULTRPY	6	/* mult reply is back */
#define FSG_DELAY	7	/* delaying before rearming */
#define FSG_COLLECTMORE 8	/* start another collection */
	char	fsg_b_frigmode;		/* frig flag */
	char	fsg_b_triggermode;	/* trigger mode */
	word	fsg_w_tmo;		/* timeout counter to wait for reply */
	int	fsg_l_dates[30];	/* time of attempts */
	int	fsg_l_armtime;		/* time of arming */
	word	fsg_w_pierr[3];		/* up to 3 pending errors */
	uword	fsg_w_classcode;	/* class code */
	char	fsg_b_newprotocol;	/* new protocol when TRUE */
	char	fsg_b_timestamplen;	/* timestamp length */
	int	fsg_l_maxpoints;	/* maximum number of points */
	int	fsg_l_rate;
	int	fsg_l_delay;		/* delay in microseconds */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;

/*
  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 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 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 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 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)) /* Added by the PACKINATOR(tm) */;

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 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 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 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 ADE))
#define	NET_TC_SADR	111		/* single active device request */

struct ADIR {				/* insert device list request */
      	uword 	adir_w_tc;		/* typecode NET_TC_ADIR */
	word	adir_w_numentries;	/* number to insert */
	struct ADE adir_ade[1];		/* insert entry packets */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
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 ADIP {				/* insert device list reply */
      	uword 	adip_w_status[1];	/* status of insert(s) */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct DSNAP_ADIP {			/* insert device list reply */
      	uword 	adip_w_status[1];	/* status of insert(s) */
	} __attribute__((packed));
struct ADDR {				/* delete device list request */
      	uword 	addr_w_tc;		/* typecode NET_TC_ADDR */
	word	addr_w_numentries;	/* number to delete */
	struct ADE addr_ade[1];		/* delete entry packets */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
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 ADDP {				/* delete device list reply */
      	uword 	addp_w_status[1];	/* status of delete(s) */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
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 full directory information on a single device 
  entry in the file (used by the listing interface).  
*/
struct FDDR {				/* full device directory request */
      	uword	fddr_w_tc;		/* typecode NET_TC_FDDR */
	uword	fddr_w_recordnum;	/* record number */
	uword	fddr_w_subsystem;	/* subsystem id */
	} __attribute__((packed)) /* Added by the PACKINATOR(tm) */;
struct FDDP {				/* full device directory reply */
	uword 	fddp_w_status;		/* status of request */
	uword	fddp_w_recordnum;	/* record number */
	uword	fddp_w_subsystem;	/* subsystem id */
	ulong	fddp_l_time;		/* ctime of sample arm */
	ulong	fddp_l_di;		/* Device Index */
	uword	fddp_w_userid;		/* user key id */
	uword	fddp_w_userkey2;	/* user defined key */
	uword	fddp_w_userkey1;	/* user defined key */
	char	fddp_b_name[8];		/* name of device */
	word	fddp_w_error;		/* Acnet standard error code */
	uword 	fddp_w_node;		/* Front end node number */
	uword	fddp_w_numpoints;	/* number of points */
	uword	fddp_w_ats;		/* arm and trigger selection */
	uword	fddp_w_smp;		/* data sample period in 10 uS units */
	word	fddp_w_adl;		/* arm delay (ms or sample periods) */
	ubyte	fddp_ab_arm[8];		/* arm clock events */
	ubyte	fddp_ab_tre[8];		/* trigger clock events */
 	char	fddp_ab_time[24];	/* arm event */
	} __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 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 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 SDDE sddp_sdde[1];	/* device directory entries */
	} __attribute__((packed));
#define SDDP_MAX 200			/* max number device/dir */

/*
  Define structures for the support of FRIG
*/
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) */;
/*
 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

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

#define	DETACHED_SNAPSHOT_ADD_PLOT_SETUP_C	detached_snapshot_add_plot_setup_c
#define	DETACHED_SNAPSHOT_DELETE_PLOT_SETUP_C	detached_snapshot_delete_plot_setup_c
#define	DETACHED_SNAPSHOT_FIND_DEVICE_C		detached_snapshot_find_device_c
#define	DETACHED_SNAPSHOT_GET_DEVICE_FILES_C	detached_snapshot_get_device_files_c
#define	DETACHED_SNAPSHOT_GET_PLOT_SETUP_C	detached_snapshot_get_plot_setup_c
#define	DETACHED_SNAPSHOT_GET_PLOT_SETUPS_C	detached_snapshot_get_plot_setups_c
#define	DETACHED_SNAPSHOT_GET_SYSTEM_FILES_C	detached_snapshot_get_system_files_c
#define	DETACHED_SNAPSHOT_REINIT_PLOT_C		detached_snapshot_reinit_plot_c
#define	DETACHED_SNAPSHOT_SYSTEM_NAME_TO_ID_C	detached_snapshot_system_name_to_id_c
#define	DETACHED_SNAPSHOT_SYSTEM_NAMES_C	detached_snapshot_system_names_c
#define	GET_DETACHED_SNAPSHOT_SERVER_NODE	get_detached_snapshot_server_node

#endif