read tag after programming and retry programming if needed
[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 =back
13
14
15 =head1 METHODS
16
17 =head2 to_hash
18
19   my $hash = Biblio::RFID::Decode::SmartX->to_hash( [ 'sector1', 'sector2', ... , 'sector7' ] );
20
21 =cut
22
23 sub bcd {
24         my $data = shift;
25         return join('', map { sprintf("%02x",ord($_)) } split (//, $data));
26 }
27
28 sub to_hash {
29         my ( $self, $data ) = @_;
30
31         return unless $data;
32
33         die "expecting array of sectors" unless ref $data eq 'ARRAY';
34
35         my $decoded;
36         foreach ( 4 .. 6 ) {
37                 warn "# $_: ",
38                 $decoded->[$_] = bcd( $data->[$_] );
39         }
40
41         my $hash;
42         $hash->{SXID}    = substr( $decoded->[4], 0,  20 );
43         $hash->{JMBAG}   = substr( $decoded->[4], 22, 10 );
44         $hash->{OIB}     = substr( $decoded->[5], 16, 11 );
45         $hash->{SPOL}    = substr( $data->[5], 14, 1 ); # char, not BCD!
46         $hash->{INST_ID} = substr( $decoded->[6], 0, 12 );
47         $hash->{CARD_V}  = substr( $decoded->[6], 12, 4  );
48
49         warn "## hash = ",dump($hash);
50
51         return $hash;
52
53 }
54
55 1;