nmea_gps 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/lib/nmea_gps/gps.rb +19 -18
- data/lib/nmea_gps/sentence_base.rb +4 -6
- data/lib/nmea_gps/version.rb +1 -1
- data/spec/lib/nmea_gps/sentence_base_spec.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 186f2e292efec893a3cfb3790f00b763261cba01
|
4
|
+
data.tar.gz: a37fea6191d105c65f2087b5dac5ec4feaa3b585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 380861b8c6f53ae3fa3ab3a10e56d24bc915af6e0b55ce3fb7f0114330b105832c34a2b8c8347d5fc688ee19acfd6f5d44def03f8e166227f032e72a75723a24
|
7
|
+
data.tar.gz: 7b4e698131dc1a5b609dfa1be074e0a83c743f7f79e5a236c00265046a9196de30b025b1a2b755c21406ddd43f504f9b7d4e2c007e3334fa1410b831ed36faf4
|
data/README.md
CHANGED
@@ -37,6 +37,7 @@ gps = Nmea::Gps.new serialport update_hz: 10
|
|
37
37
|
gps.rmc do |rmc|
|
38
38
|
# you will get a sentence object as a parameter
|
39
39
|
# for gsv callback, it will be an array containing multiple gsv objects [gsv, gsv, gsv]
|
40
|
+
p rmc.raw_sentence_line
|
40
41
|
p rmc.time
|
41
42
|
p rmc.latitude
|
42
43
|
p rmc.longitude
|
@@ -52,6 +53,12 @@ gps.error do |exception|
|
|
52
53
|
puts exception.backtrace.join "\n"
|
53
54
|
end
|
54
55
|
|
56
|
+
# if you want to receive all ...
|
57
|
+
gps.all do |sentence, sentence_object|
|
58
|
+
p sentence # such as :gga, :rmc
|
59
|
+
p sentence_object # such as Nmea::Gps::Rmc, [Nmea::Gps::Gsv, Nmea::Gps::Gsv, ...]
|
60
|
+
end
|
61
|
+
|
55
62
|
# start the tracking
|
56
63
|
gps.track!
|
57
64
|
|
@@ -83,6 +90,16 @@ gps.track!
|
|
83
90
|
# ..
|
84
91
|
# ..
|
85
92
|
|
93
|
+
|
94
|
+
# you can clear callbacks on the run
|
95
|
+
gps.clear_rmc # this will stop the call instantly
|
96
|
+
|
97
|
+
|
98
|
+
# you can even start a callback on the run
|
99
|
+
gps.gga do |gga|
|
100
|
+
p [gga.latitude, gga.longitude]
|
101
|
+
end
|
102
|
+
|
86
103
|
# when you want to stop callbacks, you can call this
|
87
104
|
# gps.stop!
|
88
105
|
# then close the connection
|
@@ -92,6 +109,16 @@ gps.track!
|
|
92
109
|
## sentences
|
93
110
|
[click here](https://github.com/github0013/nmea_gps/tree/master/lib/nmea_gps/sentences) for details
|
94
111
|
|
112
|
+
| sentence | callback | parameter to be passed |
|
113
|
+
|:----|:----|:---------------|
|
114
|
+
| GGA | gga | Nmea::Gps::Gga |
|
115
|
+
| GLL | gll | Nmea::Gps::Gll |
|
116
|
+
| GSA | gsa | Nmea::Gps::Gsa |
|
117
|
+
| GSV | gsv | [Nmea::Gps::Gsv, Nmea::Gps::Gsv, ...] |
|
118
|
+
| RMC | rmc | Nmea::Gps::Rmc |
|
119
|
+
| VTG | vtg | Nmea::Gps::Vtg |
|
120
|
+
| ZDA | zda | Nmea::Gps::Zda |
|
121
|
+
|
95
122
|
## Contributing
|
96
123
|
|
97
124
|
1. Fork it ( https://github.com/[my-github-username]/nmea_gps/fork )
|
data/lib/nmea_gps/gps.rb
CHANGED
@@ -11,10 +11,14 @@ module Nmea
|
|
11
11
|
|
12
12
|
Dir[Pathname(__FILE__).join("../sentences/*.rb")].collect do |path|
|
13
13
|
Pathname(path).basename(".rb").to_s
|
14
|
-
end.tap{|array| array << "error" }.each do |sentence|
|
14
|
+
end.tap{|array| array << "error" << "all" }.each do |sentence|
|
15
15
|
define_method(sentence) do |&block|
|
16
16
|
self.callbacks[__callee__] = block
|
17
17
|
end
|
18
|
+
|
19
|
+
define_method("clear_#{sentence}") do
|
20
|
+
self.callbacks.delete(sentence.to_sym)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def track!
|
@@ -43,8 +47,8 @@ module Nmea
|
|
43
47
|
Hash.new{|hash, key| hash[key] = [] }.tap do |set|
|
44
48
|
catch(:done_one_cycle) do
|
45
49
|
loop do
|
46
|
-
ensure_sentence do |sentence,
|
47
|
-
set[sentence] <<
|
50
|
+
ensure_sentence do |sentence, raw_sentence_line|
|
51
|
+
set[sentence] << raw_sentence_line
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -54,46 +58,43 @@ module Nmea
|
|
54
58
|
def ensure_sentence
|
55
59
|
yield *@buffer if @buffer
|
56
60
|
|
57
|
-
|
61
|
+
raw_sentence_line = self.gps_serial_port.gets("\r\n").strip
|
58
62
|
# %w[ GLL RMC VTG GGA GSA GSV ZDA].join.chars.uniq.sort.join
|
59
|
-
return unless match =
|
63
|
+
return unless match = raw_sentence_line.match(/\A\$#{TALKER_ID}([ACDGLMRSTVZ]{3})/)
|
60
64
|
|
61
65
|
sentence = match[1].downcase.to_sym
|
62
66
|
if sentence == self.initial_sentence
|
63
|
-
@buffer = [sentence,
|
67
|
+
@buffer = [sentence, raw_sentence_line]
|
64
68
|
throw :done_one_cycle
|
65
69
|
end
|
66
70
|
|
67
|
-
yield sentence,
|
71
|
+
yield sentence, raw_sentence_line
|
68
72
|
|
69
73
|
self.initial_sentence ||= sentence unless sentence == :gsv
|
70
74
|
end
|
71
75
|
|
72
76
|
def callback!
|
73
|
-
|
74
|
-
this_set.keys.each do |sentence|
|
77
|
+
sentences_in_a_cycle.each do |sentence, raw_sentence_lines_in_array|
|
75
78
|
begin
|
76
|
-
this_callback = self.callbacks[sentence]
|
77
|
-
next unless this_callback
|
78
|
-
|
79
79
|
target_class = "Nmea::Gps::#{sentence.to_s.camelcase}".constantize
|
80
80
|
|
81
81
|
object = if sentence == :gsv
|
82
|
-
|
83
|
-
target_class.new
|
82
|
+
raw_sentence_lines_in_array.sort.collect do |raw_sentence|
|
83
|
+
target_class.new raw_sentence
|
84
84
|
end
|
85
85
|
else
|
86
|
-
target_class.new(
|
86
|
+
target_class.new(raw_sentence_lines_in_array.first)
|
87
87
|
end
|
88
88
|
|
89
|
-
|
89
|
+
self.callbacks[sentence].call object if self.callbacks[sentence]
|
90
|
+
self.callbacks[:all].call [sentence, object] if self.callbacks[:all]
|
90
91
|
rescue => ex
|
91
|
-
self.callbacks[:error].call ex
|
92
|
+
self.callbacks[:error].call ex if self.callbacks[:error]
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
96
|
rescue => ex
|
96
|
-
self.callbacks[:error].call ex
|
97
|
+
self.callbacks[:error].call ex if self.callbacks[:error]
|
97
98
|
end
|
98
99
|
|
99
100
|
|
@@ -15,9 +15,10 @@ module Nmea
|
|
15
15
|
"E" => :dr,
|
16
16
|
}
|
17
17
|
|
18
|
+
attr_reader :raw_sentence_line
|
18
19
|
|
19
|
-
def initialize(
|
20
|
-
@
|
20
|
+
def initialize(raw_sentence_line)
|
21
|
+
@raw_sentence_line = raw_sentence_line
|
21
22
|
end
|
22
23
|
|
23
24
|
def name
|
@@ -25,13 +26,10 @@ module Nmea
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def raw_data
|
28
|
-
_, *data = self.
|
29
|
+
_, *data = self.raw_sentence_line.split("*").first.split(",")
|
29
30
|
data
|
30
31
|
end
|
31
32
|
|
32
|
-
protected
|
33
|
-
attr_reader :line
|
34
|
-
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
data/lib/nmea_gps/version.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
require 'nmea_gps/sentence_base'
|
3
3
|
|
4
4
|
describe Nmea::Gps::SentenceBase do
|
5
|
-
let(:
|
6
|
-
subject{ Nmea::Gps::SentenceBase.new
|
5
|
+
let(:raw_sentence_line){ "" }
|
6
|
+
subject{ Nmea::Gps::SentenceBase.new raw_sentence_line }
|
7
7
|
|
8
8
|
describe "initialize" do
|
9
|
-
let(:
|
10
|
-
it{ expect(subject.
|
9
|
+
let(:raw_sentence_line){ "raw_sentence_line" }
|
10
|
+
it{ expect(subject.raw_sentence_line).to eq raw_sentence_line }
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "name" do
|
@@ -15,7 +15,7 @@ describe Nmea::Gps::SentenceBase do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "raw_data" do
|
18
|
-
let(:
|
18
|
+
let(:raw_sentence_line){ "$GPNAME,#{(0..9).to_a.join(",")}*sum" }
|
19
19
|
|
20
20
|
it{ expect(subject.raw_data.first).to eq "0" }
|
21
21
|
it{ expect(subject.raw_data.last).to eq "9" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nmea_gps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|