Skip to content

Commit

Permalink
Change gpsd client package to node-gpsd-client (#1551)
Browse files Browse the repository at this point in the history
from node-gpsd - this is done to make signalk able to reconnect to gpsd
socket when no data has been received for a configurable time.
  • Loading branch information
jakobdalsgaard authored Jul 18, 2023
1 parent a06996b commit 423077a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions packages/streams/gpsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

const Transform = require('stream').Transform
const gpsd = require('node-gpsd')
const GpsdClient = require('node-gpsd-client')

function Gpsd(options) {
Transform.call(this, {
Expand All @@ -40,16 +40,18 @@ function Gpsd(options) {

const port = options.port || 2947
const hostname = options.hostname || options.host || 'localhost'
const noDataReceivedTimeout = options.noDataReceivedTimeout || 0


function setProviderStatus(msg) {
options.app.setProviderStatus(options.providerId, msg)
}

const createDebug = options.createDebug || require('debug')

this.listener = new gpsd.Listener({
port,
hostname,
this.listener = new GpsdClient({
port: port,
hostname: hostname,
logger: {
info: createDebug('signalk:streams:gpsd'),
warn: console.warn,
Expand All @@ -61,23 +63,27 @@ function Gpsd(options) {
},
},
parse: false,
reconnectThreshold: noDataReceivedTimeout,
reconnectInterval: noDataReceivedTimeout / 2
})

setProviderStatus(`Connecting to ${hostname}:${port}`)

this.listener.connect(function () {
this.listener.on('connected', () => {
setProviderStatus(`Connected to ${hostname}:${port}`)
this.listener.watch({
class : "WATCH",
nmea: true,
json: false
})
})

const self = this
this.listener.on('raw', function (data) {
self.push(data)
})

this.listener.watch({
class: 'WATCH',
nmea: true,
})
this.listener.connect();
}

require('util').inherits(Gpsd, Transform)
Expand Down
2 changes: 1 addition & 1 deletion packages/streams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"file-timestamp-stream": "^2.1.2",
"lodash": "^4.17.4",
"moment": "^2.24.0",
"node-gpsd": "^0.3.0",
"node-gpsd-client": "^1.4.1",
"reconnect-core": "^1.3.0",
"stream-throttle": "^0.1.3"
},
Expand Down

0 comments on commit 423077a

Please sign in to comment.