153 |
{ |
{ |
154 |
my $str=shift; |
my $str=shift; |
155 |
my $count = $port->write($str); |
my $count = $port->write($str); |
156 |
print ">> ", as_hex( $str ), "\t[$count]\n"; |
print "#> ", as_hex( $str ), "\t[$count]\n"; |
157 |
} |
} |
158 |
|
|
159 |
sub as_hex { |
sub as_hex { |
206 |
my $patt = substr( str2bytes($pattern), 3 ); # just payload |
my $patt = substr( str2bytes($pattern), 3 ); # just payload |
207 |
my $l = length($patt); |
my $l = length($patt); |
208 |
my $p = substr( $assert->{payload}, 0, $l ); |
my $p = substr( $assert->{payload}, 0, $l ); |
209 |
warn "## dispatch pattern $pattern [$l] ",dump( $patt, $p ); |
warn "## dispatch pattern $pattern [$l] ",dump( $patt, $p ) if $debug; |
210 |
|
|
211 |
if ( $assert->{payload} eq $assert->{expect} ) { |
if ( $assert->{payload} eq $assert->{expect} ) { |
212 |
warn "## no dispatch, payload expected\n"; |
warn "## no dispatch, payload expected" if $debug; |
213 |
} elsif ( $p eq $patt ) { |
} elsif ( $p eq $patt ) { |
214 |
# if matched call with rest of payload |
# if matched call with rest of payload |
215 |
$coderef->( substr( $assert->{payload}, $l ) ); |
$coderef->( substr( $assert->{payload}, $l ) ); |
216 |
} else { |
} else { |
217 |
warn "## dispatch ignored\n"; |
warn "## dispatch ignored" if $debug; |
218 |
} |
} |
219 |
} |
} |
220 |
|
|