Class: Cosmos::Commanding
- Defined in:
- lib/cosmos/tools/cmd_tlm_server/commanding.rb
Overview
Sends command packets to targets or interfaces. Utilizes the System knowledge of targets and commands to correctly identify interfaces and commands before sending. Also provides #send_raw to directly send raw binary data to an interface.
Instance Method Summary collapse
-
#initialize(cmd_tlm_server_config) ⇒ Commanding
constructor
A new instance of Commanding.
-
#send_command_to_interface(interface, packet) ⇒ Object
Sends the packet to the given interface and performs other common command sending tasks.
-
#send_command_to_target(target_name, packet) ⇒ Object
Sends a command to the interface associated with the given target and logs the command using its log writer.
-
#send_raw(interface_name, data) ⇒ Object
Sends raw data to the specified interface.
Constructor Details
#initialize(cmd_tlm_server_config) ⇒ Commanding
Returns a new instance of Commanding.
20 21 22 |
# File 'lib/cosmos/tools/cmd_tlm_server/commanding.rb', line 20 def initialize(cmd_tlm_server_config) @config = cmd_tlm_server_config end |
Instance Method Details
#send_command_to_interface(interface, packet) ⇒ Object
Sends the packet to the given interface and performs other common command sending tasks.
46 47 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cosmos/tools/cmd_tlm_server/commanding.rb', line 46 def send_command_to_interface(interface, packet) # Make sure packet received time is set packet.received_time ||= Time.now unless packet.identified? identified_command = System.commands.identify(packet.buffer, interface.target_names) if identified_command identified_command.received_time = packet.received_time identified_command.raw = packet.raw packet = identified_command end end # Log to messages command being sent, update counters, and initially update current value table target = nil if packet.identified? command = System.commands.packet(packet.target_name, packet.packet_name) raise "Cannot send DISABLED command #{packet.target_name} #{packet.packet_name}" if packet.disabled target = System.targets[packet.target_name] target.cmd_cnt += 1 else command = System.commands.packet('UNKNOWN', 'UNKNOWN') Logger.warn "Unidentified packet of #{packet.length} bytes being sent to interface #{interface.name}" end command.received_time = packet.received_time command.raw = packet.raw command.buffer = packet.buffer command.received_count += 1 Logger.info System.commands.format(command, target.ignored_parameters) if !command. and command.target_name != 'UNKNOWN' if packet.identified? # Write the identified and defined packet to the interface interface.write(command) else # Write the unidentified and undefined packet to the interface # We do not want to give interfaces packets identified and defined as UNKNOWN UNKNOWN interface.write(packet) # Note: packet may have been modified by the interface to fill in a CRC, length, etc. # The following actions are done after a successful write to incorporate these possible # changes. # Update current value table again after successful write command.buffer = packet.buffer end # Write to command packet logs interface.packet_log_writer_pairs.each do |packet_log_writer_pair| packet_log_writer_pair.cmd_log_writer.write(command) end end |
#send_command_to_target(target_name, packet) ⇒ Object
Sends a command to the interface associated with the given target and logs the command using its log writer
Commands should be identified before this method is called.
31 32 33 34 35 36 37 38 39 |
# File 'lib/cosmos/tools/cmd_tlm_server/commanding.rb', line 31 def send_command_to_target(target_name, packet) # Create guaranteed uppercase target name target = System.targets[target_name.upcase] raise "Unknown target: #{target_name}" unless target raise "Target not mapped to an interface: #{target_name}" unless target.interface # Send the command send_command_to_interface(target.interface, packet) end |
#send_raw(interface_name, data) ⇒ Object
Sends raw data to the specified interface. Note: Raw data is not logged to the command packet log, because packet boundaries are not known.
103 104 105 106 107 108 |
# File 'lib/cosmos/tools/cmd_tlm_server/commanding.rb', line 103 def send_raw(interface_name, data) interface = @config.interfaces[interface_name.upcase] raise "Unknown interface: #{interface_name}" unless interface Logger.warn "Unlogged raw data of #{data.length} bytes being sent to interface #{interface_name}" interface.write_raw(data) end |