### Setup pkgin and Install Tools on NetBSD Source: https://gpsd.io/building.html Configures pkgin and installs necessary tools like Python 3.7, curses, scons, and git on NetBSD 8.1. ```bash # export PKG_PATH=\"http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/8.1/All\" # pkg_add -v pkgin # echo http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/8.1/All > \ /usr/pkg/etc/pkgin/repositories.conf # pkgin update # pkgin install python37 py37-curses # ln -s /usr/pkg/bin/python3.7 /usr/pkg/bin/python # ln -s /usr/pkg/bin/python3.7 /usr/pkg/bin/python3 # pkgin install py37-scons # pkgin install ncurses # pkgin install openssl mozilla-rootcerts # mozilla-rootcerts install # pkgin install git ``` -------------------------------- ### Start GPSD and chrony Services Source: https://gpsd.io/gpsd-time-service-howto.html This sequence demonstrates the preferred procedure for starting chronyd and gpsd when running as root, ensuring services are ready before the other. It includes killing existing processes, starting chronyd, waiting briefly, starting gpsd, and then checking the connection with cgps. ```shell $ su - # killall -9 gpsd chronyd # chronyd -f /etc/chrony/chrony.conf # sleep 2 # gpsd -n /dev/ttyXX # sleep 2 # cgps ``` -------------------------------- ### Build and Install gpsd on Gentoo Source: https://gpsd.io/building.html Clones the gpsd source, cleans the build tree, builds the project, checks the results, and installs it. Ensure prerequisites are installed before running. ```bash # make a place to keep the source mkdir -p /usr/local/src/GPSD cd /usr/local/src/GPSD # grab a shallow clone of gpsd from git. git clone --depth 1 https://gitlab.com/gpsd/gpsd.git cd gpsd # clean the tree, just in case scons -c # build the project scons # check the results scons check # and install if it looks good scons install ``` -------------------------------- ### Install Documentation Build Tool on Ubuntu Source: https://gpsd.io/building.html Installs asciidoctor, a tool required for building the project's documentation. ```bash apt install asciidoctor ``` -------------------------------- ### Install Build Tools on OpenBSD Source: https://gpsd.io/building.html Installs scons and git on OpenBSD 6.6 and 7.x, and creates a Python symlink. ```bash # syspatch -c # syspatch # pkg_add -u # pkg_add scons # pkg_add git # ln -s /usr/local/bin/python2 /usr/local/bin/python ``` -------------------------------- ### Install scons and git on FreeBSD Source: https://gpsd.io/building.html Installs scons for building and git for source control on FreeBSD systems. ```bash # pkg install scons # pkg install git ``` -------------------------------- ### Start ptp4l Daemon with Hardware Timestamping Source: https://gpsd.io/gpsd-time-service-howto.html Start the ptp4l daemon on the slave server with hardware timestamping enabled. ```bash # ethtool --set-eee eth0 eee off # ptp4l -H -f /usr/local/etc/ptp4l.conf & # sleep 3 ``` -------------------------------- ### VERSION Object Example Source: https://gpsd.io/gpsd_json.html Example of a version response from the gpsd daemon. This is sent to clients upon connection. ```json {"class":"VERSION","version":"2.40dev", "rev":"06f62e14eae9886cde907dae61c124c53eb1101f", "proto_major":3,"proto_minor":1 } ``` -------------------------------- ### Install Build Dependencies on Ubuntu Source: https://gpsd.io/building.html Installs essential development tools and libraries required for building gpsd on Ubuntu. ```bash apt install gcc scons python-gi python-gi-cairo g++ apt install libncurses5-dev libtinfo-dev pps-tools apt install gir1.2-gtk-3.0 ``` -------------------------------- ### RMB Example Source: https://gpsd.io/NMEA.html An example of a complete $GPRMB sentence, illustrating typical values for navigation data. ```text $GPRMB,A,0.66,L,003,004,4917.24,N,12309.57,W,001.3,052.5,000.5,V*0B ``` -------------------------------- ### ubxtool Examples Source: https://gpsd.io/index.html Examples for performing common `ubxtool` tasks. `ubxtool` is a utility for interacting with u-blox GPS receivers. ```bash # Example: Read configuration from a u-blox device # ubxtool -p /dev/ttyACM0 --cfg-get # Example: Set the baud rate of a u-blox device # ubxtool -p /dev/ttyACM0 --cfg-set CFG-PRT-BAUD 9600 # Example: Poll for current GPS time # ubxtool -p /dev/ttyACM0 --poll TIME-UTC # Example: Read NMEA sentences # ubxtool -p /dev/ttyACM0 --nmea ``` -------------------------------- ### Main Function Entry Point Source: https://gpsd.io/gpsd-client-example-code.html The main function for the gpsd client example. This example does not handle command-line options for clarity. ```c int main(int argc, char *argv[]) { ``` -------------------------------- ### TOFF Message Example Source: https://gpsd.io/gpsd_json.html An example of the TOFF JSON message, which reports the offset between the host's clock and GPS time at the start of a cycle. ```json {"class":"TOFF","device":"/dev/ttyUSB0", "real_sec":1330212592, "real_nsec":343182, "clock_sec":1330212592,"clock_nsec":343184, "precision":-2} ``` -------------------------------- ### Release Readiness State Announcement Example Source: https://gpsd.io/hacking.html An example of how to announce release state changes on the developer list, including the status of different device types and the expected release date. ```text Red light: total breakage in Garmin USB, partial breakage in Garmin serial Blue light: no known blockers, cosmetic problems in xgps Yellow light: Garmins tested successfully 20 Dec 2007 Green light: I'm expecting to call freeze in about 10 days Freeze: Scheduled release date 1 Feb 2008 ``` -------------------------------- ### Initialize plx_pci module for NMEA2000 on Network 1 Source: https://gpsd.io/gpsinit.html Similar to the previous example, but specifies network 1 for the NMEA2000 connection using the plx_pci module. ```bash gpsinit -n 1 plx_pci ``` -------------------------------- ### Systemd Service Configuration for gpsd Source: https://gpsd.io/troubleshooting.html Example content for a systemd service file to ensure gpsd runs continuously, as systemd typically starts it only on client request. ```ini [Unit] Description=GPS (Global Positioning System) Daemon Requires=gpsd.socket ``` -------------------------------- ### Sample NMEA Sentences Source: https://gpsd.io/gps-hacking.html These are example data lines (sentences) transmitted by GPS receivers using the NMEA 0183 protocol. Each sentence contains comma-separated fields, starting with a message type and ending with a checksum for data integrity. ```nmea $GPGGA,212734,4740.0569,N,12219.6612,W,1,08,74.00,73.9,M,638.000000,M,,*6D $GPRMC,212734,A,4740.0569,N,12219.6612,W,0.000000,0.000000,020403,18.936255,E*60 $GPGSA,A,3,17,06,23,15,16,18,10,30,,,,,152.00,74.00,133.00*3F $GPGGA,212735,4740.0569,N,12219.6612,W,1,08,74.00,74.1,M,638.000000,M,,*63 $GPRMC,212735,A,4740.0569,N,12219.6612,W,0.000000,0.000000,020403,18.936255,E*61 ``` -------------------------------- ### Compile gpsd Client Example Source: https://gpsd.io/gpsd-client-example-code.html Instructions for compiling a C example program using the gpsd client library. Requires libgps and gps.h. ```bash # example gpsd client # compile this way: # gcc example1.c -o example1 -lgps -lm #include .. for gps_*() ``` -------------------------------- ### Build and Install gpsd on macOS with Homebrew Source: https://gpsd.io/building.html After installing Homebrew, this sequence creates a directory for the source, clones gpsd, and then builds and installs it. ```bash # mkdir -p /usr/local/src/GPS # cd /usr/local/src/GPS # git clone https://gitlab.com/gpsd/gpsd.git # cd gpsd # scons && scons install ``` -------------------------------- ### Display help message Source: https://gpsd.io/gpsinit.html Shows a brief help text outlining the available options and usage of the gpsinit command. ```bash gpsinit -h ``` -------------------------------- ### Remove Existing gpsd Installation on Raspberry Pi OS Source: https://gpsd.io/building.html Ensure no previous versions of gpsd are installed before proceeding with a source installation. This involves stopping services and purging related packages. Some commands may report errors if gpsd is not already installed, which is normal. ```bash $ sudo su - # systemctl stop gpsd.socket # systemctl disable gpsd.socket # apt purge gpsd gpsd-clients gpsd-tools ``` -------------------------------- ### Display version information Source: https://gpsd.io/gpsinit.html Prints the version of the gpsinit utility. ```bash gpsinit -v ``` -------------------------------- ### Install Documentation Build Tools Source: https://gpsd.io/building.html Installs asciidoctor, a tool required for building the project's documentation, including the website and man pages. ```bash apt-get install asciidoctor ``` -------------------------------- ### Launch gpsd with Debugging and Device File Source: https://gpsd.io/troubleshooting.html Launch gpsd with debugging options and specify a device file. This example shows the output when the device file does not yet exist. ```bash # gpsd -N -D3 -F @RUNDIR/gpsd.sock /dev/ttyUSB0 gpsd: launching (Version 2.96~dev) gpsd: listening on port gpsd gpsd: running with effective group ID 0 gpsd: running with effective user ID 0 gpsd: stashing device /dev/ttyUSB0 at slot 0 ^Cgpsd: received terminating signal 2. gpsd: exiting. # ``` -------------------------------- ### Example MWD Sentence Source: https://gpsd.io/NMEA.html Example of a Wind Direction & Speed sentence. ```NMEA $WIMWD,302.4,T,289.6,M,10.5,N,5.4,M*6F ``` -------------------------------- ### Launch gpsd with Device File and Udev Interaction Source: https://gpsd.io/troubleshooting.html Launch gpsd with a device file. This example demonstrates the output when udev is active and the device file is subsequently created or accessed. ```bash # gpsd -N -D3 -F @RUNDIR/gpsd.sock /dev/ttyUSB0 gpsd: launching (Version 2.96~dev) gpsd: listening on port gpsd gpsd: running with effective group ID 0 gpsd: running with effective user ID 0 gpsd: stashing device /dev/ttyUSB0 at slot 0 gpsd: control socket connect on fd 6 gpsd: <= control(6): /dev/ttyUSB0 already active ^Cgpsd: received terminating signal 2. gpsd: exiting. # ``` -------------------------------- ### Example MTW Sentence Source: https://gpsd.io/NMEA.html Example of a Mean Temperature of Water sentence. ```NMEA $INMTW,17.9,C*1B ``` -------------------------------- ### Example MSS Sentence Source: https://gpsd.io/NMEA.html Example of a Beacon Receiver Status sentence. ```NMEA $GPMSS,0,0,0.000000,200*5A ``` -------------------------------- ### Logging Information (Supported) Source: https://gpsd.io/ubxtool-examples.html Example output indicating that the receiver supports logging, showing available filestore capacity and current log status. ```text UBX-LOG-INFO: version 1 reserved1 x0 x0 filestoreCapacity 487680 reserved2 x9600 x24900 currentMaxLogSize 134400 currentLogSize 61 entryCount 0 oldestYear 0 oldestMonth 0 oldestDay 0 oldestHour 0 oldestMin 0 oldestSec 0 reserved3 x0 newestYear 0 newestMonth 0 newestDay 0 newestHour 0 newestMin 0 newestSec 0 reserved4 x0 status x20 reserved5 x0 x0 ``` -------------------------------- ### Disable APT Recommended Packages Source: https://gpsd.io/troubleshooting.html Prevent APT from installing recommended packages, which can sometimes lead to unwanted installations like gpsd. This is useful when installing packages that recommend gpsd. ```bash APT::Install-Recommends "false"; ``` -------------------------------- ### Dump All Configuration Items Source: https://gpsd.io/ubxtool.html Retrieve a large range of configuration items, including known and unknown ones, currently in RAM. This example uses wildcards for group and item numbers and pipes the output to 'fgrep' to filter for 'item CFG-'. ```bash $ ubxtool -g CFG,0,0,1200 | fgrep "item CFG-" item CFG-1-1/0x10010001 val 0 item CFG-1-1/0x10010101 val 0 item CFG-4-1/0x10040001 val 1 item CFG-4-2/0x10040002 val 0 item CFG-4-3/0x10040003 val 0 item CFG-4-4/0x10040004 val 0 item CFG-4-9/0x10040009 val 0 item CFG-TP-TP1_ENA/0x10050007 val 1 item CFG-TP-SYNC_GNSS_TP1/0x10050008 val 1 [...] ``` -------------------------------- ### HWBIAS Example Source: https://gpsd.io/NMEA.html An example of an unknown HWBIAS sentence seen from Huawai GPS receivers. ```nmea $GPHWBIAS,11.2*21 ``` -------------------------------- ### HDT Example Source: https://gpsd.io/NMEA.html An example of an HDT sentence indicating a true heading of 274.07 degrees. ```nmea $GPHDT,274.07,T*03 ``` -------------------------------- ### GPSD Client Example in C Source: https://gpsd.io/index.html A line-by-line code walk-through of a simple gpsd client written in C. Focuses on common mistakes. ```c #include #include #include #include #include #include #include #include #define SERVER "127.0.0.1" #define BUFLEN 512 #define PORT 2947 int main(void) { struct sockaddr_in si_other; int s, i, slen=sizeof(si_other); char buf[BUFLEN]; char message[BUFLEN]; // Create socket if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; si_other.sin_port = htons(PORT); if (inet_aton(SERVER, &si_other.sin_addr) == 0) { fprintf(stderr, "inet_aton() failed\n"); exit(1); } // Send some data strcpy(message, "?WATCH={"driver=nmea"}"); if (sendto(s, message, strlen(message), 0, (struct sockaddr *) &si_other, slen) == -1) { die("sendto"); } // Receive data while (1) { printf("Waiting for packet...\n"); fflush(stdout); // Try to receive some data, this is blocking call if (recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == -1) { die("recvfrom"); } printf("Received packet: %s ", buf); } close(s); return 0; } ``` -------------------------------- ### DPT - Depth of Water Example Source: https://gpsd.io/NMEA.html Example of a Depth of Water sentence from an INDPT device. ```plaintext $INDPT,2.3,0.0*46 ``` -------------------------------- ### Build and Check gpsd on Fedora Source: https://gpsd.io/building.html Builds, checks, and installs gpsd on Fedora after dependency installation. ```bash # git clone https://gitlab.com/gpsd/gpsd.git # cd gpsd # scons # dnf builddep -y buildtmp/packaging/rpm/gpsd.spec # scons -c # scons && scons check && scons install ``` -------------------------------- ### Start Logging Source: https://gpsd.io/ubxtool-examples.html Initiates the logging process on the receiver. This command configures the log filter settings. ```bash $ ubxtool -e LOG [...] sent: UBX-CFG-LOGFILTER: version 1 flags x5 minInterval 0 timeThreshold 0 speedThreshold 0 positionThreshold 0 UBX-ACK-ACK: ACK to Class x06 (CFG) ID x47 (LOGFILTER) ``` -------------------------------- ### Build and Install gpsd from Source (Alternative) Source: https://gpsd.io/building.html A simplified sequence for cloning the gpsd repository and building/installing it using scons, after necessary dependencies are met. ```bash # git clone https://gitlab.com/gpsd/gpsd.git # cd gpsd # scons -c && scons && scons check && scons install ``` -------------------------------- ### VTG Example Source: https://gpsd.io/NMEA.html An example of a VTG sentence showing actual measured values for course and speed. ```NMEA $GPVTG,220.86,T,,M,2.550,N,4.724,K,A*34 ``` -------------------------------- ### RMC Example Source: https://gpsd.io/NMEA.html An example of a $GNRMC sentence, showing a valid fix with specific navigation parameters. ```text $GNRMC,001031.00,A,4404.13993,N,12118.86023,W,0.146,,100117,,,A*7B ``` -------------------------------- ### Install Optional GUI Dependencies (Bullseye) Source: https://gpsd.io/building.html Installs libraries for GTK3, which are necessary for running graphical clients like xgps and xgpsspeed. This is an optional step if GUI tools are not needed. ```bash # apt-get install python-gi-dev # apt-get install libgtk-3-dev ``` -------------------------------- ### DTM - Datum Reference Example Source: https://gpsd.io/NMEA.html Example of a Datum Reference sentence specifying the WGS84 datum. ```plaintext $GPDTM,W84,C*52 ``` -------------------------------- ### Install Optional Libusb (Bullseye) Source: https://gpsd.io/building.html Installs libusb-1.0-0-dev, which is required for supporting some older Garmin USB devices. ```bash # apt-get install libusb-1.0-0-dev ``` -------------------------------- ### Configure and Compile Daemon Source: https://gpsd.io/writing-a-driver.html Standard commands to configure and compile the daemon. Ensure you have the necessary build tools installed. ```bash ./configure make make install ``` -------------------------------- ### Install Optional Matplotlib (Bullseye) Source: https://gpsd.io/building.html Installs the python3-matplotlib package, which is a dependency for gpsplot to generate graphical output. ```bash # apt install python3-matplotlib ``` -------------------------------- ### Install Gentoo Build Tools Source: https://gpsd.io/building.html Installs essential build tools like scons and git on Gentoo. Use '--noreplace' to avoid reinstalling existing packages. ```bash # install the required build tools emerge --noreplace dev-build/scons dev-vcs/git # optional, to support the KPPS API, for improved timing emerge --noreplace net-misc/pps-tools # optional, for cgps and gpsmon emerge --noreplace sys-libs/ncurses # optional, for ubxtool and zerl serial port support emerge --noreplace dev-python/pyserial # optional, to support Garmin USB devices emerge --noreplace virtual/libusb # optional, to support Bluetooth GPS devices emerge --noreplace net-wireless/bluez # Skip the following optionals on a minimal system: # optional, to build man page and html pages emerge --noreplace dev-ruby/asciidoctor # Optionals for desktop (X) systems: # optional, for xgps and xgpsspeed emerge --noreplace dev-python/pygobject dev-python/pycairo # optional, for gpsplot emerge --noreplace dev-python/matplotlib # D-Bus support emerge --noreplace sys-apps/dbus # To build Qt compatible library. emerge --noreplace dev-qt/qtcore dev-qt/qtnetwork # "scons check" requires bc emerge --noreplace sys-devel/bc ``` -------------------------------- ### XDR Example Source: https://gpsd.io/NMEA.html An example of an XDR sentence reporting pitch, roll, and magnetometer data from different transducers. ```NMEA $HCXDR,A,171,D,PITCH,A,-37,D,ROLL,G,367,,MAGX,G,2420,,MAGY,G,-8984,,MAGZ*41 ``` -------------------------------- ### GPSD Client Example in Python Source: https://gpsd.io/index.html A line-by-line code walk-through of a simple gpsd client written in Python. Focuses on common mistakes. ```python import socket import json HOST = '127.0.0.1' PORT = 2947 # Create a socket object s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connect to the gpsd server try: s.connect((HOST, PORT)) except socket.error as e: print(f"Error connecting to gpsd: {e}") exit(1) # Send a command to start watching for data command = json.dumps({"enable": True, "json": True}).encode('utf-8') s.sendall(command + b'\n') # Receive and print data while True: try: data = s.recv(4096).decode('utf-8') if not data: break # gpsd sends data line by line, so we need to handle potential partial lines # For simplicity, we'll assume complete lines here, but a real client might need more robust parsing for line in data.strip().split('\n'): if line: try: message = json.loads(line) print(json.dumps(message, indent=2)) except json.JSONDecodeError: print(f"Received non-JSON data: {line}") except socket.error as e: print(f"Error receiving data: {e}") break # Close the connection s.close() ``` -------------------------------- ### Android build with custom prefix and directories Source: https://gpsd.io/building.html Build command for Android specifying prefix, library directory, udev directory, user, group, and socket export settings. ```bash scons -j3 prefix=/usr libdir=$prefix/lib udevdir=/lib/udev \ gpsd_user=gpsd gpsd_group=uucp socket_export=1 sirf=1 ``` -------------------------------- ### Install Build Dependencies on Fedora Source: https://gpsd.io/building.html Installs necessary development tools and libraries for building gpsd on Fedora 32-37. ```bash # dnf upgrade --refresh # dnf install -y gcc-c++ scons asciidoctor bzip2 # dnf install -y xz git dnf-plugins-core ``` -------------------------------- ### Check Firmware Version (FLASH) Source: https://gpsd.io/ubxtool-examples.html Use 'ubxtool -p MON-VER' to check the firmware version. 'swVersion EXT CORE' indicates the firmware is loaded from FLASH memory, allowing for updates. ```bash $ ubxtool -p MON-VER -P 27.12 [...] UBX-MON-VER: swVersion EXT CORE 1.00 (f10c36) hwVersion 00190000 extension ROM BASE 0x118B2060 extension FWVER=HPG 1.13 extension PROTVER=27.12 extension MOD=ZED-F9P extension GPS;GLO;GAL;BDS extension SBAS;QZSS ``` -------------------------------- ### Configuring Cross-Build Options Source: https://gpsd.io/building.html This snippet demonstrates how to set up cross-compilation by modifying the .scons-options-cache file. It specifies target architecture, sysroot, and installation prefix. ```bash $ cat .scons-option-cache libgpsmm = False libQgpsmm = False python = False prefix = '/work/buildroot/output/staging/usr/' sysroot = '/work/buildroot/output/staging/' target = 'arm-indigo-linux-gnueabi' ``` -------------------------------- ### Install scons and Python on OpenBSD Source: https://gpsd.io/building.html Installs scons and Python 3.8 on OpenBSD 13.0, required for building gpsd. ```bash # pkg install scons-py38 # ln -s /usr/local/bin/python3.8 /usr/local/bin/python3 ``` -------------------------------- ### GPSD Time Service Setup Source: https://gpsd.io/index.html Step-by-step instructions for setting up a Stratum 1 time server using GPSD and either ntpd or chrony. Includes tuning offsets for remote time servers. ```bash # Example commands for setting up GPSD time service # Ensure gpsd is installed and configured to output time data # sudo apt-get install gpsd gpsd-clients ntp # Configure gpsd to output time # Edit /etc/default/gpsd and set GPSD_OPTIONS="-n -G" # Restart gpsd: sudo systemctl restart gpsd # Configure ntpd to use gpsd as a time source # Edit /etc/ntp.conf # Add the following lines: # server 127.0.0.1 prefer iburst # fudge 127.0.0.1 time1 0.12345 time2 0.0 timecode 1 # Restart ntpd # sudo systemctl restart ntp # Verify time synchronization # ntpq -p ``` -------------------------------- ### Display help message for xgps Source: https://gpsd.io/xgps.html Use the -?, -h, or --help option to display a summary of available options and then exit. ```bash xgps -h ```