Class: OpenC3::Protocol
- 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.
Direct Known Subclasses
BurstProtocol, CmdResponseProtocol, CrcProtocol, IgnorePacketProtocol
Instance Attribute Summary collapse
-
#allow_empty_data ⇒ Object
Returns the value of attribute allow_empty_data.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#interface ⇒ Object
Returns the value of attribute interface.
Instance Method Summary collapse
- #connect_reset ⇒ Object
- #disconnect_reset ⇒ Object
-
#initialize(allow_empty_data = nil) ⇒ Protocol
constructor
to be passed down to later Protocols (instead of returning :STOP).
- #post_write_interface(packet, data, extra = nil) ⇒ Object
- #protocol_cmd(cmd_name, *cmd_args) ⇒ Object
-
#read_data(data, extra = nil) ⇒ Object
Ensure we have some data in case this is the only protocol.
- #read_details ⇒ Object
- #read_packet(packet) ⇒ Object
-
#read_protocol_input_base(data, _extra = nil) ⇒ Object
Called to provide insight into the protocol read_data for the input data.
-
#read_protocol_output_base(data, _extra = nil) ⇒ Object
Called to provide insight into the protocol read_data for the output data.
- #reset ⇒ Object
- #write_data(data, extra = nil) ⇒ Object
- #write_details ⇒ Object
- #write_packet(packet) ⇒ Object
-
#write_protocol_input_base(data, _extra = nil) ⇒ Object
Called to provide insight into the protocol write_data for the input data.
-
#write_protocol_output_base(data, _extra = nil) ⇒ Object
Called to provide insight into the protocol write_data for the output data.
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.
32 33 34 35 36 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 32 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_data ⇒ Object
Returns the value of attribute allow_empty_data.
26 27 28 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 26 def allow_empty_data @allow_empty_data end |
#extra ⇒ Object
Returns the value of attribute extra.
27 28 29 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 27 def extra @extra end |
#interface ⇒ Object
Returns the value of attribute interface.
25 26 27 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 25 def interface @interface end |
Instance Method Details
#connect_reset ⇒ Object
42 43 44 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 42 def connect_reset reset() end |
#disconnect_reset ⇒ Object
46 47 48 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 46 def disconnect_reset reset() end |
#post_write_interface(packet, data, extra = nil) ⇒ Object
122 123 124 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 122 def post_write_interface(packet, data, extra = nil) return packet, data, extra end |
#protocol_cmd(cmd_name, *cmd_args) ⇒ Object
126 127 128 129 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 126 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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 95 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_details ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 148 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
110 111 112 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 110 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
51 52 53 54 55 56 57 58 59 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 51 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
62 63 64 65 66 67 68 69 70 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 62 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 |
#reset ⇒ Object
38 39 40 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 38 def reset @extra = nil end |
#write_data(data, extra = nil) ⇒ Object
118 119 120 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 118 def write_data(data, extra = nil) return data, extra end |
#write_details ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 131 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
114 115 116 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 114 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
73 74 75 76 77 78 79 80 81 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 73 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
84 85 86 87 88 89 90 91 92 |
# File 'lib/openc3/interfaces/protocols/protocol.rb', line 84 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 |