gpsd_baud_rate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/README.md +61 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gpsd_baud_rate.gemspec +45 -0
- data/lib/gpsd_baud_rate.rb +183 -0
- data/lib/gpsd_baud_rate/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 87ea6b8ae67812ee48b30268572ad436c970a9299c50f1f015b2a00854a9e3e3
|
4
|
+
data.tar.gz: 2acc850c4396e6c623c5526ed76660de71527c525cf274b32fdfd3a626b23f3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '043935e4c54b7c69e919c1eb80e137f0573bf2d8ae072d3b2c7289d73917125bcbeecb06e9ffb17d617311c855a64e8adcd517574d1f927052757da19069d2b6'
|
7
|
+
data.tar.gz: a66a87d325c14ebed352cf47aad2ff883a0343ac2094347f717c9cfd026dc0a70f33953387356a6387eff688ea0cab39130dcac6039479da67031fa62875e6ea
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gpsd_baud_rate (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.5.0)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
bundler (~> 1.17)
|
16
|
+
gpsd_baud_rate!
|
17
|
+
rake (~> 10.0)
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
1.17.3
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# GpsdBaudRate
|
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_baud_rate`. 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_baud_rate'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gpsd_baud_rate
|
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. You can also 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`, which will 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
|
+
## To build, load and run a gem (from my notes)
|
34
|
+
|
35
|
+
From the gem's main folder...
|
36
|
+
|
37
|
+
$ gem build gpsd_baud_rate.gemspec
|
38
|
+
$ gem install gpsd_baud_rate-[version].gem
|
39
|
+
|
40
|
+
sol:gpsd_baud_rate sjf$ irb
|
41
|
+
irb(main):001:0> require 'gpsd_baud_rate'
|
42
|
+
=> true
|
43
|
+
irb(main):002:0> gem = GpsdBaudRate.new
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
Goal_rate: 115200
|
48
|
+
=> #<GpsdBaudRate:0x00007f99ada66938 @version="0.1.0", @goal_rate=115200>
|
49
|
+
irb(main):003:0>
|
50
|
+
irb(main):003:0> gem.version
|
51
|
+
=> "0.1.0"
|
52
|
+
irb(main):004:0>
|
53
|
+
|
54
|
+
To release to rubygems.org...
|
55
|
+
|
56
|
+
$ rake build; rake release
|
57
|
+
gpsd_baud_rate 0.1.10 built to pkg/my_gpsd_client-0.1.0.gem.
|
58
|
+
gpsd_baud_rate 0.1.10 built to pkg/my_gpsd_client-0.1.0.gem.
|
59
|
+
Tagged v0.1.10.
|
60
|
+
Pushed git commits and tags.
|
61
|
+
Pushed gpsd_baud_rate 0.1.10 to https://rubygems.org
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gpsd_baud_rate"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gpsd_baud_rate/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gpsd_baud_rate"
|
8
|
+
spec.version = GpsdBaudRate::VERSION
|
9
|
+
spec.authors = ["Steven Finnegan"]
|
10
|
+
spec.email = ["steven@rustyshamrock.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem to control the baud rate used by gpsd to communicate with GPS module}
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/sjf-control/gpsd_baud_rate"
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
24
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
|
42
|
+
spec.add_dependency 'serialport', '~> 1.3'
|
43
|
+
|
44
|
+
# spec.add_development_dependency "rspec", "~> 3.2"
|
45
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require "gpsd_baud_rate/version"
|
2
|
+
require "serialport"
|
3
|
+
|
4
|
+
|
5
|
+
class GpsdBaudRate
|
6
|
+
attr_reader :version
|
7
|
+
|
8
|
+
|
9
|
+
@@device = '/dev/ttyAMA0'
|
10
|
+
@@service = 'gpsd.service'
|
11
|
+
@@socket = 'gpsd.socket'
|
12
|
+
|
13
|
+
@@baud_rates = %w[115200 57600 38400 19200 14400 9600 4800]
|
14
|
+
@@NMEA_sentences = %w[$GPGGA $GPGSA $GPGSV $GPRMC $GPZDA]
|
15
|
+
|
16
|
+
def initialize goal_rate = @@baud_rates[0]
|
17
|
+
@version =GpsdBaudRate::VERSION
|
18
|
+
|
19
|
+
puts "\n\n\n"
|
20
|
+
|
21
|
+
# pid= %x|pgrep -f "ruby /home/deploy/bin/set_baud.rb"|
|
22
|
+
# puts "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
|
23
|
+
|
24
|
+
@goal_rate = goal_rate.to_i
|
25
|
+
puts "Goal_rate: #{@goal_rate}"
|
26
|
+
=begin
|
27
|
+
gpsd_start unless gpsd_active? #make sure it's running
|
28
|
+
|
29
|
+
puts "Service Status: #{gpsd_active?}"
|
30
|
+
puts "Baud Rate: #{@active_rate = baud_rate}"
|
31
|
+
gpsd_stop
|
32
|
+
puts "Service Status: #{gpsd_active?}"
|
33
|
+
puts "Baud Rate: #{@inactive_rate = baud_rate}"
|
34
|
+
|
35
|
+
puts "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
|
36
|
+
if (read_from_device @active_rate) && (@active_rate != @goal_rate)
|
37
|
+
puts "Setting Goal Rate (#{goal_rate})"
|
38
|
+
set_PMTK_baud_rate @goal_rate
|
39
|
+
if read_from_device @goal_rate
|
40
|
+
puts "Goal Baud Rate (#{@goal_rate}) has been set"
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts "Already at Goal Baud Rate"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
#
|
48
|
+
# Cleanup
|
49
|
+
gpsd_start
|
50
|
+
puts "Service Status: #{gpsd_active?}"
|
51
|
+
=end
|
52
|
+
end #initiallize
|
53
|
+
|
54
|
+
#~~~~~~~~~~~~~~~~~~~~~ gosd_status ~~~~~~~~~~~~~~~~~
|
55
|
+
|
56
|
+
def gpsd_active?
|
57
|
+
arry = %x|sudo systemctl status "#{@@socket}"|.split(/\n/)
|
58
|
+
s = arry.select!{ |e| e.include? "Active:"}[0].split(/\W+/)[2]
|
59
|
+
s == 'active'
|
60
|
+
end
|
61
|
+
|
62
|
+
def gpsd_stop
|
63
|
+
%x|sudo systemctl stop "#{@@socket}"|
|
64
|
+
%x|sudo systemctl stop "#{@@service}"|
|
65
|
+
sleep 1
|
66
|
+
%x|sudo systemctl daemon-reload|
|
67
|
+
end
|
68
|
+
|
69
|
+
def gpsd_start
|
70
|
+
%x|sudo systemctl start "#{@@service}"|
|
71
|
+
%x|sudo systemctl start "#{@@socket}"|
|
72
|
+
sleep 1
|
73
|
+
%x|sudo systemctl daemon-reload|
|
74
|
+
end
|
75
|
+
|
76
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~ baud rate ~~~~~~~~~~~~~~~~~~~
|
77
|
+
|
78
|
+
def baud_rate
|
79
|
+
%x| sudo stty -F "#{@@device}"|.split('; ')[0].split(/\W+/)[1].to_i
|
80
|
+
end
|
81
|
+
|
82
|
+
def baud_rate?(b_rate)
|
83
|
+
b_rate==baud_rate
|
84
|
+
end
|
85
|
+
|
86
|
+
# returns original baud_rate
|
87
|
+
def baud_rate=( b_rate)
|
88
|
+
msg= %x| sudo stty #{b_rate} -F "#{@@device}"|
|
89
|
+
msg.each {|m| puts m}
|
90
|
+
end
|
91
|
+
|
92
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
93
|
+
|
94
|
+
def test_baud_rate b_rate
|
95
|
+
read_from_device b_rate
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# Attempts to read from serial port using the baud rate specified
|
100
|
+
# Will try to receive five 'lines' of text
|
101
|
+
# Expects to receive NMEA sentences
|
102
|
+
# Returns true if at least two of the received lines start with the NMEA
|
103
|
+
# '$GPxxx' sentence codes in @@NMEA_sentences
|
104
|
+
def read_from_device( baud)
|
105
|
+
begin
|
106
|
+
results = []
|
107
|
+
count = 0
|
108
|
+
ser = SerialPort.open(@@device, baud.to_i, 8, 1, SerialPort::NONE ) { |ser|
|
109
|
+
ser.read_timeout = 900
|
110
|
+
puts "ReadTimeout: #{ser.read_timeout} ms"
|
111
|
+
5.times { results << ser.readline(100)}
|
112
|
+
results.each { |s| puts s}
|
113
|
+
results.each do |r|
|
114
|
+
count += 1 if @@NMEA_sentences.any? { |s| s == r[0,6]}
|
115
|
+
end
|
116
|
+
puts "Count: #{count}"
|
117
|
+
}
|
118
|
+
rescue IOError => e
|
119
|
+
puts "IOError: #{e.inspect}"
|
120
|
+
rescue => e
|
121
|
+
puts "Error: #{e.inspect}"
|
122
|
+
end
|
123
|
+
puts "SerialPort Closed"
|
124
|
+
count >= 2
|
125
|
+
end
|
126
|
+
|
127
|
+
def write_to_device cmmd, baud
|
128
|
+
count=0
|
129
|
+
results=[]
|
130
|
+
|
131
|
+
begin
|
132
|
+
puts "Send to device"
|
133
|
+
ser = SerialPort.open( @@device, baud, 8, 1, SerialPort::NONE) { |ser|
|
134
|
+
count = ser.write cmmd+"\r\n"
|
135
|
+
}
|
136
|
+
rescue IOError => e
|
137
|
+
puts "IOError: #{e.inspect}"
|
138
|
+
rescue => e
|
139
|
+
puts "Error: #{e.inspect}"
|
140
|
+
end
|
141
|
+
puts "Bytes Written: #{count}"
|
142
|
+
|
143
|
+
begin
|
144
|
+
puts "Receive response"
|
145
|
+
ser = SerialPort.open( @@device, @goal_rate, 8, 1, SerialPort::NONE) { |ser|
|
146
|
+
ser.read_timeout = 900
|
147
|
+
10.times {results << ser.readline(100)}
|
148
|
+
}
|
149
|
+
rescue IOError => e
|
150
|
+
puts "IOError: #{e.inspect}"
|
151
|
+
rescue => e
|
152
|
+
puts "Error: #{e.inspect}"
|
153
|
+
end
|
154
|
+
results.each { |r| puts "Results: #{r}"}
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def find_baud_rate
|
160
|
+
puts %x| sudo stty -F "#{@@device}"|
|
161
|
+
gpsd_stop
|
162
|
+
puts %x|sudo stty -F "#{@@device}"|
|
163
|
+
gpsd_start
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_PMTK_baud_rate rate
|
167
|
+
puts "In set_PMTK_baud_rate"
|
168
|
+
type = 251
|
169
|
+
cmmd = nmea_checksum("PMTK#{type},#{rate}")
|
170
|
+
write_to_device cmmd, @active_rate
|
171
|
+
end
|
172
|
+
|
173
|
+
def nmea_checksum cmmd
|
174
|
+
puts "In nmea_checksum, cmmd: #{cmmd}"
|
175
|
+
sum=0
|
176
|
+
cmmd.each_byte { |i| sum = sum ^ i.ord}
|
177
|
+
sum = sum & 0xff
|
178
|
+
new_cmmd = "\$#{cmmd}*#{sum.to_s(16)}".upcase
|
179
|
+
puts "new_cmmd: #{new_cmmd}"
|
180
|
+
new_cmmd
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpsd_baud_rate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Finnegan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: serialport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- steven@rustyshamrock.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- gpsd_baud_rate.gemspec
|
70
|
+
- lib/gpsd_baud_rate.rb
|
71
|
+
- lib/gpsd_baud_rate/version.rb
|
72
|
+
homepage: https://github.com/sjf-control/gpsd_baud_rate
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
allowed_push_host: https://rubygems.org
|
77
|
+
homepage_uri: https://github.com/sjf-control/gpsd_baud_rate
|
78
|
+
source_code_uri: https://github.com/sjf-control/gpsd_baud_rate
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.0.4
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Gem to control the baud rate used by gpsd to communicate with GPS module
|
98
|
+
test_files: []
|