don't try to decode tag without data
[Biblio-RFID.git] / lib / RFID / Serial / Decode / RFID501.pm
1 package RFID::Serial::Decode::RFID501;
2
3 use warnings;
4 use strict;
5
6 =head1 NAME
7
8 RFID::501 - 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::Serial::Decode::RFID501->to_hash( $bytes );
24
25 =cut
26
27 my $item_type = {
28         1 => 'Book',
29         6 => 'CD/CD ROM',
30         2 => 'Magazine',
31         13 => 'Book with Audio Tape',
32         9 => 'Book with CD/CD ROM',
33         0 => 'Other',
34
35         5 => 'Video',
36         4 => 'Audio Tape',
37         3 => 'Bound Journal',
38         8 => 'Book with Diskette',
39         7 => 'Diskette',
40 };
41
42 sub to_hash {
43         my ( $self, $data ) = @_;
44
45         return unless $data;
46
47         my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data);
48         my $hash = {
49                 u1 => $u1,      # FIXME
50                 u2 => $u2,      # FIXME
51                 set => ( $set_item & 0xf0 ) >> 4,
52                 total => ( $set_item & 0x0f ),
53
54                 type => $type,
55                 type_label => $item_type->{$type},
56                 content => $content,
57
58                 branch => $br_lib >> 20,
59                 library => $br_lib & 0x000fffff,
60
61                 custom => $custom,
62         };
63
64         return $hash;
65 }
66
67 1;