Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading with write conversion #1066

Merged
4 commits merged into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/cosmos/tools/cmd_sequence/cmd_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ def initialize_central_widget
end

def add_command
command = System.commands.packet(@target_select.text, @cmd_select.text).dup
command.restore_defaults
item = @sequence_list.add(command)
item = @sequence_list.add(@target_select.text, @cmd_select.text)
item.show_ignored(@show_ignored.isChecked())
item.states_in_hex(@states_in_hex.isChecked())
end
Expand Down
37 changes: 13 additions & 24 deletions lib/cosmos/tools/cmd_sequence/sequence_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,14 @@ class SequenceItem < Qt::Frame # Inherit from Frame so we can use setFrameStyle
signals 'modified()'
MANUALLY = "MANUALLY ENTERED"

# Parse a time and command string into a SequenceItem which is returned
# @param time [String] Time (absolute or relative delay). Supports a single
# float value (relative delay) or a absolute time specified as
# "YYYY/MM/DD HH:MM:SS.MS"
# @param command [String] Command String which should not be
# quoted and is everything inside the quotes of a command.
# For example: TGT PKT with STRING 'HI', VALUE 12. Parse errors are
# raised as execptions which must be handled by higher level code.
# @return [SequenceItem] SequenceItem which the line represents
def self.parse(time, command)
tgt_name, pkt_name, cmd_params = extract_fields_from_cmd_text(command)
packet = System.commands.packet(tgt_name, pkt_name).dup
packet.restore_defaults
cmd_params.each do |param_name, param_value|
packet.write(param_name, param_value)
end
SequenceItem.new(packet, time)
end

# Create a new SequenceItem based on the given command with the given delay
# @param command [Packet] Command packet
# @param time [String] Absolute time in YYYY/MM/DD HH:MM:SS format or a
# single float value representing the delta delay time
def initialize(command, time = nil)
def initialize(target, packet, params = nil, time = nil)
super()
@command = command
@command = System.commands.packet(target, packet).dup
@command.restore_defaults
@table = nil
@param_widgets = []
@show_ignored = false
Expand All @@ -68,7 +50,7 @@ def initialize(command, time = nil)
setLayout(top_layout)
top_layout.addLayout(create_cmd_layout(command, time))
top_layout.addWidget(create_parameters())
update_cmd_params()
update_cmd_params(existing: params)
set_cmd_name_info()
end

Expand All @@ -82,7 +64,7 @@ def read_only(bool)
# @param bool [Boolean] Whether to show ignored command items
def show_ignored(bool)
@show_ignored = bool
update_cmd_params(bool)
update_cmd_params(ignored_toggle: bool)
end

# Display state values in hex (or decimal)
Expand Down Expand Up @@ -266,7 +248,7 @@ def create_parameters
# Update the command parameters table for the given command
# @param ignored_toggle [Boolean] Whether to display the ignored
# parameters. Pass nil (the default) to keep the existing setting.
def update_cmd_params(ignored_toggle = nil)
def update_cmd_params(existing: nil, ignored_toggle: nil)
old_params = {}
if !ignored_toggle.nil?
# Save parameter values
Expand All @@ -280,6 +262,13 @@ def update_cmd_params(ignored_toggle = nil)
end
end

# If they passed in existing values override them here
if existing
existing.each do |param_name, param_value|
old_params[param_name] = param_value.to_s
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the essence of the fix. Use the parameter text directly instead of writing the underlying packet.

end
end

target = System.targets[@command.target_name]
packet_items = @command.sorted_items
shown_packet_items = []
Expand Down
12 changes: 7 additions & 5 deletions lib/cosmos/tools/cmd_sequence/sequence_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def open(filename)
usage = "#{keyword} <Delay Time> <Command>"
parser.verify_num_parameters(2, 2, usage)
begin
item = SequenceItem.parse(params[0], params[1])
tgt_name, pkt_name, cmd_params = extract_fields_from_cmd_text(params[1])
item = SequenceItem.new(tgt_name, pkt_name, cmd_params, params[0])
# Connect the SequenceItems modified signal to propagate it
# forward by emitting our own modified signal
item.connect(SIGNAL("modified()")) do
Expand All @@ -63,12 +64,13 @@ def open(filename)
@modified = false # Initially we're not modified
end

# Add a new SequenceItem to the list.
# @param command [Packet] Command packet to base the SequenceItem on
# Add a new SequenceItem to the list based on the given target and packet
# @param target [String] target name containing the command
# @param packet [String] packet name containing the command
# @return [SequenceItem] The item added
def add(command)
def add(target, packet)
@modified = true
item = SequenceItem.new(command)
item = SequenceItem.new(target, packet)
# Connect the SequenceItems modified signal to propagate it
# forward by emitting our own modified signal
item.connect(SIGNAL("modified()")) do
Expand Down