/**C*
 *
 * Vaisala software source code file
 *
 * Copyright (c) Vaisala Oyj 
 * 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2012, 2013.
 * All rights reserved.
 *
 * $URL: https://subversion.vaisala.com/svn/repos/sigmet/wr_iris_rda/tags/release8.13.6/base/include/dsp.h $
 *
 * $Id: dsp.h 30024 2014-05-28 09:38:37Z rke $
 *
 **C*/
/* **********************************************************************
 * *                                                                    *
 * *       Structure and Parameter Definitions for SIGMET DSPs          *
 * *                                                                    *
 * **********************************************************************
 */
  
#ifndef SIGMET_DSP_H
#define SIGMET_DSP_H 1

#include "embhw/emb_dsp.h"      /* Definitions from embedded hardware */
#include "embhw/wr_modules.h"

/* The maximum number of (I,Q) vectors per bin.  This can also be
 * interpreted as the maximum number of receive channels that the
 * radar can have.
 */
#define MAXVIQPERBIN   2        /* Use two for standard Dual-Pol */

/* Timeout interval for all DSP physical I/O
 */
#define DSP_TIMEOUT_MS  (6000)	/* Milliseconds */

/* Some constants internal to the processor
 */
#define RVP7_ROMRVP  0x00000400	/* Location of RVP.OUT in the RVP7 ROM */
#define RVP7_LOG_SLOPE (1966)	/* 0.0300 dB/LSB for RVP7 */
#define RVPW_LOG_SLOPE (2621)	/* 0.0400 dB/LSB for wide dynamic range processors */

#define RVP7_MAX_XARGS   256	/* Maximum length of XARGS list for */
#define RVP8_MAX_XARGS  1200	/*   each processor family. */
#define RVP9_MAX_XARGS  1200

/* PRF limits (in Hertz) for each type of processor.
 */
#define RVP6_MINPRF     160.0
#define RVP6_MAXPRF    3000.0

#define RVP7_MINPRF      50.0
#define RVP7_MAXPRF   20000.0	/* (In support of DPT1 mode) */

#define RVP8_MINPRF      50.0
#define RVP8_MAXPRF   20000.0

#define RVP9_MINPRF      50.0
#define RVP9_MAXPRF   20000.0

#define RVPX_MINPRF MIN(RVP6_MINPRF,MIN(RVP7_MINPRF,MIN(RVP8_MINPRF,RVP9_MINPRF)))
#define RVPX_MAXPRF MAX(RVP6_MAXPRF,MAX(RVP7_MAXPRF,MAX(RVP8_MAXPRF,RVP9_MAXPRF)))

/* Clutter filtering parameters
 */
#define DSP_NFILTS        8	/* Number of filters supported */

/* Filter selections for each range bin within a prescribed AZ/EL
 * solid angle sector.
 */
struct rvpxSectorFilters {
  SINT4 nBins ;			/* Number of bins in 'binFilters' */
  BIN2 iAzLo, iAzHi ;		/* AZ angle limits */
  BIN2 iElLo, iElHi ;		/* EL angle limits */
  UINT1 binFilters		/* Table of clutter filter choices for */
    [ RVPX_MAXBINS ] ;		/*   each possible range bin. */
} ;


/* Melting layer information for a list of measurement volumes (3D)
 */
struct rvpxMLinfo {
  int16_t  iScanType;           /* scan geometry TASK_SCAN_XXX in sigtypes.h */
  int16_t  nMLsweeps;           /* number of sweeps in the ML polar volume */
  int16_t  nMLrays;             /* number of ML rays in each sweep */
  int16_t  nMLbins;             /* number of ML bins */ 
  BIN2     iMLangRes;           /* in PPI: sweep angle resolution, RHI:offset [BIN2] */
  int16_t  iMLstartM;           /* range of the first gate in the task to output [m]*/
  int32_t  iMLspacingCM;        /* bin spacing to output  [cm] */
  int16_t  iMLthicknessM ;      /* melting Layer thickness [meters] */
  int16_t  iState ;             /* status flag (for reset action, too) */
} ;
#define DSP_ML_RHI_SWINGS (4)   /* we need to allow RHI scans to cover broader than nominal start/end */
#define DSP_ML_RHI_RESDGR (1.)  /* ray spacing in RHI scans [dgr] */
#define DSP_MLSTATE_NONE (0)
#define DSP_MLSTATE_UPLOADING (-1)
#define DSP_MLSTATE_READY (1)
#define DSP_MLSTATE_RESET (2)

/* Information about the active range mask that is being used by the
 * signal processor's data acquisition hardware.
 */
/*
 * Range information is complicated, and different information is needed
 * in different stages of the processing.  The stages are:
 * Stage 1: Info needed configure and acquire time series.
 * Stage 2: Info needed to process time series into moments (R0, R1, etc.).
 * Stage 3: Info needed to process moments into parameters (Z, V, W, etc.).
 * Stage 4: Info needed to understand the parameters.
 * In general, each processing step reads the previous stage info,
 * and makes the next stage info.  We comment each variable below
 * with the applicable stage.
 */

/* Generally all stage 1 information */
#define STRUCT_RVPXRANGEMASKINFO1_DEFINED 1
struct rvpxRangeMaskInfo1 {
    int32_t  iDataBins;         /* Number of data bins (excludes burst bin) */
    uint32_t lDataZero;         /* Range zero (burst) is also a data bin,  */
    int32_t  iDataBinsSec;      /* Second pulse (hybrid) additional bins */
    int32_t  iHwChanMask;       /* Bit mask of downconverter channels used */
    float    fHwClkMHz;         /* Frequency of hardware sampling clock */
    int32_t  iHwBitTab[RVPX_MAXBINS];/* Hardware bits selected for each range*/
    float    fRangesKM[RVPX_MAXBINS];/* Table of defined data bin ranges (km)*/
} ;

/* All stage 3 information */
#define STRUCT_RVPXRANGEMASKINFO3_DEFINED 1
struct rvpxRangeMaskInfo3 {
    int32_t  iMaxBins[2];       /**< Max number of bins (to compute stride) */
    int32_t  iBlendingStart;    /**< First bin to use for blending of 2 pulses */
    int32_t  iBlendingEnd;      /**< One-after-last blending bin, < or = of both
                                   total numbers of bins - iMaxBins[2] */
    int32_t  iRangeAvg;         /* # bins to average in range, Stage 3 */
    float    fRangesKM[RVPX_MAXBINS];/* Table of data bin ranges (km)*/
} ;

/* All stage 4 information */
#define STRUCT_RVPXRANGEMASKINFO4_DEFINED 1
struct rvpxRangeMaskInfo4 {
    int32_t  iAvgBins;          /* Number of data bins */
    float    fRangesKM[RVPX_MAXBINS];/* Table of data bin ranges (km)*/
} ;

/* Structure to hold all of the results from a noise measurement
 */
struct rvpxNoise {
  FLT4 fimean ;			/* Mean value of I   */
  FLT4 fqmean ;			/* Mean value of Q   */
  FLT4 fisqmean ;		/* Mean value of I^2 */
  FLT4 fqsqmean ;		/* Mean value of Q^2 */
  FLT4 fNoiseDbm ;		/* Present noise level in dBm */
  FLT4 fNoiseStdvDB ;		/* Noise sample standard deviation (dB) */
} ;


/** Structure that holds per RX channel, per Down-Conversion (sub-pulse) channel
    volitile (changing) parameters */
struct rvpxChannelParams {
    float fNoiseLeveldBm;
    float fNoiseStdvDB;
    float fBurstPulsePowerdBm;
} ; 

/** Structure that holds per RX channel, per Down-Conversion (sub-pulse) channel
    calibration parameters */
#define STRUCT_RVPXCHANNELCALIB_DEFINED 1
struct rvpxChannelCalib {
    float fZCal;   /**< fZCal constant with respect to the noise at calibration, unchanged */
    struct rvpxChannelParams calibration;
    struct rvpxChannelParams current;
} ; 

struct rvpxCalib {
    int8_t is_used;
//    float saturation_dbm; /** Max  A/D full scale power (dBm) */
    float fGdrOffsetdB; /**< H/V gain ratio of TX and RX combined (Zdr) */
    float fXdrOffsetdB; /**< H/V gain ratio of RX only (Ldr) */   
    struct rvpxChannelCalib CalibData[MAXVIQPERBIN];
};


/* Coherent Processing Interval (CPI) parameters
 */
#define RVPXASTABSIZE  4096	/* Max size of antenna sync table */

/* Parameters related to range bin selection and averaging
 */
#define DSP_MAXAVG       16	/* Largest permitted range averaging factor */
#define USERMASKLEN     512	/* Number of 16-bit range mask words */
#define CUSTOMRNVSIZE   251     /* Custom range normalization lookup table size */

/* What kind of Dual/Multiple PRF scheme we are using.  Note that the
 * number of custom trigger sequences here should match the parameter
 * CUSTOMTRIGS.
 */
#define PRF_FIXED   (0)		/* Fixed trigger rate */
#define PRF_2_3     (1)		/* 2:3 PRF Ratio */
#define PRF_3_4     (2)		/* 3:4 PRF Ratio */
#define PRF_4_5     (3)		/* 4:5 PRF Ratio */
#define PRF_SEQ0    (4)		/* Custom sequence 0 */
#define PRF_SEQ1    (5)		/* Custom sequence 1 */
#define PRF_SEQ2    (6)		/* Custom sequence 2 */
#define PRF_SEQ3    (7)		/* Custom sequence 3 */

/* What kind of polarization transmission is being used.  These
 * bits are input to the PROC command, and antenna library where
 * relevent.
 */
#define POL_HORIZ_FIX    (0)	/* Horizontal fixed */
#define POL_VERT_FIX     (1)	/* Vertical fixed */
#define POL_ALTERNATING  (2)	/* Alternating between H and V */
#define POL_SIMULTANEOUS (3)	/* Simultaneous on both H and V */
#define POL_UNCHANGED    (7)    /* Do not change the polarization (in RCP02) */

/* Options for transmitted phase sequence.
 */
#define PHSEQ_FIXED   (0)	/* Unmodulated output */
#define PHSEQ_RANDOM  (1)	/* Random sequence */
#define PHSEQ_CUSTOM  (2)	/* Custom user defined sequence */
#define PHSEQ_SZ8_64  (3)	/* Sachi/Zrnic sequence */

/* Transmitter channel setup options and bits.
 */
#define TX_APPLY_MODE        (0x0001)
#define TX_APPLY_PHASEMOD    (0x0002)
#define TX_APPLY_ABRUPTPH    (0x0004)
#define TX_APPLY_PEAKPOWER   (0x0008)
#define TX_APPLY_FREQMHZ     (0x0010)
#define TX_APPLY_PHASEDEG    (0x0020)
#define TX_APPLY_POWERDBM    (0x0040)
#define TX_MODE_UNUSED       (0)        /*   Unused (no signal is output) */
#define TX_MODE_FIXEDFREQ    (1)        /*   Freerunning numerically controlled oscillator */
#define TX_MODE_TXWAVEFORM   (2)        /*   Actual synthesized Tx waveform */
#define TX_BITS_CHAN_SEL     (0x0100)
#define TX_BITS_MODE         (0x0600)
#define TX_BITS_PHASEMOD     (0x0800)
#define TX_BITS_ABRUPTPH     (0x1000)
#define TX_BITS_PEAKPOWER    (0x2000)
#define TX_TOTAL_ARGS_SIZE   (6)

/* Available output formats when the signal processor is
 * collecting Time Series / Power Spectrum data.
 */
#define ENUM_SIGMET_DSP_TSOUT_FORMAT_DEFINED 1
enum sigmet_dsp_tsout_format
{
    DSP_TSOUT_TS8   = 0,       /*  8-bit Time Series */
    DSP_TSOUT_TS16  = 1,       /* 16-bit Time Series */
    DSP_TSOUT_SPEC  = 2,       /* Power Spectrum */
    DSP_TSOUT_HISNR = 3        /* Packed TS16 w/higher SNR */
};
#define DSP_TSOUT_MASK   (0x07)

/* Possible choices of spectrum to view.  These values may be
 * combined only with the DSP_TSOUT_SPEC format choice.
 */
#define ENUM_SIGMET_DSP_SPEC_TYPE_DEFINED 1
enum sigmet_dsp_spec_type
{
    DSP_SPEC_RAW1    = 0x00,   /* Raw first trip */
    DSP_SPEC_WHITE1  = 0x10,   /* Whitened first trip */
    DSP_SPEC_CLEAN1  = 0x20,   /* Cleaned first trip */
    DSP_SPEC_FINAL1  = 0x30,   /* Final first trip */
    DSP_SPEC_RAW2    = 0x40,   /* Raw second trip */
    DSP_SPEC_WHITE2  = 0x50,   /* Whitened second trip */
    DSP_SPEC_CLEAN2  = 0x60,   /* Cleaned second trip */
    DSP_SPEC_FINAL2  = 0x70,   /* Final second trip */
    DSP_SPEC_RAWRES1 = 0x80,   /* Raw residual first trip */
    DSP_SPEC_RAWRES2 = 0x90    /* Raw residual second trip */
};
#define DSP_SPEC_MASK     (0xF0)

#define DSP_SPEC_BIT( OPT ) (1 << (((OPT) & DSP_SPEC_MASK ) >> 4))
#define DSP_SPEC_DEFAULT_BITS \
  ( DSP_SPEC_BIT( DSP_SPEC_RAW1   ) | DSP_SPEC_BIT( DSP_SPEC_WHITE1 ) | \
    DSP_SPEC_BIT( DSP_SPEC_CLEAN1 ) | DSP_SPEC_BIT( DSP_SPEC_FINAL1 ) | \
    DSP_SPEC_BIT( DSP_SPEC_RAW2   ) | DSP_SPEC_BIT( DSP_SPEC_WHITE2 ) | \
    DSP_SPEC_BIT( DSP_SPEC_CLEAN2 ) | DSP_SPEC_BIT( DSP_SPEC_FINAL2 ) )

/* Possible choices of time series to view.  These values may be
 * combined only with the DSP_TSOUT_TS* format choices.
 */
#define ENUM_SIGMET_DSP_TS_TYPE_DEFINED 1
enum sigmet_dsp_ts_type
{
    DSP_TS_PULSE1    = 0x00,   /* Data from first pulse */
    DSP_TS_PULSE2    = 0x01,   /* Data from second pulse */
};
#define DSP_TS_MASK     (0x03)

/* DSPX Scope plotting definitions.
 */
#define MAXPLOTS 16		/* Max # of plotted lines (can't exceed 16) */
#define PLOTLEN 500		/* Length of data plots */

/* ------------------------------
 * Target simulator definitions.  Beginning with the RVP8, the signal
 * processor can simulate physical targets that are mixed in with the
 * realtime receiver (I,Q) values.
 */
#define DSPPHYSTARGSIMCOUNT  4	/* Max number of simulated targets */

struct dspPhysTargSim {		/* Parameters to simulate a physical target */
  UINT1 iFlags ;		/*   This simulated target is enabled */
#define DPTS_SIMCOPOL   0x01	/*     Apply signal to Co-Pol Rx channel */
#define DPTS_SIMCXPOL   0x02	/*     Apply signal to Cross-Pol Rx channel */
  char  ipad1x1[1] ;
  UINT2 iStartKM10 ;		/*   Starting range and span of the */
  UINT2 iLengthKM10 ;		/*     target in tenths of km. */
  SINT2 iPowerDB10 ;		/*   Power in tenths of dB relative to saturation */
  SINT2 iPowerSpanDB10 ;	/*     and delta over the range span. */
  SINT2 iDopplerHZ ;		/*   Target Doppler shift in tenths of Hz, */
  SINT2 iDopplerSpanHZ ;	/*     and delta over the range span. */
  char  ipad14x6[6] ;
} ;

/* ------------------------------
 * Task identification information describing the meaning of the data
 * that are being collected.
 */
#define DSPSITENAMELEN 16	/* Site name length within DSPs */
#define DSPTASKNAMELEN 16	/* Task name length within DSPs */

struct dspTaskID {
  UINT2 iSweep ;		/* Sweep number within a task */
  UINT2 iAuxNum ;		/* Auxiliary sequence number */
  char sTaskName[1+DSPTASKNAMELEN] ; /* Name of the task (NULL terminated) */
  UINT1 iScanType ;		/* Scan geometry, one of SCAN_xxx */
  char pad22x2[2] ;
} ;
struct dspTaskID_IO {		/* I/O Version encoded as UINT2's */
  UINT2 iSweep, iAuxNum ;
  UINT2 sTaskName[DSPTASKNAMELEN/2] ;
  UINT2 iScanType, pad22x3[3] ;
} ;

/* ------------------------------
 * User supplied bits (uninterpreted by the signal processor itself)
 * that are supplied via XOP_UIQBITS and read back via RBACK_UIQBITS.
 * The bits are guaranteed to be glitch-free to reader apps within
 * internal 32-bit integers, but not necessarilly across those 32-bit
 * boundaries.
 */
struct uiqbits {		/* Generic user bits */
  UINT4 iLong[2] ;		/*   No interpretation, just size */
} ;

/* ------------------------------
 * Spectral clutter filter definitions
 */
struct dspSpecFilt {
  SINT4 iType ;			/* Spectral Filter Type */
#define SPFILT_FIXED      0	/*   Fixed width filter */
#define SPFILT_VARIABLE   1	/*   Variable width based on slope */
#define SPFILT_VARLSQ     2	/*   Variable width, least squares */
#define SPFILT_GMAP       3	/*   Gaussian Model Adaptive Processing */
#define SPFILT_NUMCODES     4

  SINT4 iMinWidth ;		/* Minimum width (center plus one side) */
  SINT4 iSlopePts ;		/* Additional central points to consider */
  SINT4 iEdgePts ;		/* Edge points for determining interpolation */
#define SPFILTMAXPTS 30		/*   Max filter width (center plus one side) */

  FLT4  fClutWidthMS ;		/* Clutter width (m/sec) for Gaussian model */
  UINT4 iWinType ;		/* Override of data window (one of WIN_XXX), */
#define SPFILT_USEWIN 0x0100	/*   but only if this flag bit is also set. */
} ;

struct dspSpecFiltIO {		/* DSP I/O version */
  SINT2 iType ;			/*   Filter Type (Must be first in I/O list) */
  SINT2 iMinWidth ;		/*   Minimum width (center plus one side) */
  SINT2 iSlopePts ;		/*   Additional central points to consider */
  SINT2 iEdgePts ;		/*   Edge points for determining interpolation */
  UINT2 iClutWidthMMS ;		/*   Clutter width (mm/sec) for Gaussian model */
  UINT2 iWinType ;		/*   Flag + Override of data window */
} ;

/* ------------------------------
 * Batch mode parameters configuration
 */
struct dspBatchSetup {
  UINT4 lAvailable ;		/* Provide BATCH major mode */
  FLT4  fLoPrfScl ;		/* Scale and offset for computing the low */
  FLT4  fLoPrfOff ;		/*   PRF from the high PRF. */
  FLT4  fSampsScl ;		/* Scale and offset for computing the number */
  FLT4  fSampsOff ;		/*   of low PRF pulses from high PRF pulses. */
  FLT4  fMaxUnfoldKM ;		/* Maximum range to unfold (km) */
  SINT4 iLoPrfAvgSide ;		/* Additional bins range averaged on each side */
  FLT4  fdBOverRefl ;		/* Power differences (in dB) required to declare */
  FLT4  fdBOverVel ;		/*   unobscured echos for reflectivity, velocity, */
  FLT4  fdBOverWid ;		/*   and width. */
  FLT4  fdBAddNseThr ;		/* Amount to increase low PRF noise threshold */
} ;

/* ------------------------------
 * Extended angle information from the pedestal as well as optional
 * INU measurements.  These are the antenna's supplementary spatial
 * and orientation data, i.e., everything except Earth AZ and EL.
 */
struct dspINU {
  BIN2 iRoll , iPitch , iHead  ;      /* Orientation angles (binary angle) */
  BIN2 iRollV, iPitchV, iHeadV ;      /* Derivitives of above (binang/sec) */
  BIN4 iLatitude, iLongitude ;	      /* Earth location (binary angle) */
  SINT2 iHeight ;		      /* Height (meters relative to MSL) */
  SINT2 iVelEast, iVelNorth, iVelUp ; /* Velocities (centimeters/sec) */
} ;
struct dspAuxPedINU {
  struct dspINU inu ;		/* The INU portion */
  BIN2  iPedAz, iPedEl ;	/* Pedestal AZ and EL (binary angle) */
  BIN2    iAzV,   iElV ;	/* Earth AZ and EL velocity (binang/sec) */
} ;

/* **********************************
 * *                                *
 * *  SOPRM Operational Parameters  *
 * *                                *
 * **********************************
 */
/* ------------------------------
 * Operational Parameter Structure.  The first twenty words are loaded
 * directly by the SOPRM user command; remaining words are loaded via
 * XARGS.
 */
struct opprm {
  UINT2 isamp ;			/*  1: Sample size */
  UINT2 iflags ;		/*  2: Processing/threshold flags */
  SINT2 iz_slope ;		/*  3: LOG conversion Slope */
  SINT2 izns_thr ;		/*  4: LOG noise threshold */
  SINT2 iccr_thr ;		/*  5: Clutter correction threshold */
  UINT2 isqi_thr ;		/*  6: SQI threshold */
  SINT2 isig_thr ;		/*  7: Signal Power threshold */
  SINT2 iz_calib ;		/*  8: Calibration Reflectivity */
  UINT2 flg_agc  ;		/*  9: Flags / #pulses integrated for AGC */
  UINT2 filter   ;		/* 10: Filter delay & control */
  UINT2 dbt_tcf ;		/* 11: Uncorrected dBZ Threshold Control Flag */
  UINT2 dbz_tcf ;		/* 12: */
  UINT2 vel_tcf  ;		/* 13: */
  UINT2 wid_tcf  ;		/* 14: */
  BIN2  iAzOffset ;		/* 15: Additive offset for measured AZ angles */
  BIN2  iElOffset ;		/* 16: Additive offset for measured EL angles */
  UINT2 gas_atten ;		/* 17: intervening gas attenuation */
  UINT2 zdr_tcf ;		/* 18: Zdr threshold control flags */
  SINT2 zdr_offset ;		/* 19: Fixed offset to correct in Zdr (db*16) */
  UINT2 wavelength ;		/* 20: Radar wavelength in CM * 1000 */
  /* ------- Beginning of XARGS ------- */
  SINT2 ldr_offset ;		/*  1: Fixed offset to correct in LDR (dB*100) */
  UINT2 ibin_smooth ;		/*  2: Range smoothing (0:None, 1:pairs, etc) */
  UINT2 iPtCltDetect ;		/*  3: Point clutter detection parameters */
  UINT2 iPtCltCensor ;		/*  4: Point clutter censoring parameters */
  UINT2 iMismatchTSIgnore ;	/*  5: Bit mask of mismatch conditions to ignore */
  UINT2 iFlagsTS ;		/*  6: Flag bits related to timeseries data stream */
  UINT2 iCltSigPacks[2] ;	/* 7/8 Residual clutter noise margin packed info */
  SINT2 iMeltHgtMeters ;	/*  9: Melting height, meters relative to mean sea level (MSL) */
  SINT2 iBurstPowerDBm100 ;	/* 10: Calibration burst power (in 1/100 of dBm) */
} ;
#define SOPRM_FIXED_ARGS 20	/* Number of fixed args */
#define SOPRM_TOTAL_ARGS 30	/* Total number of args defined */

/* Bits for Operational Parameter Flag word
 */
#define OPF_RNV      0x0001	/* Range normalization (else see OPF_ZRELNSE) */
#define OPF_DSR      0x0002	/* Doppler speckle remover */
#define OPF_LSR      0x0004	/* LOG speckle remover */
#define OPF_FFTPPP   0x0010     /* Calculate exact PPP autocorr's in FFT modes */
#define OPF_2DPASS   0x0020	/* Final 2D (3x3) speckle/unfold pass */
#define OPF_AGC      0x0040	/* Use AGC rather than STC */
#define OPF_R2       0x0080	/* Compute two-lag autocorrelations */
#define OPF_AVGCTH   0x0100	/* Range averaging clutter suppression */
#define OPF_16B      0x0200	/* Output individual params as 16-bits */
#define OPF_ANYSPEC  0x0400	/* Request that spectra size match sample size */
#define OPF_NHD      0x0800	/* Disable ray header in PROC command */
#define OPF_POL      0x3000	/* Two bits of polarization control */
#define OPF_ZRELNSE  0x4000	/* !OPR_RNV ==> Z's are (T/N) rather than (T-N)/N */
#define OPF_DPATT    0x8000     /* Dual pol attenuation correction */

#define POL_FROM_OPF(OPF) (((OPF) >> 12)  &  3)
#define OPF_FROM_POL(POL) (((POL)  &  3) << 12)

/* Bits for Operational Parameter Filter word
 */
#define OPFLT_RESET    0x0100	/* Reset filter state before waiting */
#define OPFLT_WIN      0x0E00	/* Window code in bits 9,10,11 */
#define OPFLT_CTRIGOK  0x1000	/* Allow custom triggers in normal algorithms */
#define OPFLT_UNFDIFF  0x2000	/* Unfold velocity using simple difference */

#define WIN_RECT          0	/* Window codes used within IRIS, as well */
#define WIN_HAMMING       1	/*   as within the signal processors. */
#define WIN_BLACKMAN      2
#define WIN_BLKMANEX      3
#define WIN_VONHANN       4
#define WIN_ADAPTIVE      5
#define NWINTYPES           6	/* Total number of window types */

#define WIN_FROM_OPFLT(OPFLT) (((OPFLT) >> 9)  & 7)
#define OPFLT_FROM_WIN(WIN  ) (((WIN  )  & 7) << 9)

/* Major mode of the signal processor (RVP6 and greater).  Values
 * for bit field within the opprm Flag/AGC word.
 */
#define PMODE_PPP     (0x0)	/* Pulse Pair Doppler */
#define PMODE_FFT     (0x1)	/* FFT Doppler */
#define PMODE_RPH     (0x2)	/* Random Phase Doppler */
#define PMODE_KNMI    (0x3)	/* KNMI custom LOG clutter filter */
#define PMODE_DPT1    (0x4)	/* Dual-PRT Type-1 (for low duty cycle) */
#define PMODE_DPT2    (0x5)	/* Dual-PRT Type-2 (for velocity unfolding) */
#define PMODE_BATCH   (0x6)	/* Legacy WSR88D batched trigger/unfolding */
#define PMODE_ADPDF   (0x7)     /* Adaptive Dual-Pulse Dual-Frequency */

#define PMODE_USER1   (0xC)	/* User-defined modes */
#define PMODE_USER2   (0xD)
#define PMODE_USER3   (0xE)
#define PMODE_USER4   (0xF)
#define PMODE_MAX_COUNT (16)     /* Maximum possible number of processing modes */

#define PMODE_FROM_OPF(OPF) (((OPF) & 0x0F00) >> 8)
#define PMODE_INTO_OPF(PMODE,OPF) ( ((OPF) & 0xF0FF) | (((PMODE) & 0xF) << 8) )

/* Threshold control flag bit definitions, and mask words having that
 * selected half of the bits set on.  These are used to generate masks
 * required by the DSPWTHRESH subroutine.
 */
#define TCFTERM_NONE    0       /* The TCFTERM_xx constants are used to */
#define TCFTERM_LOG     1       /*   specify a collection of threshhold */
#define TCFTERM_CSR     2       /*   qualifiers for a given parameter.  */
#define TCFTERM_SQI     3       /*   Up to four my be combined as the  */
#define TCFTERM_WSP     4       /*   nybbles of a 16-bit TCFMASK word.  */
#define TCFTERM_PMI     5
#define TCFTERM_COUNT     6     /* Count of total number of terms */
#define TCFTERM_STRINGS { "---", "LOG", "CSR", "SQI", "SIG", "PMI" }

#define TCFMASK_COMPAT 0x0000   /* For backward compatibility */
#define TCFMASK_LEGACY 0x4321   /* Legacy WSP/SQI/CSR/LOG combination */

#define TCF_Q0    0xAAAA        /* The four TCFMASK terms are combined  */
#define TCF_Q1    0xCCCC        /*   in an arbitrary Boolean expression */
#define TCF_Q2    0xF0F0        /*   to qualify each parameter.         */
#define TCF_Q3    0xFF00

#define TCF_LOG   TCF_Q0        /* Legacy threshold control flags, only   */
#define TCF_CSR   TCF_Q1        /*   for TCFMASK_LEGACY or TCFMASK_COMPAT */
#define TCF_SQI   TCF_Q2
#define TCF_WSP   TCF_Q3

/* Bits for Operational Parameter iFlagsTS word (timeseries flags)
 */
#define OPTS_ZCAL       0x0001	/* Obtain calibration info from TS */
#define OPTS_NOISE      0x0002	/* Obtain noise levels from TS */
#define OPTS_NOSATLOG   0x0004	/* LOG threshold unaffected by saturated clutter */

/* Packed information for residual clutter LOG noise margin adjustment
 */
#define CLTSIG_DEFAULT  0x0000	/* Revert to RVP default values */
#define CLTSIG_LOADNEW  0x8000	/* Load new Beginning dB and Slope */
#define CLTSIG_PACK( BEGDB, SLOPE ) ( CLTSIG_LOADNEW |			\
    ( NINT(   1.0 * MAX( 0.0, MIN( 120.0, (BEGDB) ) ) ) << 8 ) |	\
    ( NINT( 100.0 * MAX( 0.0, MIN(   2.5, (SLOPE) ) ) )      ) )
#define CLTSIG_BEGDB( PACK ) ( ((FLT4)(((PACK) >> 8) & 0x7F)) /   1.0 )
#define CLTSIG_SLOPE( PACK ) ( ((FLT4)( (PACK)       & 0xFF)) / 100.0 )

/*  Special code indicating 'unknown' value in iMeltHgtMeters
 */
#define SOPRM_NOMELTHGT (-32768)

/*  Special code indicating 'unknown' value in iBurstPowerDBm100
 */
#define SOPRM_NO_BURSTPWR (SINT2)(0x8000)


/* Threshold comparison and control structure for one individual type
 * of data parameter.
 */
struct dspThreshOneParam {
  UINT2 iTCF ;			/* Threshold control flag bit mask */
  UINT2 iTCFMask ;              /* TCFTERM_xxx choices in nybbles */
  FLT4  fLOG_dB ;               /* LOG (total power) threshold (dB) */
  FLT4  fCCR_dB ;               /* Clutter Correction threshold (dB) */
  FLT4  fSQI ;			/* SQI threshold (fraction, [0-1])*/
  FLT4  fWSP_dB  ;              /* Weather Signal Power threshold (dB) */
  FLT4  fPMI ;                  /* Probability of MET target ([0-1]) */
} ;
struct dspThreshOneParamAUG {   /* Augmented with redundant terms for  */
  struct dspThreshOneParam t ;  /*   computational efficiently in RVPs */
  struct {
    FLT4 fLOG_lin, fCCR_lin, fWSP_lin ;
    struct { UINT2 iTCF, iTCFMask ; } postClass ;
  } u ;
} ;

/* ****************************************
 * *                                      *
 * *  GPARM Current Operating Parameters  *
 * *                                      *
 * ****************************************
 */
/* ------------------------------
 * Structure holding output data in response to the GPARM command
 */
#define DSP_GPARM_SIZE (128)

#define SIGMET_GPARM_DEFINED 1
struct gparm {
  UINT2 irev_ser ;		/* 01: Rev/Serial # */
  UINT2 ibin_out_num ;		/* 02: # range bins output by processor */
  UINT2 iprt_mes ;		/* 03: Current trigger period */
  UINT2 itaga ;			/* 04: Tag bits 00 - 15 */
  UINT2 itagb ;			/* 05: Tag bits 16 - 31 */
  UINT2 log_nse ;		/* 06: Log Channel Noise */
  SINT2 i_nse_ ;		/* 07: I Channel Noise */
  SINT2 q_nse_ ;		/* 08: Q Channel Noise */
  UINT2 istat_l ;		/* 09: Latched status */
  UINT2 istat_i ;		/* 10: Immediate status */
  UINT2 idiag_a ;		/* 11: Diagnostic Results A */
  UINT2 idiag_b ;		/* 12: Diagnostic Results B */
  UINT2 isamp ;			/* 13: # pulses / ray */
  UINT2 itrg_cnt_a ;		/* 14: Low 16 bits of trigger count */
  UINT2 itrg_cnt_b ;		/* 15: High 8 bits of trigger count */
  UINT2 iaqbins ;		/* 16: # properly acquired bins */
  UINT2 iprbins ;		/* 17: # properly processed bins */
  UINT2 istat_i2 ;		/* 18: Immediate Status (second word) */
  UINT2 inse_rng ;		/* 19: Noise range in Km */
  UINT2 inse_prt ;		/* 20: Noise period */
  UINT2 ipwmin_0 ;		/* 21: Pulse width 0 min trigger period */
  UINT2 ipwmin_1 ;		/* 22: Pulse width 1 min trigger period */
  UINT2 ipwmin_2 ;		/* 23: Pulse width 2 min trigger period */
  UINT2 ipwmin_3 ;		/* 24: Pulse width 3 min trigger period */
  UINT2 ipw_bits ;		/* 25: Pulse width bit patterns */
  UINT2 ipw_now ;		/* 26: Current pulsewidth choice */
#define GPARM_PW_PULSE1_MASK   (0x000f)
#define GPARM_PW_PULSE1_SHIFT  (0)
#define GPARM_MAJOR_MODE_MASK  (0x00f0)
#define GPARM_MAJOR_MODE_SHIFT (4)
#define GPARM_WINDOW_MASK      (0x0700)
#define GPARM_WINDOW_SHIFT     (8)
#define GPARM_HAS_PULSE2_FLAG  (0x0800)
#define GPARM_PW_PULSE2_MASK   (0xf000)
#define GPARM_PW_PULSE2_SHIFT  (12)
  UINT2 iprt_gen ;		/* 27: Current trigger generator period */
  UINT2 iprt_des ;		/* 28: Desired trigger generator period */
  UINT2 iprt_start ;		/* 29: Measured PRT at start of last ray */
  UINT2 iprt_end ;		/* 30: Measured PRT at end of last ray */
  UINT2 iflags ;		/* 31: Processing/threshold flags */
  SINT2 iz_slope ;		/* 32: LOG conversion Slope */
  SINT2 izns_thr ;		/* 33: LOG noise threshold */
  SINT2 iccr_thr ;		/* 34: Clutter correction threshold */
  UINT2 isqi_thr ;		/* 35: SQI threshold */
  SINT2 isig_thr ;		/* 36: Signal Power threshold */
  SINT2 iz_calib ;		/* 37: Calibration Reflectivity */
  UINT2 iqi_now ;		/* 38: (Q,I) current A/D sample */
  UINT2 iz_now ;		/* 39: LOG current A/D sample */
  UINT2 ibin_avg ;		/* 40: Range averaging choice (0:None, 1:Pairs, etc) */

  UINT2 idiag_c ;		/* 41: Reserved for future diagnostic bits */
  UINT2 idiag_d ;		/* 42: Reserved for future diagnostic bits */

  UINT2 iproc_hdr0 ;		/* 43: Bits 0-15 defining header of PROC rays */

  UINT2 isq_lo ;		/* 44: Noise sample average value of I squared, */
  SINT2 isq_hi ;		/* 45:   expressed as a 32-bit quantity. */
  UINT2 qsq_lo ;		/* 46: Same for Q... */
  SINT2 qsq_hi ;		/* 47:  */

  SINT2 zlin_noise ;		/* 48: Linearized LOG power noise sample mean */
  SINT2 zlin_rms  ;		/* 49: Linearized LOG power noise root-mean-square */

  SINT2 inse_hv_ratio ;		/* 50: Horiz/Vert noise ratio in dB*100 */

  SINT2 iafclevel ;		/* 51: Signed 16-bit AFC level */

  UINT2 intflt ;		/* 52: Interference filter (bits  3:0) */
				/*            Minor Version (bits  7:4) */
				/*       IFD Sat.Power Code (bits 11:8) */
  SINT2 intflt_p1 ;		/* 53: Interference filter parameter #1 */
  SINT2 intflt_p2 ;		/* 54: Interference filter parameter #1 */

  UINT2 istat_i3 ;		/* 55: Immediate Status (third word) */
  SINT2 itrigslew ;		/* 56: Burst tracking slew (usec * 100) */

  UINT2 iPolFlags ;		/* 57: Polarization flags */
#define POLFLAG_TX_H     0x0001	/*       Use H transmissions for (T,Z,V,W) */
#define POLFLAG_TX_V     0x0002	/*       Use V transmissions for (T,Z,V,W) */
#define POLFLAG_RX_CO    0x0004	/*       Use Co-Pol reception for (T,Z,V,W) */
#define POLFLAG_RX_CX    0x0008	/*       Use Cross-Pol reception for (T,Z,V,W) */
#define POLFLAG_CNOISE   0x0010	/*       Correct polar power params for noise */
#define POLFLAG_FILTER   0x0020	/*       Use filtered data for all polar params */
#define POLFLAG_PHISIGN  0x0040	/*       Sign convention for PHIdp */
#define POLFLAG_CNOISECOV 0x0100 /*       Correct polar phase params for noise */
#define POLFLAG_DPATTEN  0x0080  /*       Z and ZDR are corrected for attenuation using PhiDP */

  UINT2 iMaskSpacingCM ;	/* 58: Range mask spacing (cm) for current pulsewidth */

  UINT2 istat_i4 ;		/* 59: Immediate Status (fourth word) */

  UINT2 unused_word_60 ;	/* 60:  */
  UINT2 unused_word_61 ;	/* 61:  */
  UINT2 unused_word_62 ;	/* 62:  */
  UINT2 unused_word_63 ;	/* 63:  */
  UINT2 unused_word_64 ;	/* 64:  */
} ;

/* Bits in GPARM latched status word
 */
#define GLS_NTRIGNSE	 0x0001	/* No trigger during noise measurement */
#define GLS_FASTNSE	 0x0002	/* Trig too fast during noise measurement */
#define GLS_NTGPROC	 0x0004	/* No trigger during PROC command */
#define GLS_PRFVARIED	 0x0008	/* PRF varied from beginning to end of ray */
#define GLS_POLERROR	 0x0010	/* Error in polarization control/status */
#define GLS_FIFOERROR	 0x0020	/* Buffer overflow during PROC command */
#define GLS_OLOST	 0x0040	/* Some user output words were lost */
#define GLS_NOISERROR	 0x0080	/* Error detected during noise measurement */
#define GLS_RMASK	 0x0200	/* Range mask error */
#define GLS_SIMULATE	 0x0400	/* Simulated data sequencing error */
#define GLS_PHSEQMES	 0x0800	/* Measured phase sequence is incorrect */
#define GLS_NOLICENSE	 0x2000	/* Attempt to use an unlicensed feature */
#define GLS_ZLINSE	 0x4000	/* Error in linear Z noise calculation */
#define GLS_PMODERR	 0x8000	/* Configuration error during PROC command */

#define MAXPRTVARYUSEC 10.0	/* Maximum allowable PRT (1/PRF) variation */

/* Bits in GPARM immediate status word (#1)
 */
#define GIS_NOTRIG       0x0001	/* No trigger */
#define GIS_SYLDERR      0x0002	/* Error loading sync angle table */
#define GIS_PWINFO       0x0004	/* PWINFO command is enabled */

#define GIS_SYBCD        0x0008	/* Sync: angles are BCD */
#define GIS_SYEL         0x0010	/* Sync: angles are for elevation axis */
#define GIS_SYENAB       0x0020	/* Sync: enabled */
#define GIS_SYSHORT      0x0040	/* Sync: allow rays from short pulse groups */
#define GIS_SYDYNAM      0x0080	/* Sync: dynamic ray width (else table bounds) */
#define GIS_SYOPBITS     0x00F8	/* The above four bits */

#define GIS_HASIAGC      0x0100	/* An AUX board with IAGC is connected */
#define GIS_16BITTS      0x0200	/* 16-bit time series is supported */

#define GIS_UMODE0	 0x0400	/* 2-bit unfolding mode */
#define GIS_UMODE1	 0x0800

#define GIS_NAUX0	 0x1000	/* Count of # of AUX boards attached */
#define GIS_NAUX1	 0x2000

#define GIS_SPEC	 0x4000	/* Power Spectrum output is supported */

/* Bits in GPARM immediate status word (#2)
 */
#define GI2S_FFT	 0x0001	/* FFT processing mode is supported */
#define GI2S_RPH	 0x0002	/* Random phase mode is supported */
#define GI2S_KNM	 0x0004	/* KNMI LOG filtering is supported */
#define GI2S_DPT1	 0x0008	/* Dual-PRT Type-1 is supported */
#define GI2S_UPLERR	 0x0010	/* Error in uplink to receiver */
#define GI2S_DNLERR	 0x0020	/* Downlink error / no signal detected */
				/* 0x0040 was: separate noise levels per PW */
#define GI2S_PLLERR	 0x0080	/* Error in user clock PLL in receiver */

#define GI2S_AFCBITS     0x0700	/* Current AFC status code */
#define GI2S_AFCLOWBIT   8

#define AFC_DISABLED  1
#define AFC_MANUAL    2
#define AFC_NOBURST   3
#define AFC_WAIT      4
#define AFC_LOCKED    5
#define AFC_TRACK     6

#define GI2S_IFDSWS	 0x0800	/* Receiver's switches not set to "run" */
#define GI2S_TBLANK	 0x1000	/* Trigger blanking is enabled */
#define GI2S_NOBURST	 0x2000	/* Missing signal at IFD burst input */
#define GI2S_DSPCOUNT	 0x4000	/* DSP count may be less than what's available */
#define GI2S_SLIPBURST	 0x8000	/* Burst pulse energy is not well centered */

/* Bits in GPARM immediate status word (#3)
 */
#define GI3S_BPTIMEADJ	 0x0001	/* Burst Pulse time adjustments are okay */
#define GI3S_BPFREQADJ	 0x0002	/* Burst Pulse frequency adjustments are okay */
#define GI3S_BPHUNTENA	 0x0004	/* Burst Pulse hunting is enabled */
#define GI3S_BPHUNTNOW	 0x0008	/* Hunting is running right now */
#define GI3S_BPHFAIL	 0x0010	/* Last hunt failed to find the burst */
#define GI3S_DPT2	 0x0020	/* Dual PRT (Type 2) is supported */
#define GI3S_PHSEQGEN	 0x0040	/* Could not generate the requested phase seq */
#define GI3S_TXCLK	 0x0080	/* Problem with digital transmitter clock */
#define GI3S_USER1	 0x0100	/* Extended user PMODEs are supported */
#define GI3S_USER2	 0x0200
#define GI3S_USER3	 0x0400
#define GI3S_USER4	 0x0800
/*                       0x1000  Reserved for GI3S_USER5 */
/*                       0x2000  Reserved for GI3S_USER6 */
/*                       0x4000  Reserved for GI3S_USER7 */
/*                       0x8000  Reserved for GI3S_USER8 */

/* Bits in GPARM immediate status word (#4)
 */
#define GI4S_ANYSPECINT  0x0001	/* Power spectra for params matches sample size */
#define GI4S_ANYSPECOUT  0x0002	/* PROC output spectra match sample size */
#define GI4S_ALTPATTERN  0x0004	/* Bits indicating that the trigger */
#define GI4S_ALTPERIOD   0x0008	/*   pattern and/or PRT were altered. */
#define GI4S_IQPACKHISNR 0x0010	/* Using High-SNR packed (I,Q) format */
#define GI4S_ALTTRUNC    0x0020	/* Out-of-Memory, triggers truncated */
#define GI4S_EXTERNALTS  0x0040	/* TimeSeries data source is external to the DSP */
#define GI4S_BATCH       0x0080	/* Batch processing mode is supported */
#define GI4S_CANTEXTRIG  0x0100	/* Major mode refuses to use external trigger */
#define GI4S_NSEFMTPACK  0x0200	/* Use packed format for i_nse and q_nse */
#define GI4S_RXPROTFLT   0x0400	/* Receiver protection fault */
#define GI4S_IFDCHANERR  0x0800	/* IFD dual-channel inconsistency */
#define GI4S_GPS1PPSERR  0x1000	/* GPS 1-pulse-per-second clock error */

/* Scale factors for encoding/decoding trigger periods
 */
#define TREQSCL 6000000.0	/* Scale factors for I/O encoding of */
#define TMESSCL 1200000.0	/*  requested and measured PRT/PRF. */

/* ------------------------------
 * Extended parameter information structure.  These are elements that
 * really should be included in GPARM, but that structure has become
 * full.  The 'IO' form is used between the signal processor and the
 * DSP driver.
 */
struct dspExParm {		/* Extended DSP parameter readback */
  char sSiteName		/*  Site name (NULL terminated) */
    [ DSPSITENAMELEN+1 ] ;
  char pad17x3[3] ;

  FLT4 fMaxRangeKM ;		/* Furthest range mask bin (km) */

  FLT4 fPulseWidthUSec ;	/* Pulsewidth in microseconds */
  FLT4 fBandWidthMHz ;		/* Tx/Rx Bandwidth in megaHertz */

  struct ymds_time rayUTC ;	/* UTC time of last processed ray */

  FLT4  fBurstFreqMHz ;		/* Measured frequency and power of the */
  FLT4  fBurstPowerDBm ;	/*   primary channel burst pulse. */

  UINT1 iBurstPhaseLock ;	/* Lock (I,Q) data to burst (one of BPLOCK_xxx) */
  UINT1 lBurstAmplCor ;	        /* Pulse-to-pulse amplitude correction being used */

  UINT2 iMismatchTS ;		/* RVP vs TimeSeries mismatched parameters */
#define MMTS_MAJORMODE  0x0001	/*   Major mode of the processor */
#define MMTS_BINCOUNT   0x0002	/*   Number of input bins (range mask bits) */
#define MMTS_UMODE      0x0004  /*   Dual-PRF unfolding mode */
#define MMTS_PWIDTH     0x0008  /*   Pulsewidth selection code */
#define MMTS_PHASEMOD   0x0010  /*   Phase modulation sequence */
#define MMTS_POLAR      0x0020  /*   Transmit Polarization */
#define MMTS_NOMPRF     0x0040  /*   Nominal PRF from last SETPWF opcode */
#define MMTS_BINPLACE   0x0080  /*   Placement of input bins (range mask bits) */
#define MMTS_RMASKRES   0x0100  /*   Range mask resolution */

				/* Desired RVP settings based on last ray */
  UINT2 iRayMajorMode ;		/*   Major mode for data acquisition */
  UINT2 iRayBinCount ;		/*   Overall input bin count */
  UINT1 iRayUmode ;		/*   Dual-PRF unfolding mode */
  UINT1 iRayPWidth ;		/*   Pulsewidth code */
  UINT1 iRayPhaseMod ;		/*   Tx phase modulation */
  UINT1 iRayPolar ;		/*   Tx polarization */
  FLT4  fRayNomPRF ;		/*   Nominal PRF (Hertz) */

  SINT2 iIFDTempCaseDegC[2] ;	/* Temperature of the IFD chassis and of */
  SINT2 iIFDTempFPGADegC[2] ;	/*   the onboard FPGA chip (Centigrade). */
  BIN2 iNoiseAZ, iNoiseEL ;     /* Mean AZ/EL of last noise sample */

  float fBurstPowerDBmPulse2;   /* Burst power of pulse 2*/
  float fPulseWidthUSecPulse2;  /* Pulsewidth in microseconds */
  float fBandWidthMHzPulse2;    /* Tx/Rx Bandwidth in megaHertz */
  float fZCalPulse2;            /* fZCal of the second pulse, (1/100 of dBZ) */
  float fNoisePowerPulse2;      /* Current noise sample mean power in dBm */
  float fNoiseHVRatioPulse2;    /* Current Horiz/Vert noise ratio in dB */
  uint32_t iZ0Corrections;      /* Corrections applied on fdBZ0 at calibration: */
#define Z0CR_NOISE  0x0001      /*  Current noise power / Calibration noise power (nv.lNoiseZ0CorrEnable) */
#define Z0CR_BURST  0x0002      /*  Current burst pulse power / Calibration burst power (nv.lBpZ0CorrEnable) */
#define Z0CR_AMPL   0x0004      /*  Current burst amplitude / Mean burst amplitude (nv.lampc_inuse) */
#define Z0CR_HYBR   0x0008      /*  Hybrid pulsing in use */

  float fCalNoiseHoriz;         /* Calibration noise power in dBm */
  float fCalNoiseHVRatio;       /* Calibration Horiz/Vert noise ratio in dB */
  float fCalNoiseHorizPulse2;   /* Calibration noise power in dBm, 2nd pulse */
  float fCalNoiseHVRatioPulse2; /* Calibration Horiz/Vert noise ratio in dB, 2nd pulse */
  float fGdrOffsetdB;           /* H/V gain ratio of TX and RX combined (Zdr) */
  float fXdrOffsetdB;           /* H/V gain ratio in RX (Ldr) */
  int16_t iMLaveMslM;           /* The average current melting layer altitude (MSL) [m]; (0x8000^) swapped*/
  int16_t iMLminMslM;           /* The lowest current melting layer altitude (MSL) [m]; (0x8000^) swapped  */
  int16_t iMLmaxMslM;           /* The lowest current layer altitude (MSL) [m]; (0x8000^) swapped */
} ;

struct dspExParmIO {		/* DSP I/O structure (APPEND TO END ONLY) */
  UINT2 iSiteName		/* Site name (packed in Lo/Hi order */
    [ DSPSITENAMELEN/2 ] ;	/*   within the 16-bit words. */

  UINT2 iMaxRangeKM ;		/* Kilometer and meter components of */
  UINT2 iMaxRangeM ;		/*   furthest bin in the range mask. */

  UINT2 iPwUSec ;		/* Pulsewidth microsecond and nanosecond */
  UINT2 iPwNSec ;		/*   component parts. */

  UINT2 iRayMsUTC ;		/* UTC last ray time, 16-bit milliseconds and */
  UINT2 iRayLoUTC, iRayHiUTC ;	/*   32-bit seconds. */

  UINT2 iBurstPhaseLock ;	/* Lock (I,Q) data to burst (one of BPLOCK_xxx) */
  UINT2 lBurstAmplCor ;    	/* Pulse-to-pulse amplitude correction being used */

  UINT2 iMismatchTS ;		/* RVP vs TimeSeries mismatched parameters */
  UINT2 iRayMajorMode ;		/*   Major mode for data acquisition */
  UINT2 iRayBinCount ;		/*   Overall input bin count */
  UINT2 iRayUmode ;		/*   Dual-PRF unfolding mode */
  UINT2 iRayPWidth ;		/*   Pulsewidth code */
  UINT2 iRayPhaseMod ;		/*   Tx phase modulation */
  UINT2 iRayPolar ;		/*   Tx polarization */
  UINT2 iRayHiNomPRF ;		/*   Nominal PRF (Hertz) */
  UINT2 iRayLoNomPRF ;		/*     (and Hertz / 2^16) */

  UINT2 iBandWidthKHz ;         /* Tx/Rx Bandwidth in kiloHertz */

  UINT2 iBurstFreq2KHz ;	/* Burst frequency (2KHz increments) */
  SINT2 iBurstPowerDBm100 ;	/* Burst power (hundredths of dBm) */

  SINT2 iIFDTempCaseDegC[2] ;	/* Temperature of the IFD chassis and of */
  SINT2 iIFDTempFPGADegC[2] ;	/*   the onboard FPGA chip (Centigrade). */

  UINT2 iNoiseAZ, iNoiseEL ;	/* Mean AZ/EL of last noise sample */

  /* The eight values below here are available in the RVP9 */
  int16_t iZCalPulse2;          /* fZCal of second pulse, (1/100 of dBZ) */
  int16_t iNoisePowerPulse2;  /* Noise sample mean power in dBm*100 */
  int16_t iNoiseHVRatioPulse2;/* Horiz/Vert noise ratio in dB*100 */
  int16_t iBurstPowerDBm100Pulse2;  /* Burst power of pulse 2*/

  uint16_t iPwUSecPulse2;     /* Pulsewidth microsecond and nanosecond */
  uint16_t iPwNSecPulse2;     /*   component parts. */
  uint16_t iBandWidthKHzPulse2; /* Tx/Rx Bandwidth in kiloHertz */
  uint16_t iZ0Corrections ;     /* Corrections applied on fdBZ0 at calibration */

  /* Available in RVP8, RVP9 */
  int16_t iCalNoiseHoriz;        /* Calibration noise power in IF dBm */
  int16_t iCalNoiseHVRatio;      /* Calibration Horiz/Vert noise ratio in dB */
  /* Available in RVP9 */
  int16_t iCalNoiseHorizPulse2;  /* Calibration noise power in IF dBm */
  int16_t iCalNoiseHVRatioPulse2;/* Calibration Horiz/Vert noise ratio in dB */
  int16_t iGdrOffsetdB;          /* H/V gain ratio of TX and RX combined (Zdr) */
  int16_t iXdrOffsetdB;          /* H/V gain ratio in RX (Ldr) */
  int16_t iMLaveMslM;            /* The average current melting layer altitude (MSL) [m] */
  int16_t iMLminMslM;            /* The lowest current melting layer altitude (MSL) [m] */
  int16_t iMLmaxMslM;            /* The lowest current layer altitude (MSL) [m] */
} ;

/* ***********************************
 * *                                 *
 * *  OpCodes and Output Parameters  *
 * *                                 *
 * ***********************************
 */
/* ------------------------------
 * The DSPALLPARAMS macro provides a maintainable way of performing
 * operations on the entire set of parameters.  Note that the order of
 * these statements may be important depending on the specific macro
 * operations being performed (e.g., the ordering of multiple output
 * parameters is determined here).
 */
#define DSPALLPARAMS( MACRO ) \
  MACRO(    dbz, DBZ    )  MACRO(    dbt, DBT    )  MACRO(    vel, VEL    ) \
  MACRO(    wid, WID    )  MACRO(    zdr, ZDR    )  MACRO(    kdp, KDP    ) \
  MACRO(  phidp, PHIDP  )  MACRO(  rhohv, RHOHV  )  MACRO(    sqi, SQI    ) \
  MACRO(   ldrh, LDRH   )  MACRO(   rhoh, RHOH   )  MACRO(   phih, PHIH   ) \
  MACRO(   ldrv, LDRV   )  MACRO(   rhov, RHOV   )  MACRO(   phiv, PHIV   ) \
  MACRO(  flags, FLAGS  )  MACRO( hclass, HCLASS )  MACRO(    snr, SNR    ) \
  MACRO(   dbza, DBZA   )  MACRO(   dbta, DBTA  ) \
  MACRO(   dbze, DBZE   )  MACRO(   dbte, DBTE  )

#define PPRMS_N_DBZ      0	/* Possible bits in iPPrms. */
#define PPRMS_N_DBT      1	/* Can't use DSPALLPARAMS, */
#define PPRMS_N_VEL      2	/*   though we'd like to.   */
#define PPRMS_N_WID      3
#define PPRMS_N_ZDR      4
#define PPRMS_N_KDP      5
#define PPRMS_N_PHIDP    6
#define PPRMS_N_RHOHV    7
#define PPRMS_N_SQI      8
#define PPRMS_N_LDRH     9
#define PPRMS_N_RHOH    10
#define PPRMS_N_PHIH    11
#define PPRMS_N_LDRV    12
#define PPRMS_N_RHOV    13
#define PPRMS_N_PHIV    14
#define PPRMS_N_FLAGS   15
#define PPRMS_N_HCLASS  16
#define PPRMS_N_SNR     17
#define PPRMS_N_DBZA    18
#define PPRMS_N_DBTA    19
#define PPRMS_N_DBZE    20
#define PPRMS_N_DBTE    21

#define PPRMS_N_COUNT   22	/* Number of defined parameter types */

#define PPRMS_DBZ     BIT( PPRMS_N_DBZ    )
#define PPRMS_DBT     BIT( PPRMS_N_DBT    )
#define PPRMS_VEL     BIT( PPRMS_N_VEL    )
#define PPRMS_WID     BIT( PPRMS_N_WID    )
#define PPRMS_ZDR     BIT( PPRMS_N_ZDR    )
#define PPRMS_KDP     BIT( PPRMS_N_KDP    )
#define PPRMS_PHIDP   BIT( PPRMS_N_PHIDP  )
#define PPRMS_RHOHV   BIT( PPRMS_N_RHOHV  )
#define PPRMS_SQI     BIT( PPRMS_N_SQI    )
#define PPRMS_LDRH    BIT( PPRMS_N_LDRH   )
#define PPRMS_RHOH    BIT( PPRMS_N_RHOH   )
#define PPRMS_PHIH    BIT( PPRMS_N_PHIH   )
#define PPRMS_LDRV    BIT( PPRMS_N_LDRV   )
#define PPRMS_RHOV    BIT( PPRMS_N_RHOV   )
#define PPRMS_PHIV    BIT( PPRMS_N_PHIV   )
#define PPRMS_FLAGS   BIT( PPRMS_N_FLAGS  )
#define PPRMS_HCLASS  BIT( PPRMS_N_HCLASS )
#define PPRMS_SNR     BIT( PPRMS_N_SNR    )
#define PPRMS_DBZA    BIT( PPRMS_N_DBZA   )
#define PPRMS_DBTA    BIT( PPRMS_N_DBTA   )
#define PPRMS_DBZE    BIT( PPRMS_N_DBZE   )
#define PPRMS_DBTE    BIT( PPRMS_N_DBTE   )

#define PPSET_POLAR_BASE  ( PPRMS_ZDR   | PPRMS_KDP   | PPRMS_PHIDP | PPRMS_RHOHV )
#define PPSET_POLAR_LDRH  ( PPRMS_LDRH  | PPRMS_RHOH  | PPRMS_PHIH                )
#define PPSET_POLAR_LDRV  ( PPRMS_LDRV  | PPRMS_RHOV  | PPRMS_PHIV                )
#define PPSET_POLAR_TZALT ( PPRMS_DBTA  | PPRMS_DBZA                              )
#define PPSET_POLAR_TZENH ( PPRMS_DBTE  | PPRMS_DBZE                              )

#define PPSET_POLAR_ALL ( PPSET_POLAR_BASE | PPSET_POLAR_LDRH | PPSET_POLAR_LDRV | PPSET_POLAR_TZALT | PPSET_POLAR_TZENH)

/* ------------------------------
 * Standard command opcodes from host computer.  Normal ones
 * occupy lower 5-bits ; extended ones occupy middle 7-bits.
 */
#define OP_NOP       0x00
#define OP_LRMSK     0x01	/* Load range mask */
#define OP_SOPRM     0x02	/* Set operating parameters */
#define OP_IOTEST    0x03	/* Input/Output test */
#define OP_OTEST     0x04	/* Output only test */
#define OP_SNOISE    0x05	/* Sample receiver noise */
#define OP_PROC      0x06	/* Acquire/process data */
#define OP_LSTCB     0x07	/* Load STC and user range bits */
#define OP_LFILT     0x08	/* Load filter versus range */
#define OP_GPARM     0x09	/* Get processor parameters */
#define OP_LSIMUL    0x0A	/* Load simulated time series */
#define OP_LDBCOR    0x0B	/* Load LOG correction table */
#define OP_RESET     0x0C	/* Various resets */
#define OP_TRIGWF    0x0D	/* Set trigger waveforms */
#define OP_RNGOFF    0x0E	/* Set range offset */
#define OP_PWINFO    0x0F	/* Set pulse width bits & bounds */
#define OP_SETPWF    0x10	/* Set pulse width and PRF */
#define OP_LSYNC     0x11	/* Load angle sync info */
#define OP_SLED      0x12	/* Control panel LED */
#define OP_TTYOP     0x13	/* TTY simulated op */
#define OP_LDAGC     0x14	/* Load AGC lookup table */
#define OP_LDRNV     0x15	/* Load custom range norm table */
#define OP_RBACK     0x16	/* Read back internal params */
#define OP_IAGCTRL   0x17	/* Instantaneous AGC control */
#define OP_XARGS     0x18	/* Supply extended args to commands */

#define OP_EXTEND    0x1F
#define XOP_LFSPECS    0x00	/* Load clutter filter specifications */
#define XOP_KNMCMDS    0x01	/* Custom commands for KNMI filters */
#define XOP_CFGHDR     0x02	/* Configure header of PROC output rays */
#define XOP_CFGINTF    0x03	/* Configure interference filter */
#define XOP_BOOT       0x04	/* Load ROM image and reboot */
#define XOP_SETAFC     0x05	/* Set AFC level */
#define XOP_SETSLEW    0x06	/* Set trigger timing slew */
#define XOP_BPHUNT     0x07	/* Hunt for burst pulse */
#define XOP_CFGPHZ     0x08	/* Configure phase modulation */
#define XOP_UIQBITS    0x09	/* Set user bits for IQ headers*/
#define XOP_THRESH     0x0A	/* Set individual parameter thresholds */
#define XOP_TASKID     0x0B	/* Set task identification information */
#define XOP_PRFSECT    0x0C	/* Set trigger waveform within a sector */
#define XOP_TARGSIM    0x0D	/* Configure the internal target simulator */
#define XOP_BPOPTS     0x0E	/* Set Burst Pulse Processing Options */
#define XOP_XMTCHAN    0x0F	/* Set transmitter channel control */
#define XOP_MLSPECS    0x10     /* Load Melting layer specifications */
#define XOP_USRINTR    0x7C	/* User defined opcodes for current major mode */
#define XOP_USRCONT    0x7D	/*   (Interrupting and Continuous side effects) */
#define XOP_LICENSE    0x7F	/* Enable licensed features */

#define XOPC(XOP) ( OP_EXTEND | ((XOP) << 5) )

/* Additional details of the PROC command
 */
#define OP_PROC_MODE    0x00000060 /* Processing mode bit field */
#define OP_PROC_SYNCDOP 0x00000020 /*   Synchronous Doppler */
#define OP_PROC_FREEDOP 0x00000040 /*   Free running Doppler */
#define OP_PROC_TS      0x00000060 /*   Time series */

#define OP_PROC_UMODE   0x00000300 /* Location of PRF unfolding choice */
#define OP_PROC_UMODE_SHIFT      8

#define OP_PROC_KDP     0x00000080 /* Parameter selection bits */
#define OP_PROC_ZDR     0x00000400
#define OP_PROC_WID     0x00000800
#define OP_PROC_VEL     0x00001000
#define OP_PROC_DBT     0x00002000
#define OP_PROC_DBZ     0x00004000
#define OP_PROC_ARCHIVE 0x00008000
#define OP_PROC_PHIDP   0x00010000
#define OP_PROC_RHOHV   0x00020000
#define OP_PROC_SQI     0x00040000
#define OP_PROC_LDRH    0x00080000
#define OP_PROC_RHOH    0x00100000
#define OP_PROC_PHIH    0x00200000
#define OP_PROC_LDRV    0x00400000
#define OP_PROC_RHOV    0x00800000
#define OP_PROC_PHIV    0x01000000
#define OP_PROC_FLAGS   0x02000000
#define OP_PROC_HCLASS  0x04000000
#define OP_PROC_SNR     0x08000000
#define OP_PROC_DBTA    0x10000000
#define OP_PROC_DBZA    0x20000000
#define OP_PROC_DBTE    0x40000000
#define OP_PROC_DBZE    0x80000000

/* Mask of universe of explicit data parameter bits
 */
#define OP_PROC_UBITS ( OP_PROC_DBZ   | OP_PROC_DBT   | OP_PROC_VEL  | \
                        OP_PROC_WID   | OP_PROC_ZDR   | OP_PROC_KDP  | \
                        OP_PROC_PHIDP | OP_PROC_RHOHV | OP_PROC_SQI  | \
                        OP_PROC_LDRH  | OP_PROC_RHOH  | OP_PROC_PHIH | \
                        OP_PROC_LDRV  | OP_PROC_RHOV  | OP_PROC_PHIV | \
                        OP_PROC_DBZA  | OP_PROC_DBTA  | OP_PROC_SNR  | \
                        OP_PROC_DBZE  | OP_PROC_DBTE  | \
                        OP_PROC_FLAGS | OP_PROC_HCLASS )

/* Ray Header options for output rays generated by the PROC command
 * (selected by the CFGHDR command).
 */
#define DSP_HEADER_MAX_SIZE (2*78)  /* Maximum number of bytes output you can get */

#define DSP_HDR_TAGS    0x00000001 /* 32-bit TAGs from start and end */
#define DSP_HDR_PRT     0x00000002 /* Instantaneous PRT (end of ray) */
#define DSP_HDR_PULSES  0x00000004 /* Number of pulses in the ray */
#define DSP_HDR_TSTAMP  0x00000008 /* Millisecond time stamp (end of ray) */
#define DSP_HDR_GPARM   0x00000010 /* Complete GPARM structure */
#define DSP_HDR_FLAGS   0x00000020 /* Miscellaneous flags, see below */
#define DSP_HDR_UTC     0x00000040 /* UTC time plus milliseconds (start of ray) */
#define DSP_HDR_MMTS    0x00000080 /* Mismatch timeseries bits (MMTS_xxx) */
#define DSP_HDR_SYTIME  0x00000100 /* IFD system clock time (start of ray) */
#define DSP_HDR_TSVERS  0x00000200 /* Timeseries playback version number */
#define DSP_HDR_TASKID  0x00000400 /* Task ID encoded as struct dspTaskID_IO */
#define DSP_HDR_AUXANG  0x00000800 /* Aux angles as struct dspAuxPedINU (end of ray) */

#define DSP_HDR_FLG_DPRFLOW  0x0001 /* Dual-PRF is in the low PRF state */
#define DSP_HDR_FLG_BLANKED  0x0002 /* Trigger is blanked for this ray */
#define DSP_HDR_FLG_PRFSECT  0x0004 /* This ray is from a special PRF sector */
#define DSP_HDR_FLG_ENDEDTS  0x0008 /* This ray resulted from a TS writer ending */
#define DSP_HDR_FLG_PRFSECT0 0x0010 /* When DSP_HDR_FLG_PRFSECT is set, */
#define DSP_HDR_FLG_PRFSECT1 0x0020 /*   these bits indicate which PRF  */
#define DSP_HDR_FLG_PRFSECT2 0x0040 /*   was actually selected. */

/* Opcodes for the OP_RBACK read back command
 */
#define RBACK_SOPRM      ( 0)	/* Operating parameters */
#define RBACK_RAYHIST    ( 1)	/* Ray history */
#define RBACK_LDSYNC     ( 2)	/* Angle SYNC table */
#define RBACK_LDAGC      ( 3)	/* AGC mapping table */
#define RBACK_LFILT      ( 4)	/* Filter selection vs range */
#define RBACK_LSTCB      ( 5)	/* STC waveform */
#define RBACK_LDRNV      ( 6)	/* Custom range normalization */
#define RBACK_TAGSAMPS   ( 7)	/* Samples of TAG input lines */
#define RBACK_MASKRES    (10)	/* Range mask bit spacing */
#define RBACK_UIQBITS    (11)	/* Custom 'UserIQ' bits */
#define RBACK_THRESH     (12)	/* Data threshold settings */
#define RBACK_EXPARM     (13)	/* Extended parameters */
#define RBACK_ADCLOHI    (14)	/* Min/Max analog ADC samps */
#define RBACK_LFSPECS    (15)	/* Clutter filter parameter definitions */
#define RBACK_CLSSFIERS  (16)   /* Classifiers' IDs, data formats */
#define RBACK_CLSSNICK   (17)   /* HydroClass configuration nick name */
#define RBACK_TXCHAN     (18)   /* TX channel A/B parameters */

/* Other miscellaneous opcode parameters
 */
#define PRFSECT_MAXSECTS   8	/* Maximum number of PRF sectors */

#define BPL_PHASELOCK_OFF  0x0001 /* Force phase locking OFF */
#define BPL_PHASELOCK_ON   0x0002 /* Force phase locking ON */
#define BPL_AMPLCORR_OFF   0x0004 /* Force Amplitude Correction OFF */
#define BPL_AMPLCORR_ON    0x0008 /* Force Amplitude Correction ON */

#define DSP_LFILT_L3K  3072     /* Legacy 3K bins loaded by LFILT */

#endif /* #ifndef SIGMET_DSP_H */
