gps.c File Reference

#include <include.h>

Include dependency graph for gps.c:

Go to the source code of this file.

Defines

#define DEFAULTHOST   "localhost"
#define DEFAULTPORT   "2947"

Functions

int OpenGPSD (void)
 GetGPSPos (float lat, float lon)

Variables

int GPSDsock
float lat
float lon
float alt
float spd
float hed
float last_lat
float last_lon
float last_hed
struct sockaddr_in servaddr localaddr
int mode
const char gpsd_command [] = "PAVMH\n"
 return


Define Documentation

#define DEFAULTHOST   "localhost"

Definition at line 24 of file gps.c.

Referenced by OpenGPSD().

#define DEFAULTPORT   "2947"

Definition at line 25 of file gps.c.

Referenced by my_serial_open(), and OpenGPSD().


Function Documentation

int OpenGPSD ( void   ) 

Definition at line 34 of file gps.c.

References alt, DEFAULTHOST, DEFAULTPORT, GPSD_CANT_BIND_PORT, GPSD_CANT_CONNECT, GPSD_CANT_OPEN_SOCKET, GPSD_UNKNOWN_HOST, GPSDsock, hed, last_hed, last_lat, last_lon, lat, localaddr, lon, mode, and spd.

00035 {
00036   int save_mode;
00037 
00038   GPSDsock = -1;
00039   lat = lon = alt = spd = hed = 0;
00040   last_lat = last_lon = last_hed = 0;
00041   mode = -1;
00042 
00043   host = strdup(DEFAULTHOST);
00044   port = DEFAULTPORT;
00045 
00046   // Find the host
00047   h = gethostbyname(host);
00048   if (h == NULL) {
00049     return GPSD_UNKNOWN_HOST;
00050   }
00051   // Fill in the server
00052   servaddr.sin_family = h->h_addrtype;
00053   memcpy((char *) &servaddr.sin_addr.s_addr, h->h_addr_list[0],
00054          h->h_length);
00055   servaddr.sin_port = htons(port);
00056 
00057   // Create the socket
00058   if ((GPSDsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
00059     return GPSD_CANT_OPEN_SOCKET;
00060   }
00061   // Bind to any local port
00062   localaddr.sin_family = AF_INET;
00063   localaddr.sin_addr.s_addr = htonl(INADDR_ANY);
00064   localaddr.sin_port = htons(0);
00065 
00066   if (bind(sock, (struct sockaddr *) &localaddr, sizeof(localaddr)) < 0) {
00067     return GPSD_CANT_BIND_PORT;
00068   }
00069   // Connect
00070   if (connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
00071     return GPSD_CANT_CONNECT;
00072   }
00073   // Set nonblocking mode
00074   save_mode = fcntl(sock, F_GETFL, 0);
00075   fcntl(sock, F_SETFL, save_mode | O_NONBLOCK);
00076 
00077   }

GetGPSPos ( float  lat,
float  lon 
)

Definition at line 82 of file gps.c.

References gpsd_command, GPSD_WRITE_ERROR, GPSDsock, and NO_ERROR.

00083 {
00084   const gpsd_command = "P";
00085   int result;
00086 
00087   // Kick a command off into the system, too
00088   if (write(sock, gpsd_command, sizeof(gpsd_command)) < 0) {
00089     if (errno != EAGAIN) {
00090       close(GPSDsock);
00091       GPSDsock = -1;
00092       return GPSD_WRITE_ERROR;
00093     }
00094   }
00095   result = read(sock, buf, 1024);
00096   return NO_ERROR;
00097 }


Variable Documentation

int GPSDsock

Definition at line 26 of file gps.c.

Referenced by GetGPSPos(), and OpenGPSD().

float lat

Definition at line 27 of file gps.c.

Referenced by OpenGPSD().

float lon

Definition at line 27 of file gps.c.

Referenced by OpenGPSD().

float alt

Definition at line 27 of file gps.c.

Referenced by OpenGPSD().

float spd

Definition at line 27 of file gps.c.

Referenced by OpenGPSD().

float hed

Definition at line 27 of file gps.c.

Referenced by OpenGPSD().

float last_lat

Definition at line 28 of file gps.c.

Referenced by OpenGPSD().

float last_lon

Definition at line 28 of file gps.c.

Referenced by OpenGPSD().

float last_hed

Definition at line 28 of file gps.c.

Referenced by OpenGPSD().

struct sockaddr_in servaddr localaddr

Definition at line 29 of file gps.c.

Referenced by OpenGPSD().

int mode

Definition at line 30 of file gps.c.

Referenced by OpenGPSD().

const char gpsd_command[] = "PAVMH\n"

Definition at line 32 of file gps.c.

Referenced by GetGPSPos().

Definition at line 79 of file gps.c.


Generated on Fri Jul 25 17:10:59 2008 for WifiScanner by  doxygen 1.5.5