Class: MyGpsdClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Examples:

Easy setup

Quickest raw mode, just dumping all json packets as the are



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

#commandObject

Returns the value of attribute command.



8
9
10
# File 'lib/my_gpsd_client.rb', line 8

def command
  @command
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/my_gpsd_client.rb', line 8

def host
  @host
end

#last_watchObject (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_formatObject

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_levelObject

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_pathObject

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_prognameObject

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_formatObject

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_speedObject

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_countsObject (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

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/my_gpsd_client.rb', line 8

def port
  @port
end

#readthreadObject (readonly)

Returns the value of attribute readthread.



10
11
12
# File 'lib/my_gpsd_client.rb', line 10

def readthread
  @readthread
end

#socketObject (readonly)

Returns the value of attribute socket.



10
11
12
# File 'lib/my_gpsd_client.rb', line 10

def socket
  @socket
end

#socket_init_threadObject (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_readyObject (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

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/my_gpsd_client.rb', line 10

def version
  @version
end

#watchdog_countObject (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_euthanizedObject

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_countObject (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_forceObject

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_maxObject

Returns the value of attribute watchdog_max.



8
9
10
# File 'lib/my_gpsd_client.rb', line 8

def watchdog_max
  @watchdog_max
end

#watchdogthreadObject (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

Parameters:

  • options (Object) (defaults to: {})

    Possible options to pass (not used yet)

  • block (Block)

    Block to call when new json object comes from gpsd



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