Class: Argus::NavStreamer

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ 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

#stateObject (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_timeoutObject


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_dataObject


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_dataObject


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_timeoutObject


37
38
39
40
41
# File 'lib/argus/nav_streamer.rb', line 37

def short_timeout
  if state == :wait
    request_nav_data
  end
end

#startObject


32
33
34
35
# File 'lib/argus/nav_streamer.rb', line 32

def start
  @state = :wait
  reconnect
end