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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cosmos/interfaces/interface.rb', line 85

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
end

Instance Attribute Details

#auto_reconnectBoolean

Returns Flag indicating if the interface should automatically reconnect after losing connection.

Returns:

  • (Boolean)

    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_readInteger

Returns The number of bytes read from this interface.

Returns:

  • (Integer)

    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_writtenInteger

Returns The number of bytes written to this interface.

Returns:

  • (Integer)

    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_startupBoolean

Returns Flag indicating if the interface should be connected to on startup.

Returns:

  • (Boolean)

    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_disconnectBoolean

Returns Flag indicating if the user is allowed to disconnect this interface.

Returns:

  • (Boolean)

    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

#interfacesArray<Interface>

Returns Array of interfaces to route packets to (when used as a Router).

Returns:

  • (Array<Interface>)

    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

#nameString

Returns Name of the interface.

Returns:

  • (String)

    Name of the interface



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

def name
  @name
end

#num_clientsInteger

Returns The number of active clients (when used as a Router).

Returns:

  • (Integer)

    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

#packet_log_writer_pairsArray

Returns Array of packet logger classes for this interface.

Returns:

  • (Array)

    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_pairRawLoggerPair

Returns RawLoggerPair instance or nil.

Returns:



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

def raw_logger_pair
  @raw_logger_pair
end

#read_countInteger

Returns The number of packets read from this interface.

Returns:

  • (Integer)

    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_sizeInteger

Returns The number of packets in the read queue (when used as a Router).

Returns:

  • (Integer)

    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_delayInteger[ Delay between reconnect attempts

Returns Integer[ Delay between reconnect attempts.

Returns:

  • (Integer[ Delay between reconnect attempts)

    Integer[ Delay between reconnect attempts



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

def reconnect_delay
  @reconnect_delay
end

#routersArray<Routers>

Returns Array of routers that receive packets read from the interface.

Returns:

  • (Array<Routers>)

    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_namesArray<String>

Returns Array of target names associated with this interface.

Returns:

  • (Array<String>)

    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

#threadThread

Returns Thread reading from the interface.

Returns:

  • (Thread)

    Thread reading from the interface



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

def thread
  @thread
end

#write_countInteger

Returns The number of packets written to this interface.

Returns:

  • (Integer)

    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_sizeInteger

Returns The number of packets in the write queue (when used as a Router).

Returns:

  • (Integer)

    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

#connectObject

Connects the interface to its target(s). Must be implemented by a subclass.



111
112
113
# File 'lib/cosmos/interfaces/interface.rb', line 111

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.

Returns:

  • (Boolean)


117
118
119
# File 'lib/cosmos/interfaces/interface.rb', line 117

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.

Parameters:

  • other_interface (Interface)

    The other interface to copy to



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cosmos/interfaces/interface.rb', line 182

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
end

#disconnectObject

Disconnects the interface from its target(s). Must be implemented by a subclass.



123
124
125
# File 'lib/cosmos/interfaces/interface.rb', line 123

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.

Parameters:

  • packet (Packet)

    The identified packet read from the interface



208
209
# File 'lib/cosmos/interfaces/interface.rb', line 208

def post_identify_packet(packet)
end

#readObject

Retrieves the next packet from the interface. Must be implemented by a subclass.



129
130
131
# File 'lib/cosmos/interfaces/interface.rb', line 129

def read
  raise "Interface read method not implemented"
end

#read_allowed?Boolean

Returns Whether reading is allowed.

Returns:

  • (Boolean)

    Whether reading is allowed



146
147
148
# File 'lib/cosmos/interfaces/interface.rb', line 146

def read_allowed?
  @read_allowed
end

#start_raw_loggingObject

Start raw logging for this interface



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

def start_raw_logging
  @raw_logger_pair.start if @raw_logger_pair
end

#stop_raw_loggingObject

Stop raw logging for this interface



166
167
168
# File 'lib/cosmos/interfaces/interface.rb', line 166

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.



135
136
137
# File 'lib/cosmos/interfaces/interface.rb', line 135

def write(packet)
  raise "Interface write method not implemented"
end

#write_allowed?Boolean

Returns Whether writing is allowed.

Returns:

  • (Boolean)

    Whether writing is allowed



151
152
153
# File 'lib/cosmos/interfaces/interface.rb', line 151

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.



141
142
143
# File 'lib/cosmos/interfaces/interface.rb', line 141

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.

Returns:

  • (Boolean)

    Whether writing raw data over the interface is allowed



156
157
158
# File 'lib/cosmos/interfaces/interface.rb', line 156

def write_raw_allowed?
  @write_raw_allowed
end