Class: OpenC3::TableParser

Inherits:
PacketParser show all
Defined in:
lib/openc3/tools/table_manager/table_parser.rb

Overview

Parses the TABLE keyword definition in table configuration files.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PacketParser

check_item_data_types, #create_command, #create_packet, #create_telemetry, finish_create_command, finish_create_telemetry, #initialize, parse_command, parse_telemetry

Constructor Details

This class inherits a constructor from OpenC3::PacketParser

Class Method Details

.check_for_duplicate(tables, table) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/openc3/tools/table_manager/table_parser.rb', line 80

def self.check_for_duplicate(tables, table)
  msg = nil
  if tables[Table::TARGET][table.table_name]
    msg = "Table #{table.table_name} redefined."
    Logger.instance.warn msg
  end
  msg
end

.finish_create_table(table, tables, warnings) ⇒ Object



89
90
91
92
93
# File 'lib/openc3/tools/table_manager/table_parser.rb', line 89

def self.finish_create_table(table, tables, warnings)
  warning = TableParser.check_for_duplicate(tables, table)
  warnings << warning if warning
  table
end

.parse_table(parser, tables, warnings) ⇒ Object

Parameters:

  • parser (ConfigParser)

    Configuration parser

  • tables (Hash)

    Hash of the currently defined tables

  • warnings (Array<String>)

    Any warning strings generated while parsing this command will be appended to this array



33
34
35
36
37
# File 'lib/openc3/tools/table_manager/table_parser.rb', line 33

def self.parse_table(parser, tables, warnings)
  parser = TableParser.new(parser)
  parser.verify_parameters
  parser.create_table(tables, warnings)
end

Instance Method Details

#create_table(tables, warnings) ⇒ Object

Parameters:

  • tables (Array<Table>)

    All tables defined in the configuration

  • warnings (String)

    List of warnings to append to



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/openc3/tools/table_manager/table_parser.rb', line 48

def create_table(tables, warnings)
  params = @parser.parameters
  table_name = params[0].to_s.upcase
  endianness = params[1].to_s.upcase.to_sym
  if endianness != :BIG_ENDIAN && endianness != :LITTLE_ENDIAN
    raise @parser.error(
            "Invalid endianness #{params[1]}. Must be BIG_ENDIAN or LITTLE_ENDIAN.",
            @usage,
          )
  end
  type = params[2].to_s.upcase.to_sym
  case type
  when :KEY_VALUE, :ONE_DIMENSIONAL # :ONE_DIMENSIONAL is deprecated
    @parser.verify_num_parameters(3, 4, @usage)
    description = params[3].to_s
  when :ROW_COLUMN, :TWO_DIMENSIONAL # :TWO_DIMENSIONAL is deprecated
    @parser.verify_num_parameters(4, 5, @usage)
    num_rows = params[3].to_i
    description = params[4].to_s
  else
    raise @parser.error(
            "Invalid display type #{params[2]}. Must be KEY_VALUE or ROW_COLUMN.",
            @usage,
          )
  end
  table =
    Table.new(table_name, endianness, type, description, @parser.filename)
  table.num_rows = num_rows if type == :ROW_COLUMN
  TableParser.finish_create_table(table, tables, warnings)
end

#verify_parametersObject

Verify the correct number of arguments to the TABLE keyword



40
41
42
43
44
# File 'lib/openc3/tools/table_manager/table_parser.rb', line 40

def verify_parameters
  @usage =
    'TABLE <TABLE NAME> <ENDIANNESS: BIG_ENDIAN/LITTLE_ENDIAN> <DISPLAY: KEY_VALUE/ROW_COLUMN> <ROW_COLUMN ROW COUNT> <DESCRIPTION (Optional)>'
  @parser.verify_num_parameters(3, 5, @usage)
end