/*-----------------------------------------------------------------------*
  PROGRAM: eagle picher battery wrapper

  DESCRIPTION: Main file for metrabyte driver binary

  AUTHOR: Hans Thomas 

  *-----------------------------------------------------------------------*/

#include "epiBatt.h"
#include "Syslog.h"
#include "SerialParameters.h"

int main( int argc, char **argv )
{
  epiBatt *batt= 0;
  SerialDevice *device = 0;
  Boolean exitFlag = True;

  char epiname[64];
  Boolean hasName = False;

  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-n"))
    {
      strncpy(epiname, argv[i+1], 63);
      hasName = True;
    }
  }

  if (!hasName)
  {
    Syslog::write("epiBattDriver must have name argument (-n name)");
    return 1;
  }


  SerialParameters serialParams(&argc, argv);
  while (argc) {
	if (argc-- && !strcmp(*argv++, "-noexit")) {
		exitFlag = False;
    	} 
  }

  if (exitFlag) printf("exitFlag is True\n"); else printf("exitFlag is False\n");

  try {
    SerialDevice *device = new SerialDevice(&serialParams); //set to 3.2 for shallower dives
    batt = new epiBatt(device, 3.20/*3.18*/, 3.05, exitFlag, epiname);  // hard-code to 3 for now
    batt->run();
  }
  catch (...) {
    Syslog::write("batt - Exception caught\n");
  }
  
  delete device;
  delete batt;

  return 0;

}
