Skip to content

Commit

Permalink
Merge pull request #447 from BallAerospace/tlm_viewer_clear_all
Browse files Browse the repository at this point in the history
Add clear_all which can also take a target name #433
  • Loading branch information
jmthomas authored May 10, 2017
2 parents 7baaec2 + c7c4b9a commit 4633e63
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
14 changes: 10 additions & 4 deletions lib/cosmos/script/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@ module Script
#######################################

def display(display_name, x_pos = nil, y_pos = nil)
run_tlm_viewer(display_name, "displayed") do |tlm_viewer|
run_tlm_viewer("display", display_name) do |tlm_viewer|
tlm_viewer.display(display_name, x_pos, y_pos)
end
end

def clear(display_name)
run_tlm_viewer(display_name, "cleared") do |tlm_viewer|
run_tlm_viewer("clear", display_name) do |tlm_viewer|
tlm_viewer.clear(display_name)
end
end

def run_tlm_viewer(display_name, action)
def clear_all(target = nil)
run_tlm_viewer("clear_all") do |tlm_viewer|
tlm_viewer.clear_all(target)
end
end

def run_tlm_viewer(action, display_name = '')
tlm_viewer = JsonDRbObject.new "localhost", System.ports['TLMVIEWER_API']
begin
yield tlm_viewer
Expand All @@ -48,7 +54,7 @@ def run_tlm_viewer(display_name, action)
canceled = cosmos_script_sleep(1)
retry unless canceled
end
raise "Unable to Successfully Start Listening Telemetry Viewer: #{display_name} could not be #{action}"
raise "Unable to Successfully Start Listening Telemetry Viewer: Could not #{action} #{display_name}"
rescue Errno::ENOENT
raise "Display Screen File: #{display_name}.txt does not exist"
end
Expand Down
26 changes: 22 additions & 4 deletions lib/cosmos/tools/tlm_viewer/tlm_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def display(display_name, x_pos = nil, y_pos = nil)
def clear(display_name)
TlmViewer.instance.clear(display_name)
end

def clear_all(target = nil)
TlmViewer.instance.clear_all(target)
end
end
end
end
Expand Down Expand Up @@ -125,7 +129,8 @@ def initialize(options)
@json_drb.acl = acl
whitelist = [
'display',
'clear']
'clear',
'clear_all']
@json_drb.method_whitelist = whitelist
begin
@json_drb.start_service "localhost", port, self
Expand Down Expand Up @@ -476,10 +481,23 @@ def display(screen_full_name, x_pos = nil, y_pos = nil)

# Close the specified screen
def clear(screen_full_name)
# Find the specified screen
screen_info = find_screen_info(screen_full_name)
close_screen(find_screen_info(screen_full_name))
end

# Close all screens
def clear_all(target_name = nil)
if target_name
screens = @tlm_viewer_config.screen_infos.values.select do |screen_info|
screen_info.target_name == target_name.upcase
end
raise "Unknown screen target: #{target_name.upcase}" if screens.length == 0
screens.each { |screen_info| close_screen(screen_info) }
else
Qt.execute_in_main_thread(true) { Screen.close_all_screens(self) }
end
end

# Close the screen
def close_screen(screen_info)
Qt.execute_in_main_thread(true) do
begin
screen_info.screen.window.close if screen_info.screen
Expand Down
19 changes: 17 additions & 2 deletions spec/script/tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Cosmos
allow_any_instance_of(Object).to receive(:sleep)
allow_any_instance_of(Object).to receive(:cosmos_script_sleep).and_return(true)
allow(Cosmos).to receive(:run_process)
expect { display("HI") }.to raise_error(RuntimeError, /HI could not be displayed/)
expect { display("HI") }.to raise_error(RuntimeError, /Could not display HI/)
end

it "complains if the screen doesn't exist" do
Expand All @@ -83,7 +83,7 @@ module Cosmos
allow_any_instance_of(Object).to receive(:sleep)
allow_any_instance_of(Object).to receive(:cosmos_script_sleep).and_return(true)
allow(Cosmos).to receive(:run_process)
expect { clear("HI") }.to raise_error(RuntimeError, /HI could not be cleared/)
expect { clear("HI") }.to raise_error(RuntimeError, /Could not clear HI/)
end

it "complains if the screen doesn't exist" do
Expand All @@ -92,6 +92,21 @@ module Cosmos
end
end

describe "clear_all" do
it "closes all telemetry viewer screens" do
allow_any_instance_of(JsonDRbObject).to receive(:clear_all)
clear_all
end

it "complains if unable to start telemetry viewer" do
# Avoid the needless delay by stubbing sleep
allow_any_instance_of(Object).to receive(:sleep)
allow_any_instance_of(Object).to receive(:cosmos_script_sleep).and_return(true)
allow(Cosmos).to receive(:run_process)
expect { clear_all }.to raise_error(RuntimeError, /Could not clear_all/)
end
end

describe "ScriptRunnerFrame methods" do
it "calls various ScriptRunnerFrame methods" do
class Dummy; def method_missing(meth, *args, &block); end; end
Expand Down

0 comments on commit 4633e63

Please sign in to comment.