gpsd_client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gpsd_client.gemspec +1 -0
- data/lib/gpsd_client/version.rb +1 -1
- data/lib/gpsd_client.rb +38 -21
- metadata +8 -3
data/gpsd_client.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.license = "MIT"
|
20
20
|
|
21
21
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
#spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
23
|
spec.bindir = "exe"
|
23
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
25
|
spec.require_paths = ["lib"]
|
data/lib/gpsd_client/version.rb
CHANGED
data/lib/gpsd_client.rb
CHANGED
@@ -11,7 +11,7 @@ module GpsdClient
|
|
11
11
|
@started = false
|
12
12
|
|
13
13
|
def initialize(options = {})
|
14
|
-
@host
|
14
|
+
@host = options[:host] ||= 'localhost'
|
15
15
|
@port = options[:port] ||= 2947
|
16
16
|
end
|
17
17
|
|
@@ -19,12 +19,18 @@ module GpsdClient
|
|
19
19
|
if not @started
|
20
20
|
begin
|
21
21
|
@socket = TCPSocket.new(@host, @port)
|
22
|
-
@socket.puts
|
23
|
-
line = @socket.gets
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
@socket.puts 'w+'
|
23
|
+
line = JSON.parse @socket.gets rescue ''
|
24
|
+
if line.is_a? Hash and line['class'] == 'VERSION'
|
25
|
+
#@socket.puts '?WATCH={"enable":true,"json":true}' # disabled reporting, instead we are polling
|
26
|
+
@socket.puts '?WATCH={"enable":true};'
|
27
|
+
@started = true
|
28
|
+
end
|
29
|
+
|
30
|
+
rescue Exception => ex
|
31
|
+
puts 'Some error happen starting socket connection:'
|
32
|
+
puts ex.message
|
33
|
+
self.stop
|
28
34
|
end
|
29
35
|
end
|
30
36
|
return @started
|
@@ -36,27 +42,37 @@ module GpsdClient
|
|
36
42
|
|
37
43
|
def stop
|
38
44
|
return not_started_msg("Gpsd.stop") if not self.started?
|
39
|
-
@socket.puts
|
45
|
+
@socket.puts '?WATCH={"enable":false};'
|
46
|
+
@socket.close unless @socket.closed?
|
47
|
+
@started = false if @socket.closed?
|
48
|
+
!self.started?
|
40
49
|
end
|
41
50
|
|
42
51
|
def get_position
|
43
52
|
reads = 0
|
53
|
+
empty_hash = {lat: nil, lon: nil, time: nil, speed: nil, altitude: nil }
|
54
|
+
return empty_hash if not self.started?
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
while reads < 7 do # Skip VERSION SKY WATCH or DEVICES response
|
56
|
+
while reads < 10 do # Skip VERSION SKY WATCH or DEVICES response
|
48
57
|
line = ""
|
49
58
|
begin
|
50
|
-
@socket.puts
|
59
|
+
@socket.puts '?WATCH={"enable":true};'
|
60
|
+
@socket.puts "?POLL;"
|
61
|
+
sleep 1
|
51
62
|
line = @socket.gets
|
52
|
-
|
53
|
-
|
54
|
-
puts "Error writing Socket"
|
63
|
+
rescue Exception => ex
|
64
|
+
puts "Error while reading Socket: #{ex.message}"
|
55
65
|
end
|
56
66
|
|
57
|
-
#
|
58
|
-
if
|
59
|
-
|
67
|
+
# Parse line, return empty string on fail
|
68
|
+
# if parsed, extract ptv Hash from the JSON report polled
|
69
|
+
line = JSON.parse(line) rescue ''
|
70
|
+
if line.is_a? Hash and line['tpv'].is_a? Array
|
71
|
+
#puts "debug >> #{line.to_json.to_s}"
|
72
|
+
line = line['tpv'][0]
|
73
|
+
end
|
74
|
+
|
75
|
+
if line.is_a? Hash and line['class'] == 'TPV'
|
60
76
|
# http://www.catb.org/gpsd/client-howto.html
|
61
77
|
# mode 1 means no valid data
|
62
78
|
# return "Lat: #{line['lat'].to_s}, Lon: #{line['lon'].to_s}" unless line['mode'] == 1
|
@@ -66,13 +82,14 @@ module GpsdClient
|
|
66
82
|
reads = reads + 1
|
67
83
|
|
68
84
|
end
|
69
|
-
|
85
|
+
puts "TPV not found polling on GPSd"
|
86
|
+
return empty_hash
|
70
87
|
end
|
71
88
|
|
72
89
|
private
|
73
90
|
|
74
|
-
def not_started_msg( method =
|
75
|
-
puts "#{method}:
|
91
|
+
def not_started_msg( method = 'Gpsd' )
|
92
|
+
puts "#{method}: No socket connection started"
|
76
93
|
return nil
|
77
94
|
end
|
78
95
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpsd_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -74,7 +74,6 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- bin/console
|
76
76
|
- bin/setup
|
77
|
-
- gpsd_client-0.0.2.gem
|
78
77
|
- gpsd_client.gemspec
|
79
78
|
- lib/.gitignore
|
80
79
|
- lib/gpsd_client.rb
|
@@ -92,12 +91,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
91
|
- - ! '>='
|
93
92
|
- !ruby/object:Gem::Version
|
94
93
|
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 223085853
|
95
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
98
|
none: false
|
97
99
|
requirements:
|
98
100
|
- - ! '>='
|
99
101
|
- !ruby/object:Gem::Version
|
100
102
|
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: 223085853
|
101
106
|
requirements: []
|
102
107
|
rubyforge_project:
|
103
108
|
rubygems_version: 1.8.23
|