Class: OpenC3::Protocol

Inherits:
Object show all
Defined in:
lib/openc3/interfaces/protocols/protocol.rb,
ext/openc3/ext/burst_protocol/burst_protocol.c

Overview

Base class for all OpenC3 protocols which defines a framework which must be implemented by a subclass.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allow_empty_data = nil) ⇒ Protocol

to be passed down to later Protocols (instead of returning :STOP). Can be true, false, or nil, where nil is interpreted as true unless the Protocol is the last Protocol of the chain.

Parameters:

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

    Whether or not this protocol will allow an empty string



37
38
39
40
41
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 37

def initialize(allow_empty_data = nil)
  @interface = nil
  @allow_empty_data = ConfigParser.handle_true_false_nil(allow_empty_data)
  reset()
end

Instance Attribute Details

#allow_empty_dataObject

Returns the value of attribute allow_empty_data.



31
32
33
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 31

def allow_empty_data
  @allow_empty_data
end

#extraObject

Returns the value of attribute extra.



32
33
34
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 32

def extra
  @extra
end

#interfaceObject

Returns the value of attribute interface.



30
31
32
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 30

def interface
  @interface
end

Instance Method Details

#connect_resetObject



47
48
49
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 47

def connect_reset
  reset()
end

#disconnect_resetObject



51
52
53
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 51

def disconnect_reset
  reset()
end

#post_write_interface(packet, data, extra = nil) ⇒ Object



83
84
85
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 83

def post_write_interface(packet, data, extra = nil)
  return packet, data, extra
end

#protocol_cmd(cmd_name, *cmd_args) ⇒ Object



87
88
89
90
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 87

def protocol_cmd(cmd_name, *cmd_args)
  # Default do nothing - Implemented by subclasses
  return false
end

#read_data(data, extra = nil) ⇒ Object

Ensure we have some data in case this is the only protocol



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 56

def read_data(data, extra = nil)
  if data.length <= 0
    if @allow_empty_data.nil?
      if @interface and @interface.read_protocols[-1] == self
        # Last read interface in chain with auto @allow_empty_data
        return :STOP
      end
    elsif !@allow_empty_data
      # Don't @allow_empty_data means STOP
      return :STOP
    end
  end
  return data, extra
end

#read_packet(packet) ⇒ Object



71
72
73
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 71

def read_packet(packet)
  return packet
end

#resetObject



43
44
45
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 43

def reset
  @extra = nil
end

#write_data(data, extra = nil) ⇒ Object



79
80
81
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 79

def write_data(data, extra = nil)
  return data, extra
end

#write_packet(packet) ⇒ Object



75
76
77
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 75

def write_packet(packet)
  return packet
end