From 6278bec636d830e1032eb9a0344b4e6aa93eef13 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 13 Feb 2016 16:18:52 -0500 Subject: [PATCH] Deprecated gpd functionality using GPSD --- src/gps.sh | 9 -- src/lib/gpsd_client.h | 26 ---- src/lib/gpsd_config.h | 271 ---------------------------------------- src/modules/gps-debug.c | 125 ------------------ src/modules/pgps.c | 227 --------------------------------- 5 files changed, 658 deletions(-) delete mode 100644 src/gps.sh delete mode 100644 src/lib/gpsd_client.h delete mode 100644 src/lib/gpsd_config.h delete mode 100644 src/modules/gps-debug.c delete mode 100644 src/modules/pgps.c diff --git a/src/gps.sh b/src/gps.sh deleted file mode 100644 index c266ac1..0000000 --- a/src/gps.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -print_message() { - echo '\033[36m\033[1m'$1'\033[0m\033[39m' -} - -print_message 'Configuring GPSD...' -sudo killall gpsd -sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock diff --git a/src/lib/gpsd_client.h b/src/lib/gpsd_client.h deleted file mode 100644 index 9bc20a4..0000000 --- a/src/lib/gpsd_client.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _GPSD_GPSDCLIENT_H_ -#define _GPSD_GPSDCLIENT_H_ -struct fixsource_t -/* Describe a data source */ -{ - char *spec; /* Pointer to actual storage */ - char *server; - char *port; - /*@null@*/char *device; -}; - -enum unit {unspecified, imperial, nautical, metric}; -enum unit gpsd_units(void); -enum deg_str_type { deg_dd, deg_ddmm, deg_ddmmss }; - -extern /*@observer@*/ char *deg_to_str( enum deg_str_type type, double f); - -extern void gpsd_source_spec(/*@null@*/const char *fromstring, - /*@out@*/struct fixsource_t *source); - -char *maidenhead(double n,double e); - -/* This needs to match JSON_DATE_MAX in gpsd.h */ -#define CLIENT_DATE_MAX 24 - -#endif /* _GPSDCLIENT_H_ */ diff --git a/src/lib/gpsd_config.h b/src/lib/gpsd_config.h deleted file mode 100644 index a8c67ac..0000000 --- a/src/lib/gpsd_config.h +++ /dev/null @@ -1,271 +0,0 @@ -#define VERSION "3.3" - -#define GPSD_URL "http://catb.org/gpsd" - -#define HAVE_LIBUSB 1 - -#define HAVE_LIBRT 1 - -/* #undef HAVE_DBUS */ - -#define HAVE_BLUEZ 1 - -/* #undef HAVE_SYS_TIMEPPS_H */ - -#define HAVE_DAEMON 1 - -/* #undef HAVE_STRLCPY */ - -/* #undef HAVE_STRLCAT */ - -#define HAVE_CLOCK_GETTIME 1 - -/* AIVDM support */ -#define AIVDM_ENABLE 1 - -/* Ashtech support */ -#define ASHTECH_ENABLE 1 - -/* application binaries directory */ -#define BINDIR "/bin" - -/* BlueZ support for Bluetooth devices */ -#define BLUEZ_ENABLE 1 - -/* float ops are cheap, compute error estimates */ -#define CHEAPFLOATS_ENABLE 1 - -/* client debugging support */ -#define CLIENTDEBUG_ENABLE 1 - -/* control socket for hotplug notifications */ -#define CONTROL_SOCKET_ENABLE 1 - -/* allow gpsctl/gpsmon to change device settings */ -#define CONTROLSEND_ENABLE 1 - -/* enable DBUS export support */ -/* #undef DBUS_EXPORT_ENABLE */ - -/* include debug information in build */ -/* #undef DEBUG_ENABLE */ - -/* documents directory */ -#define DOCDIR "/share/doc" - -/* DeLorme EarthMate Zodiac support */ -#define EARTHMATE_ENABLE 1 - -/* EverMore binary support */ -#define EVERMORE_ENABLE 1 - -/* fixed serial port speed */ -/* #undef FIXED_PORT_SPEED */ - -/* fixed serial port stop bits */ -/* #undef FIXED_STOP_BITS */ - -/* force daemon to listen on all addressses */ -/* #undef FORCE_GLOBAL_ENABLE */ - -/* Jackson Labs Fury and Firefly support */ -#define FURY_ENABLE 1 - -/* San Jose Navigation FV-18 support */ -#define FV18_ENABLE 1 - -/* Garmin kernel driver support */ -#define GARMIN_ENABLE 1 - -/* Garmin Simple Text support */ -#define GARMINTXT_ENABLE 1 - -/* Geostar Protocol support */ -#define GEOSTAR_ENABLE 1 - -/* GPSClock support */ -#define GPSCLOCK_ENABLE 1 - -/* privilege revocation group */ -/* #undef GPSD_GROUP */ - -/* privilege revocation user */ -#define GPSD_USER "nobody" - -/* implicit linkage is supported in shared libs */ -#define IMPLICIT_LINK_ENABLE 1 - -/* header file directory */ -#define INCLUDEDIR "/include" - -/* build IPv6 support */ -#define IPV6_ENABLE 1 - -/* iTrax hardware support */ -#define ITRAX_ENABLE 1 - -/* build QT bindings */ -#define LIBQGPSMM_ENABLE 1 - -/* system libraries */ -#define LIBDIR "/lib" - -/* build C++ bindings */ -#define LIBGPSMM_ENABLE 1 - -/* maximum allowed clients */ -/* #undef LIMITED_MAX_CLIENTS */ - -/* maximum allowed devices */ -/* #undef LIMITED_MAX_DEVICES */ - -/* manual pages directory */ -#define MANDIR "/share/man" - -/* MTK-3301 support */ -#define MTK3301_ENABLE 1 - -/* Navcom support */ -#define NAVCOM_ENABLE 1 - -/* build with ncurses */ -#define NCURSES_ENABLE 1 - -/* build support for handling TCP/IP data sources */ -#define NETFEED_ENABLE 1 - -/* NMEA support */ -#define NMEA_ENABLE 1 - -/* NTP time hinting support */ -#define NTPSHM_ENABLE 1 - -/* NTRIP support */ -#define NTRIP_ENABLE 1 - -/* OceanServer support */ -#define OCEANSERVER_ENABLE 1 - -/* oldstyle (pre-JSON) protocol support */ -#define OLDSTYLE_ENABLE 1 - -/* Motorola OnCore chipset support */ -#define ONCORE_ENABLE 1 - -/* build support for passing through JSON */ -#define PASSTHROUGH_ENABLE 1 - -/* pkgconfig file directory */ -#define PKGCONFIG "/lib/pkgconfig" - -/* PPS time syncing support */ -#define PPS_ENABLE 1 - -/* pin to expect PPS pulses on */ -#define PPS_PIN "DCD" - -/* installation directory prefix */ -#define PREFIX "/usr/local" - -/* build with profiling enabled */ -/* #undef PROFILING_ENABLE */ - -/* build Python support and modules. */ -#define PYTHON_ENABLE 1 - -/* allow gpsd to change device settings */ -#define RECONFIGURE_ENABLE 1 - -/* rtcm104v2 support */ -#define RTCM104V2_ENABLE 1 - -/* rtcm104v3 support */ -#define RTCM104V3_ENABLE 1 - -/* system binaries directory */ -#define SBINDIR "/sbin" - -/* build shared libraries, not static */ -#define SHARED_ENABLE 1 - -/* export via shared memory */ -#define SHM_EXPORT_ENABLE 1 - -/* SiRF chipset support */ -#define SIRF_ENABLE 1 - -/* data export over sockets */ -#define SOCKET_EXPORT_ENABLE 1 - -/* squelch gpsd_report/gpsd_hexdump to save cpu */ -/* #undef SQUELCH_ENABLE */ - -/* build with stripping of binaries enabled */ -#define STRIP_ENABLE 1 - -/* Novatel SuperStarII chipset support */ -#define SUPERSTAR2_ENABLE 1 - -/* system configuration directory */ -#define SYSCONFDIR "/etc" - -/* cross-development system root */ -/* #undef SYSROOT */ - -/* systemd socket activation */ -/* #undef SYSTEMD_ENABLE */ - -/* cross-development target */ -/* #undef TARGET */ - -/* latency timing support */ -/* #undef TIMING_ENABLE */ - -/* True North Technologies support */ -#define TNT_ENABLE 1 - -/* DeLorme TripMate support */ -#define TRIPMATE_ENABLE 1 - -/* Trimble TSIP support */ -#define TSIP_ENABLE 1 - -/* UBX Protocol support */ -#define UBX_ENABLE 1 - -/* libusb support for USB devices */ -#define USB_ENABLE 1 - - -/* Will not handle pre-Intel Apples that can run big-endian */ -#if defined __BIG_ENDIAN__ -#define WORDS_BIGENDIAN 1 -#else -#undef WORDS_BIGENDIAN -#endif - -/* Some libcs do not have strlcat/strlcpy. Local copies are provided */ -#ifndef HAVE_STRLCAT -#ifdef __cplusplus - -extern "C" { - #endif - size_t strlcat(/*@out@*/char *dst, /*@in@*/const char *src, size_t size); - #ifdef __cplusplus -} - -#endif -#endif -#ifndef HAVE_STRLCPY -#ifdef __cplusplus - -extern "C" { - #endif - size_t strlcpy(/*@out@*/char *dst, /*@in@*/const char *src, size_t size); - #ifdef __cplusplus -} - -#endif -#endif - -#define GPSD_CONFIG_H diff --git a/src/modules/gps-debug.c b/src/modules/gps-debug.c deleted file mode 100644 index 70a669f..0000000 --- a/src/modules/gps-debug.c +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include - -#include - -// GPSD Specific Libraries -#include -#include "../lib/gpsd_config.h" -#include "../lib/gpsdclient.h" - -static time_t status_timer; -static struct fixsource_t source; -static struct gps_data_t gpsdata; - -int main(int argc, char * * argv) { - printf("\033c"); - sleep(2); - - // Close GPS in case of prior inproper shutdown - gps_close(&gpsdata); - - // Flags for GPSD - unsigned int flags = WATCH_ENABLE; - char tbuf[CLIENT_DATE_MAX + 1]; - - int count = 0, track = 0, status = 0, heading = 0; - double latitude = 0, longitude = 0, unix_time = 0; - double roll = 0, pitch = 0, yaw = 0, speed = 0; - - if (optind < argc) { - gpsd_source_spec(argv[optind], & source); - - } else { - gpsd_source_spec(NULL, & source); - } - - // Open the GPSD stream - if (gps_open("127.0.0.1", "2947", & gpsdata) != 0) { - printf("No GPSD running or network error!\n"); - return 1; - } else { - printf("GPS port successfully opened! \n\n"); - } - - sleep(2); - - status_timer = time(NULL); - - if (source.device != NULL) { - flags |= WATCH_DEVICE; - } - - // Stream GPS Parameters - (void) gps_stream( & gpsdata, flags, source.device); - - // Infinite loop - for (;;) { - - // Changes frequency of sampling (10 Hz) - usleep(100000); - - // Clear terminal - printf("\033c"); - - if (gps_read(&gpsdata) == -1) { - // Print error if GPS isn't read - printf("GPS not read.\n"); - } else { - if (isnan(gpsdata.fix.latitude) != 0) { - // Don't use GPS data without a Fix - printf("No GPS Fix.\n"); - } - else { - // Get basic GPS parameters - latitude = gpsdata.fix.latitude; - longitude = gpsdata.fix.longitude; - unix_time = gpsdata.fix.time; - track = gpsdata.fix.track; - speed = gpsdata.fix.speed; - - // Specific to Hemisphere H-102 GPS - heading = gpsdata.attitude.heading; - roll = gpsdata.attitude.roll; - pitch = gpsdata.attitude.pitch; - yaw = gpsdata.attitude.yaw; - status = gpsdata.attitude.mag_st; - - if (status == 0) { - heading = track; - } - - if ((isnan(gpsdata.attitude.heading) != 0) || (heading > 360 || heading < 0)) { - heading = 0; - } - if ((isnan(gpsdata.fix.track) != 0) || (track > 360 || track < 0)) { - track = 0; - } - if ((isnan(gpsdata.attitude.roll) != 0) || (roll > 360 || roll < 0)) { - roll = 0; - } - if ((isnan(gpsdata.attitude.pitch) != 0) || (pitch > 360 || pitch < 0)) { - pitch = 0; - } - if ((isnan(gpsdata.attitude.yaw) != 0) || (yaw > 360 || yaw < 0)) { - yaw = 0; - } - } - } - - - printf("Time: %s\n", unix_to_iso8601((timestamp_t) time(NULL), tbuf, sizeof(tbuf))); - printf("GPS time (seconds): %f\n\n", unix_time); - printf("Boat Latitude: %lf\n", latitude); - printf("Boat Longitude: %lf\n\n", longitude); - printf("Heading (degrees, N): %d\n", heading); - printf("Track (degrees, N): %d\n", track); - printf("Speed (mph): %lf\n\n", speed); - printf("Compass Lock Status: %d\n\n", status); - printf("Roll (degrees): %lf\n", roll); - printf("Pitch (degrees): %lf\n", pitch); - printf("Yaw (degrees): %lf\n", yaw); - - } - -} diff --git a/src/modules/pgps.c b/src/modules/pgps.c deleted file mode 100644 index dcdb1f8..0000000 --- a/src/modules/pgps.c +++ /dev/null @@ -1,227 +0,0 @@ -#include -#include -#include -#include - -#include - -// Socket specific libraries -#include -#include -#include - -// GPSD specific libraries -#include -#include "../lib/gpsd_config.h" -#include "../lib/gpsd_client.h" - -static time_t status_timer; -static struct fixsource_t source; -static struct gps_data_t gpsdata; - -char json[256]; - -// Method prototypes -void build_json(void); -void write_element(char*, float, char*, bool); -void get_data(void); - -// GPS variables -int count = 0, track = 0, status = 0, heading = 0; -double latitude = 0, longitude = 0, unix_time = 0; -double roll = 0, pitch = 0, yaw = 0, speed = 0; - -// Define error handling methods -void error(const char *msg) { - perror(msg); - exit(1); -} - -int main(int argc, char *argv[]) { - printf("[GPS Socket]: Starting the GPS Socketn"); - - // Close GPS in case of prior inproper shutdown - gps_close(&gpsdata); - - // Flags for GPSD - unsigned int flags = WATCH_ENABLE; - char tbuf[CLIENT_DATE_MAX + 1]; - - if (optind < argc) { - gpsd_source_spec(argv[optind], & source); - - } else { - gpsd_source_spec(NULL, & source); - } - - // Open the GPSD stream - if (gps_open("127.0.0.1", "2947", & gpsdata) != 0) { - error("[GPS Socket]: No GPSD running or network error!\n"); - // Exit with error status - return 1; - } else { - printf("[GPS Socket]: GPS port successfully opened!\n"); - } - - status_timer = time(NULL); - - if (source.device != NULL) { - flags |= WATCH_DEVICE; - } - - // Stream GPS Parameters - (void) gps_stream(&gpsdata, flags, source.device); - - // Setup the socket connection - int sockfd, clientsockfd, port; - - socklen_t client; - - char buffer[256]; - struct sockaddr_in server_address, client_address; - - int n; - - if (argc < 2) { - fprintf(stderr, "[GPS Socket]: Error: No port specified\n"); - exit(1); - } - - // Create the socket connection - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - if (sockfd < 0) { - error("[GPS Socket]: Error: Cannot open socket\n"); - exit(1); - } - - bzero((char*) & server_address, sizeof(server_address)); - - port = atoi(argv[1]); - server_address.sin_family = AF_INET; - server_address.sin_addr.s_addr = INADDR_ANY; - server_address.sin_port = htons(port); - - // Bind to the socket - if (bind(sockfd, (struct sockaddr*) & server_address, - sizeof(server_address)) < 0) { - error("[GPS Socket]: Error: Failed to bind to socket\n"); - exit(1); - } - - listen(sockfd, 5); - - // Create and accept the client socket connection - client = sizeof(client_address); - clientsockfd = accept(sockfd, (struct sockaddr*) & client_address, &client); - - if (clientsockfd < 0) { - error("[GPS Socket]: Error: Problem accepting request\n"); - } - - // Enter and infinite connection with the client - for (;;) { - bzero(buffer, 256); - - // Socket read functions - n = read(clientsockfd, buffer, 255); - - if(n == 0) { - printf("[GPS Socket]: Client disconnected\n"); - break; - } - - if (n < 0) { - error("[GPS Socket]: Error: Cannot read from socket\n"); - } - - get_data(); - build_json(); - - // Socket write functions - printf("[GPS Socket]: Sent: %s\n", json); - n = write(clientsockfd, json, 256); - - - if (n < 0) { - error("[GPS Socket]: Error: Cannot write to socket\n"); - } - } - - // Close the client and socket connections - close(clientsockfd); - close(sockfd); - - return 0; -} - -void build_json(void) { - strcpy(json, "{"); - - write_element("time", unix_time, "%d", true); - write_element("latitude", latitude, "%0.7f", true); - write_element("longitude", longitude, "%0.7f", true); - write_element("heading", heading, "%f", true); - write_element("roll", roll, "%0.3f", true); - write_element("pitch", pitch, "%0.3f", true); - write_element("yaw", yaw, "%0.3f", false); - - strcpy(json + strlen(json), "}"); -} - -void write_element(char* property, float value, char* format, bool last) { - sprintf(json + strlen(json), "\"%s\":", property); - sprintf(json + strlen(json), format, value); - - if(last) { - strcpy(json + strlen(json), ", "); - } -} - - -void get_data(void) { - if (gps_read(&gpsdata) == -1) { - // Print error if GPS isn't read - printf("[GPS Socket]: GPS not read!\n"); - } else { - if (isnan(gpsdata.fix.latitude) != 0) { - // Don't use GPS data without a Fix - printf("[GPS Socket]: No GPS fix!\n"); - } - else { - // Get Basic GPS parameters - latitude = gpsdata.fix.latitude; - longitude = gpsdata.fix.longitude; - unix_time = gpsdata.fix.time; - track = gpsdata.fix.track; - speed = gpsdata.fix.speed; - - // Specific to Hemisphere H-102 GPS - heading = gpsdata.attitude.heading; - roll = gpsdata.attitude.roll; - pitch = gpsdata.attitude.pitch; - yaw = gpsdata.attitude.yaw; - status = gpsdata.attitude.mag_st; - - if (status == 0) { - heading = track; - } - - if ((isnan(gpsdata.attitude.heading) != 0) || (heading > 360 || heading < 0)) { - heading = 0; - } - if ((isnan(gpsdata.fix.track) != 0) || (track > 360 || track < 0)) { - track = 0; - } - if ((isnan(gpsdata.attitude.roll) != 0) || (roll > 360 || roll < 0)) { - roll = 0; - } - if ((isnan(gpsdata.attitude.pitch) != 0) || (pitch > 360 || pitch < 0)) { - pitch = 0; - } - if ((isnan(gpsdata.attitude.yaw) != 0) || (yaw > 360 || yaw < 0)) { - yaw = 0; - } - } - } -} \ No newline at end of file