/****************************************************************************/
/* Copyright 2003 MBARI							    */
/****************************************************************************/
/* Summary  : Routines to test config file parsing on a PC		    */
/* Filename : configTest.c						    */
/* Author   : Robert Herlien (rah)					    */
/* Project  : OASIS Mooring Replacement (OASIS3)			    */
/* Revision : 1.0							    */
/* Created  : 08/20/2003						    */
/*									    */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*									    */
/****************************************************************************/
/* Modification History:						    */
/* 20aug2003 rah - created						    */
/****************************************************************************/

#include <mbariTypes.h>		/* MBARI type definitions		*/
#include <mbariConst.h>		/* MBARI constants			*/
#include <oasis.h>		/* OASIS controller definitions		*/
#include <drvr.h>		/* OASIS driver functions		*/
#include <log.h>		/* Log record definitions	        */
#include <config.h>		/* OASIS Config file parser definitions	*/
#include <parm.h>		/* Parameter table definitions	        */
#include <utils.h>		/* OASIS utility functions		*/

#include <stdio.h>		/* Standard I/O library			*/
#include <string.h>		/* Standard string library		*/


/************************************************************************/
/* Function    : main							*/
/* Purpose     : Main function for standalone test version		*/
/* Inputs      : argc, argv						*/
/* Outputs     : int, but ignored					*/
/* Comments    : Create an oasis.cfg file in the working directory, and	*/
/*		 run this program to see how it parses the file		*/
/************************************************************************/
int main()
{
  parseConfigFile();
  return(0);

} /* main() */


/************************************************************************/
/* Function    : drvr_create						*/
/* Purpose     : Create a driver header					*/
/* Inputs      : Ptr to driver descriptor				*/
/* Outputs     : Driver pointer						*/
/* Comments    : Adds it to the system driver list			*/
/************************************************************************/
	Driver *
drvr_create( const DrvDesc *ddp )
{
  printf("Driver create: name = \"%s\"\n", ddp->dd_name);
  printf("  Interval = %lu  Serial Port = %ld  Baud = %lu  Serial Setup = %#lx\n",
	 ddp->dd_parms[INTERVAL], ddp->dd_parms[SER_PORT], ddp->dd_parms[SER_BAUD], 
	 ddp->dd_parms[SER_SETUP]); 
  printf("  PwrBits = %#lx  SampleType = %ld  TOD mask = %#lx  Timeout = %lu\n",
	 ddp->dd_parms[PWR_CTRL], ddp->dd_parms[SAMPLE_TYPE], ddp->dd_parms[TOD_MASK],
	 ddp->dd_parms[TIMEOUT]);
  printf("  Parm0 = %lu  Parm1 = %lu  Parm2 = %lu\n",
	 ddp->dd_parms[PARM0], ddp->dd_parms[PARM1], ddp->dd_parms[PARM2]);

} /* drvr_create() */


/************************************************************************/
/* Function    : setParm						*/
/* Purpose     : Set user parameter					*/
/* Inputs      : Parm name, Parm value in ASCII				*/
/* Outputs     : OK if found & parm set, ERROR if parm not found	*/
/************************************************************************/
	Int16
setParm(char *name, char *value)
{
  printf("setParm: \"%s\"  \"%s\"\n", name, value);
  return(OK);

} /* setParm() */

/************************************************************************/
/* Function    : executeCmdLIne						*/
/* Purpose     : Execute the given command line (from user)		*/
/* Inputs      : Command Line ptr					*/
/* Outputs     : OK or ERROR						*/
/************************************************************************/
	Int16
executeCmdLine(char *cmdLine)
{
  printf("executeCmdLine: \"%s\"\n", cmdLine);
  return(OK);

} /* executeCmdLine() */


/************************/
/* From utils.c		*/
/************************/

/************************************************************************/
/* Function    : delimit						*/
/* Purpose     : Determine if character is a delimiter			*/
/* Inputs      : Character						*/
/* Outputs     : TRUE if character is ',', NULL, or space		*/
/************************************************************************/
	MBool
delimit( Reg char c )
{
  return( isspace(c) || (c == '\0') || (c == ',') || (c == '.') );

} /* delimit() */


/************************************************************************/
/* Function    : cmp_ulc						*/
/* Purpose     : Compare strings, case insensitive			*/
/* Inputs      : String ptr (mixed case, leading blanks),		*/
/*		 string ptr (mixed case, no blanks)			*/
/* Outputs     : NULL if strings don't match, else ptr to remainder of	*/
/*		 user input string					*/
/************************************************************************/
	char *
cmp_ulc( const char *s, const char *cs )
{
    deblank(s);
    while( *cs )
    {
	if ( toupper(*s) != toupper(*cs) )
	    return( NULL );
	s++;
	cs++;
    }

    return((char *)(delimit(*s) ? s : NULL));

} /* cmp_ulc() */


/************************************************************************/
/* Function    : sscanNum						*/
/* Purpose     : Similar to sscanf(s, "%d"), but understands 0xnnn and nnnH*/
/* Inputs      : String to scan, long int to put it in			*/
/* Outputs     : Number of items found (0 or 1)				*/
/************************************************************************/
	Int16
sscanNum(char *s, Parm_t *valp)
{
  if (strncasecmp(s, "0x", 2) == 0)
    return(sscanf(s+2, "%lx", valp));

  if (strpbrk(s, "Hh") != NULL)
    return(sscanf(s, "%lx", valp));

  return(sscanf(s, "%ld", valp));

} /* sscanNum() */


/****************************************/
/*  Dummy Instrument Drivers		*/
/****************************************/

Void	adcp_drv(Driver *dp) {}
MBool	adcp_wake(Driver *dp, MBool on){}
Void	analog_drv(Driver *dp){}
Void	argos_drv(Driver *dp){}
Void	emeter_drv(Driver *dp){}
Void	freewave_drv(Driver *dp){}
Void	garmin_drv(Driver *dp){}
MBool	garmin_wake( Driver *dp, MBool on){}
Void	gf_drv(Driver *dp){}
Void	hobi_drv(Driver *dp){}
Void	isus_drv(Driver *dp){}
MBool	isus_wake(Driver *dp, MBool on, char *buffer){}
Void    log_drv(Driver *dp) {}
Void	metsysDrv(Driver *dp){}
Void	microcat_drv(Driver *dp){}
Void	onoff_drv(Driver *dp){}
Void	nitrate_drv(Driver *dp){}
MBool	nitrate_wake(Driver *dp, MBool on, char *buffer){}
Void	pco2_drv(Driver *dp){}
MBool	pco2_wake(Driver *dp, MBool on){}
Void	runShutter(Driver *dp){}
Void	specprr_drv(Driver *dp){}
Void	tnc_drv(Driver *dp){}
Void	tstring_drv(Driver *dp){}
Void	usr_drv(Driver *dp){}
MBool	null_func(Void){}
Void	asimet_drv(Driver *dp){}
Void	ctd_drv(Driver *dp){}
Void	eco_drv(Driver *dp){}
Void	hobiGeneric_drv(Driver *dp){}




