Class: OpenC3::FixedProtocol

Inherits:
BurstProtocol show all
Defined in:
lib/openc3/interfaces/protocols/fixed_protocol.rb

Overview

Delineates packets by identifying them and then reading out their entire fixed length. Packets lengths can vary but they must all be fixed.

Instance Attribute Summary

Attributes inherited from Protocol

#allow_empty_data, #extra, #interface

Instance Method Summary collapse

Methods inherited from BurstProtocol

#handle_sync_pattern, #log_discard, #read_data, #reset, #write_data, #write_packet

Methods inherited from Protocol

#connect_reset, #disconnect_reset, #post_write_interface, #protocol_cmd, #read_data, #reset, #write_data, #write_packet

Constructor Details

#initialize(min_id_size, discard_leading_bytes = 0, sync_pattern = nil, telemetry = true, fill_fields = false, unknown_raise = false, allow_empty_data = nil) ⇒ FixedProtocol

Returns a new instance of FixedProtocol.

Parameters:

  • min_id_size (Integer)

    The minimum amount of data needed to identify a packet.

  • telemetry (Boolean) (defaults to: true)

    Whether the interface is returning telemetry (true) or commands (false)

  • unknown_raise (defaults to: false)

    Whether to raise an exception on an unknown 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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/openc3/interfaces/protocols/fixed_protocol.rb', line 40

def initialize(
  min_id_size,
  discard_leading_bytes = 0,
  sync_pattern = nil,
  telemetry = true,
  fill_fields = false,
  unknown_raise = false,
  allow_empty_data = nil
)
  super(discard_leading_bytes, sync_pattern, fill_fields, allow_empty_data)
  @min_id_size = Integer(min_id_size)
  @telemetry = telemetry
  @unknown_raise = ConfigParser.handle_true_false(unknown_raise)
  @received_time = nil
  @target_name = nil
  @packet_name = nil
end

Instance Method Details

#read_packet(packet) ⇒ Object

Set the received_time, target_name and packet_name which we recorded when we identified this packet. The server will also do this but since we know the information here, we perform this optimization.



61
62
63
64
65
66
# File 'lib/openc3/interfaces/protocols/fixed_protocol.rb', line 61

def read_packet(packet)
  packet.received_time = @received_time
  packet.target_name = @target_name
  packet.packet_name = @packet_name
  return packet
end