class F4R::Definition::RecordField
Record
Field
| Bit | Name | Description | |-----+------------------+-------------------------------------| | 7 | Endian Ability | 0 - for single byte data | | | | 1 - if base type has endianness | | | | (i.e. base type is 2 or more bytes) | | 5-6 | Reserved | Reserved | | 0-4 | Base Type Number | Number assigned to Base Type |
Public Instance Methods
base_type_definition()
click to toggle source
Base type definitions for field
@return [Hash]
# File lib/f4r.rb, line 1018 def base_type_definition @base_type_definition ||= get_base_type_definition end
global_message()
click to toggle source
Global message for field.
@return [Hash]
# File lib/f4r.rb, line 1009 def global_message @global_message ||= parent.parent.global_message end
global_message_field()
click to toggle source
Global message field with all its properties
@return [Hash]
# File lib/f4r.rb, line 999 def global_message_field @global_message_field ||= global_message[:fields]. find { |f| f[:field_def] == field_definition_number.snapshot } end
name()
click to toggle source
@return [String]
# File lib/f4r.rb, line 950 def name global_message_field[:field_name] end
number()
click to toggle source
@return [Integer]
# File lib/f4r.rb, line 957 def number global_message_field[:field_def] end
to_bindata_struct()
click to toggle source
Returns field in [BinData::Struct] format. Field identifier is its number since some field names (e.g., 'type') are reserved [BinData::Struct] keywords.
@example
[:uint8, '1'] [:string, '2', {length: 8}] [:array, '3', {type: uint8, initial_length: 4}]
@return [Array]
# File lib/f4r.rb, line 973 def to_bindata_struct type = base_type_definition[:bindata] bytes = base_type_definition[:bytes] case when type == :string [type, number.to_s, {length: byte_count.snapshot}] when byte_count.snapshot > bytes # array if byte_count.snapshot % bytes != 0 Log.error <<~ERROR Total bytes ("#{total_bytes}") must be multiple of base type bytes ("#{bytes}") of type "#{type}" in global FIT message "#{name}". ERROR end length = byte_count.snapshot / bytes [:array, number.to_s, {type: type, initial_length: length}] else [type, number.to_s] end end
to_log_s(value)
click to toggle source
Field log output
@example:
FDN:2 BC: 4 EA: 1 R: 0 BTN:4 uint16 message_# field_#: 0 65535
@param [String,Integer] value @return [String]
# File lib/f4r.rb, line 1031 def to_log_s(value) [ ('%-8s' % "FDN:#{field_definition_number.snapshot}"), ('%-8s' % "BC: #{byte_count.snapshot}"), ('%-8s' % "EA: #{endian_ability.snapshot}"), ('%-8s' % "R: #{reserved.snapshot}"), ('%-8s' % "BTN:#{base_type_number.snapshot}"), ('%-8s' % (base_type_definition[:fit])), global_message[:name], " #{name}: ", value, ].join(' ') end
Private Instance Methods
get_base_type_definition()
click to toggle source
Find base type definition for field
@return [Hash]
# File lib/f4r.rb, line 1052 def get_base_type_definition field_type = global_message_field[:field_type].to_sym global_type = GlobalFit.types[field_type] type_definition = GlobalFit.base_types.find do |dt| dt[:fit] == (global_type ? global_type[:base_type].to_sym : field_type) end unless type_definition Log.warn <<~WARN Data type "#{global_message_field[:field_type]}" is not a valid type for field field "#{global_message_field[:field_name]} (#{global_message_field[:filed_number]})" in message number "#{field_definition_number.snapshot}". WARN end type_definition end