Method: OpenC3::CrcProtocol#read_data

Defined in:
lib/openc3/interfaces/protocols/crc_protocol.rb

#read_data(data) ⇒ Object



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

def read_data(data)
  return super(data) if data.length <= 0

  crc = BinaryAccessor.read(@bit_offset, @bit_size, :UINT, data, @endianness)
  calculated_crc = @crc.calc(data[0...(@bit_offset / 8)])
  if calculated_crc != crc
    Logger.error "#{@interface ? @interface.name : ""}: Invalid CRC detected! Calculated 0x#{calculated_crc.to_s(16).upcase} vs found 0x#{crc.to_s(16).upcase}."
    if @bad_strategy == DISCONNECT
      return :DISCONNECT
    end
  end
  if @strip_crc
    new_data = data.dup
    new_data = new_data[0...(@bit_offset / 8)]
    end_range = (@bit_offset + @bit_size) / 8
    new_data << data[end_range..-1] if end_range != 0
    return new_data
  end
  return data
end