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



127
128
129
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 127

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

#protocol_cmd(cmd_name, *cmd_args) ⇒ Object



131
132
133
134
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 131

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 100

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_detailsObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 153

def read_details
  result = {'name' => self.class.name.to_s.split("::")[-1]}
  if @read_data_input_time
    result['read_data_input_time'] = @read_data_input_time.iso8601
  else
    result['read_data_input_time'] = nil
  end
  result['read_data_input'] = @read_data_input
  if @read_data_output_time
    result['read_data_output_time'] = @read_data_output_time.iso8601
  else
    result['read_data_output_time'] = nil
  end
  result['read_data_output'] = @read_data_output
  return result
end

#read_packet(packet) ⇒ Object



115
116
117
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 115

def read_packet(packet)
  return packet
end

#read_protocol_input_base(data, _extra = nil) ⇒ Object

Called to provide insight into the protocol read_data for the input data



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

def read_protocol_input_base(data, _extra = nil)
  if @interface
    if @interface.save_raw_data
      @read_data_input_time = Time.now
      @read_data_input = data.clone
    end
    # Todo: @interface.stream_log_pair.read_log.write(data) if @interface.stream_log_pair
  end
end

#read_protocol_output_base(data, _extra = nil) ⇒ Object

Called to provide insight into the protocol read_data for the output data



67
68
69
70
71
72
73
74
75
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 67

def read_protocol_output_base(data, _extra = nil)
  if @interface
    if @interface.save_raw_data
      @read_data_output_time = Time.now
      @read_data_output = data.clone
    end
    # Todo: @interface.stream_log_pair.read_log.write(data) if @interface.stream_log_pair
  end
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



123
124
125
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 123

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

#write_detailsObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 136

def write_details
  result = {'name' => self.class.name.to_s.split("::")[-1]}
  if @write_data_input_time
    result['write_data_input_time'] = @write_data_input_time.iso8601
  else
    result['write_data_input_time'] = nil
  end
  result['write_data_input'] = @write_data_input
  if @write_data_output_time
    result['write_data_output_time'] = @write_data_output_time.iso8601
  else
    result['write_data_output_time'] = nil
  end
  result['write_data_output'] = @write_data_output
  return result
end

#write_packet(packet) ⇒ Object



119
120
121
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 119

def write_packet(packet)
  return packet
end

#write_protocol_input_base(data, _extra = nil) ⇒ Object

Called to provide insight into the protocol write_data for the input data



78
79
80
81
82
83
84
85
86
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 78

def write_protocol_input_base(data, _extra = nil)
  if @interface
    if @interface.save_raw_data
      @write_data_input_time = Time.now
      @write_data_input = data.clone
    end
    # Todo: @interface.stream_log_pair.write_log.write(data) if @interface.stream_log_pair
  end
end

#write_protocol_output_base(data, _extra = nil) ⇒ Object

Called to provide insight into the protocol write_data for the output data



89
90
91
92
93
94
95
96
97
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 89

def write_protocol_output_base(data, _extra = nil)
  if @interface
    if @interface.save_raw_data
      @write_data_output_time = Time.now
      @write_data_output = data.clone
    end
    # Todo: @interface.stream_log_pair.write_log.write(data) if @interface.stream_log_pair
  end
end