Merge branch 'master' of mjesec.ffzg.hr:/git/zc
[zc] / log-parse
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6
7 use lib '.';
8 use Protocol;
9
10 my $debug = $ENV{DEBUG};
11
12 $| = 1;
13
14 warn "## protocol = ",dump( $protocol ) if $debug;
15
16 sub print_hex {
17         my ( $up_down, $hex ) = @_;
18
19         warn "hex = $hex\n";
20
21         my $raw = join('', map { chr(hex($_)) } split(/\s+/,$hex));
22
23         warn "raw = ", hex_dump($raw);
24
25         my $hash = protocol_decode( $up_down, $raw );
26
27         warn "hash = ",dump($hash);
28
29         my $function_code = $hash->{function_code} || die "no function_code";
30         my $fc_desc = $function_code_description->{$up_down}->{$function_code} || die "no function_code_description for $up_down $function_code";
31         print " function_code=$function_code ",
32                 $fc_desc,
33                 " ver=", $hash->{ver},
34                 " len=", $hash->{len},
35                 "\n";
36
37         foreach my $data_id ( @{ $hash->{data_id_order} } ) {
38                 print join(" | ", 
39                         $hash->{up_down},
40                         unpack('H*', chr($data_id)),
41                         $protocol->{$data_id}->{description},
42                         $hash->{data_id}->{$data_id},
43                         "hex:" . unpack('H*', $hash->{data_range}->{$data_id}),
44                         "len:" . $hash->{data_len}->{$data_id},
45                         "fmt:" . $protocol->{$data_id}->{pack_fmt},
46                         "range:" . $protocol->{$data_id}->{range}, 
47                         "remark:" . $protocol->{$data_id}->{remark}
48                 ),"\n";
49         }
50         print "\n";
51 }
52
53 my $raw;
54 my ( $timestamp, $sensor, $imei, $up_down );
55 my $stat;
56 while(<>) {
57         chomp;
58
59         if ( m{^(\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d).*Inclinometer/([^/]+)/([^/]+)/(\w+)} ) {
60                 if ( $raw ) {
61                         $raw =~ s{^\s+}{}; # strip leading spaces
62                         print "## $timestamp $sensor $imei $up_down $raw\n";
63                         print_hex( $up_down, $raw );
64                         $raw = '';
65                 }
66                 ( $timestamp, $sensor, $imei, $up_down ) = ( $1, $2, $3, $4 );
67                 $stat->{$sensor}->{$imei}->{$up_down}++;
68         } elsif ( m{^\s+} ) {
69                 s/^\s+/ /;
70                 s/\s\s.+$//g; # remove ascii
71                 $raw .= $_;
72                 warn "++ $_\n";
73         } else {
74                 warn "IGNORE: $_\n";
75         }
76
77 }
78
79 if ( $raw ) {
80         $raw =~ s{^\s+}{}; # strip leading spaces
81         print "## $timestamp $sensor $imei $up_down $raw\n";
82         print_hex( $up_down, $raw );
83 }
84
85 print "stat = ",dump($stat), "\n";
86