- or download this
# Get rid of all line endings, regardless of which flavor they are
(my $line = shift) =~ s/[\r\n]//g;
- or download this
# does this look like a S1, S2, or S3 record? These are the only o
+nes that
# carry an actual data payload. Other record types do not, so just
+ ignore
...
# Make sure the COUNT field makes sense. It should represent the s
+um of
# address, data, and checksum fields, in bytes
return unless hex($count) == (length($address) + length($data) + l
+ength($cs)) / 2;
- or download this
my $compCs = hex($count);
foreach my $nibble ($address =~ m/../g, $data =~ m/../g) {
$compCs += hex($nibble);
}
- or download this
my $compCs = hex($count);
$compCs += hex($_) foreach($address =~ m/../g, $data =~ m/../g);
- or download this
my $compCs = reduce { $a + $b }
map { hex $_ }
($count, $address =~ m/../g, $data =~ m/../g);
- or download this
my $status = $compCs == hex($cs);
- or download this
use List::Util;
...
return ($status, $address, $data);
}
- or download this
# ...
# if the checksum actually matches, then call it a good S-record
return ($compCs == hex($cs), $address, $data);