diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-04-21 14:15:14 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-04-21 14:15:14 +0200 |
commit | bc0bd155d03a8108badd441f8756739565fe300a (patch) | |
tree | d9621cb479402d65c514bfc9894f32ce8908dd7f /lib/Kratos/DFADriver | |
parent | f79cec3648491e7d178b372bcc1beaea9baaadef (diff) |
allow setting static params via LUT
Diffstat (limited to 'lib/Kratos/DFADriver')
-rw-r--r-- | lib/Kratos/DFADriver/DFA.pm | 5 | ||||
-rw-r--r-- | lib/Kratos/DFADriver/Model.pm | 29 |
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/Kratos/DFADriver/DFA.pm b/lib/Kratos/DFADriver/DFA.pm index db11a17..c17e054 100644 --- a/lib/Kratos/DFADriver/DFA.pm +++ b/lib/Kratos/DFADriver/DFA.pm @@ -143,6 +143,11 @@ sub run_str_to_trace { $self->model->update_parameter_hash( \%param, $cmd, @args ); ($state) = $dfa->successors( $state, ":${transition_str}" ); + + if (not defined $state) { + die("Transition $transition_str is invalid or has no successors\n"); + } + $prev_transition = $transition; for my $extra_cmd ( $self->model->get_state_extra_transitions( diff --git a/lib/Kratos/DFADriver/Model.pm b/lib/Kratos/DFADriver/Model.pm index 18bccfe..9f4f3f4 100644 --- a/lib/Kratos/DFADriver/Model.pm +++ b/lib/Kratos/DFADriver/Model.pm @@ -65,6 +65,13 @@ sub parse_xml_property { $param_idx++; } } + for my $lut_node ( $property_node->findnodes('./lut/*') ) { + my @paramkey = map { $_->[0]->getValue } + sort { $a->[1] cmp $b->[1] } + map { [ $_, $_->nodeName ] } + @{$lut_node->attributes->nodes}; + $ret->{lut}{join(';', @paramkey)} = 0 + $lut_node->textContent; + } return $ret; } @@ -95,12 +102,11 @@ sub parse_xml { my $param_name = $param_node->getAttribute('name'); my $function_name = $param_node->getAttribute('functionname'); my $function_arg = $param_node->getAttribute('functionparam'); - my $default = $param_node->textContent; $self->{parameter}{$param_name} = { function => $function_name, arg_name => $function_arg, - default => $default, + default => undef, }; } @@ -528,6 +534,25 @@ sub get_state_power { return $self->{states}{$name}{power}{static}; } +sub get_state_power_with_params { + my ($self, $name, $param_values) = @_; + + my $hash_str = join(';', map { $param_values->{$_} } + sort { $a cmp $b } keys %{$param_values} ); + + if (not $hash_str) { + return $self->get_state_power($name); + } + + if (exists $self->{states}{$name}{power}{lut}{$hash_str}) { + return $self->{states}{$name}{power}{lut}{$hash_str}; + } + + say "Note: No matching LUT for state ${name}, using median"; + + return $self->get_state_power($name); +} + sub get_state_enum { my ($self) = @_; |