bltuti_h

/*
 *  Copyright 1999, University Research Association. All rights reserved
 */
/*-----------------------------------------------------------------------------
 * bltuti.h
 *
 *      function prototypes and defined constants for arguement values for
 *      BLT (Beam Line Tuner) access routines
 *
 *---------------------------------------------------------------------------*/

#ifndef BLTUTI_DEFINED
#define BLTUTI_DEFINED                             /* include this only once */

#include "cbslib.h"
#include "macro.h"

/*-----------------------------------------------------------------------------
 *
 *      defined constants for arguement values
 *
 *---------------------------------------------------------------------------*/

/* machine names */

#define BLT_TEVATRON      0
#define BLT_MAIN_INJECTOR 1
#define BLT_TEST          2
#define BLT_RECYCLER      3

/* modes for blt_is_fresh() */
#define BLT_UPDATE_SET	  0
#define	BLT_UPDATE_CHECK  1

/* offset sizes */
#define BLT_BUFFER_SIZE	   36
#define BLT_POSITION_SIZE 256
#define BLT_TAG_SIZE	  240
#define BLT_MAX_BUFFER      9
#define BLT_MAX_BATCH      35

/* BLT modes */
#define BLT_PROTON		    0
#define BLT_PBAR		    1

/* Types of Position Data */
#define BLT_POS_RAW		    0
#define	BLT_POS_FILTERED	    1

#define BLT_SPEC_NAMELEN   32
#define BLT_SPEC_FILLERLEN 13
#define BLT_SPEC_NUMBER	    9
#define	BLT_SPEC_SIZE	   100

typedef struct BLT_SPEC {
  char name[BLT_SPEC_NAMELEN];
  unsigned short  bsync;
  unsigned short  bsyncEvent;
	   int   bsyncDelay;
  unsigned short  tclockEvent;
           int   tclockDelay;
  unsigned short  aquire;
  unsigned short  oneSample;
  unsigned short  save;
  unsigned short  analysis;
  unsigned short  pattern;
  unsigned short  nextSpec;
  unsigned short  repeat;
  unsigned short  hitsTrig;
  unsigned short  buffer;
  unsigned short  mode;
  unsigned short  turns;
  unsigned short  batch;
  unsigned short  cycle;
  unsigned short  cnt;
  unsigned short  filler[13];
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ BLT_SPEC;

typedef struct BLT_TAG {
  short          measspec_idx;
  unsigned short reset_cycle;
  unsigned short mdat_state;
  unsigned int  timestamp;
  unsigned short not_used[115];
} __attribute__((packed)) /* Added by the PACKINATOR(tm) */ BLT_TAG;
 
typedef struct BLT_DATA{
    float hAmp;
    float vAmp;
    float hPhase;
    float vPhase;
    float hTune;
    float vTune;
    float hQual;
    float vQual;
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ BLT_DATA;

typedef struct BLT_POS{
    float hPositions[1024];
    float vPositions[1024];
    } __attribute__((packed)) /* Added by the PACKINATOR(tm) */ BLT_POS;

/*-----------------------------------------------------------------------------
 *
 *      ACNET parameter names
 *
 *---------------------------------------------------------------------------*/
/*****************************************************************************
*
*    GLOBALS: Mostly static Acnet device names
*
*****************************************************************************/
namespace blt {
	extern char phTune[DEVICE_NAME_LEN + 1];   /* Tunes */
	extern char pvTune[DEVICE_NAME_LEN + 1];
	extern char ahTune[DEVICE_NAME_LEN + 1];
	extern char avTune[DEVICE_NAME_LEN + 1];
	extern char phPhase[DEVICE_NAME_LEN + 1];   /* Phases */
	extern char pvPhase[DEVICE_NAME_LEN + 1];
	extern char ahPhase[DEVICE_NAME_LEN + 1];
	extern char avPhase[DEVICE_NAME_LEN + 1];
	extern char phAmp[DEVICE_NAME_LEN + 1];   /* Amplitudes */
	extern char pvAmp[DEVICE_NAME_LEN + 1];
	extern char ahAmp[DEVICE_NAME_LEN + 1];
	extern char avAmp[DEVICE_NAME_LEN + 1];
	extern char phDamp[DEVICE_NAME_LEN + 1];   /* Damping */
	extern char pvDamp[DEVICE_NAME_LEN + 1];
	extern char ahDamp[DEVICE_NAME_LEN + 1];
	extern char avDamp[DEVICE_NAME_LEN + 1];
	extern char phCoup[DEVICE_NAME_LEN + 1];   /* Coupling */
	extern char pvCoup[DEVICE_NAME_LEN + 1];
	extern char ahCoup[DEVICE_NAME_LEN + 1];
	extern char avCoup[DEVICE_NAME_LEN + 1];
	extern char phFitQ[DEVICE_NAME_LEN + 1];   /* Fit Quality */
	extern char pvFitQ[DEVICE_NAME_LEN + 1];
	extern char ahFitQ[DEVICE_NAME_LEN + 1];
	extern char avFitQ[DEVICE_NAME_LEN + 1];
	extern char hrData[DEVICE_NAME_LEN + 1];   /* Data arrays */
	extern char vrData[DEVICE_NAME_LEN + 1];   /* Raw and  */
	extern char hfData[DEVICE_NAME_LEN + 1];   /* Filtered */
	extern char vfData[DEVICE_NAME_LEN + 1];
	extern char tagData[DEVICE_NAME_LEN + 1];   /* Tag Data */
	extern char paramSize[DEVICE_NAME_LEN + 1]; /* Bunch/Batch Data */
	extern char dimentions[DEVICE_NAME_LEN + 1];  /* Data Dimentions */
	extern char horzSpect[DEVICE_NAME_LEN + 1];   /* Horz FFT data */
	extern char vertSpect[DEVICE_NAME_LEN + 1];   /* Vert FFT data */
	extern char batchIdx[DEVICE_NAME_LEN + 1];
	extern char specName[DEVICE_NAME_LEN + 1];   /* BLT spec */
	extern char cmdName[DEVICE_NAME_LEN + 1];   /* BLT command */
	extern char bltUpdate[DEVICE_NAME_LEN + 1];   /* BLT update */
};

/*-----------------------------------------------------------------------------
 *
 * function prototypes for BLT routines
 *
 *---------------------------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif

/* Get analysed data from the selected BLT */
int blt_get_data(int machine, int mode, int batch, BLT_DATA *Request,
		 int buffer=0 );

/* Get positions from the selected BLT */
int blt_get_pos(int machine, int batch, int type, int size, BLT_POS *Request );

/* Get tag data from selected BLT */
int blt_get_tag( int machine, int buffer, BLT_TAG *Request );

/* Activate the BLT Measurement Specification */
int blt_activate_spec(int machine, int spec_number );

/* Either set the freshness parameter or chech the measurements freshness */
int blt_is_fresh(int machine, int setCheck);

int blt_get_pos_device( int machine, int particle, int bunch, int size, 
			BLT_POS *Request );

#ifdef __cplusplus
}   /** END OF extern "C" { */
#endif

#endif /** END OF BLTUTI_DEFINED */