parse_usb.pl: fix handling of ./parse_tcpdump_log.pl logs
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Fri, 25 Jul 2014 14:17:13 +0000 (11:17 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Fri, 25 Jul 2014 14:17:13 +0000 (11:17 -0300)
The regex were not parsing right those logs. Fix it, and add
the timestamps to the dumps.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
contrib/usb_parse/parse_usb.pl

index 5af6408..3d88943 100755 (executable)
@@ -61,16 +61,19 @@ sub type_req($)
 }
 
 while (<>) {
-       tr/A-F/a-f/;
-       if (m/([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].)[\<\>\s]+(.*)/) {
-               my $reqtype = hex($1);
-               my $req = hex($2);
-               my $wvalue = hex("$4$3");
-               my $windex = hex("$6$5");
-               my $wlen = hex("$8$7");
-               my $payload = $9;
+       if (m/(.*)([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].)[\<\>\s]+(.*)/) {
+               my $timestamp = $1;
+               my $reqtype = hex($2);
+               my $req = hex($3);
+               my $wvalue = hex("$5$4");
+               my $windex = hex("$7$6");
+               my $wlen = hex("$9$8");
+               my $payload = $10;
 
-               printf("%s, Req %3d, wValue: 0x%04x, wIndex 0x%04x, wlen %d: %s\n",
-                       type_req($reqtype), $req, $wvalue, $windex, $wlen, $payload);
+               $timestamp =~ s/^\s+//;
+               $timestamp =~ s/\s+$//;
+
+               printf("%s %s(0x%02x), Req 0x%02x, wValue: 0x%04x, wIndex 0x%04x, wlen %d: %s\n",
+                       $timestamp, type_req($reqtype), $reqtype, $req, $wvalue, $windex, $wlen, $payload);
        }
 }