Class: OpenC3::TerminatedProtocol
- Inherits:
-
BurstProtocol
- Object
- Protocol
- BurstProtocol
- OpenC3::TerminatedProtocol
- Defined in:
- lib/openc3/interfaces/protocols/terminated_protocol.rb
Overview
Protocol which delineates packets using termination characters at the end of the data.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Protocol
#allow_empty_data, #extra, #interface
Instance Method Summary collapse
-
#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
constructor
A new instance of TerminatedProtocol.
- #write_data(data, extra = nil) ⇒ Object
Methods inherited from BurstProtocol
#handle_sync_pattern, #log_discard, #read_data, #reset, #write_packet
Methods inherited from Protocol
#connect_reset, #disconnect_reset, #post_write_interface, #protocol_cmd, #read_data, #read_packet, #reset, #write_packet
Constructor Details
#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.
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 |
Instance Method Details
#write_data(data, extra = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/openc3/interfaces/protocols/terminated_protocol.rb', line 60 def write_data(data, extra = nil) raise "Packet contains termination characters!" if data.index(@write_termination_characters) data, extra = super(data, extra) @write_termination_characters.each_byte do |byte| data << byte end return data, extra end |