File Coverage

blib/lib/RFID/Matrics/Reader/Test.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 8 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package RFID::Matrics::Reader::Test;
2 4     4   29026 use RFID::Matrics::Reader; $VERSION=$RFID::Matrics::Reader::VERSION;
  4         9  
  4         222  
3 4     4   4068 use RFID::Reader::TestBase;
  4         51110  
  4         264  
4             @ISA=qw(RFID::Reader::TestBase RFID::Matrics::Reader);
5              
6             # Written by Scott Gifford
7             # Copyright (C) 2004 The Regents of the University of Michigan.
8             # See the file LICENSE included with the distribution for license
9             # information.
10              
11             =head1 NAME
12              
13             RFID::Matrics::Reader::Test - A fake implementation of L for testing
14              
15             =head1 SYNOPSIS
16              
17             Provides fake backend methods to test out
18             L without having access
19             to a real reader. Inherits from
20             L.
21              
22             =cut
23              
24 4     4   35 use RFID::Matrics::Reader qw(hexdump);
  4         10  
  4         2038  
25              
26             our %TESTRESPONSE =
27             (
28             # Start constant read
29              
30             # Stop constant read
31             hex2bin('01 04 05 26 0a 45')
32             => hex2bin('01 04 06 25 00 6b 9a'),
33            
34             # Get parameter block
35             hex2bin('01 04 06 24 a0 b9 26')
36             => hex2bin('01 04 26 24 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 8a f6'),
37              
38             # Set parameter block
39             hex2bin('01 04 29 23 01 00 00 00 ff 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 bf 9e')
40             => hex2bin('01 04 06 23 00 bb ce'),
41              
42             # Get node address
43             hex2bin('01 ff 0d 19 af 03 00 00 00 00 00 00 af 8f')
44             => hex2bin('01 04 06 19 00 69 85'),
45            
46             # Get node status
47             hex2bin('01 04 05 14 9b 57')
48             => hex2bin('01 04 26 14 00 af 03 00 00 00 00 00 00 02 01 02 00 00 00 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 e7 0f e4 6f'),
49              
50             # Read tags
51             hex2bin('01 04 06 22 a0 69 72')
52             => hex2bin('01 04 35 22 01 a0 05 00 de 09 96 00 a8 07 05 c8 02 02 c4 76 01 00 00 00 00 02 02 c0 76 01 00 00 00 00 02 02 bc 76 01 00 00 00 00 02 02 bc 76 01 00 00 00 00 5a 0b')
53             . hex2bin('01 04 0c 22 00 05 00 23 00 00 00 81 e9'),
54             );
55              
56             sub new
57             {
58 2     2 0 36 my $class = shift;
59 2         13 my(%p)=@_;
60 2         6 my $self = {};
61 2         7 bless $self,$class;
62            
63             # Initialize everything.
64 2         9 foreach my $parent (@ISA)
65             {
66 4 50       92 if (my $init = $parent->can('_init'))
67             {
68 4         28 $init->($self,%p);
69             }
70             }
71              
72 2         24 $self;
73             }
74              
75             sub _process_input
76             {
77 8     8   436 my $self = shift;
78 8         12 my($buf)=@_;
79              
80 8 50       41 if ($buf =~ /^\x01.(.)/o)
81             {
82 8         47 my $pktsize = ord($1)+1;
83 8 50       22 if (length($buf) >= ($pktsize))
84             {
85 8 50       35 my $resp = $TESTRESPONSE{substr($buf,0,$pktsize,'')}
86             or die "Test module received invalid input: ",hexdump $buf,"\n";
87 8         35 $self->_add_output($resp);
88             }
89             }
90 8         59 $buf;
91             }
92              
93             sub hex2bin
94             {
95 52     52 0 68 my $hex = $_[0];
96 52         110 $hex =~ tr/0-9a-fA-F//cd;
97 52         487 pack("C*",map { hex } unpack("a2"x(length($hex)/2),$hex));
  992         1286  
98             }
99            
100             1;
101              
102             =head1 SEE ALSO
103              
104             L, L,
105             L, L.
106              
107             =head1 AUTHOR
108              
109             Scott Gifford Egifford@umich.eduE, Esgifford@suspectclass.comE
110              
111             Copyright (C) 2004 The Regents of the University of Michigan.
112              
113             See the file LICENSE included with the distribution for license
114             information.
115              
116             =cut
117              
118             1;