/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : gpsServer.cc                                                  */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
/*-----------------------------------------------------------------------*
  PROGRAM: gpsServer

  DESCRIPTION: Binary wrapper for psa916 Server

  AUTHOR: John Rieffel

  $Id: _gpsServer.cc,v 1.3 2003/01/28 22:21:54 dorado Exp $
  *-----------------------------------------------------------------------*/

#include "GpsServer.h"
#include "Syslog.h"
#include "System.h"
#include "SerialParameters.h"

void usage()
{
  printf("usage: gpsServer -r [garmin | ashtech] -dev port\n");
  printf("       'port' is serial port designation, i.e., /dev/ser1\n");
  exit(1);
}

int main( int argc, char **argv )
{
  // Set task priority
  // if (System::setTaskPriority(CriticalServerPriority) == -1)
  // return 1;

  char driverName[32];
  GpsServer *gpsServer = 0;

  strcpy(driverName, "NoName");
  for (int ia = 1; ia < (argc-1); ia++)
  {
    if (!strcmp(argv[ia], "-r"))
    {
      strncpy(driverName, argv[ia+1], sizeof(driverName));
      break;
    }
  }

  // Quit now if no driver was specified or
  // if the specified driver was not recognized
  //
  if (!strcmp(driverName, "NoName") || (strcmp(driverName, "ashtech") &&
       strcmp(driverName, "garmin")))
  {
    usage();
    exit(1);
  }

  // This assumes that the name of the executable for the gps
  // driver is of the form gps_vendorDriver
  //
  strcat(driverName, "Driver");

  try {
    SerialParameters params(&argc, argv);
    gpsServer = new GpsServer(driverName, &params);
    gpsServer->run();
  }
  catch( SharedObject::Error e ) {
    Syslog::write("gpsServer -- Caught Exception: %s\n", e.msg );
  }
  catch( ... ) {
    Syslog::write("gpsServer -- Caught exception!\n");
  }

  delete gpsServer;

  return 0;
}
