Beaucoup modifs cosmétiques et ajouts dans GuiNuMo

Partout où cela était possible :
* Indentation "Emacs" du code, aération.
* Utilisation de #define pour les valeurs par défaut.
* Utilisation des valeurs par défaut dans les constructeurs.

server.cc/hh :
* Gestion d'erreur basique pour les ouvertures de fichiers.

Ajout du TODO, d'après celui fait par Fred sous format papier.

Création des répertoires :
* cfg : fichiers de configuration.
* csv : fichiers d'entrée.
* log : fichiers de sortie.

git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@28 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
Matteo Cypriani 2008-04-15 10:19:15 +00:00
parent f273cba513
commit f5292a5dd6
18 changed files with 401 additions and 381 deletions

View File

@ -30,6 +30,7 @@ test: test.o point.o measurement.o accesspoint.o referencepoint.o clientinfo.o s
$(LD) $(LDFLAGS) -o test test.o point.o measurement.o accesspoint.o referencepoint.o clientinfo.o server.o $(LD) $(LDFLAGS) -o test test.o point.o measurement.o accesspoint.o referencepoint.o clientinfo.o server.o
clean: clean:
rm -fv *~ @rm -fv *~ *.o
rm -fv *.o
rm -fv test purge : clean
@rm -fv test

24
GuiNuMo-server/TODO Normal file
View File

@ -0,0 +1,24 @@
* Measurement :
→ RÀS
* Point :
→ RÀS
* ReferencePoint :
→ RÀS pour l'instant.
* ClientInfo : classe qui doit contenir les données des utilisateurs.
- IP,
- Socket,
→ plus tard, pour une vraie démo.
- Historique Viterbi,
→ à faire maintenant.
* Server :
→ Mettre à jour les algos de Viterbi (3 au total).
* Area : déf. des zones & waypoints entre les zones. Une zone = 2 points.
→ Ajouter au serveur la gestion des connexités entre les zones + graphe qui s'étend (cf. avec les points de référence pour l'algo).
→ Faire la fonction qui calcule les matrices étendues en utilisant :
° la matrice de distances entre les points de connexité ;
° les distances euclidiennes entre les points après FBCM et les points de connexité.

View File

@ -1,67 +1,58 @@
#include "accesspoint.hh" #include "accesspoint.hh"
AccessPoint::AccessPoint()
{
coordinates.setX(0);
coordinates.setY(0);
coordinates.setZ(0);
ap_addr = "";
friis_index = 0;
freq = 2412;
antenna_gain = 2; //a good value
output_power = 20; //another good value, eq. to 100mW
}
AccessPoint::AccessPoint(string addr, float fidx, Point coords, unsigned int f, float antg, float outp) AccessPoint::AccessPoint(string addr, float fidx, Point coords, unsigned int f, float antg, float outp)
{ {
coordinates = coords; coordinates = coords;
ap_addr = addr; ap_addr = addr;
friis_index = fidx; friis_index = fidx;
freq = f; freq = f;
antenna_gain = antg; antenna_gain = antg;
output_power = outp; output_power = outp;
//cout << "coords = " << coords << " ; addr = " << addr << " ; fidx = " << fidx << " ; antg = " << antg << " ; outp = " << outp << endl ;
} }
AccessPoint::AccessPoint(const AccessPoint &ap) AccessPoint::AccessPoint(const AccessPoint &ap)
{ {
coordinates = ap.coordinates; coordinates = ap.coordinates;
ap_addr = ap.ap_addr; ap_addr = ap.ap_addr;
friis_index = ap.friis_index; friis_index = ap.friis_index;
freq = ap.freq; freq = ap.freq;
antenna_gain = ap.antenna_gain; antenna_gain = ap.antenna_gain;
output_power = ap.output_power; output_power = ap.output_power;
} }
bool AccessPoint::operator==(const AccessPoint &ap)const bool AccessPoint::operator==(const AccessPoint &ap)const
{ {
if(ap_addr == ap.ap_addr) if(ap_addr == ap.ap_addr)
return true; return true;
return false; return false;
} }
bool AccessPoint::operator!=(const AccessPoint &ap)const bool AccessPoint::operator!=(const AccessPoint &ap)const
{ {
if(ap_addr != ap.ap_addr) if(ap_addr != ap.ap_addr)
return true; return true;
return false; return false;
} }
AccessPoint AccessPoint::operator=(const AccessPoint &ap) AccessPoint AccessPoint::operator=(const AccessPoint &ap)
{ {
if(this == &ap) if(this == &ap)
return *this; return *this;
ap_addr = ap.ap_addr; ap_addr = ap.ap_addr;
friis_index = ap.friis_index; friis_index = ap.friis_index;
return *this; return *this;
} }
ostream &operator<<(ostream & os, AccessPoint & ap) ostream &operator<<(ostream & os, AccessPoint & ap)
{ {
os << "MAC Address: " << ap.ap_addr << endl; os << "MAC Address: " << ap.ap_addr << endl;
os << "Coordinates: " << ap.coordinates << endl; os << "Coordinates: " << ap.coordinates << endl;
os << "Frequency: " << ap.freq << " Hz" << endl; os << "Frequency: " << ap.freq << " Hz" << endl;
os << "Antenna gain: " << ap.antenna_gain << "dBi" << endl; os << "Antenna gain: " << ap.antenna_gain << "dBi" << endl;
os << "Output power: " << ap.output_power << "dBm" << endl; os << "Output power: " << ap.output_power << "dBm" << endl;
return os; return os;
} }

View File

@ -8,38 +8,43 @@
using namespace std; using namespace std;
using std::string; using std::string;
#define AP_DEFAULT_ADDR ""
#define AP_DEFAULT_FRIIS_INDEX 0
#define AP_DEFAULT_FREQ 2412
#define AP_DEFAULT_ANTENNA_GAIN 2 // A good value
#define AP_DEFAULT_OUTPUT_POWER 20 // Another good value, eq. to 100mW
class AccessPoint class AccessPoint
{ {
protected: protected:
Point coordinates; Point coordinates;
string ap_addr; string ap_addr;
float friis_index; float friis_index;
unsigned int freq; unsigned int freq;
float antenna_gain; float antenna_gain;
float output_power; float output_power;
public: public:
AccessPoint(); AccessPoint(string addr = AP_DEFAULT_ADDR, float fidx = AP_DEFAULT_FRIIS_INDEX, Point coords = Point(), unsigned int f = AP_DEFAULT_FREQ, float antg = AP_DEFAULT_ANTENNA_GAIN, float outp = AP_DEFAULT_OUTPUT_POWER);
AccessPoint(string addr, float fidx, Point coords, unsigned int f, float antg, float outp); AccessPoint(const AccessPoint &ap);
AccessPoint(const AccessPoint &ap); ~AccessPoint() {};
~AccessPoint() {}; string getApAddr()const { return ap_addr; };
string getApAddr()const { return ap_addr; }; float getFriisIndex()const { return friis_index; };
float getFriisIndex()const { return friis_index; }; Point getCoordinates()const { return coordinates; };
Point getCoordinates()const { return coordinates; }; float getAntennaGain()const { return antenna_gain; };
float getAntennaGain()const { return antenna_gain; }; unsigned int getFrequency()const { return freq; };
unsigned int getFrequency()const { return freq; }; float getOutputPower()const { return output_power; };
float getOutputPower()const { return output_power; }; void setApAddr(string addr) { ap_addr = addr; };
void setApAddr(string addr) { ap_addr = addr; }; void setFriisIndex(float fidx) { friis_index = fidx; };
void setFriisIndex(float fidx) { friis_index = fidx; }; void setCoordinates(Point apc) { coordinates = apc; };
void setCoordinates(Point apc) { coordinates = apc; }; void setCoordinates(float x, float y, float z) { Point apc(x, y, z); coordinates = apc; };
void setCoordinates(float x, float y, float z) { Point apc(x, y, z); coordinates = apc; }; void setFrequency(unsigned int f) { freq = f; };
void setFrequency(unsigned int f) { freq = f; }; void setAntennaGain(float antg) { antenna_gain = antg; };
void setAntennaGain(float antg) { antenna_gain = antg; }; void setOutputPower(float outp) {output_power = outp; };
void setOutputPower(float outp) {output_power = outp; }; bool operator==(const AccessPoint &ap)const;
bool operator==(const AccessPoint &ap)const; bool operator!=(const AccessPoint &ap)const;
bool operator!=(const AccessPoint &ap)const; AccessPoint operator=(const AccessPoint &ap);
AccessPoint operator=(const AccessPoint &ap); friend ostream &operator<<(ostream & os, AccessPoint & ap);
friend ostream &operator<<(ostream & os, AccessPoint & ap);
}; };
#endif #endif

View File

@ -1,41 +1,36 @@
#include "area.hh" #include "area.hh"
Area::Area()
{
area_name = "None";
x_min = 0;
x_max = 0;
y_min = 0;
y_max = 0;
z_min = 0;
z_max = 0;
}
Area::Area(string an, float x1, float x2, float y1, float y2, float z1, float z2) Area::Area(string an, float x1, float x2, float y1, float y2, float z1, float z2)
{ {
area_name = an; area_name = an;
x_min = x1; x_min = x1;
x_max = x2; x_max = x2;
y_min = y1; y_min = y1;
y_max = y2; y_max = y2;
z_min = z1; z_min = z1;
z_max = z2; z_max = z2;
} }
Area::Area(const Area &a) Area::Area(const Area &a)
{ {
area_name = a.area_name; area_name = a.area_name;
x_min = a.x_min; x_min = a.x_min;
x_max = a.x_max; x_max = a.x_max;
y_min = a.y_min; y_min = a.y_min;
y_max = a.y_max; y_max = a.y_max;
z_min = a.z_min; z_min = a.z_min;
z_max = a.z_max; z_max = a.z_max;
} }
bool Area::containsPoint(Point p)const bool Area::containsPoint(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) \
return true; && (p.getX() <= x_max) \
return false; && (p.getY() >= y_min) \
&& (p.getY() <= y_max) \
&& (p.getZ() >= z_min) \
&& (p.getZ() <= z_max))
return true;
return false;
} }

View File

@ -10,34 +10,33 @@ using std::string;
class Area class Area
{ {
protected: protected:
string area_name; string area_name;
float x_min; float x_min;
float x_max; float x_max;
float y_min; float y_min;
float y_max; float y_max;
float z_min; float z_min;
float z_max; float z_max;
public: public:
Area(); Area(string an = "None", float x1 = 0, float x2 = 0, float y1 = 0, float y2 = 0, float z1 = 0, float z2 = 0);
Area(string an, float x1, float x2, float y1, float y2, float z1, float z2); Area(const Area &a);
Area(const Area &a); ~Area() {};
~Area() {}; bool containsPoint(Point p)const;
bool containsPoint(Point p)const; string getLabel()const { return label; };
string getLabel()const { return label; }; float getXmin()const { return x_min; };
float getXmin()const { return x_min; }; float getXmax()const { return x_max; };
float getXmax()const { return x_max; }; float getYmin()const { return y_min; };
float getYmin()const { return y_min; }; float getYmax()const { return y_max; };
float getYmax()const { return y_max; }; float getZmin()const { return z_min; };
float getZmin()const { return z_min; }; float getZmax()const { return z_max; };
float getZmax()const { return z_max; }; void setLabel(string l) { label = l; };
void setLabel(string l) { label = l; }; void setXmin(float v) { x_min = v; };
void setXmin(float v) { x_min = v; }; void setXmax(float v) { x_max = v; };
void setXmax(float v) { x_max = v; }; void setYmin(float v) { y_min = v; };
void setYmin(float v) { y_min = v; }; void setYmax(float v) { y_max = v; };
void setYmax(float v) { y_max = v; }; void setZmin(float v) { z_min = v; };
void setZmin(float v) { z_min = v; }; void setZmax(float v) { z_max = v; };
void setZmax(float v) { z_max = v; };
}; };
#endif #endif

View File

@ -1,20 +1,13 @@
#include "clientinfo.hh" #include "clientinfo.hh"
ClientInfo::ClientInfo()
{
client_ip = "127.0.0.1";
antenna_gain = 2; //good default value
client_listen_port = CLIENT_DEFAULT_PORT;
for(int i=0;i<5;i++)
viterbi_distances[i] = 0;
}
ClientInfo::ClientInfo(string ip, int port, float antg) ClientInfo::ClientInfo(string ip, int port, float antg)
{ {
client_ip = ip; client_ip = ip;
antenna_gain = antg; antenna_gain = antg;
client_listen_port = port; client_listen_port = port;
for(int i=0;i<5;i++)
for(int i=0 ; i < 5 ; i++)
viterbi_distances[i] = 0; viterbi_distances[i] = 0;
} }

View File

@ -10,6 +10,8 @@ using namespace std;
using std::string; using std::string;
#define CLIENT_DEFAULT_PORT 7778 #define CLIENT_DEFAULT_PORT 7778
#define CLIENT_DEFAULT_IP "127.0.0.1"
#define CLIENT_DEFAULT_ANTENNA_GAIN 2 // Good default value
class ClientInfo class ClientInfo
{ {
@ -17,13 +19,12 @@ protected:
string client_ip; string client_ip;
float antenna_gain; float antenna_gain;
int client_listen_port; int client_listen_port;
vector<Point> viterbi_vector1; /* Previous vector */ vector<Point> viterbi_vector1; // Previous vector
vector<Point> viterbi_vector2; /* Last vector */ vector<Point> viterbi_vector2; // Last vector
float viterbi_distances[5]; float viterbi_distances[5];
public: public:
ClientInfo(); ClientInfo(string ip = CLIENT_DEFAULT_IP, int port = CLIENT_DEFAULT_PORT, float antg = CLIENT_DEFAULT_ANTENNA_GAIN);
ClientInfo(string ip, int port, float antg);
~ClientInfo(); ~ClientInfo();
float getAntennaGain()const { return antenna_gain; }; float getAntennaGain()const { return antenna_gain; };
}; };

View File

@ -2,32 +2,32 @@
void Measurement::addSsValue(int ssv) void Measurement::addSsValue(int ssv)
{ {
float ss_mwatts = pow(10, (float) ssv / 10.0) + (ss_list.size() * pow(10, average_ss / 10.0)); float ss_mwatts = pow(10, (float) ssv / 10.0) + (ss_list.size() * pow(10, average_ss / 10.0));
ss_list.push_back(ssv); ss_list.push_back(ssv);
average_ss = 10 * log10(ss_mwatts / ss_list.size()); average_ss = 10 * log10(ss_mwatts / ss_list.size());
} }
float Measurement::getSsSquareDistance(float ss)const float Measurement::getSsSquareDistance(float ss)const
{ {
return ((ss - average_ss) * (ss - average_ss)); return ((ss - average_ss) * (ss - average_ss));
} }
ostream &operator<<(ostream &os, Measurement &m) ostream &operator<<(ostream &os, Measurement &m)
{ {
unsigned int i; unsigned int i;
os << m.mac_addr << "->"; os << m.mac_addr << "->";
if(m.ss_list.size() == 0) if (m.ss_list.size() == 0)
os << "No values"; os << "No values";
else else
for(i=0;i<m.ss_list.size();i++) for (i = 0 ; i < m.ss_list.size() ; i++)
{ {
os << m.ss_list[i]; os << m.ss_list[i];
if(i < m.ss_list.size() - 1) if(i < m.ss_list.size() - 1)
os << ";"; os << ";";
} }
os << " [AVG=" << m.average_ss << "]"; os << " [AVG=" << m.average_ss << "]";
return os; return os;
} }

View File

@ -11,23 +11,22 @@ using std::string;
class Measurement class Measurement
{ {
protected: protected:
string mac_addr; string mac_addr;
float average_ss; float average_ss;
vector<int> ss_list; vector<int> ss_list;
public: public:
Measurement() { mac_addr = "ff:ff:ff:ff:ff:ff"; average_ss = 0; }; Measurement(string ma = "ff:ff:ff:ff:ff:ff", float avg = 0, vector<int> ssl = vector<int>()) { mac_addr = ma; average_ss = avg, ss_list = ssl; };
Measurement(string ma, float avg, vector<int> ssl) { mac_addr = ma; average_ss = avg, ss_list = ssl; }; Measurement(const Measurement &m) { mac_addr = m.mac_addr; average_ss = m.average_ss; ss_list = m.ss_list; };
Measurement(const Measurement &m) { mac_addr = m.mac_addr; average_ss = m.average_ss; ss_list = m.ss_list; }; ~Measurement() { ss_list.clear(); };
~Measurement() { ss_list.clear(); }; vector<int> getSsList()const { return ss_list; };
vector<int> getSsList()const { return ss_list; }; float getAverage()const { return average_ss; };
float getAverage()const { return average_ss; }; string getMacAddr()const { return mac_addr; };
string getMacAddr()const { return mac_addr; }; void addSsValue(int ssv);
void addSsValue(int ssv); void setMacAddr(string ma) { mac_addr = ma; };
void setMacAddr(string ma) { mac_addr = ma; }; float getSsSquareDistance(float ss)const;
float getSsSquareDistance(float ss)const; friend ostream &operator<<(ostream &os, Measurement &m);
friend ostream &operator<<(ostream &os, Measurement &m);
}; };
#endif #endif

View File

@ -2,30 +2,30 @@
Point Point::operator=(const Point &p) Point Point::operator=(const Point &p)
{ {
if(this == &p) if(this == &p)
return *this; return *this;
x = p.x; x = p.x;
y = p.y; y = p.y;
z = p.z; z = p.z;
return *this; return *this;
} }
bool Point::operator==(const Point &p)const bool Point::operator==(const Point &p)const
{ {
if((x == p.x)&&(y == p.y)&&(z == p.z)) if((x == p.x) && (y == p.y) && (z == p.z))
return true; return true;
return false; return false;
} }
bool Point::operator!=(const Point &p)const bool Point::operator!=(const Point &p)const
{ {
if((x == p.x)&&(y == p.y)&&(z == p.z)) if((x == p.x) && (y == p.y) && (z == p.z))
return false; return false;
return true; return true;
} }
ostream &operator<<(ostream &os, const Point &p) ostream &operator<<(ostream &os, const Point &p)
{ {
os << "(" << p.x << ";" << p.y << ";" << p.z << ")"; os << "(" << p.x << ";" << p.y << ";" << p.z << ")";
return os; return os;
} }

View File

@ -8,29 +8,28 @@ using namespace std;
class Point class Point
{ {
protected: protected:
float x; float x;
float y; float y;
float z; float z;
public: public:
Point() { x = 0; y = 0; z = 0; }; Point(float _x = 0, float _y = 0, float _z = 0) { x = _x; y = _y; z = _z; } ;
Point(const Point &p) { x = p.x; y = p.y; z = p.z; } ; Point(const Point &p) { x = p.x; y = p.y; z = p.z; } ;
Point(float my_x, float my_y, float my_z) { x = my_x; y = my_y; z = my_z; }; ~Point() {};
~Point() {}; float getX()const { return x; };
float getX()const { return x; }; float getY()const { return y; };
float getY()const { return y; }; float getZ()const { return z; };
float getZ()const { return z; }; void setX(float my_x) { x = my_x; };
void setX(float my_x) { x = my_x; }; void setY(float my_y) { y = my_y; };
void setY(float my_y) { y = my_y; }; void setZ(float my_z) { z = my_z; };
void setZ(float my_z) { z = my_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)); };
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)); }; float squareDistance(float mx, float my, float mz)const { return ((x-mx)*(x-mx))+((y-my)*(y-my))+((z-mz)*(z-mz)); };
float squareDistance(float mx, float my, float mz)const { return ((x-mx)*(x-mx))+((y-my)*(y-my))+((z-mz)*(z-mz)); }; float distance(const Point &p)const { return sqrt(((x-p.x)*(x-p.x))+((y-p.y)*(y-p.y))+((z-p.z)*(z-p.z))); };
float distance(const Point &p)const { return sqrt(((x-p.x)*(x-p.x))+((y-p.y)*(y-p.y))+((z-p.z)*(z-p.z))); }; Point operator=(const Point &p);
Point operator=(const Point &p); bool operator==(const Point &p)const;
bool operator==(const Point &p)const; bool operator!=(const Point &p)const;
bool operator!=(const Point &p)const; friend ostream &operator<<(ostream & os, const Point &p);
friend ostream &operator<<(ostream & os, const Point &p);
}; };
#endif #endif

View File

@ -15,9 +15,8 @@ protected:
vector<Measurement> measurement_list; vector<Measurement> measurement_list;
public: public:
ReferencePoint() { coordinates.setX(0); coordinates.setY(0); coordinates.setZ(0); }; ReferencePoint(float x = 0, float y = 0, float z = 0) { coordinates.setX(x); coordinates.setY(y); coordinates.setZ(z); };
ReferencePoint(const ReferencePoint &rp) { coordinates = rp.coordinates; measurement_list = rp.measurement_list; }; ReferencePoint(const ReferencePoint &rp) { coordinates = rp.coordinates; measurement_list = rp.measurement_list; };
ReferencePoint(float x, float y, float z) { coordinates.setX(x); coordinates.setY(y); coordinates.setZ(z); };
ReferencePoint(Point c) { coordinates = c; }; ReferencePoint(Point c) { coordinates = c; };
~ReferencePoint() { measurement_list.clear(); }; ~ReferencePoint() { measurement_list.clear(); };
float getSsSquareDistance(vector<Measurement> m)const; float getSsSquareDistance(vector<Measurement> m)const;

View File

@ -1,15 +1,16 @@
#include "server.hh" #include "server.hh"
/* Misc. very usefull functions */ /* Misc. very usefull functions */
/* Explodes a string into substrings based on separator sep. Returns a string vector. */ /* Explodes a string into substrings based on separator sep. Returns a string vector. */
inline vector<string> explode(string input, char sep) inline vector<string> explode(string input, char sep)
{ {
vector<string> vs; vector<string> vs;
string tmp; string tmp;
unsigned int i; unsigned int i;
for(i=0;i<input.size();i++) for (i = 0 ; i < input.size() ; i++)
if(input[i] == sep) if (input[i] == sep)
{ {
vs.push_back(tmp); vs.push_back(tmp);
tmp.clear(); tmp.clear();
@ -18,11 +19,11 @@ inline vector<string> explode(string input, char sep)
{ {
tmp.push_back(input[i]); tmp.push_back(input[i]);
} }
//Last entry, did not encounter a separator. //Last entry, did not encounter a separator.
vs.push_back(tmp); vs.push_back(tmp);
tmp.clear(); tmp.clear();
return vs; return vs;
} }
@ -30,9 +31,9 @@ inline vector<string> explode(string input, char sep)
inline int string2int(string nb) inline int string2int(string nb)
{ {
istringstream iss(nb); istringstream iss(nb);
int tmp; int tmp;
iss>>tmp; iss >> tmp;
return tmp; return tmp;
} }
@ -40,9 +41,9 @@ inline int string2int(string nb)
inline unsigned int string2uint(string nb) inline unsigned int string2uint(string nb)
{ {
istringstream iss(nb); istringstream iss(nb);
unsigned int tmp; unsigned int tmp;
iss>>tmp; iss >> tmp;
return tmp; return tmp;
} }
@ -50,9 +51,9 @@ inline unsigned int string2uint(string nb)
inline float string2float(string nb) inline float string2float(string nb)
{ {
istringstream iss(nb); istringstream iss(nb);
float tmp; float tmp;
iss>>tmp; iss >> tmp;
return tmp; return tmp;
} }
@ -62,13 +63,13 @@ inline vector<int> extractValues(string buff)
unsigned int ptr = 0; unsigned int ptr = 0;
vector<int> ret; vector<int> ret;
string tmp_field; string tmp_field;
if(buff[buff.size()-1] != ';') if (buff[buff.size()-1] != ';')
buff.push_back(';'); buff.push_back(';');
while(ptr < buff.size()) while (ptr < buff.size())
{ {
if(buff[ptr] != ';') if (buff[ptr] != ';')
tmp_field.push_back(buff[ptr]); tmp_field.push_back(buff[ptr]);
else else
{ {
@ -85,10 +86,10 @@ inline vector<string> extractReferencePointInfoFromBuffer(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 */ /* Extract coordinates */
/* x */ /* x */
while(buffer_in[i] != ';') while (buffer_in[i] != ';')
{ {
tmp_field.push_back(buffer_in[i]); tmp_field.push_back(buffer_in[i]);
i++; i++;
@ -96,9 +97,9 @@ inline vector<string> extractReferencePointInfoFromBuffer(string buffer_in)
ret.push_back(tmp_field); ret.push_back(tmp_field);
tmp_field.clear(); tmp_field.clear();
i++; //go after the ';' i++; //go after the ';'
/* y */ /* y */
while(buffer_in[i] != ';') while (buffer_in[i] != ';')
{ {
tmp_field.push_back(buffer_in[i]); tmp_field.push_back(buffer_in[i]);
i++; i++;
@ -106,9 +107,9 @@ inline vector<string> extractReferencePointInfoFromBuffer(string buffer_in)
ret.push_back(tmp_field); ret.push_back(tmp_field);
tmp_field.clear(); tmp_field.clear();
i++; i++;
/* Extract direction (not used now) */ /* 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]);
i++; i++;
@ -116,9 +117,9 @@ inline vector<string> extractReferencePointInfoFromBuffer(string buffer_in)
ret.push_back(tmp_field); ret.push_back(tmp_field);
tmp_field.clear(); tmp_field.clear();
i++; i++;
/* Extract mac address */ /* Extract mac address */
while(buffer_in[i] != ';') while (buffer_in[i] != ';')
{ {
tmp_field.push_back(buffer_in[i]); tmp_field.push_back(buffer_in[i]);
i++; i++;
@ -126,49 +127,35 @@ inline vector<string> extractReferencePointInfoFromBuffer(string buffer_in)
ret.push_back(tmp_field); ret.push_back(tmp_field);
tmp_field.clear(); tmp_field.clear();
i++; i++;
/* Extract scan list */ /* Extract scan list */
while(i < buffer_in.size()) while (i < buffer_in.size())
{ {
tmp_field.push_back(buffer_in[i]); tmp_field.push_back(buffer_in[i]);
i++; i++;
} }
ret.push_back(tmp_field); ret.push_back(tmp_field);
tmp_field.clear(); tmp_field.clear();
/* Return the vector with each data */ /* Return the vector with each data */
return ret; return ret;
} }
/* ***************************************************************** */ /* ***************************************************************** */
Server::Server()
{
/* Open socket */
sockListen = socket(PF_INET, SOCK_DGRAM, 0);
sockSend = socket(PF_INET, SOCK_DGRAM, 0);
/* Set addr */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(DEFAULT_LISTEN_PORT);
server_addr.sin_addr.s_addr = inet_addr(DEFAULT_IP);
memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));
/* Bind */
bind(sockListen, (struct sockaddr *)&server_addr, sizeof(server_addr));
}
Server::Server(string ip_addr, int listen_port, int send_port) //Server::Server(string ip_addr, int listen_port, int send_port) // FIXME : paramètre send_port inutilisé
Server::Server(string ip_addr, int listen_port)
{ {
/* Open socket */ /* Open socket */
sockListen = socket(PF_INET, SOCK_DGRAM, 0); sockListen = socket(PF_INET, SOCK_DGRAM, 0);
sockSend = socket(PF_INET, SOCK_DGRAM, 0); sockSend = socket(PF_INET, SOCK_DGRAM, 0);
/* Set addr */ /* Set addr */
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(listen_port); server_addr.sin_port = htons(listen_port);
server_addr.sin_addr.s_addr = inet_addr(ip_addr.c_str()); server_addr.sin_addr.s_addr = inet_addr(ip_addr.c_str());
memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero)); memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));
/* Bind */ /* Bind */
bind(sockListen, (struct sockaddr *)&server_addr, sizeof(server_addr)); bind(sockListen, (struct sockaddr *)&server_addr, sizeof(server_addr));
} }
@ -197,10 +184,11 @@ bool Server::pointExists(float x, float y, float z)const
{ {
Point p(x, y, z); Point p(x, y, z);
unsigned int i; unsigned int i;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
if(p == reference_point_list[i].getCoordinates()) if (p == reference_point_list[i].getCoordinates())
return true; return true;
return false; return false;
} }
@ -209,57 +197,57 @@ unsigned int Server::pointIndex(float x, float y, float z)const
{ {
Point p(x, y, z); Point p(x, y, z);
unsigned int i; unsigned int i;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
if(p == reference_point_list[i].getCoordinates()) if (p == reference_point_list[i].getCoordinates())
return i; return i;
/* Should never happen */
return 0; return 0; // Should never happen
} }
bool Server::pointExists(Point p)const bool Server::pointExists(Point p)const
{ {
unsigned int i; unsigned int i;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
if(p == reference_point_list[i].getCoordinates()) if (p == reference_point_list[i].getCoordinates())
return true; return true;
return false; return false;
} }
bool Server::apExists(string ap_addr)const bool Server::apExists(string ap_addr)const
{ {
unsigned int i; unsigned int i;
for(i=0;i<access_point_list.size();i++) for (i = 0 ; i < access_point_list.size() ; i++)
if(access_point_list[i].getApAddr() == ap_addr) if (access_point_list[i].getApAddr() == ap_addr)
return true; return true;
return false; return false;
} }
unsigned int Server::apIndex(string ap_addr)const unsigned int Server::apIndex(string ap_addr)const
{ {
unsigned int i; unsigned int i;
for(i=0;i<access_point_list.size();i++) for (i = 0 ; i < access_point_list.size() ; i++)
if(access_point_list[i].getApAddr() == ap_addr) if (access_point_list[i].getApAddr() == ap_addr)
return i; return i;
/* Should never happen */ return 0; // Should never happen
return 0;
} }
/* Do not forget to call pointExists() before this one */ /* Do not forget to call pointExists() before this one */
unsigned int Server::pointIndex(Point p)const unsigned int Server::pointIndex(Point p)const
{ {
unsigned int i; unsigned int i;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
if(p == reference_point_list[i].getCoordinates()) if (p == reference_point_list[i].getCoordinates())
return i; return i;
/* Should never happen */
return 0; return 0; // Should never happen
} }
/* return -1 if point does not exist, which should never happen */ /* return -1 if point does not exist, which should never happen */
@ -270,9 +258,9 @@ vector<Point> Server::getkClosestInSs(vector<Measurement> m, unsigned int k, boo
vector<Point> points_vector; vector<Point> points_vector;
Point tmp_pt; Point tmp_pt;
float tmp_distance = 0, dist_max = 10000000, tmp_min; float tmp_distance = 0, dist_max = 10000000, tmp_min;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
if(!ignore_point||(reference_point_list[i].getCoordinates() != point_ignored)) if (!ignore_point||(reference_point_list[i].getCoordinates() != point_ignored))
{ {
tmp_distance = reference_point_list[i].getSsSquareDistance(m); tmp_distance = reference_point_list[i].getSsSquareDistance(m);
/* if not k points, add it */ /* if not k points, add it */
@ -288,8 +276,8 @@ vector<Point> Server::getkClosestInSs(vector<Measurement> m, unsigned int k, boo
if(dist_max > tmp_distance) if(dist_max > tmp_distance)
{ {
/* remove old max */ /* remove old max */
for(j=0;j<distances_vector.size();j++) for (j = 0 ; j < distances_vector.size() ; j++)
if(distances_vector[j] == dist_max) if (distances_vector[j] == dist_max)
{ {
dist_max = tmp_distance; dist_max = tmp_distance;
distances_vector.erase(distances_vector.begin() + j); distances_vector.erase(distances_vector.begin() + j);
@ -302,31 +290,32 @@ vector<Point> Server::getkClosestInSs(vector<Measurement> m, unsigned int k, boo
/* Else nothing needs to be done */ /* Else nothing needs to be done */
} }
} }
/* Sorts the vector */ /* Sorts the vector */
for(i=0;i<distances_vector.size()-1;i++) for (i = 0 ; i < distances_vector.size() - 1 ; i++)
{ {
tmp_min = distances_vector[i]; tmp_min = distances_vector[i];
min_idx = i; min_idx = i;
for(j=i+1;j<distances_vector.size();j++) for (j = i+1 ; j < distances_vector.size() ; j++)
if(tmp_min > distances_vector[j]) if (tmp_min > distances_vector[j])
{ {
tmp_min = distances_vector[j]; tmp_min = distances_vector[j];
min_idx = j; min_idx = j;
} }
if(min_idx != i)
if (min_idx != i)
{ {
/* Swap points */ /* Swap points */
tmp_pt = points_vector[i]; tmp_pt = points_vector[i];
points_vector[i] = points_vector[min_idx]; points_vector[i] = points_vector[min_idx];
points_vector[min_idx] = tmp_pt; points_vector[min_idx] = tmp_pt;
/* Swap distances */ /* Swap distances */
distances_vector[min_idx] = distances_vector[i]; distances_vector[min_idx] = distances_vector[i];
distances_vector[i] = tmp_min; distances_vector[i] = tmp_min;
} }
} }
return points_vector; return points_vector;
} }
@ -338,25 +327,25 @@ Point Server::getkWeightedInSs(vector<Measurement> m, unsigned int k, bool ignor
float tmp_distance = 0, dist_max = 10000000; float tmp_distance = 0, dist_max = 10000000;
Point ret; Point ret;
float total = 0, x = 0, y = 0, z = 0; float total = 0, x = 0, y = 0, z = 0;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
if(!ignore_point||(reference_point_list[i].getCoordinates() != point_ignored)) if (!ignore_point || (reference_point_list[i].getCoordinates() != point_ignored))
{ {
tmp_distance = reference_point_list[i].getSsSquareDistance(m); tmp_distance = reference_point_list[i].getSsSquareDistance(m);
/* if not k points, add it */ /* if not k points, add it */
if(distances_vector.size() < k) if (distances_vector.size() < k)
{ {
distances_vector.push_back(tmp_distance); distances_vector.push_back(tmp_distance);
points_vector.push_back(reference_point_list[i].getCoordinates()); points_vector.push_back(reference_point_list[i].getCoordinates());
dist_max = (dist_max > tmp_distance)?tmp_distance:dist_max; dist_max = (dist_max > tmp_distance) ? tmp_distance : dist_max;
} }
else else
{ {
/* if tmp_dst < dist_max, should add it and remove previous greatest dist. */ /* if tmp_dst < dist_max, should add it and remove previous greatest dist. */
if(dist_max > tmp_distance) if (dist_max > tmp_distance)
{ {
/* remove old max */ /* remove old max */
for(j=0;j<distances_vector.size();j++) for (j = 0 ; j < distances_vector.size() ; j++)
if(distances_vector[j] == dist_max) if(distances_vector[j] == dist_max)
{ {
dist_max = tmp_distance; dist_max = tmp_distance;
@ -370,20 +359,20 @@ Point Server::getkWeightedInSs(vector<Measurement> m, unsigned int k, bool ignor
/* Else nothing needs to be done */ /* Else nothing needs to be done */
} }
} }
for(i=0;i<distances_vector.size();i++) for (i = 0 ; i < distances_vector.size() ; i++)
total += distances_vector[i]; total += distances_vector[i];
for(i=0;i<distances_vector.size();i++) for (i = 0 ; i < distances_vector.size() ; i++)
{ {
x += points_vector[i].getX() * distances_vector[i] / total; x += points_vector[i].getX() * distances_vector[i] / total;
y += points_vector[i].getY() * distances_vector[i] / total; y += points_vector[i].getY() * distances_vector[i] / total;
z += points_vector[i].getZ() * distances_vector[i] / total; z += points_vector[i].getZ() * distances_vector[i] / total;
} }
ret.setX(x); ret.setX(x);
ret.setY(y); ret.setY(y);
ret.setZ(z); ret.setZ(z);
return ret; return ret;
} }
@ -392,8 +381,8 @@ Point Server::kPointsAverage(vector<Point> vp)const
unsigned int i; unsigned int i;
float x=0, y=0, z=0; float x=0, y=0, z=0;
Point p; Point p;
for(i=0;i<vp.size();i++) for (i = 0 ; i < vp.size() ; i++)
{ {
x += vp[i].getX(); x += vp[i].getX();
y += vp[i].getY(); y += vp[i].getY();
@ -402,7 +391,7 @@ Point Server::kPointsAverage(vector<Point> vp)const
p.setX(x / (float) vp.size()); p.setX(x / (float) vp.size());
p.setY(y / (float) vp.size()); p.setY(y / (float) vp.size());
p.setZ(z / (float) vp.size()); p.setZ(z / (float) vp.size());
return p; return p;
} }
@ -415,47 +404,47 @@ Point Server::fbcm(vector<Measurement> m, int client_idx)const
unsigned int i, ap_idx; unsigned int i, ap_idx;
float constant_term, minmax_res, minmax_max; float constant_term, minmax_res, minmax_max;
float x = MINMAX_X_START, y = MINMAX_Y_START; float x = MINMAX_X_START, y = MINMAX_Y_START;
i = 0; i = 0;
//cout << "FBCM: "; //cout << "FBCM: ";
for(i=0;i<m.size();i++) for (i = 0 ; i < m.size() ; i++)
if(apExists(m[i].getMacAddr())) if (apExists(m[i].getMacAddr()))
{ {
ap_idx = apIndex(m[i].getMacAddr()); ap_idx = apIndex(m[i].getMacAddr());
//cout << "AP idx: " << ap_idx << " "; //cout << "AP idx: " << ap_idx << " ";
centres.push_back(access_point_list[ap_idx].getCoordinates()); centres.push_back(access_point_list[ap_idx].getCoordinates());
addr.push_back(m[i].getMacAddr()); addr.push_back(m[i].getMacAddr());
constant_term = access_point_list[ap_idx].getOutputPower() + access_point_list[ap_idx].getAntennaGain() + 2; constant_term = access_point_list[ap_idx].getOutputPower() + access_point_list[ap_idx].getAntennaGain() + 2;
constant_term += 20 * log10((300000000.0/(float) access_point_list[ap_idx].getFrequency())/(4*M_PI)); constant_term += 20 * log10((300000000.0 / (float) access_point_list[ap_idx].getFrequency()) / (4*M_PI));
//end of expr. should be: client_list[client_idx].getAntennaGain() instead of 2. //end of expr. should be: client_list[client_idx].getAntennaGain() instead of 2.
//cout << "20log(" << (300000000.0/(float) access_point_list[ap_idx].getFrequency())/(4*M_PI) << ") = "; //cout << "20log(" << (300000000.0 / (float) access_point_list[ap_idx].getFrequency()) / (4*M_PI) << ") = ";
//cout << constant_term << " "; //cout << constant_term << " ";
dist_vect.push_back(pow(10, (constant_term - m[i].getAverage()) / (10 * access_point_list[ap_idx].getFriisIndex()))); dist_vect.push_back(pow(10, (constant_term - m[i].getAverage()) / (10 * access_point_list[ap_idx].getFriisIndex())));
//cout << endl; //cout << endl;
} }
/* Then: min-max */ /* Then: min-max */
minmax_res = 1000000; minmax_res = 1000000;
for(x=MINMAX_X_START;x<MINMAX_X_STOP;x+=MINMAX_STEP) for (x = MINMAX_X_START ; x < MINMAX_X_STOP ; x += MINMAX_STEP)
for(y=MINMAX_Y_START;y<MINMAX_Y_STOP;y+=MINMAX_STEP) for (y = MINMAX_Y_START ; y < MINMAX_Y_STOP ; y += MINMAX_STEP)
{ {
minmax_max = 0; minmax_max = 0;
for(i=0;i<centres.size();i++) for (i = 0 ; i < centres.size() ; i++)
if((centres[i].squareDistance(x, y, 3) - (dist_vect[i]*dist_vect[i])) > minmax_max) if ((centres[i].squareDistance(x, y, 3) - (dist_vect[i]*dist_vect[i])) > minmax_max)
minmax_max = centres[i].squareDistance(x, y, 3) - (dist_vect[i]*dist_vect[i]); minmax_max = centres[i].squareDistance(x, y, 3) - (dist_vect[i] * dist_vect[i]);
if(minmax_max < minmax_res) if (minmax_max < minmax_res)
{ {
ret.setX(x); ret.setX(x);
ret.setY(y); ret.setY(y);
minmax_res = minmax_max; minmax_res = minmax_max;
} }
} }
/* Clear all vectors */ /* Clear all vectors */
addr.clear(); addr.clear();
dist_vect.clear(); dist_vect.clear();
centres.clear(); centres.clear();
/* Return position */ /* Return position */
return ret; return ret;
} }
@ -469,42 +458,42 @@ Point Server::interlink(vector<Measurement> m, int client_idx)const
unsigned int i, ap_idx; unsigned int i, ap_idx;
float constant_term, minmax_res, minmax_max; float constant_term, minmax_res, minmax_max;
float x = MINMAX_X_START, y = MINMAX_Y_START; float x = MINMAX_X_START, y = MINMAX_Y_START;
i = 0; i = 0;
for(i=0;i<m.size();i++) for (i = 0 ; i < m.size() ; i++)
if(apExists(m[i].getMacAddr())) if (apExists(m[i].getMacAddr()))
{ {
ap_idx = apIndex(m[i].getMacAddr()); ap_idx = apIndex(m[i].getMacAddr());
centres.push_back(access_point_list[ap_idx].getCoordinates()); centres.push_back(access_point_list[ap_idx].getCoordinates());
addr.push_back(m[i].getMacAddr()); addr.push_back(m[i].getMacAddr());
constant_term = access_point_list[ap_idx].getOutputPower() + access_point_list[ap_idx].getAntennaGain(); constant_term = access_point_list[ap_idx].getOutputPower() + access_point_list[ap_idx].getAntennaGain();
constant_term += 20 * log10((300000000.0/(float) access_point_list[ap_idx].getFrequency())/(4*M_PI)) + 2; constant_term += 20 * log10((300000000.0 / (float) access_point_list[ap_idx].getFrequency()) / (4*M_PI)) + 2;
//end of expr. should be: client_list[client_idx].getAntennaGain() instead of 2. //end of expr. should be: client_list[client_idx].getAntennaGain() instead of 2.
dist_vect.push_back(pow(10, (constant_term - m[i].getAverage()) / 35)); dist_vect.push_back(pow(10, (constant_term - m[i].getAverage()) / 35));
} }
/* Then: min-max */ /* Then: min-max */
minmax_res = 1000000; minmax_res = 1000000;
for(x=MINMAX_X_START;x<MINMAX_X_STOP;x+=MINMAX_STEP) for (x = MINMAX_X_START ; x < MINMAX_X_STOP ; x += MINMAX_STEP)
for(y=MINMAX_Y_START;y<MINMAX_Y_STOP;y+=MINMAX_STEP) for (y = MINMAX_Y_START ; y < MINMAX_Y_STOP ; y += MINMAX_STEP)
{ {
minmax_max = 0; minmax_max = 0;
for(i=0;i<centres.size();i++) for (i = 0 ; i < centres.size() ; i++)
if((centres[i].squareDistance(x, y, 3) - (dist_vect[i]*dist_vect[i])) > minmax_max) if ((centres[i].squareDistance(x, y, 3) - (dist_vect[i] * dist_vect[i])) > minmax_max)
minmax_max = centres[i].squareDistance(x, y, 3) - (dist_vect[i]*dist_vect[i]); minmax_max = centres[i].squareDistance(x, y, 3) - (dist_vect[i] * dist_vect[i]) ;
if(minmax_max < minmax_res) if (minmax_max < minmax_res)
{ {
ret.setX(x); ret.setX(x);
ret.setY(y); ret.setY(y);
minmax_res = minmax_max; minmax_res = minmax_max;
} }
} }
/* Clear all vectors */ /* Clear all vectors */
addr.clear(); addr.clear();
dist_vect.clear(); dist_vect.clear();
centres.clear(); centres.clear();
/* Return position */ /* Return position */
return ret; return ret;
} }
@ -521,12 +510,18 @@ void Server::makeReferencePointListFromFile(string filename)
string cpp_buffer, tmp_mes; string cpp_buffer, tmp_mes;
vector<int> measures_vector; vector<int> measures_vector;
vector<string> infos; vector<string> infos;
input_file.open(filename.c_str()); input_file.open(filename.c_str()) ;
while(!input_file.eof()) if (input_file.fail())
{
cerr << "Error opening input file « " << filename << " » !" << endl ;
return ;
}
while (!input_file.eof())
{ {
input_file.getline(buffer, BUFFER_LENGTH); input_file.getline(buffer, BUFFER_LENGTH);
if ((input_file.rdstate() & ifstream::eofbit ) == 0 ) if ((input_file.rdstate() & ifstream::eofbit) == 0)
{ {
/* Extract fields */ /* Extract fields */
cpp_buffer = buffer; cpp_buffer = buffer;
@ -538,18 +533,18 @@ void Server::makeReferencePointListFromFile(string filename)
tmp_point.setY(y); tmp_point.setY(y);
tmp_point.setZ(DEFAULT_Z); tmp_point.setZ(DEFAULT_Z);
/* Use C++ string format */ /* Use C++ string format */
if(!pointExists(tmp_point)) if (!pointExists(tmp_point))
{ {
rp.setCoordinates(tmp_point); rp.setCoordinates(tmp_point);
reference_point_list.push_back(rp); reference_point_list.push_back(rp);
} }
pt_idx = pointIndex(tmp_point); pt_idx = pointIndex(tmp_point);
measures_vector = extractValues(infos[4]); measures_vector = extractValues(infos[4]);
for(i=0;i<measures_vector.size();i++) for (i = 0 ; i < measures_vector.size() ; i++)
reference_point_list[pt_idx].addMeasurement(infos[3], measures_vector[i]); reference_point_list[pt_idx].addMeasurement(infos[3], measures_vector[i]);
} }
} }
input_file.close(); input_file.close();
measures_vector.clear(); measures_vector.clear();
} }
@ -560,16 +555,22 @@ void Server::makeApListFromFile(string filename)
char buffer[BUFFER_LENGTH]; char buffer[BUFFER_LENGTH];
vector<string> ap_infos; vector<string> ap_infos;
AccessPoint tmp_ap; AccessPoint tmp_ap;
input_file.open(filename.c_str()); input_file.open(filename.c_str());
while(!input_file.eof()) if (input_file.fail())
{
cerr << "Error opening input file « " << filename << " » !" << endl ;
return ;
}
while (!input_file.eof())
{ {
input_file.getline(buffer, BUFFER_LENGTH); input_file.getline(buffer, BUFFER_LENGTH);
if ((input_file.rdstate() & ifstream::eofbit ) == 0 ) if ((input_file.rdstate() & ifstream::eofbit) == 0)
{ {
ap_infos = explode(buffer, ';'); ap_infos = explode(buffer, ';');
cout << buffer << endl; cout << buffer << endl;
for(unsigned int i=0;i<ap_infos.size();i++) for (unsigned int i=0 ; i < ap_infos.size() ; i++)
cout << ap_infos[i] << endl; cout << ap_infos[i] << endl;
tmp_ap.setApAddr(ap_infos[0]); tmp_ap.setApAddr(ap_infos[0]);
tmp_ap.setCoordinates(string2float(ap_infos[1]), string2float(ap_infos[2]), string2float(ap_infos[3])); tmp_ap.setCoordinates(string2float(ap_infos[1]), string2float(ap_infos[2]), string2float(ap_infos[3]));
@ -580,23 +581,23 @@ void Server::makeApListFromFile(string filename)
ap_infos.clear(); ap_infos.clear();
} }
} }
input_file.close(); input_file.close();
} }
void Server::printReferencePointList() void Server::printReferencePointList()
{ {
unsigned int i; unsigned int i;
for(i=0;i<reference_point_list.size();i++) for (i = 0 ; i < reference_point_list.size() ; i++)
cout << reference_point_list[i] << endl; cout << reference_point_list[i] << endl;
} }
void Server::printAccessPointList() void Server::printAccessPointList()
{ {
unsigned int i; unsigned int i;
for(i=0;i<access_point_list.size();i++) for (i = 0 ; i < access_point_list.size() ; i++)
cout << access_point_list[i] << endl; cout << access_point_list[i] << endl;
} }
@ -608,8 +609,8 @@ void Server::computeFriisFromRefList()
float ap_power, ap_gain, calib_gain = 2, const_term, mes_power, friis_sum; float ap_power, ap_gain, calib_gain = 2, const_term, mes_power, friis_sum;
unsigned int ap_freq; unsigned int ap_freq;
string ap_mac; string ap_mac;
for(i=0;i<access_point_list.size();i++) for (i = 0 ; i < access_point_list.size() ; i++)
{ {
ap_power = access_point_list[i].getOutputPower(); ap_power = access_point_list[i].getOutputPower();
ap_coords = access_point_list[i].getCoordinates(); ap_coords = access_point_list[i].getCoordinates();
@ -623,17 +624,15 @@ void Server::computeFriisFromRefList()
const_term += 20 * log10 (300000000.0 / ap_freq) + ap_power; const_term += 20 * log10 (300000000.0 / ap_freq) + ap_power;
/* Compute an index for each ref point. List stored in friis_idx_list */ /* Compute an index for each ref point. List stored in friis_idx_list */
for(j=0;j<reference_point_list.size();j++) for (j = 0 ; j < reference_point_list.size() ; j++)
{ {
pt_coords = reference_point_list[j].getCoordinates(); pt_coords = reference_point_list[j].getCoordinates();
if(reference_point_list[i].getPowerForAp(ap_mac, &mes_power)) if (reference_point_list[i].getPowerForAp(ap_mac, &mes_power))
{ friis_idx_list.push_back((const_term - mes_power) / (10 * log10(ap_coords.distance(pt_coords))));
friis_idx_list.push_back((const_term - mes_power) / (10 * log10(ap_coords.distance(pt_coords))));
}
} }
/* Now, compute avg value */ /* Now, compute avg value */
friis_sum = 0; friis_sum = 0;
for(j=0;j<friis_idx_list.size();j++) for (j = 0 ; j < friis_idx_list.size() ; j++)
friis_sum += friis_idx_list[j]; friis_sum += friis_idx_list[j];
access_point_list[i].setFriisIndex(friis_sum / friis_idx_list.size()); access_point_list[i].setFriisIndex(friis_sum / friis_idx_list.size());
cout << access_point_list[i].getApAddr() << " -> " << (friis_sum / friis_idx_list.size()) << endl; cout << access_point_list[i].getApAddr() << " -> " << (friis_sum / friis_idx_list.size()) << endl;
@ -641,45 +640,49 @@ void Server::computeFriisFromRefList()
} }
} }
/* /*
* Function computes new cumulative distances for each running viterbi instance, * Function computes new cumulative distances for each running viterbi instance,
* Returns the solution (type: Point) of the last ended viterbi. * Returns the solution (type: Point) of the last ended viterbi.
* Distances are grouped by line corresponding to an instance. * Distances are grouped by line corresponding to an instance.
* vk MUST be the same as last.size() and current.size() ! * vk MUST be the same as last.size() and current.size() !
*/ */
/*
Point Server::viterbiLike(float ** dists, unsigned short vk, unsigned short vn, vector<Point> last, vector<Point> current) Point Server::viterbiLike(float ** dists, unsigned short vk, unsigned short vn, vector<Point> last, vector<Point> current)
{ {
unsigned int i, j, k; unsigned int i, j, k;
float min; float min;
vector<float> last_dists; vector<float> last_dists;
Point position; Point position;
/* Compute the ending viterbi: line 0 */ // Compute the ending viterbi: line 0
for(i=0;i<current.size();i++) for (i = 0 ; i < current.size() ; i++)
{ {
min = dists[0][0] + last[0].distance(current[i]); min = dists[0][0] + last[0].distance(current[i]);
for(j=1;j<last.size();j++) for (j = 1 ; j < last.size() ; j++)
if((dists[0][j] + last[j].distance(current[i])) < min) if ((dists[0][j] + last[j].distance(current[i])) < min)
min = dists[0][j] + last[j].distance(current[i]); min = dists[0][j] + last[j].distance(current[i]);
last_dists.push_back(min); last_dists.push_back(min);
} }
/* Find shortest dist */ // Find shortest dist
min = last_dists[0]; min = last_dists[0];
j = 0; j = 0;
for(i=1;i<last_dists.size();i++) for (i = 1 ; i < last_dists.size() ; i++)
if(last_dists[i] < min) if (last_dists[i] < min)
{ {
min = last_dists[i]; min = last_dists[i];
j = i; j = i;
} }
/* Shortest distance determines the true point */ // Shortest distance determines the true point
position = current[j]; position = current[j];
/* Now, compute the remaining of the distance matrix */ // Now, compute the remaining of the distance matrix
} }
*/
/* For experimentation purpose only */ /* For experimentation purpose only */
void Server::radar_exp() void Server::radar_exp()
@ -690,17 +693,23 @@ void Server::radar_exp()
unsigned int i; unsigned int i;
vector<Measurement> vm; vector<Measurement> vm;
makeReferencePointListFromFile("complete-scan.csv"); makeReferencePointListFromFile(DEFAULT_REF_POINT_FILE);
makeApListFromFile("accesspoints.cfg"); makeApListFromFile(DEFAULT_AP_FILE);
computeFriisFromRefList(); computeFriisFromRefList();
/* Open a log file */ /* Open a log file */
logfile.open("radar_exp.csv"); logfile.open(DEFAULT_LOGFILE);
if (logfile.fail())
{
cerr << "Error opening output file « " << logfile << " » !" << endl ;
return ;
}
/* Column names */ /* Column names */
logfile << "Coordinates\t2-kss\t(Error)\t3-kss\t(Error)\t4-kss\t(Error)\t5-kss\t(Error)\tnss\t(Error)\tInterlink\t(Error)\tFBCM\t(Error)" << endl; logfile << "Coordinates\t2-kss\t(Error)\t3-kss\t(Error)\t4-kss\t(Error)\t5-kss\t(Error)\tnss\t(Error)\tInterlink\t(Error)\tFBCM\t(Error)" << endl;
for(i=0;i<reference_point_list.size();i++) cout << reference_point_list.size() << " reference points." << endl ;
for (i = 0 ; i < reference_point_list.size() ; i++)
{ {
/* Get point measurements */ /* Get point measurements */
vm.clear(); vm.clear();
@ -719,7 +728,7 @@ void Server::radar_exp()
logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; logfile << solution << "\t" << solution.distance(ref_coords) << "\t";
solution = getkWeightedInSs(vm, 5, true, ref_coords); solution = getkWeightedInSs(vm, 5, true, ref_coords);
logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; logfile << solution << "\t" << solution.distance(ref_coords) << "\t";
/* Nearest in SS */ /* Nearest in SS */
solutions = getkClosestInSs(vm, 1, true, ref_coords); solutions = getkClosestInSs(vm, 1, true, ref_coords);
logfile << solutions[0] << "\t" << solutions[0].distance(ref_coords) << "\t"; logfile << solutions[0] << "\t" << solutions[0].distance(ref_coords) << "\t";

View File

@ -22,6 +22,9 @@
using namespace std; using namespace std;
using std::string; using std::string;
#define DEFAULT_LOGFILE "log/radar_exp.csv"
#define DEFAULT_REF_POINT_FILE "csv/complete-scan.csv"
#define DEFAULT_AP_FILE "cfg/accesspoints.cfg"
#define DEFAULT_IP "127.0.0.1" #define DEFAULT_IP "127.0.0.1"
#define DEFAULT_LISTEN_PORT 7777 #define DEFAULT_LISTEN_PORT 7777
#define LIGHT_SPEED 300000000 #define LIGHT_SPEED 300000000
@ -43,10 +46,10 @@ protected:
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
int sockListen; int sockListen;
int sockSend; int sockSend;
public: public:
Server(); //Server(string ip_addr = DEFAULT_IP, int listen_port = DEFAULT_LISTEN_PORT, int send_port);
Server(string ip_addr, int listen_port, int send_port); Server(string ip_addr = DEFAULT_IP, int listen_port = DEFAULT_LISTEN_PORT);
~Server(); ~Server();
void send_to_client(int cl); void send_to_client(int cl);
int receive_data(); int receive_data();
@ -69,6 +72,8 @@ public:
unsigned int getNbReferencePoints()const { return reference_point_list.size(); }; unsigned int getNbReferencePoints()const { return reference_point_list.size(); };
/* For experimentation purpose only ! */ /* For experimentation purpose only ! */
void radar_exp(); void radar_exp();
/* For compilation purpose :-) */
// Point viterbiLike(float**, short unsigned int, short unsigned int, std::vector<Point, std::allocator<Point> >, std::vector<Point, std::allocator<Point> >) ;
}; };
#endif #endif

View File

@ -18,8 +18,8 @@ int main(int argc, char ** argv)
ofstream output_file; ofstream output_file;
string read_file; string read_file;
Server my_server; Server my_server;
my_server.radar_exp(); my_server.radar_exp();
return 0; return 0;
} }