Class: Cosmos::Interface
- Includes:
- Api
- Defined in:
- lib/cosmos/interfaces/interface.rb
Overview
Defines all the attributes and methods common to all interface classes used by COSMOS.
Direct Known Subclasses
CmdTlmServerInterface, SimulatedTargetInterface, StreamInterface, TcpipServerInterface, UdpInterface
Constant Summary
Constants included from Extract
Extract::SCANNING_REGULAR_EXPRESSION
Instance Attribute Summary collapse
-
#auto_reconnect ⇒ Boolean
Flag indicating if the interface should automatically reconnect after losing connection.
-
#bytes_read ⇒ Integer
The number of bytes read from this interface.
-
#bytes_written ⇒ Integer
The number of bytes written to this interface.
-
#connect_on_startup ⇒ Boolean
Flag indicating if the interface should be connected to on startup.
-
#disable_disconnect ⇒ Boolean
Flag indicating if the user is allowed to disconnect this interface.
-
#interfaces ⇒ Array<Interface>
Array of interfaces to route packets to (when used as a Router).
-
#name ⇒ String
Name of the interface.
-
#num_clients ⇒ Integer
The number of active clients (when used as a Router).
-
#options ⇒ Hash<option name, option values>
Hash of options supplied to interface/router.
-
#packet_log_writer_pairs ⇒ Array
Array of packet logger classes for this interface.
-
#raw_logger_pair ⇒ RawLoggerPair
RawLoggerPair instance or nil.
-
#read_count ⇒ Integer
The number of packets read from this interface.
-
#read_queue_size ⇒ Integer
The number of packets in the read queue (when used as a Router).
-
#reconnect_delay ⇒ Integer[ Delay between reconnect attempts
Integer[ Delay between reconnect attempts.
-
#routers ⇒ Array<Routers>
Array of routers that receive packets read from the interface.
-
#target_names ⇒ Array<String>
Array of target names associated with this interface.
-
#thread ⇒ Thread
Thread reading from the interface.
-
#write_count ⇒ Integer
The number of packets written to this interface.
-
#write_queue_size ⇒ Integer
The number of packets in the write queue (when used as a Router).
Instance Method Summary collapse
-
#connect ⇒ Object
Connects the interface to its target(s).
-
#connected? ⇒ Boolean
Indicates if the interface is connected to its target(s) or not.
-
#copy_to(other_interface) ⇒ Object
Copy settings from this interface to another interface.
-
#disconnect ⇒ Object
Disconnects the interface from its target(s).
-
#initialize ⇒ Interface
constructor
Initialize default attribute values.
-
#post_identify_packet(packet) ⇒ Object
This method is called by the CmdTlmServer after each read packet is identified.
-
#read ⇒ Object
Retrieves the next packet from the interface.
-
#read_allowed? ⇒ Boolean
Whether reading is allowed.
-
#set_option(option_name, option_values) ⇒ Object
Set an interface or router specific option.
-
#start_raw_logging ⇒ Object
Start raw logging for this interface.
-
#stop_raw_logging ⇒ Object
Stop raw logging for this interface.
-
#write(packet) ⇒ Object
Method to send a packet on the interface.
-
#write_allowed? ⇒ Boolean
Whether writing is allowed.
-
#write_raw(data) ⇒ Object
Writes preformatted data onto the interface.
-
#write_raw_allowed? ⇒ Boolean
Whether writing raw data over the interface is allowed.
Methods included from Api
#cmd, #cmd_no_checks, #cmd_no_hazardous_check, #cmd_no_range_check, #cmd_raw, #cmd_raw_no_checks, #cmd_raw_no_hazardous_check, #cmd_raw_no_range_check, #connect_interface, #connect_router, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_limits, #enable_limits_group, #get_cmd_hazardous, #get_cmd_list, #get_cmd_log_filename, #get_cmd_param_list, #get_cmd_time, #get_cmd_value, #get_interface_names, #get_limits, #get_limits_event, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_out_of_limits, #get_overall_limits_state, #get_packet_data, #get_router_names, #get_server_message_log_filename, #get_stale, #get_target_list, #get_tlm_details, #get_tlm_item_list, #get_tlm_list, #get_tlm_log_filename, #get_tlm_packet, #get_tlm_values, #interface_state, #limits_enabled?, #map_target_to_interface, #router_state, #send_raw, #set_limits, #set_limits_set, #set_tlm, #set_tlm_raw, #start_cmd_log, #start_logging, #start_new_server_message_log, #start_raw_logging_interface, #start_raw_logging_router, #start_tlm_log, #stop_cmd_log, #stop_logging, #stop_raw_logging_interface, #stop_raw_logging_router, #stop_tlm_log, #subscribe_limits_events, #subscribe_packet_data, #tlm, #tlm_formatted, #tlm_raw, #tlm_variable, #tlm_with_units, #unsubscribe_limits_events, #unsubscribe_packet_data
Constructor Details
#initialize ⇒ Interface
Initialize default attribute values
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cosmos/interfaces/interface.rb', line 88 def initialize @name = self.class.to_s @target_names = [] @thread = nil @connect_on_startup = true @auto_reconnect = true @reconnect_delay = 5.0 @disable_disconnect = false @packet_log_writer_pairs = [] @raw_logger_pair = RawLoggerPair.new(@name) @routers = [] @read_count = 0 @write_count = 0 @bytes_read = 0 @bytes_written = 0 @num_clients = 0 @read_queue_size = 0 @write_queue_size = 0 @interfaces = [] @read_allowed = true @write_allowed = true @write_raw_allowed = true @options = {} end |
Instance Attribute Details
#auto_reconnect ⇒ Boolean
Returns Flag indicating if the interface should automatically reconnect after losing connection.
37 38 39 |
# File 'lib/cosmos/interfaces/interface.rb', line 37 def auto_reconnect @auto_reconnect end |
#bytes_read ⇒ Integer
Returns The number of bytes read from this interface.
63 64 65 |
# File 'lib/cosmos/interfaces/interface.rb', line 63 def bytes_read @bytes_read end |
#bytes_written ⇒ Integer
Returns The number of bytes written to this interface.
66 67 68 |
# File 'lib/cosmos/interfaces/interface.rb', line 66 def bytes_written @bytes_written end |
#connect_on_startup ⇒ Boolean
Returns Flag indicating if the interface should be connected to on startup.
33 34 35 |
# File 'lib/cosmos/interfaces/interface.rb', line 33 def connect_on_startup @connect_on_startup end |
#disable_disconnect ⇒ Boolean
Returns Flag indicating if the user is allowed to disconnect this interface.
44 45 46 |
# File 'lib/cosmos/interfaces/interface.rb', line 44 def disable_disconnect @disable_disconnect end |
#interfaces ⇒ Array<Interface>
Returns Array of interfaces to route packets to (when used as a Router).
82 83 84 |
# File 'lib/cosmos/interfaces/interface.rb', line 82 def interfaces @interfaces end |
#name ⇒ String
Returns Name of the interface.
23 24 25 |
# File 'lib/cosmos/interfaces/interface.rb', line 23 def name @name end |
#num_clients ⇒ Integer
Returns The number of active clients (when used as a Router).
70 71 72 |
# File 'lib/cosmos/interfaces/interface.rb', line 70 def num_clients @num_clients end |
#options ⇒ Hash<option name, option values>
Returns Hash of options supplied to interface/router.
85 86 87 |
# File 'lib/cosmos/interfaces/interface.rb', line 85 def @options end |
#packet_log_writer_pairs ⇒ Array
Returns Array of packet logger classes for this interface.
47 48 49 |
# File 'lib/cosmos/interfaces/interface.rb', line 47 def packet_log_writer_pairs @packet_log_writer_pairs end |
#raw_logger_pair ⇒ RawLoggerPair
Returns RawLoggerPair instance or nil.
50 51 52 |
# File 'lib/cosmos/interfaces/interface.rb', line 50 def raw_logger_pair @raw_logger_pair end |
#read_count ⇒ Integer
Returns The number of packets read from this interface.
57 58 59 |
# File 'lib/cosmos/interfaces/interface.rb', line 57 def read_count @read_count end |
#read_queue_size ⇒ Integer
Returns The number of packets in the read queue (when used as a Router).
74 75 76 |
# File 'lib/cosmos/interfaces/interface.rb', line 74 def read_queue_size @read_queue_size end |
#reconnect_delay ⇒ Integer[ Delay between reconnect attempts
Returns Integer[ Delay between reconnect attempts.
40 41 42 |
# File 'lib/cosmos/interfaces/interface.rb', line 40 def reconnect_delay @reconnect_delay end |
#routers ⇒ Array<Routers>
Returns Array of routers that receive packets read from the interface.
54 55 56 |
# File 'lib/cosmos/interfaces/interface.rb', line 54 def routers @routers end |
#target_names ⇒ Array<String>
Returns Array of target names associated with this interface.
26 27 28 |
# File 'lib/cosmos/interfaces/interface.rb', line 26 def target_names @target_names end |
#thread ⇒ Thread
Returns Thread reading from the interface.
29 30 31 |
# File 'lib/cosmos/interfaces/interface.rb', line 29 def thread @thread end |
#write_count ⇒ Integer
Returns The number of packets written to this interface.
60 61 62 |
# File 'lib/cosmos/interfaces/interface.rb', line 60 def write_count @write_count end |
#write_queue_size ⇒ Integer
Returns The number of packets in the write queue (when used as a Router).
78 79 80 |
# File 'lib/cosmos/interfaces/interface.rb', line 78 def write_queue_size @write_queue_size end |
Instance Method Details
#connect ⇒ Object
Connects the interface to its target(s). Must be implemented by a subclass.
115 116 117 |
# File 'lib/cosmos/interfaces/interface.rb', line 115 def connect raise "Interface connect method not implemented" end |
#connected? ⇒ Boolean
Indicates if the interface is connected to its target(s) or not. Must be implemented by a subclass.
121 122 123 |
# File 'lib/cosmos/interfaces/interface.rb', line 121 def connected? raise "Interface connected? method not implemented" end |
#copy_to(other_interface) ⇒ Object
Copy settings from this interface to another interface. All instance variables are copied except for thread, num_clients, read_queue_size, and write_queue_size since these are all specific to the operation of the interface rather than its instantiation.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/cosmos/interfaces/interface.rb', line 186 def copy_to(other_interface) other_interface.name = self.name.clone other_interface.target_names = self.target_names.clone # The other interface has its own Thread other_interface.connect_on_startup = self.connect_on_startup other_interface.auto_reconnect = self.auto_reconnect other_interface.reconnect_delay = self.reconnect_delay other_interface.disable_disconnect = self.disable_disconnect other_interface.packet_log_writer_pairs = self.packet_log_writer_pairs.clone other_interface.routers = self.routers.clone other_interface.read_count = self.read_count other_interface.write_count = self.write_count other_interface.bytes_read = self.bytes_read other_interface.bytes_written = self.bytes_written other_interface.raw_logger_pair = self.raw_logger_pair.clone if self.raw_logger_pair # num_clients is per interface so don't copy # read_queue_size is the number of packets in the queue so don't copy # write_queue_size is the number of packets in the queue so don't copy other_interface.interfaces = self.interfaces.clone other_interface. = self..clone end |
#disconnect ⇒ Object
Disconnects the interface from its target(s). Must be implemented by a subclass.
127 128 129 |
# File 'lib/cosmos/interfaces/interface.rb', line 127 def disconnect raise "Interface disconnect method not implemented" end |
#post_identify_packet(packet) ⇒ Object
This method is called by the CmdTlmServer after each read packet is identified. It can be used to perform custom processing/monitoring as each packet is received by the CmdTlmServer.
220 221 |
# File 'lib/cosmos/interfaces/interface.rb', line 220 def post_identify_packet(packet) end |
#read ⇒ Object
Retrieves the next packet from the interface. Must be implemented by a subclass.
133 134 135 |
# File 'lib/cosmos/interfaces/interface.rb', line 133 def read raise "Interface read method not implemented" end |
#read_allowed? ⇒ Boolean
Returns Whether reading is allowed.
150 151 152 |
# File 'lib/cosmos/interfaces/interface.rb', line 150 def read_allowed? @read_allowed end |
#set_option(option_name, option_values) ⇒ Object
Set an interface or router specific option
211 212 213 |
# File 'lib/cosmos/interfaces/interface.rb', line 211 def set_option(option_name, option_values) @options[option_name.upcase] = option_values.clone end |
#start_raw_logging ⇒ Object
Start raw logging for this interface
165 166 167 |
# File 'lib/cosmos/interfaces/interface.rb', line 165 def start_raw_logging @raw_logger_pair.start if @raw_logger_pair end |
#stop_raw_logging ⇒ Object
Stop raw logging for this interface
170 171 172 |
# File 'lib/cosmos/interfaces/interface.rb', line 170 def stop_raw_logging @raw_logger_pair.stop if @raw_logger_pair end |
#write(packet) ⇒ Object
Method to send a packet on the interface. Must be implemented by a subclass.
139 140 141 |
# File 'lib/cosmos/interfaces/interface.rb', line 139 def write(packet) raise "Interface write method not implemented" end |
#write_allowed? ⇒ Boolean
Returns Whether writing is allowed.
155 156 157 |
# File 'lib/cosmos/interfaces/interface.rb', line 155 def write_allowed? @write_allowed end |
#write_raw(data) ⇒ Object
Writes preformatted data onto the interface. Malformed data may cause problems. Must be implemented by a subclass.
145 146 147 |
# File 'lib/cosmos/interfaces/interface.rb', line 145 def write_raw(data) raise "Interface write_raw method not implemented" end |
#write_raw_allowed? ⇒ Boolean
Returns Whether writing raw data over the interface is allowed.
160 161 162 |
# File 'lib/cosmos/interfaces/interface.rb', line 160 def write_raw_allowed? @write_raw_allowed end |