gpsd_baud_rate 0.1.5 → 0.1.6

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: 16dfe1b4f78b68d169e579548fc6fece7cd65dbbd1114f70865af22069418887
4
- data.tar.gz: 90a67d3bc104cd38623b856e05d3585e5ef4272de86b3a7aafcc7ebf01b5b166
3
+ metadata.gz: 96a00a30d7ff931c648e4d127ae5f253f9bf328d376e96e6f32650082b306ba4
4
+ data.tar.gz: 8549c6d82accb16822416fa8a57f4be95348e90a0c50ed894e3474ebe0e4bf15
5
5
  SHA512:
6
- metadata.gz: 44c84a67ac0ab6f83ed61c3bf1cc75fac39ee958707b8e763ccb6cffa493a2535db77a2646457447eceb1adf97be7f605fa59449c666d729cc6ac752ef04b36d
7
- data.tar.gz: 001663ed32e69d5d9353de94faa783ef307d0b3b60d695117df7e3de85052944c61b4b590c8d3ebb4febdde8a2dbce5a482ee02f1016132779578dbe43768b06
6
+ metadata.gz: 3bc5af12c004b9d533d006409977064bf0b888c6dd0d09cb57b92d7e3bb2f64a0f5debfcc9d52b227ce4a5a7a9b7beedb299cb7f859723993dc0344216a67cae
7
+ data.tar.gz: 2947d2490fde65c8d28ec4cf2739dcd90a5965e671fb9cf4d1109e8becb50dcdef91646322f939802ddaab0a2480e06c645dbae4ab4b32e3e9830ca3cc1b7796
@@ -6,7 +6,6 @@ require 'logger'
6
6
  class GpsdBaudRate
7
7
  attr_reader :version
8
8
 
9
- @@logger ||= defined?(Rails.logger) ? Rails.logger : Logger.new(STDOUT)
10
9
  @@version =GpsdBaudRate::VERSION
11
10
 
12
11
  @@device = '/dev/ttyAMA0'
@@ -18,40 +17,40 @@ class GpsdBaudRate
18
17
 
19
18
  def initialize goal_rate = @@baud_rates[0]
20
19
 
21
- # @@logger.debug "\n\n\n"
22
-
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}"
23
22
  # pid= %x|pgrep -f "ruby /home/deploy/bin/set_baud.rb"|
24
- # @@logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
23
+ # @logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
25
24
 
26
25
  @goal_rate = goal_rate.to_i
27
- @@logger.debug "Hello from gpsd_baud_rate!"
28
- @@logger.debug "Goal_rate: #{@goal_rate}"
26
+ @logger.debug "Hello from gpsd_baud_rate!"
27
+ @logger.debug "Goal_rate: #{@goal_rate}"
29
28
 
30
29
 
31
30
  gpsd_start unless gpsd_active? #make sure it's running
32
31
 
33
- @@logger.debug "Service Status: #{gpsd_active?}"
34
- @@logger.debug "Baud Rate: #{@active_rate = baud_rate}"
32
+ @logger.debug "Service Status: #{gpsd_active?}"
33
+ @logger.debug "Baud Rate: #{@active_rate = baud_rate}"
35
34
  gpsd_stop
36
- @@logger.debug "Service Status: #{gpsd_active?}"
37
- @@logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
35
+ @logger.debug "Service Status: #{gpsd_active?}"
36
+ @logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
38
37
 
39
- @@logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
38
+ @logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
40
39
  if (read_from_device @active_rate) && (@active_rate != @goal_rate)
41
- @@logger.debug "Setting Goal Rate (#{goal_rate})"
40
+ @logger.debug "Setting Goal Rate (#{goal_rate})"
42
41
  set_PMTK_baud_rate @goal_rate
43
42
  if read_from_device @goal_rate
44
- @@logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
43
+ @logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
45
44
  end
46
45
  else
47
- @@logger.debug "Already at Goal Baud Rate"
46
+ @logger.debug "Already at Goal Baud Rate"
48
47
  end
49
48
 
50
49
 
51
50
  #
52
51
  # Cleanup
53
52
  gpsd_start
54
- @@logger.debug "Service Status: #{gpsd_active?}"
53
+ @logger.debug "Service Status: #{gpsd_active?}"
55
54
  end #initiallize
56
55
 
57
56
  #~~~~~~~~~~~~~~~~~~~~~ gosd_status ~~~~~~~~~~~~~~~~~
@@ -89,7 +88,7 @@ class GpsdBaudRate
89
88
  # returns original baud_rate
90
89
  def baud_rate=( b_rate)
91
90
  msg= %x| sudo stty #{b_rate} -F "#{@@device}"|
92
- msg.each {|m| @@logger.debug m}
91
+ msg.each {|m| @logger.debug m}
93
92
  end
94
93
 
95
94
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -111,20 +110,20 @@ class GpsdBaudRate
111
110
  count = 0
112
111
  ser = SerialPort.open(@@device, baud.to_i, 8, 1, SerialPort::NONE ) { |ser|
113
112
  ser.read_timeout = 900
114
- @@logger.debug "ReadTimeout: #{ser.read_timeout} ms"
113
+ @logger.debug "ReadTimeout: #{ser.read_timeout} ms"
115
114
  5.times { results << ser.readline(100)}
116
- results.each { |s| @@logger.debug s}
115
+ results.each { |s| @logger.debug s}
117
116
  results.each do |r|
118
117
  count += 1 if @@NMEA_sentences.any? { |s| s == r[0,6]}
119
118
  end
120
- @@logger.debug "Count: #{count}"
119
+ @logger.debug "Count: #{count}"
121
120
  }
122
121
  rescue IOError => e
123
- @@logger.debug "IOError: #{e.inspect}"
122
+ @logger.debug "IOError: #{e.inspect}"
124
123
  rescue => e
125
- @@logger.debug "Error: #{e.inspect}"
124
+ @logger.debug "Error: #{e.inspect}"
126
125
  end
127
- @@logger.debug "SerialPort Closed"
126
+ @logger.debug "SerialPort Closed"
128
127
  gpsd_start
129
128
  count >= 2
130
129
  end
@@ -134,55 +133,68 @@ class GpsdBaudRate
134
133
  results=[]
135
134
 
136
135
  begin
137
- @@logger.debug "Send to device"
136
+ @logger.debug "Send to device"
138
137
  ser = SerialPort.open( @@device, baud, 8, 1, SerialPort::NONE) { |ser|
139
138
  count = ser.write cmmd+"\r\n"
140
139
  }
141
140
  rescue IOError => e
142
- @@logger.debug "IOError: #{e.inspect}"
141
+ @logger.debug "IOError: #{e.inspect}"
143
142
  rescue => e
144
- @@logger.debug "Error: #{e.inspect}"
143
+ @logger.debug "Error: #{e.inspect}"
145
144
  end
146
- @@logger.debug "Bytes Written: #{count}"
145
+ @logger.debug "Bytes Written: #{count}"
147
146
 
148
147
  begin
149
- @@logger.debug "Receive response"
148
+ @logger.debug "Receive response"
150
149
  ser = SerialPort.open( @@device, @goal_rate, 8, 1, SerialPort::NONE) { |ser|
151
150
  ser.read_timeout = 900
152
151
  10.times {results << ser.readline(100)}
153
152
  }
154
153
  rescue IOError => e
155
- @@logger.debug "IOError: #{e.inspect}"
154
+ @logger.debug "IOError: #{e.inspect}"
156
155
  rescue => e
157
- @@logger.debug "Error: #{e.inspect}"
156
+ @logger.debug "Error: #{e.inspect}"
158
157
  end
159
- results.each { |r| @@logger.debug "Results: #{r}"}
158
+ results.each { |r| @logger.debug "Results: #{r}"}
160
159
 
161
160
  end
162
161
 
163
162
 
164
163
  def find_baud_rate
165
- @@logger.debug %x| sudo stty -F "#{@@device}"|
164
+ @logger.debug %x| sudo stty -F "#{@@device}"|
166
165
  gpsd_stop
167
- @@logger.debug %x|sudo stty -F "#{@@device}"|
166
+ @logger.debug %x|sudo stty -F "#{@@device}"|
168
167
  gpsd_start
169
168
  end
170
169
 
171
170
  def set_PMTK_baud_rate rate
172
- @@logger.debug "In set_PMTK_baud_rate"
171
+ @logger.debug "In set_PMTK_baud_rate"
173
172
  type = 251
174
173
  cmmd = nmea_checksum("PMTK#{type},#{rate}")
175
174
  write_to_device cmmd, @active_rate
176
175
  end
177
176
 
178
177
  def nmea_checksum cmmd
179
- @@logger.debug "In nmea_checksum, cmmd: #{cmmd}"
178
+ @logger.debug "In nmea_checksum, cmmd: #{cmmd}"
180
179
  sum=0
181
180
  cmmd.each_byte { |i| sum = sum ^ i.ord}
182
181
  sum = sum & 0xff
183
182
  new_cmmd = "\$#{cmmd}*#{sum.to_s(16)}".upcase
184
- @@logger.debug "new_cmmd: #{new_cmmd}"
183
+ @logger.debug "new_cmmd: #{new_cmmd}"
185
184
  new_cmmd
186
185
  end
187
186
 
187
+ LOG_LEVELS = {debug: Logger::DEBUG, info: Logger::INFO, warn: Logger::WARN,
188
+ error: Logger::ERROR, fatal: Logger::FATAL, unknown: Logger::UNKNOWN}
189
+
190
+ def new_logger( progname: nil, path:, format: nil, time_format: nil, level: LOG_LEVELS[:debug])
191
+ logger = Logger.new(path)
192
+ logger.progname = progname if progname
193
+ logger.format = format if format
194
+ logger.level = level if level
195
+ logger.datetime_format = time_format if time_format
196
+ logger
197
+ end
198
+
199
+
188
200
  end
@@ -1,3 +1,3 @@
1
1
  class GpsdBaudRate
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
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.5
4
+ version: 0.1.6
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler