Class: S19::SRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/rsrec.rb

Overview

Represents a line in the S-Record format

en.wikipedia.org/wiki/SREC_%28file_format%29

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rtype, addr, data) ⇒ SRecord

Returns a new instance of SRecord.



11
12
13
14
15
# File 'lib/rsrec.rb', line 11

def initialize rtype,addr,data
  self.record_type= rtype
  @address = addr
  self.data=data
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



10
11
12
# File 'lib/rsrec.rb', line 10

def address
  @address
end

#binaryObject (readonly)

Returns the value of attribute binary.



10
11
12
# File 'lib/rsrec.rb', line 10

def binary
  @binary
end

#byte_countObject (readonly)

Returns the value of attribute byte_count.



10
11
12
# File 'lib/rsrec.rb', line 10

def byte_count
  @byte_count
end

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/rsrec.rb', line 10

def data
  @data
end

#record_typeObject

Returns the value of attribute record_type.



10
11
12
# File 'lib/rsrec.rb', line 10

def record_type
  @record_type
end

Class Method Details

.parse(text_data) ⇒ Object

Parses a single line in SREC format and returns an SRecord instance



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rsrec.rb', line 25

def self.parse text_data
  text_data.chomp!
  #duplicate because we're slicing and dicing and throwing stuff away
  line=text_data.dup
  #the (0..0) is for 1.8.7 compatibility, in 1.9 it gives the sliced char back
  if line.slice!(0..0)=='S'
    record_type = line.slice!(0..0).to_i
    #convert everything to hex
    #take out the byte count
    line.slice!(0..1).to_i(16)
    address = calculate_address(record_type,line)
    #take out the crc
    line.slice!(-2..-1)
    data = line
    check_crc(text_data)
    return SRecord.new(record_type,address,data)
  else
    raise SRecordError,"Line without leading S"
  end
end

Instance Method Details

#crcObject

Returns the S-Record CRC



21
22
23
# File 'lib/rsrec.rb', line 21

def crc
  SRecord.calculate_crc("#{"%02x"% @byte_count}#{format_address}#{@data}")
end

#data_record?Boolean

True if the record is of type 1,2 or 3

Returns:

  • (Boolean)


46
47
48
# File 'lib/rsrec.rb', line 46

def data_record?
  [1,2,3].include?(@record_type)
end

#to_sObject



17
18
19
# File 'lib/rsrec.rb', line 17

def to_s
  "S#{@record_type}#{"%02x"% @byte_count}#{format_address}#{@data}#{crc}".upcase
end