gpsd_baud_rate 0.1.4 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acdc0604312e1797841f53b9925306879c7033d06c66121669e34427f78d8e42
4
- data.tar.gz: 2fb9cfbfa998def80fdd4adfa08a3e0970ae43bb76b3231fb26bdb73c015233d
3
+ metadata.gz: 88fae926e75b2a9b416f0c094bb90ea1ddf1bf7420df48cbcdccb5c4827346b5
4
+ data.tar.gz: 760d0ebc840be57fdd60ef7b9f838512b575d69a9a8b64dae1e00d83060803bb
5
5
  SHA512:
6
- metadata.gz: bf0297ffc543ce07e7c3553ba421680aa0029933e4d27141a913e16cd55e200aae28aed51f2058a48ba601ecc52ec9538efa32edc255c094fab855a9c7bc01a6
7
- data.tar.gz: 11a1a01b429f81a75ae24f8eeeba8fd863d9ac5cfc4b98423ed6e98e739651c6a02f957b789e882024c029bfaa113b568d08995cea6f5a1eca5eb921024807e8
6
+ metadata.gz: 2941c465784ac13a43a2096560a38e3f3a712ffa228872b13bc0b520c2bcb92d67aa04f3b924abdce7e6360dd6aabb95e5a3f17283655c059692dd46fafac19a
7
+ data.tar.gz: 4ee4cd934585921cff5d23bbe7fba21c93eb8a559f03c580685c83bdfe1eb4252301ff3a2082464633ce3f8b5b85db6e7f4b6ed96a97c177e4c86ce14eb1a69d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpsd_baud_rate (0.1.4)
4
+ gpsd_baud_rate (0.1.5)
5
5
  serialport (~> 1.3)
6
6
 
7
7
  GEM
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "bundler", "~> 1.17"
40
40
  spec.add_development_dependency "rake", "~> 10.0"
41
41
 
42
- spec.add_dependency 'serialport', '~> 1.3'
42
+ spec.add_dependency 'serialport', '>= 1.3.1'
43
43
 
44
44
  # spec.add_development_dependency "rspec", "~> 3.2"
45
45
  end
@@ -1,12 +1,12 @@
1
1
  require "gpsd_baud_rate/version"
2
2
  require "serialport"
3
+ require 'logger'
3
4
 
4
5
 
5
6
  class GpsdBaudRate
6
7
  attr_reader :version
7
8
 
8
- @@logger ||= defined?(Rails.logger) ? Rails.logger : Logger.new(STDOUT)
9
- @@version =GpsdBaudRate::VERSION
9
+ @@version = GpsdBaudRate::VERSION.to_s
10
10
 
11
11
  @@device = '/dev/ttyAMA0'
12
12
  @@service = 'gpsd.service'
@@ -17,59 +17,71 @@ class GpsdBaudRate
17
17
 
18
18
  def initialize goal_rate = @@baud_rates[0]
19
19
 
20
- # puts "\n\n\n"
20
+ @logger = new_logger path: "log/GpsdBaudRate.log", progname: "GpsdBaudRate", time_format: "'%Y-%m-%d %T.%N %z %Z'", level: Logger::DEBUG
21
+ @logger.info "GpsdBaudRate Gem - Version: #{@@version}"
21
22
 
23
+ if check_device?
24
+ @logger.info "Device: #{@@device} not found"
25
+ raise StandardError.new "Device #{@@device} not found"
26
+ else
27
+ @logger.info "Device: #{@@device} Okay"
28
+ end
22
29
  # pid= %x|pgrep -f "ruby /home/deploy/bin/set_baud.rb"|
23
- # puts "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
24
-
30
+ # @logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
31
+ =begin
25
32
  @goal_rate = goal_rate.to_i
26
- @@logger.debug "Hello from gpsd_baud_rate!"
27
- @@logger.debug "Goal_rate: #{@goal_rate}"
33
+ @logger.debug "Goal_rate: #{@goal_rate}"
34
+
28
35
 
29
- =begin
30
36
  gpsd_start unless gpsd_active? #make sure it's running
31
37
 
32
- puts "Service Status: #{gpsd_active?}"
33
- puts "Baud Rate: #{@active_rate = baud_rate}"
38
+ @logger.debug "Service Status: #{gpsd_active?}"
39
+ @logger.debug "Baud Rate: #{@active_rate = baud_rate}"
34
40
  gpsd_stop
35
- puts "Service Status: #{gpsd_active?}"
36
- puts "Baud Rate: #{@inactive_rate = baud_rate}"
41
+ @logger.debug "Service Status: #{gpsd_active?}"
42
+ @logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
37
43
 
38
- puts "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
44
+ @logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
39
45
  if (read_from_device @active_rate) && (@active_rate != @goal_rate)
40
- puts "Setting Goal Rate (#{goal_rate})"
46
+ @logger.debug "Setting Goal Rate (#{goal_rate})"
41
47
  set_PMTK_baud_rate @goal_rate
42
48
  if read_from_device @goal_rate
43
- puts "Goal Baud Rate (#{@goal_rate}) has been set"
49
+ @logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
44
50
  end
45
51
  else
46
- puts "Already at Goal Baud Rate"
52
+ @logger.debug "Already at Goal Baud Rate"
47
53
  end
48
54
 
49
55
 
50
56
  #
51
57
  # Cleanup
52
58
  gpsd_start
53
- puts "Service Status: #{gpsd_active?}"
59
+ @logger.debug "Service Status: #{gpsd_active?}"
54
60
  =end
55
61
  end #initiallize
56
62
 
57
- #~~~~~~~~~~~~~~~~~~~~~ gosd_status ~~~~~~~~~~~~~~~~~
63
+ #~~~~~~~~~~~~~~~~~~~~~ gpsd_status ~~~~~~~~~~~~~~~~~
64
+
65
+ def self.check_device?
66
+ # Does the @@device exist and is it a character device
67
+ 0 = %x| test -c "#{@@device}" ; echo $?|
58
68
 
59
- def gpsd_active?
69
+ end
70
+
71
+ def self.gpsd_active?
60
72
  arry = %x|sudo systemctl status "#{@@socket}"|.split(/\n/)
61
73
  s = arry.select!{ |e| e.include? "Active:"}[0].split(/\W+/)[2]
62
74
  s == 'active'
63
75
  end
64
76
 
65
- def gpsd_stop
77
+ def self.gpsd_stop
66
78
  %x|sudo systemctl stop "#{@@socket}"|
67
79
  %x|sudo systemctl stop "#{@@service}"|
68
80
  sleep 1
69
81
  %x|sudo systemctl daemon-reload|
70
82
  end
71
83
 
72
- def gpsd_start
84
+ def self.gpsd_start
73
85
  %x|sudo systemctl start "#{@@service}"|
74
86
  %x|sudo systemctl start "#{@@socket}"|
75
87
  sleep 1
@@ -78,7 +90,7 @@ class GpsdBaudRate
78
90
 
79
91
  #~~~~~~~~~~~~~~~~~~~~~~~~ baud rate ~~~~~~~~~~~~~~~~~~~
80
92
 
81
- def baud_rate
93
+ def self.baud_rate
82
94
  %x| sudo stty -F "#{@@device}"|.split('; ')[0].split(/\W+/)[1].to_i
83
95
  end
84
96
 
@@ -89,7 +101,7 @@ class GpsdBaudRate
89
101
  # returns original baud_rate
90
102
  def baud_rate=( b_rate)
91
103
  msg= %x| sudo stty #{b_rate} -F "#{@@device}"|
92
- msg.each {|m| puts m}
104
+ msg.each {|m| @logger.debug m}
93
105
  end
94
106
 
95
107
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -111,20 +123,20 @@ class GpsdBaudRate
111
123
  count = 0
112
124
  ser = SerialPort.open(@@device, baud.to_i, 8, 1, SerialPort::NONE ) { |ser|
113
125
  ser.read_timeout = 900
114
- puts "ReadTimeout: #{ser.read_timeout} ms"
126
+ @logger.debug "ReadTimeout: #{ser.read_timeout} ms"
115
127
  5.times { results << ser.readline(100)}
116
- results.each { |s| puts s}
128
+ results.each { |s| @logger.debug s}
117
129
  results.each do |r|
118
130
  count += 1 if @@NMEA_sentences.any? { |s| s == r[0,6]}
119
131
  end
120
- puts "Count: #{count}"
132
+ @logger.debug "Count: #{count}"
121
133
  }
122
134
  rescue IOError => e
123
- puts "IOError: #{e.inspect}"
135
+ @logger.debug "IOError: #{e.inspect}"
124
136
  rescue => e
125
- puts "Error: #{e.inspect}"
137
+ @logger.debug "Error: #{e.inspect}"
126
138
  end
127
- puts "SerialPort Closed"
139
+ @logger.debug "SerialPort Closed"
128
140
  gpsd_start
129
141
  count >= 2
130
142
  end
@@ -134,55 +146,68 @@ class GpsdBaudRate
134
146
  results=[]
135
147
 
136
148
  begin
137
- puts "Send to device"
149
+ @logger.debug "Send to device"
138
150
  ser = SerialPort.open( @@device, baud, 8, 1, SerialPort::NONE) { |ser|
139
151
  count = ser.write cmmd+"\r\n"
140
152
  }
141
153
  rescue IOError => e
142
- puts "IOError: #{e.inspect}"
154
+ @logger.debug "IOError: #{e.inspect}"
143
155
  rescue => e
144
- puts "Error: #{e.inspect}"
156
+ @logger.debug "Error: #{e.inspect}"
145
157
  end
146
- puts "Bytes Written: #{count}"
158
+ @logger.debug "Bytes Written: #{count}"
147
159
 
148
160
  begin
149
- puts "Receive response"
161
+ @logger.debug "Receive response"
150
162
  ser = SerialPort.open( @@device, @goal_rate, 8, 1, SerialPort::NONE) { |ser|
151
163
  ser.read_timeout = 900
152
164
  10.times {results << ser.readline(100)}
153
165
  }
154
166
  rescue IOError => e
155
- puts "IOError: #{e.inspect}"
167
+ @logger.debug "IOError: #{e.inspect}"
156
168
  rescue => e
157
- puts "Error: #{e.inspect}"
169
+ @logger.debug "Error: #{e.inspect}"
158
170
  end
159
- results.each { |r| puts "Results: #{r}"}
171
+ results.each { |r| @logger.debug "Results: #{r}"}
160
172
 
161
173
  end
162
174
 
163
175
 
164
176
  def find_baud_rate
165
- puts %x| sudo stty -F "#{@@device}"|
177
+ @logger.debug %x| sudo stty -F "#{@@device}"|
166
178
  gpsd_stop
167
- puts %x|sudo stty -F "#{@@device}"|
179
+ @logger.debug %x|sudo stty -F "#{@@device}"|
168
180
  gpsd_start
169
181
  end
170
182
 
171
183
  def set_PMTK_baud_rate rate
172
- puts "In set_PMTK_baud_rate"
184
+ @logger.debug "In set_PMTK_baud_rate"
173
185
  type = 251
174
186
  cmmd = nmea_checksum("PMTK#{type},#{rate}")
175
187
  write_to_device cmmd, @active_rate
176
188
  end
177
189
 
178
190
  def nmea_checksum cmmd
179
- puts "In nmea_checksum, cmmd: #{cmmd}"
191
+ @logger.debug "In nmea_checksum, cmmd: #{cmmd}"
180
192
  sum=0
181
193
  cmmd.each_byte { |i| sum = sum ^ i.ord}
182
194
  sum = sum & 0xff
183
195
  new_cmmd = "\$#{cmmd}*#{sum.to_s(16)}".upcase
184
- puts "new_cmmd: #{new_cmmd}"
196
+ @logger.debug "new_cmmd: #{new_cmmd}"
185
197
  new_cmmd
186
198
  end
187
199
 
200
+ LOG_LEVELS = {debug: Logger::DEBUG, info: Logger::INFO, warn: Logger::WARN,
201
+ error: Logger::ERROR, fatal: Logger::FATAL, unknown: Logger::UNKNOWN}
202
+
203
+ def new_logger( progname: nil, path:, format: nil, time_format: nil, level: LOG_LEVELS[:debug])
204
+ logger = Logger.new(path)
205
+ logger.progname = progname if progname
206
+ logger.format = format if format
207
+ logger.level = level if level
208
+ logger.datetime_format = time_format if time_format
209
+ logger
210
+ end
211
+
212
+
188
213
  end
@@ -1,3 +1,3 @@
1
1
  class GpsdBaudRate
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpsd_baud_rate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Finnegan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-24 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: serialport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: 1.3.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: 1.3.1
55
55
  description:
56
56
  email:
57
57
  - steven@rustyshamrock.com