/*

                                   _JNJ`                        
                               .JNMH`                           
                              JMMF`       `;.                   
                            .NMM)          `MN.                 
                            MMM)            (MML                
                           (MMM`             MMML               
                     M  I  D  N  I  G  H  T    C  o  D  E       
                           (NMMF             MHNH               
                            NMML            .MMM                
                             NMML          .NMH                 
                              4MMNL       .#F                   
                               `4HNNL_   `                      
                                   `"""`                        

                          Copyright (C) 2004-2007
       "Ian (Larry) Latter" <ian dot latter at midnightcode dot org>

    Midnight Code is a registered trademark of Ian Latter.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, and mirrored at the Midnight Code web
    site; as at version 2 of the License only.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
  
    You should have received a copy of the GNU General Public License
    (version 2) along with this program; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA, or see http://midnightcode.org/gplv2.txt

*/


/* midnightcode-gps.h :: Midnight Code Global Position System library	*/


#ifndef __MIDNIGHTCODE_GPS_H
#define __MIDNIGHTCODE_GPS_H 1


#define MIDNIGHTCODE_GPS_STRUCTURE "gps"
#define MIDNIGHTCODE_GPS_DAEMON_WATCHER "w=1\n"
#define MIDNIGHTCODE_GPS_DAEMON_NOFIX "GPSD,O=?"
#define MIDNIGHTCODE_GPS_DAEMON_FIXED "GPSD,O=RMC"
#define MIDNIGHTCODE_GPS_SOCKET_HANG_MAX 2
#define MIDNIGHTCODE_GPS_POLL_TIME_HANDLER 100000
#define MIDNIGHTCODE_GPS_PORT 2947
#define MIDNIGHTCODE_GPS_POLL_INTERVAL 1

enum midnightcode_gps_state_t
{
  MIDNIGHTCODE_GPS_STATE_INACTIVE = 0,
  MIDNIGHTCODE_GPS_STATE_ACTIVE = 1,
  MIDNIGHTCODE_GPS_STATE_2DFIX = 2,
  MIDNIGHTCODE_GPS_STATE_3DFIX = 4
};

struct midnightcode_gps_element_t
{
  struct in_addr ipv4_address;
  char ipv4_address_s[32];
  int port;
  struct midnightcode_socket_element_t * socket;
  int state;
  double time;
  double latitude;
  double longitude;
  double altitude;
  double course;
  double speed;
  double climb;
  midnightcode_list_entry(midnightcode_gps_element_t)
};

midnightcode_list_head(midnightcode_gps_head_t,
                       midnightcode_gps_element_t)

int midnightcode_gps_open(struct midnightcode_gps_element_t ** fix_p,
                     char * ipv4_address_s, int port);
int midnightcode_gps_close(struct midnightcode_gps_element_t * fix);
int midnightcode_gps_receive(
                     struct midnightcode_gps_element_t * fix,
                     struct midnightcode_socket_element_t * socket);
int midnightcode_gps_unfix(struct midnightcode_gps_head_t * fixes);
void * midnightcode_gps_handler(void *arg);
int midnightcode_gps_initialise(struct midnightcode_gps_head_t * fixes);
int midnightcode_gps_shutdown(struct midnightcode_gps_head_t * fixes);


#endif
