Class: Cosmos::Interfaces
- Inherits:
-
Connections
- Object
- Connections
- Cosmos::Interfaces
- Defined in:
- lib/cosmos/tools/cmd_tlm_server/interfaces.rb
Overview
Controls the interfaces as defined in the Command/Telemetry configuration file. Interfaces provide the connection between the Command and Telemetry Server and targets. They send command packets to and receive telemetry packets from targets.
Instance Method Summary collapse
-
#initialize(cmd_tlm_server_config, identified_packet_callback = nil) ⇒ Interfaces
constructor
A new instance of Interfaces.
-
#map_all_targets(interface_name) ⇒ Object
Determines all targets in the system and maps them to the given interface.
-
#map_target(target_name, interface_name) ⇒ Object
Maps a target to an interface and unmaps the target from its existing interface if present.
-
#recreate(interface_name, *params) ⇒ Object
Recreate an interface with new initialization parameters.
Methods inherited from Connections
#all, #clear_counters, #connect, #disconnect, #names, #start, #start_raw_logging, #state, #stop, #stop_raw_logging
Constructor Details
#initialize(cmd_tlm_server_config, identified_packet_callback = nil) ⇒ Interfaces
Returns a new instance of Interfaces.
25 26 27 28 |
# File 'lib/cosmos/tools/cmd_tlm_server/interfaces.rb', line 25 def initialize(cmd_tlm_server_config, identified_packet_callback = nil) super(:INTERFACES, cmd_tlm_server_config) @identified_packet_callback = identified_packet_callback end |
Instance Method Details
#map_all_targets(interface_name) ⇒ Object
Determines all targets in the system and maps them to the given interface
33 34 35 36 37 38 39 40 |
# File 'lib/cosmos/tools/cmd_tlm_server/interfaces.rb', line 33 def map_all_targets(interface_name) interface = @config.interfaces[interface_name.upcase] raise "Unknown interface: #{interface_name}" unless interface System.targets.each do |target_name, target| target.interface = interface interface.target_names << target_name end end |
#map_target(target_name, interface_name) ⇒ Object
Maps a target to an interface and unmaps the target from its existing interface if present.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cosmos/tools/cmd_tlm_server/interfaces.rb', line 48 def map_target(target_name, interface_name) # Find the new interface new_interface = @config.interfaces[interface_name.upcase] raise "Unknown interface: #{interface_name}" unless new_interface # Find the target target = System.targets[target_name.upcase] raise "Unknown target: #{target_name}" unless target # Find the old interface old_interface = System.targets[target_name.upcase].interface # Remove target from old interface old_interface.target_names.delete(target_name.upcase) if old_interface # Add target to new interface new_interface.target_names << target_name.upcase unless new_interface.target_names.include? target_name.upcase # Update targets System.targets[target_name.upcase].interface = new_interface end |
#recreate(interface_name, *params) ⇒ Object
Recreate an interface with new initialization parameters
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 |
# File 'lib/cosmos/tools/cmd_tlm_server/interfaces.rb', line 75 def recreate(interface_name, *params) interface = @config.interfaces[interface_name.upcase] raise "Unknown interface: #{interface_name}" unless interface # Build New Interface new_interface = interface.class.new(*params) interface.copy_to(new_interface) # Replace interface for targets System.targets.each do |target_name, target| target.interface = new_interface if target.interface == interface end # Replace interface for routers @config.routers.each do |router_name, router| if router.interfaces.include?(interface) router.interfaces.delete(interface) router.interfaces << new_interface end end # Replace interface in @interfaces array @config.interfaces[interface_name.upcase] = new_interface # Make sure there is no thread stop_thread(interface) return new_interface end |