X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=checkcard.pl;h=4e3816f6a50a68f302f38d7a64730b0f595f0862;hp=b948393935c0cf4e7a19e397f6d32aae52d8abad;hb=050398149d26f27a0b19971cbcea990574d73a57;hpb=889622e0c6757408211798cfe8562a026a93b5b2 diff --git a/checkcard.pl b/checkcard.pl index b948393..4e3816f 100755 --- a/checkcard.pl +++ b/checkcard.pl @@ -3,22 +3,31 @@ use Socket; use strict; my $fh; -#my $fifofile = "/tmp/door_cmd.fifo"; -my $socketfile = "/tmp/door_cmd.socket"; -exit(1) unless (-S $socketfile); +my $socketfile = $ARGV[0] || "/var/run/tuer/door_cmd.socket"; +my $keysfile = '/flash/keys'; + +sleep(1) while (! -S $socketfile); my $socketaddr = sockaddr_un($socketfile); -my $keys; my %good; +my $keys_last_read=0; -open $keys,'/flash/realraum/keys'; -while (<$keys>) +sub read_keys { - if ($_ =~ /([0-9A-Fa-f]{8})\s(\S+)/) - { - $good{$1}=$2; - } + %good=(); + my $keys; + open $keys,$keysfile; + while (<$keys>) + { + chomp; + if ($_ =~ /^([0-9A-Fa-f]{8})\s+(.+)$/) + { + $good{$1}=$2; + } + } + close $keys; + $keys_last_read = -M ($keysfile); } sub send_to_fifo @@ -29,12 +38,25 @@ sub send_to_fifo close($conn); } -while (sleep 1) +read_keys(); + + +while (sleep 2) { - open $fh,'/flash/realraum/mifare-read 0 2>&1 |'; - while (<$fh>) - { - next unless /UID/; + send_to_fifo("log starting mifare-read"); + open $fh,'/flash/tuer/mifare-read 0 2>&1 |'; + + read_keys() unless ($keys_last_read == -M ($keysfile)); + + READLOOP: while (<$fh>) + { + unless (/UID/) + { + close($fh); + system("/usr/bin/killall -9 mifare-read"); + send_to_fifo("log restarting mifare-read after invalid output"); + last READLOOP; + } my ($id) = /UID=(\S+)\s+/; if ($good{$id}) { @@ -53,36 +75,5 @@ while (sleep 1) # # ############################################################### -# /dev/ttyUSB0: door key printer -# -# -# Ok -# Ok, closing now -# Already closed -# Already opened -# close forced manually\nOk -# open forced manually\nOk -# Error: .* -# .* be: unknown command -# Operation in progress -# open/close took too long! -# last open/close operation took to long! -# -# commands: -# c ... close -# response: "Ok", "Already closed", "Error: .*" -# o ... open -# response: "Ok", "Already opened", "Error: .*" -# s ... status -# response: "Status: closed|opened|<->, opening|waiting|closing|idle" -# or "Error: .*" -# r ... reset -# "Ok, closing now" or "Error: .*" -# -# open/close will only be accepted if Status: ..., idle -# Reset overrules all other operations in progress -# s will always be accepted -# -############################################################### # #