#!/usr/bin/perl use warnings; use strict; use Data::Dump qw(dump); use File::Slurp; use POSIX qw(strftime); use FindBin; use lib "$FindBin::Bin/."; use Protocol; my $debug = $ENV{DEBUG} // 0; $| = 1; if ( $debug > 1 ) { warn "## protocol = ",dump( $protocol ); warn "## function_code_description = ",dump( $function_code_description ); } my $raw; foreach my $filename ( @ARGV ) { my ( $up_down, $t ); if ( $filename =~ m/(\d+)\.(up|down|sent)/ ) { $t = $1; $up_down = $2; } else { warn "ERROR: can't parse $filename, skipping\n"; next; } my $raw = read_file $filename; print "# ",strftime("%Y-%m-%dT%H:%M:%S",localtime($t)), " $filename size:", -s $filename, " "; $up_down = 'down' if $up_down eq 'sent'; my $hash = protocol_decode( $up_down, $raw ); warn "hash = ",dump($hash) if $debug; my $imei = $1 if $filename =~ m{queue/(\d+)}; 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(" | ", $imei, $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"; }