-warn "up/down: $up_down hex = ",dump($hex);
-
-my $bin = join('', map { chr(hex($_)) } split(/\s+/,$hex));
-
-warn "bin = ", dump($bin);
-
-if ( $debug ) {
- open(my $dump, '>', "/dev/shm/zc.$pkg_nr.$up_down");
- print $dump $bin;
- close($dump);
- $pkg_nr++;
-}
-
-my $cksum = substr($bin, -2, 2);
-
-if ( my $crc = modbus_crc16( substr($bin,0,-2) ) ) {
- if ( $crc ne $cksum ) {
- warn "CRC error, got ",unpack('H*',$crc), " expected ", unpack('H*',$cksum), "\n";
- } else {
- warn "CRC OK ", unpack('H*',$crc), "\n";
- }
-}
-
-my ( $header, $ver, $function_code, $len ) = unpack("CCCv", $bin);
-
-my $data = substr($bin,5,-2);
-
-warn "header = $header ver = $ver function_code = $function_code len = $len == ",length($data), " data = ",dump($data), " cksum = ", unpack('H*',$cksum);
-
-warn "header corrupt: $header" if $header != 0x5a;
-warn "invalid length $len got ",length($data) if length($data) != $len;
-
-my $function_code_upstream = {
-0x07 => 'Upstream Heartbeat Frame',
-0x08 => 'Upstream alarm frame',
-0x03 => 'Upstream Read Parameter Frame',
-0x06 => 'Upstream return write parameter frame',
-};
-
-my $function_code_downstream = {
-0x03 => 'Downstream read parameter frame',
-0x06 => 'Downstream write parameter frame',
-};
-
-print "Function code: $function_code ",
- $up_down eq 'up' ? $function_code_upstream->{ $function_code } : $function_code_downstream->{ $function_code }, "\n";
-
-
-