Class: F4R::Definition::RecordField
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- F4R::Definition::RecordField
- Defined in:
- lib/f4r.rb
Overview
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 |
Instance Method Summary collapse
-
#base_type_definition ⇒ Hash
Base type definitions for field.
-
#global_message ⇒ Hash
Global message for field.
-
#global_message_field ⇒ Hash
Global message field with all its properties.
- #name ⇒ String
- #number ⇒ Integer
-
#to_bindata_struct ⇒ Array
Returns field in [BinData::Struct] format.
-
#to_log_s(value) ⇒ String
Field log output.
Instance Method Details
#base_type_definition ⇒ Hash
Base type definitions for field
1018 1019 1020 |
# File 'lib/f4r.rb', line 1018 def base_type_definition @base_type_definition ||= get_base_type_definition end |
#global_message ⇒ Hash
Global message for field.
1009 1010 1011 |
# File 'lib/f4r.rb', line 1009 def @global_message ||= parent.parent. end |
#global_message_field ⇒ Hash
Global message field with all its properties
999 1000 1001 1002 |
# File 'lib/f4r.rb', line 999 def @global_message_field ||= [:fields]. find { |f| f[:field_def] == field_definition_number.snapshot } end |
#name ⇒ String
950 951 952 |
# File 'lib/f4r.rb', line 950 def name [:field_name] end |
#number ⇒ Integer
957 958 959 |
# File 'lib/f4r.rb', line 957 def number [:field_def] end |
#to_bindata_struct ⇒ Array
Returns field in [BinData::Struct] format. Field identifier is its number since some field names (e.g., ‘type’) are reserved [BinData::Struct] keywords.
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
# 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) ⇒ String
Field log output
@example:
FDN:2 BC: 4 EA: 1 R: 0 BTN:4 uint16 message_# field_#: 0 65535
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# 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])), [:name], " #{name}: ", value, ].join(' ') end |