Class: Cosmos::CmdTlmServerInterface
- Defined in:
- lib/cosmos/interfaces/cmd_tlm_server_interface.rb
Overview
Allows commands to be sent and telemetry received from the the CmdTlmServer.
Constant Summary
Constants included from Extract
Extract::SCANNING_REGULAR_EXPRESSION
Instance Attribute Summary
Attributes inherited from Interface
#auto_reconnect, #bytes_read, #bytes_written, #connect_on_startup, #disable_disconnect, #interfaces, #name, #num_clients, #options, #packet_log_writer_pairs, #raw_logger_pair, #read_count, #read_queue_size, #reconnect_delay, #routers, #target_names, #thread, #write_count, #write_queue_size
Instance Method Summary collapse
-
#connect ⇒ Object
Start the limits event subscription.
-
#connected? ⇒ Boolean
Always returns true.
-
#disconnect ⇒ Object
Unsubscribe from the limits events.
-
#initialize ⇒ CmdTlmServerInterface
constructor
Create the interface and disallow raw writes.
-
#raw_logger_pair=(raw_logger_pair) ⇒ Object
Raise an error because raw logging is not supported for this interface.
-
#read ⇒ Packet
Read from the CmdTlmServer interface by first getting the COSMOS VERSION packet and then continuously waiting for limits events and returning COSMOS LIMITS_CHANGE packets.
-
#write(packet) ⇒ Object
Write a packet to the CmdTlmServer to change various settings.
-
#write_raw(data) ⇒ Object
Raise an error because this method is not implemented for this interface.
Methods inherited from Interface
#copy_to, #post_identify_packet, #read_allowed?, #set_option, #start_raw_logging, #stop_raw_logging, #write_allowed?, #write_raw_allowed?
Methods included from Api
#cmd, #cmd_no_checks, #cmd_no_hazardous_check, #cmd_no_range_check, #cmd_raw, #cmd_raw_no_checks, #cmd_raw_no_hazardous_check, #cmd_raw_no_range_check, #connect_interface, #connect_router, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_limits, #enable_limits_group, #get_cmd_hazardous, #get_cmd_list, #get_cmd_log_filename, #get_cmd_param_list, #get_cmd_time, #get_cmd_value, #get_interface_names, #get_limits, #get_limits_event, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_out_of_limits, #get_overall_limits_state, #get_packet_data, #get_router_names, #get_server_message_log_filename, #get_stale, #get_target_list, #get_tlm_details, #get_tlm_item_list, #get_tlm_list, #get_tlm_log_filename, #get_tlm_packet, #get_tlm_values, #interface_state, #limits_enabled?, #map_target_to_interface, #router_state, #send_raw, #set_limits, #set_limits_set, #set_tlm, #set_tlm_raw, #start_cmd_log, #start_logging, #start_new_server_message_log, #start_raw_logging_interface, #start_raw_logging_router, #start_tlm_log, #stop_cmd_log, #stop_logging, #stop_raw_logging_interface, #stop_raw_logging_router, #stop_tlm_log, #subscribe_limits_events, #subscribe_packet_data, #tlm, #tlm_formatted, #tlm_raw, #tlm_variable, #tlm_with_units, #unsubscribe_limits_events, #unsubscribe_packet_data
Constructor Details
#initialize ⇒ CmdTlmServerInterface
Create the interface and disallow raw writes
20 21 22 23 24 25 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 20 def initialize super() @raw_logger_pair = nil @write_raw_allowed = false @limit_id = nil end |
Instance Method Details
#connect ⇒ Object
Start the limits event subscription
28 29 30 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 28 def connect @limit_id = CmdTlmServer.instance.subscribe_limits_events end |
#connected? ⇒ Boolean
Returns Always returns true.
33 34 35 36 37 38 39 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 33 def connected? if @limit_id return true else return false end end |
#disconnect ⇒ Object
Unsubscribe from the limits events
146 147 148 149 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 146 def disconnect CmdTlmServer.instance.unsubscribe_limits_events(@limit_id) if @limit_id @limit_id = nil end |
#raw_logger_pair=(raw_logger_pair) ⇒ Object
Raise an error because raw logging is not supported for this interface
141 142 143 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 141 def raw_logger_pair=(raw_logger_pair) raise "Raw logging not supported for CmdTlmServerInterface" end |
#read ⇒ Packet
Read from the CmdTlmServer interface by first getting the COSMOS VERSION packet and then continuously waiting for limits events and returning COSMOS LIMITS_CHANGE packets.
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 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 47 def read if @read_count == 0 begin packet = System.telemetry.packet("COSMOS","VERSION") packet.write('PKT_ID',1) packet.write('COSMOS', Cosmos::VERSION) packet.write('RUBY', "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}") packet.write('CTDB', System.cmd_tlm_version) packet.write('USER', USER_VERSION) if defined? USER_VERSION @read_count += 1 return packet rescue # if they haven't defined COSMOS VERSION we just fall through end end while true begin event = CmdTlmServer.instance.get_limits_event(@limit_id) if event if event[0] == :LIMITS_CHANGE data = event[1] packet ||= System.telemetry.packet("COSMOS","LIMITS_CHANGE") packet.received_time = Time.now packet.write('PKT_ID',2) packet.write('TARGET', data[0]) packet.write('PACKET', data[1]) packet.write('ITEM', data[2]) # For the first limits change the old_state is nil # so set it to a usable string data[3] = 'UNKNOWN' unless data[3] packet.write('OLD_STATE', data[3]) packet.write('NEW_STATE', data[4]) @read_count += 1 return packet end else return nil end rescue => error puts error.formatted # if they haven't defined COSMOS LIMITS_CHANGE we fall through # and break the loop because nothing will work break end end # Block forever Thread.stop end |
#write(packet) ⇒ Object
Write a packet to the CmdTlmServer to change various settings.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 100 def write(packet) @write_count += 1 command_data = packet.buffer @bytes_written += command_data.length identified_command = System.commands.identify(command_data, ['COSMOS']) if identified_command case identified_command.packet_name when 'STARTLOGGING' interface_name = identified_command.read('interface') label = identified_command.read('label') CmdTlmServer.instance.start_logging(interface_name, label) when 'STARTCMDLOG' interface_name = identified_command.read('interface') CmdTlmServer.instance.start_cmd_log(interface_name) when 'STARTTLMLOG' interface_name = identified_command.read('interface') CmdTlmServer.instance.start_tlm_log(interface_name) when 'STOPLOGGING' interface_name = identified_command.read('interface') CmdTlmServer.instance.stop_logging(interface_name) when 'STOPCMDLOG' interface_name = identified_command.read('interface') CmdTlmServer.instance.stop_cmd_log(interface_name) when 'STOPTLMLOG' interface_name = identified_command.read('interface') CmdTlmServer.instance.stop_tlm_log(interface_name) else raise "Command unhandled at COSMOS server interface. : #{identifed_command.packet_name}" end else raise "Unknown command received at COSMOS Server Interface." end end |
#write_raw(data) ⇒ Object
Raise an error because this method is not implemented for this interface
136 137 138 |
# File 'lib/cosmos/interfaces/cmd_tlm_server_interface.rb', line 136 def write_raw(data) raise "write_raw not implemented for CmdTlmServerInterface" end |