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 +4 -4
- data/lib/gpsd_baud_rate.rb +47 -35
- data/lib/gpsd_baud_rate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a00a30d7ff931c648e4d127ae5f253f9bf328d376e96e6f32650082b306ba4
|
4
|
+
data.tar.gz: 8549c6d82accb16822416fa8a57f4be95348e90a0c50ed894e3474ebe0e4bf15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bc5af12c004b9d533d006409977064bf0b888c6dd0d09cb57b92d7e3bb2f64a0f5debfcc9d52b227ce4a5a7a9b7beedb299cb7f859723993dc0344216a67cae
|
7
|
+
data.tar.gz: 2947d2490fde65c8d28ec4cf2739dcd90a5965e671fb9cf4d1109e8becb50dcdef91646322f939802ddaab0a2480e06c645dbae4ab4b32e3e9830ca3cc1b7796
|
data/lib/gpsd_baud_rate.rb
CHANGED
@@ -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
|
-
|
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
|
-
#
|
23
|
+
# @logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
|
25
24
|
|
26
25
|
@goal_rate = goal_rate.to_i
|
27
|
-
|
28
|
-
|
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
|
-
|
34
|
-
|
32
|
+
@logger.debug "Service Status: #{gpsd_active?}"
|
33
|
+
@logger.debug "Baud Rate: #{@active_rate = baud_rate}"
|
35
34
|
gpsd_stop
|
36
|
-
|
37
|
-
|
35
|
+
@logger.debug "Service Status: #{gpsd_active?}"
|
36
|
+
@logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
|
38
37
|
|
39
|
-
|
38
|
+
@logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
|
40
39
|
if (read_from_device @active_rate) && (@active_rate != @goal_rate)
|
41
|
-
|
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
|
-
|
43
|
+
@logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
|
45
44
|
end
|
46
45
|
else
|
47
|
-
|
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
|
-
|
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|
|
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
|
-
|
113
|
+
@logger.debug "ReadTimeout: #{ser.read_timeout} ms"
|
115
114
|
5.times { results << ser.readline(100)}
|
116
|
-
results.each { |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
|
-
|
119
|
+
@logger.debug "Count: #{count}"
|
121
120
|
}
|
122
121
|
rescue IOError => e
|
123
|
-
|
122
|
+
@logger.debug "IOError: #{e.inspect}"
|
124
123
|
rescue => e
|
125
|
-
|
124
|
+
@logger.debug "Error: #{e.inspect}"
|
126
125
|
end
|
127
|
-
|
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
|
-
|
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
|
-
|
141
|
+
@logger.debug "IOError: #{e.inspect}"
|
143
142
|
rescue => e
|
144
|
-
|
143
|
+
@logger.debug "Error: #{e.inspect}"
|
145
144
|
end
|
146
|
-
|
145
|
+
@logger.debug "Bytes Written: #{count}"
|
147
146
|
|
148
147
|
begin
|
149
|
-
|
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
|
-
|
154
|
+
@logger.debug "IOError: #{e.inspect}"
|
156
155
|
rescue => e
|
157
|
-
|
156
|
+
@logger.debug "Error: #{e.inspect}"
|
158
157
|
end
|
159
|
-
results.each { |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
|
-
|
164
|
+
@logger.debug %x| sudo stty -F "#{@@device}"|
|
166
165
|
gpsd_stop
|
167
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
+
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-
|
11
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|