]> err.no Git - mapper/blob - src/gps.h
Parse directly but update informations in callbacks only if we got a sentence that...
[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 "path.h"
32 #include "utils.h"
33 #include "mapper-types.h"
34 #include "gpsdata.h"
35
36 #define GPS_READ_BUF_SIZE       (1024)
37
38 /**
39  * Types of GPS data sources
40  */
41 typedef enum {
42         GPS_IO_TYPE_MIN=0,
43         GPS_IO_RFCOMM=1,        /* Bluetooth rfcomm socket */
44         GPS_IO_HILDON_DBUS,     /* Request rfcomm using hildon bluetooth D-Bus */
45         GPS_IO_BLUEZ_DBUS,      /* Request rfcomm using bluez bluetooth D-Bus*/
46         GPS_IO_FILE,            /* File or (serial) device node */
47         GPS_IO_TCP,                     /* TCP */
48         GPS_IO_GPSD,            /* TCP connection to gpsd (as TCP, but will send a request for NMEA mode */
49         GPS_IO_GYPSY,           /* Gypsy events */
50         GPS_IO_SIMULATION,      /* Random movement */
51         GPS_IO_TYPE_MAX
52 } GpsIOSourceType;
53
54 typedef struct _GpsTypes GpsTypes;
55 struct _GpsTypes {
56     GpsIOSourceType type;
57     const gchar *name;
58     gboolean scan;
59     gboolean address;
60 };
61
62 /** This enumerated type defines the possible connection states. */
63 typedef enum {
64         RCVR_OFF,
65         RCVR_DOWN,
66         RCVR_UP,
67         RCVR_FIXED
68 } GpsConnState;
69
70 /**
71  * GPS IO struct
72  *
73  */
74 typedef struct _GpsIO GpsIO;
75 struct _GpsIO {
76         gint fd;
77         gchar *address; /* BT MAC, File path or IP */
78         guint port;
79         GpsIOSourceType type;
80         GpsConnState conn;
81         GIOChannel *channel;
82         DBusConnection *dbus_conn;
83         DBusGProxy *rfcomm_req_proxy;
84 #ifdef WITH_BLUEZ
85         struct sockaddr_rc rcvr_addr_rc;
86 #endif
87         struct sockaddr_in rcvr_addr_in;
88         /* Channel callback IDs*/
89         guint connect_sid;
90         guint error_sid;
91         guint input_sid;
92         guint clater_sid;
93         guint errors; /* G_IO_STATUS_ERRROR counter */
94         guint again; /* G_IO_STATUS_AGAIN counter */
95         /* Input buffer */
96         gchar buffer[GPS_READ_BUF_SIZE];
97         gchar *curr;
98         gchar *last;
99         /* Latest NMEA line, ready for parsing */
100         guint nmea_cnt;
101         gchar *nmea;
102 };
103
104 /**
105  * Gps 
106  */
107 typedef struct _Gps Gps;
108 struct _Gps {
109         gchar *name;    /* Name of the connection */
110         GpsIO io;
111         GpsData data;
112         /* Event callbacks */
113
114         /* On errors */
115         gboolean(* connection_error) (Gps *gps, const gchar *error_str);
116
117         /* Connection retry */
118         gboolean(* connection_retry) (Gps *gps, const gchar *error_str);
119
120         /* Connection progress */
121         gboolean(* connection_progress)(Gps *gps, gdouble fix);
122
123         /* New location */
124         gboolean(* update_location)(Gps *gps);
125         gboolean(* update_satellite)(Gps *gps);
126         gboolean(* update_info)(Gps *gps);
127 };
128
129 Gps *_gps;
130 gint _gmtoffset;
131
132 const GpsTypes *gps_get_supported_types(void);
133
134 Gps *gps_new(GpsIOSourceType type);
135 void gps_set_address(Gps *gps, gchar *address, guint port);
136 void gps_set_type(Gps *gps, GpsIOSourceType type);
137 void gps_free(Gps *gps);
138 void gps_data_integerize(GpsData *gpsdata);
139 gboolean gps_connect(Gps *gps);
140 gboolean gps_connect_now(Gps *gps);
141 void gps_connect_later(Gps *gps);
142 void gps_disconnect(Gps *gps);
143
144 #endif