gpsd_client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gpsd_client.gemspec +29 -0
- data/lib/gpsd_client.rb +81 -0
- data/lib/gpsd_client/version.rb +3 -0
- metadata +105 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# GpsdClient
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gpsd_client`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'gpsd_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gpsd_client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/rccursach/gpsd_client/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gpsd_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/gpsd_client.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gpsd_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gpsd_client"
|
8
|
+
spec.version = GpsdClient::VERSION
|
9
|
+
spec.authors = ["rccursach"]
|
10
|
+
spec.email = ["rccursach@gmail.com"]
|
11
|
+
|
12
|
+
# if spec.respond_to?(:metadata)
|
13
|
+
# spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
14
|
+
# end
|
15
|
+
|
16
|
+
spec.summary = %q{Ruby gem for GPSD.}
|
17
|
+
spec.description = %q{A simple GPSd client intended for use on the Raspberry Pi.}
|
18
|
+
spec.homepage = "https://github.com/rccursach/gpsd_client"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec-core", "~> 3.2.1"
|
29
|
+
end
|
data/lib/gpsd_client.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "gpsd_client/version"
|
2
|
+
|
3
|
+
require "socket"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module GpsdClient
|
7
|
+
|
8
|
+
class Gpsd
|
9
|
+
attr_reader :host, :port
|
10
|
+
|
11
|
+
@started = false
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@host ||= options[:host] ||= "localhost"
|
15
|
+
@port = options[:port] ||= 2947
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
if not @started
|
20
|
+
begin
|
21
|
+
@socket = TCPSocket.new(@host, @port)
|
22
|
+
@socket.puts("w+")
|
23
|
+
line = @socket.gets
|
24
|
+
# puts "debug >> #{line[0...20]}"
|
25
|
+
@started = true if line.start_with? '{"class":"VERSION"'
|
26
|
+
rescue
|
27
|
+
@started = false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
return @started
|
31
|
+
end
|
32
|
+
|
33
|
+
def started?
|
34
|
+
@started
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
return not_started_msg("Gpsd.stop") if not self.started?
|
39
|
+
@socket.puts('?WATCH={"enable":false}')
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_position
|
43
|
+
reads = 0
|
44
|
+
|
45
|
+
return not_started_msg("Gpsd.get_position") if not self.started?
|
46
|
+
|
47
|
+
while reads < 7 do # Skip VERSION SKY WATCH or DEVICES response
|
48
|
+
line = ""
|
49
|
+
begin
|
50
|
+
@socket.puts('?WATCH={"enable":true,"json":true}')
|
51
|
+
line = @socket.gets
|
52
|
+
#puts "debug >> #{line[0...20]}"
|
53
|
+
rescue
|
54
|
+
puts "Error writing Socket"
|
55
|
+
end
|
56
|
+
|
57
|
+
#puts line
|
58
|
+
if line.start_with? '{"class":"TPV"'
|
59
|
+
line = JSON.parse(line)
|
60
|
+
# http://www.catb.org/gpsd/client-howto.html
|
61
|
+
# mode 1 means no valid data
|
62
|
+
# return "Lat: #{line['lat'].to_s}, Lon: #{line['lon'].to_s}" unless line['mode'] == 1
|
63
|
+
return {lat: line['lat'], lon: line['lon']} unless line['mode'] == 1
|
64
|
+
end
|
65
|
+
|
66
|
+
reads = reads + 1
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
return {lat: nil, lon: nil}
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def not_started_msg( method = "Gpsd" )
|
76
|
+
puts "#{method}: Socket connection wasn't started"
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpsd_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- rccursach
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.8'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.8'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '10.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '10.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec-core
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.1
|
62
|
+
description: A simple GPSd client intended for use on the Raspberry Pi.
|
63
|
+
email:
|
64
|
+
- rccursach@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .travis.yml
|
72
|
+
- Gemfile
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
77
|
+
- gpsd_client.gemspec
|
78
|
+
- lib/gpsd_client.rb
|
79
|
+
- lib/gpsd_client/version.rb
|
80
|
+
homepage: https://github.com/rccursach/gpsd_client
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.23
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Ruby gem for GPSD.
|
105
|
+
test_files: []
|