Class: Cosmos::TlmDetailsDialog

Inherits:
DetailsDialog show all
Defined in:
lib/cosmos/gui/dialogs/tlm_details_dialog.rb

Constant Summary collapse

VALUE_UPDATE_PERIOD_MS =
1000
VALUE_TYPES =
[:RAW, :CONVERTED, :FORMATTED, :WITH_UNITS]

Instance Method Summary collapse

Methods inherited from DetailsDialog

#build_details_layout, #closeEvent, #reject, #show_conversion, #show_data_type, #show_endianness, #show_nil

Constructor Details

#initialize(parent, target_name, packet_name, item_name, packet = nil) ⇒ TlmDetailsDialog

Returns a new instance of TlmDetailsDialog.



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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/cosmos/gui/dialogs/tlm_details_dialog.rb', line 25

def initialize(parent, target_name, packet_name, item_name, packet = nil)
  super(parent, target_name, packet_name, item_name)

  @item_array = [[@target_name, @packet_name, @item_name],
                 [@target_name, @packet_name, @item_name],
                 [@target_name, @packet_name, @item_name],
                 [@target_name, @packet_name, @item_name]]

  begin
    update = false
    if !packet
      update = true
      _, item = System.telemetry.packet_and_item(target_name, packet_name, item_name)
    else
      item = packet.get_item(item_name)
    end

    setWindowTitle("#{@target_name} #{@packet_name} #{@item_name} Details")

    layout = Qt::VBoxLayout.new
    layout.addWidget(Qt::Label.new(tr("#{target_name} #{packet_name} #{item_name}")))

    # Display the item values
    item_values = Qt::GroupBox.new(tr("Item Values"))

    values_layout = Qt::FormLayout.new
    @raw_value = Qt::LineEdit.new
    @raw_value.setReadOnly(true)
    values_layout.addRow(tr("Raw Value:"), @raw_value)
    @hex_raw_value = nil
    @hex_raw_num_digits = 0
    case item.data_type
    when :INT, :UINT
      if item.bit_size >= 0
        @hex_raw_value = Qt::LineEdit.new
        @hex_raw_value.setReadOnly(true)
        @hex_raw_num_digits = (((item.bit_size - 1) / 8) + 1) * 2
        values_layout.addRow(tr("Hex Raw Value:"), @hex_raw_value)
      end
    end
    @converted_value = Qt::LineEdit.new
    @converted_value.setReadOnly(true)
    values_layout.addRow(tr("Converted Value:"), @converted_value)
    @formatted_value = Qt::LineEdit.new
    @formatted_value.setReadOnly(true)
    values_layout.addRow(tr("Formatted Value:"), @formatted_value)
    @formatted_with_units_value = Qt::LineEdit.new
    @formatted_with_units_value.setReadOnly(true)
    values_layout.addRow(tr("Formatted with Units Value:"), @formatted_with_units_value)
    @limits_state = Qt::LineEdit.new
    @limits_state.setReadOnly(true)
    values_layout.addRow(tr("Limits State:"), @limits_state)

    item_values.setLayout(values_layout)
    layout.addWidget(item_values)

    if update
      @timer = Qt::Timer.new
      connect(@timer, SIGNAL('timeout()'), self, SLOT('value_update_timeout()'))
      @timer.method_missing(:start, VALUE_UPDATE_PERIOD_MS)
      value_update_timeout()
    else
      raw_value = packet.read(item_name, :RAW).to_s
      @raw_value.text = raw_value
      set_hex_value(raw_value) if @hex_raw_value
      @converted_value.text = packet.read(item_name, :CONVERTED).to_s
      @formatted_value.text = packet.read(item_name, :FORMATTED).to_s
      @formatted_with_units_value.text = packet.read(item_name, :WITH_UNITS).to_s
    end

    # Display the item details
    item_details = Qt::GroupBox.new(tr("Item Details"))
    item_details.setLayout(build_details_layout(item, :TLM))
    layout.addWidget(item_details)

    # Add the OK button
    ok = Qt::PushButton.new("Ok")
    connect(ok, SIGNAL('clicked()'), self, SLOT('close()'))
    if update
      connect(self, SIGNAL('finished(int)')) do |result|
        @timer.stop
      end
    end
    layout.addWidget(ok)

    self.setLayout(layout)
    self.show
    self.raise
  rescue DRb::DRbConnError
    # Just do nothing
  end
end

Instance Method Details

#set_hex_value(value) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/cosmos/gui/dialogs/tlm_details_dialog.rb', line 190

def set_hex_value(value)
  if Array === value
    text = "["
    value[0..-2].each do |part|
      text << sprintf("0x%0#{@hex_raw_num_digits}X, ", part.to_i)
    end
    text << sprintf("0x%0#{@hex_raw_num_digits}X", value[-1].to_i) if values[-1]
    text << "]"
    @hex_raw_value.text = text
  else
    @hex_raw_value.text = sprintf("0x%0#{@hex_raw_num_digits}X", value.to_i)
  end
end

#value_update_timeoutObject



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
160
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
186
187
188
# File 'lib/cosmos/gui/dialogs/tlm_details_dialog.rb', line 118

def value_update_timeout
  # Check to see that the server is still running. If the user shut down
  # the underlying tool (like PacketViewer for example) the $cmd_tlm_server
  # will be nil.
  unless $cmd_tlm_server
    @timer.stop
    return
  end
  begin
    # Gather updated values
    values, limits_states, limits_settings, limits_set = get_tlm_values(@item_array, VALUE_TYPES)
    if limits_settings[0]
      if @limits_labels[limits_set]
        if limits_settings[0][4] and limits_settings[0][5]
          @limits_labels[limits_set].text = "RL/#{limits_settings[0][0]} YL/#{limits_settings[0][1]} YH/#{limits_settings[0][2]} RH/#{limits_settings[0][3]} GL/#{limits_settings[0][4]} GH/#{limits_settings[0][5]}"
        else
          @limits_labels[limits_set].text = "RL/#{limits_settings[0][0]} YL/#{limits_settings[0][1]} YH/#{limits_settings[0][2]} RH/#{limits_settings[0][3]}"
        end
      elsif @limits_layout
        if limits_settings[0][4] and limits_settings[0][5]
          label = Qt::Label.new("RL/#{limits_settings[0][0]} YL/#{limits_settings[0][1]} YH/#{limits_settings[0][2]} RH/#{limits_settings[0][3]} GL/#{limits_settings[0][4]} GH/#{limits_settings[0][5]}")
        else
          label = Qt::Label.new("RL/#{limits_settings[0][0]} YL/#{limits_settings[0][1]} YH/#{limits_settings[0][2]} RH/#{limits_settings[0][3]}")
        end
        @limits_labels[limits_set] = label
        @limits_layout.addRow(tr("#{limits_set}:"), label)
      end
    end

    # Determine color
    color = nil
    case limits_states[0]
    when :RED, :RED_HIGH
      color = Cosmos::RED
    when :RED_LOW
      color = Cosmos::RED
    when :YELLOW, :YELLOW_HIGH
      color = Cosmos::YELLOW
    when :YELLOW_LOW
      color = Cosmos::YELLOW
    when :GREEN, :GREEN_HIGH
      color = Cosmos::GREEN
    when :GREEN_LOW
      color = Cosmos::GREEN
    when :BLUE
      color = Cosmos::BLUE
    when :STALE
      color = Cosmos::PURPLE
    else
      color = Cosmos::BLACK
    end

    # Update text fields
    @raw_value.setColors(color, Cosmos::WHITE)
    @raw_value.text = values[0].to_s
    if @hex_raw_value
      @hex_raw_value.setColors(color, Cosmos::WHITE)
      set_hex_value(values[0])
    end
    @converted_value.setColors(color, Cosmos::WHITE)
    @converted_value.text = values[1].to_s
    @formatted_value.setColors(color, Cosmos::WHITE)
    @formatted_value.text = values[2].to_s
    @formatted_with_units_value.setColors(color, Cosmos::WHITE)
    @formatted_with_units_value.text = values[3].to_s
    @limits_state.setColors(color, Cosmos::WHITE)
    @limits_state.text = limits_states[0].to_s
  rescue DRb::DRbConnError
    # Just do nothing
  end
end