SmartX turn off warnings
[Biblio-RFID.git] / lib / Biblio / RFID / SmartX.pm
1 package Biblio::RFID::SmartX;
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7
8 =head1 NAME
9
10 Biblio::RFID::SmartX - Croatian student cards format
11
12
13 =head1 METHODS
14
15 =head2 to_hash
16
17   my $hash = Biblio::RFID::Decode::SmartX->to_hash( [ 'sector1', 'sector2', ... , 'sector7' ] );
18
19 =cut
20
21 sub bcd {
22         my $data = shift;
23         no warnings;
24         return join('', map { sprintf("%02x",ord($_)) } split (//, $data));
25 }
26
27 sub to_hash {
28         my ( $self, $data ) = @_;
29
30         return unless $data;
31
32         die "expecting array of sectors" unless ref $data eq 'ARRAY';
33
34         my $decoded;
35         foreach ( 4 .. 6 ) {
36                 warn "# $_: ",
37                 $decoded->[$_] = bcd( $data->[$_] );
38         }
39
40         no warnings;
41
42         my $hash;
43         $hash->{SXID}    = substr( $decoded->[4], 0,  20 );
44         $hash->{JMBAG}   = substr( $decoded->[4], 22, 10 );
45         $hash->{OIB}     = substr( $decoded->[5], 16, 11 );
46         $hash->{SPOL}    = substr( $data->[5], 14, 1 ); # char, not BCD!
47         $hash->{INST_ID} = substr( $decoded->[6], 0, 12 );
48         $hash->{CARD_V}  = substr( $decoded->[6], 12, 4  );
49
50         warn "## hash = ",dump($hash);
51
52         return $hash;
53
54 }
55
56 1;