Class: S19::SRecord
- Inherits:
-
Object
- Object
- S19::SRecord
- Defined in:
- lib/rsrec.rb
Overview
Represents a line in the S-Record format
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#binary ⇒ Object
readonly
Returns the value of attribute binary.
-
#byte_count ⇒ Object
readonly
Returns the value of attribute byte_count.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#record_type ⇒ Object
readonly
Returns the value of attribute record_type.
Class Method Summary collapse
-
.parse(text_data) ⇒ Object
Parses a single line in SREC format and returns an SRecord instance.
Instance Method Summary collapse
-
#crc ⇒ Object
Returns the S-Record CRC.
-
#data_record? ⇒ Boolean
True if the record is of type 1,2 or 3.
-
#initialize(rtype, addr, data) ⇒ SRecord
constructor
A new instance of SRecord.
- #to_s ⇒ Object
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
#address ⇒ Object (readonly)
Returns the value of attribute address.
10 11 12 |
# File 'lib/rsrec.rb', line 10 def address @address end |
#binary ⇒ Object (readonly)
Returns the value of attribute binary.
10 11 12 |
# File 'lib/rsrec.rb', line 10 def binary @binary end |
#byte_count ⇒ Object (readonly)
Returns the value of attribute byte_count.
10 11 12 |
# File 'lib/rsrec.rb', line 10 def byte_count @byte_count end |
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/rsrec.rb', line 10 def data @data end |
#record_type ⇒ Object
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
#crc ⇒ Object
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
46 47 48 |
# File 'lib/rsrec.rb', line 46 def data_record? [1,2,3].include?(@record_type) end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/rsrec.rb', line 17 def to_s "S#{@record_type}#{"%02x"% @byte_count}#{format_address}#{@data}#{crc}".upcase end |