gpsd_baud_rate 0.1.0 → 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: 87ea6b8ae67812ee48b30268572ad436c970a9299c50f1f015b2a00854a9e3e3
4
- data.tar.gz: 2acc850c4396e6c623c5526ed76660de71527c525cf274b32fdfd3a626b23f3f
3
+ metadata.gz: 96a00a30d7ff931c648e4d127ae5f253f9bf328d376e96e6f32650082b306ba4
4
+ data.tar.gz: 8549c6d82accb16822416fa8a57f4be95348e90a0c50ed894e3474ebe0e4bf15
5
5
  SHA512:
6
- metadata.gz: '043935e4c54b7c69e919c1eb80e137f0573bf2d8ae072d3b2c7289d73917125bcbeecb06e9ffb17d617311c855a64e8adcd517574d1f927052757da19069d2b6'
7
- data.tar.gz: a66a87d325c14ebed352cf47aad2ff883a0343ac2094347f717c9cfd026dc0a70f33953387356a6387eff688ea0cab39130dcac6039479da67031fa62875e6ea
6
+ metadata.gz: 3bc5af12c004b9d533d006409977064bf0b888c6dd0d09cb57b92d7e3bb2f64a0f5debfcc9d52b227ce4a5a7a9b7beedb299cb7f859723993dc0344216a67cae
7
+ data.tar.gz: 2947d2490fde65c8d28ec4cf2739dcd90a5965e671fb9cf4d1109e8becb50dcdef91646322f939802ddaab0a2480e06c645dbae4ab4b32e3e9830ca3cc1b7796
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpsd_baud_rate (0.1.0)
4
+ gpsd_baud_rate (0.1.5)
5
+ serialport (~> 1.3)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  rake (10.5.0)
11
+ serialport (1.3.1)
10
12
 
11
13
  PLATFORMS
12
14
  ruby
@@ -1,10 +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
 
9
+ @@version =GpsdBaudRate::VERSION
8
10
 
9
11
  @@device = '/dev/ttyAMA0'
10
12
  @@service = 'gpsd.service'
@@ -14,41 +16,41 @@ class GpsdBaudRate
14
16
  @@NMEA_sentences = %w[$GPGGA $GPGSA $GPGSV $GPRMC $GPZDA]
15
17
 
16
18
  def initialize goal_rate = @@baud_rates[0]
17
- @version =GpsdBaudRate::VERSION
18
-
19
- puts "\n\n\n"
20
19
 
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
  # pid= %x|pgrep -f "ruby /home/deploy/bin/set_baud.rb"|
22
- # puts "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
23
+ # @logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
23
24
 
24
25
  @goal_rate = goal_rate.to_i
25
- puts "Goal_rate: #{@goal_rate}"
26
- =begin
26
+ @logger.debug "Hello from gpsd_baud_rate!"
27
+ @logger.debug "Goal_rate: #{@goal_rate}"
28
+
29
+
27
30
  gpsd_start unless gpsd_active? #make sure it's running
28
31
 
29
- puts "Service Status: #{gpsd_active?}"
30
- puts "Baud Rate: #{@active_rate = baud_rate}"
32
+ @logger.debug "Service Status: #{gpsd_active?}"
33
+ @logger.debug "Baud Rate: #{@active_rate = baud_rate}"
31
34
  gpsd_stop
32
- puts "Service Status: #{gpsd_active?}"
33
- puts "Baud Rate: #{@inactive_rate = baud_rate}"
35
+ @logger.debug "Service Status: #{gpsd_active?}"
36
+ @logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
34
37
 
35
- puts "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
38
+ @logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
36
39
  if (read_from_device @active_rate) && (@active_rate != @goal_rate)
37
- puts "Setting Goal Rate (#{goal_rate})"
40
+ @logger.debug "Setting Goal Rate (#{goal_rate})"
38
41
  set_PMTK_baud_rate @goal_rate
39
42
  if read_from_device @goal_rate
40
- puts "Goal Baud Rate (#{@goal_rate}) has been set"
43
+ @logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
41
44
  end
42
45
  else
43
- puts "Already at Goal Baud Rate"
46
+ @logger.debug "Already at Goal Baud Rate"
44
47
  end
45
48
 
46
49
 
47
50
  #
48
51
  # Cleanup
49
52
  gpsd_start
50
- puts "Service Status: #{gpsd_active?}"
51
- =end
53
+ @logger.debug "Service Status: #{gpsd_active?}"
52
54
  end #initiallize
53
55
 
54
56
  #~~~~~~~~~~~~~~~~~~~~~ gosd_status ~~~~~~~~~~~~~~~~~
@@ -86,7 +88,7 @@ class GpsdBaudRate
86
88
  # returns original baud_rate
87
89
  def baud_rate=( b_rate)
88
90
  msg= %x| sudo stty #{b_rate} -F "#{@@device}"|
89
- msg.each {|m| puts m}
91
+ msg.each {|m| @logger.debug m}
90
92
  end
91
93
 
92
94
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -102,25 +104,27 @@ class GpsdBaudRate
102
104
  # Returns true if at least two of the received lines start with the NMEA
103
105
  # '$GPxxx' sentence codes in @@NMEA_sentences
104
106
  def read_from_device( baud)
107
+ gpsd_stop
105
108
  begin
106
109
  results = []
107
110
  count = 0
108
111
  ser = SerialPort.open(@@device, baud.to_i, 8, 1, SerialPort::NONE ) { |ser|
109
112
  ser.read_timeout = 900
110
- puts "ReadTimeout: #{ser.read_timeout} ms"
113
+ @logger.debug "ReadTimeout: #{ser.read_timeout} ms"
111
114
  5.times { results << ser.readline(100)}
112
- results.each { |s| puts s}
115
+ results.each { |s| @logger.debug s}
113
116
  results.each do |r|
114
117
  count += 1 if @@NMEA_sentences.any? { |s| s == r[0,6]}
115
118
  end
116
- puts "Count: #{count}"
119
+ @logger.debug "Count: #{count}"
117
120
  }
118
121
  rescue IOError => e
119
- puts "IOError: #{e.inspect}"
122
+ @logger.debug "IOError: #{e.inspect}"
120
123
  rescue => e
121
- puts "Error: #{e.inspect}"
124
+ @logger.debug "Error: #{e.inspect}"
122
125
  end
123
- puts "SerialPort Closed"
126
+ @logger.debug "SerialPort Closed"
127
+ gpsd_start
124
128
  count >= 2
125
129
  end
126
130
 
@@ -129,55 +133,68 @@ class GpsdBaudRate
129
133
  results=[]
130
134
 
131
135
  begin
132
- puts "Send to device"
136
+ @logger.debug "Send to device"
133
137
  ser = SerialPort.open( @@device, baud, 8, 1, SerialPort::NONE) { |ser|
134
138
  count = ser.write cmmd+"\r\n"
135
139
  }
136
140
  rescue IOError => e
137
- puts "IOError: #{e.inspect}"
141
+ @logger.debug "IOError: #{e.inspect}"
138
142
  rescue => e
139
- puts "Error: #{e.inspect}"
143
+ @logger.debug "Error: #{e.inspect}"
140
144
  end
141
- puts "Bytes Written: #{count}"
145
+ @logger.debug "Bytes Written: #{count}"
142
146
 
143
147
  begin
144
- puts "Receive response"
148
+ @logger.debug "Receive response"
145
149
  ser = SerialPort.open( @@device, @goal_rate, 8, 1, SerialPort::NONE) { |ser|
146
150
  ser.read_timeout = 900
147
151
  10.times {results << ser.readline(100)}
148
152
  }
149
153
  rescue IOError => e
150
- puts "IOError: #{e.inspect}"
154
+ @logger.debug "IOError: #{e.inspect}"
151
155
  rescue => e
152
- puts "Error: #{e.inspect}"
156
+ @logger.debug "Error: #{e.inspect}"
153
157
  end
154
- results.each { |r| puts "Results: #{r}"}
158
+ results.each { |r| @logger.debug "Results: #{r}"}
155
159
 
156
160
  end
157
161
 
158
162
 
159
163
  def find_baud_rate
160
- puts %x| sudo stty -F "#{@@device}"|
164
+ @logger.debug %x| sudo stty -F "#{@@device}"|
161
165
  gpsd_stop
162
- puts %x|sudo stty -F "#{@@device}"|
166
+ @logger.debug %x|sudo stty -F "#{@@device}"|
163
167
  gpsd_start
164
168
  end
165
169
 
166
170
  def set_PMTK_baud_rate rate
167
- puts "In set_PMTK_baud_rate"
171
+ @logger.debug "In set_PMTK_baud_rate"
168
172
  type = 251
169
173
  cmmd = nmea_checksum("PMTK#{type},#{rate}")
170
174
  write_to_device cmmd, @active_rate
171
175
  end
172
176
 
173
177
  def nmea_checksum cmmd
174
- puts "In nmea_checksum, cmmd: #{cmmd}"
178
+ @logger.debug "In nmea_checksum, cmmd: #{cmmd}"
175
179
  sum=0
176
180
  cmmd.each_byte { |i| sum = sum ^ i.ord}
177
181
  sum = sum & 0xff
178
182
  new_cmmd = "\$#{cmmd}*#{sum.to_s(16)}".upcase
179
- puts "new_cmmd: #{new_cmmd}"
183
+ @logger.debug "new_cmmd: #{new_cmmd}"
180
184
  new_cmmd
181
185
  end
182
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
+
183
200
  end
@@ -1,3 +1,3 @@
1
1
  class GpsdBaudRate
2
- VERSION = "0.1.0"
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.0
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-23 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