Method: OpenC3::TemplateProtocol#initialize

Defined in:
lib/openc3/interfaces/protocols/template_protocol.rb

#initialize(write_termination_characters, read_termination_characters, ignore_lines = 0, initial_read_delay = nil, response_lines = 1, strip_read_termination = true, discard_leading_bytes = 0, sync_pattern = nil, fill_fields = false, response_timeout = 5.0, response_polling_period = 0.02, raise_exceptions = false, allow_empty_data = nil) ⇒ TemplateProtocol

Returns a new instance of TemplateProtocol.

Parameters:

  • ignore_lines (Integer) (defaults to: 0)

    Number of newline terminated reads to ignore when processing the response

  • initial_read_delay (Integer) (defaults to: nil)

    Initial delay when connecting before trying to read

  • response_lines (Integer) (defaults to: 1)

    Number of newline terminated lines which comprise the response

  • response_timeout (Float) (defaults to: 5.0)

    Number of seconds to wait before timing out when waiting for a response

  • response_polling_period (Float) (defaults to: 0.02)

    Number of seconds to wait between polling for a response

  • raise_exceptions (String) (defaults to: false)

    Whether to raise exceptions when errors occur in the protocol like unexpected responses or response timeouts.

  • allow_empty_data (true/false/nil) (defaults to: nil)

    See Protocol#initialize

  • write_termination_characters (String)

    The characters to write after writing the Packet buffer. Must be given as a hexadecimal string such as '0xABCD'.

  • read_termination_characters (String)

    The characters at the end of the data which delineate the end of a Packet. Must be given as a hexadecimal string such as '0xABCD'.

  • strip_read_termination (Boolean) (defaults to: true)

    Whether to remove the read_termination_characters before turning the data into a Packet.

  • discard_leading_bytes (Integer) (defaults to: 0)

    The number of bytes to discard from the binary data after reading. Note that this is often used to remove a sync pattern from the final packet data.

  • sync_pattern (String) (defaults to: nil)

    String representing a hex number ("0x1234") that will be searched for in the raw data. Bytes encountered before this pattern is found are discarded.

  • fill_fields (Boolean) (defaults to: false)

    Fill any required fields when writing packets



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/openc3/interfaces/protocols/template_protocol.rb', line 49

def initialize(
  write_termination_characters,
  read_termination_characters,
  ignore_lines = 0,
  initial_read_delay = nil,
  response_lines = 1,
  strip_read_termination = true,
  discard_leading_bytes = 0,
  sync_pattern = nil,
  fill_fields = false,
  response_timeout = 5.0,
  response_polling_period = 0.02,
  raise_exceptions = false,
  allow_empty_data = nil
)
  super(
    write_termination_characters,
    read_termination_characters,
    strip_read_termination,
    discard_leading_bytes,
    sync_pattern,
    fill_fields,
    allow_empty_data)
  @response_template = nil
  @response_packet = nil
  @response_target_name = nil
  @response_packets = []
  @write_block_queue = Queue.new
  @ignore_lines = ignore_lines.to_i
  @response_lines = response_lines.to_i
  @initial_read_delay = ConfigParser.handle_nil(initial_read_delay)
  @initial_read_delay = @initial_read_delay.to_f if @initial_read_delay
  @response_timeout = ConfigParser.handle_nil(response_timeout)
  @response_timeout = @response_timeout.to_f if @response_timeout
  @response_polling_period = response_polling_period.to_f
  @connect_complete_time = nil
  @raise_exceptions = ConfigParser.handle_true_false(raise_exceptions)
end