Class: Cosmos::Screen::Widgets
- Defined in:
- lib/cosmos/tools/tlm_viewer/screen.rb
Constant Summary collapse
- @@closing_all =
Flag to indicate all screens should close
false
Instance Attribute Summary collapse
-
#invalid ⇒ Object
Returns the value of attribute invalid.
-
#item ⇒ Object
Returns the value of attribute item.
-
#items ⇒ Object
Returns the value of attribute items.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#named ⇒ Object
Returns the value of attribute named.
-
#non_item ⇒ Object
Returns the value of attribute non_item.
-
#polling_period ⇒ Object
Returns the value of attribute polling_period.
-
#value_types ⇒ Object
Returns the value of attribute value_types.
Class Method Summary collapse
Instance Method Summary collapse
- #add_widget(klass, parameters, widget, widget_name, substitute, original_target_name, force_substitute) ⇒ Object
- #graceful_kill ⇒ Object
-
#initialize(screen, mode) ⇒ Widgets
constructor
A new instance of Widgets.
- #process_settings ⇒ Object
- #shutdown ⇒ Object
- #start_updates ⇒ Object
- #update_gui ⇒ Object
- #update_limits_set ⇒ Object
- #widgets ⇒ Object
Constructor Details
#initialize(screen, mode) ⇒ Widgets
Returns a new instance of Widgets.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 36 def initialize(screen, mode) @screen = screen # The telemetry viewer mode. Must be :REALTIME or basically anything else? @mode = mode # Hash of only the named widgets identifed by the NAMED_WIDGET keyword @named = {} # Array of all widgets which take a value @item = [] # Array of all widgets which do NOT take a value @non_item = [] # Array of all the invalid items detected while parsing the config file @invalid = [] # Array of all the items used by the item_widgets @items = [] # Array of all the value types associated with the items @value_types = [] # Latest limits set returned by the value update thread @limits_set = :DEFAULT # Current limits set which is compared against the one returned by the # value update thread @current_limits_set = :DEFAULT # Whether the value update thread is alive and running @alive = true # Values returned from the value update thread which are used to # update all the item_widgets @values = nil # Limits states returned from the value update thread which are used to # update all the item_widgets @limits_states = nil # Mutex used to synchronize the value update thread and updating the GUI @mutex = Mutex.new # Polling period of the value update thread @polling_period = nil # The value update thread instance @value_thread = nil # Used to gracefully break out of the value thread @value_sleeper = Sleeper.new end |
Instance Attribute Details
#invalid ⇒ Object
Returns the value of attribute invalid.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def invalid @invalid end |
#item ⇒ Object
Returns the value of attribute item.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def item @item end |
#items ⇒ Object
Returns the value of attribute items.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def items @items end |
#mode ⇒ Object
Returns the value of attribute mode.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def mode @mode end |
#named ⇒ Object
Returns the value of attribute named.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def named @named end |
#non_item ⇒ Object
Returns the value of attribute non_item.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def non_item @non_item end |
#polling_period ⇒ Object
Returns the value of attribute polling_period.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def polling_period @polling_period end |
#value_types ⇒ Object
Returns the value of attribute value_types.
30 31 32 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 30 def value_types @value_types end |
Class Method Details
.closing_all=(value) ⇒ Object
32 33 34 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 32 def self.closing_all= (value) @@closing_all = value end |
Instance Method Details
#add_widget(klass, parameters, widget, widget_name, substitute, original_target_name, force_substitute) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 85 def (klass, parameters, , , substitute, original_target_name, force_substitute) # Add to item or non_item widgets if klass.takes_value? if substitute and (original_target_name == parameters[0].upcase or force_substitute) @items << [substitute, parameters[1], parameters[2]] else @items << [parameters[0], parameters[1], parameters[2]] end @value_types << .value_type @item << else @non_item << end # Add to named widgets if necessary @named[] = if end |
#graceful_kill ⇒ Object
197 198 199 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 197 def graceful_kill @value_sleeper.cancel end |
#process_settings ⇒ Object
79 80 81 82 83 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 79 def process_settings ().each do || .process_settings end end |
#shutdown ⇒ Object
187 188 189 190 191 192 193 194 195 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 187 def shutdown @alive = false Cosmos.kill_thread(self, @value_thread) # Shutdown All Widgets ().each do || .shutdown() end end |
#start_updates ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 112 def start_updates @value_thread = Thread.new do begin while(true) break if @@closing_all time = Time.now begin # Gather item values for value widgets if @mode == :REALTIME values, limits_states, limits_settings, limits_set = get_tlm_values(@items, @value_types) index = 0 @items.each do |target_name, packet_name, item_name| begin System.limits.set(target_name, packet_name, item_name, limits_settings[index][0], limits_settings[index][1], limits_settings[index][2], limits_settings[index][3], limits_settings[index][4], limits_settings[index][5], limits_set) if limits_settings[index] rescue # This can fail if we missed setting the DEFAULT limits set earlier - Oh well end index += 1 end end @mutex.synchronize do @values = values @limits_states = limits_states @limits_set = limits_set end rescue DRb::DRbConnError break if @@closing_all break if @value_sleeper.sleep(1) next end Qt.execute_in_main_thread {update_gui()} if @alive and (@mode == :REALTIME) delta = Time.now - time break if @@closing_all if @polling_period - delta > 0 break if @value_sleeper.sleep(@polling_period - delta) else break if @value_sleeper.sleep(0.1) # Minimum delay end end rescue Exception => error @alive = false Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(@screen, error, "Screen - Value Update Thread", false)} Thread.exit end end end |
#update_gui ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 161 def update_gui begin if @alive # Handle change in limits set update_limits_set() # Update widgets with values and limits_states @mutex.synchronize do (0..(@values.length - 1)).each do |index| @item[index].limits_state = @limits_states[index] @item[index].value = @values[index] end end # Update non_item widgets @non_item.each do || . end end rescue Exception => error @alive = false Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(@screen, error, "Screen - update_gui", false)} Thread.exit end end |
#update_limits_set ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 103 def update_limits_set if @limits_set != @current_limits_set @current_limits_set = @limits_set @item.each do || .limits_set = @current_limits_set end end end |
#widgets ⇒ Object
75 76 77 |
# File 'lib/cosmos/tools/tlm_viewer/screen.rb', line 75 def @item + @non_item end |