73 lines
1.4 KiB
PHP
Executable File
73 lines
1.4 KiB
PHP
Executable File
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
require_once __DIR__.'/../../include/php/const';
|
|
|
|
$f_authlist;
|
|
$f_accesslog;
|
|
|
|
$last_card;
|
|
$times;
|
|
|
|
|
|
function mfrc522_setup(){
|
|
|
|
/* [1] Open file descriptors on useful files
|
|
=========================================================*/
|
|
$f_authlist = new SplFileObject(AUTH_LIST, 'r');
|
|
$f_accesslog = new SplFileObject(ACCESS_LOG, 'a');
|
|
|
|
/* [2] Parse @authlist to cache [action]=>[rfid1, rfid2, ..]
|
|
=========================================================*/
|
|
|
|
|
|
/* [3] Initialize global variables
|
|
=========================================================*/
|
|
$last_card = null;
|
|
$times = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function mfrc522_loop(){
|
|
|
|
/* [1] Wait for rfid card
|
|
=========================================================*/
|
|
while( ($code=syscall(SOURCE_DIR.'/lib/mfrc522/read')) === false );
|
|
|
|
$code = strtoupper($code);
|
|
|
|
slog("card '$code' read", 'mfrc522:read');
|
|
|
|
$start_ts = microtime(true);
|
|
|
|
|
|
/* [2] Check for user in auth list
|
|
=========================================================*/
|
|
|
|
|
|
/* [3] Manage action (states)
|
|
=========================================================*/
|
|
|
|
|
|
/* [n] Wait for 0.5 s before reading again
|
|
=========================================================*/
|
|
while( microtime(true)-$start_ts < 0.5 );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
slog('daemon started (loop)', 'mfrc522:loop');
|
|
|
|
while( true )
|
|
mfrc522_loop();
|
|
?>
|
|
|