X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=checkcard.pl;h=cc1d1b715a11cddcf31e92213e0afddd542e0af7;hb=efb533dcb175bf15fd003a635d77b6ff15756b6f;hp=71c1966df286b44f5bf21905a585185b94878278;hpb=35f34ea01e12293c9f987cdd69e582d0c88473d7;p=svn42.git diff --git a/checkcard.pl b/checkcard.pl index 71c1966..cc1d1b7 100755 --- a/checkcard.pl +++ b/checkcard.pl @@ -1,16 +1,21 @@ #!/usr/bin/perl -w +use Socket; use strict; my $fh; -my $fifofile = "/tmp/door_cmd.fifo"; + +my $socketfile = $ARGV[0] || "/var/run/tuer/door_cmd.socket"; +sleep(1) while (! -S $socketfile); +my $socketaddr = sockaddr_un($socketfile); my $keys; my %good; -open $keys,'/flash/realraum/keys'; +open $keys,'/flash/keys'; while (<$keys>) { - if ($_ =~ /([0-9A-Fa-f]{8})\s(\S+)/) + chomp; + if ($_ =~ /^([0-9A-Fa-f]{8})\s+(.+)$/) { $good{$1}=$2; } @@ -18,17 +23,15 @@ while (<$keys>) sub send_to_fifo { - if( -p $fifofile) - { - open(my $fifo,"> $fifofile"); - print $fifo shift(@_)."\n"; - close($fifo); - } + socket(my $conn, PF_UNIX, SOCK_STREAM,0) || die "socket: $!"; + connect($conn, $socketaddr) || die "socket connect: $!"; + print $conn shift(@_)."\n"; + close($conn); } while (sleep 1) { - open $fh,'/flash/realraum/mifare-read 0 2>&1 |'; + open $fh,'/flash/tuer/mifare-read 0 2>&1 |'; while (<$fh>) { next unless /UID/; @@ -50,36 +53,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 -# -############################################################### # #