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:
parent
f273cba513
commit
f5292a5dd6
|
@ -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
|
||||
|
||||
clean:
|
||||
rm -fv *~
|
||||
rm -fv *.o
|
||||
rm -fv test
|
||||
@rm -fv *~ *.o
|
||||
|
||||
purge : clean
|
||||
@rm -fv test
|
||||
|
|
|
@ -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é.
|
|
@ -1,16 +1,5 @@
|
|||
#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)
|
||||
{
|
||||
|
@ -20,6 +9,8 @@ AccessPoint::AccessPoint(string addr, float fidx, Point coords, unsigned int f,
|
|||
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)
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
using namespace std;
|
||||
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
|
||||
{
|
||||
protected:
|
||||
|
@ -19,8 +25,7 @@ class AccessPoint
|
|||
float output_power;
|
||||
|
||||
public:
|
||||
AccessPoint();
|
||||
AccessPoint(string addr, float fidx, Point coords, unsigned int f, float antg, float outp);
|
||||
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(const AccessPoint &ap);
|
||||
~AccessPoint() {};
|
||||
string getApAddr()const { return ap_addr; };
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
#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)
|
||||
{
|
||||
|
@ -35,7 +25,12 @@ Area::Area(const Area &a)
|
|||
|
||||
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) \
|
||||
&& (p.getX() <= x_max) \
|
||||
&& (p.getY() >= y_min) \
|
||||
&& (p.getY() <= y_max) \
|
||||
&& (p.getZ() >= z_min) \
|
||||
&& (p.getZ() <= z_max))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@ protected:
|
|||
float z_max;
|
||||
|
||||
public:
|
||||
Area();
|
||||
Area(string an, float x1, float x2, float y1, float y2, float z1, float z2);
|
||||
Area(string an = "None", float x1 = 0, float x2 = 0, float y1 = 0, float y2 = 0, float z1 = 0, float z2 = 0);
|
||||
Area(const Area &a);
|
||||
~Area() {};
|
||||
bool containsPoint(Point p)const;
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
#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)
|
||||
{
|
||||
client_ip = ip;
|
||||
antenna_gain = antg;
|
||||
client_listen_port = port;
|
||||
|
||||
for(int i=0 ; i < 5 ; i++)
|
||||
viterbi_distances[i] = 0;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ using namespace std;
|
|||
using std::string;
|
||||
|
||||
#define CLIENT_DEFAULT_PORT 7778
|
||||
#define CLIENT_DEFAULT_IP "127.0.0.1"
|
||||
#define CLIENT_DEFAULT_ANTENNA_GAIN 2 // Good default value
|
||||
|
||||
class ClientInfo
|
||||
{
|
||||
|
@ -17,13 +19,12 @@ protected:
|
|||
string client_ip;
|
||||
float antenna_gain;
|
||||
int client_listen_port;
|
||||
vector<Point> viterbi_vector1; /* Previous vector */
|
||||
vector<Point> viterbi_vector2; /* Last vector */
|
||||
vector<Point> viterbi_vector1; // Previous vector
|
||||
vector<Point> viterbi_vector2; // Last vector
|
||||
float viterbi_distances[5];
|
||||
|
||||
public:
|
||||
ClientInfo();
|
||||
ClientInfo(string ip, int port, float antg);
|
||||
ClientInfo(string ip = CLIENT_DEFAULT_IP, int port = CLIENT_DEFAULT_PORT, float antg = CLIENT_DEFAULT_ANTENNA_GAIN);
|
||||
~ClientInfo();
|
||||
float getAntennaGain()const { return antenna_gain; };
|
||||
};
|
||||
|
|
|
@ -17,8 +17,7 @@ class Measurement
|
|||
vector<int> ss_list;
|
||||
|
||||
public:
|
||||
Measurement() { mac_addr = "ff:ff:ff:ff:ff:ff"; average_ss = 0; };
|
||||
Measurement(string ma, float avg, vector<int> ssl) { mac_addr = ma; average_ss = avg, ss_list = ssl; };
|
||||
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(const Measurement &m) { mac_addr = m.mac_addr; average_ss = m.average_ss; ss_list = m.ss_list; };
|
||||
~Measurement() { ss_list.clear(); };
|
||||
vector<int> getSsList()const { return ss_list; };
|
||||
|
|
|
@ -14,9 +14,8 @@ class Point
|
|||
float z;
|
||||
|
||||
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(float my_x, float my_y, float my_z) { x = my_x; y = my_y; z = my_z; };
|
||||
~Point() {};
|
||||
float getX()const { return x; };
|
||||
float getY()const { return y; };
|
||||
|
|
|
@ -15,9 +15,8 @@ protected:
|
|||
vector<Measurement> measurement_list;
|
||||
|
||||
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(float x, float y, float z) { coordinates.setX(x); coordinates.setY(y); coordinates.setZ(z); };
|
||||
ReferencePoint(Point c) { coordinates = c; };
|
||||
~ReferencePoint() { measurement_list.clear(); };
|
||||
float getSsSquareDistance(vector<Measurement> m)const;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "server.hh"
|
||||
|
||||
/* Misc. very usefull functions */
|
||||
|
||||
/* Explodes a string into substrings based on separator sep. Returns a string vector. */
|
||||
inline vector<string> explode(string input, char sep)
|
||||
{
|
||||
|
@ -141,23 +142,9 @@ inline vector<string> extractReferencePointInfoFromBuffer(string buffer_in)
|
|||
}
|
||||
/* ***************************************************************** */
|
||||
|
||||
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 */
|
||||
sockListen = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
|
@ -201,6 +188,7 @@ bool Server::pointExists(float x, float y, float z)const
|
|||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -213,8 +201,8 @@ unsigned int Server::pointIndex(float x, float y, float z)const
|
|||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
return i;
|
||||
/* Should never happen */
|
||||
return 0;
|
||||
|
||||
return 0; // Should never happen
|
||||
}
|
||||
|
||||
bool Server::pointExists(Point p)const
|
||||
|
@ -224,6 +212,7 @@ bool Server::pointExists(Point p)const
|
|||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -246,8 +235,7 @@ unsigned int Server::apIndex(string ap_addr)const
|
|||
if (access_point_list[i].getApAddr() == ap_addr)
|
||||
return i;
|
||||
|
||||
/* Should never happen */
|
||||
return 0;
|
||||
return 0; // Should never happen
|
||||
}
|
||||
|
||||
/* Do not forget to call pointExists() before this one */
|
||||
|
@ -258,8 +246,8 @@ unsigned int Server::pointIndex(Point p)const
|
|||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
return i;
|
||||
/* Should never happen */
|
||||
return 0;
|
||||
|
||||
return 0; // Should never happen
|
||||
}
|
||||
|
||||
/* return -1 if point does not exist, which should never happen */
|
||||
|
@ -314,6 +302,7 @@ vector<Point> Server::getkClosestInSs(vector<Measurement> m, unsigned int k, boo
|
|||
tmp_min = distances_vector[j];
|
||||
min_idx = j;
|
||||
}
|
||||
|
||||
if (min_idx != i)
|
||||
{
|
||||
/* Swap points */
|
||||
|
@ -523,6 +512,12 @@ void Server::makeReferencePointListFromFile(string filename)
|
|||
vector<string> infos;
|
||||
|
||||
input_file.open(filename.c_str()) ;
|
||||
if (input_file.fail())
|
||||
{
|
||||
cerr << "Error opening input file « " << filename << " » !" << endl ;
|
||||
return ;
|
||||
}
|
||||
|
||||
while (!input_file.eof())
|
||||
{
|
||||
input_file.getline(buffer, BUFFER_LENGTH);
|
||||
|
@ -562,6 +557,12 @@ void Server::makeApListFromFile(string filename)
|
|||
AccessPoint tmp_ap;
|
||||
|
||||
input_file.open(filename.c_str());
|
||||
if (input_file.fail())
|
||||
{
|
||||
cerr << "Error opening input file « " << filename << " » !" << endl ;
|
||||
return ;
|
||||
}
|
||||
|
||||
while (!input_file.eof())
|
||||
{
|
||||
input_file.getline(buffer, BUFFER_LENGTH);
|
||||
|
@ -627,10 +628,8 @@ void Server::computeFriisFromRefList()
|
|||
{
|
||||
pt_coords = reference_point_list[j].getCoordinates();
|
||||
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))));
|
||||
}
|
||||
}
|
||||
/* Now, compute avg value */
|
||||
friis_sum = 0;
|
||||
for (j = 0 ; j < friis_idx_list.size() ; j++)
|
||||
|
@ -641,12 +640,14 @@ void Server::computeFriisFromRefList()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Function computes new cumulative distances for each running viterbi instance,
|
||||
* Returns the solution (type: Point) of the last ended viterbi.
|
||||
* Distances are grouped by line corresponding to an instance.
|
||||
* 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)
|
||||
{
|
||||
unsigned int i, j, k;
|
||||
|
@ -654,7 +655,7 @@ Point Server::viterbiLike(float ** dists, unsigned short vk, unsigned short vn,
|
|||
vector<float> last_dists;
|
||||
Point position;
|
||||
|
||||
/* Compute the ending viterbi: line 0 */
|
||||
// Compute the ending viterbi: line 0
|
||||
for (i = 0 ; i < current.size() ; i++)
|
||||
{
|
||||
min = dists[0][0] + last[0].distance(current[i]);
|
||||
|
@ -664,7 +665,7 @@ Point Server::viterbiLike(float ** dists, unsigned short vk, unsigned short vn,
|
|||
last_dists.push_back(min);
|
||||
}
|
||||
|
||||
/* Find shortest dist */
|
||||
// Find shortest dist
|
||||
min = last_dists[0];
|
||||
j = 0;
|
||||
for (i = 1 ; i < last_dists.size() ; i++)
|
||||
|
@ -674,12 +675,14 @@ Point Server::viterbiLike(float ** dists, unsigned short vk, unsigned short vn,
|
|||
j = i;
|
||||
}
|
||||
|
||||
/* Shortest distance determines the true point */
|
||||
// Shortest distance determines the true point
|
||||
position = current[j];
|
||||
|
||||
/* Now, compute the remaining of the distance matrix */
|
||||
// Now, compute the remaining of the distance matrix
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/* For experimentation purpose only */
|
||||
void Server::radar_exp()
|
||||
|
@ -690,16 +693,22 @@ void Server::radar_exp()
|
|||
unsigned int i;
|
||||
vector<Measurement> vm;
|
||||
|
||||
makeReferencePointListFromFile("complete-scan.csv");
|
||||
makeApListFromFile("accesspoints.cfg");
|
||||
makeReferencePointListFromFile(DEFAULT_REF_POINT_FILE);
|
||||
makeApListFromFile(DEFAULT_AP_FILE);
|
||||
computeFriisFromRefList();
|
||||
|
||||
/* 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 */
|
||||
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;
|
||||
|
||||
cout << reference_point_list.size() << " reference points." << endl ;
|
||||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
{
|
||||
/* Get point measurements */
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
using namespace std;
|
||||
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_LISTEN_PORT 7777
|
||||
#define LIGHT_SPEED 300000000
|
||||
|
@ -45,8 +48,8 @@ protected:
|
|||
int sockSend;
|
||||
|
||||
public:
|
||||
Server();
|
||||
Server(string ip_addr, int listen_port, int send_port);
|
||||
//Server(string ip_addr = DEFAULT_IP, int listen_port = DEFAULT_LISTEN_PORT, int send_port);
|
||||
Server(string ip_addr = DEFAULT_IP, int listen_port = DEFAULT_LISTEN_PORT);
|
||||
~Server();
|
||||
void send_to_client(int cl);
|
||||
int receive_data();
|
||||
|
@ -69,6 +72,8 @@ public:
|
|||
unsigned int getNbReferencePoints()const { return reference_point_list.size(); };
|
||||
/* For experimentation purpose only ! */
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue