]> err.no Git - mapper/blob - src/gps.h
Move ProgressUpdateInfo struct
[mapper] / src / gps.h
1 #include <config.h>
2
3 #ifndef _MAPPER_GPS_H
4 #define _MAPPER_GPS_H
5
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stddef.h>
11 #include <locale.h>
12 #include <math.h>
13 #include <errno.h>
14 #include <sys/wait.h>
15 #include <glib/gstdio.h>
16 #include <gtk/gtk.h>
17 #include <dbus/dbus.h>
18 #include <dbus/dbus-glib.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <netinet/ip.h> 
23
24 #ifdef WITH_BLUEZ
25 #include <bluetooth/bluetooth.h>
26 #include <bluetooth/hci.h>
27 #include <bluetooth/hci_lib.h>
28 #include <bluetooth/rfcomm.h>
29 #endif
30
31 #include "utils.h"
32 #include "mapper-types.h"
33 #include "gpsdata.h"
34
35 #define GPS_READ_BUF_SIZE       (1024)
36
37 /**
38  * Types of GPS data sources
39  */
40 typedef enum {
41         GPS_IO_TYPE_MIN=0,
42         GPS_IO_RFCOMM=1,        /* Bluetooth rfcomm socket */
43         GPS_IO_HILDON_DBUS,     /* Request rfcomm using hildon bluetooth D-Bus */
44         GPS_IO_BLUEZ_DBUS,      /* Request rfcomm using bluez bluetooth D-Bus*/
45         GPS_IO_FILE,            /* File or (serial) device node */
46         GPS_IO_TCP,                     /* TCP */
47         GPS_IO_GPSD,            /* TCP connection to gpsd (as TCP, but will send a request for NMEA mode */
48         GPS_IO_GYPSY,           /* Gypsy events */
49         GPS_IO_SIMULATION,      /* Random movement */
50         GPS_IO_TYPE_MAX
51 } GpsIOSourceType;
52
53 typedef struct _GpsTypes GpsTypes;
54 struct _GpsTypes {
55         GpsIOSourceType type;
56         const gchar *name;
57         gboolean scan;          /* Can scan for device */
58         gboolean address;       /* Needs address */
59         gboolean port;          /* Needs port */
60         guint port_def;         /* Default port */
61         const gchar *address_def; /* Default mac/ip/device */
62 };
63
64 /** This enumerated type defines the possible connection states. */
65 typedef enum {
66         RCVR_OFF,
67         RCVR_DOWN,
68         RCVR_UP,
69         RCVR_FIXED
70 } GpsConnState;
71
72 /**
73  * GPS IO struct
74  *
75  */
76 typedef struct _GpsIO GpsIO;
77 struct _GpsIO {
78         gint fd;
79         gchar *address; /* BT MAC, File path or IP */
80         guint port;
81         GpsIOSourceType type;
82         GpsConnState conn;
83         GIOChannel *channel;
84         DBusConnection *dbus_conn;
85         DBusGProxy *rfcomm_req_proxy;
86 #ifdef WITH_BLUEZ
87         struct sockaddr_rc rcvr_addr_rc;
88 #endif
89         struct sockaddr_in rcvr_addr_in;
90         /* Channel callback IDs*/
91         guint connect_sid;
92         guint error_sid;
93         guint input_sid;
94         guint clater_sid;
95         guint errors; /* G_IO_STATUS_ERRROR counter */
96         guint again; /* G_IO_STATUS_AGAIN counter */
97         /* Input buffer */
98         gchar buffer[GPS_READ_BUF_SIZE];
99         gchar *curr;
100         gchar *last;
101         /* Latest NMEA line, ready for parsing */
102         guint nmea_cnt;
103         gchar *nmea;
104 };
105
106 /**
107  * Gps 
108  */
109 typedef struct _Gps Gps;
110 struct _Gps {
111         gchar *name;    /* Name of the connection */
112         GpsIO io;
113         GpsData data;
114         /* Event callbacks */
115
116         /* On errors */
117         gboolean(* connection_error) (Gps *gps, const gchar *error_str);
118
119         /* Connection retry */
120         gboolean(* connection_retry) (Gps *gps, const gchar *error_str);
121
122         /* Connection progress */
123         gboolean(* connection_progress)(Gps *gps, gdouble fix);
124
125         /* New location */
126         gboolean(* update_location)(Gps *gps);
127         gboolean(* update_satellite)(Gps *gps);
128         gboolean(* update_info)(Gps *gps);
129 };
130
131 Gps *_gps;
132 gint _gmtoffset;
133
134 const GpsTypes *gps_get_supported_types(void);
135
136 Gps *gps_new(GpsIOSourceType type);
137 void gps_clear(Gps *gps);
138 void gps_set_address(Gps *gps, gchar *address, guint port);
139 void gps_set_type(Gps *gps, GpsIOSourceType type);
140 void gps_free(Gps *gps);
141 void gps_data_integerize(GpsData *gpsdata);
142 gboolean gps_connect(Gps *gps);
143 gboolean gps_connect_now(Gps *gps);
144 void gps_connect_later(Gps *gps);
145 void gps_disconnect(Gps *gps);
146
147 #endif