nmea_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.
data/nmea_gps.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 'nmea_gps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nmea_gps"
8
+ spec.version = NmeaGps::VERSION
9
+ spec.authors = ["ore"]
10
+ spec.email = ["orenoimac@gmail.com"]
11
+ spec.summary = %q{NMEA GPS logs to trigger a callback on each NMEA 0183 sentence.}
12
+ spec.description = %q{add your serialport object, and you'll get callbacks every time the serialport gets logs.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "factory_girl"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "timecop"
27
+ spec.add_dependency "serialport"
28
+ spec.add_dependency "activesupport"
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/gps'
3
+
4
+ describe Nmea::DddFormatable do
5
+ class Target
6
+ include Nmea::DddFormatable
7
+ end
8
+
9
+ subject{ Target.new }
10
+
11
+ describe "dmm_to_ddd" do
12
+ let(:dmm){ 3539.51480 }
13
+ let(:direction){ "N" }
14
+
15
+ it{ expect(subject.send :dmm_to_ddd, dmm, direction).to eq 35.65858 }
16
+ end
17
+
18
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/gps'
3
+
4
+ describe Nmea::Gps do
5
+ let(:serial_port){ double("serial_port") }
6
+ let(:update_hz){ 1 }
7
+ let(:gps){ Nmea::Gps.new serial_port, update_hz: update_hz }
8
+
9
+ describe "hz" do
10
+ subject{ gps.send :hz }
11
+ it{ expect(subject).to eq 1 }
12
+
13
+ context "10Hz" do
14
+ let(:update_hz){ 10 }
15
+ it{ expect(subject).to eq 0.1 }
16
+ end
17
+ end
18
+
19
+ describe "frequency" do
20
+ let(:hz){ 1 / 1 }
21
+ before{ allow(Kernel).to receive(:sleep).with(hz) }
22
+ it{ expect{ gps.send :frequency }.not_to raise_error }
23
+
24
+ context "10Hz" do
25
+ let(:hz){ 1 / 10 }
26
+ it{ expect{ gps.send :frequency }.not_to raise_error }
27
+ end
28
+ end
29
+
30
+ describe "dynamic sentence methods" do
31
+ it{ expect(gps).to respond_to :gga }
32
+ it{ expect(gps).to respond_to :gll }
33
+ it{ expect(gps).to respond_to :gsa }
34
+ it{ expect(gps).to respond_to :gsv }
35
+ it{ expect(gps).to respond_to :rmc }
36
+ it{ expect(gps).to respond_to :gga }
37
+ it{ expect(gps).to respond_to :vtg }
38
+ it{ expect(gps).to respond_to :zda }
39
+ end
40
+
41
+ describe "line_set" do
42
+ before do
43
+ allow(serial_port).to receive(:gets).and_return *lines.collect{|line| "#{line}\r\n" }
44
+ end
45
+
46
+ subject{ gps.send :line_set }
47
+
48
+ context "single" do
49
+ let(:lines){ ["$GPGGA,075247.000,3539.51480,N,13944.72598,E,1,8,0.97,-15.6,M,27.5,M,13,X*44"] }
50
+
51
+ it{ expect(subject.keys).to eq [:gga] }
52
+ it{ expect(subject.values).to eq [lines] }
53
+ end
54
+
55
+ context "multiple lines", focus: true do
56
+ let(:lines) do
57
+ [
58
+ "$GPGLL,3539.51480,N,13944.72598,E,075247.000,A,A*5D",
59
+ "$GPGSA,A,3,24,26,05,13,21,12,15,18,,,,,1.29,0.97,0.86*00",
60
+ "$GPGSV,3,1,11,24,70,198,52,15,63,016,,50,47,156,38,21,44,270,39*78",
61
+ "$GPGSV,3,2,11,18,40,314,30,26,27,058,46,05,19,124,42,12,09,159,35*73",
62
+ "$GPGSV,3,3,11,13,07,067,35,28,07,041,15,22,05,309,28*42",
63
+ "$GPRMC,075333.000,A,3539.51480,N,13944.72598,E,32.84,151.55,171214,,,A*68",
64
+ "$GPVTG,93.98,T,,M,32.84,N,60.85,K,D*05",
65
+ "$GPZDA,075936.000,17,12,2014,,*5A",
66
+ "$GPGGA,075247.000,3539.51480,N,13944.72598,E,1,8,0.97,-15.6,M,27.5,M,13,X*44",
67
+ ]
68
+ end
69
+
70
+
71
+ it{ expect(subject.keys.sort).to eq [:gga, :gll, :gsa, :gsv, :rmc, :vtg, :zda] }
72
+ it do
73
+ expect(subject).to eq({
74
+ gll: ["$GPGLL,3539.51480,N,13944.72598,E,075247.000,A,A*5D"],
75
+ gsa: ["$GPGSA,A,3,24,26,05,13,21,12,15,18,,,,,1.29,0.97,0.86*00"],
76
+ gsv: [
77
+ "$GPGSV,3,1,11,24,70,198,52,15,63,016,,50,47,156,38,21,44,270,39*78",
78
+ "$GPGSV,3,2,11,18,40,314,30,26,27,058,46,05,19,124,42,12,09,159,35*73",
79
+ "$GPGSV,3,3,11,13,07,067,35,28,07,041,15,22,05,309,28*42",
80
+ ],
81
+ rmc: ["$GPRMC,075333.000,A,3539.51480,N,13944.72598,E,32.84,151.55,171214,,,A*68"],
82
+ vtg: ["$GPVTG,93.98,T,,M,32.84,N,60.85,K,D*05"],
83
+ zda: ["$GPZDA,075936.000,17,12,2014,,*5A"],
84
+ gga: ["$GPGGA,075247.000,3539.51480,N,13944.72598,E,1,8,0.97,-15.6,M,27.5,M,13,X*44"],
85
+ })
86
+ end
87
+
88
+ end
89
+ end
90
+
91
+ describe "" do
92
+ end
93
+
94
+ describe "" do
95
+ end
96
+
97
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/gps'
3
+ require 'nmea_gps/sentences/gga'
4
+ require 'nmea_gps/sentences/gll'
5
+ require 'nmea_gps/sentences/gsa'
6
+ require 'nmea_gps/sentences/gsv'
7
+ require 'nmea_gps/sentences/rmc'
8
+ require 'nmea_gps/sentences/vtg'
9
+ require 'nmea_gps/sentences/zda'
10
+
11
+ describe Nmea::Gps do
12
+ let(:serial_port){ double("serial_port") }
13
+ let(:update_hz){ 1 }
14
+ let(:gps){ Nmea::Gps.new serial_port, update_hz: update_hz }
15
+
16
+ describe "hz" do
17
+ subject{ gps.send :hz }
18
+ it{ expect(subject).to eq 1 }
19
+
20
+ context "10Hz" do
21
+ let(:update_hz){ 10 }
22
+ it{ expect(subject).to eq 0.1 }
23
+ end
24
+ end
25
+
26
+ describe "frequency" do
27
+ before{ expect(gps).to receive(:sleep).with(hz).at_least 1 }
28
+
29
+ let(:hz){ 1 / 1 }
30
+ it{ gps.send :frequency }
31
+
32
+ context "10Hz" do
33
+ let(:update_hz){ 10 }
34
+ let(:hz){ 1 / 10.0 }
35
+ it{ gps.send :frequency }
36
+ end
37
+ end
38
+
39
+ describe "dynamic sentence methods" do
40
+ it{ expect(gps).to respond_to :gga }
41
+ it{ expect(gps).to respond_to :gll }
42
+ it{ expect(gps).to respond_to :gsa }
43
+ it{ expect(gps).to respond_to :gsv }
44
+ it{ expect(gps).to respond_to :rmc }
45
+ it{ expect(gps).to respond_to :gga }
46
+ it{ expect(gps).to respond_to :vtg }
47
+ it{ expect(gps).to respond_to :zda }
48
+ end
49
+
50
+ describe "line_set" do
51
+ before do
52
+ allow(serial_port).to receive(:gets).and_return *lines.collect{|line| "#{line}\r\n" }
53
+ end
54
+
55
+ subject{ gps.send :line_set }
56
+
57
+ context "single line" do
58
+ let(:lines) do
59
+ ["$GPGGA,075800.000,3357.7401,N,13112.3701,E,2,9,1.04,-3.6,M,27.5,M,0000,0000*74"]
60
+ end
61
+ it{ expect(subject.keys).to eq [:gga] }
62
+ end
63
+
64
+ context "multiple lines" do
65
+ let(:lines) do
66
+ [
67
+ "$GPGLL,3539.51480,N,13944.72598,E,075247.000,A,A*5D",
68
+ "$GPGSA,A,3,24,26,05,13,21,12,15,18,,,,,1.29,0.97,0.86*00",
69
+ "$GPGSV,3,1,11,24,70,198,52,15,63,016,,50,47,156,38,21,44,270,39*78",
70
+ "$GPGSV,3,2,11,18,40,314,30,26,27,058,46,05,19,124,42,12,09,159,35*73",
71
+ "$GPGSV,3,3,11,13,07,067,35,28,07,041,15,22,05,309,28*42",
72
+ "$GPRMC,075333.000,A,3539.51480,N,13944.72598,E,32.84,151.55,171214,,,A*68",
73
+ "$GPVTG,93.98,T,,M,32.84,N,60.85,K,D*05",
74
+ "$GPZDA,075936.000,17,12,2014,,*5A",
75
+ "$GPGGA,075800.000,3357.7401,N,13112.3701,E,2,9,1.04,-3.6,M,27.5,M,0000,0000*74",
76
+ ]
77
+ end
78
+ it{ expect(subject.keys.sort).to eq [:gga, :gll, :gsa, :gsv, :rmc, :vtg, :zda] }
79
+ it do expect(subject).to eq({
80
+
81
+ gga: ["$GPGGA,075800.000,3357.7401,N,13112.3701,E,2,9,1.04,-3.6,M,27.5,M,0000,0000*74"],
82
+ gll: ["$GPGLL,3539.51480,N,13944.72598,E,075247.000,A,A*5D"],
83
+ gsa: ["$GPGSA,A,3,24,26,05,13,21,12,15,18,,,,,1.29,0.97,0.86*00"],
84
+ gsv: [
85
+ "$GPGSV,3,1,11,24,70,198,52,15,63,016,,50,47,156,38,21,44,270,39*78",
86
+ "$GPGSV,3,2,11,18,40,314,30,26,27,058,46,05,19,124,42,12,09,159,35*73",
87
+ "$GPGSV,3,3,11,13,07,067,35,28,07,041,15,22,05,309,28*42",
88
+ ],
89
+ rmc: ["$GPRMC,075333.000,A,3539.51480,N,13944.72598,E,32.84,151.55,171214,,,A*68"],
90
+ vtg: ["$GPVTG,93.98,T,,M,32.84,N,60.85,K,D*05"],
91
+ zda: ["$GPZDA,075936.000,17,12,2014,,*5A"],
92
+ })
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ describe "callback!" do
99
+ before do
100
+ allow(gps).to receive(:line_set).and_return(
101
+ {
102
+ gga: ["$GPGGA,075800.000,3357.7401,N,13112.3701,E,2,9,1.04,-3.6,M,27.5,M,0000,0000*74"],
103
+ gsv: [
104
+ "$GPGSV,3,1,11,24,70,198,52,15,63,016,,50,47,156,38,21,44,270,39*78",
105
+ "$GPGSV,3,2,11,18,40,314,30,26,27,058,46,05,19,124,42,12,09,159,35*73",
106
+ "$GPGSV,3,3,11,13,07,067,35,28,07,041,15,22,05,309,28*42",
107
+ ],
108
+ }
109
+ )
110
+ end
111
+
112
+ it "single line callback" do
113
+ gps.gga do |gga|
114
+ expect(gga.class).to eq Nmea::Gps::Gga
115
+ end
116
+ gps.send :callback!
117
+ end
118
+
119
+ it "multiple line callback" do
120
+ gps.gsv do |gsvs|
121
+ expect(gsvs.count).to eq 3
122
+ expect(gsvs.first.class).to eq Nmea::Gps::Gsv
123
+ end
124
+ gps.send :callback!
125
+ end
126
+ end
127
+
128
+ describe "kill!" do
129
+ before do
130
+ thread = double("thread")
131
+ expect(thread).to receive(:kill).at_least(1)
132
+ gps.instance_eval{ self.track_thread = thread }
133
+ end
134
+
135
+ it{ gps.stop! }
136
+ end
137
+
138
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentence_base'
3
+
4
+ describe Nmea::Gps::SentenceBase do
5
+ let(:line){ "" }
6
+ subject{ Nmea::Gps::SentenceBase.new line }
7
+
8
+ describe "initialize" do
9
+ let(:line){ "line" }
10
+ it{ expect(subject.instance_eval{@line}).to eq line }
11
+ end
12
+
13
+ describe "name" do
14
+ it{ expect{ subject.name }.to raise_error }
15
+ end
16
+
17
+ describe "raw_data" do
18
+ let(:line){ "$GPNAME,#{(0..9).to_a.join(",")}*sum" }
19
+
20
+ it{ expect(subject.raw_data.first).to eq "0" }
21
+ it{ expect(subject.raw_data.last).to eq "9" }
22
+ end
23
+
24
+
25
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/gga'
3
+
4
+ describe Nmea::Gps::Gga do
5
+ let(:line){ "$GPGGA,075247.000,3539.51480,N,13944.72598,E,1,8,0.97,-15.6,M,27.5,M,13,X*44" }
6
+ subject{ Nmea::Gps::Gga.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "Global positioning system fixed data" }
10
+ end
11
+
12
+ describe "time" do
13
+ # 2014/01/01 0:00:00
14
+ before{ Timecop.freeze Time.zone.at(TIMECOP_2014_01_01__0_00_00) }
15
+ after{ Timecop.return }
16
+
17
+ it{ expect(subject.time).to eq Time.zone.parse("2014/01/01 07:52:47") }
18
+ it{ expect(subject.time.zone).to eq "UTC" }
19
+ end
20
+
21
+ describe "latitude" do
22
+ it{ expect(subject.latitude).to eq 35.65858 }
23
+ end
24
+
25
+ describe "longitude" do
26
+ it{ expect(subject.longitude).to eq 139.74543299999996 }
27
+ end
28
+
29
+ describe "quality" do
30
+ it{ expect(subject.quality).to eq :gps_sps_fix }
31
+ end
32
+
33
+ describe "number_of_satellites" do
34
+ it{ expect(subject.number_of_satellites).to eq 8 }
35
+ end
36
+
37
+ describe "horizontal_dilution_of_precision" do
38
+ it{ expect(subject.horizontal_dilution_of_precision).to eq 0.97 }
39
+ end
40
+
41
+ describe "altitude_in_meters" do
42
+ it{ expect(subject.altitude_in_meters).to eq -15.6 }
43
+ end
44
+
45
+ describe "height_of_geoid_above_wgs84_ellipsoid" do
46
+ it{ expect(subject.height_of_geoid_above_wgs84_ellipsoid).to eq 27.5 }
47
+ end
48
+
49
+ describe "time_in_seconds_since_last_dgps_update" do
50
+ it{ expect(subject.time_in_seconds_since_last_dgps_update).to eq 13 }
51
+ end
52
+
53
+ describe "dgps_station_id" do
54
+ it{ expect(subject.dgps_station_id).to eq "X" }
55
+ end
56
+
57
+
58
+
59
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/gll'
3
+
4
+ describe Nmea::Gps::Gll do
5
+ let(:line){ "$GPGLL,3539.51480,N,13944.72598,E,075247.000,A,A*5D" }
6
+ subject{ Nmea::Gps::Gll.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "Geographic position—latitude/longitude" }
10
+ end
11
+
12
+ describe "latitude" do
13
+ it{ expect(subject.latitude).to eq 35.65858 }
14
+ end
15
+
16
+ describe "longitude" do
17
+ it{ expect(subject.longitude).to eq 139.74543299999996 }
18
+ end
19
+
20
+ describe "time" do
21
+ # 2014/01/01 0:00:00
22
+ before{ Timecop.freeze Time.zone.at(TIMECOP_2014_01_01__0_00_00) }
23
+ after{ Timecop.return }
24
+
25
+ it{ expect(subject.time).to eq Time.zone.parse("2014/01/01 07:52:47") }
26
+ it{ expect(subject.time.zone).to eq "UTC" }
27
+ end
28
+
29
+ describe "status" do
30
+ it{ expect(subject.status).to eq :valid }
31
+ end
32
+
33
+ describe "mode" do
34
+ it{ expect(subject.mode).to eq :autonomous }
35
+ end
36
+
37
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/gsa'
3
+
4
+ describe Nmea::Gps::Gsa do
5
+ let(:line){ "$GPGSA,A,3,24,26,05,13,21,12,15,18,,,,,1.29,0.97,0.86*00" }
6
+ subject{ Nmea::Gps::Gsa.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "GNSS DOP and active satellites" }
10
+ end
11
+
12
+ describe "mode_selection" do
13
+ it{ expect(subject.mode_selection).to eq :automatic }
14
+ end
15
+
16
+ describe "mode" do
17
+ it{ expect(subject.mode).to eq :fix_3D }
18
+ end
19
+
20
+ describe "ids_of_svs_used_in_position_fix" do
21
+ let(:at){ :all }
22
+ context "all" do
23
+ it{ expect(subject.ids_of_svs_used_in_position_fix.count).to eq 12 }
24
+ end
25
+
26
+ context "a position" do
27
+ it{ expect(subject.ids_of_svs_used_in_position_fix(3)).to eq 5 }
28
+ it{ expect(subject.ids_of_svs_used_in_position_fix(12)).to eq nil }
29
+ end
30
+ end
31
+
32
+ describe "position_dilution_of_precision" do
33
+ it{ expect(subject.position_dilution_of_precision).to eq 1.29 }
34
+ end
35
+
36
+ describe "horizontal_dilution_of_precision" do
37
+ it{ expect(subject.horizontal_dilution_of_precision).to eq 0.97 }
38
+ end
39
+
40
+ describe "vertical_dilution_of_precision" do
41
+ it{ expect(subject.vertical_dilution_of_precision).to eq 0.86 }
42
+ end
43
+
44
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/gsv'
3
+
4
+ describe Nmea::Gps::Gsv do
5
+ let(:line){ "$GPGSV,3,1,11,24,70,198,52,15,63,016,32,50,47,156,39,21,44,270,38*79" }
6
+ subject{ Nmea::Gps::Gsv.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "GNSS satellites in view" }
10
+ end
11
+
12
+ describe "number_of_message" do
13
+ it{ expect(subject.number_of_message).to eq 3 }
14
+ end
15
+
16
+ describe "message_number" do
17
+ it{ expect(subject.message_number).to eq 1 }
18
+ end
19
+
20
+ describe "number_of_satellites_in_view" do
21
+ it{ expect(subject.number_of_satellites_in_view).to eq 11 }
22
+ end
23
+
24
+ describe "satellites" do
25
+ it{ expect(subject.satellites.count).to eq 4 }
26
+
27
+ context "first satellite" do
28
+ let(:satellite){ subject.satellites.first }
29
+ it{ expect(satellite.id).to eq 24 }
30
+ it{ expect(satellite.elevation).to eq 70 }
31
+ it{ expect(satellite.azinmuth).to eq 198 }
32
+ it{ expect(satellite.signal_to_noise_ratio).to eq 52 }
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/rmc'
3
+
4
+ describe Nmea::Gps::Rmc do
5
+ let(:line){ "$GPRMC,075333.000,A,3539.51480,N,13944.72598,E,32.84,151.55,171214,,,A*68" }
6
+ subject{ Nmea::Gps::Rmc.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "Recommended minimum specific GNSS data" }
10
+ end
11
+
12
+ describe "time" do
13
+ # 2014/01/01 0:00:00
14
+ before{ Timecop.freeze Time.zone.at(TIMECOP_2014_01_01__0_00_00) }
15
+ after{ Timecop.return }
16
+
17
+ it{ expect(subject.time).to eq Time.zone.parse("2014/01/01 07:53:33") }
18
+ it{ expect(subject.time.zone).to eq "UTC" }
19
+ end
20
+
21
+ describe "status" do
22
+ it{ expect(subject.status).to eq :valid }
23
+ end
24
+
25
+ describe "latitude" do
26
+ it{ expect(subject.latitude).to eq 35.65858 }
27
+ end
28
+
29
+ describe "longitude" do
30
+ it{ expect(subject.longitude).to eq 139.74543299999996 }
31
+ end
32
+
33
+ describe "knot_per_hour" do
34
+ it{ expect(subject.knot_per_hour).to eq 32.84}
35
+ end
36
+
37
+ describe "km_per_hour" do
38
+ it{ expect(subject.km_per_hour).to eq(32.84 * 1.85200) }
39
+ end
40
+
41
+ describe "heading" do
42
+ it{ expect(subject.heading).to eq 151.55 }
43
+ end
44
+
45
+ describe "date" do
46
+ it{ expect(subject.date).to eq Date.parse("2014/12/17") }
47
+ end
48
+
49
+ describe "magnetic_variation" do
50
+ it{ expect(subject.magnetic_variation).to eq nil }
51
+ end
52
+
53
+ describe "magnetic_variation_direction" do
54
+ it{ expect(subject.magnetic_variation_direction).to eq nil }
55
+ end
56
+
57
+ describe "mode" do
58
+ it{ expect(subject.mode).to eq :autonomous }
59
+ end
60
+
61
+
62
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/vtg'
3
+
4
+ describe Nmea::Gps::Vtg do
5
+ let(:line){ "$GPVTG,93.98,T,,M,32.84,N,60.85,K,D*05" }
6
+ subject{ Nmea::Gps::Vtg.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "Course over ground and ground speed" }
10
+ end
11
+
12
+ describe "true_course" do
13
+ it{ expect(subject.true_course).to eq 93.98 }
14
+ end
15
+
16
+ describe "magnetic_course" do
17
+ it{ expect(subject.magnetic_course).to eq nil }
18
+ end
19
+
20
+ describe "knot_per_hour" do
21
+ it{ expect(subject.knot_per_hour).to eq 32.84 }
22
+ end
23
+
24
+ describe "km_per_hour" do
25
+ it{ expect(subject.km_per_hour).to eq 60.85 }
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/sentences/zda'
3
+
4
+ describe Nmea::Gps::Zda do
5
+ let(:line){ "$GPZDA,075936.000,17,12,2014,,*5A" }
6
+ subject{ Nmea::Gps::Zda.new line }
7
+
8
+ describe "name" do
9
+ it{ expect(subject.name).to eq "Date and Time" }
10
+ end
11
+
12
+ describe "time" do
13
+ # 2014/01/01 0:00:00
14
+ before{ Timecop.freeze Time.zone.at(TIMECOP_2014_01_01__0_00_00) }
15
+ after{ Timecop.return }
16
+
17
+ it{ expect(subject.time).to eq Time.zone.parse("2014/01/01 07:59:36") }
18
+ it{ expect(subject.time.zone).to eq "UTC" }
19
+ end
20
+
21
+ describe "date" do
22
+ it{ expect(subject.date).to eq Date.parse("2014/12/17") }
23
+ end
24
+
25
+ describe "local_zone_hours" do
26
+ it{ expect(subject.local_zone_hours).to eq nil }
27
+ end
28
+
29
+ describe "local_zone_minutes" do
30
+ it{ expect(subject.local_zone_minutes).to eq nil }
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe NmeaGps do
4
+ it 'has a version number' do
5
+ expect(NmeaGps::VERSION).not_to be nil
6
+ end
7
+
8
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'factory_girl'
3
+ require 'timecop'
4
+ require 'nmea_gps'
5
+
6
+ TIMECOP_2014_01_01__0_00_00 = 1388534400
7
+
8
+ RSpec.configure do |config|
9
+ config.include FactoryGirl::Syntax::Methods
10
+ # config.filter_run :focus
11
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'nmea_gps/gps'
3
+
4
+ describe Nmea::UtcTimeable do
5
+ class Target
6
+ include Nmea::UtcTimeable
7
+ end
8
+
9
+ subject{ Target.new }
10
+
11
+ describe "hhmmss_to_local_time" do
12
+ let(:text){ "101112.000" }
13
+
14
+ # 2014/01/01 0:00:00
15
+ before{ Timecop.freeze Time.zone.at(TIMECOP_2014_01_01__0_00_00) }
16
+ after{ Timecop.return }
17
+
18
+ context "when Nmea::Config.time_zone is nil" do
19
+ let(:time){ subject.send :hhmmss_to_local_time, text }
20
+ it{ expect(time).to eq Time.zone.parse("2014/01/01 10:11:12") }
21
+ it{ expect(time.zone).to eq "UTC" }
22
+
23
+ context "when 'Tokyo'" do
24
+ before{ Nmea::Config.time_zone = "Tokyo" }
25
+ it{ expect(time).to eq Time.zone.parse("2014/01/01 10:11:12").in_time_zone "Tokyo" }
26
+ it{ expect(time.zone).to eq "JST" }
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end