Class: OpenC3::StreamInterface

Inherits:
Interface show all
Defined in:
lib/openc3/interfaces/stream_interface.rb

Overview

Base class for interfaces that act read and write from a stream

Constant Summary

Constants included from Api

Api::DELAY_METRICS, Api::DURATION_METRICS, Api::SUBSCRIPTION_DELIMITER, Api::SUM_METRICS

Constants included from ApiShared

ApiShared::DEFAULT_TLM_POLLING_RATE

Constants included from Extract

Extract::SCANNING_REGULAR_EXPRESSION

Instance Attribute Summary collapse

Attributes inherited from Interface

#auto_reconnect, #bytes_read, #bytes_written, #cmd_routers, #cmd_target_names, #config_params, #connect_on_startup, #disable_disconnect, #interfaces, #name, #num_clients, #options, #packet_log_writer_pairs, #protocol_info, #read_count, #read_protocols, #read_queue_size, #read_raw_data, #read_raw_data_time, #reconnect_delay, #routers, #scheduler, #secrets, #state, #stored_packet_log_writer_pairs, #stream_log_pair, #target_names, #tlm_target_names, #write_count, #write_protocols, #write_queue_size, #written_raw_data, #written_raw_data_time

Instance Method Summary collapse

Methods inherited from Interface

#_write, #add_protocol, #as_json, #connection_string, #convert_data_to_packet, #convert_packet_to_data, #copy_to, #interface_cmd, #protocol_cmd, #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

#_build_cmd_output_string, #_cmd_implementation, #_extract_target_command_names, #_extract_target_command_parameter_names, #_extract_target_packet_item_names, #_extract_target_packet_names, #_get_and_set_cmd, #_get_item, #_limits_group, #_set_tlm_process_args, #_tlm_process_args, #_validate_tlm_type, #build_cmd, #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, #config_tool_names, #connect_interface, #connect_router, #delete_config, #disable_cmd, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_cmd, #enable_limits, #enable_limits_group, #get_all_cmd_names, #get_all_cmds, #get_all_interface_info, #get_all_router_info, #get_all_settings, #get_all_target_info, #get_all_tlm, #get_all_tlm_names, #get_cmd, #get_cmd_buffer, #get_cmd_cnt, #get_cmd_cnts, #get_cmd_hazardous, #get_cmd_time, #get_cmd_value, #get_interface, #get_interface_names, #get_item, #get_limits, #get_limits_events, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_metrics, #get_out_of_limits, #get_overall_limits_state, #get_overrides, #get_packet_derived_items, #get_packets, #get_param, #get_router, #get_router_names, #get_setting, #get_settings, #get_target, #get_target_interfaces, #get_target_names, #get_tlm, #get_tlm_buffer, #get_tlm_cnt, #get_tlm_cnts, #get_tlm_packet, #get_tlm_values, #inject_tlm, #interface_cmd, #interface_protocol_cmd, #limits_enabled?, #list_configs, #list_settings, #load_config, #map_target_to_interface, #normalize_tlm, #offline_access_needed, #override_tlm, #router_cmd, #router_protocol_cmd, #save_config, #send_raw, #set_limits, #set_limits_set, #set_offline_access, #set_setting, #set_tlm, #start_raw_logging_interface, #start_raw_logging_router, #stash_all, #stash_delete, #stash_get, #stash_keys, #stash_set, #stop_raw_logging_interface, #stop_raw_logging_router, #subscribe_packets, #tlm, #tlm_formatted, #tlm_raw, #tlm_variable, #tlm_with_units

Constructor Details

#initialize(protocol_type = nil, protocol_args = []) ⇒ StreamInterface

Returns a new instance of StreamInterface.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openc3/interfaces/stream_interface.rb', line 30

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 = OpenC3.require_class(protocol_class_name.class_name_to_filename)
    add_protocol(klass, protocol_args, :PARAMS)
  end
end

Instance Attribute Details

#streamObject

Returns the value of attribute stream.



28
29
30
# File 'lib/openc3/interfaces/stream_interface.rb', line 28

def stream
  @stream
end

Instance Method Details

#connectObject



42
43
44
45
# File 'lib/openc3/interfaces/stream_interface.rb', line 42

def connect
  super()
  @stream.connect if @stream
end

#connected?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/openc3/interfaces/stream_interface.rb', line 47

def connected?
  if @stream
    @stream.connected?
  else
    false
  end
end

#disconnectObject



55
56
57
58
# File 'lib/openc3/interfaces/stream_interface.rb', line 55

def disconnect
  @stream.disconnect if @stream
  super()
end

#read_interfaceObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/openc3/interfaces/stream_interface.rb', line 60

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

  extra = nil
  read_interface_base(data, extra)
  return data, extra
end

#write_interface(data, extra = nil) ⇒ Object



80
81
82
83
84
# File 'lib/openc3/interfaces/stream_interface.rb', line 80

def write_interface(data, extra = nil)
  write_interface_base(data, extra)
  @stream.write(data)
  return data, extra
end