fix pod
[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         return join('', map { sprintf("%02x",ord($_)) } split (//, $data));
24 }
25
26 sub to_hash {
27         my ( $self, $data ) = @_;
28
29         return unless $data;
30
31         die "expecting array of sectors" unless ref $data eq 'ARRAY';
32
33         my $decoded;
34         foreach ( 4 .. 6 ) {
35                 warn "# $_: ",
36                 $decoded->[$_] = bcd( $data->[$_] );
37         }
38
39         my $hash;
40         $hash->{SXID}    = substr( $decoded->[4], 0,  20 );
41         $hash->{JMBAG}   = substr( $decoded->[4], 22, 10 );
42         $hash->{OIB}     = substr( $decoded->[5], 16, 11 );
43         $hash->{SPOL}    = substr( $data->[5], 14, 1 ); # char, not BCD!
44         $hash->{INST_ID} = substr( $decoded->[6], 0, 12 );
45         $hash->{CARD_V}  = substr( $decoded->[6], 12, 4  );
46
47         warn "## hash = ",dump($hash);
48
49         return $hash;
50
51 }
52
53 1;