decode RFID 501: RFID Standards for Libraries
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 27 Jul 2010 13:52:14 +0000 (15:52 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 27 Jul 2010 13:52:14 +0000 (15:52 +0200)
lib/RFID/Serial/Decode/RFID501.pm [new file with mode: 0644]
t/05-RFID501.t [new file with mode: 0755]

diff --git a/lib/RFID/Serial/Decode/RFID501.pm b/lib/RFID/Serial/Decode/RFID501.pm
new file mode 100644 (file)
index 0000000..22168e4
--- /dev/null
@@ -0,0 +1,49 @@
+package RFID::Serial::Decode::RFID501;
+
+use warnings;
+use strict;
+
+=head1 NAME
+
+RFID::501 - RFID Standard for Libraries
+
+=head1 DESCRIPTION
+
+This module tries to decode tag format as specified in document
+
+  RFID 501: RFID Standards for Libraries
+
+However, document is lacking real specification, so tag decoding
+was done to be compliant with 3M implementation
+
+=head1 METHODS
+
+=head2 decode_tag
+
+  my $hash = RFID::Serial::Decode::RFID501->to_hash( $bytes );
+
+=cut
+
+sub to_hash {
+       my ( $self, $data ) = @_;
+
+       my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data);
+       my $hash = {
+               u1 => $u1,      # FIXME
+               u2 => $u2,      # FIXME
+               set => ( $set_item & 0xf0 ) >> 4,
+               total => ( $set_item & 0x0f ),
+
+               type => $type,
+               content => $content,
+
+               branch => $br_lib >> 20,
+               library => $br_lib & 0x000fffff,
+
+               custom => $custom,
+       };
+
+       return $hash;
+}
+
+1;
diff --git a/t/05-RFID501.t b/t/05-RFID501.t
new file mode 100755 (executable)
index 0000000..d8e15e9
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use Test::More tests => 3;
+use Data::Dump qw(dump);
+
+use lib 'lib';
+
+BEGIN {
+       use_ok( 'RFID::Serial::Decode::RFID501' );
+}
+
+ok( my $hash = RFID::Serial::Decode::RFID501->to_hash( "\x04\x11\x00\x00200912310123\x00\x00\x00\x00" ), 'decode_tag' );
+diag dump $hash;
+
+ok( my $hash = RFID::Serial::Decode::RFID501->to_hash( "\x04\x11\x00\x011301234567\x00\x00\x00\x00\x00\x00" ), 'decode_tag' );
+diag dump $hash;
+