Class: Cosmos::TabbedPlotsRealtimeThread

Inherits:
InterfaceThread show all
Defined in:
lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb

Overview

Thread used to gather telemetry in realtime and process it using a TabbedPlotsDefinition

Constant Summary

Constants inherited from InterfaceThread

InterfaceThread::UNKNOWN_BYTES_TO_PRINT

Instance Attribute Summary

Attributes inherited from InterfaceThread

#connection_failed_callback, #connection_lost_callback, #connection_success_callback, #fatal_exception_callback, #identified_packet_callback

Instance Method Summary collapse

Methods inherited from InterfaceThread

#start, #stop

Constructor Details

#initialize(tabbed_plots_config, connection_success_callback = nil, connection_failed_callback = nil, connection_lost_callback = nil, fatal_exception_callback = nil, replay_mode = false) ⇒ TabbedPlotsRealtimeThread

Create a new TabbedPlotsRealtimeThread



20
21
22
23
24
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
53
54
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb', line 20

def initialize(tabbed_plots_config, connection_success_callback = nil, connection_failed_callback = nil, connection_lost_callback = nil, fatal_exception_callback = nil, replay_mode = false)
  if replay_mode
    interface = TcpipClientInterface.new(System.connect_hosts['REPLAY_PREIDENTIFIED'], nil, System.ports['REPLAY_PREIDENTIFIED'], nil, nil, 'PREIDENTIFIED')
  else
    interface = TcpipClientInterface.new(System.connect_hosts['CTS_PREIDENTIFIED'], nil, System.ports['CTS_PREIDENTIFIED'], nil, tabbed_plots_config.cts_timeout, 'PREIDENTIFIED')
  end
  super(interface)

  @queue = Queue.new
  @tabbed_plots_config = tabbed_plots_config

  # Connect callbacks
  self.identified_packet_callback = method(:received_packet_callback)
  self.connection_success_callback = connection_success_callback
  self.connection_failed_callback = connection_failed_callback
  self.connection_lost_callback = connection_lost_callback
  self.fatal_exception_callback = fatal_exception_callback

  @process_thread = Thread.new do
    begin
      loop do
        packet = @queue.pop
        break unless packet
        @tabbed_plots_config.process_packet(packet)
      end
    rescue Exception => error
      if self.fatal_exception_callback
        self.fatal_exception_callback.call(error)
      end
    end
  end

  # Start interface thread
  start()
end

Instance Method Details

#graceful_killObject



69
70
71
72
73
74
75
76
77
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb', line 69

def graceful_kill
  # Allow the callbacks a chance to update the GUI so that they can die gracefully
  if defined? Qt and Thread.current == Thread.main
    5.times do
      Qt::CoreApplication.instance.processEvents
      sleep(0.05)
    end
  end
end

#killObject

Kills the realtime thread



62
63
64
65
66
67
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb', line 62

def kill
  @queue << nil
  stop()
  Cosmos.kill_thread(self, @process_thread)
  @process_thread = nil
end

#received_packet_callback(packet) ⇒ Object

Callback to the system definition when a packet is received



57
58
59
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb', line 57

def received_packet_callback(packet)
  @queue << packet.clone
end