/* ---------------------------------------------------------------------- */ 
/* Begin PulseFile.h                                                      */ 
/* Defines the binary format of a pulse data file which contains          */ 
/* parameters for DACs and Input processing (eg matched filters)          */ 
/* ---------------------------------------------------------------------- */ 
/*                                                                        */ 
/* (c) Copyright 1999  EdgeTech,                                          */ 
/*                                                                        */ 
/* This file contains proprietary information, and trade secrets of       */ 
/* EdgeTech, and may not be disclosed or reproduced without the prior     */ 
/* written consent of EdgeTech.                                           */ 
/*                                                                        */ 
/* EdgeTech is not responsible for the consequences of the use or misuse  */ 
/* of this software, even if they result from defects in it.              */ 
/*                                                                        */ 
/* ---------------------------------------------------------------------- */ 

#ifndef __PULSEFILE_H__
#define __PULSEFILE_H__


/* --------------------------------------------------------------------- */ 

#ifndef PULSEFILE_STRING_SIZE

#define PULSEFILE_STRING_SIZE                     (80)

#endif  /* Not PULSEFILE_STRING_SIZE */ 

#define PULSE_FILE_MAGIC_VALUE 0x35799753

/* --------------------------------------------------------------------- */ 
/* ADC and matched filter info.                                          */ 
/* --------------------------------------------------------------------- */ 

typedef struct
{
  /* null terminated ASCII string.                                       */ 
  /* Contains engineering notes - eg how pulse was made.                 */ 
  char description[PULSEFILE_STRING_SIZE];

  /* Logical channel number of data.                                     */ 
  unsigned short int channel;

  /* Pulse transmit phase (1..7).                                        */ 
  unsigned short int transmitPhase;

  /* Desired data sample rate in Hz.                                     */ 
  /* This value should be an EXACT multiple of the internal crystal on   */ 
  /* the acquisition card.  Other constraints may apply.                 */ 
  float sampleRate;

  /* Decimation factor to be applied to the data prior to the start of   */ 
  /* the actual FFT processing                                           */  
  unsigned long int preFFTDecimationFactor;

  /* Number of samples to be annihilated prior to the start of the       */ 
  /* actual FFT processing.                                              */  
  unsigned long int preFFTAnnihilationSize;

  /* Forward FFT size - must be an exponent of 2.                        */  
  unsigned long int forwardFFTSize;

  /* Forward FFT decimation factor - each processing step takes this many*/ 
  /* forward FFTs.  The total forward FFT size is:                       */ 
  /*   forwardFFTSize * forwardFFTDecimationFactor                       */ 
  unsigned long int forwardFFTDecimationFactor;

  /* Inverse complex FFT size - must be an exponent of 2                 */ 
  /* Note that the TOTAL SUBSAMPLING FACTOR is:                          */ 
  /*   forwardFFTSize * forwardFFTDecimationFactor / inverseFFTSize      */ 
  /* Since the result is complex data, the inverseFFTSize would normally */ 
  /* be 1/2 of the TOTAL forward FFT Size.                               */ 
  /* NOTE: To preserve data alignment from ping to ping, up to the       */ 
  /*   TOTAL SUBSAMPLING FACTOR - 1 of 0s will be inserted when a new    */ 
  /*   ping is detected.  The new ping data will then always begin at    */ 
  /*   a sample offset that is divisible by this number.                 */ 
  unsigned long int inverseFFTSize;

  /* Total number of valid samples which result from the inverse FFT     */ 
  /* processing.  For maximum computation efficiency, this should be     */ 
  /* slightly larger than the pulse length expressed in the decimated    */ 
  /* inverse FFT sample rate.  The raw input data will be shifted by     */ 
  /* (this many samples) * TOTAL SUBSAMPLING FACTOR                      */ 
  unsigned long int samples;

  /* The first FFT Coeficient to save.  This will be shifted down to 0   */ 
  /* frequency, and will be followed with coefs. for rest of match filter*/ 
  unsigned long int firstFFTCoef;

  /* Match filter size in FFT Samples.  The first sample in the match    */ 
  /* filter array is for the firstFFTCoef in the forward FFT.            */ 
  unsigned long int size;

  /* Frequency band of the matched filter : Low end.                     */ 
  float freq0;

  /* Frequency band of the matched filter : High end.                    */ 
  float freqn;

  /* Match filter delay in adc samples                                   */ 
  long int mfDelay;

  /* Reserved for future use - should be set to all 0                    */ 
  long int reserved[5];

  /* Match filter data.  This consists of 32-bit data words.  When the   */ 
  /* inverse FFT is taken values after the matchFilterSize are set to 0. */ 
  /* The match filter is stored unconjugated so that the output of FFT   */ 
  /* is IFFT( FFTData * Conj(MatchFilter) )                              */ 
  /* float data[];                                                       */ 

} SonarReceiveType;

/* --------------------------------------------------------------------- */ 
/* Pulse data information.                                               */ 
/* --------------------------------------------------------------------- */ 

typedef struct
{
  /* null terminated ASCII string.                                       */ 
  /* Contains engineering notes - eg how pulse was made.                 */ 
  char description[PULSEFILE_STRING_SIZE];

  /* Logical channel number of data.                                     */ 
  unsigned short int channel;

  /* Pulse transmit phase (1..7).                                        */ 
  unsigned short int transmitPhase;

  /* Sample rate of the outgoing pulse in Hz.                            */ 
  float sampleRate;

  /* Offset in samples from start of pulse.  This many 0s are inserted   */ 
  /* in front of the pulse.                                              */ 
  long int pulseOffset;

  /* Scale factor applied to all pulse data.  This provides an easy way  */ 
  /* to attenuate the pulse.  Must be between 0 and 1.                   */ 
  float pulseGain;

  /* Type of pulse.  Use 1 for standard pulse, 2 for variable gain       */ 
  /* profile, 3 for DAC generated trigger output.  Note that only        */ 
  /* standard pulses are scaled by the topside commanded pulse gain.     */ 
  long int pulseType;

  /* Pulse size in samples.  Can be 0 for an autogen pulse.              */ 
  long int size;

  /* Frequency band of the pulse : Low end.                              */ 
  float freq0;

  /* Frequency band of the pulse : High end.                             */ 
  float freqn;

  /* Reserved for future use - should be set to all 0                    */ 
  long int reserved[6];

  /* The pulse data.                                                     */ 
  /* short int data[];                                                   */ 

} SonarTransmitType;


/* --------------------------------------------------------------------- */ 
/* Impulse response data used to generate either a pulse or a match filt.*/ 
/* --------------------------------------------------------------------- */ 

typedef struct
{
  /* null terminated ASCII string.                                       */ 
  /* Contains engineering notes - eg how data was made.                  */ 
  char description[PULSEFILE_STRING_SIZE];

  /* Logical channel number of data.                                     */ 
  unsigned long int channel;

  /* Sample rate of the impulse response data.                           */ 
  float sampleRate;

  /* Impulse response size in samples.                                   */ 
  unsigned long int size;

  /* Reserved for future use - should be set to all 0                    */ 
  long int reserved[8];

  /* The impulse response data.                                          */ 
  /* short int data[];                                                   */ 
} ImpulseResponseType;


/* --------------------------------------------------------------------- */ 
/* Overall file header for SonarIO Pulses and Matched Filters.           */ 
/* --------------------------------------------------------------------- */ 

typedef struct
{
  /* Magic header number to identify this as a pulse file.              */ 
  /* Always set to PULSE_FILE_MAGIC_VALUE                               */ 
  unsigned long int magicNumber;

  /* null terminated ASCII string.                                       */ 
  /* Contains engineering notes - eg how pulse was made.                 */ 
  char description[PULSEFILE_STRING_SIZE];

  /* Subsystem this file applies to.                                     */ 
  /* Subsystems are defined in Subsystem.h.                              */ 
  /* (Eg Subbottom or Sidescan IO)                                       */ 
  long int subsystem;

  /* ------------------------------------------------------------------- */ 
  /* The following parameters are returned as the pulse description.     */ 
  /* ------------------------------------------------------------------- */ 

  /* Name to used for selecting this pulse.                              */ 
  char pulseName[PULSEFILE_STRING_SIZE];

  /* Pulse description - null terminated ASCII string                    */ 
  char pulseDescription[PULSEFILE_STRING_SIZE];

  /* Minimum pulse frequency in Hz.                                      */ 
  unsigned long int fMin;

  /* Maximum pulse frequency in Hz.                                      */ 
  unsigned long int fMax;

  /* Pulse duration in us                                                */ 
  unsigned long int time;

  /* Unique identifier for this pulse.                                   */ 
  unsigned short int pulseID;    

  /* Hardware configuration options                                      */ 
  /* For SIB Card:                                                       */ 
  /*   SS ADC Card                                                       */ 
  /*   Bit 0: Diag Mode.                                                 */ 
  /*   Bit 1: Test Signal Gen.                                           */ 
  /*     NOTE: If Bit 0 and Bit 1 are set then Diag=0,Test=0, Relay=1    */ 
  /*           where relay sets the relay control bit                    */ 
  /*   Bit 2: Band pass mode toggle.                                     */ 
  /*   SB ADC Card                                                       */ 
  /*   Bit 0: Diag Mode.                                                 */ 
  /*   Bit 1: Double speed clock (not recommended)                       */ 
  /*   Bit 2: HPF (high pass filter mode)                                */ 
  unsigned short int cfgOptions;    

  /* Type of sonar this pulse was designed for.                          */ 
  unsigned long int sonarType;

  /* Type of pulse.                                                      */ 
  unsigned long int pulseType;


  /* ------------------------------------------------------------------- */ 
  /* Information about data to follow.                              .    */ 
  /* ------------------------------------------------------------------- */ 

  /* Total pulses in this file (SonarTransmitType structs to attached)   */ 
  unsigned long int transmitCount;

  /* Total input / match filter channels (SonarReceiveType  attached)    */ 
  unsigned long int receiveCount;

  /* Total impulse response data sets (ImpulseResponseType to follow)    */ 
  unsigned long int impulseCount;

  /* Maximum ping rate in Hertz                                          */ 
  float maxPingRate;

  /* Reserved extension words for future use.  Should be set to all 0    */ 
  long int reserved[7];

  /* Byte offsets from top of file for SonarTransmitType values,         */ 
  /* SonarReceiveType, ImpulseResponseType values.                       */ 
  /* (eg [0] = pulse 0, [1] = pulse 1, [2] = input 0 ...                 */ 
  /* long int offsets[];                                                 */ 

} PulseFileType;


#endif  /*__PULSEFILE_H__ */ 

/* --------------------------------------------------------------------- */ 
/*                           end PulseFile.h                             */ 
/* --------------------------------------------------------------------- */ 
