Class: Cosmos::SimulatedTargetInterface
- Defined in:
- lib/cosmos/interfaces/simulated_target_interface.rb
Overview
An interface class that provides simulated telemetry and command responses
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, #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
Initialize the simulated target object and “connect” to the target.
-
#connected? ⇒ Boolean
Whether the simulated target is connected (initialized).
-
#disconnect ⇒ Object
Disconnect from the simulator.
-
#initialize(sim_target_file) ⇒ SimulatedTargetInterface
constructor
A new instance of SimulatedTargetInterface.
-
#raw_logger_pair=(raw_logger_pair) ⇒ Object
Raise an error because raw logging is not supported for this interface.
-
#read ⇒ Packet
Returns a simulated target packet from the simulator.
- #write(packet) ⇒ Object
-
#write_raw(data) ⇒ Object
write_raw is not implemented and will raise a RuntimeError.
Methods inherited from Interface
#copy_to, #post_identify_packet, #read_allowed?, #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_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_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(sim_target_file) ⇒ SimulatedTargetInterface
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 19 def initialize(sim_target_file) super() @connected = false @initialized = false @count_100hz = 0 @next_tick_time = nil @pending_packets = [] @sim_target_class = Cosmos.require_class sim_target_file @sim_target = nil @write_raw_allowed = false @raw_logger_pair = nil end |
Instance Method Details
#connect ⇒ Object
Initialize the simulated target object and “connect” to the target
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 35 def connect unless @initialized # Save the current time + 10 ms as the next expected tick time @next_tick_time = Time.now + 0.01 # Create Simulated Target Object @sim_target = @sim_target_class.new(@target_names[0]) # Set telemetry rates @sim_target.set_rates @initialized = true end @connected = true end |
#connected? ⇒ Boolean
53 54 55 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 53 def connected? @connected end |
#disconnect ⇒ Object
Disconnect from the simulator
112 113 114 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 112 def disconnect @connected = false end |
#raw_logger_pair=(raw_logger_pair) ⇒ Object
Raise an error because raw logging is not supported for this interface
107 108 109 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 107 def raw_logger_pair=(raw_logger_pair) raise "Raw logging not supported for SimulatedTargetInterface" end |
#read ⇒ Packet
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 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 58 def read if @connected packet = first_pending_packet() return packet if packet while true # Calculate time to sleep to make ticks 10ms apart now = Time.now delta = @next_tick_time - now if delta > 0.0 sleep(delta) # Sleep up to 10 ms return nil unless @connected elsif delta < -1.0 # Fell way behind - jump next tick time @next_tick_time = Time.now end @pending_packets = @sim_target.read(@count_100hz, @next_tick_time) @next_tick_time += 0.01 @count_100hz += 1 packet = first_pending_packet() return packet if packet end else raise "Interface not connected" end end |
#write(packet) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 88 def write(packet) if @connected # Update count of commands sent through this interface @write_count += 1 @bytes_written += packet.buffer.length # Have simulated target handle the packet @sim_target.write(packet) else raise "Interface not connected" end end |
#write_raw(data) ⇒ Object
write_raw is not implemented and will raise a RuntimeError
102 103 104 |
# File 'lib/cosmos/interfaces/simulated_target_interface.rb', line 102 def write_raw(data) raise "write_raw not implemented for SimulatedTargetInterface" end |