return $bytes;
}
+sub crc {
+ my $data = shift;
+ my $crc = 0;
+ for my $i ( 0 .. length($data) - 2 ) {
+ if ( $crc & 0x80 ) {
+ $crc = ( $crc << 1 ) ^ 25;
+ } else {
+ $crc = $crc << 1;
+ }
+ $crc = $crc & 0xff;
+ my $byte = ord(substr($data,$i,1));
+ $crc = $crc ^ $byte;
+# warn "## ", as_hex(chr($byte)), " crc = ", $crc, " ", as_hex(chr($crc));
+ }
+ if ( chr($crc) ne substr($data,-1,1) ) {
+ warn "CRC error for ",as_hex($data), " calulated ", as_hex(chr($crc));
+ }
+}
+
sub v {
my ($hex,$desc) = @_;
my $bytes = hex2bytes( $hex );
warn "# $desc\n";
retry:
warn ">> ",as_hex( $bytes );
+ crc( $bytes );
$port->write( $bytes );
my $data = $port->read(1);
goto retry if ord($data) == 0;
$data .= $port->read(ord($data) - 1);
+ crc($data);
warn "<< ",as_hex($data);
}