class F4R::Definition::Record
| Byte | Description | Length | Value | |-----------------+-----------------------+------------+---------------| | 0 | Reserved | 1 Byte | 0 | | 1 | Architecture | 1 Byte | Arch Type: | | | | | 0: Little | | | | | 1: Big | | 2-3 | Global Message # | 2 Bytes | 0: 65535 | | 4 | Fields | 1 Byte | # of fields | | 5- | Field Definition | 3 Bytes | Field content | | 4 + Fields * 3 | | per field | | | 5 + Fields * 3 | # of Developer Fields | 1 Byte | # of Fields | | 6 + Fields * 3- | Developer Field Def. | 3 Bytes | | | END | | per feld | Field content |
Public Instance Methods
endian()
click to toggle source
Helper for getting the architecture
@return [Symbol]
# File lib/f4r.rb, line 1125 def endian @endion ||= architecture.zero? ? :little : :big end
global_message()
click to toggle source
Helper for getting the message global message
@return [Hash] @global_message
# File lib/f4r.rb, line 1134 def global_message @global_message ||= GlobalFit.messages.find do |m| m[:number] == global_message_number.snapshot end end
read(io)
click to toggle source
Serves as first place for validating data.
@param [IO] io
Calls superclass method
# File lib/f4r.rb, line 1110 def read(io) super unless global_message Log.error <<~ERROR Undefined global message: "#{global_message_number.snapshot}". ERROR end end
read_data(io)
click to toggle source
Read data belonging to the same definition.
@param [IO] io @return [BinData::Struct] data
# File lib/f4r.rb, line 1146 def read_data(io) data = to_bindata_struct.read(io) Log.decode [self.class, __method__], pos: io.pos, record: to_log_s data_fields.each do |df| Log.decode [self.class, __method__], field: df.to_log_s(data[df.number].snapshot) end data end
to_bindata_struct()
click to toggle source
Create [BinData::Struct] to contain and read and write the data belonging to the same definition.
@return [BinData::Struct]
# File lib/f4r.rb, line 1186 def to_bindata_struct opts = { endian: endian, fields: data_fields.map(&:to_bindata_struct) } BinData::Struct.new(opts) end
write_data(io, record)
click to toggle source
Write data belonging to the same definition.
@param [IO] io @param [Record] record
# File lib/f4r.rb, line 1166 def write_data(io, record) struct = to_bindata_struct record[:fields].each do |name, field| struct[field[:definition].number] = field[:value] Log.encode [self.class, __method__], pos: io.pos, field: field[:definition].to_log_s(field[:value]) end struct.write(io) end
Private Instance Methods
to_log_s()
click to toggle source
Definition
log output
@example:
R: 0 A: 0 GM: 18 FC: 95
@return [String]
# File lib/f4r.rb, line 1204 def to_log_s [ ('%-8s' % "R: #{reserved.snapshot}"), ('%-8s' % "A: #{architecture.snapshot}"), ('%-8s' % "GM: #{global_message_number.snapshot}"), ('%-8s' % "FC: #{field_count.snapshot}"), ('%-8s' % global_message[:value_name]), ].join(' ') end