diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kratos/DFADriver.pm | 6 | ||||
-rw-r--r-- | lib/Kratos/DFADriver/Model.pm | 63 |
2 files changed, 66 insertions, 3 deletions
diff --git a/lib/Kratos/DFADriver.pm b/lib/Kratos/DFADriver.pm index 6acb686..046a013 100644 --- a/lib/Kratos/DFADriver.pm +++ b/lib/Kratos/DFADriver.pm @@ -615,6 +615,9 @@ sub update_model { @{ $state->{power}{function}{$fname}{params} } ); } + if ($self->{with_lut}) { + $self->model->set_state_lut( $name, 'power', $state->{power}{median_by_param} ); + } } for my $name (sort keys %{ $self->{log}{aggregate}{transition} }) { my $transition = $self->{log}{aggregate}{transition}{$name}; @@ -635,6 +638,9 @@ sub update_model { @{ $transition->{$key}{function}{$fname}{params} } ); } + if ($self->{with_lut}) { + $self->model->set_transition_lut( $name, $key, $transition->{$key}{median_by_param} ); + } } } diff --git a/lib/Kratos/DFADriver/Model.pm b/lib/Kratos/DFADriver/Model.pm index cb29f33..e6f8142 100644 --- a/lib/Kratos/DFADriver/Model.pm +++ b/lib/Kratos/DFADriver/Model.pm @@ -179,8 +179,8 @@ sub reset_property { my ($property_node) = $node->findnodes("./${name}"); if ($property_node) { - for my $static_node ($property_node->findnodes('./static')) { - $property_node->removeChild($static_node); + for my $attr_node ($property_node->findnodes('./static | ./lut')) { + $property_node->removeChild($attr_node); } for my $function_parent ($property_node->findnodes('./function')) { for my $function_node ($function_parent->childNodes) { @@ -218,11 +218,12 @@ sub set_state_power { my $state_node = $self->{states}{$state}{node}; $power = sprintf( '%.f', $power ); - $self->{states}{$state}{power}{static} = $power; printf( "state %-16s: adjust power %d -> %d µW\n", $state, $self->{states}{$state}{power}{static}, $power ); + $self->{states}{$state}{power}{static} = $power; + my ($static_parent) = $state_node->findnodes('./power'); if (not $static_parent) { $static_parent = XML::LibXML::Element->new('power'); @@ -275,6 +276,62 @@ sub set_transition_property { $static_parent->appendChild($static_node); } +sub set_state_lut { + my ($self, $state, $property, $lut) = @_; + my $state_node = $self->{states}{$state}{node}; + + if (not defined $lut) { + return; + } + + my ($lut_parent) = $state_node->findnodes("./${property}"); + for my $lut_node ( $lut_parent->findnodes('./lut') ) { + $lut_parent->removeChild($lut_node); + } + + my $lut_node = XML::LibXML::Element->new('lut'); + $lut_parent->appendChild($lut_node); + + for my $lut_entry (@{$lut}) { + my $entry_node = XML::LibXML::Element->new('entry'); + my $value_node = XML::LibXML::Text->new($lut_entry->{value}); + for my $param (sort keys %{$lut_entry->{key}}) { + $entry_node->setAttribute($param, $lut_entry->{key}{$param}); + } + $entry_node->appendChild($value_node); + $lut_node->appendChild($entry_node); + } +} + +sub set_transition_lut { + my ($self, $transition_name, $property, $lut) = @_; + + if (not defined $lut) { + return; + } + + my $transition = $self->get_transition_by_name($transition_name); + my $transition_node = $transition->{node}; + + my ($lut_parent) = $transition_node->findnodes("./${property}"); + for my $lut_node ( $lut_parent->findnodes('./lut') ) { + $lut_parent->removeChild($lut_node); + } + + my $lut_node = XML::LibXML::Element->new('lut'); + $lut_parent->appendChild($lut_node); + + for my $lut_entry (@{$lut}) { + my $entry_node = XML::LibXML::Element->new('entry'); + my $value_node = XML::LibXML::Text->new($lut_entry->{value}); + for my $param (sort keys %{$lut_entry->{key}}) { + $entry_node->setAttribute($param, $lut_entry->{key}{$param}); + } + $entry_node->appendChild($value_node); + $lut_node->appendChild($entry_node); + } +} + sub set_state_params { my ( $self, $state, $fun_name, $function, @params ) = @_; my $old_params = 'None'; |