/* **********************************************************************
 * *                                                                    *
 * *               ChatMode Thread Private Definitions                  *
 * *                                                                    *
 * **********************************************************************
 * File: rda/rvp8main/core/chat_def.h
 *
 *                   COPYRIGHT (c) 2001, 2004, 2005 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 CHAT_DEF_ALLOCATE
  #define XM
#else
  #define XM extern
#endif

/* TTY and input processing variables
 */
XM struct ttydev setupTTY_c ;	/* Setup TTY */

XM UINT1 lreadline_from_user_c ; /* Read user's input (else simulate CR's) */

XM struct {			/* Structure for line oriented TTY input. */
#define TTYBUFLEN 80
  char buf[TTYBUFLEN], *ptr ;	/*   Input buffer and pointer to next read */
  SINT4 iRdFlag ;		/*   Read results flag */
#define RDFLG_NONE   0		/*     Nothing was typed (must be zero) */
#define RDFLG_OKAY   1		/*     New value was okay */
#define RDFLG_INVAL  2		/*     New value was out of bounds */
} ttybuf_c ;

/* The following shared variables are used by the query macros to
 * implement moving up within the list of setup questions.
 */
#define MAX_QUERIES 50		/* Max # of questions in a row */

XM SINT4 jmpidx_c ;		/* Must be set to zero initially */
XM jmp_buf jmpbuf_c[MAX_QUERIES] ;
XM jmp_buf quitjmp_c ;

/* Definitions shared by plotting routines.
 */
#define PLOTPERIOD 200		  /* Time (milliseconds) between updates */

struct stroke {			/* A single stroke of a plot */
  UINT4 lnew_data ;		/* Data values have changed */
  UINT2 idata[PLOTLEN] ;	/* Data to plot (12-bits) */
} ;
struct plotdef {
  SINT4 intensities ;		   /* Current 2-bit intensity levels */
  UINT4 lnew_intensities ;	   /* Intensities have changed */
  struct stroke strokes[MAXPLOTS] ;/* Stroke info */  
} ;
XM struct plotdef plotdef_c ;	/* Shared among these routines */

/* ------------------- chat_main.c -------------------
 */
FLT8 fGetValue    ( FLT8 fval_a, FLT8 flow_a, FLT8 fhigh_a ) ;
FLT8 fGetValueUQ  ( FLT8 fval_a, FLT8 flow_a, FLT8 fhigh_a ) ;
FLT8 fGetValueRd  ( FLT8 fval_a, FLT8 flow_a, FLT8 fhigh_a ) ; 
FLT8 fGetValueRdUQ( FLT8 fval_a, FLT8 flow_a, FLT8 fhigh_a ) ;

UINT1 iGetYn    ( UINT1 lVal_a ) ;
UINT1 iGetYnUQ  ( UINT1 lVal_a ) ;
UINT1 iGetYnRd  ( UINT1 lVal_a ) ;
UINT1 iGetYnRdUQ( UINT1 lVal_a ) ;

SINT4 iGetStr    ( volatile char *pStr_a, SINT4 iMaxLen_a ) ;
SINT4 iGetStrUQ  ( volatile char *pStr_a, SINT4 iMaxLen_a ) ;
SINT4 iGetStrRd  ( volatile char *pStr_a, SINT4 iMaxLen_a ) ;
SINT4 iGetStrRdUQ( volatile char *pStr_a, SINT4 iMaxLen_a ) ;

#define       GETVALUE( ITEM, MINVAL, MAXVAL ) \
  ( (ITEM = fGetValueRdUQ( ITEM, MINVAL, MAXVAL )), ttybuf_c.iRdFlag )
#define      GETVALUE_( ITEM, MINVAL, MAXVAL ) \
  ( (ITEM = fGetValueUQ  ( ITEM, MINVAL, MAXVAL )), ttybuf_c.iRdFlag )
#define NOUQ_GETVALUE_( ITEM, MINVAL, MAXVAL ) \
  ( (ITEM = fGetValue    ( ITEM, MINVAL, MAXVAL )), ttybuf_c.iRdFlag )

#define  NV_GETVALUE( ITEM )  GETVALUE( GM->nv.ITEM, GM->nvMIN.ITEM, GM->nvMAX.ITEM )
#define NV_GETVALUE_( ITEM ) GETVALUE_( GM->nv.ITEM, GM->nvMIN.ITEM, GM->nvMAX.ITEM )

#define       GETYN( ITEM ) ( (ITEM = iGetYnRdUQ( ITEM )), ttybuf_c.iRdFlag )
#define      GETYN_( ITEM ) ( (ITEM = iGetYnUQ  ( ITEM )), ttybuf_c.iRdFlag )
#define NOUQ_GETYN_( ITEM ) ( (ITEM = iGetYn    ( ITEM )), ttybuf_c.iRdFlag )

#define       GETSTR( ITEM ) ( iGetStrRdUQ( ITEM, sizeof(ITEM) ) )
#define      GETSTR_( ITEM ) ( iGetStrUQ  ( ITEM, sizeof(ITEM) ) )
#define NOUQ_GETSTR_( ITEM ) ( iGetStr    ( ITEM, sizeof(ITEM) ) )

void handle_u_and_q( void ) ;
void askagain( void ) ;
void titletext( const char *title_a, const char *cmd_a ) ;
char *yntext( UINT1 val_a ) ;
void crlf( void ) ;
void padline_and_cr( SINT4 iCol_a ) ;

char *readline( void ) ;
char chatRch( void ) ;
UINT1 lChatRchAvail( SINT4 iTimeoutMS_a ) ;

char getnextch( void ) ;
char getnbch( void ) ;
char peeknbch( void ) ;

/* ------------------- chat_setup.c -------------------
 */
void ttmonitor( void ) ;

/* -------------------- chat_pa.c ---------------------
 */
void plot_ambiguity( void ) ;

/* -------------------- chat_pb.c ---------------------
 */
void plot_burst_timing( void ) ;

/* -------------------- chat_pr.c ---------------------
 */
void plot_receive_data( void ) ;

/* -------------------- chat_ps.c ---------------------
 */
void plot_burst_spectra( void ) ;

/* ------------------- chat_plots.c -------------------
 */
void plot_testpattern( void ) ;

void plot_initdefs( void ) ;
void begin_plot( SINT4 which_a ) ;
void plot_point( SINT4 ival_a ) ;
void plot_array( UINT2 *imem_a, SINT4 ilen_a ) ;
void plotmode_on( SINT4 intensities_a ) ;
void plotmode_off( void ) ;
void update_plot_output( void ) ;

UINT1 pauseplot( void ) ;
SINT4 ibest125( FLT4 fval_a, SINT4 imin_a, SINT4 imax_a ) ;
UINT1 lbump_implength( UINT1 linc_a, volatile struct rvp8Pwdef *pwdef_a ) ;
void bump_bfe
( volatile struct rvp8Pwdef *pwdef_a, SINT4 istart_a, SINT4 ilength_a ) ;

void plotfdata
( const FLT4 fdata_a[], SINT4 idatalen_a, UINT2 iplot_a[], SINT4 iplotlen_a,
  FLT4 fslope_a, FLT4 foffset_a, SINT4 ipmin_a, SINT4 ipmax_a, SINT4 iPltfd_a ) ;
#define PLTFD_AVG   0		/* Plot average values */
#define PLTFD_ONE   1		/* Plot single central value */
#define PLTFD_MIN   2		/* Plot minimum values */
#define PLTFD_MAX   3		/* Plot maximum values */

FLT4 fdbmlevel
( FLT4 flevel_a, SINT4 lfilt_a, const struct firinfo *firinfo_a ) ;

void log_spectrum_plot
( FLT4 fspec_a[], FLT4 fplot_a[], UINT2 iplot_a[],
  SINT4 iplotnum_a, FLT4 fscale_a, SINT4 idivs_a ) ;

void plot_spectra_ticks( UINT2 iplot_a[], UINT2 iticks_a[], SINT4 nlines_a ) ;

void draw_tick_indicators
( UINT2 iplot_a[], FLT4 fmajor_a, FLT4 fminor_a ) ;

void burst_spectrum
( FLT4 fsamps_a[], SINT4 ilen_a, FLT4 fspecsum_a[] ) ;

void pupdate_navg( volatile SINT4 *ival_a, UINT1 lup_a ) ;
void fprint_drx_selection( FILE *stream_a ) ;

#ifdef SIGMET_PCICARDS_LIB_H
Rvp8Rx * RxToPlot( void ) ;
#endif /* #ifdef SIGMET_PCICARDS_LIB_H */
