Method: OpenC3::TerminatedProtocol#initialize

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

#initialize(write_termination_characters, read_termination_characters, strip_read_termination = true, discard_leading_bytes = 0, sync_pattern = nil, fill_fields = false, allow_empty_data = nil) ⇒ TerminatedProtocol

Returns a new instance of TerminatedProtocol.

Parameters:

  • 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.

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

    See Protocol#initialize

  • 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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openc3/interfaces/protocols/terminated_protocol.rb', line 43

def initialize(
  write_termination_characters,
  read_termination_characters,
  strip_read_termination = true,
  discard_leading_bytes = 0,
  sync_pattern = nil,
  fill_fields = false,
  allow_empty_data = nil
)
  @write_termination_characters = write_termination_characters.hex_to_byte_string
  @read_termination_characters = read_termination_characters.hex_to_byte_string
  @strip_read_termination = ConfigParser.handle_true_false(strip_read_termination)
  raise "strip_read_termination must be true or false" if @strip_read_termination != true and @strip_read_termination != false

  super(discard_leading_bytes, sync_pattern, fill_fields, allow_empty_data)
end