Skip to content

Commit

Permalink
improve commenting, change delay values, address jasons comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Nov 16, 2017
1 parent abd673f commit eae2b12
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 31 deletions.
4 changes: 2 additions & 2 deletions demo/procedures/replay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
wait(2)
replay_set_playback_delay(0.125)
wait(5)
replay_set_playback_delay(-1.0)
wait(2)
replay_set_playback_delay(nil)
wait(2)
replay_set_playback_delay(0.0)
wait(4)
replay_stop()
replay_reverse_play()
Expand Down
5 changes: 5 additions & 0 deletions lib/cosmos/system/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ def self.load_configuration(name = nil)
return self.instance.load_configuration(name)
end

# Resets the System's internal state to defaults.
#
# @params [String] Path to system.txt config file to process. Defaults to config/system/system.txt
def reset_variables(filename = nil)
@targets = {}
@targets['UNKNOWN'] = Target.new('UNKNOWN')
Expand Down Expand Up @@ -561,11 +564,13 @@ def reset_variables(filename = nil)
@initial_config = nil
end

# Reset variables and load packets
def reset(filename = nil)
reset_variables(filename)
load_packets()
end

# Class level convenience reset method
def self.reset
self.instance.reset
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/tools/cmd_tlm_server/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ def replay_status

# Set the replay delay
#
# @param delay [Float] delay between packets in seconds 0.0 to 1.0, nil = No Delay, -1.0 = REALTIME
# @param delay [Float] delay between packets in seconds 0.0 to 1.0, nil = REALTIME
def replay_set_playback_delay(delay)
CmdTlmServer.replay_backend.set_playback_delay(delay)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def self.meta_callback= (meta_callback)
@@meta_callback = meta_callback
end

# Constructor for a CmdTlmServer
# Constructor for a CmdTlmServer. Initializes all internal state and
# starts up the sever
#
# @param config_file [String] The name of the server configuration file
# which must be in the config/tools/cmd_tlm_server directory.
Expand All @@ -124,6 +125,7 @@ def self.meta_callback= (meta_callback)
# stand-alone mode which does not actually use the interfaces to send and
# receive data. This is useful for testing scripts when actual hardware
# is not available.
# @param mode [Symbol] :CMD_TLM_SERVER or :REPLAY - Defines overall mode
def initialize(
config_file = DEFAULT_CONFIG_FILE,
production = false,
Expand Down Expand Up @@ -681,7 +683,7 @@ def identified_packet_callback(packet)
#
# This method is shoudl only called by initialize which is why it is private
#
# @param production (see #initialize)
# @param start_packet_logging [Boolean] Whether to start logging data or not
def start(start_packet_logging = false)
if @mode == :CMD_TLM_SERVER
@replay_backend = nil # Remove access to Replay
Expand Down
6 changes: 3 additions & 3 deletions lib/cosmos/tools/cmd_tlm_server/gui/replay_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def populate
@playback_delay = nil
@speed_select = Qt::ComboBox.new
@variants = []
@variants << [Qt::Variant.new(nil), nil]
@variants << [Qt::Variant.new(0.0), 0.0]
@speed_select.addItem("No Delay", @variants[-1][0])
@variants << [Qt::Variant.new(0.001), 0.001]
@speed_select.addItem("1ms Delay", @variants[-1][0])
Expand All @@ -129,7 +129,7 @@ def populate
@speed_select.addItem("500ms Delay", @variants[-1][0])
@variants << [Qt::Variant.new(1.0), 1.0]
@speed_select.addItem("1s Delay", @variants[-1][0])
@variants << [Qt::Variant.new(-1.0), -1.0]
@variants << [Qt::Variant.new(nil), nil]
@speed_select.addItem("Realtime", @variants[-1][0])
@speed_select.setMaxVisibleItems(11)
@speed_select.connect(SIGNAL('currentIndexChanged(int)')) do
Expand Down Expand Up @@ -192,7 +192,7 @@ def update
end
unless found
@variants << [Qt::Variant.new(playback_delay.to_f), playback_delay.to_f]
@speed_select.addItem("#{(playback_delay.to_f * 1000.0).to_i}ms Delay", @variants[-1][0])
@speed_select.addItem("#{(playback_delay.to_f * 1000.0).to_i}ms Delay", @variants[-1][0])
@speed_select.currentIndex = @variants.length - 1
end
@start_time.value = file_start
Expand Down
49 changes: 26 additions & 23 deletions lib/cosmos/tools/cmd_tlm_server/replay_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def initialize(cmd_tlm_server_config)
reset()
@config_change_callback = nil
end

# Reset internal state
def reset
@cancel = false
@playback_delay = nil
@playback_delay = 0.0
@default_packet_log_reader = System.default_packet_log_reader.new(*System.default_packet_log_reader_params)
@packet_log_reader = @default_packet_log_reader
@log_directory = System.paths['LOGS']
Expand All @@ -41,13 +41,13 @@ def reset
@playback_sleeper = nil
@thread = nil
@playback_index = 0
@playback_max_index = 0
@playback_max_index = 0
@packet_offsets = []
@progress = 0
@status = ''
@status = ''
@start_time = ''
@current_time = ''
@end_time = ''
@end_time = ''
end

# Select and start analyzing a file for replay
Expand Down Expand Up @@ -84,12 +84,12 @@ def select_file(filename, packet_log_reader = 'DEFAULT')
if System.configuration_name != start_config_name
@config_change_callback.call() if @config_change_callback
end
@packet_offsets = @packet_log_reader.packet_offsets(@log_filename, lambda {|percentage|
@packet_offsets = @packet_log_reader.packet_offsets(@log_filename, lambda {|percentage|
progress_int = (percentage * 100).to_i
if @progress != progress_int
@progress = progress_int
@status = "Analyzing: #{@progress}%"
end
end
@cancel
})
@playback_index = 0
Expand All @@ -108,7 +108,7 @@ def select_file(filename, packet_log_reader = 'DEFAULT')
packet = read_at_index(@packet_offsets.length - 1, :FORWARD)
@end_time = packet.received_time.formatted(true, 3, true) if packet and packet.received_time
packet = read_at_index(0, :FORWARD)
@start_time = packet.received_time.formatted(true, 3, true) if packet and packet.received_time
@start_time = packet.received_time.formatted(true, 3, true) if packet and packet.received_time
end
rescue Exception => error
Logger.error "Error in Analysis Thread\n#{error.formatted}"
Expand All @@ -117,21 +117,21 @@ def select_file(filename, packet_log_reader = 'DEFAULT')
@playing = false
@playback_sleeper = nil
@thread = nil
end
end
end
end
end

# Get current replay status
#
# status, playback_delay, filename, file_start, file_current, file_end, file_index, file_max_index
# @return [status, playback_delay, filename, file_start, file_current, file_end, file_index, file_max_index]
def status
[@status,
@playback_delay,
@log_filename.to_s,
@start_time,
@current_time,
@end_time,
@playback_index,
[@status,
@playback_delay,
@log_filename.to_s,
@start_time,
@current_time,
@end_time,
@playback_index,
@playback_max_index]
end

Expand All @@ -141,8 +141,8 @@ def status
def set_playback_delay(delay)
if delay
delay = delay.to_f
if delay < 0.0
@playback_delay = -1.0
if delay <= 0.0
@playback_delay = 0.0
elsif delay > 1.0
@playback_delay = 1.0
else
Expand Down Expand Up @@ -238,7 +238,7 @@ def shutdown
# Gracefully kill threads
def graceful_kill
stop()
end
end

private

Expand All @@ -252,14 +252,16 @@ def start_playback(direction)

previous_packet = nil
while (@playing)
if @playback_delay
if @playback_delay != 0.0
packet_start = Time.now.sys
packet = read_at_index(@playback_index, direction)
break unless packet
delay_time = 0.0
if @playback_delay > 0.0
if @playback_delay
# Fixed Time Delay
delay_time = @playback_delay - (Time.now.sys - packet_start)
elsif previous_packet and packet.received_time and previous_packet.received_time
# Realtime
if direction == :FORWARD
delay_time = packet.received_time - previous_packet.received_time - (Time.now.sys - packet_start)
else
Expand All @@ -271,6 +273,7 @@ def start_playback(direction)
end
previous_packet = packet
else
# No Delay
packet = read_at_index(@playback_index, direction)
break unless packet
previous_packet = packet
Expand Down

0 comments on commit eae2b12

Please sign in to comment.