From a714db78a9ed2740fae65f624a098624ab7a5c10 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Fri, 26 Oct 2018 15:04:49 -0600 Subject: [PATCH 1/3] Map tgts to interfaces in Replay when loading config --- .../tools/cmd_tlm_server/cmd_tlm_server.rb | 25 ++++++++++++++++--- .../cmd_tlm_server/cmd_tlm_server_gui.rb | 7 +++--- lib/cosmos/tools/cmd_tlm_server/routers.rb | 2 ++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb index 2c47b7e14..14e025294 100644 --- a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +++ b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb @@ -20,7 +20,6 @@ require 'cosmos/tools/cmd_tlm_server/replay_backend' module Cosmos - # Provides the interface for all applications to get the latest telemetry and # to send commands. class CmdTlmServer @@ -126,6 +125,9 @@ def self.meta_callback=(meta_callback) # receive data. This is useful for testing scripts when actual hardware # is not available. # @param mode [Symbol] :CMD_TLM_SERVER or :REPLAY - Defines overall mode + # @param replay_routers [Boolean] Whether to keep existing routers when starting + # the server in REPLAY mode. Default is false which means to clear all + # existing routers and simply create the preidentified routers. def initialize( config_file = DEFAULT_CONFIG_FILE, production = false, @@ -218,16 +220,31 @@ def initialize( @routers.add_preidentified('PREIDENTIFIED_ROUTER', System.ports['CTS_PREIDENTIFIED']) @routers.add_cmd_preidentified('PREIDENTIFIED_CMD_ROUTER', System.ports['CTS_CMD_ROUTER']) else + # Create dummy interface for Replay so we can attach the preidentified routers to it. + # This is needed because interfaces are not mapped to targets when loading a saved_config. + # Since interfaces are used to access the routers, nothing is send out the preidentified + # interface port and TlmGrapher (most notably) does not work. + @replay_interface = Interface.new + @replay_interface.name = "REPLAY" @routers.all.clear unless replay_routers - @routers.add_preidentified('PREIDENTIFIED_ROUTER', System.ports['REPLAY_PREIDENTIFIED']) - @routers.add_cmd_preidentified('PREIDENTIFIED_CMD_ROUTER', System.ports['REPLAY_CMD_ROUTER']) + @replay_interface.routers << @routers.add_preidentified('PREIDENTIFIED_ROUTER', System.ports['REPLAY_PREIDENTIFIED']) + @replay_interface.cmd_routers << @routers.add_cmd_preidentified('PREIDENTIFIED_CMD_ROUTER', System.ports['REPLAY_CMD_ROUTER']) end System.telemetry.limits_change_callback = method(:limits_change_callback) @routers.start start(production) end - end # end def initialize + end + + # Map any targets without interfaces to the dummy replay interface. + # Targets will only have an interface already mapped if the replay_routers + # flag was passed to the server. + def map_targets_to_interfaces + System.targets.each do |name, target| + target.interface = @replay_interface unless target.interface + end + end # Properly shuts down the command and telemetry server by stoping the # JSON-RPC server, background tasks, routers, and interfaces. Also kills diff --git a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb index c7929484d..1c414eda2 100644 --- a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +++ b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb @@ -75,7 +75,6 @@ def self.run(option_parser = nil, options = nil) end module Cosmos - # Implements the GUI functions of the Command and Telemetry Server. All the # QT calls are implemented here. The non-GUI functionality is contained in # the CmdTlmServer class. @@ -271,6 +270,7 @@ def initialize_central_widget end def config_change_callback + CmdTlmServer.instance.map_targets_to_interfaces start(nil) end @@ -647,6 +647,5 @@ def self.run(option_parser = nil, options = nil) super(option_parser, options) end end - - end # class CmdTlmServerGui -end # module Cosmos + end +end diff --git a/lib/cosmos/tools/cmd_tlm_server/routers.rb b/lib/cosmos/tools/cmd_tlm_server/routers.rb index 95acb051a..3c2f2b3b1 100644 --- a/lib/cosmos/tools/cmd_tlm_server/routers.rb +++ b/lib/cosmos/tools/cmd_tlm_server/routers.rb @@ -49,6 +49,7 @@ def add_preidentified(router_name, port) router.interfaces << interface interface.routers << router end + router end # Adds a Preidentified command router to the system with given name and port. @@ -72,6 +73,7 @@ def add_cmd_preidentified(cmd_router_name, port) @config.interfaces.each do |interface_name, interface| interface.cmd_routers << cmd_router end + cmd_router end # Recreate a router with new initialization parameters From 8195a893e64a945b7ee32a1b8dfca5ce0f07273b Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Tue, 6 Nov 2018 10:39:26 -0700 Subject: [PATCH 2/3] Rename map method & try to map existing interfaces to targets --- lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb | 11 ++++++++++- lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb index 14e025294..6d955ede4 100644 --- a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +++ b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb @@ -240,7 +240,16 @@ def initialize( # Map any targets without interfaces to the dummy replay interface. # Targets will only have an interface already mapped if the replay_routers # flag was passed to the server. - def map_targets_to_interfaces + def replay_map_targets_to_interfaces + # Try to map existing interfaces to targets + if @interfaces + @interfaces.all.each do |name, interface| + interface.target_names.each do |target| + System.targets[target] = interface + end + end + end + # If any remaing targets don't have an interface map to the @replay_interface System.targets.each do |name, target| target.interface = @replay_interface unless target.interface end diff --git a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb index 1c414eda2..80ddca8c2 100644 --- a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +++ b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb @@ -270,7 +270,7 @@ def initialize_central_widget end def config_change_callback - CmdTlmServer.instance.map_targets_to_interfaces + CmdTlmServer.instance.replay_map_targets_to_interfaces start(nil) end From 3c4b71e73e0b2de16009c85167a9ead8ecd8dc59 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Tue, 13 Nov 2018 12:15:42 -0700 Subject: [PATCH 3/3] Fix mapping interface --- lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb index 6d955ede4..558695a77 100644 --- a/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +++ b/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb @@ -245,7 +245,7 @@ def replay_map_targets_to_interfaces if @interfaces @interfaces.all.each do |name, interface| interface.target_names.each do |target| - System.targets[target] = interface + System.targets[target].interface = interface end end end