Class: Cosmos::StreamInterface
- Defined in:
- lib/cosmos/interfaces/stream_interface.rb
Overview
Base class for interfaces that act read and write from a stream
Direct Known Subclasses
Constant Summary
Constants included from Api
Api::SETTINGS_KEY, Api::SUBSCRIPTION_DELIMITER
Constants included from ApiShared
ApiShared::DEFAULT_TLM_POLLING_RATE
Constants included from Extract
Extract::SCANNING_REGULAR_EXPRESSION
Instance Attribute Summary collapse
-
#stream ⇒ Object
Returns the value of attribute stream.
Attributes inherited from Interface
#auto_reconnect, #bytes_read, #bytes_written, #cmd_routers, #config_params, #connect_on_startup, #disable_disconnect, #interfaces, #name, #num_clients, #options, #override_tlm, #packet_log_writer_pairs, #protocol_info, #raw_logger_pair, #read_count, #read_protocols, #read_queue_size, #read_raw_data, #read_raw_data_time, #reconnect_delay, #routers, #state, #stored_packet_log_writer_pairs, #target_names, #write_count, #write_protocols, #write_queue_size, #written_raw_data, #written_raw_data_time
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#initialize(protocol_type = nil, protocol_args = []) ⇒ StreamInterface
constructor
A new instance of StreamInterface.
- #read_interface ⇒ Object
- #write_interface(data) ⇒ Object
Methods inherited from Interface
#_normalize_tlm, #_override, #_override_tlm, #_override_tlm_raw, #_write, #add_protocol, #as_json, #convert_data_to_packet, #convert_packet_to_data, #copy_to, #read, #read_allowed?, #read_interface_base, #set_option, #start_raw_logging, #stop_raw_logging, #write, #write_allowed?, #write_interface_base, #write_raw, #write_raw_allowed?
Methods included from Api
#_get_cnt, #_limits_group, #_validate_tlm_type, #build_cmd_output_string, #cmd, #cmd_implementation, #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, #delete_config, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_limits, #enable_limits_group, #get_all_cmd_info, #get_all_cmd_tlm_info, #get_all_commands, #get_all_commands_list, #get_all_interface_info, #get_all_router_info, #get_all_settings, #get_all_target_info, #get_all_telemetry, #get_all_telemetry_list, #get_all_tlm_info, #get_cmd_buffer, #get_cmd_cnt, #get_cmd_hazardous, #get_cmd_time, #get_cmd_value, #get_command, #get_interface, #get_interface_names, #get_item, #get_limits, #get_limits_events, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_oldest_logfile, #get_out_of_limits, #get_overall_limits_state, #get_packet_derived_items, #get_packets, #get_parameter, #get_router, #get_router_names, #get_saved_config, #get_setting, #get_settings, #get_stale, #get_target, #get_target_list, #get_telemetry, #get_tlm_buffer, #get_tlm_cnt, #get_tlm_packet, #get_tlm_values, #inject_tlm, #limits_enabled?, #list_configs, #list_settings, #load_config, #normalize_tlm, #override_tlm, #save_config, #save_setting, #send_raw, #set_limits, #set_limits_set, #set_tlm, #set_tlm_process_args, #start_raw_logging_interface, #start_raw_logging_router, #stop_raw_logging_interface, #stop_raw_logging_router, #subscribe_packets, #tlm, #tlm_formatted, #tlm_process_args, #tlm_raw, #tlm_variable, #tlm_with_units
Constructor Details
#initialize(protocol_type = nil, protocol_args = []) ⇒ StreamInterface
Returns a new instance of StreamInterface.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 27 def initialize(protocol_type = nil, protocol_args = []) super() @stream = nil @protocol_type = ConfigParser.handle_nil(protocol_type) @protocol_args = protocol_args if @protocol_type protocol_class_name = protocol_type.to_s.capitalize << 'Protocol' klass = Cosmos.require_class(protocol_class_name.class_name_to_filename) add_protocol(klass, protocol_args, :READ_WRITE) end end |
Instance Attribute Details
#stream ⇒ Object
Returns the value of attribute stream.
25 26 27 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 25 def stream @stream end |
Instance Method Details
#connect ⇒ Object
39 40 41 42 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 39 def connect super() @stream.connect if @stream end |
#connected? ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 44 def connected? if @stream @stream.connected? else false end end |
#disconnect ⇒ Object
52 53 54 55 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 52 def disconnect @stream.disconnect if @stream super() end |
#read_interface ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 57 def read_interface timeout = false begin data = @stream.read rescue Timeout::Error Logger.error "#{@name}: Timeout waiting for data to be read" timeout = true data = nil end if data.nil? or data.length <= 0 Logger.info "#{@name}: #{@stream.class} read returned nil" if data.nil? and not timeout Logger.info "#{@name}: #{@stream.class} read returned 0 bytes (stream closed)" if not data.nil? and data.length <= 0 return nil end read_interface_base(data) data end |
#write_interface(data) ⇒ Object
76 77 78 79 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 76 def write_interface(data) write_interface_base(data) @stream.write(data) end |