/* **********************************************************************
 * *                                                                    *
 * *    UTILITY TO READ GPS DATA AND SET IRIS ANTENNA POSTIOPN SETUP    *
 * *                                                                    *
 * **********************************************************************
 * File: utils/custom/GpsToStup.C
 *
 *                       COPYRIGHT (c) 2006  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.
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <sys/stat.h>
#include <unistd.h>

#include "sigtypes.h"
#include "setup.h"

#include "config_lib.h"
#include "user_lib.h"

static MESSAGE GetPosFromGps
( double *pfLat_a,
  double *pfLon_a,
  double *pfAlt_a );


int main( int argc_a, char** argv_a)
{
  double  fLat, fLon, fAlt;  /* Lat/Lon in degrees, altitude in m */
  MESSAGE iStatus;
  char *sHost=NULL;          /* Possible remote host name */
  struct ant_manual_setup ASetup;

  setlocale(LC_ALL, "");

  /* Fill in current position */
  iStatus = GetPosFromGps( &fLat, &fLon, &fAlt );
  if (iStatus!=SS_NORMAL) { sig_signal(iStatus); exit(EXIT_FAILURE); }

  iStatus = ant_load_setup( sHost, &ASetup );
  if (iStatus!=SS_NORMAL) { sig_signal(iStatus); exit(EXIT_FAILURE); }

  ASetup.ilat     = iBin4FromFDeg( fLat );
  ASetup.ilon     = iBin4FromFDeg( fLon );
  ASetup.ignd_hgt = NINT( fAlt );

  iStatus = ant_save_setup( sHost, &ASetup );
  if (iStatus!=SS_NORMAL) { sig_signal(iStatus); exit(EXIT_FAILURE); }
  
  exit(EXIT_SUCCESS) ;
} 

/* ========================================
 * Function to get the position.
 */
static MESSAGE GetPosFromGps
( double *pfLat_a,
  double *pfLon_a,
  double *pfAlt_a )
{

  *pfLat_a = -30.0;
  *pfLon_a = -45.0;
  *pfAlt_a =  50.0;
  return SS_NORMAL;

}
