Last active
February 4, 2020 11:07
-
-
Save ZiTAL/c6f2b453f2a595bfa016573a7a3b3e7d to your computer and use it in GitHub Desktop.
php: beacon algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$error_break = 2; | |
$error_array = array(); | |
$beacon_set_list = getBeacons(true); | |
// reset errors | |
foreach($beacon_set_list as $beacon) | |
$error_array[$beacon] = 0; | |
echo "Initial Beacon list:\n"; | |
print_r($beacon_set_list); | |
echo "-------------------\n"; | |
do | |
{ | |
$beacon_get_list = getBeacons(); | |
echo "Loop Beacon list:\n"; | |
print_r($beacon_get_list); | |
if(count($beacon_set_list)!==count($beacon_get_list)) | |
{ | |
$error_list = array(); | |
foreach($beacon_set_list as $beacon) | |
{ | |
if(!in_array($beacon, $beacon_get_list)) | |
{ | |
$error_array[$beacon]++; | |
if($error_array[$beacon]===$error_break) | |
$error_list[] = $beacon; | |
} | |
else | |
$error_array[$beacon] = 0; | |
} | |
if(count($error_list)>0) | |
{ | |
echo "ERROR!\n"; | |
print_r($error_list); | |
exit(); | |
} | |
} | |
else | |
{ | |
foreach($beacon_set_list as $beacon) | |
$error_array[$beacon] = 0; | |
} | |
sleep(1); | |
} | |
while(true); | |
function getBeacons($flag = false) | |
{ | |
$array = array | |
( | |
'e0:97:ff:6a:4a:a9', | |
'd1:09:ee:7f:5b:b0' | |
); | |
$r = rand(0,2); | |
if($flag || $r===0) | |
return $array; | |
else | |
return array($array[$r-1]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Initial Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
------------------- | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
[1] => d1:09:ee:7f:5b:b0 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
) | |
Loop Beacon list: | |
Array | |
( | |
[0] => e0:97:ff:6a:4a:a9 | |
) | |
ERROR! | |
Array | |
( | |
[0] => d1:09:ee:7f:5b:b0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment