gpsd_baud_rate 0.1.2 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f0c1ba9617119a0d8538ad374e97e5c4fd43819bd5842e63b0371c4872edfd5
4
- data.tar.gz: 5966238bd00c471eb263930d7ba89fffef8cb507d9e40d4f1a03b89fbe5ee1b5
3
+ metadata.gz: 644352f16bb5cb4bc0b324213fc0539a44ba17af466dc0d0cd056f5459196c89
4
+ data.tar.gz: 2aa27d9c33141c5023aa188464d817ba505a065924eb7770c83ad677ae1f3db8
5
5
  SHA512:
6
- metadata.gz: '09a188da5f3d082dab6588eb2c3bb0060651042a37f7cdf77eb831a9cfaa2118b39226b98aa25ce1478a5343c876162f895a805e4ec09e6fb441f52c28339d03'
7
- data.tar.gz: 712116ad4c7a8b7ec8b2f7c43e3dbd413b1b0ce2bcd540b00ee7e98af3c6aacd435c9d923772a542e92d2f6a7c9d5eb613731d4842fe1eb9039b93d194b93c94
6
+ metadata.gz: b4c3efb0f01bf8dccdb12e4fe2364e87e80e479a24c7ac747259106bb4029a9c220f637879a04c7b7225b893dcd6faae268caef6d38b11910b00472462c6a137
7
+ data.tar.gz: e7858601e5712b37237474b1541e62fc01f4cc048e5b9896ea45c61036bfc81946eda19bcf598f7a3b044f70e2b11df8d540cdcdc32a51c576b8f41039bcaad1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpsd_baud_rate (0.1.1)
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,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.to_s
8
10
 
9
11
  @@device = '/dev/ttyAMA0'
10
12
  @@service = 'gpsd.service'
@@ -14,61 +16,58 @@ 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
- logger.debug "Hello from gpsd_baud_rate!"
26
- Rails.logger.debug "Goal_rate: #{@goal_rate}"
26
+ @logger.debug "Goal_rate: #{@goal_rate}"
27
+
27
28
 
28
- =begin
29
29
  gpsd_start unless gpsd_active? #make sure it's running
30
30
 
31
- puts "Service Status: #{gpsd_active?}"
32
- puts "Baud Rate: #{@active_rate = baud_rate}"
31
+ @logger.debug "Service Status: #{gpsd_active?}"
32
+ @logger.debug "Baud Rate: #{@active_rate = baud_rate}"
33
33
  gpsd_stop
34
- puts "Service Status: #{gpsd_active?}"
35
- puts "Baud Rate: #{@inactive_rate = baud_rate}"
34
+ @logger.debug "Service Status: #{gpsd_active?}"
35
+ @logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
36
36
 
37
- puts "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
37
+ @logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
38
38
  if (read_from_device @active_rate) && (@active_rate != @goal_rate)
39
- puts "Setting Goal Rate (#{goal_rate})"
39
+ @logger.debug "Setting Goal Rate (#{goal_rate})"
40
40
  set_PMTK_baud_rate @goal_rate
41
41
  if read_from_device @goal_rate
42
- puts "Goal Baud Rate (#{@goal_rate}) has been set"
42
+ @logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
43
43
  end
44
44
  else
45
- puts "Already at Goal Baud Rate"
45
+ @logger.debug "Already at Goal Baud Rate"
46
46
  end
47
47
 
48
48
 
49
49
  #
50
50
  # Cleanup
51
51
  gpsd_start
52
- puts "Service Status: #{gpsd_active?}"
53
- =end
52
+ @logger.debug "Service Status: #{gpsd_active?}"
54
53
  end #initiallize
55
54
 
56
- #~~~~~~~~~~~~~~~~~~~~~ gosd_status ~~~~~~~~~~~~~~~~~
55
+ #~~~~~~~~~~~~~~~~~~~~~ gpsd_status ~~~~~~~~~~~~~~~~~
57
56
 
58
- def gpsd_active?
57
+ def self.gpsd_active?
59
58
  arry = %x|sudo systemctl status "#{@@socket}"|.split(/\n/)
60
59
  s = arry.select!{ |e| e.include? "Active:"}[0].split(/\W+/)[2]
61
60
  s == 'active'
62
61
  end
63
62
 
64
- def gpsd_stop
63
+ def self.gpsd_stop
65
64
  %x|sudo systemctl stop "#{@@socket}"|
66
65
  %x|sudo systemctl stop "#{@@service}"|
67
66
  sleep 1
68
67
  %x|sudo systemctl daemon-reload|
69
68
  end
70
69
 
71
- def gpsd_start
70
+ def self.gpsd_start
72
71
  %x|sudo systemctl start "#{@@service}"|
73
72
  %x|sudo systemctl start "#{@@socket}"|
74
73
  sleep 1
@@ -77,7 +76,7 @@ class GpsdBaudRate
77
76
 
78
77
  #~~~~~~~~~~~~~~~~~~~~~~~~ baud rate ~~~~~~~~~~~~~~~~~~~
79
78
 
80
- def baud_rate
79
+ def self.baud_rate
81
80
  %x| sudo stty -F "#{@@device}"|.split('; ')[0].split(/\W+/)[1].to_i
82
81
  end
83
82
 
@@ -88,7 +87,7 @@ class GpsdBaudRate
88
87
  # returns original baud_rate
89
88
  def baud_rate=( b_rate)
90
89
  msg= %x| sudo stty #{b_rate} -F "#{@@device}"|
91
- msg.each {|m| puts m}
90
+ msg.each {|m| @logger.debug m}
92
91
  end
93
92
 
94
93
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -110,20 +109,20 @@ class GpsdBaudRate
110
109
  count = 0
111
110
  ser = SerialPort.open(@@device, baud.to_i, 8, 1, SerialPort::NONE ) { |ser|
112
111
  ser.read_timeout = 900
113
- puts "ReadTimeout: #{ser.read_timeout} ms"
112
+ @logger.debug "ReadTimeout: #{ser.read_timeout} ms"
114
113
  5.times { results << ser.readline(100)}
115
- results.each { |s| puts s}
114
+ results.each { |s| @logger.debug s}
116
115
  results.each do |r|
117
116
  count += 1 if @@NMEA_sentences.any? { |s| s == r[0,6]}
118
117
  end
119
- puts "Count: #{count}"
118
+ @logger.debug "Count: #{count}"
120
119
  }
121
120
  rescue IOError => e
122
- puts "IOError: #{e.inspect}"
121
+ @logger.debug "IOError: #{e.inspect}"
123
122
  rescue => e
124
- puts "Error: #{e.inspect}"
123
+ @logger.debug "Error: #{e.inspect}"
125
124
  end
126
- puts "SerialPort Closed"
125
+ @logger.debug "SerialPort Closed"
127
126
  gpsd_start
128
127
  count >= 2
129
128
  end
@@ -133,55 +132,68 @@ class GpsdBaudRate
133
132
  results=[]
134
133
 
135
134
  begin
136
- puts "Send to device"
135
+ @logger.debug "Send to device"
137
136
  ser = SerialPort.open( @@device, baud, 8, 1, SerialPort::NONE) { |ser|
138
137
  count = ser.write cmmd+"\r\n"
139
138
  }
140
139
  rescue IOError => e
141
- puts "IOError: #{e.inspect}"
140
+ @logger.debug "IOError: #{e.inspect}"
142
141
  rescue => e
143
- puts "Error: #{e.inspect}"
142
+ @logger.debug "Error: #{e.inspect}"
144
143
  end
145
- puts "Bytes Written: #{count}"
144
+ @logger.debug "Bytes Written: #{count}"
146
145
 
147
146
  begin
148
- puts "Receive response"
147
+ @logger.debug "Receive response"
149
148
  ser = SerialPort.open( @@device, @goal_rate, 8, 1, SerialPort::NONE) { |ser|
150
149
  ser.read_timeout = 900
151
150
  10.times {results << ser.readline(100)}
152
151
  }
153
152
  rescue IOError => e
154
- puts "IOError: #{e.inspect}"
153
+ @logger.debug "IOError: #{e.inspect}"
155
154
  rescue => e
156
- puts "Error: #{e.inspect}"
155
+ @logger.debug "Error: #{e.inspect}"
157
156
  end
158
- results.each { |r| puts "Results: #{r}"}
157
+ results.each { |r| @logger.debug "Results: #{r}"}
159
158
 
160
159
  end
161
160
 
162
161
 
163
162
  def find_baud_rate
164
- puts %x| sudo stty -F "#{@@device}"|
163
+ @logger.debug %x| sudo stty -F "#{@@device}"|
165
164
  gpsd_stop
166
- puts %x|sudo stty -F "#{@@device}"|
165
+ @logger.debug %x|sudo stty -F "#{@@device}"|
167
166
  gpsd_start
168
167
  end
169
168
 
170
169
  def set_PMTK_baud_rate rate
171
- puts "In set_PMTK_baud_rate"
170
+ @logger.debug "In set_PMTK_baud_rate"
172
171
  type = 251
173
172
  cmmd = nmea_checksum("PMTK#{type},#{rate}")
174
173
  write_to_device cmmd, @active_rate
175
174
  end
176
175
 
177
176
  def nmea_checksum cmmd
178
- puts "In nmea_checksum, cmmd: #{cmmd}"
177
+ @logger.debug "In nmea_checksum, cmmd: #{cmmd}"
179
178
  sum=0
180
179
  cmmd.each_byte { |i| sum = sum ^ i.ord}
181
180
  sum = sum & 0xff
182
181
  new_cmmd = "\$#{cmmd}*#{sum.to_s(16)}".upcase
183
- puts "new_cmmd: #{new_cmmd}"
182
+ @logger.debug "new_cmmd: #{new_cmmd}"
184
183
  new_cmmd
185
184
  end
186
185
 
186
+ LOG_LEVELS = {debug: Logger::DEBUG, info: Logger::INFO, warn: Logger::WARN,
187
+ error: Logger::ERROR, fatal: Logger::FATAL, unknown: Logger::UNKNOWN}
188
+
189
+ def new_logger( progname: nil, path:, format: nil, time_format: nil, level: LOG_LEVELS[:debug])
190
+ logger = Logger.new(path)
191
+ logger.progname = progname if progname
192
+ logger.format = format if format
193
+ logger.level = level if level
194
+ logger.datetime_format = time_format if time_format
195
+ logger
196
+ end
197
+
198
+
187
199
  end
@@ -1,3 +1,3 @@
1
1
  class GpsdBaudRate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.8"
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.2
4
+ version: 0.1.8
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-26 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