SATS/lib/mfrc522/source/read.php

34 lines
642 B
PHP
Raw Normal View History

#!/usr/bin/php
<?php
require_once __DIR__.'/../../include/const';
function mfrc522_read(){
/* [1] Read card code
=========================================================*/
/* (1) Fetch card file */
$code = @file_get_contents(TMP_DIR.'/card');
/* (2) Manage error */
if( !is_string($code) || !preg_match("/^\s*([A-F0-9]{2}(?:-[A-F0-9]{2}){3,5})\s*$/m", $code, $match) )
return 127;
/* (3) Extract only code */
$code = $match[1];
/* [2] Return card code
=========================================================*/
slog("read $code code", 'mfrc522:read');
return $code;
}
echo mfrc522_read();
?>