#!/usr/bin/perl use warnings; use strict; use Data::Dump qw(dump); use lib '.'; use Protocol; my $debug = $ENV{DEBUG}; $| = 1; warn "## protocol = ",dump( $protocol ) if $debug; sub print_hex { my ( $up_down, $hex ) = @_; warn "hex = $hex\n"; my $raw = join('', map { chr(hex($_)) } split(/\s+/,$hex)); warn "raw = ", hex_dump($raw); 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"; } my $raw; my ( $timestamp, $sensor, $imei, $up_down ); my $stat; while(<>) { chomp; if ( m{^(\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d).*Inclinometer/([^/]+)/([^/]+)/(\w+)} ) { if ( $raw ) { $raw =~ s{^\s+}{}; # strip leading spaces print "## $timestamp $sensor $imei $up_down $raw\n"; print_hex( $up_down, $raw ); $raw = ''; } ( $timestamp, $sensor, $imei, $up_down ) = ( $1, $2, $3, $4 ); $stat->{$sensor}->{$imei}->{$up_down}++; } elsif ( m{^\s+} ) { s/^\s+/ /; s/\s\s.+$//g; # remove ascii $raw .= $_; warn "++ $_\n"; } else { warn "IGNORE: $_\n"; } } if ( $raw ) { $raw =~ s{^\s+}{}; # strip leading spaces print "## $timestamp $sensor $imei $up_down $raw\n"; print_hex( $up_down, $raw ); } print "stat = ",dump($stat), "\n";