Class: Cosmos::Interface

Inherits:
Object show all
Includes:
Api
Defined in:
lib/cosmos/interfaces/interface.rb

Overview

Defines all the attributes and methods common to all interface classes used by COSMOS.

Constant Summary

Constants included from Extract

Extract::SCANNING_REGULAR_EXPRESSION

Instance Attribute Summary collapse

Instance Method Summary collapse

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_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_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

#initializeInterface

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_reconnectBoolean



37
38
39
# File 'lib/cosmos/interfaces/interface.rb', line 37

def auto_reconnect
  @auto_reconnect
end

#bytes_readInteger



63
64
65
# File 'lib/cosmos/interfaces/interface.rb', line 63

def bytes_read
  @bytes_read
end

#bytes_writtenInteger



66
67
68
# File 'lib/cosmos/interfaces/interface.rb', line 66

def bytes_written
  @bytes_written
end

#connect_on_startupBoolean



33
34
35
# File 'lib/cosmos/interfaces/interface.rb', line 33

def connect_on_startup
  @connect_on_startup
end

#disable_disconnectBoolean



44
45
46
# File 'lib/cosmos/interfaces/interface.rb', line 44

def disable_disconnect
  @disable_disconnect
end

#interfacesArray<Interface>



82
83
84
# File 'lib/cosmos/interfaces/interface.rb', line 82

def interfaces
  @interfaces
end

#nameString



23
24
25
# File 'lib/cosmos/interfaces/interface.rb', line 23

def name
  @name
end

#num_clientsInteger



70
71
72
# File 'lib/cosmos/interfaces/interface.rb', line 70

def num_clients
  @num_clients
end

#optionsHash<option name, option values>



85
86
87
# File 'lib/cosmos/interfaces/interface.rb', line 85

def options
  @options
end

#packet_log_writer_pairsArray



47
48
49
# File 'lib/cosmos/interfaces/interface.rb', line 47

def packet_log_writer_pairs
  @packet_log_writer_pairs
end

#raw_logger_pairRawLoggerPair



50
51
52
# File 'lib/cosmos/interfaces/interface.rb', line 50

def raw_logger_pair
  @raw_logger_pair
end

#read_countInteger



57
58
59
# File 'lib/cosmos/interfaces/interface.rb', line 57

def read_count
  @read_count
end

#read_queue_sizeInteger



74
75
76
# File 'lib/cosmos/interfaces/interface.rb', line 74

def read_queue_size
  @read_queue_size
end

#reconnect_delayInteger[ Delay between reconnect attempts



40
41
42
# File 'lib/cosmos/interfaces/interface.rb', line 40

def reconnect_delay
  @reconnect_delay
end

#routersArray<Routers>



54
55
56
# File 'lib/cosmos/interfaces/interface.rb', line 54

def routers
  @routers
end

#target_namesArray<String>



26
27
28
# File 'lib/cosmos/interfaces/interface.rb', line 26

def target_names
  @target_names
end

#threadThread



29
30
31
# File 'lib/cosmos/interfaces/interface.rb', line 29

def thread
  @thread
end

#write_countInteger



60
61
62
# File 'lib/cosmos/interfaces/interface.rb', line 60

def write_count
  @write_count
end

#write_queue_sizeInteger



78
79
80
# File 'lib/cosmos/interfaces/interface.rb', line 78

def write_queue_size
  @write_queue_size
end

Instance Method Details

#connectObject

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.options = self.options.clone
end

#disconnectObject

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

#readObject

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



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_loggingObject

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_loggingObject

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



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



160
161
162
# File 'lib/cosmos/interfaces/interface.rb', line 160

def write_raw_allowed?
  @write_raw_allowed
end