gps 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.
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Gps::Fix do
4
+
5
+ class Fix
6
+ include Gps::Fix
7
+ end
8
+
9
+ it "initializes GPS fix values to nil or 0" do
10
+ fix = Fix.new
11
+ fix.last_tag.should == nil
12
+ fix.timestamp.should == nil
13
+ fix.timestamp_error_estimate.should == nil
14
+ fix.latitude.should == 0
15
+ fix.longitude.should == 0
16
+ fix.altitude.should == 0
17
+ fix.horizontal_error_estimate.should == nil
18
+ fix.vertical_error_estimate.should == nil
19
+ fix.course.should == 0
20
+ fix.speed.should == 0
21
+ fix.climb.should == nil
22
+ fix.course_error_estimate.should == nil
23
+ fix.speed_error_estimate.should == nil
24
+ fix.climb_error_estimate.should == nil
25
+ fix.satellites.should == 0
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Gps::Receivers::Gpsd do
4
+
5
+ it "initializes itself with a host of localhost and port 2947 by default" do
6
+ gps = Gps::Receiver.create("gpsd")
7
+ gps.host.should == "localhost"
8
+ gps.port.should == 2947
9
+ end
10
+
11
+ it "initializes itself with the specified host and port" do
12
+ gps = Gps::Receiver.create("gpsd", :host => "foo.com", :port => 123)
13
+ gps.host.should == "foo.com"
14
+ gps.port.should == 123
15
+ end
16
+
17
+ it "opens a socket to its host and port and activates watcher mode when started" do
18
+ gps = Gps::Receiver.create
19
+ socket = mock("socket")
20
+ TCPSocket.should_receive(:new).with(gps.host, gps.port).and_return(socket)
21
+ socket.should_receive(:puts).with("w+")
22
+ gps.start
23
+ end
24
+
25
+ it "correctly parses O sentences on update" do
26
+ line = "GPSD,O=MID2 1187698425.040 0.005 53.527158 -113.530148 704.05 2.00 1.73 0.0000 0.074 0.101 ? ? ? 3\r\n"
27
+ gps = Gps::Receiver.create
28
+ socket = mock("socket")
29
+ TCPSocket.should_receive(:new).with(gps.host, gps.port).and_return(socket)
30
+ socket.should_receive(:puts).with("w+")
31
+ socket.should_receive(:gets).any_number_of_times.and_return(line)
32
+ gps.start
33
+ params = line.chomp.split("=")[1].split
34
+ sleep(0.1)
35
+ gps.last_tag.should == params[0]
36
+ gps.timestamp.should == params[1].to_f
37
+ gps.timestamp_error_estimate.should == params[2].to_f
38
+ gps.latitude.should == params[3].to_f
39
+ gps.longitude.should == params[4].to_f
40
+ gps.altitude.should == params[5].to_f
41
+ gps.horizontal_error_estimate.should == params[6].to_f
42
+ gps.vertical_error_estimate.should == params[7].to_f
43
+ gps.course.should == params[8].to_f
44
+ gps.speed.should == params[9].to_f
45
+ gps.climb.should == params[10].to_f
46
+ gps.course_error_estimate.should == params[11].to_f
47
+ gps.speed_error_estimate.should == params[12].to_f
48
+ gps.climb_error_estimate.should == params[13].to_f
49
+ end
50
+
51
+ it "correctly parses Y sentences on update" do
52
+ line = "GPSD,Y=MID4 1187698430.040 9:9 31 58 41 1:14 62 198 45 1:1 26 214 41 1:19 32 264 42 1:3 16 232 38 1:11 14 310 38 1:22 75 85 47 1:18 35 90 42 1:138 28 171 38 0:\r\n"
53
+ gps = Gps::Receiver.create
54
+ socket = mock("socket")
55
+ TCPSocket.should_receive(:new).with(gps.host, gps.port).and_return(socket)
56
+ socket.should_receive(:puts).with("w+")
57
+ socket.should_receive(:gets).any_number_of_times.and_return(line)
58
+ gps.start
59
+ params = line.chomp.split("=")[1].split(":")
60
+ sleep(0.1)
61
+ gps.satellites.should == params[0].split[-1].to_i
62
+ end
63
+ end
@@ -0,0 +1,111 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Gps::Receiver do
4
+
5
+ it "creates an instance of the first receiver in Gps::Receivers with specified options when its create method is called" do
6
+ First = mock("first")
7
+ Second = mock("second")
8
+ Gps::Receivers.should_receive(:constants).and_return([First, Second])
9
+ Gps::Receivers.should_receive(:const_get).with(First).and_return(First)
10
+ options = {:foo => :bar}
11
+ First.should_receive(:new).with(options)
12
+ Gps::Receiver.create(options)
13
+ end
14
+
15
+ it "creates an instance of the specified receiver in Gps::Receivers with specified options when its create method is called" do
16
+ receiver = mock("receiver")
17
+ Gps::Receivers.should_receive(:const_get).with("Receiver").and_return(receiver)
18
+ options = {:foo => :bar}
19
+ receiver.should_receive(:new).with(options)
20
+ Gps::Receiver.create("receiver", options)
21
+ end
22
+
23
+ it "supports setting latitude and longitude via the position attribute" do
24
+ gps = Gps::Receiver.new
25
+ gps.position = [20, 30]
26
+ gps.latitude.should == 20
27
+ gps.longitude.should == 30
28
+ end
29
+
30
+ it "should call the on_position_change callback on position changes" do
31
+ gps = Gps::Receiver.new
32
+ called = false
33
+ gps.on_position_change { called = true }
34
+ gps.position = [20, 30]
35
+ called.should == true
36
+ end
37
+
38
+ it "should not call the on_position_change callback if the position change is below the specified threshold" do
39
+ gps = Gps::Receiver.new
40
+ called = false
41
+ gps.on_position_change(5) { called = true }
42
+ gps.position = [0, 1]
43
+ called.should == false
44
+ end
45
+
46
+ it "should call the on_position_change callback if the position change is above the specified threshold" do
47
+ gps = Gps::Receiver.new
48
+ called = false
49
+ gps.on_position_change(5) { called = true }
50
+ gps.position = [0, 6]
51
+ called.should == true
52
+ end
53
+
54
+ it "should cope with intermediate position changes, not calling on_position_change until the threshold is exceeded" do
55
+ gps = Gps::Receiver.new
56
+ called = false
57
+ gps.on_position_change(5) { called = true }
58
+ gps.position = [0, 4]
59
+ called.should == false
60
+ gps.position = [0, 6]
61
+ called.should == true
62
+ end
63
+
64
+ it "should call position, speed , satellite and course change callbacks when updated, if necessary" do
65
+ gps = Gps::Receiver.new
66
+ course_changed = speed_changed = position_changed = altitude_changed = satellites_changed = nil
67
+ degrees_changed = 0
68
+ gps.on_position_change { |degrees| position_changed = true; degrees_changed = degrees }
69
+ gps.on_speed_change { speed_changed = true }
70
+ gps.on_course_change { course_changed = true }
71
+ gps.on_altitude_change { altitude_changed = true }
72
+ gps.on_satellites_change { satellites_changed = true }
73
+ gps.instance_eval("@latitude = 5")
74
+ gps.instance_eval("@speed = 10")
75
+ gps.instance_eval("@course = 1")
76
+ gps.instance_eval("@altitude = 1000")
77
+ gps.instance_eval("@satellites = 15")
78
+ gps.update
79
+ course_changed.should == true
80
+ position_changed.should == true
81
+ degrees_changed.should == 5
82
+ speed_changed.should == true
83
+ altitude_changed.should == true
84
+ satellites_changed.should == true
85
+ end
86
+
87
+ it "should spawn a new, updating thread when started" do
88
+ gps = Gps::Receiver.new
89
+ gps.should_receive(:update).any_number_of_times
90
+ gps.start
91
+ end
92
+
93
+ it "should report that it is started" do
94
+ gps = Gps::Receiver.new
95
+ gps.start
96
+ gps.started?.should == true
97
+ end
98
+
99
+ it "should report that it is not started before start has been called" do
100
+ gps = Gps::Receiver.new
101
+ gps.started?.should == false
102
+ end
103
+
104
+ it "should kill its update thread when stopped" do
105
+ gps = Gps::Receiver.new
106
+ gps.start
107
+ gps.started?.should == true
108
+ gps.stop
109
+ gps.started?.should == false
110
+ end
111
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require File.dirname(__FILE__)+"/../lib/gps"
@@ -0,0 +1,31 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ task :check_version do
11
+ unless ENV['VERSION']
12
+ puts 'Must pass a VERSION=x.y.z release version'
13
+ exit
14
+ end
15
+ unless ENV['VERSION'] == VERS
16
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
17
+ exit
18
+ end
19
+ end
20
+
21
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
22
+ task :install_gem_no_doc => [:clean, :package] do
23
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
24
+ end
25
+
26
+ namespace :manifest do
27
+ desc 'Recreate Manifest.txt to include ALL files'
28
+ task :refresh do
29
+ `rake check_manifest | patch -p0 > Manifest.txt`
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/*_spec.rb']
21
+ end
@@ -0,0 +1,9 @@
1
+ # stubs for the website generation
2
+ # To install the website framework:
3
+ # script/generate website
4
+
5
+ task :website_generate
6
+
7
+ task :website_upload
8
+
9
+ task :website => :publish_docs
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nolan Darilek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-11 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: An interface to GPS receivers
17
+ email: nolan@thewordnerd.info
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - License.txt
25
+ - Manifest.txt
26
+ - README.txt
27
+ files:
28
+ - History.txt
29
+ - License.txt
30
+ - Manifest.txt
31
+ - README.txt
32
+ - Rakefile
33
+ - config/hoe.rb
34
+ - config/requirements.rb
35
+ - lib/gps.rb
36
+ - lib/gps/fix.rb
37
+ - lib/gps/receiver.rb
38
+ - lib/gps/receivers/gpsd.rb
39
+ - lib/gps/version.rb
40
+ - script/destroy
41
+ - script/generate
42
+ - setup.rb
43
+ - spec/fix_spec.rb
44
+ - spec/gpsd_spec.rb
45
+ - spec/receiver_spec.rb
46
+ - spec/spec.opts
47
+ - spec/spec_helper.rb
48
+ - tasks/deployment.rake
49
+ - tasks/environment.rake
50
+ - tasks/rspec.rake
51
+ - tasks/website.rake
52
+ has_rdoc: true
53
+ homepage: http://hermes-gps.info/
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --main
57
+ - README.txt
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project: hermes
75
+ rubygems_version: 1.0.1
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: This library provides an elegant interface to data from GPS receivers. An extensible architecture simplifies adding new receiver types, with a GPSD receiver already written. Additionally, the API supports registering callbacks triggered on change of position, course, altitude and visible satellites.
79
+ test_files: []
80
+