Class: Cosmos::Table

Inherits:
Packet show all
Defined in:
lib/cosmos/tools/table_manager/table.rb

Overview

Table extends Packet by adding more attributes relative to displaying binary data in a gui.

Constant Summary collapse

TARGET =

Define the target for tables as ‘TABLE’ since there is no target

'TABLE'

Constants inherited from Packet

Packet::CATCH_ALL_STATE, Packet::RESERVED_ITEM_NAMES, Packet::VALUE_TYPES

Instance Attribute Summary collapse

Attributes inherited from Packet

#abstract, #cmd_or_tlm, #description, #disabled, #extra, #given_values, #hazardous, #hazardous_description, #hidden, #messages_disabled, #packet_name, #packet_rate, #raw, #received_count, #received_time, #stale, #stored, #target_name

Instance Method Summary collapse

Methods inherited from Packet

#append_item, #as_json, #buffer=, #check_bit_offsets, #check_limits, #clone, #config_name, #define, #define_item, #define_reserved_items, #disable_limits, #enable_limits, #formatted, from_json, #get_item, #id_items, #identified?, #identify?, #limits_change_callback=, #limits_items, #meta, #meta=, next_bit_offset, #out_of_limits, #packed?, #packet_time, #processors, #read, #read_all, #read_all_with_limits_states, #read_id_values, #read_item, #reset, #restore_defaults, #set_all_limits_states, #set_received_time_fast, #set_stale, #to_config, #update_id_items, #update_limits_items_cache, #write, #write_item

Constructor Details

#initialize(name, endianness, type, description, filename) ⇒ Table

Constructor for a TableDefinition



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cosmos/tools/table_manager/table.rb', line 42

def initialize(name, endianness, type, description, filename)
  super(TARGET, name, endianness, description, '', TableItem)
  # ONE_DIMENSIONAL and TWO_DIMENSIONAL are deprecated so translate
  type = :KEY_VALUE if type == :ONE_DIMENSIONAL
  type = :ROW_COLUMN if type == :TWO_DIMENSIONAL
  if type != :KEY_VALUE && type != :ROW_COLUMN
    raise ArgumentError,
          "Invalid type '#{type}' for table '#{name}'. Must be KEY_VALUE or ROW_COLUMN"
  end
  @type = type
  @filename = filename
  @num_rows = 0
  @num_columns = (@type == :KEY_VALUE) ? 1 : 0
end

Instance Attribute Details

#filenameString (readonly)

Returns File which contains the table definition.

Returns:

  • (String)

    File which contains the table definition



34
35
36
# File 'lib/cosmos/tools/table_manager/table.rb', line 34

def filename
  @filename
end

#num_columnsInteger

Returns Number of columns in the table.

Returns:

  • (Integer)

    Number of columns in the table



37
38
39
# File 'lib/cosmos/tools/table_manager/table.rb', line 37

def num_columns
  @num_columns
end

#typeSymbol (readonly)

Returns Either :KEY_VALUE or :ROW_COLUMN.

Returns:

  • (Symbol)

    Either :KEY_VALUE or :ROW_COLUMN



31
32
33
# File 'lib/cosmos/tools/table_manager/table.rb', line 31

def type
  @type
end

Instance Method Details

#num_rowsInteger

Returns Number of rows in the table.

Returns:

  • (Integer)

    Number of rows in the table



68
69
70
71
72
73
74
75
# File 'lib/cosmos/tools/table_manager/table.rb', line 68

def num_rows
  case @type
  when :KEY_VALUE
    @sorted_items.count { |item| !item.hidden }
  when :ROW_COLUMN
    @num_rows
  end
end

#num_rows=(num_rows) ⇒ Object

Parameters:

  • num_rows (Integer)

    Set the number of rows in a ROW_COLUMN table



58
59
60
61
62
63
64
65
# File 'lib/cosmos/tools/table_manager/table.rb', line 58

def num_rows=(num_rows)
  case @type
  when :KEY_VALUE
    raise 'Rows are fixed in a KEY_VALUE table'
  when :ROW_COLUMN
    @num_rows = num_rows
  end
end