rename to log-parse
[zc] / zc-queue-inspect
diff --git a/zc-queue-inspect b/zc-queue-inspect
new file mode 100755 (executable)
index 0000000..2f75590
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use Data::Dump qw(dump);
+use File::Slurp;
+
+use lib '.';
+use Protocol;
+
+my $debug = $ENV{DEBUG};
+$| = 1;
+
+if ( $debug ) {
+       warn "## protocol = ",dump( $protocol );
+       warn "## function_code_description = ",dump( $function_code_description );
+}
+
+my $raw;
+
+foreach my $filename ( @ARGV ) {
+       my $up_down = $1 if $filename =~ m/(up|down)/;
+       my $raw = read_file $filename;
+       print "# $filename size:", -s $filename, " ";
+       my $hash = protocol_decode( $up_down, $raw );
+
+       warn "hash = ",dump($hash);
+
+       my $function_code = $hash->{function_code} || die "no function_code";
+       my $fc_desc = $function_code_description->{$up_down}->{$function_code} || die "no function_code_description for $up_down $function_code";
+       print " function_code=$function_code ",
+               $fc_desc,
+               " ver=", $hash->{ver},
+               " len=", $hash->{len},
+               "\n";
+
+       foreach my $data_id ( @{ $hash->{data_id_order} } ) {
+               print join(" | ", 
+                       $hash->{up_down},
+                       unpack('H*', chr($data_id)),
+                       $protocol->{$data_id}->{description},
+                       $hash->{data_id}->{$data_id},
+                       "hex:" . unpack('H*', $hash->{data_range}->{$data_id}),
+                       "len:" . $hash->{data_len}->{$data_id},
+                       "fmt:" . $protocol->{$data_id}->{pack_fmt},
+                       "range:" . $protocol->{$data_id}->{range}, 
+                       "remark:" . $protocol->{$data_id}->{remark}
+               ),"\n";
+       }
+       print "\n";
+
+}
+