[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:
Matteo Cypriani 2009-07-16 15:25:14 +00:00
parent 92194b4f50
commit c2f18d715e
5 changed files with 43 additions and 20 deletions

View File

@ -46,7 +46,7 @@ class ClientInfo
float getAntennaGain()const
{
return antenna_gain;
};
} ;
vector<Point>& getRef_viterbi_Ecurrent()
{
return viterbi_Ecurrent;

View File

@ -1,5 +1,7 @@
#include "libowlps-positioning.hh"
/* Tronque le float "f" à "n" décimales et le retourne */
float round_float(float f, int n)
{
n = (int) pow((double) 10, (double) n) ;
@ -9,6 +11,8 @@ float round_float(float f, int n)
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> vs;
@ -32,12 +36,16 @@ vector<string> explode(const string &input, const char &sep)
return vs;
}
/* Le Format Fred n'est pas utilisé */
vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
{
unsigned int i = 0;
string tmp_field;
vector<string> ret;
/* Extract coordinates */
/* x */
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
@ -47,6 +55,7 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
tmp_field.clear();
i++; // go after the ';'
/* y */
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
@ -56,6 +65,7 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
tmp_field.clear();
i++;
/* z */
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
@ -65,6 +75,7 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
tmp_field.clear();
i++;
/* Extract direction (not used now) */
while (buffer_in[i] != ';')
{
tmp_field.push_back(buffer_in[i]);
@ -87,9 +98,12 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
i++ ;
}
/* Return the vector with each data */
return ret;
}
uint64_t timeval_to_ms(const struct timeval &d)
{
return d.tv_sec * 1000 + d.tv_usec / 1000 ;

View File

@ -2,10 +2,10 @@
/* Transforme un string en un type différent */
template <class T>
inline T from_string(const string &s)
{
T t;
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)
{
ostringstream oss;
string buf;
/* Connexion à la BdD */
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>();
else
{
@ -32,7 +33,7 @@ int Server::init(const boost::program_options::variables_map vm)
}
oss << "' dbname = '";
if (vm.count("db.name"))
if (vm.count("db.name")) // Recherche du nom de la BdD
oss << vm["db.name"].as<string>();
else
{
@ -41,7 +42,7 @@ int Server::init(const boost::program_options::variables_map vm)
}
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>();
else
{
@ -50,7 +51,7 @@ int Server::init(const boost::program_options::variables_map vm)
}
oss << "' password = '";
if (vm.count("db.passwd"))
if (vm.count("db.passwd")) // Recherche du mot de passe
oss << vm["db.passwd"].as<string>() << "'";
else
{
@ -69,12 +70,15 @@ int Server::init(const boost::program_options::variables_map vm)
return 1;
}
/* Création de la topology */
if (vm.count("input-topo")) pos.makeTopologyFromFile(vm["input-topo"].as<string>());
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>());
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);
else pos.makeReferencePointListFromDb(conn, true);
@ -86,6 +90,7 @@ int Server::init(const boost::program_options::variables_map vm)
pos.makeReferencePointDistances();
/* Création de la liste des Access Point */
if (vm.count("input-ap"))
pos.makeApListFromFile(vm["input-ap"].as<string>()) ;
else
@ -129,6 +134,7 @@ int Server::start()
/* Récupération des données envoyées par le client */
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)
{
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 << "\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++)
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()
{
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));
ostringstream oss;
PGresult *res;
/* */
Treatment treat(pos.getAccessPointList(), pos.getReferencePointList());
treat.makeMeasurementList(recv_info);
@ -177,10 +186,10 @@ void Server::treatment()
oss << "SELECT r.id_request FROM request r, mobile m ";
oss << "WHERE r.mobile_time = " << timeval_to_ms(att_request.request_time);
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());
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);
/* 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)
{
int id_result;
string buf;
ostringstream oss;
@ -229,7 +238,7 @@ void Server::createResult(Point solution, int id_request, string use_algo)
PGresult *res;
gettimeofday(&current, NULL);
gettimeofday(&current, NULL); // On récupère l'heure du calcul
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;
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 << id_result << "','" << solution.getX() << "','" << solution.getY() << "','" << solution.getZ();
oss << "','" << timeval_to_ms(current) << "','" << use_algo;
if (id_request != 0) oss << "','" << id_request;
if (id_request != -1) oss << "','" << id_request;
oss << "');";
PQexec(conn, oss.str().c_str());
@ -262,7 +271,7 @@ void Server::sendToClient(Point solution, char *mac)
PGresult *res;
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());
if (PQntuples(res) != 0)
@ -290,6 +299,7 @@ void Server::sendToClient(Point solution, char *mac)
y = solution.getY();
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 *)&y, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
sendto(sockfd, (void *)&z, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);

View File

@ -20,12 +20,12 @@ class Server
{
private:
request att_request;
request att_request;
vector<couple_info> recv_info;
int listen_port;
int listen_port;
int mobile_port;
int listen_socket;
int listen_socket;
PGconn *conn;
@ -50,4 +50,4 @@ class Server
void sendToClient(Point, char *);
};
#endif
#endif // _SERVER_HH_

View File

@ -414,4 +414,3 @@ Point Treatment::getkWeightedInSs(const unsigned int &k, const Point *point_igno
return ret;
}