From 6ec9cc35f3402bbd747d1d8eaead82dfa4b9f8bb Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Fri, 9 Aug 2013 12:59:09 +0200 Subject: [PATCH] added movie option to unpacker --- tools/preview/unpack_hld.pl | 70 +++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/tools/preview/unpack_hld.pl b/tools/preview/unpack_hld.pl index 0a9bf1c..7f8fd47 100755 --- a/tools/preview/unpack_hld.pl +++ b/tools/preview/unpack_hld.pl @@ -11,7 +11,7 @@ my $SensorHeaderLength = 7; my $Statistics; my $PMap; - +my $hitcount; ############################################################################### ## Configuration ############################################################## @@ -25,6 +25,7 @@ my $opt_debug = 0; my $opt_frameinfo = 0; my $opt_picpath = "./"; my $totalevents = 1E9; +my $opt_movie = 0; my $mode = ""; GetOptions ('h|help' => \$opt_help, @@ -32,7 +33,8 @@ GetOptions ('h|help' => \$opt_help, 'v|verb' => \$opt_verb, 'i|info' => \$opt_frameinfo, 'd|debug' => \$opt_debug, - 'p|picpath=s' => \$opt_picpath, + 'p|picpath=s' => \$opt_picpath, + 'm|movie=i' => \$opt_movie, 'e|events=i' => \$totalevents); @@ -45,6 +47,7 @@ if($opt_help) { printf("[-v|--verb] Dump hld file content\n"); printf("[-i|--info] Show frame information\n"); printf("[-d|--debug] More debugging output\n"); + printf("[-m|--movie] Make a slideshow of frames\n"); printf("[-p|--picpath] Set where to write plots\n"); printf("\n"); exit; @@ -114,9 +117,16 @@ while(1){ #----------> User function <--------- &analyzeData($evtHeader_aref, $subEvtHeader_aref, $data_aref); } + if($opt_movie) { + WriteResults($evtHeader_aref->[3]); + $PMap = {}; + $Statistics = {}; + $hitcount = {}; + last if $opt_movie < $evtHeader_aref->[3]; + } } -WriteResults(); +WriteResults() unless $opt_movie; $fh->close(); @@ -445,12 +455,13 @@ sub analyzeData() { $ovf += ($d >> 15) & 1; $line = ($d >> 4) & 0x7FF; $statecnt = $d & 0xF; + $hitcount->{$SensorId}++; } else { $pixels = ($d & 0x3); $column = ($d >> 2) & 0x7FF; printf("\t$line, $column x %d\n",$pixels+1) if $opt_frameinfo; - + $hitcount->{$SensorId}++; $matrix->[$line]->[$column]++; if ($pixels > 0) { $matrix->[$line]->[$column+1]++; @@ -480,28 +491,42 @@ sub analyzeData() { } } +my $fg = undef; sub WriteResults { - + my ($num ) = @_; + $num = "_".$num if defined $num; + $num = "" unless defined $num; foreach my $id (keys $Statistics) { #No frames? No plot! if(!defined $Statistics->{$id}->{Valid}) {next;} - my $fn = "gnuplot"; - $fh = new FileHandle ("|$fn") or die "error: no gnuplot"; - $fh->autoflush(1); - - print $fh "set terminal png size 800,400 font \",9\";\n"; - print $fh strftime("set label 100 \"%H:%M:%S\" at screen 0.98,0.02 right tc rgb \"#000044\" font \"monospace,8\"\n", localtime()); - print $fh "set palette model RGB;\n"; - print $fh "set xrange [0:1152];\n"; - print $fh "set yrange [0:576];\n"; - print $fh "set cbrange [0:5000];\n"; - print $fh "set palette defined ( 0 'white', 1 'red', 5 'black', 10 'blue', 5000 'green');\n"; - my $s = sprintf("%04x",$id); - print $fh "set output '$opt_picpath/image_recalibrated_$s.png';\n"; - print $fh "plot '-' matrix with image\n"; + if(!defined $fg) { + $fg = new FileHandle ("|gnuplot") or die "error: no gnuplot"; + $fg->autoflush(1); + print $fg "set terminal png size 800,400 font \",9\";\n"; + print $fg "set palette model RGB;\n"; + print $fg "set xrange [0:1152];\n"; + print $fg "set yrange [0:576];\n"; + print $fg "set cbrange [0:5000];\n"; + print $fg "set palette defined ( 0 'white', 1 'red', 5 'black', 10 'blue', 5000 'green');\n"; + my $s = sprintf("%04x",$id); + + print $fg strftime("set label 100 \"%H:%M:%S\" at screen 0.98,0.02 right tc rgb \"#000044\" font \"monospace,8\"\n", localtime()); + print $fg "set label 101 \"".$hitcount->{$id}." States\" at screen 0.02,0.02 left tc rgb \"#000044\" font \"monospace,8\"\n" ; + print $fg "set output '$opt_picpath/image_recalibrated_$s$num.png';\n"; + print $fg "plot '-' matrix with image\n"; + } + else { + my $s = sprintf("%04x",$id); + print $fg strftime("set label 100 \"%H:%M:%S\" at screen 0.98,0.02 right tc rgb \"#000044\" font \"monospace,8\"\n", localtime()); + print $fg "set label 101 \"".$hitcount->{$id}." States\" at screen 0.02,0.02 left tc rgb \"#000044\" font \"monospace,8\"\n" ; + print $fg "set output '$opt_picpath/image_recalibrated_$s$num.png';\n"; + print $fg "replot\n"; + + } + my @matrix; @@ -513,11 +538,12 @@ sub WriteResults { @matrix = map {$_ || 0 } @{$map}; #Join lines my $l = join(" ",@matrix); - print $fh $l."\n"; + print $fg $l."\n"; } - print $fh "e\nexit\n"; - $fh->close(); + print $fg "e\n\n"; + $fg->close(); + $fg = undef; } -- 2.43.0