//  The science logger functions available to general user are the following:
//
//		sci_logger_power_on_init (): Should be called once when the system
//			is first powered on.  Inits data structures.  Do not call more
//			than once.
//
//		sci_logger_open(): turns on power; initializes all data structures;
//			does not begin data collection.  Must be called before all other
//			routines except power_on_init
//
//		sci_logger_close(): closes the logger down and releases all resources,
//			including memory; turns power off.
//
//		sci_logger_set_gain (): sets the gain on a particular science channel
//
//		sci_logger_set_rate (): sets the conversion rate; applies to all channels
//
//		sci_logger_set_pre_event (): sets the length of the pre-event recording
//
//		sci_logger_set_post_event (): sets the length of the post-event recording
//
//		sci_logger_set_STA_time: sets length of the short term average
//
//		sci_logger_set_LTA_time: sets length of the long term average
//
//		sci_logger_set_trigger_level (): sets the STA/LTA which causes a trigger
//
//		sci_logger_reset (): stops data collection and resets all buffers; does
//			not turn off power or release memory resources.
//
//		sci_logger_start_data (): starts data collection
//
//		sci_logger_stop_data (): stops data collection and resets all buffers
//
//		sci_logger_pause_data (): temporarly releases the QSPI interface without shutting
//			down the A/D or changing any of the data queues; if science_logger_resume()
//			is called quickly enough, no data will be lost.
//
//		sci_logger_resume_data (): takes QSPI interface back and resumes data collection
//			at the point it was paused.
//
//		sci_logger_collect: manages all incoming data streams; the user must call this
//			routine periodicly to process new data.  The length of time that the user
//			can go without calling this routine is determined by the length of the
//			data buffers allocated when the AD7716 was set up;  currently this is
//			approximately one minute.
//
//		sci_logger_preview_ASCII (): marks a particular channel for immediate return
//			of the data in ASCII so that the user can verify that the data looks good.
//			Returns only every 100th point or so because of bandwidth limitations
//
//		sci_logger_preview_binary (): marks a particular channel for immediate return
//			of the binary data so that the user can verify that the data looks good.
//			Returns every point.
//
//		sci_logger_disk_request (): returns non-zero if the science logger wants
//			the main program to turn on the disk and call the routines that write
//			data to the disks
//
//		sci_logger_write_disk (): writes any data which the science logger has queued
//			out to disk.  This is separate from the disk_request so that the main program
//			can dump data from other parts of the logger while the disk is spun up.
//
//  All interactions with the science logger should be through calls to these
//  functions
//

#ifndef SCIENCE_DEFINED
#define SCIENCE_DEFINED 0x7F02

/*
//  Header which is written to the start of every data file so we can
//  figure out what it all means later
//
struct science_disk_header  {
	short version;			//  version number of this header
	char location[64];		//  character string used to describe location
	char sensor_type[64];	//  character string describing the sensor type
	char comment[64];		//  any comment the user wants to add
	short lattitude_deg;	//  degrees of latitude
	short lattitude_min;	//  minutes
	short lattitude_sec;	//  seconds
	short longitude_deg;	//  degrees of longitude
	short longitude_min;	//  minutes
	short longitude_sec;	//  seconds
	short AtoD_type;		//  type of A/D used to digitize data
	short n_bits;			//  number of bits per data point
	float gain;				//  gain setting of input amplifier
	double volts_per_bit;	//  voltage of one least-significant bit; this is refered
							//  to the input of the A/D, and does not include the gain
							//  of the input amplifier
	float sample_rate;		//  number of samples per second
	time_tt start_time;		//  time at which the first data point was recorded
	char filler[278];		//  filler to round out the header to 512 bytes
};	
*/


//  definitions of the externally accessible routines;  additional routines
//  intended for internal use only are declared in the .c file
void sci_logger_power_on_init (void);
int sci_logger_open (void);
void sci_logger_close (void);
void sci_logger_reset (void);
void sci_logger_start_data (void);
void sci_logger_stop_data (void);
void sci_logger_pause_data (void);
void sci_logger_resume_data (void);
double sci_logger_set_conversion_rate (float rate);
short sci_logger_set_averaging (short n_average);
double sci_logger_get_conversion_rate (void);

int sci_logger_activate_chans (int record_chans);
void sci_logger_set_trigger_level (short chan, float level);
int sci_logger_set_gain (int channel, float gain);
int sci_logger_get_gain (int channel);
int sci_logger_set_pre_event (float t);
int sci_logger_set_post_event (float t);
int sci_logger_set_STA_time (float t);
int sci_logger_set_LTA_time (float t);
int sci_logger_collect (int max_to_collect);
void sci_logger_set_ASCII_preview (int channel);
void sci_logger_set_binary_preview (int channel);
int sci_logger_get_n_channels (void);

int sci_logger_disk_request (void);
void sci_logger_overflow_check (void);
int sci_logger_write_disk (void);
void sci_logger_make_dir_name (char* buff, int channel, int year, int month, int day);
void sci_logger_setup_partition (void);
int sci_logger_print_file (int fd);
int sci_logger_self_test (void);
int sci_logger_is_open (void);
void sci_logger_show_status (void);


//  number of science channels currently implemented.  This is the number
//  that are available from a single AD7716 A/D converter
#define		N_SCI_CHANNELS		4
#define		SCIENCE_FILE_LENGTH	524288L
//#define		SCIENCE_FILE_LENGTH	65536L
//	This buffer length is the number of longs allocated for the temp buffer
//  created by the AD7716 routines.  (16384/128.5Hz) ~= 127 seconds, assuming
//  3 channels
#define		AD7716_BUFFER_LENGTH	(3L*16384L)
#endif
