rssi_localisation.php
3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once 'model/map.php';
require_once 'model/access_point.php';
require_once 'model/location.php';
require_once 'model/rssi_record.php';
require_once 'model/struct.php';
class Controller_localisation
{
$a_pointsIP = {"192.168.2.11","192.168.2.8","192.168.2.9"};
$a_pointPORT = 8080;//"8080";//5000
public function localisation()
{
if(!empty($_GET['mac_addr']))
{
// ----------------------------------------------------------------------------------------- //
// ------------------------- Translation from DB to our Stuctures -------------------------- //
// ----------------------------------------------------------------------------------------- //
$loc = $entityManager->select('location')
->from('rssi_record')
->groupBy('location')
->getQuery()
->getResult();
$db = Array();
foreach($loc as $l) {
$ap = $entityManager->select('access_point')
->from('rssi_record')
->groupBy('location', 'access_point')
->getQuery()
->getResult();
$myHistoFinger = new HistogramFingerprint();
foreach($ap as $a) {
$myHistoVal = new HistogramValue();
$beans = $entityManager->getRepository('rssi_record')->findBy(array('location' => $l, 'access_point' => $a));
foreach($beans as $b) {
$myBean = new Bean();
$myBean->_value = $b.getValue();
$myBean->_occurence = $b.getOccurences();
array_push($myHistoVal->_value,$myBean);
}
$myHistoVal->_macAddr = ($entityManager->getRepository('access_point')->findOneBy(array('id' => $a.getAccess_point())).getMac_addr());
array_push($myHistoFinger->_mesurement,$myHistoVal);
}
$tmpPos = $entityManager->getRepository('location')->findOneBy(array('id' => $record.getLocation()));
$myLocation = new Location();
$myLocation->_x=$tmpPos.getX();
$myLocation->_y=$tmpPos.getY();
$myHistoFinger->_location = $myLocation;
array_push($db, $myHistoFinger);
}
// ----------------------------------------------------------------------------------------- //
// --------------------- Translation from AP response to our Stuctures --------------------- //
// ----------------------------------------------------------------------------------------- //
$devMeasurement = Array;
$response = http_get("http://".$ip.":".$a_pointPORT."/RSSIRequest?mac=".$_GET['mac_addr'], array("timeout"=>1), $info);
foreach($a_pointsIP as &$ip){
$histoVal = new HistogramValue();
$histoVal->_macAddr = $ip;
$response = http_get("http://".$ip.":".$a_pointPORT."/RSSIRequest?mac=".$_GET['mac_addr'], array("timeout"=>1), $info);
foreach($response["bean"] as $b) {
$bean = new Bean();
$bean->_value = $b["value"];
$bean->_occurence = $b["occurence"];
array_push($histoVal->_value,$bean);
}
array_push($devMeasurement,$histoVal);
}
// ----------------------------------------------------------------------------------------- //
// ---------------------------------- Find Position ---------------------------------------- //
// ----------------------------------------------------------------------------------------- //
$loc = locate($decFingerPrint, $db);
echo $loc->_x . ";" . $lox->_y;
}
}
}