Class: Cosmos::RawDialog

Inherits:
Qt::Dialog
  • Object
show all
Defined in:
lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb

Overview

Creates a dialog showing a packet formatted as a binary hex dump

Direct Known Subclasses

CmdRawDialog, TlmRawDialog

Constant Summary collapse

CMD_TYPE =

Constant to indicate a command packet dump

'cmd'
TLM_TYPE =

Constant to indicate a telemetry packet dump

'tlm'
PACKET_UPDATE_PERIOD_MS =

Dialog update period

1000
HEADER =

Header string to display over the dump

"Address   Data                                             Ascii\n"\
"---------------------------------------------------------------------------\n"
@@font =

Returns Font to display the dialog dump (should be monospaced).

Returns:

  • (Qt::Font)

    Font to display the dialog dump (should be monospaced)

nil

Instance Method Summary collapse

Constructor Details

#initialize(parent, type, target_name, packet_name) ⇒ RawDialog

Returns a new instance of RawDialog.

Parameters:

  • parent (Qt::Dialog)

    Parent for the dialog

  • type (String)

    Dialog type which must be 'cmd' or 'tlm'

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet



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
# File 'lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb', line 39

def initialize(parent, type, target_name, packet_name)
  super(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
  raise "RawDialog: Undefined type:#{type}" if (type != CMD_TYPE) && (type != TLM_TYPE)

  @type = type
  @done = false
  @target_name = target_name
  @packet_name = packet_name

  begin
    if @type == CMD_TYPE
      title = "Raw Command Packet: #{target_name} #{packet_name}"
    else
      title = "Raw Telemetry Packet: #{target_name} #{packet_name}"
    end
    setWindowTitle(title)

    @timer = Qt::Timer.new

    overall_layout = Qt::VBoxLayout.new
    top_layout = Qt::HBoxLayout.new
    text_layout = Qt::VBoxLayout.new

    title_label = Qt::Label.new(title)
    text_layout.addWidget(title_label)
    @packet_time = Qt::Label.new("Packet Time: ")
    text_layout.addWidget(@packet_time)
    @received_time = Qt::Label.new("Received Time: ")
    text_layout.addWidget(@received_time)
    top_layout.addLayout(text_layout)
    top_layout.addStretch(1)

    button = Qt::PushButton.new("Pause")
    top_layout.addWidget(button)
    button.connect(SIGNAL('clicked()')) do
      if button.text == "Pause"
        button.setText("Resume")
        @timer.method_missing(:stop)
      else
        button.setText("Pause")
        @timer.method_missing(:start, PACKET_UPDATE_PERIOD_MS)
      end
    end
    overall_layout.addLayout(top_layout)

    @packet_data = Qt::PlainTextEdit.new
    @packet_data.setReadOnly(true)
    @packet_data.setWordWrapMode(Qt::TextOption::NoWrap)
    overall_layout.addWidget(@packet_data)
    if Kernel.is_windows?
      @@font = Cosmos.getFont('Courier', 10) unless @@font
    else
      @@font = Cosmos.getFont('Courier', 14) unless @@font
    end
    @format = @packet_data.currentCharFormat()
    @format.setFont(@@font)
    @packet_data.setCurrentCharFormat(@format)

    connect(@timer, SIGNAL('timeout()'), self, SLOT('packet_update_timeout()'))
    @timer.method_missing(:start, PACKET_UPDATE_PERIOD_MS)
    packet_update_timeout()

    self.setLayout(overall_layout)
    self.resize(700, 280)
    self.show
    self.raise
  rescue DRb::DRbConnError
    # Just do nothing
  end
end

Instance Method Details

#closeEvent(event) ⇒ Object



135
136
137
138
139
# File 'lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb', line 135

def closeEvent(event)
  super(event)
  stop_timer if @timer
  self.dispose
end

#packet_update_timeoutObject

Callback to get the latest packet and update the dialog



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb', line 111

def packet_update_timeout
  if (@type == CMD_TYPE)
    packet = System.commands.packet(@target_name, @packet_name)
  else
    packet = System.telemetry.packet(@target_name, @packet_name)
  end
  packet_data = packet.buffer
  packet_time = packet.packet_time
  @packet_time.setText("Packet Time: #{packet_time.formatted}") if packet_time
  received_time = packet.received_time
  @received_time.setText("Received Time: #{received_time.formatted}") if received_time
  position_x = @packet_data.horizontalScrollBar.value
  position_y = @packet_data.verticalScrollBar.value
  @packet_data.setPlainText(HEADER + packet_data.formatted)
  @packet_data.horizontalScrollBar.setValue(position_x)
  @packet_data.verticalScrollBar.setValue(position_y)
end

#rejectObject



129
130
131
132
133
# File 'lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb', line 129

def reject
  super()
  stop_timer if @timer
  self.dispose
end

#stop_timerObject



141
142
143
144
145
# File 'lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb', line 141

def stop_timer
  @timer.stop
  @timer.dispose
  @timer = nil
end