support sent files, less verbose debug output
[zc] / zc-queue-inspect
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6 use File::Slurp;
7
8 use lib '.';
9 use Protocol;
10
11 my $debug = $ENV{DEBUG};
12 $| = 1;
13
14 if ( $debug > 1 ) {
15         warn "## protocol = ",dump( $protocol );
16         warn "## function_code_description = ",dump( $function_code_description );
17 }
18
19 my $raw;
20
21 foreach my $filename ( @ARGV ) {
22         my $up_down = $1 if $filename =~ m/(up|down|sent)/;
23         my $raw = read_file $filename;
24         print "# $filename size:", -s $filename, " ";
25         $up_down = 'down' if $up_down eq 'sent';
26         my $hash = protocol_decode( $up_down, $raw );
27
28         warn "hash = ",dump($hash) if $debug;
29
30         my $function_code = $hash->{function_code} || die "no function_code";
31         my $fc_desc = $function_code_description->{$up_down}->{$function_code} || die "no function_code_description for $up_down $function_code";
32         print " function_code=$function_code ",
33                 $fc_desc,
34                 " ver=", $hash->{ver},
35                 " len=", $hash->{len},
36                 "\n";
37
38         foreach my $data_id ( @{ $hash->{data_id_order} } ) {
39                 print join(" | ", 
40                         $hash->{up_down},
41                         unpack('H*', chr($data_id)),
42                         $protocol->{$data_id}->{description},
43                         $hash->{data_id}->{$data_id},
44                         "hex:" . unpack('H*', $hash->{data_range}->{$data_id}),
45                         "len:" . $hash->{data_len}->{$data_id},
46                         "fmt:" . $protocol->{$data_id}->{pack_fmt},
47                         "range:" . $protocol->{$data_id}->{range}, 
48                         "remark:" . $protocol->{$data_id}->{remark}
49                 ),"\n";
50         }
51         print "\n";
52
53 }
54