Class: MyGpsdClient
- Inherits:
-
Object
- Object
- MyGpsdClient
- Defined in:
- lib/my_gpsd_client.rb
Constant Summary collapse
- DEFAULT_HOST =
'localhost'
- DEFAULT_PORT =
2947
- DEFAULT_WATCH =
{"class":"WATCH", "enable":false,"json":false,"nmea":false}
- DEFAULT_WATCHDOG_MAX =
2.0
- DEFAULT_LOG_PROGNAME =
"MyGpsdClient"
- DEFAULT_LOG_LEVEL =
Logger::DEBUG
- DEFAULT_LOG_PATH =
'log/MyGpsdClient.log'
- DEFAULT_LOG_FORMAT =
''
- DEFAULT_LOG_TIME_FORMAT =
'%Y-%m-%d %T.%N %z %Z'
- WATCHDOG_STEP =
Check watchdog ten times per second
0.1
- THREAD_NAMES =
Keep displayed names the same length
{ # Keep displayed names the same length MainThread: "MainThread ", SocketInitThread: "SockInitThd", WatchdogThread: "WatchdogThd", ReadThread: "ReadThread " }
- @@logger =
nil
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#host ⇒ Object
Returns the value of attribute host.
-
#last_watch ⇒ Object
readonly
Returns the value of attribute last_watch.
-
#log_format ⇒ Object
Returns the value of attribute log_format.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#log_path ⇒ Object
Returns the value of attribute log_path.
-
#log_progname ⇒ Object
Returns the value of attribute log_progname.
-
#log_time_format ⇒ Object
Returns the value of attribute log_time_format.
-
#min_speed ⇒ Object
Returns the value of attribute min_speed.
-
#msg_counts ⇒ Object
readonly
Returns the value of attribute msg_counts.
-
#port ⇒ Object
Returns the value of attribute port.
-
#readthread ⇒ Object
readonly
Returns the value of attribute readthread.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#socket_init_thread ⇒ Object
readonly
Returns the value of attribute socket_init_thread.
-
#socket_ready ⇒ Object
readonly
Returns the value of attribute socket_ready.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#watchdog_count ⇒ Object
readonly
Returns the value of attribute watchdog_count.
-
#watchdog_euthanized ⇒ Object
Returns the value of attribute watchdog_euthanized.
-
#watchdog_fired_count ⇒ Object
readonly
Returns the value of attribute watchdog_fired_count.
-
#watchdog_force ⇒ Object
Returns the value of attribute watchdog_force.
-
#watchdog_max ⇒ Object
Returns the value of attribute watchdog_max.
-
#watchdogthread ⇒ Object
readonly
Returns the value of attribute watchdogthread.
Instance Method Summary collapse
-
#initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, watch: DEFAULT_WATCH, log_level: DEFAULT_LOG_LEVEL) ⇒ MyGpsdClient
constructor
A simple gpsd client that dump’s json objects contianing all info received from the gpsd deamon you need to at least setup either the raw callback (on_raw_change) or position callback (on_position_change) to use GPSD2JSON.
- #log_marker(level: 'debug', msg: "Log Marker") ⇒ Object
- #on_raw_change(options: {}, &block) ⇒ Object
- #on_raw_send(options: {}, &block) ⇒ Object
Constructor Details
#initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, watch: DEFAULT_WATCH, log_level: DEFAULT_LOG_LEVEL) ⇒ MyGpsdClient
A simple gpsd client that dump’s json objects contianing all info received from the gpsd deamon 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. gps = GPSD2JSON.new() gps.on_satellites_change { |sats| STDERR.puts “found #MyGpsdClient.satssats.length satellites, of which #sat } active” } gps.on_position_change { |pos| STDERR.puts “lat: #'lat', lng: #'lon', alt: #'alt', speed: #'speed' at #'time', which is #- pos.to_time) * 1000ms old” } gps.start #when done gps.stop gps = GPSD2JSON.new() gps.on_raw_change { |raw| STDERR.puts raw.inspect } gps.start #when done gps.stop
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/my_gpsd_client.rb', line 53 def initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, watch: DEFAULT_WATCH, log_level: DEFAULT_LOG_LEVEL) @version = MyGpsdClient_version::VERSION @host = host @port = port @last_watch = watch @log_level = log_level @log_path = DEFAULT_LOG_PATH @log_format = DEFAULT_LOG_FORMAT @log_time_format = DEFAULT_LOG_TIME_FORMAT @log_progname = DEFAULT_LOG_PROGNAME @socket = nil @socket_ready = false @readthread = nil @socket_init_thread = nil @watchdog_thread = nil @watchdog_count = 0.0 @watchdog_max = DEFAULT_WATCHDOG_MAX @watchdog_fired_count = 0 @watchdog_force = false @watchdog_euthanized = false @min_speed = 0 # speed needs to be higher than this to make the gps info count @last = nil #last gps info @sats = nil # last satellites info @sent_raw_callback = nil @json_raw_callback = nil @json_pos_callback = nil @json_sat_callback = nil @json_pps_callback = nil @json_unk_callback = nil @msg_counts = {wtch: 0, ver: 0, tpv: 0, sky: 0, gst: 0, att: 0, toff: 0, pol: 0, pps: 0, dev: 0, devs: 0, err: 0, unk: 0} @logger = new_logger path: @log_path, progname: @log_progname, time_format: @log_time_format, level: @log_level my_logger level: 'info', msg: "MyGpsdClient Gem - Version: #{@version}" end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def command @command end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def host @host end |
#last_watch ⇒ Object (readonly)
Returns the value of attribute last_watch.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def last_watch @last_watch end |
#log_format ⇒ Object
Returns the value of attribute log_format.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def log_format @log_format end |
#log_level ⇒ Object
Returns the value of attribute log_level.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def log_level @log_level end |
#log_path ⇒ Object
Returns the value of attribute log_path.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def log_path @log_path end |
#log_progname ⇒ Object
Returns the value of attribute log_progname.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def log_progname @log_progname end |
#log_time_format ⇒ Object
Returns the value of attribute log_time_format.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def log_time_format @log_time_format end |
#min_speed ⇒ Object
Returns the value of attribute min_speed.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def min_speed @min_speed end |
#msg_counts ⇒ Object (readonly)
Returns the value of attribute msg_counts.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def msg_counts @msg_counts end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def port @port end |
#readthread ⇒ Object (readonly)
Returns the value of attribute readthread.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def readthread @readthread end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def socket @socket end |
#socket_init_thread ⇒ Object (readonly)
Returns the value of attribute socket_init_thread.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def socket_init_thread @socket_init_thread end |
#socket_ready ⇒ Object (readonly)
Returns the value of attribute socket_ready.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def socket_ready @socket_ready end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def version @version end |
#watchdog_count ⇒ Object (readonly)
Returns the value of attribute watchdog_count.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def watchdog_count @watchdog_count end |
#watchdog_euthanized ⇒ Object
Returns the value of attribute watchdog_euthanized.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def watchdog_euthanized @watchdog_euthanized end |
#watchdog_fired_count ⇒ Object (readonly)
Returns the value of attribute watchdog_fired_count.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def watchdog_fired_count @watchdog_fired_count end |
#watchdog_force ⇒ Object
Returns the value of attribute watchdog_force.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def watchdog_force @watchdog_force end |
#watchdog_max ⇒ Object
Returns the value of attribute watchdog_max.
8 9 10 |
# File 'lib/my_gpsd_client.rb', line 8 def watchdog_max @watchdog_max end |
#watchdogthread ⇒ Object (readonly)
Returns the value of attribute watchdogthread.
10 11 12 |
# File 'lib/my_gpsd_client.rb', line 10 def watchdogthread @watchdogthread end |
Instance Method Details
#log_marker(level: 'debug', msg: "Log Marker") ⇒ Object
132 133 134 |
# File 'lib/my_gpsd_client.rb', line 132 def log_marker level: 'debug', msg: "Log Marker" my_logger level: level, msg: "~~~~~~~~~~~~~~~~~~~~~~~ #{msg} ~~~~~~~~~~~~~~~~~~~~~~~" end |
#on_raw_change(options: {}, &block) ⇒ Object
142 143 144 |
# File 'lib/my_gpsd_client.rb', line 142 def on_raw_change(options:{}, &block) @json_raw_callback = block end |
#on_raw_send(options: {}, &block) ⇒ Object
136 137 138 |
# File 'lib/my_gpsd_client.rb', line 136 def on_raw_send(options:{}, &block) @sent_raw_callback = block end |