Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map tgts to interfaces in Replay when loading config #910

Merged
3 commits merged into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be named differently to show it is only replay mode. Also, an attempt needs to be made to remap targets to interfaces using Interface#target_names. Only after that fails should the target get mapped to @replay_interface.

Overall really nice clean fix for this though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanatball I tried to address this but never saw any existing interfaces being mapped. Not sure if this is what you wanted.

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
Expand Down
7 changes: 3 additions & 4 deletions lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -271,6 +270,7 @@ def initialize_central_widget
end

def config_change_callback
CmdTlmServer.instance.map_targets_to_interfaces
start(nil)
end

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/cosmos/tools/cmd_tlm_server/routers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down