Class: Cosmos::Routers
- Inherits:
-
Connections
- Object
- Connections
- Cosmos::Routers
- Defined in:
- lib/cosmos/tools/cmd_tlm_server/routers.rb
Overview
Controls the routers as defined in the Command/Telemetry configuration file. Routers are just interfaces which receive command packets from their remote connection and send them out to their interfaces. They receive telemetry packets from their interfaces and send them to their remote connections. This allows them to be intermediaries between an external client and the actual device.
Instance Method Summary collapse
-
#add_preidentified(router_name, port) ⇒ Object
Adds a Preidentified router to the system with given name and port.
-
#initialize(cmd_tlm_server_config) ⇒ Routers
constructor
A new instance of Routers.
-
#recreate(router_name, *params) ⇒ Object
Recreate a router 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) ⇒ Routers
Returns a new instance of Routers.
26 27 28 |
# File 'lib/cosmos/tools/cmd_tlm_server/routers.rb', line 26 def initialize(cmd_tlm_server_config) super(:ROUTERS, cmd_tlm_server_config) end |
Instance Method Details
#add_preidentified(router_name, port) ⇒ Object
Adds a Preidentified router to the system with given name and port. All interfaces defined by the Command/Telemetry configuration are directed to this router for both commands and telemetry.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cosmos/tools/cmd_tlm_server/routers.rb', line 36 def add_preidentified(router_name, port) router_name = router_name.upcase router = TcpipServerInterface.new(port, port, 10.0, nil, 'PREIDENTIFIED') router.name = router_name router.disable_disconnect = true @config.routers[router_name] = router @config.interfaces.each do |interface_name, interface| router.interfaces << interface interface.routers << router end end |
#recreate(router_name, *params) ⇒ Object
Recreate a router with new initialization parameters
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cosmos/tools/cmd_tlm_server/routers.rb', line 53 def recreate(router_name, *params) router = @config.routers[router_name.upcase] raise "Unknown router: #{router_name}" unless router # Build New Router new_router = router.class.new(*params) router.copy_to(new_router) # Remove old router and add new to each interface router.interfaces.each do |interface| interface.routers.delete(router) interface.routers << new_router end # Replace interface in @interfaces array @config.routers[router_name.upcase] = new_router # Make sure there is no thread stop_thread(router) return new_router end |