Class: Orion6Rep::MultiMessageCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/orion6_rep/multi_message_command.rb

Direct Known Subclasses

EmployerGet

Instance Method Summary collapse

Methods inherited from Command

convert_to_integer_as_big_endian, convert_to_integer_as_little_endian, xor

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/orion6_rep/multi_message_command.rb', line 23

def execute
  # calculate how many messages will be needed:
  messages_quantity = get_field_quantity / get_field_size
  message_remainder = get_field_quantity % get_field_size

  payload = ""

  @messages_sent = 0
  messages_quantity.times do
    command_data = generate_partial_message_header
    payload += get_and_process_message(command_data)

    # For some very obscure reason, on each received message the next
    # command must increased by the size of the received payload.
    # Go figure...
    @command += payload.size
    @messages_sent += 1
  end

  if message_remainder > 0
    command_data = generate_remainder_header(message_remainder)
    payload += get_and_process_message(command_data)
  end

  return get_data_from_response(payload)
end