Class: Cosmos::StateParser

Inherits:
Object show all
Defined in:
lib/cosmos/packets/parsers/state_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ StateParser

Returns a new instance of StateParser.

Parameters:



29
30
31
# File 'lib/cosmos/packets/parsers/state_parser.rb', line 29

def initialize(parser)
  @parser = parser
end

Class Method Details

.parse(parser, packet, cmd_or_tlm, item, warnings) ⇒ Object

Parameters:

  • parser (ConfigParser)

    Configuration parser

  • packet (Packet)

    The current packet

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet

  • item (PacketItem)

    The packet item to create states on

  • warnings (Array<String>)

    Array of string warnings which will be appended with any warnings found when parsing the limits



22
23
24
25
26
# File 'lib/cosmos/packets/parsers/state_parser.rb', line 22

def self.parse(parser, packet, cmd_or_tlm, item, warnings)
  @parser = StateParser.new(parser)
  @parser.verify_parameters(cmd_or_tlm)
  @parser.create_state(packet, cmd_or_tlm, item, warnings)
end

Instance Method Details

#create_state(packet, cmd_or_tlm, item, warnings) ⇒ Object

Parameters:

  • packet (Packet)

    The current packet

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet

  • item (PacketItem)

    The packet item to create states on

  • warnings (Array<String>)

    Array of string warnings which will be appended with any warnings found when parsing the limits



50
51
52
53
54
55
56
57
# File 'lib/cosmos/packets/parsers/state_parser.rb', line 50

def create_state(packet, cmd_or_tlm, item, warnings)
  item.states ||= {}

  state_name = get_state_name()
  check_for_duplicate_states(item, warnings)
  item.states[state_name] = get_state_value(item.data_type)
  parse_additional_parameters(packet, cmd_or_tlm, item)
end

#verify_parameters(cmd_or_tlm) ⇒ Object

Parameters:

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet



34
35
36
37
38
39
40
41
42
43
# File 'lib/cosmos/packets/parsers/state_parser.rb', line 34

def verify_parameters(cmd_or_tlm)
  @usage = "STATE <STATE NAME> <STATE VALUE> "
  if cmd_or_tlm == PacketConfig::COMMAND
    @usage << "<HAZARDOUS (Optional)> <Hazardous Description (Optional)>"
    @parser.verify_num_parameters(2, 4, @usage)
  else
    @usage << "<COLOR: GREEN/YELLOW/RED (Optional)>"
    @parser.verify_num_parameters(2, 3, @usage)
  end
end