Class: Cosmos::TableItem

Inherits:
PacketItem show all
Defined in:
lib/cosmos/tools/table_manager/table_item.rb

Overview

Maintains knowledge of an item in a Table

Constant Summary

Constants inherited from PacketItem

PacketItem::STATE_COLORS

Instance Attribute Summary collapse

Attributes inherited from PacketItem

#default, #description, #format_string, #hazardous, #id_value, #limits, #range, #read_conversion, #required, #state_colors, #states, #units, #units_full, #write_conversion

Instance Method Summary collapse

Methods inherited from PacketItem

#check_default_and_range_data_types, #meta

Constructor Details

#initialize(name, bit_offset, bit_size, data_type, endianness, array_size = nil, overflow = :ERROR) ⇒ TableItem

Create a StructureItem by setting all the attributes. It calls all the setter routines to do the attribute verification and then verifies the overall integrity.

It also initializes the attributes of the PacketItem. It also initializes the attributes of the TableItem.

Parameters:

  • name (String)

    The item name

  • bit_offset (Integer)

    Offset to the item starting at 0

  • bit_size (Integer)

    Size of the items in bits

  • data_type (Symbol)

    DATA_TYPES

  • endianness (Symbol)
  • array_size (Integer, nil) (defaults to: nil)

    Size of the array item in bits. For example, if the bit_size is 8, an array_size of 16 holds two values.



23
24
25
26
27
28
# File 'lib/cosmos/tools/table_manager/table_item.rb', line 23

def initialize(name, bit_offset, bit_size, data_type, endianness, array_size = nil, overflow = :ERROR)
  super(name, bit_offset, bit_size, data_type, endianness, array_size, overflow)
  @display_type = nil
  @editable = true
  @constraint = nil
end

Instance Attribute Details

#constraintObject

Returns the value of attribute constraint.



19
20
21
# File 'lib/cosmos/tools/table_manager/table_item.rb', line 19

def constraint
  @constraint
end

#display_typeObject

Returns the value of attribute display_type.



17
18
19
# File 'lib/cosmos/tools/table_manager/table_item.rb', line 17

def display_type
  @display_type
end

#editableObject

Returns the value of attribute editable.



18
19
20
# File 'lib/cosmos/tools/table_manager/table_item.rb', line 18

def editable
  @editable
end

Instance Method Details

#cloneObject Also known as: dup

Make a light weight clone of this item



49
50
51
52
53
# File 'lib/cosmos/tools/table_manager/table_item.rb', line 49

def clone
  item = super()
  item.constraint = self.constraint.clone if self.constraint
  item
end

#to_hashObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cosmos/tools/table_manager/table_item.rb', line 56

def to_hash
  hash = super()
  if self.display_type
    hash['display_type'] = self.display_type.to_s
  else
    hash['display_type'] = nil
  end
  hash['editable'] = self.editable
  if self.constraint
    hash['constraint'] = self.constraint.to_s
  else
    hash['constraint'] = nil
  end
  hash
end