#!/usr/bin/perl -w
use strict;

sub parse_hexdigits() {
    my $str = "";
    while(<>) {
#	print "parse read: $_";
	last
	    unless (/[0-9]: /);
	my ($addr, $hexstr) = split(/:/);
	my @hexdigits = split(/[ \n]+/, $hexstr);
	foreach my $digit (@hexdigits) {
	    last
		if ($digit eq "0d");
	    if ($digit ne "") {
		$str .= chr(hex($digit));
	    }
	}
    }
    return $str;
}

    
my $direction = "?";
while(<>) {
#    print "read      : $_";
    /USBD_TRANSFER_DIRECTION_IN/ and $direction = "<";
    /USBD_TRANSFER_DIRECTION_OUT/ and $direction = ">";
    if (/TransferBufferMDL/) {
	my $str = parse_hexdigits();
	if ($str ne "") {
	    print "transfer $direction \"$str\"\n";
	}
    }
#    if (/SetupPacket/) {
#	my $str = parse_hexdigits();
#	print "setup    $direction \"$str\"\n";
#    }
}
	
