/*
 * **********************************************************************
 * *                                                                    *
 * *       Parameters For Antenna Driver Processes and Routines         * 
 * *                                                                    *
 * ********************************************************************** 
 * File: libs/antenna/antsim_global.h
 *
 *           COPYRIGHT (c) 1988, 1989, 1991, 1998, 2001  BY
 *         SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A. 
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED. 
 */    

#ifdef ANTSIM_GLOBAL_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

/* ============== Structure for Holding Antenna Simulator Info ===============
 */
struct antsim_info
{
  UINT4 ixmt_pid ;               /* Process ID's for the two processes */
  UINT4 ircv_pid ;

  MESSAGE ixmt_status ;          /* Status for xmt process */
  MESSAGE ircv_status ;          /* status for rcv process     */

  UINT2 lauto ;			/* Automatic startup flag */

                                /* See antenna_lib.h file for definitions */
  UINT2 iazmode, ielmode ;       /* Servo mode for each axis */

  BIN2  iaz, idaz ;              /* Actual and Desired AZ and EL */
  BIN2  iel, idel ;              /* binary angle positions */
  char pad30x2[2] ;
      
  FLT4  fazv, fdazv ;            /* Actual and Desired AZ and EL */
  FLT4  felv, fdelv ;            /* velocities (deg / sec) */
      
  BIN2  itr_order ;              /* Actual train order and velocity */

  BIN2  iel_order ;              /* Actual elevation order and velocity */

  BIN2  ipitch ;                 /* Pitch angle and rate */
  BIN2  iroll ;                  /* Roll angle and rate */
  BIN2  iheading ;               /* Heading angle and rate */
  char pad58x2[2] ;

  FLT4  frollv ;
  FLT4  fpitchv ;
  FLT4  fheadingv ;

  BIN4  ilatitude ;              /* Position of the platform, lat/long are binary  */
  BIN4  ilongitude ;             /* angles */
  FLT4  faltitude ;              /* Altitude in meters */

  FLT4 fvel_east ;               /* Motion of the platform */
  FLT4 fvel_north ;
  FLT4 fvel_up ;

  FLT4 fsim_rock_pitch ;         /* Amplitude of the simulated rocking.. */
  FLT4 fsim_rock_roll ;
  FLT4 fsim_rock_heading ;
  FLT4 fsim_rock_phase ;         /* Number between 0 and 2pi indicating sim phase*/

  FLT4 fsim_tilt_pitch ;         /* Fixed tilt to the simulated platform */
  FLT4 fsim_tilt_roll ;
  FLT4 fsim_tilt_heading ;

                                /* See antenna.inc file for definitions */
  UINT4 icbits ;                 /* Control Flags */

                                /* See antenna.inc file for definitions */
  UINT4 isbits ;                 /* Status Flags  */

  UINT2 iActualPolar, iDesiredPolar ;  /* Actual and Desired Polarization */
  UINT2 iActualPwbw, iDesiredPwbw ;    /* Actual and Desired Pulse/Band Width */

  SINT4 idsiggen_value ;         /* Desired signal generator value */
  SINT4 isiggen_value ;          /* Actual signal generator value */

  UINT4 icurrent_rst_mode ;      /* Current RST mode reported from IRIS */
  UINT4 irequested_rst_mode ;    /* RST mode request going to IRIS */

  UINT4 icurrent_nst_bits ;      /* Current NST bits reported from IRIS */

  UINT4 ibtime ;                 /* Relative binary time of last update */
                                /*  from antenna controller. */

  SINT4 iin_cnt ;                /* Input Operation count */
  SINT4 iout_cnt ;               /* Output Operation count */
  SINT4 iin_ercnt ;              /* Input Error count */
  SINT4 iout_ercnt ;             /* Output Error count */

  /* Masks indicate what control and status bits are available
   */
  UINT4 ic_mask ;                      
  UINT4 is_mask ;

  /* Time of last simulator update
   */
  UINT4 isim_time ;

  /* Time of last Q-BITE simulator update */
  UINT4 iQBiteSimTime ;

  /* Time that T/R was turned on
   */
  UINT4 itr_on_time ;

  UINT2 lwe_should_reset ;

  /* Non-zero if we should send a time packet
   */
  UINT2 lsend_time ;

  /* Time that the last time packet was sent
   */
  UINT4 itime_sent_time ;

  /* The last transmission starting with an 80hex which got an error
   */
  UINT1 sant_diagnostic[BITE_MAX_LENGTH] ;
  SINT4 iant_diag_size ;

  /* The last transmission not starting with an 80, C0, or B0 hex
   * which got an error
   */
  UINT1 sother_diagnostic[BITE_MAX_LENGTH] ;
  SINT4 iother_diag_size ;

  /* Dual RCP system parameters
   */
  struct drcp_status drcp ;	/* Overall System Status */    
  UINT2 iDrcpModeReq ;		/* Requested mode (A/B/Auto) */
  UINT1 lDrcpWouldUseReq ;	/* Requested "Would use if available" flag */
  UINT1 lDrcpRelinquishReq ;	/* Requested "Relinquish control to other" flag */
} ;

struct bitesim_unit_info
{
  /* Data packet to transmit back to IRIS for each of the units
   */
  UINT1 sbite_reception[BITE_MAX_LENGTH] ;
  /* Input and output operation counts
   */
  SINT4 iin_cnt ;
  SINT4 iout_cnt ;
  UINT1 lSendUpdate ;  /* Request a new transmission */
  char pad137x3[3] ;
} ;

struct bitesim_info
{
  UINT2 ltake_sample ;
  char pad2x2[2] ;

  /* Current mask data and error flag
   */
  UINT4 iQBiteValues[BITE_NUM_FIELD_DEFS] ; /* Q-BITE values */
  UINT2 lerror_flag ;
  char pad1030x2[2] ;

  /* Relative binary time of last update to the simulated state
   */
  UINT4 ibtime ;

  struct bitesim_unit_info Units[BITE_MAX_UNITS] ;
} ;

struct antsim_global
{
  /* Current information for the simulated antenna.
   */
  struct antsim_info info ;

  /* Setup information for the antenna (hard coded initialization)
   */
  struct ant_manual_setup setup ;
  
  /* Current information for the simulated Bite.
   */
  struct bitesim_info binfo ;

  /* Setup information for bitex definition structures.  (actually
   * initialized from hard-coded info.
   */
  struct bitex_setup bitex ;
} ;

/* =============== Information for I/O Protocols ================
 * EEC machine units per (degree/second)
 */
#define ANTSIM01_VEL_UNITS (1.81)
#define ANTSIM02_VEL_UNITS (8192.0/180.0)

/* =============== Information for Antenna Simulation =================
 */

/* Specify the priorities for the various processes
 */
#define ANTSIM_RCV_PRIORITY_P  (23)
#define ANTSIM_XMT_PRIORITY_P  (23)

EXTERN volatile struct antsim_global *pantsim_c ;
EXTERN SINT4                          antsim_size_c ;
EXTERN SINT4                          antsim_id_c ;

#undef EXTERN
