Commit 900dd7d9 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

FIJI: allow default values to be calculated by functions

Use this to set the available UART ports and default timer values.
The latter gets rid of FIJI::DEFAULT_TIMER_VALUE by replacing it with
FIJI::Settings::default_timer_value().

However, it requires some non-trivial changes, namely the refactoring
of FIJI::Tests. While at it, we got almost rid of the 'ext' field in
Tests. It is lessened to 'TESTPATMAP' containing info to verify tests.

The refactoring also allows for unification of opening of tests files
in the EE GUI. To that end this patch adds _read_tests_file() that
handles creation of the Tests instance and handle user interaction if
need be.
parent b4e84b4f
......@@ -24,7 +24,6 @@ use Cwd;
use strict;
use warnings;
use constant DEFAULT_TIMER_VALUE => 1000000;
use Cwd 'realpath';
use File::Spec;
use Log::Log4perl qw(:easy);
......@@ -774,7 +773,8 @@ use constant FIUMAP => \%fiumap;
# The respective constant is only relevant (and thuse required as input)
# if the value of the referenced constant is true.
# - order (optional) specifies how to sort this value in output group
# - default (optional) default value if not given in file and not determinable otherwise
# - default (optional) default value if not given in file and not determinable otherwise,
# Can either be a scalar or a function pointer expecting a FIJI settings reference.
# - help (optional) short help text, e.g. to be displayed via Tk:Balloon
# The respective constant may not be enabled if the value
# of the referenced constant is true
......@@ -793,7 +793,10 @@ BEGIN {
UART => {
description => "Control UART",
ini_name => "UART",
default => "/dev/ttyUSB0",
default => sub {
my $devs = FIJI::Utils::get_uart_devs();
return (scalar(@$devs) > 0) ? @{$devs}[0] : "";
},
type => "autocomplete",
gui_modes => [qw (manual auto random)],
values => \&FIJI::Utils::get_uart_devs,
......@@ -875,7 +878,7 @@ BEGIN {
MIN_DURATION_T1 => {
description => "Minimum Duration T1",
ini_name => "MIN_DURATION_T1",
default => DEFAULT_TIMER_VALUE,
default => sub {shift->default_timer_value()},
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "min_duration",
......@@ -886,7 +889,7 @@ BEGIN {
MIN_DURATION_T2 => {
description => "Minimum Duration T2",
ini_name => "MIN_DURATION_T2",
default => DEFAULT_TIMER_VALUE,
default => sub {shift->default_timer_value()},
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "min_duration",
......@@ -897,7 +900,7 @@ BEGIN {
MAX_DURATION_T1 => {
description => "Maximum Duration T1",
ini_name => "MAX_DURATION_T1",
default => (10 * DEFAULT_TIMER_VALUE),
default => sub {10 * shift->default_timer_value()},
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "max_duration",
......@@ -908,7 +911,7 @@ BEGIN {
MAX_DURATION_T2 => {
description => "Maximum Duration T2",
ini_name => "MAX_DURATION_T2",
default => (10 * DEFAULT_TIMER_VALUE),
default => sub {10 * shift->default_timer_value()},
phases_opt => [qw(manual auto)],
gui_modes => [qw (random)],
type => "max_duration",
......@@ -1158,7 +1161,6 @@ our @EXPORT_OK = ('FIJI_DOCUMENTATION_PATH',
'TESTGUIMODES',
keys(%testguimodes),
'HOST_TO_FIJI_LATENCY',
'DEFAULT_TIMER_VALUE',
'OPTIMIZATIONS',
'LFSR_POLY_CHOICES',
'DISPLAYGROUPS_FIU_KEY',
......
......@@ -89,7 +89,7 @@ sub settings_from_file {
my ($self, $cfgname) = @_;
my ($fiji_settings, $warn) = FIJI::Settings->new("download", $cfgname);
if (!defined($fiji_settings)) {
$rv = $warn . " Aborting.\n";
$rv = $warn;
} else {
$logger->warn($warn) if defined $warn;
$rv = $self->{'fiji_settings'} = $fiji_settings;
......@@ -121,9 +121,9 @@ sub tests_from_file {
my $logger = get_logger("");
my ($self, $mode, $set_ref, $cfgname) = @_;
$logger->info("New Tests for mode '$mode'");
my $fiji_tests = FIJI::Tests->new($mode, $set_ref, $cfgname);
my ($fiji_tests, $warn) = FIJI::Tests->new($mode, $set_ref, $cfgname);
if (!ref($fiji_tests)) {
$rv = $fiji_tests . " Aborting.\n";
$rv = $warn;
} else {
$rv = $self->{'fiji_tests'} = $fiji_tests;
}
......
......@@ -76,7 +76,7 @@ sub new ($;$$) {
if (defined($fiji_ini_file)) {
($fiji_settings_ref, $warn) = read_settingsfile($phase, $fiji_ini_file, $fiji_settings_ref);
if (!defined($fiji_settings_ref)) {
return ($fiji_settings_ref, $warn);
return (undef, $warn);
}
$fiji_settings_ref->{'filename'} = $fiji_ini_file;
} else {
......@@ -344,6 +344,15 @@ sub set_fiu_defaults ($) {
return _set_defaults(FIUMAP, $consts_ref);
}
## @method public default_timer_value()
# @brief Return sensible default timer values for these settings
sub default_timer_value {
my ($self) = @_;
# default to 10 ms at default frequency
return (10e-3 * $self->{'design'}->{'FREQUENCY'});
}
## @function _set_defaults (%$map_ref, %$consts_ref)
# @brief Set defaults according to FIJI.pm.
sub _set_defaults {
......@@ -520,7 +529,7 @@ sub _rename_import {
}
foreach my $entry_key (keys(%{$consts_ref})) {
if (!exists($map_ref->{$entry_key})) {
$logger->debug("Deleting unknown setting %s = %s.", $entry_key, $consts_ref->{$entry_key});
$logger->debug(sprintf("Deleting unknown setting %s = %s.", $entry_key, $consts_ref->{$entry_key}));
delete $consts_ref->{$entry_key};
}
}
......@@ -570,7 +579,7 @@ sub _validate_hashmap {
my $ini_name = $map_ref->{$entry_key}->{'ini_name'};
if (!exists($map_ref->{$entry_key})) {
$logger->debug("Deleting unknown setting %s = %s.", $entry_key, $consts_ref->{$entry_key});
$logger->debug(sprintf("Deleting unknown setting %s = %s.", $entry_key, $consts_ref->{$entry_key}));
next;
}
......
This diff is collapsed.
......@@ -78,10 +78,10 @@ sub test {
# set defaults
if (!defined $self->{'test'}->{'TIMER_VALUE_1'}) {
$self->{'test'}->{'TIMER_VALUE_1'} = 0;
$self->{'test'}->{'TIMER_VALUE_1'} = $self->{'settings'}->default_timer_value();
}
if (!defined $self->{'test'}->{'TIMER_VALUE_2'}) {
$self->{'test'}->{'TIMER_VALUE_2'} = 0;
$self->{'test'}->{'TIMER_VALUE_2'} = $self->{'settings'}->default_timer_value();
}
if (!defined $self->{'test'}->{'RESET_DUT_AFTER_CONFIG'}) {
$self->{'test'}->{'RESET_DUT_AFTER_CONFIG'} = 0;
......
......@@ -138,12 +138,6 @@ sub Populate {
$self->{'tests'}->{'tests'} = [];
}
if ( ($self->{'tests'}->{'ext'}->{'CFGS_PER_MSG'} != $self->{'settings'}->{'design'}->{'CFGS_PER_MSG'})
|| ($self->{'tests'}->{'ext'}->{'FIU_NUM'} != $self->{'settings'}->{'design'}->{'FIU_NUM'}))
{
$logger->error("Given Tests file does not match Settings file.");
return;
}
$self->{'original_tests'} = clone($tests);
$self->{'original_tests'}->{'tests'} = clone($tests->{'tests'});
$self->traceVariable($self->{'tests'}->{'design'}, 'w' => [\&_watch_settings, $self]);
......@@ -1017,8 +1011,8 @@ sub _add_test ($$) {
my $lbl = $self->{'fr_tests'}->Label('-text' => "Test $i",);
my $t1 = $self->{'fr_tests'}->Entry(-text => @{$self->{'tests'}->{'tests'}}[$i]->{'TIMER_VALUE_1'}, -state => "readonly");
my $t2 = $self->{'fr_tests'}->Entry(-text => @{$self->{'tests'}->{'tests'}}[$i]->{'TIMER_VALUE_2'}, -state => "readonly");
my $t1 = $self->{'fr_tests'}->Entry(-text => $test->{'TIMER_VALUE_1'}, -state => "readonly");
my $t2 = $self->{'fr_tests'}->Entry(-text => $test->{'TIMER_VALUE_2'}, -state => "readonly");
my $edit_button = $self->{'fr_tests'}->Button(
-text => 'Edit',
......
......@@ -235,7 +235,7 @@ sub main {
if (defined $settings_filename && (-e $settings_filename)) {
my $filename = $settings_filename;
my ($tmp_settings, $warn) = FIJI::Settings->new('setup', $filename);
my ($tmp_settings, $warn) = FIJI::Settings->new('download', $filename);
if (defined($warn)) {
my $msg = "Settings file $filename could not be loaded correctly.";
$msg .= "\n$warn" if (defined($warn));
......@@ -264,36 +264,23 @@ sub main {
goto bailout;
}
if (defined $tests_filename) {
my $filename = $tests_filename;
my $fr = $mw;
if (-e $filename) {
# the mode 'GUI' is not defined in any ->phases_opt lists in TESTCONSTMAP and TESTPATMAP, thus all possible parameters have to be present.
my $tmp_tests = FIJI::Tests->new('GUI', $self->{'settings'}, $filename,);
if (!ref($tmp_tests)) {
my $msg = "Tests file $filename could not be loaded correctly: $tmp_tests";
$logger->error($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-image => Tk::FIJIUtils::error_image($self->{'mw'}),
-wraplength => "200",
-text => $msg,
-title => 'Open FIJI Tests failed!',);
$d->Show();
$ret = 1;
goto bailout;
}
$self->{'tests'} = $tmp_tests;
} else {
# the mode 'GUI' is not defined in any ->phases_opt lists in TESTCONSTMAP and TESTPATMAP, thus all possible parameters have to be present.
$self->{'tests'} = FIJI::Tests->new('GUI', $self->{'settings'}->{'design'}, undef, undef, 1);
$self->{'tests'}->save($filename);
}
${$self->{'tests_ini_name'}} = $filename;
$current_dir = _setdir($filename);
my $tmp_tests;
if (defined($tests_filename)) {
# Try loading it
$tmp_tests = $self->_read_tests_file($tests_filename,);
} else {
# Create one with defaults
$logger->info("No test file given. Creating one with defaults.");
my $warn;
# the mode 'GUI' is not defined in any ->phases_opt lists in TESTCONSTMAP and TESTPATMAP, thus all possible parameters have to be present.
$self->{'tests'} = FIJI::Tests->new('GUI', $self->{'settings'}, undef, undef, 1);
${$self->{'tests_ini_name'}} = undef;
($tmp_tests, $warn) = FIJI::Tests->new('GUI', $self->{'settings'}, undef, undef, 1);
$logger->error($warn) if (defined($warn));
}
if (!ref($tmp_tests)) {
$ret = 1;
goto bailout;
}
$self->{'tests'} = $tmp_tests;
$downloader = FIJI::Downloader->new(undef,undef,$self->{'tests'}, undef, $self->{'settings'});
$self->{'ctrl'} = _ctrl_frame($self, $mw);
......@@ -627,6 +614,45 @@ sub _ctrl_frame {
return $fr_ctrl;
}
## @method private _read_tests_file ($self, $filename)
#
# @brief Creates a new FIJI::Tests object by reading the given file
#
# @returns the newly created FIJI::Tests object
sub _read_tests_file {
my $logger = get_logger("");
my ($self, $filename) = @_;
my $tmp_tests;
if (-e $filename) {
# the mode 'GUI' is not defined in any ->phases_opt lists in TESTCONSTMAP and TESTPATMAP, thus all possible parameters have to be present.
my $msg_ref;
($tmp_tests, $msg_ref) = FIJI::Tests->new('GUI', $self->{'settings'}, $filename,);
if (defined($msg_ref)) {
my $msg;
if (!defined($tmp_tests)) {
$msg = "Tests file $filename could not be loaded correctly:\n";
} else {
$msg = "Tests file $filename contained errors:\n";
}
if (ref($msg_ref) eq "ARRAY") {
$msg .= join("\n", @$msg_ref);
} else {
$msg .= $msg_ref;
}
$logger->error($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-image => Tk::FIJIUtils::error_image($self->{'mw'}),
-wraplength => "500",
-text => $msg,
-title => 'Open FIJI Tests failed!',);
$d->Show();
return undef;
}
}
${$self->{'tests_ini_name'}} = $filename;
$current_dir = _setdir($filename);
return $tmp_tests;
}
sub _open_tests_file {
my $logger = get_logger("");
my $self = shift;
......@@ -647,17 +673,11 @@ sub _open_tests_file {
}
$current_dir = _setdir($filename);
my $tmp_tests = (defined $self->{'tests'}) ? \%{Clone::clone($self->{'tests'})} : undef;
$tmp_tests = FIJI::Tests->new('GUI', $self->{'settings'}, $filename, $tmp_tests);
$tmp_tests = $self->_read_tests_file($filename);
if (!ref($tmp_tests)) {
my $msg = "Tests file $filename could not be loaded correctly:\n$tmp_tests";
$logger->error($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-image => Tk::FIJIUtils::error_image($self->{'mw'}),
-wraplength => "200",
-text => $msg,
-title => 'Open FIJI Tests failed!',);
$d->Show();
return;
}
if (!defined($self->{'FIJITestsViewer'}->configure(-tests => $tmp_tests))) {
my $msg = "Could not update GUI correctly with new tests.";
$logger->error($msg);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment