]> err.no Git - mapper/blob - src/gps.h
Allow a bit faster movement for the random gps simulator.
[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;              /* Can scan for device */
59     gboolean address;   /* Needs address */
60         gboolean port;          /* Needs port */
61         guint port_def;         /* Default port */
62         const gchar *address_def; /* Default mac/ip/device */
63 };
64
65 /** This enumerated type defines the possible connection states. */
66 typedef enum {
67         RCVR_OFF,
68         RCVR_DOWN,
69         RCVR_UP,
70         RCVR_FIXED
71 } GpsConnState;
72
73 /**
74  * GPS IO struct
75  *
76  */
77 typedef struct _GpsIO GpsIO;
78 struct _GpsIO {
79         gint fd;
80         gchar *address; /* BT MAC, File path or IP */
81         guint port;
82         GpsIOSourceType type;
83         GpsConnState conn;
84         GIOChannel *channel;
85         DBusConnection *dbus_conn;
86         DBusGProxy *rfcomm_req_proxy;
87 #ifdef WITH_BLUEZ
88         struct sockaddr_rc rcvr_addr_rc;
89 #endif
90         struct sockaddr_in rcvr_addr_in;
91         /* Channel callback IDs*/
92         guint connect_sid;
93         guint error_sid;
94         guint input_sid;
95         guint clater_sid;
96         guint errors; /* G_IO_STATUS_ERRROR counter */
97         guint again; /* G_IO_STATUS_AGAIN counter */
98         /* Input buffer */
99         gchar buffer[GPS_READ_BUF_SIZE];
100         gchar *curr;
101         gchar *last;
102         /* Latest NMEA line, ready for parsing */
103         guint nmea_cnt;
104         gchar *nmea;
105 };
106
107 /**
108  * Gps 
109  */
110 typedef struct _Gps Gps;
111 struct _Gps {
112         gchar *name;    /* Name of the connection */
113         GpsIO io;
114         GpsData data;
115         /* Event callbacks */
116
117         /* On errors */
118         gboolean(* connection_error) (Gps *gps, const gchar *error_str);
119
120         /* Connection retry */
121         gboolean(* connection_retry) (Gps *gps, const gchar *error_str);
122
123         /* Connection progress */
124         gboolean(* connection_progress)(Gps *gps, gdouble fix);
125
126         /* New location */
127         gboolean(* update_location)(Gps *gps);
128         gboolean(* update_satellite)(Gps *gps);
129         gboolean(* update_info)(Gps *gps);
130 };
131
132 Gps *_gps;
133 gint _gmtoffset;
134
135 const GpsTypes *gps_get_supported_types(void);
136
137 Gps *gps_new(GpsIOSourceType type);
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