Class: Argus::NavStreamer
- Inherits:
-
Object
- Object
- Argus::NavStreamer
- Defined in:
- lib/argus/nav_streamer.rb
Overview
NavStreamer State Transitions:
State Trigger Next Action —— ————– —- —————– init start wait reconnect
wait short_timeout wait request_nav_data wait long_timeout wait reconnect wait received_data run –
run short_timeout run – run long_timeout wait reconnect run received_data run –
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ NavStreamer
constructor
A new instance of NavStreamer.
- #long_timeout ⇒ Object
- #receive_data ⇒ Object
- #received_data ⇒ Object
- #short_timeout ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ NavStreamer
Returns a new instance of NavStreamer.
22 23 24 25 26 27 28 29 30 |
# File 'lib/argus/nav_streamer.rb', line 22 def initialize(opts={}) @state = :init @socket = nil @remote_host = opts.fetch(:remote_host) @local_host = opts[:local_host] || '0.0.0.0' @port = opts[:port] || 5554 @socket_class = opts[:UDPSocket] || UDPSocket start_timer unless opts[:disable_timer] end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
20 21 22 |
# File 'lib/argus/nav_streamer.rb', line 20 def state @state end |
Instance Method Details
#long_timeout ⇒ Object
43 44 45 46 47 48 |
# File 'lib/argus/nav_streamer.rb', line 43 def long_timeout if @state == :wait || @state == :run @state = :wait reconnect end end |
#receive_data ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/argus/nav_streamer.rb', line 50 def receive_data data, from = @socket.recvfrom(1024) if data.unpack("V").first == 0x55667788 received_data NavData.new(data) else nil end end |
#received_data ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/argus/nav_streamer.rb', line 60 def received_data if state == :wait || state == :run @state = :run @long_flag = false @short_flag = false end end |
#short_timeout ⇒ Object
37 38 39 40 41 |
# File 'lib/argus/nav_streamer.rb', line 37 def short_timeout if state == :wait request_nav_data end end |
#start ⇒ Object
32 33 34 35 |
# File 'lib/argus/nav_streamer.rb', line 32 def start @state = :wait reconnect end |