23464ee21644217c7570e57f429a65868fd623b4
[Biblio-RFID.git] / lib / RFID / Biblio / RFID501.pm
1 package RFID::Biblio::RFID501;
2
3 use warnings;
4 use strict;
5
6 =head1 NAME
7
8 RFID::Biblio::RFID501 - RFID Standard for Libraries
9
10 =head1 DESCRIPTION
11
12 This module tries to decode tag format as specified in document
13
14   RFID 501: RFID Standards for Libraries
15
16 However, document is lacking real specification, so tag decoding
17 was done to be compliant with 3M implementation
18
19 =head1 METHODS
20
21 =head2 decode_tag
22
23   my $hash = RFID::Biblio::Decode::RFID501->to_hash( $bytes );
24
25   my $hash = RFID::Biblio::Decode::RFID501->to_hash( [ 'blk1', 'blk2', ... , 'blk7' ] );
26
27 =cut
28
29 my $item_type = {
30         1 => 'Book',
31         6 => 'CD/CD ROM',
32         2 => 'Magazine',
33         13 => 'Book with Audio Tape',
34         9 => 'Book with CD/CD ROM',
35         0 => 'Other',
36
37         5 => 'Video',
38         4 => 'Audio Tape',
39         3 => 'Bound Journal',
40         8 => 'Book with Diskette',
41         7 => 'Diskette',
42 };
43
44 sub to_hash {
45         my ( $self, $data ) = @_;
46
47         return unless $data;
48
49         $data = join('', @$data) if ref $data eq 'ARRAY';
50
51         warn "## to_hash $data\n";
52
53         my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data);
54         my $hash = {
55                 u1 => $u1,      # FIXME
56                 u2 => $u2,      # FIXME
57                 set => ( $set_item & 0xf0 ) >> 4,
58                 total => ( $set_item & 0x0f ),
59
60                 type => $type,
61                 type_label => $item_type->{$type},
62                 content => $content,
63
64                 branch => $br_lib >> 20,
65                 library => $br_lib & 0x000fffff,
66
67                 custom => $custom,
68         };
69
70         return $hash;
71 }
72
73 1;