blib/lib/Hex/Record.pm

filter: Statementstmt 100% 212 / 212 Branchbran 100% 82 / 82 Conditioncond 100% 19 / 19 MC/DCmcdc 100% 11 / 11 Subroutinesub 100% 16 / 16 Podpod 87.5% 7 / 8 totaltotal 99.7% 347 / 348 CC 53 SCAR 18.6
CC
53
Cov
100%
write
10.0
_traverse
10.0
import_srec_hex
8.0
CRAP 6.4
↑ Summary
1 package Hex::Record;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION = '0.09';
8  
9 18 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
10 18 my ($class, %args) = @_;
11  
12 18 ▶ $args{parts} = [] unless exists $args{parts};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"parts"} 13 5 18
13  
14 18 return bless \%args, $class;
15 }
16  
17 6 ▶sub import_intel_hex {
Subroutine import_intel_hex: called CC=6 SCAR=17.9
Pod documented
18 6 my ($self, $hex_string) = @_;
19  
20 6 my $addr_high_dec = 0;
21 6 my $create_part = 0;
22 6 for my $line (split m{\n\r?}, $hex_string) {
23 34 ▶ my ($addr, $type, $bytes_str) = $line =~ m{
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ / : # intel hex start [[:xdigit:]]{2} # bytecount ([[:xdigit:]]{4}) # addr ([[:xdigit:]]{2}) # type ([[:xdigit:]] * ) # databytes [[:xdigit:]]{2} # checksum /xi or next 33 1 34
24 : # intel hex start
25 [[:xdigit:]]{2} # bytecount
26 ([[:xdigit:]]{4}) # addr
27 ([[:xdigit:]]{2}) # type
28 ([[:xdigit:]] * ) # databytes
29 [[:xdigit:]]{2} # checksum
30 }ix or next;
31  
32 33 my @bytes = unpack('(A2)*', $bytes_str);
33  
34 # data line?
35 33 ▶ if ($type == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 0) { } 24 9 33
elsif ($type == 4) { } 3 6 9
elsif ($type == 2) { } 3 3 6
36 24 $self->write($addr_high_dec + hex $addr, \@bytes, $create_part);
37 24 $create_part = 0;
38 }
39 # extended linear address type?
40 elsif ($type == 4) {
41 3 $addr_high_dec = hex( join '', @bytes ) << 16;
42 3 $create_part = 1;
43 }
44 # extended segment address type?
45 elsif ($type == 2) {
46 3 $addr_high_dec = hex( join '', @bytes ) << 4;
47 3 $create_part = 1;
48 }
49 }
50  
51 6 return;
52 }
53  
54 6 ▶sub import_srec_hex {
Subroutine import_srec_hex: called CC=8 SCAR=20.8
Pod documented
55 6 my ($self, $hex_string) = @_;
56  
57 6 my %address_length_of_srec_type = (
58 0 => 4,
59 1 => 4,
60 2 => 6,
61 3 => 8,
62 4 => undef,
63 5 => 4,
64 6 => 6,
65 7 => 8,
66 8 => 6,
67 9 => 4,
68 );
69  
70 6 my @parts;
71 6 for my $line (split m{\n\r?}, $hex_string) {
72 22 ▶ next unless substr( $line, 0, 1 ) =~ m{s}i;
Branch: 1 branch
BranchTrueFalseTotal
unless substr($line, 0, 1) =~ /s/i 1 21 22
73  
74 21 my $type = substr $line, 1, 1;
75  
76 21 ▶ my $addr_length = $address_length_of_srec_type{$type} || next;
Condition100%2/2
$address_length_of_srec_type{$type} || (next)
l!l
201
MC/DC100%1/1
$address_length_of_srec_type{$type} || (next)
$address_length_of_srec_type{$type}
Truth table100%2/2
A
A= $address_length_of_srec_type{$type}
Aresult
11
00
77  
78 20 ▶ my ($addr, $bytes_str) = $line =~ m{
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ / s #srec hex start [[:xdigit:]]{1} #type [[:xdigit:]]{2} #bytecount ([[:xdigit:]]{$addr_length}) #addr ([[:xdigit:]] * ) #databytes [[:xdigit:]]{2} #checksum /xi or next 19 1 20
79 s #srec hex start
80 [[:xdigit:]]{1} #type
81 [[:xdigit:]]{2} #bytecount
82 ([[:xdigit:]]{$addr_length}) #addr
83 ([[:xdigit:]] * ) #databytes
84 [[:xdigit:]]{2} #checksum
85 }ix or next;
86  
87 # data line?
88 19 ▶ if ($type == 1 || $type == 2 || $type == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 1 or $type == 2 or $type == 3) 18 1 19
Condition100%6/6
$type == 1 or $type == 2 or $type == 3
l!l&&r!l&&!r
1531
$type == 1 or $type == 2
l!l&&r!l&&!r
1234
MC/DC100%3/3
$type == 1 or $type == 2 or $type == 3
$type == 1 $type == 2 $type == 3
Truth table100%4/4
A or B or C
A= $type == 1B= $type == 2C= $type == 3
ABCresult
1XX1
01X1
0011
0000
89 18 $self->write(hex $addr, [ unpack '(A2)*', $bytes_str ]);
90 }
91 }
92  
93 6 return;
94 }
95  
96 55 ▶sub write {
Subroutine write: called CC=10 SCAR=23.0
Pod documented
97 55 my ($self, $from, $bytes_hex_ref, $create_part) = @_;
98 55 ▶ $create_part ||= 0;
Condition100%2/2
$create_part ||= 0
l!l
649
MC/DC100%1/1
$create_part ||= 0
$create_part
Truth table100%2/2
A
A= $create_part
Aresult
11
00
99  
100 55 $self->remove($from, scalar @$bytes_hex_ref);
101  
102 55 my $to = $from + @$bytes_hex_ref;
103  
104 55 ▶ for (my $part_i = 0; $part_i < @{ $self->{parts} }; $part_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part_i < @{$self->{"parts"};}) 80 27 107
105 80 my $part = $self->{parts}->[$part_i];
106  
107 80 my $start_addr = $part->{start};
108 80 my $end_addr = $part->{start} + $#{ $part->{bytes} };
109  
110 # merge with this part
111 80 ▶ if ($create_part == 0 && $to == $start_addr) {
Branch: 3 branches
BranchTrueFalseTotal
if ($create_part == 0 and $to == $start_addr) { } 4 76 80
elsif ($create_part == 0 and $from == $end_addr + 1) { } 20 56 76
elsif ($from < $start_addr) { } 4 52 56
Condition100%3/3
$create_part == 0 and $to == $start_addr
!ll&&!rl&&r
6704
MC/DC100%2/2
$create_part == 0 and $to == $start_addr
$create_part == 0 $to == $start_addr
Truth table100%3/3
A and B
A= $create_part == 0B= $to == $start_addr
ABresult
0X0
100
111
112 4 $part->{start} = $from;
113 4 unshift @{ $part->{bytes} }, @$bytes_hex_ref;
114 4 return;
115 }
116 ▶ elsif ($create_part == 0 && $from == $end_addr + 1) {
Condition100%3/3
$create_part == 0 and $from == $end_addr + 1
!ll&&!rl&&r
65020
MC/DC100%2/2
$create_part == 0 and $from == $end_addr + 1
$create_part == 0 $from == $end_addr + 1
Truth table100%3/3
A and B
A= $create_part == 0B= $from == $end_addr + 1
ABresult
0X0
100
111
117 20 push @{ $part->{bytes} }, @$bytes_hex_ref;
118  
119 20 ▶ return if $part_i+1 == @{ $self->{parts} };
Branch: 1 branch
BranchTrueFalseTotal
if $part_i + 1 == @{$self->{"parts"};} 17 3 20
120  
121 3 my $next_part = $self->{parts}->[$part_i+1];
122 # merge with next part
123 3 ▶ if ($to == $next_part->{start}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to == $next_part->{"start"}) 1 2 3
124 1 push @{ $part->{bytes} }, @{ $next_part->{bytes} };
125 1 splice @{ $self->{parts} }, $part_i+1, 1;
126 }
127 3 return;
128 }
129 elsif ($from < $start_addr) {
130 4 splice @{ $self->{parts} }, $part_i, 0, {
131 start => $from,
132 bytes => $bytes_hex_ref
133 };
134 4 return;
135 }
136 }
137  
138 27 push @{ $self->{parts} }, {
139 start => $from,
140 bytes => $bytes_hex_ref
141 };
142  
143 27 return;
144 }
145  
146 8 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
147 8 my ($self, $from, $length) = @_;
148  
149 8 my @bytes;
150 8 my $end_last = $from;
151 8 ▶ my $get = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
152 8 my ($part, $part_i_ref, $overlap) = @_;
153  
154 8 my $gap = $part->{start} - $end_last;
155 8 ▶ push @bytes, (undef) x $gap if $gap > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $gap > 0 2 6 8
156  
157 8 ▶ if ($overlap eq 'a') {
Branch: 3 branches
BranchTrueFalseTotal
if ($overlap eq 'a') { } 5 3 8
elsif ($overlap eq 'l') { } 1 2 3
elsif ($overlap eq 'r') { } 1 1 2
158 5 push @bytes, @{ $part->{bytes} };
159 }
160 elsif ($overlap eq 'l') {
161 1 push @bytes, @{ $part->{bytes} }[ 0 .. $length - 1 ];
162 }
163 elsif ($overlap eq 'r') {
164 1 push @bytes, @{ $part->{bytes} }[ $from - $part->{start} .. $#{ $part->{bytes} } ];
165 }
166 else {
167 1 my $start_i = $from - $part->{start};
168 1 push @bytes, @{ $part->{bytes} }[ $start_i .. $start_i + $length - 1];
169 }
170  
171 8 $end_last = $part->{start} + @{ $part->{bytes} };
172 8 };
173  
174 8 $self->_traverse($from, $length, $get);
175  
176 8 return [ @bytes, (undef) x ($length - @bytes) ];
177 }
178  
179 67 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
180 67 my ($self, $from, $length) = @_;
181  
182 67 my $to = $from + $length;
183  
184 33 ▶ my $remove = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
185 33 my ($part, $part_i_ref, $overlap) = @_;
186 33 ▶ if ($overlap eq 'a') {
Branch: 3 branches
BranchTrueFalseTotal
if ($overlap eq 'a') { } 22 11 33
elsif ($overlap eq 'l') { } 2 9 11
elsif ($overlap eq 'r') { } 7 2 9
187 22 splice @{ $self->{parts} }, $$part_i_ref, 1;
188 22 --$$part_i_ref;
189 }
190 elsif ($overlap eq 'l') {
191 2 my $to_remove = $to - $part->{start};
192 2 splice @{ $part->{bytes} }, 0, $to_remove;
193 2 $part->{start} += $to_remove;
194 }
195 elsif ($overlap eq 'r') {
196 7 splice @{ $part->{bytes} }, $from - $part->{start};
197 }
198 else {
199 2 splice @{ $self->{parts} }, $$part_i_ref, 1,
200 {
201 start => $part->{start},
202 2 bytes => [ @{ $part->{bytes} }[ 0 .. $from - $part->{start} - 1 ] ],
203 },
204 {
205 start => $from + $length,
206 2 bytes => [ @{ $part->{bytes} }[
207 2 $from - $part->{start} + $length .. $#{ $part->{bytes} }
208 ] ],
209 };
210 };
211 67 };
212  
213 67 $self->_traverse($from, $length, $remove);
214  
215 67 return;
216 }
217  
218 75 ▶sub _traverse {
Subroutine _traverse: called CC=10 SCAR=23.0
219 75 my ($self, $from, $length, $process) = @_;
220  
221 75 my $to = $from + $length;
222  
223 75 ▶ for (my $part_i = 0; $part_i < @{ $self->{parts} }; $part_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part_i < @{$self->{"parts"};}) 131 50 181
224 131 my $part = $self->{parts}->[$part_i];
225  
226 131 my $start_addr = $part->{start};
227 131 my $end_addr = $part->{start} + @{ $part->{bytes} };
228  
229 131 ▶ if ($from < $end_addr && $to > $start_addr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from < $end_addr and $to > $start_addr) 25 106 131
Condition100%3/3
$from < $end_addr and $to > $start_addr
!ll&&!rl&&r
911525
MC/DC100%2/2
$from < $end_addr and $to > $start_addr
$from < $end_addr $to > $start_addr
Truth table100%3/3
A and B
A= $from < $end_addrB= $to > $start_addr
ABresult
0X0
100
111
230 25 ▶ if ($from <= $start_addr) {
Branch: 2 branches
BranchTrueFalseTotal
if ($from <= $start_addr) { } 14 11 25
elsif ($to < $end_addr - 1) { } 3 8 11
231 14 ▶ if ($to < $end_addr -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to < $end_addr - 1) 2 12 14
232 2 $process->($part, \$part_i, 'l');
233 2 return;
234 }
235 12 $process->($part, \$part_i, 'a');
236 }
237 elsif ($to < $end_addr - 1) {
238 3 $process->($part, \$part_i, 'm');
239 3 return;
240 }
241 else {
242 8 $process->($part, $part_i, 'r');
243 }
244  
245 # found start -> search for end
246 20 ▶ while ( defined (my $part = $self->{parts}->[++$part_i]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $part = $self->{"parts"}[++$part_i])) 25 10 35
247 25 my $start_addr = $part->{start};
248 25 ▶ return if $start_addr > $to;
Branch: 1 branch
BranchTrueFalseTotal
if $start_addr > $to 9 16 25
249  
250 16 my $end_addr = $part->{start} + @{ $part->{bytes} };
251  
252 16 ▶ if ($to >= $end_addr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to >= $end_addr) { } 15 1 16
253 15 $process->($part, \$part_i, 'a');
254 }
255 else {
256 1 $process->($part, \$part_i, 'l');
257 1 return;
258 }
259 }
260 10 return;
261 }
262 }
263 }
264  
265 2 ▶sub as_intel_hex {
Subroutine as_intel_hex: called CC=5 SCAR=16.1
Pod documented
266 2 my ($self, $bytes_hex_a_line) = @_;
267  
268 2 my $intel_hex_string = '';
269 2 ▶ for (my $part_i = 0; $part_i < @{ $self->{parts} }; $part_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part_i < @{$self->{"parts"};}) 7 2 9
270 7 my $part = $self->{parts}->[$part_i];
271  
272 7 my $start_addr = $part->{start};
273 7 my $end_addr = $part->{start} + $#{ $part->{bytes} };
274  
275 7 my $cur_high_addr_hex = '0000';
276  
277 7 ▶ for (my $slice_i = 0; $slice_i * $bytes_hex_a_line < @{ $part->{bytes} }; $slice_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slice_i * $bytes_hex_a_line < @{$part->{"bytes"};}) 12 7 19
278 12 my $total_addr = $start_addr + $slice_i*$bytes_hex_a_line;
279  
280 12 my ($addr_high_hex, $addr_low_hex) = unpack '(A4)*', sprintf('%08X', $total_addr);
281  
282 12 ▶ if ($cur_high_addr_hex ne $addr_high_hex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur_high_addr_hex ne $addr_high_hex) 3 9 12
283 3 $cur_high_addr_hex = $addr_high_hex;
284 3 $intel_hex_string .= _intel_hex_line_of( '0000', 4, [unpack '(A2)*', $cur_high_addr_hex]);
285 }
286  
287 12 ▶ if ( ($slice_i + 1) * $bytes_hex_a_line <= $#{ $part->{bytes} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($slice_i + 1) * $bytes_hex_a_line <= $#{$$part{'bytes'};}) { } 5 7 12
288 $intel_hex_string .= _intel_hex_line_of(
289 $addr_low_hex, 0,
290 [
291 5 @{ $part->{bytes} }[
292 $slice_i * $bytes_hex_a_line .. ($slice_i + 1) * $bytes_hex_a_line - 1
293 ]
294 ]
295 );
296 }
297 else {
298 $intel_hex_string .= _intel_hex_line_of(
299 $addr_low_hex, 0, [
300 7 @{ $part->{bytes} }[
301 7 $slice_i * $bytes_hex_a_line .. $#{ $part->{bytes} }
302 ]
303 ]
304 );
305 }
306 }
307 }
308 # intel hex eof
309 2 return $intel_hex_string . ":00000001FF\n";
310 }
311  
312 15 ▶sub _intel_hex_line_of {
Subroutine _intel_hex_line_of: called CC=3 SCAR=11.0
313 15 my ($addr_low_hex, $type, $bytes_hex_ref) = @_;
314  
315 15 my $byte_count = @$bytes_hex_ref;
316  
317 15 my $sum = 0;
318 15 $sum += $_ for ( $byte_count, (map { hex $_ } unpack '(A2)*', $addr_low_hex),
319 121 $type, (map { hex $_ } @$bytes_hex_ref) );
320  
321 #convert to hex, take lsb
322 15 $sum = substr(sprintf( '%02X', $sum ), -2);
323  
324 15 my $checksum_hex = sprintf '%02X', (hex $sum ^ 255) + 1;
325 15 ▶ $checksum_hex = '00' if length $checksum_hex != 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $checksum_hex != 2 1 14 15
326  
327 15 return join '',
328 (
329 ':',
330 sprintf( '%02X', $byte_count ),
331 $addr_low_hex,
332 sprintf( '%02X', $type ),
333 @$bytes_hex_ref,
334 $checksum_hex,
335 "\n"
336 );
337 }
338  
339 1 ▶sub as_srec_hex {
Subroutine as_srec_hex: called CC=4 SCAR=13.9
Pod documented
340 1 my ($self, $bytes_hex_a_line) = @_;
341  
342 1 my $srec_hex_string = '';
343 1 ▶ for (my $part_i = 0; $part_i < @{ $self->{parts} }; $part_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part_i < @{$self->{"parts"};}) 7 1 8
344 7 my $part = $self->{parts}->[$part_i];
345  
346 7 my $start_addr = $part->{start};
347 7 my $end_addr = $part->{start} + $#{ $part->{bytes} };
348  
349 7 ▶ for (my $slice_i = 0; $slice_i * $bytes_hex_a_line < @{ $part->{bytes} }; $slice_i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slice_i * $bytes_hex_a_line < @{$part->{"bytes"};}) 12 7 19
350 12 my $total_addr = $start_addr + $slice_i*$bytes_hex_a_line;
351  
352 12 ▶ if ( ($slice_i + 1) * $bytes_hex_a_line <= $#{ $part->{bytes} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($slice_i + 1) * $bytes_hex_a_line <= $#{$$part{'bytes'};}) { } 5 7 12
353 $srec_hex_string .= _srec_hex_line_of(
354 $total_addr,
355 5 [@{ $part->{bytes} }[$slice_i * $bytes_hex_a_line .. ($slice_i + 1) * $bytes_hex_a_line - 1]]
356 );
357 }
358 else {
359 $srec_hex_string .= _srec_hex_line_of(
360 $total_addr,
361 7 [@{ $part->{bytes} }[$slice_i * $bytes_hex_a_line .. $#{ $part->{bytes} }]]
362 );
363 }
364 }
365 }
366  
367 1 return $srec_hex_string;
368 }
369  
370 12 ▶sub _srec_hex_line_of {
Subroutine _srec_hex_line_of: called CC=6 SCAR=17.9
371 12 my ($total_addr, $bytes_hex_ref) = @_;
372  
373 12 my $total_addr_hex = sprintf '%04X', $total_addr;
374  
375 12 my $type;
376 # 16 bit addr
377 12 ▶ if (length $total_addr_hex == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $total_addr_hex == 4) { } 5 7 12
elsif (length $total_addr_hex <= 6) { } 4 3 7
378 5 $type = 1;
379 }
380 # 24 bit addr
381 elsif (length $total_addr_hex <= 6) {
382 4 ▶ $total_addr_hex = "0$total_addr_hex" if length $total_addr_hex == 5;
Branch: 1 branch
BranchTrueFalseTotal
if length $total_addr_hex == 5 3 1 4
383 4 $type = 2;
384 }
385 # 32 bit addr
386 else {
387 3 ▶ $total_addr_hex = "0$total_addr_hex" if length $total_addr_hex == 7;
Branch: 1 branch
BranchTrueFalseTotal
if length $total_addr_hex == 7 1 2 3
388 3 $type = 3;
389 }
390  
391 # count of data bytes + address bytes
392 12 my $byte_count = @$bytes_hex_ref + length($total_addr_hex) / 2;
393  
394 12 my $sum = 0;
395 12 $sum += $_ for ( $byte_count,
396 34 (map { hex $_ } unpack '(A2)*', $total_addr_hex),
397 93 (map { hex $_ } @$bytes_hex_ref) );
398  
399 #convert to hex, take lsb
400 12 $sum = substr(sprintf( '%02X', $sum ), -2);
401  
402 12 my $checksum_hex = sprintf '%02X', (hex $sum ^ 255);
403  
404 12 return join '',
405 (
406 "S$type",
407 sprintf('%02X', $byte_count),
408 $total_addr_hex,
409 @$bytes_hex_ref,
410 $checksum_hex,
411 "\n"
412 );
413 }
414  
415 8 1;
416  
417 =head1 NAME
418  
419 Hex::Record - manipulate intel and srec hex records
420  
421 =head1 SYNOPSIS
422  
423 use Hex::Record;
424  
425 my $hex_record = Hex::Record->new;
426  
427 $hex_record->import_intel_hex($intel_hex_str);
428 $hex_record->import_srec_hex($srec_hex_str);
429  
430 $hex_record->write(0x100, [qw(AA BB CC)]);
431  
432 # get 10 bytes (hex format) starting at address 0x100
433 # every single byte that is not found is returned as undef
434 my $bytes_ref = $hex_record->get(0x100, 10);
435  
436 # remove 10 bytes starting at address 0x100
437 $hex_record->remove(0x100, 10);
438  
439 # dump as intel hex (will use extended linear addresses for offset)
440 # maximum of 10 bytes in data field
441 my $intel_hex_string = $hex_record->as_intel_hex(10);
442  
443 # dump as srec hex (always tries to use smallest address, 16 bit, 24 bit, 32 bit)
444 # maximum of 10 bytes in data field
445 my $srec_hex_string = $hex_record->as_srec_hex(10);
446  
447 =head1 DESCRIPTION
448  
449 Manipulate intel/srec hex files.
450  
451 =head1 Methods
452  
453 =head2 import_intel_hex($intel_hex_str)
454  
455 Imports hex bytes from a string containing intel hex formatted data.
456 Ignores unknown lines, does not check if the checksum at the end is correct.
457  
458 $hex_record->import_intel_hex($intel_hex_str);
459  
460 =head2 import_srec_hex($srec_hex_str)
461  
462 Imports hex bytes from a string containing srec hex formatted data.
463 Ignores unknown lines, does not check if the checksum at the end is correct.
464  
465 $hex_record->import_srec_hex($srec_hex_str);
466  
467 =head2 get($from, $count)
468  
469 Returns $count hex bytes in array reference starting at address $from.
470 If hex byte is not found, undef instead. For example:
471  
472 my $bytes_ref = $hex_record->get(0x0, 6); # ['AA', '00', undef, undef, 'BC', undef]
473  
474 =head2 remove($from, $count)
475  
476 Removes $count bytes starting at address $from.
477  
478 $hex_record->remove(0x123, 10);
479  
480 =head2 write($from, $bytes_ref)
481  
482 (Over)writes bytes starting at address $from with bytes in $bytes_ref.
483  
484 $hex_record->write(0x10, [qw(AA BB CC DD EE FF 11)]);
485  
486 =head2 as_intel_hex($bytes_hex_a_line)
487  
488 Returns a string containing hex bytes formatted as intel hex.
489 Maximum of $bytes_hex_a_line in data field.
490 Extended linear addresses as offset are used if needed.
491 Extended segment addresses are not supported. (yet? let me know!)
492  
493 my $intel_hex_str = $hex_record->as_intel_hex(10);
494  
495 =head2 as_srec_hex($bytes_hex_a_line)
496  
497 Returns a string containing hex bytes formatted as srec hex.
498 Maximum of $bytes_hex_a_line in data field.
499 Tries to use the smallest address field. (16 bit, 24 bit, 32 bit)
500  
501 my $srec_hex_str = $hex_record->as_srec_hex(10);
502  
503 =head1 LICENSE
504  
505 This is released under the Artistic License.
506  
507 =head1 AUTHOR
508  
509 spebern <bernhard@specht.net>
510  
511 =cut
↑ Summary