my_gpsd_client 0.02.03 → 0.02.08

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: deb1eb0758c13fb908e9ac239ba2e84f1ddbe23507400bbfc4774eb9c529ef06
4
- data.tar.gz: f69f14b3c0cc30e8827fb97076eb067fc12131950bd859f15ece5bcad1299c33
3
+ metadata.gz: 344365d55d636550821b173a6de9b95724c32cf3d5f5ccd9f3aba48271523ab8
4
+ data.tar.gz: 49b25953b00050f46bc717f36173b3afd57362e6b1d6a5acc501f79ee329c4f4
5
5
  SHA512:
6
- metadata.gz: e8521af40063d27ae44db6f4f0ffa3a56bf4da309f0efb0d03e883229ae3554ea695964aad9177fce7b9da4fcd050f2f00ff52e2de0c9ad103ef7044af3e35a3
7
- data.tar.gz: 94037574dd6f7e6a07e33bc52b8908d1abddb4879bc8bbb70f9b762d49d2e0223ed113c433908948e0578802c0b7106ef219d46f10fe37ac9dd812eae2cf4007
6
+ metadata.gz: a24acac04267b68fd530f34b70b34c4db6f93520bc6930c124a43fdca89217818f4c9a41432f382826e00fc5e6901bde290fb330ee2fb8bc087b24e03cb8b915
7
+ data.tar.gz: d9bbecef22de226e0d205e8bfd81dc597ad0ccf8e80d0716f6bbe1ca9e90b990d0f0e5472d82993fabf08d680cef87cdee2e818d27298735dc88dd07b13ad269
@@ -5,14 +5,23 @@ require 'date'
5
5
  require 'logger'
6
6
 
7
7
  class MyGpsdClient
8
- attr_accessor :host, :port, :command, :log_level, :min_speed, :watchdog_max, :watchdog_force
9
- attr_reader :version, :last_watch, :socket_ready, :msg_counts, :watchdog_fired_count
8
+ attr_accessor :host, :port, :command, :min_speed, :watchdog_max, :watchdog_force, :watchdog_euthanized,
9
+ :log_progname, :log_level, :log_path, :log_format, :log_time_format
10
+ attr_reader :version, :last_watch, :socket_ready, :socket, :msg_counts, :watchdog_fired_count,
11
+ :readthread, :socket_init_thread, :watchdogthread, :watchdog_count
12
+
10
13
 
11
14
  DEFAULT_HOST = 'localhost'
12
15
  DEFAULT_PORT = 2947
13
- DEFAULT_WATCH = {"enable":false,"json":false,"nmea":false}
14
- DEFAULT_LOG_LEVEL = 0
16
+ DEFAULT_WATCH = {"class":"WATCH", "enable":false,"json":false,"nmea":false}
15
17
  DEFAULT_WATCHDOG_MAX = 5.0
18
+
19
+ DEFAULT_LOG_PROGNAME = "MyGpsdClient"
20
+ DEFAULT_LOG_LEVEL = Logger::DEBUG
21
+ DEFAULT_LOG_PATH = 'log/MyGpsdClient.log'
22
+ DEFAULT_LOG_FORMAT = ''
23
+ DEFAULT_LOG_TIME_FORMAT = '%Y-%m-%d %T.%N %z %Z'
24
+
16
25
  WATCHDOG_STEP = 0.1 # Check watchdog ten times per second
17
26
 
18
27
  THREAD_NAMES = { # Keep displayed names the same length
@@ -23,6 +32,8 @@ class MyGpsdClient
23
32
  }
24
33
  Thread.current[:name]=THREAD_NAMES[:MainThread]
25
34
 
35
+ @@logger = nil
36
+
26
37
 
27
38
  # A simple gpsd client that dump's json objects contianing all info received from the gpsd deamon
28
39
  # you need to at least setup either the raw callback (on_raw_change) or position callback (on_position_change) to use GPSD2JSON. the raw callback just passes the json objects it received from the daemon on to the block you pass it. the on_position_change and on_satellites_change are a bit easier to use.
@@ -44,7 +55,12 @@ class MyGpsdClient
44
55
  @host = host
45
56
  @port = port
46
57
  @last_watch = watch
58
+
47
59
  @log_level = log_level
60
+ @log_path = DEFAULT_LOG_PATH
61
+ @log_format = DEFAULT_LOG_FORMAT
62
+ @log_time_format = DEFAULT_LOG_TIME_FORMAT
63
+ @log_progname = DEFAULT_LOG_PROGNAME
48
64
 
49
65
  @socket = nil
50
66
  @socket_ready = false
@@ -55,6 +71,7 @@ class MyGpsdClient
55
71
  @watchdog_max = DEFAULT_WATCHDOG_MAX
56
72
  @watchdog_fired_count = 0
57
73
  @watchdog_force = false
74
+ @watchdog_euthanized = false
58
75
  @min_speed = 0 # speed needs to be higher than this to make the gps info count
59
76
  @last = nil #last gps info
60
77
  @sats = nil # last satellites info
@@ -68,13 +85,12 @@ class MyGpsdClient
68
85
  toff: 0, pol: 0, pps: 0, dev: 0, devs: 0, err: 0,
69
86
  unk: 0}
70
87
 
71
- MyGpsdClient.logger.progname = MyGpsdClient
72
- MyGpsdClient.logger.level = @log_level
88
+ @logger = new_logger path: @log_path, progname: @log_progname, time_format: @log_time_format, level: @log_level
73
89
  my_logger level: 'info', msg: "MyGpsdClient Gem - Version: #{@version}"
74
90
  end
75
91
 
76
92
  #
77
- # Receive Commands from User
93
+ # attribute_writters additional actions
78
94
  #
79
95
  def command=(val)
80
96
  @command = val
@@ -85,9 +101,34 @@ class MyGpsdClient
85
101
 
86
102
  def log_level=(val)
87
103
  @log_level = val
88
- MyGpsdClient.logger.level = @log_level
104
+ @logger.level = @log_level
105
+ end
106
+
107
+ def log_progname=(val)
108
+ @log_progname = val
109
+ @logger.progname = @log_progname
89
110
  end
90
111
 
112
+ def log_format=(val)
113
+ @log_format = val
114
+ @logger.format = @log_format
115
+ end
116
+
117
+ def log_time_format=(val)
118
+ @log_time_format = val
119
+ @logger.datetime_format = @log_time_format
120
+ end
121
+
122
+ def log_path=(val)
123
+ @log_path = val
124
+ @logger = new_logger path: @log_path, progname: @log_progname, time_format: @log_time_format, level: @log_level
125
+ end
126
+ #
127
+ # End attribute_writters additional actions
128
+ #
129
+
130
+
131
+
91
132
  def log_marker level: 'debug', msg: "Log Marker"
92
133
  my_logger level: level, msg: "~~~~~~~~~~~~~~~~~~~~~~~ #{msg} ~~~~~~~~~~~~~~~~~~~~~~~"
93
134
  end
@@ -119,11 +160,16 @@ class MyGpsdClient
119
160
  else
120
161
  # it's ready, tell it to start watching and passing
121
162
  my_logger msg: "Send_cmmd: socket ready, send cmmd"
122
- str = "?#{@command[:class].upcase}=#{@command.to_json}"
163
+ if @command.size > 1
164
+ str = "?#{@command[:class].upcase}=#{@command.to_json}"
165
+ else
166
+ str = "?#{@command[:class].upcase};"
167
+ end
123
168
  my_logger level: 'info', msg: "Send_cmmd: sending: #{str}"
124
169
  @sent_raw_callback.call( str) if @sent_raw_callback
125
170
  @socket.puts str
126
171
  # If Enable was false in the last WATCH command, close the connecction
172
+ my_logger msg: "@last_watch.key?(:enable) #{@last_watch.key?(:enable)}, @last_watch[:enable] #{@last_watch[:enable]}"
127
173
  stop if @last_watch.key?(:enable) && !@last_watch[:enable]
128
174
  end
129
175
  my_logger msg: "Send_cmmd: Exiting send_cmmd"
@@ -178,43 +224,48 @@ class MyGpsdClient
178
224
 
179
225
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
226
  # background thread to implement a watchdog timer
181
- my_logger msg: "Start: Starting Watchdog Thread"
182
- @watchdogthread = Thread.start do
183
- Thread.current[:name]=THREAD_NAMES[:WatchdogThread]
184
- my_logger msg: "Watchdog Thread: #{Thread.current[:name]}"
185
- @watchdog_count = 0.0
186
- @watchdog_enabled = true
187
- while @watchdog_enabled do
188
- if @watchdog_force
189
- @watchdog_force = false
190
- # force the watchdog to fire by killing the socket
191
- @socket.close if @socket && !@socket.closed?
192
- #@watchdog_count = @watchdog_max
193
- end
194
- if (@watchdog_count += WATCHDOG_STEP) >= @watchdog_max
195
- my_logger level: 'warn', msg: "Watchdog Fired"
196
- @watchdog_count = 0.0
197
- @watchdog_fired_count += 1
198
- @watchdog_enabled = false
199
- # Kill the readthread...
200
- my_logger msg: "Watchdog Thread: Killing ReadThread"
201
- Thread.kill(@readthread) if @readthread && @readthread.alive?
202
- if @last_watch[:enable]
203
- stop
204
- sleep 0.5
205
- my_logger msg: "Watchdog Thread: Send Last_Watch: #{@last_watch}"
206
- @command = @last_watch
207
- send_cmmd
208
- my_logger msg: "Watchdog Thread: Thread.exit"
209
- Thread.exit
210
- else
211
- close_socket
227
+ if @watchdog_euthanized
228
+ my_logger msg: "Watchdog has been euthanized!"
229
+ else
230
+ my_logger msg: "Start: Starting Watchdog Thread"
231
+ @watchdogthread = Thread.start do
232
+ Thread.current[:name]=THREAD_NAMES[:WatchdogThread]
233
+ my_logger msg: "Watchdog Thread: #{Thread.current[:name]}"
234
+ @watchdog_count = 0.0
235
+ @watchdog_enabled = true
236
+ while @watchdog_enabled && !@watchdog_euthanized do
237
+ my_logger msg: "Watchdog Thread: Watchdog Tick"
238
+ if @watchdog_force
239
+ @watchdog_force = false
240
+ # force the watchdog to fire by killing the socket
241
+ @socket.close if @socket && !@socket.closed?
242
+ #@watchdog_count = @watchdog_max
212
243
  end
213
- end
214
- sleep WATCHDOG_STEP
215
- end # while
216
- my_logger msg: "Closing Watchdog Thread"
217
- end # watchdog thread
244
+ if (@watchdog_count += WATCHDOG_STEP) >= @watchdog_max
245
+ my_logger level: 'warn', msg: "Watchdog Fired"
246
+ @watchdog_count = 0.0
247
+ @watchdog_fired_count += 1
248
+ @watchdog_enabled = false
249
+ # Kill the readthread...
250
+ my_logger msg: "Watchdog Thread: Killing ReadThread"
251
+ Thread.kill(@readthread) if @readthread && @readthread.alive?
252
+ if @last_watch[:enable]
253
+ stop
254
+ sleep 0.5
255
+ my_logger msg: "Watchdog Thread: Send Last_Watch: #{@last_watch}"
256
+ @command = @last_watch
257
+ send_cmmd
258
+ my_logger msg: "Watchdog Thread: Thread.exit"
259
+ Thread.exit
260
+ else
261
+ close_socket
262
+ end
263
+ end
264
+ sleep WATCHDOG_STEP
265
+ end # while Wchdog enabled
266
+ my_logger msg: "Closing Watchdog Thread"
267
+ end # wtchdg thread start do
268
+ end # watchdog euthanize if
218
269
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219
270
 
220
271
  my_logger msg: "Start: Exiting Start"
@@ -452,16 +503,28 @@ LOG_LEVELS = {debug: Logger::DEBUG, info: Logger::INFO, warn: Logger::WARN,
452
503
  error: Logger::ERROR, fatal: Logger::FATAL, unknown: Logger::UNKNOWN}
453
504
 
454
505
  def my_logger(level: 'debug', msg: "Blank")
455
- MyGpsdClient.logger.add (LOG_LEVELS[level.to_sym]) {"#{Thread.current[:name]} -- #{msg}"}
506
+ @logger.add (LOG_LEVELS[level.to_sym]) {"#{Thread.current[:name]} -- #{msg}"}
507
+ end
508
+
509
+ def new_logger( progname: nil, path:, format: nil, time_format: nil, level: LOG_LEVELS[:debug])
510
+ logger = Logger.new(path)
511
+ logger.progname = progname if progname
512
+ logger.format = format if format
513
+ logger.level = level if level
514
+ logger.datetime_format = time_format if time_format
515
+ logger
456
516
  end
457
517
 
518
+ =begin
458
519
  def self.logger
520
+ puts "In self.logger: log_path => #{@log_path}, @@logger.nil? => #{@@logger.nil?}"
459
521
  @@logger ||= defined?(Rails) ? Rails.logger : Logger.new("log/MyGpsdClient.log")
522
+ puts "Exiting self.logger: @@logger => #{@@logger}"
460
523
  end
461
524
 
462
525
  def self.logger=(logger)
463
526
  @@logger = logger
464
527
  end
465
-
528
+ =end
466
529
 
467
530
  end
@@ -1,3 +1,3 @@
1
1
  class MyGpsdClient_version
2
- VERSION = "0.02.03"
2
+ VERSION = "0.02.08"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_gpsd_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.02.03
4
+ version: 0.02.08
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Finnegan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler