Example #1
0
int main(int argc, char *argv[])
{
    char *server = NULL, *port = DEFAULT_GPSD_PORT;
    GMainLoop *ml =  g_main_loop_new(NULL, FALSE);

    gpsdata = gps_open(server, port);

    if (!gpsdata) perror("error connecting to gpsd");

    gps_set_raw_hook(gpsdata, update_gps);

    gps_stream(gpsdata, WATCH_ENABLE, NULL);
  
    IvyInit ("GPSd2Ivy", "GPSd2Ivy READY", NULL, NULL, NULL, NULL);
    IvyStart("127.255.255.255");
  
    g_timeout_add(TIMEOUT_PERIOD, gps_periodic, NULL);
  
    g_main_loop_run(ml);

    return 0;
}
Example #2
0
static int
gpsd_open(struct gpsd_priv *priv)
{
	char *source = strdup(priv->url);
	char *colon = index(source + 7, ':');
	if (colon) {
		*colon = '\0';
		priv->gps = gps_open(source + 7, colon + 1);
	} else
		priv->gps = gps_open(source + 7, NULL);
	free(source);
	if (!priv->gps)
		return 0;
	priv->iochan = g_io_channel_unix_new(priv->gps->gps_fd);
	priv->watch = g_io_add_watch(priv->iochan, IOFLAGS, gpsd_io, priv);
	priv->timeout = g_timeout_source_new(1500);
	g_source_set_callback(priv->timeout, gpsd_timeout_cb, priv, NULL);
	priv->tag = g_source_attach(priv->timeout, NULL);
	gps_query(priv->gps, "w+x\n");
	gps_set_raw_hook(priv->gps, gpsd_callback);
	return 1;
}
Example #3
0
/*@ -globstate -branchstate @*/
void
handle_gps(XtPointer client_data, XtIntervalId *ignored)
{
	char *err_str = NULL;
	char error[128];
	static bool dialog_posted = false;

	/*@i@*/gpsdata = gps_open(server, port);
	if (!gpsdata) {
		switch (errno ){
		case NL_NOSERVICE:
			err_str = "can't get service entry";
			break;
		case NL_NOHOST:
			err_str = "can't get host entry";
			break;
		case NL_NOPROTO:
			err_str = "can't get protocol entry";
			break;
		case NL_NOSOCK:
			err_str = "can't create socket";
			break;
		case NL_NOSOCKOPT:
			err_str = "error SETSOCKOPT SO_REUSEADDR";
			break;
		case NL_NOCONNECT:
			err_str = "can't connect to host";
			break;
		default:
			err_str = "Unknown";
			break;
		}
		if (!gps_lost && !dialog_posted) {
			(void)snprintf(error, sizeof(error),
			    "No GPS data available.\n\n%s\n\n"
			    "Check the connection to gpsd and if "
			    "gpsd is running.", err_str);
			(void)err_dialog(toplevel, error);
			dialog_posted = true;
		}
		gps_timeout = XtAppAddTimeOut(app, 1000, handle_gps, app);
	} else {
		timeout = XtAppAddTimeOut(app, 2000, handle_time_out, app);
		timer = time(NULL);

		gps_set_raw_hook(gpsdata, update_panel);

		if (jitteropt)
		    (void)gps_query(gpsdata, "J=1");

		if (device)
		    (void)gps_query(gpsdata, "F=%s", device);

		(void)gps_query(gpsdata, "w+x");

		gps_input = XtAppAddInput(app, gpsdata->gps_fd,
		    (XtPointer)XtInputReadMask, handle_input, NULL);
		if (gps_lost || dialog_posted)
		    (void)err_dialog(toplevel, "GPS data is available.");
		dialog_posted = gps_lost = false;
	}
}
Example #4
0
int
main(int argc, char **argv){
	int ch;
	fd_set fds;
	int casoc = 0;

	progname = argv[0];
	while ((ch = getopt(argc, argv, "hVi:j:s:p:")) != -1){
	switch (ch) {
	case 'i':
		sl = (unsigned int)atoi(optarg);
		if (sl < 1)
			sl = 1;
		if (sl >= 3600)
			fprintf(stderr,
			    "WARNING: polling interval is an hour or more!\n");
		break;
	case 'j':
		casoc = (unsigned int)atoi(optarg);
		casoc = casoc ? 1 : 0;
		break;
	case 's':
		host = optarg;
		break;
	case 'p':
		port = optarg;
		break;
	case 'V':
		(void)fprintf(stderr, "SVN ID: $Id: cgpxlogger.c 4406 2007-07-27 16:18:18Z ckuethe $ \n");
		exit(0);
	default:
		usage();
		/* NOTREACHED */
	}
	}

	gpsdata = gps_open(host, port);
	if (!gpsdata) {
		char *err_str;
		switch (errno) {
		case NL_NOSERVICE:
			err_str = "can't get service entry";
			break;
		case NL_NOHOST:
			err_str = "can't get host entry";
			break;
		case NL_NOPROTO:
			err_str = "can't get protocol entry";
			break;
		case NL_NOSOCK:
			err_str = "can't create socket";
			break;
		case NL_NOSOCKOPT:
			err_str = "error SETSOCKOPT SO_REUSEADDR";
			break;
		case NL_NOCONNECT:
			err_str = "can't connect to host";
			break;
		default:
			err_str = "Unknown";
			break;
		}
		fprintf(stderr,
		    "cgpxlogger: no gpsd running or network error: %d, %s\n",
		    errno, err_str);
		exit(1);
	}

	signal(SIGINT, bye);
	signal(SIGTERM, bye);
	signal(SIGQUIT, bye);
	signal(SIGHUP, bye);

	header();

	if (casoc)
		gps_query(gpsdata, "j1\n");

	gps_set_raw_hook(gpsdata, process);

	for(;;){
		int data;
		struct timeval tv;

		FD_ZERO(&fds);
		FD_SET(gpsdata->gps_fd, &fds);

		gps_query(gpsdata, pollstr);

		tv.tv_usec = 250000;
		tv.tv_sec = 0;
		data = select(gpsdata->gps_fd + 1, &fds, NULL, NULL, &tv);

		if (data < 0) {
			fprintf(stderr,"%s\n", strerror(errno));
			footer();
			exit(2);
		}
		else if (data)
			gps_poll(gpsdata);

		sleep(sl);
	}
}