document data model on rfid tags
[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 described in document
13
14   RFID 501: RFID Standards for Libraries
15
16 L<http://solutions.3m.com/wps/portal/3M/en_US/3MLibrarySystems/Home/Resources/CaseStudiesAndWhitePapers/RFID501/>
17
18 Goal is to be compatibile with existing 3M Alphanumeric tag format
19 which, as far as I know, isn't specificed anywhere. My documentation about
20 this format is available at
21
22 L<http://saturn.ffzg.hr/rot13/index.cgi?hitchhikers_guide_to_rfid>
23
24 =head1 Data model
25
26 =head2 3M Alphanumeric tag
27
28  0   04 is 00 tt   i [4 bit] = number of item in set    [1 .. i .. s]
29                    s [4 bit] = total items in set
30                    tt [8 bit] = item type
31
32  1   dd dd dd dd   dd [16 bytes] = barcode data
33  2   dd dd dd dd
34  3   dd dd dd dd
35  4   dd dd dd dd
36
37  5   bb bl ll ll   b [12 bit] = branch [unsigned]
38                    l [20 bit] = library [unsigned]
39
40  6   cc cc cc cc   c [32 bit] = custom signed integer
41
42 =head2 3M Manufacturing Blank
43
44  0   55 55 55 55
45  1   55 55 55 55
46  2   55 55 55 55
47  3   55 55 55 55
48  4   55 55 55 55
49  5   55 55 55 55
50  6   00 00 00 00 
51
52 =head2 Generic blank
53
54  0   00 00 00 00
55  1   00 00 00 00
56  2   00 00 00 00
57
58 =head1 METHODS
59
60 =head2 decode_tag
61
62   my $hash = RFID::Biblio::Decode::RFID501->to_hash( $bytes );
63
64   my $hash = RFID::Biblio::Decode::RFID501->to_hash( [ 'blk1', 'blk2', ... , 'blk7' ] );
65
66 =cut
67
68 my $item_type = {
69         1 => 'Book',
70         6 => 'CD/CD ROM',
71         2 => 'Magazine',
72         13 => 'Book with Audio Tape',
73         9 => 'Book with CD/CD ROM',
74         0 => 'Other',
75
76         5 => 'Video',
77         4 => 'Audio Tape',
78         3 => 'Bound Journal',
79         8 => 'Book with Diskette',
80         7 => 'Diskette',
81 };
82
83 sub to_hash {
84         my ( $self, $data ) = @_;
85
86         return unless $data;
87
88         $data = join('', @$data) if ref $data eq 'ARRAY';
89
90         warn "## to_hash $data\n";
91
92         my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data);
93         my $hash = {
94                 u1 => $u1,      # FIXME
95                 set => ( $set_item & 0xf0 ) >> 4,
96                 total => ( $set_item & 0x0f ),
97
98                 u2 => $u2,      # FIXME
99
100                 type => $type,
101                 type_label => $item_type->{$type},
102                 content => $content,
103
104                 branch => $br_lib >> 20,
105                 library => $br_lib & 0x000fffff,
106
107                 custom => $custom,
108         };
109
110         return $hash;
111 }
112
113 1;