Incorporation de la dernière version de Julien
Extrait de son courriel : « Par rapport à la précédente j'ai surtout corrigé des bugs. » Note : la version du listener portable sur Fonera, envoyée en même temps par Julien, viendra plus tard (le temps que je l'incorpore). Détail des changements après analyse du code : aggregator : correction de bogues. positioning : * Ajout d'un fichier de config format boost (cfg/config.cfg). * Makefile : implantation des cibles "install" et "uninstall" ; la cible "astyle" devient "style". * accesspoint.{hh,cc}, area.cc, measurement.hh, point.{hh,cc}, referencepoint.{hh,cc} : cosmétique. * owlps-positioning.c : correction de la lecture du fichier de config (ajout d'une option permettant de spécifier un fichier alternatif). * server.cc : essentiellement correction des requêtes. * libowlps-positioning.{hh,cc} : passage de "unsigned long long" à "uint64_t" comme type de retour de timeval_to_ms(). writeInDb : * Ajout de la gestion d'un fichier de config. * Ajout de deux scripts pour la BDD. git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@96 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
parent
f1e1122091
commit
b9bdb9400a
|
@ -21,7 +21,7 @@ CFLAGS=-O2 -W -Wall -Wstrict-prototypes -O -I.
|
|||
DEPFLAGS=-MMD
|
||||
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
|
||||
PICFLAG=-fPIC
|
||||
LIBS=-lpthread -lconfuse ../../libowlps/libowlps.so.1.0
|
||||
LIBS=-lpthread -lconfuse ../../libowlps/libowlps.so.1.0 -lpq
|
||||
|
||||
|
||||
## Cibles de compilation standard ##
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#define DEFAULT_CHECK_INTERVAL 500000 // Temps entre deux vérifications de la liste (en micro-secondes)
|
||||
#define DEFAULT_HOST_DB "127.0.0.1"
|
||||
#define DEFAULT_DB_NAME "owlps_db"
|
||||
#define DEFAULT_USER_DB "julien"
|
||||
#define DEFAULT_PASS_DB "10,mamci"
|
||||
#define DEFAULT_USER_DB "owlps"
|
||||
#define DEFAULT_PASS_DB "owlps"
|
||||
|
||||
/* Codes d'erreur */
|
||||
#define ERR_NO_MESSAGE_RECEIVED 1 // Erreur lors de la lecture sur la socket
|
||||
|
|
|
@ -274,7 +274,7 @@ void* monitor_couple_list(couple_list **couples)
|
|||
socklen_t serv_len = sizeof(serv);
|
||||
request demande;
|
||||
couple_info info;
|
||||
int sockfd,i;
|
||||
int sockfd;
|
||||
|
||||
sockfd = create_udp_sending_socket(cfg_getstr(cfg, "ip_positioner"), cfg_getint(cfg, "send_port"), &serv, &client);
|
||||
|
||||
|
@ -332,7 +332,6 @@ void* monitor_couple_list(couple_list **couples)
|
|||
// Envoi des infos de l'AP vers le serveur de géolocalisation
|
||||
memcpy(info.ap_mac_addr_bytes, couple_info_ptr->ap_mac_addr_bytes, 6);
|
||||
info.antenna_signal_dbm = couple_info_ptr->antenna_signal_dbm - 0x100;
|
||||
for(i = 0; i < demande.nb_couples; i++)
|
||||
sendto(sockfd, (void *)&info, sizeof(couple_info), 0, (struct sockaddr *)&serv, serv_len);
|
||||
|
||||
// Inscription des infos de l'AP dans le fichier
|
||||
|
@ -600,6 +599,16 @@ int DbAccessPoint(couple_message message, PGconn *conn)
|
|||
if(PQresultStatus(res) != PGRES_TUPLES_OK){
|
||||
printf("Commande incorrect : %s\n", PQerrorMessage(conn));
|
||||
return -1;
|
||||
}else if(PQntuples(res) == 0){
|
||||
PQclear(res);
|
||||
sprintf(buf, "SELECT * FROM ap;");
|
||||
res = PQexec(conn, buf);
|
||||
id_ap = (PQntuples(res) != 0)? atoi(PQgetvalue(res, PQntuples(res) - 1, 0)) + 1 : 1;
|
||||
|
||||
sprintf(buf, "INSERT INTO ap VALUES('%d','%s', '0', '0', '0', '0', '2417000000', '5', '20');",id_ap, ap_mac_string);
|
||||
|
||||
PQexec(conn, buf);
|
||||
|
||||
}else{
|
||||
id_ap = atoi(PQgetvalue(res, 0, 0));
|
||||
}
|
||||
|
@ -635,13 +644,13 @@ int DbMobile(couple_message message, PGconn *conn)
|
|||
res = PQexec(conn, buf);
|
||||
id_mobile = (PQntuples(res) != 0)? atoi(PQgetvalue(res, PQntuples(res) - 1, 0)) + 1 : 1;
|
||||
|
||||
sprintf(buf, "INSERT INTO mobile(id_mobile, mobile_addr, ip_mobile, last_connect) VALUES('%d','%s','%s','%lld');",id_mobile, mobile_mac_string, mobile_ip_string, timeval_to_ms(message.request_time));
|
||||
sprintf(buf, "INSERT INTO mobile(id_mobile, mobile_addr, ip_mobile, last_connect) VALUES('%d','%s','%s','%llu');",id_mobile, mobile_mac_string, mobile_ip_string, timeval_to_ms(message.request_time));
|
||||
|
||||
PQexec(conn, buf);
|
||||
}else{
|
||||
id_mobile = atoi(PQgetvalue(res, 0, 0));
|
||||
|
||||
sprintf(buf, "UPDATE mobile SET last_connect = %lld, ip_mobile = '%s' WHERE id_mobile = %d;", timeval_to_ms(message.request_time), mobile_ip_string, id_mobile);
|
||||
sprintf(buf, "UPDATE mobile SET last_connect = %llu, ip_mobile = '%s' WHERE id_mobile = %d;", timeval_to_ms(message.request_time), mobile_ip_string, id_mobile);
|
||||
|
||||
PQexec(conn, buf);
|
||||
}
|
||||
|
@ -700,8 +709,8 @@ int DbRequest(couple_message message, PGconn *conn, int id_mobile, int *id_point
|
|||
PGresult *res;
|
||||
|
||||
/** Ajout de la requete si elle n'existe pas **/
|
||||
if(ref) sprintf(buf, "SELECT * FROM ref_request WHERE mobile_time = %lld AND id_mobile = %d;", timeval_to_ms(message.request_time), id_mobile);
|
||||
else sprintf(buf, "SELECT * FROM request WHERE mobile_time = %lld AND id_mobile = %d;", timeval_to_ms(message.request_time), id_mobile);
|
||||
if(ref) sprintf(buf, "SELECT * FROM ref_request WHERE mobile_time = %llu AND id_mobile = %d;", timeval_to_ms(message.request_time), id_mobile);
|
||||
else sprintf(buf, "SELECT * FROM request WHERE mobile_time = %llu AND id_mobile = %d;", timeval_to_ms(message.request_time), id_mobile);
|
||||
|
||||
res = PQexec(conn, buf);
|
||||
if(PQresultStatus(res) != PGRES_TUPLES_OK){
|
||||
|
@ -715,8 +724,8 @@ int DbRequest(couple_message message, PGconn *conn, int id_mobile, int *id_point
|
|||
id_request = (PQntuples(res) != 0)? atoi(PQgetvalue(res, PQntuples(res) - 1, 0)) + 1: 1;
|
||||
if(ref){
|
||||
if((*id_point = DbRefPoint(message, conn)) < 0) return -1;
|
||||
sprintf(buf, "INSERT INTO ref_request(id_ref_request, mobile_time, id_mobile, id_ref_point) VALUES('%d','%lld','%d','%d');", id_request, timeval_to_ms(message.request_time), id_mobile, *id_point);
|
||||
}else sprintf(buf, "INSERT INTO request(id_request, mobile_time, id_mobile) VALUES('%d','%lld','%d');", id_request, timeval_to_ms(message.request_time), id_mobile);
|
||||
sprintf(buf, "INSERT INTO ref_request(id_ref_request, mobile_time, id_mobile, id_ref_point) VALUES('%d','%llu','%d','%d');", id_request, timeval_to_ms(message.request_time), id_mobile, *id_point);
|
||||
}else sprintf(buf, "INSERT INTO request(id_request, mobile_time, id_mobile) VALUES('%d','%llu','%d');", id_request, timeval_to_ms(message.request_time), id_mobile);
|
||||
|
||||
PQexec(conn, buf);
|
||||
}else{
|
||||
|
@ -736,8 +745,8 @@ int DbPacket(couple_message message, PGconn *conn, int id_ap, int id_request, BO
|
|||
char *buf = (char *) malloc(200 * sizeof(char));
|
||||
|
||||
/** Ajout du paquet **/
|
||||
if(ref) sprintf(buf, "INSERT INTO ref_packet(ap_time, power, id_ap, id_ref_request) VALUES('%lld','%d','%d','%d');", timeval_to_ms(message.start_time), message.antenna_signal_dbm - 0x100, id_ap, id_request);
|
||||
else sprintf(buf, "INSERT INTO packet(ap_time, power, id_ap, id_request) VALUES('%lld','%d','%d','%d');", timeval_to_ms(message.start_time), message.antenna_signal_dbm - 0x100, id_ap, id_request);
|
||||
if(ref) sprintf(buf, "INSERT INTO ref_packet(ap_time, power, id_ap, id_ref_request) VALUES('%llu','%d','%d','%d');", timeval_to_ms(message.start_time), message.antenna_signal_dbm - 0x100, id_ap, id_request);
|
||||
else sprintf(buf, "INSERT INTO packet(ap_time, power, id_ap, id_request) VALUES('%llu','%d','%d','%d');", timeval_to_ms(message.start_time), message.antenna_signal_dbm - 0x100, id_ap, id_request);
|
||||
|
||||
PQexec(conn, buf);
|
||||
free(buf);
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
.PHONY : all clean purge install uninstall astyle
|
||||
.PHONY : all clean purge install uninstall style
|
||||
|
||||
# Répertoire d'installation
|
||||
PREFIX = /usr/local
|
||||
INSTALL_DIR = $(PREFIX)/bin
|
||||
|
||||
# Commandes d'installation et de désinstallation
|
||||
RM = rm -fv
|
||||
CP = cp -v
|
||||
|
||||
# Autres outils
|
||||
STYLE = astyle --style=gnu
|
||||
|
||||
GXX = g++
|
||||
DEBUG = -g
|
||||
|
@ -36,11 +47,13 @@ clean:
|
|||
purge : clean
|
||||
@rm -f $(TARGET)
|
||||
|
||||
install :
|
||||
@echo "La cible d'installation de ${TARGET} sera implémentée prochainement. Vous devez lancer le programme 'guinumo' depuis le répertoire des sources."
|
||||
install : $(TARGET)
|
||||
@$(CP) $(TARGET) $(INSTALL_DIR) && \
|
||||
chmod 755 $(INSTALL_DIR)/$(TARGET) && \
|
||||
chown root:root $(INSTALL_DIR)/$(TARGET)
|
||||
|
||||
uninstall :
|
||||
@echo "La cible de désinstallation de ${TARGET} sera implémentée en même temps que la cible d'installation."
|
||||
@$(RM) $(INSTALL_DIR)/$(TARGET)
|
||||
|
||||
astyle :
|
||||
@astyle --style=gnu *.cc *.hh
|
||||
style :
|
||||
@$(STYLE) *.cc *.hh
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "accesspoint.hh"
|
||||
|
||||
|
||||
|
||||
AccessPoint::AccessPoint(const string &addr, const float &fidx, const Point &coords, const unsigned int &f, const float &antg, const float &outp)
|
||||
{
|
||||
coordinates = coords;
|
||||
|
@ -9,10 +10,10 @@ AccessPoint::AccessPoint(const string &addr, const float &fidx, const Point &coo
|
|||
freq = f;
|
||||
antenna_gain = antg;
|
||||
output_power = outp;
|
||||
|
||||
//cout << "coords = " << coords << " ; addr = " << addr << " ; fidx = " << fidx << " ; antg = " << antg << " ; outp = " << outp << endl ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AccessPoint::AccessPoint(const AccessPoint &ap)
|
||||
{
|
||||
coordinates = ap.coordinates;
|
||||
|
@ -23,29 +24,41 @@ AccessPoint::AccessPoint(const AccessPoint &ap)
|
|||
output_power = ap.output_power;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AccessPoint::operator==(const AccessPoint &ap)const
|
||||
{
|
||||
if (ap_addr == ap.ap_addr)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AccessPoint::operator!=(const AccessPoint &ap)const
|
||||
{
|
||||
if (ap_addr != ap.ap_addr)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AccessPoint AccessPoint::operator=(const AccessPoint &ap)
|
||||
{
|
||||
if (this == &ap)
|
||||
return *this;
|
||||
|
||||
ap_addr = ap.ap_addr;
|
||||
friis_index = ap.friis_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ostream &operator<<(ostream &os, const AccessPoint &ap)
|
||||
{
|
||||
os << "MAC Address: " << ap.ap_addr << endl;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "point.hh"
|
||||
|
||||
using namespace std;
|
||||
|
@ -28,6 +29,7 @@ class AccessPoint
|
|||
AccessPoint(const string &addr = AP_DEFAULT_ADDR, const float &fidx = AP_DEFAULT_FRIIS_INDEX, const Point &coords = Point(), const unsigned int &f = AP_DEFAULT_FREQ, const float &antg = AP_DEFAULT_ANTENNA_GAIN, const float &outp = AP_DEFAULT_OUTPUT_POWER);
|
||||
AccessPoint(const AccessPoint &ap);
|
||||
~AccessPoint() {};
|
||||
|
||||
string getApAddr()const
|
||||
{
|
||||
return ap_addr;
|
||||
|
@ -52,6 +54,7 @@ class AccessPoint
|
|||
{
|
||||
return output_power;
|
||||
};
|
||||
|
||||
void setApAddr(const string &addr)
|
||||
{
|
||||
ap_addr = addr;
|
||||
|
@ -81,10 +84,11 @@ class AccessPoint
|
|||
{
|
||||
output_power = outp;
|
||||
};
|
||||
|
||||
bool operator==(const AccessPoint &ap)const;
|
||||
bool operator!=(const AccessPoint &ap)const;
|
||||
AccessPoint operator=(const AccessPoint &ap);
|
||||
friend ostream &operator<<(ostream &os, const AccessPoint &ap);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // _ACCESSPOINT_HH_
|
||||
|
|
|
@ -71,12 +71,13 @@ Area::Area(const Area &a)
|
|||
|
||||
bool Area::containsPoint(const Point &p)const
|
||||
{
|
||||
if ((p.getX() >= x_min)
|
||||
&& (p.getX() <= x_max)
|
||||
&& (p.getY() >= y_min)
|
||||
&& (p.getY() <= y_max)
|
||||
&& (p.getZ() >= z_min)
|
||||
&& (p.getZ() <= z_max))
|
||||
if (p.getX() >= x_min &&
|
||||
p.getX() <= x_max &&
|
||||
p.getY() >= y_min &&
|
||||
p.getY() <= y_max &&
|
||||
p.getZ() >= z_min &&
|
||||
p.getZ() <= z_max
|
||||
)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[Server]
|
||||
port = 9902
|
||||
mobile-port = 9903
|
||||
|
||||
[BDD]
|
||||
name = owlps_db
|
||||
hostaddr = 127.0.0.1
|
||||
user = owlps
|
||||
passwd = owlps
|
|
@ -91,9 +91,8 @@ vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in)
|
|||
return ret;
|
||||
}
|
||||
|
||||
unsigned long timeval_to_ms(const struct timeval *tv)
|
||||
uint64_t timeval_to_ms(const struct timeval &d)
|
||||
{
|
||||
return (tv->tv_sec * 1000) + ((tv->tv_usec + 500) / 1000);
|
||||
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
@ -25,6 +26,13 @@
|
|||
#define DEFAULT_TOPO_FILE "csv/topo.csv"
|
||||
#define DEFAULT_WAYPOINT_FILE "csv/waypoints.csv"
|
||||
|
||||
#define DEFAULT_CONFIG_FILE "owlps-positioning.cfg"
|
||||
|
||||
#define DEFAULT_BDD_HOST "127.0.0.1"
|
||||
#define DEFAULT_BDD_NAME "owlps_db"
|
||||
#define DEFAULT_BDD_USER "owlps"
|
||||
#define DEFAULT_BDD_PASS "owlps"
|
||||
|
||||
#define LIGHT_SPEED 300000000
|
||||
#define MINMAX_STEP 0.5
|
||||
#define MINMAX_X_START 0.5
|
||||
|
@ -52,6 +60,6 @@ using namespace std;
|
|||
float round_float(float f, int n);
|
||||
vector<string> explode(const string &input, const char &sep);
|
||||
vector<string> extractReferencePointInfoFromBuffer(const string &buffer_in);
|
||||
unsigned long timeval_to_ms(const struct timeval *tv);
|
||||
uint64_t timeval_to_ms(const struct timeval &d);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,4 +53,4 @@ class Measurement
|
|||
friend ostream &operator<<(ostream &os, const Measurement &m);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // _MEASUREMENT_HH_
|
||||
|
|
|
@ -8,12 +8,12 @@ int main(int argc, char** argv)
|
|||
po::options_description opt("Aide");
|
||||
po::variables_map vm;
|
||||
|
||||
ifstream ifs("owlps-positioning.cfg");
|
||||
|
||||
string file = DEFAULT_CONFIG_FILE;
|
||||
int port, mport;
|
||||
|
||||
desc.add_options()
|
||||
("help", "\t: Affichage de l'aide")
|
||||
("file-conf,F", po::value<string>(), "\t: Fichier de configuration")
|
||||
("input-topo,T", po::value<string>(), "\t: Input file topology")
|
||||
("input-waypoint,W", po::value<string>(), "\t: Input file waypoint")
|
||||
("input-refpoint,R", po::value<string>(), "\t: Input file reference point")
|
||||
|
@ -30,12 +30,22 @@ int main(int argc, char** argv)
|
|||
;
|
||||
|
||||
opt.add(desc).add(conf);
|
||||
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::store(po::parse_config_file(ifs, conf), vm);
|
||||
po::notify(vm);
|
||||
|
||||
Server server(port, mport);
|
||||
if (vm.count("file-conf"))
|
||||
file = vm["file-conf"].as<string>();
|
||||
|
||||
ifstream ifs(file.c_str());
|
||||
|
||||
if (!ifs.is_open())
|
||||
{
|
||||
cerr << "Erreur lors de la lecture du fichier ! Le fichier n'existe pas ou ne peut être lu.\nUtilisation des valeurs par défaut..." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
po::store(po::parse_config_file(ifs, conf), vm);
|
||||
}
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
|
@ -43,6 +53,8 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Server server(port, mport);
|
||||
|
||||
if (server.init(vm)) return 1;
|
||||
|
||||
server.start();
|
||||
|
|
|
@ -6,9 +6,11 @@ Point Point::operator=(const Point &p)
|
|||
{
|
||||
if (this == &p)
|
||||
return *this;
|
||||
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ class Point
|
|||
z = c[2] ;
|
||||
} ;
|
||||
~Point() {};
|
||||
|
||||
float getX()const
|
||||
{
|
||||
return x;
|
||||
|
@ -45,6 +46,7 @@ class Point
|
|||
{
|
||||
return z;
|
||||
};
|
||||
|
||||
void setX(const float &_x)
|
||||
{
|
||||
x = _x;
|
||||
|
@ -57,6 +59,7 @@ class Point
|
|||
{
|
||||
z = _z;
|
||||
};
|
||||
|
||||
float squareDistance(const Point &p)const
|
||||
{
|
||||
return ((x-p.x)*(x-p.x))+((y-p.y)*(y-p.y))+((z-p.z)*(z-p.z));
|
||||
|
|
|
@ -91,17 +91,13 @@ void ReferencePoint::addMeasurement(const string &mac_a, const int &value)
|
|||
bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const
|
||||
{
|
||||
unsigned int i;
|
||||
string str;
|
||||
string str = ap_mac;
|
||||
string macLowerCase;
|
||||
|
||||
str=ap_mac;
|
||||
|
||||
//Pour convertir les majuscules en miniscules
|
||||
const int length=str.length();
|
||||
const int length = str.length();
|
||||
for (int j=0; j < length; ++j)
|
||||
{
|
||||
str[j] = std::tolower(str[j]);
|
||||
}
|
||||
str[j] = tolower(str[j]);
|
||||
|
||||
for (i = 0 ; i < measurement_list.size() ; i++)
|
||||
if (measurement_list[i].getMacAddr() == str)
|
||||
|
@ -109,6 +105,7 @@ bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const
|
|||
*p = measurement_list[i].getAverage();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -132,7 +129,7 @@ ostream &operator<<(ostream &os, ReferencePoint &rp)
|
|||
|
||||
os << rp.coordinates << endl;
|
||||
if (rp.measurement_list.size() == 0)
|
||||
os << "No measurements" << endl;
|
||||
os << "No measurement" << endl;
|
||||
else
|
||||
for (i = 0 ; i < rp.measurement_list.size() ; i++)
|
||||
os << rp.measurement_list[i] << endl;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "point.hh"
|
||||
#include "measurement.hh"
|
||||
|
||||
|
@ -41,6 +42,7 @@ class ReferencePoint
|
|||
return coordinates;
|
||||
};
|
||||
void addMeasurement(const string &mac_a, const int &value);
|
||||
|
||||
void setCoordinates(const Point &p)
|
||||
{
|
||||
coordinates = p;
|
||||
|
|
|
@ -18,10 +18,30 @@ int Server::init(const boost::program_options::variables_map vm)
|
|||
ostringstream oss;
|
||||
string buf;
|
||||
|
||||
oss << "hostaddr = '" << vm["BDD.hostaddr"].as<string>() << "' ";
|
||||
oss << "dbname = '" << vm["BDD.name"].as<string>() << "' ";
|
||||
oss << "user = '" << vm["BDD.user"].as<string>() << "' ";
|
||||
oss << "password = '"<< vm["BDD.passwd"].as<string>() << "'";
|
||||
oss << "hostaddr = '";
|
||||
if (vm.count("BDD.hostaddr"))
|
||||
oss << vm["BDD.hostaddr"].as<string>();
|
||||
else
|
||||
oss << DEFAULT_BDD_HOST;
|
||||
|
||||
oss << "' dbname = '";
|
||||
if (vm.count("BDD.name"))
|
||||
oss << vm["BDD.name"].as<string>();
|
||||
else
|
||||
oss << DEFAULT_BDD_NAME;
|
||||
|
||||
oss << "' user = '";
|
||||
if (vm.count("BDD.user"))
|
||||
oss << vm["BDD.user"].as<string>();
|
||||
else
|
||||
oss << DEFAULT_BDD_USER;
|
||||
|
||||
oss << "' password = '";
|
||||
if (vm.count("BDD.passwd"))
|
||||
oss << vm["BDD.passwd"].as<string>() << "'";
|
||||
else
|
||||
oss << DEFAULT_BDD_PASS << "'";
|
||||
|
||||
buf = oss.str();
|
||||
|
||||
const char *conninfo = buf.c_str();
|
||||
|
@ -63,6 +83,7 @@ int Server::start()
|
|||
struct sockaddr_in client;
|
||||
socklen_t client_len = sizeof(client);
|
||||
Point solution;
|
||||
char *mac = (char *) malloc(18 * sizeof(char));
|
||||
|
||||
/* Création d'une socket UDP */
|
||||
listen_socket = socket(AF_INET, SOCK_DGRAM, 0) ;
|
||||
|
@ -99,6 +120,14 @@ int Server::start()
|
|||
}
|
||||
|
||||
recv_info.resize(att_request.nb_couples);
|
||||
sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", att_request.mobile_mac_addr_bytes[0],att_request.mobile_mac_addr_bytes[1],
|
||||
att_request.mobile_mac_addr_bytes[2],att_request.mobile_mac_addr_bytes[3],
|
||||
att_request.mobile_mac_addr_bytes[4],att_request.mobile_mac_addr_bytes[5]);
|
||||
|
||||
cout << "\n*** Message reçu de l'aggregator ***" << endl;
|
||||
cout << "\tMAC Mobile\t: " << mac << 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;
|
||||
|
||||
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);
|
||||
|
@ -128,7 +157,7 @@ void Server::treatment()
|
|||
att_request.mobile_mac_addr_bytes[4],att_request.mobile_mac_addr_bytes[5]);
|
||||
|
||||
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.mobile_addr = '" << mac << "';";
|
||||
|
||||
|
@ -191,7 +220,7 @@ void Server::createResult(Point solution, int id_request, string use_algo)
|
|||
if (id_request != 0) oss << ", id_request";
|
||||
oss << ") VALUES('";
|
||||
oss << id_result << "','" << solution.getX() << "','" << solution.getY() << "','" << solution.getZ();
|
||||
oss << "','" << timeval_to_ms(¤t) << "','" << use_algo;
|
||||
oss << "','" << timeval_to_ms(current) << "','" << use_algo;
|
||||
if (id_request != 0) oss << "','" << id_request;
|
||||
oss << "');";
|
||||
|
||||
|
@ -245,6 +274,7 @@ void Server::sendToClient(Point solution, char *mac)
|
|||
sendto(sockfd, (void *)&z, sizeof(float), 0, (struct sockaddr *)&mobile, mobile_len);
|
||||
|
||||
close(sockfd);
|
||||
cout << "Envoi de la position au client " << mac << " à l'adresse IP " << PQgetvalue(res, 0, 0) << endl;
|
||||
}
|
||||
PQclear(res);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[Server]
|
||||
port = 9902
|
||||
mobile-port = 9903
|
||||
|
||||
[BDD]
|
||||
name = owlps_db
|
||||
hostaddr = 127.0.0.1
|
||||
user = owlps
|
||||
passwd = owlps
|
|
@ -0,0 +1,11 @@
|
|||
drop table packet;
|
||||
drop table result;
|
||||
drop table ref_packet;
|
||||
drop table request;
|
||||
drop table ref_request;
|
||||
drop table ref_point;
|
||||
drop table area;
|
||||
drop table waypoint;
|
||||
drop table building;
|
||||
drop table mobile;
|
||||
drop table ap;
|
|
@ -0,0 +1,124 @@
|
|||
-- =====================================
|
||||
-- Nom de la base : owlps_db
|
||||
-- Date de création : 25/06/09
|
||||
-- =====================================
|
||||
|
||||
create table ap
|
||||
(
|
||||
id_ap serial not null unique,
|
||||
ap_addr varchar(20) not null,
|
||||
x float ,
|
||||
y float ,
|
||||
z float ,
|
||||
friis_index float ,
|
||||
freq bigint ,
|
||||
antenna_gain float ,
|
||||
output_power float ,
|
||||
primary key (id_ap, ap_addr)
|
||||
);
|
||||
|
||||
create table mobile
|
||||
(
|
||||
id_mobile serial not null unique,
|
||||
mobile_addr varchar(20) not null,
|
||||
ip_mobile varchar(20) ,
|
||||
antenna_gain float ,
|
||||
last_connect numeric(30) ,
|
||||
primary key (id_mobile, mobile_addr)
|
||||
);
|
||||
|
||||
create table building
|
||||
(
|
||||
id_building serial not null,
|
||||
building_name varchar(50) ,
|
||||
address varchar(100) ,
|
||||
postal_code varchar(10) ,
|
||||
city varchar(20) ,
|
||||
primary key (id_building)
|
||||
);
|
||||
|
||||
|
||||
create table area
|
||||
(
|
||||
id_area serial not null,
|
||||
name_area varchar(40) ,
|
||||
x_min float ,
|
||||
y_min float ,
|
||||
z_min float ,
|
||||
x_max float ,
|
||||
y_max float ,
|
||||
z_max float ,
|
||||
id_building integer references building,
|
||||
primary key (id_area)
|
||||
);
|
||||
|
||||
create table waypoint
|
||||
(
|
||||
x float ,
|
||||
y float ,
|
||||
z float ,
|
||||
id_building integer references building,
|
||||
primary key (x,y,z)
|
||||
);
|
||||
|
||||
|
||||
create table ref_point
|
||||
(
|
||||
id_ref_point serial not null,
|
||||
x float ,
|
||||
y float ,
|
||||
z float ,
|
||||
direction char(1) ,
|
||||
primary key (id_ref_point)
|
||||
);
|
||||
|
||||
create table request
|
||||
(
|
||||
id_request serial not null,
|
||||
mobile_time numeric(30) ,
|
||||
id_mobile integer references mobile(id_mobile),
|
||||
primary key (id_request)
|
||||
);
|
||||
|
||||
create table ref_request
|
||||
(
|
||||
id_ref_request serial not null,
|
||||
mobile_time numeric(30) ,
|
||||
id_mobile integer references mobile(id_mobile),
|
||||
id_ref_point integer references ref_point ON DELETE CASCADE,
|
||||
primary key (id_ref_request)
|
||||
);
|
||||
|
||||
create table packet
|
||||
(
|
||||
id_packet serial not null,
|
||||
ap_time numeric(30) ,
|
||||
power integer ,
|
||||
id_ap integer references ap(id_ap),
|
||||
id_request integer references request,
|
||||
primary key (id_packet)
|
||||
);
|
||||
|
||||
create table ref_packet
|
||||
(
|
||||
id_ref_packet serial not null,
|
||||
ap_time numeric(30) ,
|
||||
power integer ,
|
||||
id_ap integer references ap(id_ap) ,
|
||||
id_ref_request integer references ref_request ON DELETE CASCADE,
|
||||
primary key (id_ref_packet)
|
||||
);
|
||||
|
||||
create table result
|
||||
(
|
||||
id_result serial not null,
|
||||
x float ,
|
||||
y float ,
|
||||
z float ,
|
||||
direction char(1) ,
|
||||
calcul_date numeric(30) ,
|
||||
using_algo varchar(30) ,
|
||||
id_request integer references request,
|
||||
primary key (id_result)
|
||||
);
|
||||
|
|
@ -532,9 +532,12 @@ int main(int argc, char **argv)
|
|||
|
||||
WriteInDb w;
|
||||
|
||||
po::options_description conf("Configuration Positioner");
|
||||
po::options_description desc("Options");
|
||||
po::variables_map vm;
|
||||
|
||||
ifstream ifs("bdd.cfg");
|
||||
|
||||
desc.add_options()
|
||||
("help", "\t: Affichage de l'aide")
|
||||
("input-topo,T", po::value<string>(), "\t: Input file topology")
|
||||
|
@ -542,7 +545,16 @@ int main(int argc, char **argv)
|
|||
("input-refpoint,R", po::value<string>(), "\t: Input file reference point")
|
||||
("input-ap,A", po::value<string>(), "\t: Input file accesspoint")
|
||||
;
|
||||
conf.add_options()
|
||||
("Server.port", po::value<int>() -> default_value(9902), "\t: Port du serveur")
|
||||
("Server.mobile-port", po::value<int>() -> default_value(9903), "\t: Port d'envoi vers le mobile")
|
||||
("BDD.name", po::value<string>(), "\t: Nom de la BdD")
|
||||
("BDD.hostaddr", po::value<string>(), "\t: Adresse de l'hôte de la BdD")
|
||||
("BDD.user", po::value<string>(), "\t: Nom de l'utilisateur de la BdD")
|
||||
("BDD.passwd", po::value<string>(), "\t: Mot de passe de la BdD")
|
||||
;
|
||||
|
||||
po::store(po::parse_config_file(ifs, conf), vm);
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
|
@ -552,7 +564,16 @@ int main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char *conninfo = "hostaddr = '127.0.0.1' dbname = 'owlps_db' user = 'julien' password = '10,mamci'";
|
||||
ostringstream oss;
|
||||
string buf;
|
||||
|
||||
oss << "hostaddr = '" << vm["BDD.hostaddr"].as<string>() << "' ";
|
||||
oss << "dbname = '" << vm["BDD.name"].as<string>() << "' ";
|
||||
oss << "user = '" << vm["BDD.user"].as<string>() << "' ";
|
||||
oss << "password = '"<< vm["BDD.passwd"].as<string>() << "'";
|
||||
buf = oss.str();
|
||||
|
||||
const char *conninfo = buf.c_str();
|
||||
PGconn *conn;
|
||||
|
||||
conn = PQconnectdb(conninfo);
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "../referencepoint.hh"
|
||||
#include "../point.hh"
|
||||
#include "../accesspoint.hh"
|
||||
#include "../area.hh"
|
||||
#include "../measurement.hh"
|
||||
#include "../owlps-positioning/referencepoint.hh"
|
||||
#include "../owlps-positioning/point.hh"
|
||||
#include "../owlps-positioning/accesspoint.hh"
|
||||
#include "../owlps-positioning/area.hh"
|
||||
#include "../owlps-positioning/measurement.hh"
|
||||
|
||||
#include <postgresql/libpq-fe.h>
|
||||
#include <boost/program_options.hpp>
|
||||
|
|
Loading…
Reference in New Issue