$crc = $crc ^ $byte;
# warn "## ", as_hex(chr($byte)), " crc = ", $crc, " ", as_hex(chr($crc));
}
- if ( chr($crc) ne substr($data,-1,1) ) {
+ # ignore checksum errors for FF, we will calulate them!
+ if ( chr($crc) ne substr($data,-1,1) && substr($data,-1,1) ne "\xFF" ) {
warn "CRC error for ",as_hex($data), " calulated ", as_hex(chr($crc));
}
+
+ return substr($data,0,-1) . chr($crc);
}
-sub v {
- my ($hex,$desc) = @_;
- my $bytes = hex2bytes( $hex );
+sub v_bytes {
+ my ($bytes,$desc) = @_;
warn "# $desc\n";
retry:
warn ">> ",as_hex( $bytes );
crc($data);
warn "<< ",as_hex($data);
+ return $data;
+}
+
+sub v {
+ my ($hex,$desc) = @_;
+ v_bytes( hex2bytes( $hex ), $desc );
}
-v '07 02 00 00 00 04 C4', "hardware version";
+if ( ! @ARGV ) {
+ v '07 02 00 00 00 04 C4', "hardware version";
-v '07 0A 00 00 00 04 44', 'software version';
+ v '07 0A 00 00 00 04 44', 'software version';
-v '07 00 01 00 06 0E EA', 'temperatures';
+ v '07 00 01 00 06 0E EA', 'temperatures';
-v '07 00 00 00 26 0A A6', 'last errros';
+ v '07 00 00 00 26 0A A6', 'last errros';
+}
-v '07 00 00 00 26 00 AC', 'last errros (with invalid length)';
+#v '07 00 00 00 26 00 AC', 'last errros (with invalid length)';
+
+foreach my $reg ( @ARGV ) {
+ warn "# send user $reg\n";
+ v_bytes(
+ crc( hex2bytes( "07 00 00 00 $reg 01 FF" ) )
+ ,"user: $reg");
+}