gpsd_baud_rate 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gpsd_baud_rate.rb +33 -33
- data/lib/gpsd_baud_rate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16dfe1b4f78b68d169e579548fc6fece7cd65dbbd1114f70865af22069418887
|
4
|
+
data.tar.gz: 90a67d3bc104cd38623b856e05d3585e5ef4272de86b3a7aafcc7ebf01b5b166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c84a67ac0ab6f83ed61c3bf1cc75fac39ee958707b8e763ccb6cffa493a2535db77a2646457447eceb1adf97be7f605fa59449c666d729cc6ac752ef04b36d
|
7
|
+
data.tar.gz: 001663ed32e69d5d9353de94faa783ef307d0b3b60d695117df7e3de85052944c61b4b590c8d3ebb4febdde8a2dbce5a482ee02f1016132779578dbe43768b06
|
data/Gemfile.lock
CHANGED
data/lib/gpsd_baud_rate.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "gpsd_baud_rate/version"
|
2
2
|
require "serialport"
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
|
5
6
|
class GpsdBaudRate
|
@@ -17,41 +18,40 @@ class GpsdBaudRate
|
|
17
18
|
|
18
19
|
def initialize goal_rate = @@baud_rates[0]
|
19
20
|
|
20
|
-
#
|
21
|
+
# @@logger.debug "\n\n\n"
|
21
22
|
|
22
23
|
# pid= %x|pgrep -f "ruby /home/deploy/bin/set_baud.rb"|
|
23
|
-
#
|
24
|
+
# @@logger.debug "Pid: #{pid}, $$: #{$$}, $BASHPID: #{$BASHPID}"
|
24
25
|
|
25
26
|
@goal_rate = goal_rate.to_i
|
26
27
|
@@logger.debug "Hello from gpsd_baud_rate!"
|
27
28
|
@@logger.debug "Goal_rate: #{@goal_rate}"
|
28
29
|
|
29
|
-
|
30
|
+
|
30
31
|
gpsd_start unless gpsd_active? #make sure it's running
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
@@logger.debug "Service Status: #{gpsd_active?}"
|
34
|
+
@@logger.debug "Baud Rate: #{@active_rate = baud_rate}"
|
34
35
|
gpsd_stop
|
35
|
-
|
36
|
-
|
36
|
+
@@logger.debug "Service Status: #{gpsd_active?}"
|
37
|
+
@@logger.debug "Baud Rate: #{@inactive_rate = baud_rate}"
|
37
38
|
|
38
|
-
|
39
|
+
@@logger.debug "\n~~~~~~~~~~~~ Read at #{@active_rate} baud ~~~~~~~~~~~~~~"
|
39
40
|
if (read_from_device @active_rate) && (@active_rate != @goal_rate)
|
40
|
-
|
41
|
+
@@logger.debug "Setting Goal Rate (#{goal_rate})"
|
41
42
|
set_PMTK_baud_rate @goal_rate
|
42
43
|
if read_from_device @goal_rate
|
43
|
-
|
44
|
+
@@logger.debug "Goal Baud Rate (#{@goal_rate}) has been set"
|
44
45
|
end
|
45
46
|
else
|
46
|
-
|
47
|
+
@@logger.debug "Already at Goal Baud Rate"
|
47
48
|
end
|
48
49
|
|
49
50
|
|
50
51
|
#
|
51
52
|
# Cleanup
|
52
53
|
gpsd_start
|
53
|
-
|
54
|
-
=end
|
54
|
+
@@logger.debug "Service Status: #{gpsd_active?}"
|
55
55
|
end #initiallize
|
56
56
|
|
57
57
|
#~~~~~~~~~~~~~~~~~~~~~ gosd_status ~~~~~~~~~~~~~~~~~
|
@@ -89,7 +89,7 @@ class GpsdBaudRate
|
|
89
89
|
# returns original baud_rate
|
90
90
|
def baud_rate=( b_rate)
|
91
91
|
msg= %x| sudo stty #{b_rate} -F "#{@@device}"|
|
92
|
-
msg.each {|m|
|
92
|
+
msg.each {|m| @@logger.debug m}
|
93
93
|
end
|
94
94
|
|
95
95
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
@@ -111,20 +111,20 @@ class GpsdBaudRate
|
|
111
111
|
count = 0
|
112
112
|
ser = SerialPort.open(@@device, baud.to_i, 8, 1, SerialPort::NONE ) { |ser|
|
113
113
|
ser.read_timeout = 900
|
114
|
-
|
114
|
+
@@logger.debug "ReadTimeout: #{ser.read_timeout} ms"
|
115
115
|
5.times { results << ser.readline(100)}
|
116
|
-
results.each { |s|
|
116
|
+
results.each { |s| @@logger.debug s}
|
117
117
|
results.each do |r|
|
118
118
|
count += 1 if @@NMEA_sentences.any? { |s| s == r[0,6]}
|
119
119
|
end
|
120
|
-
|
120
|
+
@@logger.debug "Count: #{count}"
|
121
121
|
}
|
122
122
|
rescue IOError => e
|
123
|
-
|
123
|
+
@@logger.debug "IOError: #{e.inspect}"
|
124
124
|
rescue => e
|
125
|
-
|
125
|
+
@@logger.debug "Error: #{e.inspect}"
|
126
126
|
end
|
127
|
-
|
127
|
+
@@logger.debug "SerialPort Closed"
|
128
128
|
gpsd_start
|
129
129
|
count >= 2
|
130
130
|
end
|
@@ -134,54 +134,54 @@ class GpsdBaudRate
|
|
134
134
|
results=[]
|
135
135
|
|
136
136
|
begin
|
137
|
-
|
137
|
+
@@logger.debug "Send to device"
|
138
138
|
ser = SerialPort.open( @@device, baud, 8, 1, SerialPort::NONE) { |ser|
|
139
139
|
count = ser.write cmmd+"\r\n"
|
140
140
|
}
|
141
141
|
rescue IOError => e
|
142
|
-
|
142
|
+
@@logger.debug "IOError: #{e.inspect}"
|
143
143
|
rescue => e
|
144
|
-
|
144
|
+
@@logger.debug "Error: #{e.inspect}"
|
145
145
|
end
|
146
|
-
|
146
|
+
@@logger.debug "Bytes Written: #{count}"
|
147
147
|
|
148
148
|
begin
|
149
|
-
|
149
|
+
@@logger.debug "Receive response"
|
150
150
|
ser = SerialPort.open( @@device, @goal_rate, 8, 1, SerialPort::NONE) { |ser|
|
151
151
|
ser.read_timeout = 900
|
152
152
|
10.times {results << ser.readline(100)}
|
153
153
|
}
|
154
154
|
rescue IOError => e
|
155
|
-
|
155
|
+
@@logger.debug "IOError: #{e.inspect}"
|
156
156
|
rescue => e
|
157
|
-
|
157
|
+
@@logger.debug "Error: #{e.inspect}"
|
158
158
|
end
|
159
|
-
results.each { |r|
|
159
|
+
results.each { |r| @@logger.debug "Results: #{r}"}
|
160
160
|
|
161
161
|
end
|
162
162
|
|
163
163
|
|
164
164
|
def find_baud_rate
|
165
|
-
|
165
|
+
@@logger.debug %x| sudo stty -F "#{@@device}"|
|
166
166
|
gpsd_stop
|
167
|
-
|
167
|
+
@@logger.debug %x|sudo stty -F "#{@@device}"|
|
168
168
|
gpsd_start
|
169
169
|
end
|
170
170
|
|
171
171
|
def set_PMTK_baud_rate rate
|
172
|
-
|
172
|
+
@@logger.debug "In set_PMTK_baud_rate"
|
173
173
|
type = 251
|
174
174
|
cmmd = nmea_checksum("PMTK#{type},#{rate}")
|
175
175
|
write_to_device cmmd, @active_rate
|
176
176
|
end
|
177
177
|
|
178
178
|
def nmea_checksum cmmd
|
179
|
-
|
179
|
+
@@logger.debug "In nmea_checksum, cmmd: #{cmmd}"
|
180
180
|
sum=0
|
181
181
|
cmmd.each_byte { |i| sum = sum ^ i.ord}
|
182
182
|
sum = sum & 0xff
|
183
183
|
new_cmmd = "\$#{cmmd}*#{sum.to_s(16)}".upcase
|
184
|
-
|
184
|
+
@@logger.debug "new_cmmd: #{new_cmmd}"
|
185
185
|
new_cmmd
|
186
186
|
end
|
187
187
|
|