my $debug = $ENV{DEBUG};
+$| = 1;
+
warn "## protocol = ",dump( $protocol ) if $debug;
my $pkg_nr = 0;
my $data_id = unpack( 'C', substr($data,0,1) );
if ( ! exists( $protocol->{$data_id}->{description} ) ) {
my $len = unpack('C', substr($data,1,1));
- printf "ERROR: no description for data_id %d 0x%2x len %d SKIPPING!\n", $data_id, $data_id, $len;
+ printf "ERROR: no description for data_id %d 0x%2x len %d [%s] SKIPPING!\n", $data_id, $data_id, $len, unpack('H*', substr($data,2,$len));
$data = substr($data,2 + $len);
next;
}
my $pack_fmt = $protocol->{$data_id}->{pack_fmt} || die "can't find pack_fmt for data_id $data_id";
my $data_range;
+ my $data_len;
if ( $data_id == 0x00 ) {
# sequence number
} elsif ( $up_down eq 'up' && ( $function_code == 0x07 || $function_code == 0x08 || $function_code == 0x03 ) ) {
# type B
- my $data_len = unpack('C', substr($data,1,1));
+ $data_len = unpack('C', substr($data,1,1));
$data_range = substr($data,2, $data_len);
$data = substr($data,2 + $data_len);
} elsif ( $up_down eq 'down' && $function_code == 0x06 ) {
# type B
- my $data_len = unpack('C', substr($data,1,1));
+ $data_len = unpack('C', substr($data,1,1));
$data_range = substr($data,2, $data_len);
$data = substr($data,2 + $data_len);
warn "ERROR unknown function_code = $function_code";
}
- my $v = unpack($pack_fmt, $data_range);
+ my @v = unpack($pack_fmt, $data_range);
+
+ my $v = join(' ', @v);
if ( $data_id == 0x0c ) {
$v = $v / 100;
}
my $description = $protocol->{$data_id}->{description} || die "can't find description for data_id $data_id";
- print "$up_down | $data_id | $description | v=$v | hex:", unpack('H*', $data_range), " fmt:$pack_fmt | range:",$protocol->{$data_id}->{range}, " | remark:", $protocol->{$data_id}->{remark},"\n";
+ print "$up_down | $data_id 0x",unpack('H*', chr($data_id))," $data_len | $description | v=$v | hex:", unpack('H*', $data_range), " fmt:$pack_fmt | range:",$protocol->{$data_id}->{range}, " | remark:", $protocol->{$data_id}->{remark},"\n";
}
( $timestamp, $sensor, $imei, $up_down ) = ( $1, $2, $3, $4 );
$stat->{$sensor}->{$imei}->{$up_down}++;
} elsif ( m{^\s+} ) {
- s/\s\s\S\S\S+//g; # remove ascii
s/^\s+/ /;
+ s/\s\s.+$//g; # remove ascii
$raw .= $_;
warn "++ $_\n";
} else {