#!/usr/bin/perl
# Michel Xhaard (c)2003 Use at your own risque !!
$timenow = 0;
$timebefore = 0;
$timeback = 0;
$reqflag =0;
$bufflagback = 0;
$bufflagdown = 0;
$datacount = 0;
$lastindex = 0;
$state = -1;
#open (outfile,'>perlval.txt');
while (<>)
{
	
    # remove tabs
    s/\t/ /g;
    # remove special car 
    s/[<>\[\]\-\.=\r\*]*//g;
   
    
    # strip leading spaces
    s/^\s*//;
	
    	# strip blanks lines
	s/^\n//g;
	#print $_;
	
	$TheLine = $_;
	chomp ($TheLine);
	
	@ListWord = split(/ /, $TheLine);
	if ($ListWord[8] eq "down") {
	$state = 1;
	$timenow = $ListWord[0];
	print "**************************************\n"; #t
	print '{times :  '.$ListWord[0].', URB ->  '.$ListWord[8].', N°) '.$ListWord[6]."}\n";#t
	#print 'deltatimes down-down = '.($timenow - $timebefore)."\n"; #t
	#print 'wait down-back       = '.($timenow - $timeback)."\n"; #t
	$timebefore = $timenow;
	}
	
	if ($ListWord[8] eq "back") {
	$state = 0;
	#print '{times :  '.$ListWord[0].', URB <-  '.$ListWord[8].', N°) '.$ListWord[6]."}\n";#t
	$timeback = $ListWord[0];
	}
	
	if (($bufflagdown == 1) && ($datacount != 0) && ($state == 1)) {
	print "data send    : ";
	if ($datacount > 16) {
	 $datacount = 16 ;}
	for ($index =1 ; $index <= $datacount ; $index += 1) {
	 print "$ListWord[$index] ";
	}
	print "\n";
	$datacount = 0 ;
	$bufflagdown = 0 ;
	}
	
	if (($bufflagback == 1) && ($datacount != 0) && ($state == 0)) {
	print "data received: ";
	if ($datacount > 16) {
	 $datacount = 16 ;}
	for ($index =1 ; $index <= $datacount ; $index += 1) {
	 print "$ListWord[$index] ";
	}
	print "\n";
	$datacount = 0 ;
	$bufflagback = 0 ;
	}

	if ($reqflag == 1) {
	$direction = $ListWord[1];
	$request = $ListWord[2];
	$index = $ListWord[6].$ListWord[5];
	$value = $ListWord[4].$ListWord[3]; #t
	$value = $ListWord[3];
	$lenght = $ListWord[8].$ListWord[7];
	if ( $lastindex eq $index) {#t
	print outfile "\n";#t
	} else {#t
	print outfile "dir: $direction req: $request val: $value index: $index lenght: $lenght\n";#t
	}#t
	$lastindex = $index;
	print 'Command :'.$ListWord[1].' '.$ListWord[2].' '.$ListWord[3].' '.$ListWord[4].' '.$ListWord[5].' '.$ListWord[6].' '.$ListWord[7].' '.$ListWord[8]."\n";
	print "**************************************\n";
	$reqflag = 0;
	}
	
	if ($ListWord[0] eq "TransferBufferLength") {
	$datacount = $ListWord[2];
	}
	
	if (($ListWord[0] eq "TransferBufferMDL") && ($state == 0) && ($datacount != 0)){
	$bufflagback = 1;
	}
	
	if (($ListWord[0] eq "TransferBufferMDL") && ($state == 1) && ($datacount != 0)){
	$bufflagdown = 1;
	}
	if ($ListWord[0] eq "SetupPacket") {
	$reqflag = 1 ;
	}
}
#close(outfile);
