[Positioning] Work on AccessPoint and Measurement

Modification of AccessPoint and Measurement to fit the class diagram.
Adding class PosUtil, for static utilitary functions (will be the
successor of the false library libowlps-positioning).
This commit is contained in:
Matteo Cypriani 2009-12-11 13:52:21 +01:00
parent 85cca4debd
commit 1808acd870
10 changed files with 389 additions and 172 deletions

1
owlps-positioning/TODO Normal file
View File

@ -0,0 +1 @@
- AccessPoint : attribut float friis_index ?

View File

@ -2,70 +2,164 @@
AccessPoint::AccessPoint(const string &addr, const float &fidx, const Point &coords, const unsigned int &f, const float &antg, const float &outp)
{
coordinates = coords;
ap_addr = addr;
friis_index = fidx;
freq = f;
antenna_gain = antg;
output_power = outp;
}
/*** Constructeurs ***/
AccessPoint::AccessPoint(const Point3D &_coordinates,
const string &_ip_addr,
const string &_mac_addr,
const unsigned int &_frequency,
const float &_antenna_gain,
const float &_trx_power)
{
coordinates = _coordinates ;
ip_addr = _ip_addr ;
mac_addr = _mac_addr ;
frequency = _frequency ;
antenna_gain = PosUtil::channel_to_frequency(_antenna_gain) ;
trx_power = _trx_power ;
}
AccessPoint::AccessPoint(const AccessPoint &ap)
{
coordinates = ap.coordinates;
ap_addr = ap.ap_addr;
friis_index = ap.friis_index;
freq = ap.freq;
antenna_gain = ap.antenna_gain;
output_power = ap.output_power;
coordinates = ap.coordinates ;
ip_addr = ap.ip_addr ;
mac_addr = ap.mac_addr ;
frequency = ap.frequency ;
antenna_gain = ap.antenna_gain ;
trx_power = ap.trx_power ;
}
bool AccessPoint::operator==(const AccessPoint &ap)const
/*** Accesseurs lecture ***/
Point3D AccessPoint::get_coordinates() const
{
if (ap_addr == ap.ap_addr)
return true;
return false;
return coordinates ;
}
bool AccessPoint::operator!=(const AccessPoint &ap)const
string AccessPoint::get_ip_addr() const
{
if (ap_addr != ap.ap_addr)
return true;
return false;
return ip_addr ;
}
string AccessPoint::get_mac_addr() const
{
return mac_addr ;
}
unsigned int AccessPoint::get_frequency() const
{
return frequency ;
}
float AccessPoint::get_antenna_gain() const
{
return antenna_gain ;
}
float AccessPoint::get_trx_power() const
{
return trx_power ;
}
/*** Accesseurs écriture ***/
void AccessPoint::set_coordinates(Point3D &_coordinates)
{
coordinates = _coordinates ;
}
void AccessPoint::set_ip_addr(const string &_ip_addr)
{
ip_addr = _ip_addr ;
}
void AccessPoint::set_mac_addr(const string &_mac_addr)
{
mac_addr = _mac_addr ;
}
void AccessPoint::set_frequency(unsigned int &_frequency)
{
frequency = _frequency ;
}
void AccessPoint::set_antenna_gain(float &_antenna_gain)
{
antenna_gain = PosUtil::channel_to_frequency(_antenna_gain) ;
}
void AccessPoint::set_trx_power(float &_trx_power)
{
trx_power = _trx_power ;
}
/*** Opérateurs ***/
bool AccessPoint::operator==(const AccessPoint &ap) const
{
return
coordinates == ap.coordinates &&
ip_addr == ap.ip_addr &&
mac_addr == ap.mac_addr &&
frequency == ap.frequency &&
antenna_gain == ap.antenna_gain &&
trx_power == ap.trx_power ;
}
bool AccessPoint::operator!=(const AccessPoint &ap) const
{
return !(*this == ap) ;
}
AccessPoint AccessPoint::operator=(const AccessPoint &ap)
{
if (this == &ap)
return *this;
return *this ;
ap_addr = ap.ap_addr;
friis_index = ap.friis_index;
coordinates = ap.coordinates ;
ip_addr = ap.ip_addr ;
mac_addr = ap.mac_addr ;
frequency = ap.frequency ;
antenna_gain = ap.antenna_gain ;
trx_power = ap.trx_power ;
return *this;
return *this ;
}
ostream &operator<<(ostream &os, const AccessPoint &ap)
{
os << "MAC Address: " << ap.ap_addr << endl;
os << "Coordinates: " << ap.coordinates << endl;
os << "Frequency: " << ap.freq << " Hz" << endl;
os << "Antenna gain: " << ap.antenna_gain << "dBi" << endl;
os << "Output power: " << ap.output_power << "dBm" << endl;
os
<< "Coordinates: " << ap.coordinates << endl
<< "IP address: " << ap.ip_addr << endl
<< "MAC address: " << ap.mac_addr << endl
<< "Frequency: " << ap.frequency << " Hz" << endl
<< "Antenna gain: " << ap.antenna_gain << "dBi" << endl
<< "Output power: " << ap.trx_power << "dBm" ;
return os;
return os ;
}

View File

@ -1,94 +1,57 @@
#ifndef _ACCESSPOINT_HH_
#define _ACCESSPOINT_HH_
#ifndef _OWLPS_POSITIONING_ACCESSPOINT_HH_
#define _OWLPS_POSITIONING_ACCESSPOINT_HH_
#include "point3d.hh"
#include "posutil.hh"
#include <iostream>
#include <string>
#include "point.hh"
using namespace std ;
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
#define AP_DEFAULT_CHANNEL 6
#define AP_DEFAULT_ANTENNA_GAIN 2
#define AP_DEFAULT_TRX_POWER 20 // 20 dBm = 100 mW
class AccessPoint
{
protected:
Point coordinates;
string ap_addr;
float friis_index;
unsigned int freq;
float antenna_gain;
float output_power;
Point3D coordinates ;
string ip_addr ;
string mac_addr ;
unsigned int frequency ; // Frequency (channel) in Hz
float antenna_gain ; // Antenna gain in dBi
float trx_power ; // Transmit power in dBm
public:
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() {};
AccessPoint(const Point3D &_coordinates,
const string &_ip_addr,
const string &_mac_addr,
const unsigned int &_frequency = AP_DEFAULT_CHANNEL,
const float &_antenna_gain = AP_DEFAULT_ANTENNA_GAIN,
const float &_trx_power = AP_DEFAULT_TRX_POWER) ;
AccessPoint(const AccessPoint &ap) ;
string getApAddr()const
{
return ap_addr;
};
float getFriisIndex()const
{
return friis_index;
};
Point getCoordinates()const
{
return coordinates;
};
float getAntennaGain()const
{
return antenna_gain;
};
unsigned int getFrequency()const
{
return freq;
};
float getOutputPower()const
{
return output_power;
};
~AccessPoint() {}
void setApAddr(const string &addr)
{
ap_addr = addr;
};
void setFriisIndex(const float &fidx)
{
friis_index = fidx;
};
void setCoordinates(const Point &apc)
{
coordinates = apc;
};
void setCoordinates(const float &x, const float &y, const float &z)
{
Point apc(x, y, z);
coordinates = apc;
};
void setFrequency(const unsigned int &f)
{
freq = f;
};
void setAntennaGain(const float &antg)
{
antenna_gain = antg;
};
void setOutputPower(const float &outp)
{
output_power = outp;
};
Point3D get_coordinates(void) const ;
string get_ip_addr(void) const ;
string get_mac_addr(void) const ;
unsigned int get_frequency(void) const ;
float get_antenna_gain(void) const ;
float get_trx_power(void) const ;
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);
};
void set_coordinates(Point3D &_coordinates) ;
void set_ip_addr(const string &_ip_addr) ;
void set_mac_addr(const string &_mac_addr) ;
void set_frequency(unsigned int &_frequency) ;
void set_antenna_gain(float &_antenna_gain) ;
void set_trx_power(float &_trx_power) ;
#endif // _ACCESSPOINT_HH_
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 // _OWLPS_POSITIONING_ACCESSPOINT_HH_

View File

@ -26,7 +26,7 @@ public:
const float &_x2 = 0, const float &_y2 = 0, const float &_z2 = 0) ;
Area(const Area &a) ;
~Area() {} ;
~Area() {}
Building* get_building(void) const ;
string get_name(void) const ;

View File

@ -1,18 +1,106 @@
#include "measurement.hh"
void Measurement::addSsValue(const int &ssv)
{
float ss_mwatts = pow(10, (float) ssv / 10.0) + (ss_list.size() * pow(10, average_ss / 10.0));
ss_list.push_back(ssv);
average_ss = 10 * log10(ss_mwatts / ss_list.size());
/*** Constructeurs ***/
Measurement::Measurement(const string &_mac_addr, const vector<int> &_ss_list)
{
mac_addr = _mac_addr ;
ss_list = ssl ;
update_average_ss() ;
}
float Measurement::getSsSquareDistance(const float &ss)const
Measurement::Measurement(const Measurement &m)
{
return ((ss - average_ss) * (ss - average_ss));
mac_addr = m.mac_addr ;
ss_list = m.ss_list ;
average_ss = m.average_ss ;
}
Measurement::~Measurement()
{
ss_list.clear() ;
}
/*** Accesseurs lecture ***/
string Measurement::get_mobile_mac_addr() const
{
return mobile_mac_addr ;
}
string Measurement::get_ap_mac_addr() const
{
return ap_mac_addr ;
}
vector<int> Measurement::get_ss_list() const
{
return ss_list ;
}
float Measurement::get_average_ss() const
{
return average_ss ;
}
/*
float Measurement::get_ss_square_distance(const float &ss) const
{
return ((ss - average_ss) * (ss - average_ss)) ;
}
*/
/*** Accesseurs écriture ***/
void Measurement::update_average_ss()
{
average_ss = 0 ;
for (int i=0 ; i < ss_list ; i++)
{
float ss_mw =
pow(10, (float) ss_list[i] / 10.0) +
(ss_list.size() * pow(10, average_ss / 10.0)) ;
average_ss = 10 * log10(ss_mwatts / ss_list.size()) ;
}
}
void Measurement::set_mac_addr(const string &_mac_addr)
{
mac_addr = _mac_addr ;
}
void Measurement::add_ss(const int &ss)
{
float ss_mwatts =
pow(10, (float) ss / 10.0) +
(ss_list.size() * pow(10, average_ss / 10.0)) ;
ss_list.push_back(ss) ;
average_ss = 10 * log10(ss_mwatts / ss_list.size()) ;
}
/*** Opérateurs ***/
ostream &operator<<(ostream &os, const Measurement &m)
{
unsigned int i;

View File

@ -1,56 +1,43 @@
#ifndef _MEASUREMENT_HH_
#define _MEASUREMENT_HH_
#ifndef _OWLPS_POSITIONING_MEASUREMENT_HH_
#define _OWLPS_POSITIONING_MEASUREMENT_HH_
#include "mobile.hh"
#include "accesspoint.hh"
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
using std::string;
using namespace std ;
class Measurement
{
protected:
string mac_addr;
float average_ss;
vector<int> ss_list;
Mobile *mobile ;
AccessPoint *ap ;
float average_ss ;
vector<int> ss_list ;
void update_average_ss(void) ;
public:
Measurement(const string &ma = "ff:ff:ff:ff:ff:ff", const float &avg = 0, const 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;
};
float getAverage()const
{
return average_ss;
};
string getMacAddr()const
{
return mac_addr;
};
void addSsValue(const int &ssv);
void setMacAddr(const string &ma)
{
mac_addr = ma;
};
float getSsSquareDistance(const float &ss)const;
friend ostream &operator<<(ostream &os, const Measurement &m);
};
Measurement(const Mobile *_mobile = NULL, const AccessPoint *_ap = NULL,
const vector<int> &_ss_list = vector<int>()) ;
Measurement(const Measurement &m) ;
#endif // _MEASUREMENT_HH_
~Measurement() ;
Mobile* get_mobile() const ;
AccessPoint* get_ap() const ;
vector<int> get_ss_list() const ;
float get_average_ss() const ;
//float get_ss_square_distance(const float &ss) const ;
void set_mac_addr(const string &_mac_addr) ;
void add_ss_value(const int &ss) ;
friend ostream &operator<<(ostream &os, const Measurement &m) ;
} ;
#endif // _OWLPS_POSITIONING_MEASUREMENT_HH_

View File

@ -18,7 +18,7 @@ public:
Point3D(const Point3D &p) ;
Point3D(const float c[3]) ;
~Point3D() {} ;
~Point3D() {}
float get_x(void) const ;
float get_y(void) const ;

View File

@ -0,0 +1,58 @@
#include "posutil.hh"
/*
* Returns the frequency in Hz corresponding to the 802.11 channel "channel"
* or 0 if the channel is wrong.
*/
unsigned int PosUtil::channel_to_frequency(const int &channel)
{
switch (channel)
{
case 1:
case CHANNEL_1:
return CHANNEL_1 ;
case 2:
case CHANNEL_2:
return CHANNEL_2 ;
case 3:
case CHANNEL_3:
return CHANNEL_3 ;
case 4:
case CHANNEL_4:
return CHANNEL_4 ;
case 5:
case CHANNEL_5:
return CHANNEL_5 ;
case 6:
case CHANNEL_6:
return CHANNEL_6 ;
case 7:
case CHANNEL_7:
return CHANNEL_7 ;
case 8:
case CHANNEL_8:
return CHANNEL_8 ;
case 9:
case CHANNEL_9:
return CHANNEL_9 ;
case 10:
case CHANNEL_10:
return CHANNEL_10 ;
case 11:
case CHANNEL_11:
return CHANNEL_11 ;
case 12:
case CHANNEL_12:
return CHANNEL_12 ;
case 13:
case CHANNEL_13:
return CHANNEL_13 ;
case 14:
case CHANNEL_14:
return CHANNEL_14 ;
}
return 0 ; // Error: wrong channel value
}

View File

@ -0,0 +1,26 @@
#ifndef _OWLPS_POSITIONING_POSUTIL_HH_
#define _OWLPS_POSITIONING_POSUTIL_HH_
/* Wi-Fi channel frequencies in Hz */
#define CHANNEL_1 2412
#define CHANNEL_2 2417
#define CHANNEL_3 2422
#define CHANNEL_4 2427
#define CHANNEL_5 2432
#define CHANNEL_6 2437
#define CHANNEL_7 2442
#define CHANNEL_8 2447
#define CHANNEL_9 2452
#define CHANNEL_10 2457
#define CHANNEL_11 2462
#define CHANNEL_12 2467
#define CHANNEL_13 2472
#define CHANNEL_14 2477
class PosUtil
{
public:
static unsigned int channel_to_frequency(const int &channel) ;
} ;
#endif // _OWLPS_POSITIONING_POSUTIL_HH_

View File

@ -15,11 +15,11 @@ protected:
vector<Measurement> measurements ;
public:
ReferencePoint(const float &_x = 0, const float &_y = 0, const float &_z = 0
): Point3D(_x, _y, _z) {}
ReferencePoint(const float &_x = 0, const float &_y = 0, const float &_z = 0):
Point3D(_x, _y, _z) {}
ReferencePoint(const Point3D &p): Point3D(p) {}
ReferencePoint(const ReferencePoint &rp): Point3D(rp),
measurements(rp.measurements) {}
ReferencePoint(const ReferencePoint &rp):
Point3D(rp), measurements(rp.measurements) {}
~ReferencePoint() ;