[Positioning] Intégration commentaires de Julien
git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@105 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
parent
92194b4f50
commit
c2f18d715e
|
@ -46,7 +46,7 @@ class ClientInfo
|
||||||
float getAntennaGain()const
|
float getAntennaGain()const
|
||||||
{
|
{
|
||||||
return antenna_gain;
|
return antenna_gain;
|
||||||
};
|
} ;
|
||||||
vector<Point>& getRef_viterbi_Ecurrent()
|
vector<Point>& getRef_viterbi_Ecurrent()
|
||||||
{
|
{
|
||||||
return viterbi_Ecurrent;
|
return viterbi_Ecurrent;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "libowlps-positioning.hh"
|
#include "libowlps-positioning.hh"
|
||||||
|
|
||||||
|
|
||||||
|
/* Tronque le float "f" à "n" décimales et le retourne */
|
||||||
float round_float(float f, int n)
|
float round_float(float f, int n)
|
||||||
{
|
{
|
||||||
n = (int) pow((double) 10, (double) n) ;
|
n = (int) pow((double) 10, (double) n) ;
|
||||||
|
@ -9,6 +11,8 @@ float round_float(float f, int n)
|
||||||
return f + f_dec ;
|
return f + f_dec ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Explodes a string into substrings based on separator sep. Returns a string vector. */
|
||||||
vector<string> explode(const string &input, const char &sep)
|
vector<string> explode(const string &input, const char &sep)
|
||||||
{
|
{
|
||||||
vector<string> vs;
|
vector<string> vs;
|
||||||
|
@ -32,12 +36,16 @@ vector<string> explode(const string &input, const char &sep)
|
||||||
return vs;
|
return vs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Le Format Fred n'est pas utilisé */
|
||||||
vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
||||||
{
|
{
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
string tmp_field;
|
string tmp_field;
|
||||||
vector<string> ret;
|
vector<string> ret;
|
||||||
|
|
||||||
|
/* Extract coordinates */
|
||||||
|
/* x */
|
||||||
while (buffer_in[i] != ';')
|
while (buffer_in[i] != ';')
|
||||||
{
|
{
|
||||||
tmp_field.push_back(buffer_in[i]);
|
tmp_field.push_back(buffer_in[i]);
|
||||||
|
@ -47,6 +55,7 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
||||||
tmp_field.clear();
|
tmp_field.clear();
|
||||||
i++; // go after the ';'
|
i++; // go after the ';'
|
||||||
|
|
||||||
|
/* y */
|
||||||
while (buffer_in[i] != ';')
|
while (buffer_in[i] != ';')
|
||||||
{
|
{
|
||||||
tmp_field.push_back(buffer_in[i]);
|
tmp_field.push_back(buffer_in[i]);
|
||||||
|
@ -56,6 +65,7 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
||||||
tmp_field.clear();
|
tmp_field.clear();
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
/* z */
|
||||||
while (buffer_in[i] != ';')
|
while (buffer_in[i] != ';')
|
||||||
{
|
{
|
||||||
tmp_field.push_back(buffer_in[i]);
|
tmp_field.push_back(buffer_in[i]);
|
||||||
|
@ -65,6 +75,7 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
||||||
tmp_field.clear();
|
tmp_field.clear();
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
/* Extract direction (not used now) */
|
||||||
while (buffer_in[i] != ';')
|
while (buffer_in[i] != ';')
|
||||||
{
|
{
|
||||||
tmp_field.push_back(buffer_in[i]);
|
tmp_field.push_back(buffer_in[i]);
|
||||||
|
@ -87,9 +98,12 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
||||||
i++ ;
|
i++ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the vector with each data */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t timeval_to_ms(const struct timeval &d)
|
uint64_t timeval_to_ms(const struct timeval &d)
|
||||||
{
|
{
|
||||||
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Transforme un string en un type différent */
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T from_string(const string &s)
|
inline T from_string(const string &s)
|
||||||
{
|
{
|
||||||
|
|
||||||
T t;
|
T t;
|
||||||
istringstream iss(s);
|
istringstream iss(s);
|
||||||
|
|
||||||
|
@ -16,14 +16,15 @@ inline T from_string(const string &s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialisation du serveur */
|
||||||
int Server::init(const boost::program_options::variables_map vm)
|
int Server::init(const boost::program_options::variables_map vm)
|
||||||
{
|
{
|
||||||
|
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
string buf;
|
string buf;
|
||||||
|
|
||||||
|
/* Connexion à la BdD */
|
||||||
oss << "hostaddr = '";
|
oss << "hostaddr = '";
|
||||||
if (vm.count("db.host"))
|
if (vm.count("db.host")) // Recherche du nom de l'hôte de la BdD
|
||||||
oss << vm["db.host"].as<string>();
|
oss << vm["db.host"].as<string>();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -32,7 +33,7 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
oss << "' dbname = '";
|
oss << "' dbname = '";
|
||||||
if (vm.count("db.name"))
|
if (vm.count("db.name")) // Recherche du nom de la BdD
|
||||||
oss << vm["db.name"].as<string>();
|
oss << vm["db.name"].as<string>();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -41,7 +42,7 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
oss << "' user = '";
|
oss << "' user = '";
|
||||||
if (vm.count("db.user"))
|
if (vm.count("db.user")) // Recherche du nom d'utilisateur de la BdD
|
||||||
oss << vm["db.user"].as<string>();
|
oss << vm["db.user"].as<string>();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -50,7 +51,7 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
oss << "' password = '";
|
oss << "' password = '";
|
||||||
if (vm.count("db.passwd"))
|
if (vm.count("db.passwd")) // Recherche du mot de passe
|
||||||
oss << vm["db.passwd"].as<string>() << "'";
|
oss << vm["db.passwd"].as<string>() << "'";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -69,12 +70,15 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Création de la topology */
|
||||||
if (vm.count("input-topo")) pos.makeTopologyFromFile(vm["input-topo"].as<string>());
|
if (vm.count("input-topo")) pos.makeTopologyFromFile(vm["input-topo"].as<string>());
|
||||||
else pos.makeTopologyFromDb(conn);
|
else pos.makeTopologyFromDb(conn);
|
||||||
|
|
||||||
|
/* Création de la liste des points de passage */
|
||||||
if (vm.count("input-waypoint")) pos.makeWaypointListFromFile(vm["input-waypoint"].as<string>());
|
if (vm.count("input-waypoint")) pos.makeWaypointListFromFile(vm["input-waypoint"].as<string>());
|
||||||
else pos.makeWaypointListFromDb(conn);
|
else pos.makeWaypointListFromDb(conn);
|
||||||
|
|
||||||
|
/* Création de la liste des points de référence */
|
||||||
if (vm.count("input-refpoint")) pos.makeReferencePointListFromFile(vm["input-refpoint"].as<string>(), true);
|
if (vm.count("input-refpoint")) pos.makeReferencePointListFromFile(vm["input-refpoint"].as<string>(), true);
|
||||||
else pos.makeReferencePointListFromDb(conn, true);
|
else pos.makeReferencePointListFromDb(conn, true);
|
||||||
|
|
||||||
|
@ -86,6 +90,7 @@ int Server::init(const boost::program_options::variables_map vm)
|
||||||
|
|
||||||
pos.makeReferencePointDistances();
|
pos.makeReferencePointDistances();
|
||||||
|
|
||||||
|
/* Création de la liste des Access Point */
|
||||||
if (vm.count("input-ap"))
|
if (vm.count("input-ap"))
|
||||||
pos.makeApListFromFile(vm["input-ap"].as<string>()) ;
|
pos.makeApListFromFile(vm["input-ap"].as<string>()) ;
|
||||||
else
|
else
|
||||||
|
@ -129,6 +134,7 @@ int Server::start()
|
||||||
/* Récupération des données envoyées par le client */
|
/* Récupération des données envoyées par le client */
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
/* Attente d'une demande d'un serveur d'aggrégation */
|
||||||
if (recvfrom(listen_socket, &att_request, sizeof(att_request), 0, (struct sockaddr *) &client, &client_len) < 0)
|
if (recvfrom(listen_socket, &att_request, sizeof(att_request), 0, (struct sockaddr *) &client, &client_len) < 0)
|
||||||
{
|
{
|
||||||
cerr << "Aucun message reçu du client" << endl;
|
cerr << "Aucun message reçu du client" << endl;
|
||||||
|
@ -146,6 +152,7 @@ int Server::start()
|
||||||
cout << "\tHeure de la demande\t: " << timeval_to_ms(att_request.request_time) << endl;
|
cout << "\tHeure de la demande\t: " << timeval_to_ms(att_request.request_time) << endl;
|
||||||
cout << "\tNombre de couples\t: " << att_request.nb_couples << endl;
|
cout << "\tNombre de couples\t: " << att_request.nb_couples << endl;
|
||||||
|
|
||||||
|
/* Récupération des couples (AP;Puissance) */
|
||||||
for (int i = 0; i < att_request.nb_couples; i++)
|
for (int i = 0; i < att_request.nb_couples; i++)
|
||||||
recvfrom(listen_socket, &recv_info.at(i), sizeof(couple_info), 0, (struct sockaddr *) &client, &client_len);
|
recvfrom(listen_socket, &recv_info.at(i), sizeof(couple_info), 0, (struct sockaddr *) &client, &client_len);
|
||||||
|
|
||||||
|
@ -157,16 +164,18 @@ int Server::start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Calcul de la position avec les différents algo */
|
||||||
void Server::treatment()
|
void Server::treatment()
|
||||||
{
|
{
|
||||||
Point solution;
|
Point solution;
|
||||||
|
|
||||||
int id_request;
|
int id_request; // Permet de récupérer l'id de la requête pour lui assigner les résultats
|
||||||
char *mac = (char *) malloc(18 * sizeof(char));
|
char *mac = (char *) malloc(18 * sizeof(char));
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
|
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
|
|
||||||
|
/* */
|
||||||
Treatment treat(pos.getAccessPointList(), pos.getReferencePointList());
|
Treatment treat(pos.getAccessPointList(), pos.getReferencePointList());
|
||||||
treat.makeMeasurementList(recv_info);
|
treat.makeMeasurementList(recv_info);
|
||||||
|
|
||||||
|
@ -177,10 +186,10 @@ void Server::treatment()
|
||||||
oss << "SELECT r.id_request FROM request r, mobile m ";
|
oss << "SELECT r.id_request FROM request r, mobile m ";
|
||||||
oss << "WHERE r.mobile_time = " << timeval_to_ms(att_request.request_time);
|
oss << "WHERE r.mobile_time = " << timeval_to_ms(att_request.request_time);
|
||||||
oss << " AND m.id_mobile = r.id_mobile";
|
oss << " AND m.id_mobile = r.id_mobile";
|
||||||
oss << " AND m.mobile_addr = '" << mac << "';";
|
oss << " AND m.mobile_addr = '" << mac << "';"; // On recherche dans la BdD la requête consernée
|
||||||
|
|
||||||
res = PQexec(conn, oss.str().c_str());
|
res = PQexec(conn, oss.str().c_str());
|
||||||
id_request = (PQntuples(res) != 0)? from_string<int>(PQgetvalue(res, PQntuples(res) - 1, 0)): 0;
|
id_request = (PQntuples(res) != 0)? from_string<int>(PQgetvalue(res, PQntuples(res) - 1, 0)): -1; // On conserve l'id de la requête
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/* Interlink Networks */
|
/* Interlink Networks */
|
||||||
|
@ -218,9 +227,9 @@ void Server::treatment()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Enregistrement du résultat dans la BdD */
|
||||||
void Server::createResult(Point solution, int id_request, string use_algo)
|
void Server::createResult(Point solution, int id_request, string use_algo)
|
||||||
{
|
{
|
||||||
|
|
||||||
int id_result;
|
int id_result;
|
||||||
string buf;
|
string buf;
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
|
@ -229,7 +238,7 @@ void Server::createResult(Point solution, int id_request, string use_algo)
|
||||||
|
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
|
|
||||||
gettimeofday(¤t, NULL);
|
gettimeofday(¤t, NULL); // On récupère l'heure du calcul
|
||||||
|
|
||||||
buf = "SELECT * FROM result;";
|
buf = "SELECT * FROM result;";
|
||||||
|
|
||||||
|
@ -237,11 +246,11 @@ void Server::createResult(Point solution, int id_request, string use_algo)
|
||||||
id_result = (PQntuples(res) != 0)? from_string<int>(PQgetvalue(res, PQntuples(res) - 1, 0)) + 1: 1;
|
id_result = (PQntuples(res) != 0)? from_string<int>(PQgetvalue(res, PQntuples(res) - 1, 0)) + 1: 1;
|
||||||
|
|
||||||
oss << "INSERT INTO result(id_result, x, y, z, calcul_date, using_algo";
|
oss << "INSERT INTO result(id_result, x, y, z, calcul_date, using_algo";
|
||||||
if (id_request != 0) oss << ", id_request";
|
if (id_request != -1) oss << ", id_request"; // Si la requête n'a pas été trouvé, on enregistre le résultat mais sans associé de requête
|
||||||
oss << ") VALUES('";
|
oss << ") VALUES('";
|
||||||
oss << id_result << "','" << solution.getX() << "','" << solution.getY() << "','" << solution.getZ();
|
oss << id_result << "','" << solution.getX() << "','" << solution.getY() << "','" << solution.getZ();
|
||||||
oss << "','" << timeval_to_ms(current) << "','" << use_algo;
|
oss << "','" << timeval_to_ms(current) << "','" << use_algo;
|
||||||
if (id_request != 0) oss << "','" << id_request;
|
if (id_request != -1) oss << "','" << id_request;
|
||||||
oss << "');";
|
oss << "');";
|
||||||
|
|
||||||
PQexec(conn, oss.str().c_str());
|
PQexec(conn, oss.str().c_str());
|
||||||
|
@ -262,7 +271,7 @@ void Server::sendToClient(Point solution, char *mac)
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
|
|
||||||
oss << "SELECT ip_mobile FROM mobile ";
|
oss << "SELECT ip_mobile FROM mobile ";
|
||||||
oss << "WHERE mobile_addr = '" << mac << "';";
|
oss << "WHERE mobile_addr = '" << mac << "';"; // On récupére l'adresse IP du mobile
|
||||||
|
|
||||||
res = PQexec(conn, oss.str().c_str());
|
res = PQexec(conn, oss.str().c_str());
|
||||||
if (PQntuples(res) != 0)
|
if (PQntuples(res) != 0)
|
||||||
|
@ -290,6 +299,7 @@ void Server::sendToClient(Point solution, char *mac)
|
||||||
y = solution.getY();
|
y = solution.getY();
|
||||||
z = solution.getZ();
|
z = solution.getZ();
|
||||||
|
|
||||||
|
/* On envoie les coordonnées de la position */
|
||||||
sendto(sockfd, (void *)&x, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
sendto(sockfd, (void *)&x, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
||||||
sendto(sockfd, (void *)&y, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
sendto(sockfd, (void *)&y, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
||||||
sendto(sockfd, (void *)&z, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
sendto(sockfd, (void *)&z, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
||||||
|
|
|
@ -20,12 +20,12 @@ class Server
|
||||||
{
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
request att_request;
|
request att_request;
|
||||||
vector<couple_info> recv_info;
|
vector<couple_info> recv_info;
|
||||||
|
|
||||||
int listen_port;
|
int listen_port;
|
||||||
int mobile_port;
|
int mobile_port;
|
||||||
int listen_socket;
|
int listen_socket;
|
||||||
|
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
|
|
||||||
|
@ -50,4 +50,4 @@ class Server
|
||||||
void sendToClient(Point, char *);
|
void sendToClient(Point, char *);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _SERVER_HH_
|
||||||
|
|
|
@ -414,4 +414,3 @@ Point Treatment::getkWeightedInSs(const unsigned int &k, const Point *point_igno
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue