show empty svg if there is no data
[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 use POSIX qw(strftime);
8
9 use FindBin;
10 use lib "$FindBin::Bin/.";
11 use Protocol;
12
13 my $debug = $ENV{DEBUG} // 0;
14 $| = 1;
15
16 if ( $debug > 1 ) {
17         warn "## protocol = ",dump( $protocol );
18         warn "## function_code_description = ",dump( $function_code_description );
19 }
20
21 my $raw;
22
23 foreach my $filename ( @ARGV ) {
24         my ( $up_down, $t );
25         if ( $filename =~ m/(\d+)\.(up|down|sent)/ ) {
26                 $t = $1;
27                 $up_down = $2;
28         } else {
29                 warn "ERROR: can't parse $filename, skipping\n";
30                 next;
31         }
32         my $raw = read_file $filename;
33         print "# ",strftime("%Y-%m-%dT%H:%M:%S",localtime($t)), " $filename size:", -s $filename, " ";
34         $up_down = 'down' if $up_down eq 'sent';
35         my $hash = protocol_decode( $up_down, $raw );
36
37         warn "hash = ",dump($hash) if $debug;
38
39         my $imei = $1 if $filename =~ m{queue/(\d+)};
40
41         my $function_code = $hash->{function_code} || die "no function_code";
42         my $fc_desc = $function_code_description->{$up_down}->{$function_code} || die "no function_code_description for $up_down $function_code";
43         print " function_code=$function_code ",
44                 $fc_desc,
45                 " ver=", $hash->{ver},
46                 " len=", $hash->{len},
47                 "\n";
48
49         foreach my $data_id ( @{ $hash->{data_id_order} } ) {
50                 print join(" | ", 
51                         $imei,
52                         $hash->{up_down},
53                         unpack('H*', chr($data_id)),
54                         $protocol->{$data_id}->{description},
55                         $hash->{data_id}->{$data_id},
56                         "hex:" . unpack('H*', $hash->{data_range}->{$data_id}),
57                         "len:" . $hash->{data_len}->{$data_id},
58                         "fmt:" . $protocol->{$data_id}->{pack_fmt},
59                         "range:" . $protocol->{$data_id}->{range}, 
60                         "remark:" . $protocol->{$data_id}->{remark}
61                 ),"\n";
62         }
63         print "\n";
64
65 }
66