From c2f18d715e13a001ef3857e5de08bf20fc8803ee Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 16 Jul 2009 15:25:14 +0000 Subject: [PATCH] =?UTF-8?q?[Positioning]=20Int=C3=A9gration=20commentaires?= =?UTF-8?q?=20de=20Julien?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@105 785a6c6c-259e-4ff1-8b91-dc31627914f0 --- owlps-positioning/clientinfo.hh | 2 +- owlps-positioning/libowlps-positioning.cc | 14 +++++++++ owlps-positioning/server.cc | 38 ++++++++++++++--------- owlps-positioning/server.hh | 8 ++--- owlps-positioning/treatment.cc | 1 - 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/owlps-positioning/clientinfo.hh b/owlps-positioning/clientinfo.hh index a882af0..1b75a82 100644 --- a/owlps-positioning/clientinfo.hh +++ b/owlps-positioning/clientinfo.hh @@ -46,7 +46,7 @@ class ClientInfo float getAntennaGain()const { return antenna_gain; - }; + } ; vector& getRef_viterbi_Ecurrent() { return viterbi_Ecurrent; diff --git a/owlps-positioning/libowlps-positioning.cc b/owlps-positioning/libowlps-positioning.cc index f6af3c0..f7e89c1 100644 --- a/owlps-positioning/libowlps-positioning.cc +++ b/owlps-positioning/libowlps-positioning.cc @@ -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 explode(const string &input, const char &sep) { vector vs; @@ -32,12 +36,16 @@ vector explode(const string &input, const char &sep) return vs; } + +/* Le Format Fred n'est pas utilisé */ vector extractReferencePointInfoFromBuffer(const string &buffer_in) { unsigned int i = 0; string tmp_field; vector ret; + /* Extract coordinates */ + /* x */ while (buffer_in[i] != ';') { tmp_field.push_back(buffer_in[i]); @@ -47,6 +55,7 @@ vector 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 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 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 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 ; diff --git a/owlps-positioning/server.cc b/owlps-positioning/server.cc index 468a91e..d71a432 100644 --- a/owlps-positioning/server.cc +++ b/owlps-positioning/server.cc @@ -2,10 +2,10 @@ +/* Transforme un string en un type différent */ template 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(); 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(); 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(); 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() << "'"; 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()); else pos.makeTopologyFromDb(conn); + /* Création de la liste des points de passage */ if (vm.count("input-waypoint")) pos.makeWaypointListFromFile(vm["input-waypoint"].as()); 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(), 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()) ; 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(PQgetvalue(res, PQntuples(res) - 1, 0)): 0; + id_request = (PQntuples(res) != 0)? from_string(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(¤t, NULL); + gettimeofday(¤t, 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(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); diff --git a/owlps-positioning/server.hh b/owlps-positioning/server.hh index c34b8c1..f62b972 100644 --- a/owlps-positioning/server.hh +++ b/owlps-positioning/server.hh @@ -20,12 +20,12 @@ class Server { private: - request att_request; + request att_request; vector 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_ diff --git a/owlps-positioning/treatment.cc b/owlps-positioning/treatment.cc index 0fd838f..f024f6b 100644 --- a/owlps-positioning/treatment.cc +++ b/owlps-positioning/treatment.cc @@ -414,4 +414,3 @@ Point Treatment::getkWeightedInSs(const unsigned int &k, const Point *point_igno return ret; } -