147 lines
6.2 KiB
C++
147 lines
6.2 KiB
C++
#ifndef _SERVER_HH_
|
|
#define _SERVER_HH_
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <set>
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <cstring>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
|
|
#include "guinumo.hh"
|
|
#include "clientinfo.hh"
|
|
#include "referencepoint.hh"
|
|
#include "accesspoint.hh"
|
|
#include "point.hh"
|
|
#include "measurement.hh"
|
|
#include "area.hh"
|
|
|
|
using namespace std;
|
|
|
|
typedef ClientInfo::float_array float_array ;
|
|
typedef ClientInfo::float_index float_index ;
|
|
|
|
|
|
#define DEFAULT_LOGFILE "log/radar_exp.csv" // Fichier de sortie
|
|
#define DEFAULT_REF_POINT_FILE "csv/agreg/1m/toutes.csv" // Fichier des points de référence
|
|
#define DEFAULT_REF_POINT_FILE_1M "csv/agreg/1m/toutes.csv" // Fichier contenant tous les points de référence (maillage à 1m)
|
|
#define DEFAULT_AP_FILE "cfg/minipc.cfg" // Fichier de configuration des AP
|
|
#define DEFAULT_TRACKING_FILE "csv/agreg/divagation/divagation9_interpolé.csv" // Fichier de prérégrination
|
|
#define DEFAULT_TOPOLOGY_FILE "cfg/topo.csv"
|
|
#define DEFAULT_WAYPOINT_FILE "cfg/waypoints.csv"
|
|
#define DEFAULT_IP "127.0.0.1"
|
|
#define DEFAULT_LISTEN_PORT 7777
|
|
#define LIGHT_SPEED 300000000
|
|
#define MINMAX_STEP 0.5
|
|
#define MINMAX_X_START 0.5
|
|
#define MINMAX_Y_START 0.5
|
|
#define MINMAX_Z_START 0
|
|
#define MINMAX_X_STOP 10
|
|
#define MINMAX_Y_STOP 31.5
|
|
#define MINMAX_Z_STOP 6
|
|
#define BUFFER_LENGTH 5000
|
|
//#define DEFAULT_Z 3 // Décommenter pour utiliser des fichiers d'entrée avec des coordonnées dans un seul plan (X, Y).
|
|
//#define FRED_CSV_FORMAT // Décommenter pour utiliser les fichiers CSV au « format Fred » (plusieurs lignes par mesure, avec un AP par ligne).
|
|
|
|
typedef enum { ALGO_VLI = 1, ALGO_BASIC_FRBHM, ALGO_CONTINU_FRBHM } ALGORITHM ;
|
|
|
|
|
|
class Server
|
|
{
|
|
public :
|
|
typedef boost::multi_array<float, 2> float_array ; // On utilise boost::multi_array pour les matrices de distances temporaires.
|
|
typedef float_array::index float_index ;
|
|
|
|
protected:
|
|
vector<ClientInfo> client_list ; // Liste des clients connus.
|
|
map<string, Area> area_list ; // Liste des zones homogènes (pièces).
|
|
vector<ReferencePoint> reference_point_list ; // Liste des points de référence (calibration).
|
|
vector<AccessPoint> access_point_list ; // Liste des AP connus.
|
|
float **reference_point_matrix ; // Matrice des distances entre les points de référence.
|
|
vector<Point> waypoint_list ; // Liste des points de passage entre les zones.
|
|
float **waypoint_matrix ; // Matrice des distances entre les points de passage.
|
|
struct sockaddr_in server_addr;
|
|
int sockListen;
|
|
int sockSend;
|
|
|
|
public:
|
|
Server(const string &ap_file = DEFAULT_AP_FILE, const string &ref_pt_file = DEFAULT_REF_POINT_FILE, const string &ip_addr = DEFAULT_IP, const int &listen_port = DEFAULT_LISTEN_PORT);
|
|
~Server();
|
|
|
|
void send_to_client(const int &cl);
|
|
int receive_data();
|
|
|
|
ClientInfo& createClient() ;
|
|
|
|
map<string, Area> inWhichAreas(const Point &p) ;
|
|
bool inTheSameArea(const Point &p1, const Point &p2) ;
|
|
vector<Point> areaConnection(const Area &z1, const Area &z2) ;
|
|
vector<Point> areaConnection(const Area &z) ;
|
|
float distanceTopology(const Point &p1, const Point &p2) ;
|
|
|
|
bool pointExists(const float &x, const float &y, const float &z)const;
|
|
bool pointExists(const Point &p)const;
|
|
bool pointExists(const vector<ReferencePoint> &point_list, const float &x, const float &y, const float &z) const ;
|
|
bool pointExists(const vector<ReferencePoint> &point_list, const Point &p) const ;
|
|
|
|
int pointIndex(const float &x, const float &y, const float &z) const;
|
|
int pointIndex(const Point &p) const;
|
|
int pointIndex(const vector<ReferencePoint> &point_list, const float &x, const float &y, const float &z) const ;
|
|
int pointIndex(const vector<ReferencePoint> &point_list, const Point &p) const ;
|
|
int pointIndex(const Point *tab, unsigned int &size, const Point &p) const ;
|
|
int pointIndex(const vector<Point> &point_list, const Point &p) const ;
|
|
|
|
bool apExists(const string &ap_addr)const;
|
|
unsigned int apIndex(const string &ap_addr)const;
|
|
|
|
vector<Point> getkClosestInSs(const vector<Measurement> &m, const unsigned int &k)const ;
|
|
vector<Point> getkClosestInSs(const vector<Measurement> &m, const unsigned int &k, const Point *point_ignored)const ;
|
|
|
|
Point getkWeightedInSs(const vector<Measurement> &m, const unsigned int &k)const ;
|
|
Point getkWeightedInSs(const vector<Measurement> &m, const unsigned int &k, const Point *point_ignored)const ;
|
|
|
|
Point kPointsAverage(const vector<Point> &vp)const;
|
|
Point fbcm(const vector<Measurement> &m, const int &client_idx)const;
|
|
Point fbcm_friis( const vector<Measurement> &m, const vector<float> friis_idx_list, const float &z)const;
|
|
Point interlink(const vector<Measurement> &m, const int &client_idx)const;
|
|
|
|
void makeReferencePointListFromFile(const string &filename);
|
|
void makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename) ;
|
|
void makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename, const bool uniq_point) ;
|
|
void makeApListFromFile(const string &filename);
|
|
void makeTopologyFromFile(const string &filename) ;
|
|
void makeWaypointListFromFile(const string &filename) ;
|
|
void makeReferencePointDistances() ;
|
|
|
|
bool checkTopology() ;
|
|
|
|
void selectDistances(float_array *matrix, const vector<Point> &l1, const vector<Point> &l2) const ;
|
|
void computeEuclideanDistances(float_array *matrix, const vector<Point> &l1, const vector<Point> &l2) const ;
|
|
void computeTopologyDistances(float_array *matrix, const vector<Point> &l1, const vector<Point> &l2) ;
|
|
|
|
void printReferencePointList() ;
|
|
void printPointList(vector<ReferencePoint> &point_list) ;
|
|
void printAccessPointList() const ;
|
|
|
|
void computeFriisFromRefList();
|
|
vector<float> computeFriisFromRefList(const Point &p, const vector<Measurement> &m);
|
|
|
|
unsigned int getNbReferencePoints()const { return reference_point_list.size(); };
|
|
|
|
void monitorClient(const unsigned int &client_id, const ALGORITHM &algo) ;
|
|
Point fastViterbiLike(const unsigned int &id_client, const float_array &distance_matrix) ;
|
|
|
|
/* For experimentation purpose only ! */
|
|
void radar_exp(const string &outfile = DEFAULT_LOGFILE, const string &testfile = DEFAULT_REF_POINT_FILE_1M);
|
|
};
|
|
|
|
#endif // _SERVER_HH_
|