Class: GPS_PVT::SUPL_Client
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #get_assisted_data ⇒ Object
-
#initialize(host, opts = {}) ⇒ SUPL_Client
constructor
A new instance of SUPL_Client.
Constructor Details
#initialize(host, opts = {}) ⇒ SUPL_Client
Returns a new instance of SUPL_Client.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gps_pvt/supl.rb', line 14 def initialize(host, opts = {}) @host = host @opts = { :port => 7275, :debug => 0, :protocol => [:lpp, :rrlp], :req_data => [:ephemeris], # :almanac :timeout => 60, # [sec] }.merge(opts) end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
12 13 14 |
# File 'lib/gps_pvt/supl.rb', line 12 def opts @opts end |
Instance Method Details
#get_assisted_data ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gps_pvt/supl.rb', line 25 def get_assisted_data begin timeout = @opts[:timeout] host = timeout ? Resolv::getaddress(@host).to_s : @host @socket = TCPSocket::new(host, @opts[:port]) if @opts.include?(:ssl) ? @opts[:ssl] : (@opts[:port] == 7275) then @socket = OpenSSL::SSL::SSLSocket::new(@socket) @socket.connect end @socket.define_singleton_method(:read){|bytes| buf = String::new while (rem = (bytes - buf.size)) > 0 begin buf << read_nonblock(rem) rescue IO::WaitReadable break unless IO.select([self], nil, nil, timeout) end end buf } if timeout send_supl_start recv_supl_response send_supl_pos_init recv_supl_pos ensure @socket.close unless @socket.closed? end end |