{"id":19517511,"url":"https://github.com/ivkos/gpsd4j","last_synced_at":"2025-04-26T06:31:22.545Z","repository":{"id":54400468,"uuid":"97719881","full_name":"ivkos/gpsd4j","owner":"ivkos","description":"gpsd client for Java","archived":false,"fork":false,"pushed_at":"2021-02-20T11:58:24.000Z","size":68,"stargazers_count":12,"open_issues_count":6,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T09:11:21.324Z","etag":null,"topics":["api","async","asynchronous","client","event-driven","functional","galileo","global","glonass","gps","gpsd","java","jitpack","maven","message-driven","navigation","positioning","satellite","system","vertx"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivkos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-19T13:33:50.000Z","updated_at":"2024-06-25T14:27:06.000Z","dependencies_parsed_at":"2022-08-13T14:31:03.843Z","dependency_job_id":null,"html_url":"https://github.com/ivkos/gpsd4j","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fgpsd4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fgpsd4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fgpsd4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fgpsd4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivkos","download_url":"https://codeload.github.com/ivkos/gpsd4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250944132,"owners_count":21511698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","async","asynchronous","client","event-driven","functional","galileo","global","glonass","gps","gpsd","java","jitpack","maven","message-driven","navigation","positioning","satellite","system","vertx"],"created_at":"2024-11-11T00:04:20.892Z","updated_at":"2025-04-26T06:31:22.082Z","avatar_url":"https://github.com/ivkos.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gpsd4j\n\n[![Release](https://jitpack.io/v/com.ivkos/gpsd4j.svg)](https://jitpack.io/#com.ivkos/gpsd4j)\n[![Downloads](https://jitpack.io/v/com.ivkos/gpsd4j/month.svg)](https://jitpack.io/#com.ivkos/gpsd4j)\n\n\n**gpsd4j** is a Java library that allows you to communicate with a [gpsd server](http://www.catb.org/gpsd/).\n\n## Table of Contents\n* [Requirements](#requirements)\n* [Installation](#installation)\n\t* [Maven](#maven)\n\t* [Gradle](#gradle)\n* [Documentation](#documentation)\n* [Quick Start](#quick-start)\n\t* [Creating a client](#creating-a-client)\n\t* [Message handlers](#message-handlers)\n\t* [Client lifecycle](#client-lifecycle)\n\t\t* [Persisting device settings and watch mode](#persisting-device-settings-and-watch-mode)\n\t* [Sending commands](#sending-commands)\n\t\t* [Sending a command and expecting a response](#sending-a-command-and-expecting-a-response)\n\t\t* [Sending a command and not awaiting a response](#sending-a-command-and-not-awaiting-a-response)\n\t* [Putting it all together](#putting-it-all-together)\n\n\n\n## Requirements\n* JRE 8 or higher at runtime\n* JDK 8 or higher to compile the library from source\n\n## Installation\n### Maven\n**Step 1.** Add the JitPack repository to your `pom.xml` file:\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ejitpack.io\u003c/id\u003e\n        \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n**Step 2.** Add the dependency:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.ivkos\u003c/groupId\u003e\n    \u003cartifactId\u003egpsd4j\u003c/artifactId\u003e\n    \u003cversion\u003e1.3.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n**Step 1.** Add the JitPack repository to your root `build.gradle` at the end of repositories:\n```\nallprojects {\n    repositories {\n      ...\n      maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\n**Step 2.** Add the dependency:\n```\ndependencies {\n    compile 'com.ivkos:gpsd4j:1.3.1'\n}\n```\n\n## Documentation\nJavadocs can be found [here](https://jitpack.io/com/ivkos/gpsd4j/1.3.1/javadoc/).\n\n## Quick Start\n\u003e An example is worth a thousand pages of Javadocs.\n\n\n### Creating a client\n```java\n// Create a client for connecting to the gpsd server at localhost, port 2947\nGpsdClient client = new GpsdClient(\"localhost\", 2947);\n```\n\n```java\n// You can pass an options object if you wish to configure connection handling\nGpsdClientOptions options = new GpsdClientOptions()\n    .setReconnectOnDisconnect(true)\n    .setConnectTimeout(3000) // ms\n    .setIdleTimeout(30) // seconds\n    .setReconnectAttempts(5)\n    .setReconnectInterval(3000); // ms\n\nGpsdClient client = new GpsdClient(\"localhost\", 2947, options);\n```\n\n\n### Message handlers\nBecause of the asynchronous nature of the client, you can\ndynamically add or remove handlers with no unexpected side effects,\nno matter if the client is running or not.\n\n```java\n// Adds a handler that prints received gpsd errors to stderr\nclient.addErrorHandler(System.err::println);\n\n// Adds a message handler that handles incoming TPV messages\nclient.addHandler(TPVReport.class, tpv -\u003e {\n    Double lat = tpv.getLatitude();\n    Double lon = tpv.getLongitude();\n\n    System.out.printf(\"Lat: %f, Lon: %f\\n\", lat, lon);\n});\n\n// Adding handlers can be chained\nclient.addHandler(TPVReport.class, tpv -\u003e { ... })\n      .addHandler(SKYReport.class, sky -\u003e { ... })\n      .addHandler(GSTReport.class, gst -\u003e { ... });\n```\n\n```java\n// Suppose you use a generic handler for multiple types of messages\nConsumer\u003c? extends GpsdMessage\u003e genericHandler = msg -\u003e {\n    System.out.println(\"Got a message: \" + msg);\n};\n\nclient.addHandler(TPVReport.class, (Consumer\u003cTPVReport\u003e) genericHandler)\n      .addHandler(GSTReport.class, (Consumer\u003cGSTReport\u003e) genericHandler);\n\n// You can remove it from a specific type of message\nclient.removeHandler(TPVReport.class, (Consumer\u003cTPVReport\u003e) genericHandler);\n\n// Or you can remove it altogether from all types of messages\nclient.removeHandler(genericHandler);\n```\n\n\n### Client lifecycle\n```java\n// After you have created a client and (optionally) added handlers, you can start it\nclient.start();\n\n// As long as the client is running, you can send commands to the gpsd server\n// More on that later...\nclient.sendCommand(...)\n      .sendCommand(..., result -\u003e { ... });\n\n// Send a command to the server to enable dumping of messages\nclient.watch();\n\n// To stop the client:\nclient.stop();\n```\n\n#### Persisting device settings and watch mode\nDevice settings and watch mode settings may be lost if the connection drops\nor the gpsd server restarts. In order to persist them, you can set a connection\nhandler that gets executed upon each successful connection the gpsd server, including\nreconnections.\n```java\nnew GpsdClient(...)\n    .setSuccessfulConnectionHandler(client -\u003e {\n       DeviceMessage device = new DeviceMessage();\n       device.setPath(\"/dev/ttyAMA0\");\n       device.setNative(true);\n\n       client.sendCommand(device);\n       client.watch();\n    })\n    .addHandler(TPVReport.class, tpv -\u003e { ... })\n    .start();\n```\n\n\n### Sending commands\nThere are multiple ways of sending commands to the server. In order to send commands,\nthe client must be started and running. Otherwise, an `IllegalStateException` may be thrown.\n\n#### Sending a command and expecting a response\n```java\n// The response is the same type as the command message (subtypes of GpsdCommandMessage)\nclient.sendCommand(new PollMessage(), pollMessageResponse -\u003e {\n    Integer activeDevices = pollMessageResponse.getActiveCount();\n});\n```\n\n#### Sending a command and not awaiting a response\n```java\n// Setup the GPS device to run in its native mode\nDeviceMessage device = new DeviceMessage();\ndevice.setPath(\"/dev/ttyAMA0\");\ndevice.setNative(true);\n\nclient.sendCommand(device);\n```\n\n\n### Putting it all together\n```java\nnew GpsdClient(\"localhost\", 2947)\n      .addErrorHandler(System.err::println)\n      .addHandler(TPVReport.class, tpv -\u003e {\n          Double lat = tpv.getLatitude();\n          Double lon = tpv.getLongitude();\n\n          System.out.printf(\"Lat: %f, Lon: %f\\n\", lat, lon);\n      })\n      .addHandler(SKYReport.class, sky -\u003e {\n          System.out.printf(\"We can see %d satellites\\n\", sky.getSatellites().size())\n      })\n      .setSuccessfulConnectionHandler(client -\u003e {\n          DeviceMessage device = new DeviceMessage();\n          device.setPath(\"/dev/ttyAMA0\");\n          device.setNative(true);\n\n          client.sendCommand(device);\n          client.watch();\n      })\n      .start();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivkos%2Fgpsd4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivkos%2Fgpsd4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivkos%2Fgpsd4j/lists"}