Class: GPS_PVT::Ntrip
- Inherits:
-
Net::HTTP
- Object
- Net::HTTP
- GPS_PVT::Ntrip
- Defined in:
- lib/gps_pvt/ntrip.rb
Defined Under Namespace
Modules: MountPoints
Constant Summary collapse
- SOURCE_TBL_ITEMS =
{ :STR => [ :type, :mountpoint, :identifier, :format, :format_details, :carrier, :nav_system, :network, :country, :latitude, :longitude, :nmea, :solution, :generator, :compression, :authentication, :fee, :bitrate], :CAS => [ :type, :host, :port, :identifier, :operator, :nmea, :country, :latitude, :longitude, :fallback_host, :fallback_ip], :NET => [ :type, :identifier, :operator, :authentication, :fee, :web_net, :web_str, :web_reg], }
Class Method Summary collapse
Instance Method Summary collapse
- #generate_request(path, header) ⇒ Object
- #get_data(mount_point, header = {}, &b) ⇒ Object
- #get_source_table(header = {}, &b) ⇒ Object
- #on_connect ⇒ Object
Class Method Details
.parse_source_table(str) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gps_pvt/ntrip.rb', line 61 def Ntrip.parse_source_table(str) res = {} str.lines.each{|line| values = line.chomp.split(/\s*;\s*/) type = values[0].to_sym next unless keys = SOURCE_TBL_ITEMS[type] next unless (values.size >= keys.size) entry = Hash[*(keys.zip(values).flatten(1))] entry[:misc] = values[(keys.size)..-1] if values.size > keys.size (res[type] ||= []) << entry } res.define_singleton_method(:mount_points, lambda{ Hash[*((self[:STR] || []).collect{|entry| [entry[:mountpoint], entry] }.flatten(1))].extend(MountPoints) }) res end |
Instance Method Details
#generate_request(path, header) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gps_pvt/ntrip.rb', line 79 def generate_request(path, header) req = Net::HTTP::Get.new(path, { 'User-Agent' => "GPS_PVT NTRIP client/#{GPS_PVT::VERSION}", 'Accept' => '*/*', 'Ntrip-Version' => 'Ntrip/2.0', }.merge(header.select{|k, v| k.kind_of?(String)})) header.each{|k, v| next unless k.kind_of?(Symbol) req.send(k, *v) } req end |
#get_data(mount_point, header = {}, &b) ⇒ Object
94 95 96 97 98 |
# File 'lib/gps_pvt/ntrip.rb', line 94 def get_data(mount_point, header = {}, &b) request(generate_request("/#{mount_point}", header)){|res| res.read_body(&b) } end |
#get_source_table(header = {}, &b) ⇒ Object
91 92 93 |
# File 'lib/gps_pvt/ntrip.rb', line 91 def get_source_table(header = {}, &b) (b || proc{|str| Ntrip.parse_source_table(str)}).call(request(generate_request('/', header)).read_body) end |
#on_connect ⇒ Object
30 31 32 33 |
# File 'lib/gps_pvt/ntrip.rb', line 30 def on_connect super @socket.define_singleton_method(:ntrip){true} end |