my_gpsd_client 0.02.02 → 0.02.07

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: 97febebcc160956fb040c4facaf04e81fdd9100ec45cfd5dbd47a20dc754e192
4
- data.tar.gz: 1705002705b8c247b07d57f1f16a38bfda0a1df2977f9e74badbadaa88ecc1dc
3
+ metadata.gz: '096fa3d4b6b58846f87925834aee7c05d46301e6ef76aa10350870f977931470'
4
+ data.tar.gz: 0c551f03daa20cd290f57d1941015402e5f23ae08787205995dca6b553f179a0
5
5
  SHA512:
6
- metadata.gz: d50ea29c9bef3ef88768a33372d5824a3a253526a7f5625ce32b68b88d7262d4abfdbdcc8a0a54ce5d47e3945b97674181d2fad272552c114bd2d0de8c5f8aa2
7
- data.tar.gz: 4273baa90163fa5f645c4b3bdec80979e0bef2800192958954885f1641e82990ce02d06ed6a7ef28da21759699ce0195cae5b8707c2d336df0500d844305b80b
6
+ metadata.gz: 8bd6857e8065d4de4ad3e0aff6555940bb08ffc5c462ece1f8f6f3493eeaad984352e099676da47eb7c0eac86352f5beb5bb07078d15ccc85a0382c26c41ed3f
7
+ data.tar.gz: f75b8d76245d80cf44742ab629e72a81c9d6897c5c08962dbf1ea9ebed3fef06b25ae6ea015ad5c99f6803de3f19b921102a320385981dfe2ace0156a7502f6e
data/README.md CHANGED
@@ -36,7 +36,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
36
36
  From the gem's main folder...
37
37
 
38
38
  $ gem build my_gpsd_client.gemspec
39
- $ gem install my_gpsd_client-0.1.10.gem
39
+ $ gem install my_gpsd_client-[version].gem
40
40
 
41
41
  $ irb
42
42
  irb(main):001:0> require 'my_gpsd_client'
@@ -45,14 +45,12 @@ From the gem's main folder...
45
45
  => #<MyGpsdClient:0x00007fd8b98806a0...
46
46
  irb(main):003:0> gps.version
47
47
  => "0.1.17"
48
- irb(main):004:0>
48
+ irb(main):004:0>
49
49
 
50
50
  To release to rubygems.org...
51
51
 
52
- $ rake build
52
+ $ rake build; rake release
53
53
  my_gpsd_client 0.1.10 built to pkg/my_gpsd_client-0.1.0.gem.
54
-
55
- $ rake release
56
54
  my_gpsd_client 0.1.10 built to pkg/my_gpsd_client-0.1.0.gem.
57
55
  Tagged v0.1.10.
58
56
  Pushed git commits and tags.
@@ -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,7 +160,11 @@ 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
@@ -178,43 +223,48 @@ class MyGpsdClient
178
223
 
179
224
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
225
  # 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
226
+ if @watchdog_euthanized
227
+ my_logger msg: "Watchdog has been euthanized!"
228
+ else
229
+ my_logger msg: "Start: Starting Watchdog Thread"
230
+ @watchdogthread = Thread.start do
231
+ Thread.current[:name]=THREAD_NAMES[:WatchdogThread]
232
+ my_logger msg: "Watchdog Thread: #{Thread.current[:name]}"
233
+ @watchdog_count = 0.0
234
+ @watchdog_enabled = true
235
+ while @watchdog_enabled && !@watchdog_euthanized do
236
+ my_logger msg: "Watchdog Thread: Watchdog Tick"
237
+ if @watchdog_force
238
+ @watchdog_force = false
239
+ # force the watchdog to fire by killing the socket
240
+ @socket.close if @socket && !@socket.closed?
241
+ #@watchdog_count = @watchdog_max
212
242
  end
213
- end
214
- sleep WATCHDOG_STEP
215
- end # while
216
- my_logger msg: "Closing Watchdog Thread"
217
- end # watchdog thread
243
+ if (@watchdog_count += WATCHDOG_STEP) >= @watchdog_max
244
+ my_logger level: 'warn', msg: "Watchdog Fired"
245
+ @watchdog_count = 0.0
246
+ @watchdog_fired_count += 1
247
+ @watchdog_enabled = false
248
+ # Kill the readthread...
249
+ my_logger msg: "Watchdog Thread: Killing ReadThread"
250
+ Thread.kill(@readthread) if @readthread && @readthread.alive?
251
+ if @last_watch[:enable]
252
+ stop
253
+ sleep 0.5
254
+ my_logger msg: "Watchdog Thread: Send Last_Watch: #{@last_watch}"
255
+ @command = @last_watch
256
+ send_cmmd
257
+ my_logger msg: "Watchdog Thread: Thread.exit"
258
+ Thread.exit
259
+ else
260
+ close_socket
261
+ end
262
+ end
263
+ sleep WATCHDOG_STEP
264
+ end # while Wchdog enabled
265
+ my_logger msg: "Closing Watchdog Thread"
266
+ end # wtchdg thread start do
267
+ end # watchdog euthanize if
218
268
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219
269
 
220
270
  my_logger msg: "Start: Exiting Start"
@@ -265,8 +315,9 @@ class MyGpsdClient
265
315
  else
266
316
  sleep 0.1
267
317
  end
268
- rescue
269
- my_logger level: 'error', msg: "Read_from_socket: error reading from socket: #{$!}"
318
+ rescue StandardError => e
319
+ # my_logger level: 'error', msg: "Read_from_socket: error reading from socket: #{$!}"
320
+ my_logger level: 'error', msg: "Read_from_socket: error reading from socket: #{e.message}"
270
321
  @socket_ready = !@socket.closed? if @socket
271
322
  end
272
323
  else
@@ -451,16 +502,28 @@ LOG_LEVELS = {debug: Logger::DEBUG, info: Logger::INFO, warn: Logger::WARN,
451
502
  error: Logger::ERROR, fatal: Logger::FATAL, unknown: Logger::UNKNOWN}
452
503
 
453
504
  def my_logger(level: 'debug', msg: "Blank")
454
- MyGpsdClient.logger.add (LOG_LEVELS[level.to_sym]) {"#{Thread.current[:name]} -- #{msg}"}
505
+ @logger.add (LOG_LEVELS[level.to_sym]) {"#{Thread.current[:name]} -- #{msg}"}
506
+ end
507
+
508
+ def new_logger( progname: nil, path:, format: nil, time_format: nil, level: LOG_LEVELS[:debug])
509
+ logger = Logger.new(path)
510
+ logger.progname = progname if progname
511
+ logger.format = format if format
512
+ logger.level = level if level
513
+ logger.datetime_format = time_format if time_format
514
+ logger
455
515
  end
456
516
 
517
+ =begin
457
518
  def self.logger
519
+ puts "In self.logger: log_path => #{@log_path}, @@logger.nil? => #{@@logger.nil?}"
458
520
  @@logger ||= defined?(Rails) ? Rails.logger : Logger.new("log/MyGpsdClient.log")
521
+ puts "Exiting self.logger: @@logger => #{@@logger}"
459
522
  end
460
523
 
461
524
  def self.logger=(logger)
462
525
  @@logger = logger
463
526
  end
464
-
527
+ =end
465
528
 
466
529
  end
@@ -1,3 +1,3 @@
1
1
  class MyGpsdClient_version
2
- VERSION = "0.02.02"
2
+ VERSION = "0.02.07"
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.02
4
+ version: 0.02.07
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-21 00:00:00.000000000 Z
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,6 +55,7 @@ files:
55
55
  - bin/setup
56
56
  - lib/my_gpsd_client.rb
57
57
  - lib/my_gpsd_client/version.rb
58
+ - my_gpsd_client-0.02.05.gem
58
59
  - my_gpsd_client.gemspec
59
60
  homepage: https://github.com/sjf-control/my_gpsd_client
60
61
  licenses: