108 lines
2.3 KiB
C++
108 lines
2.3 KiB
C++
/*
|
|
* This file is part of the Owl Positioning System (OwlPS).
|
|
* OwlPS is a project of the University of Franche-Comté
|
|
* (Université de Franche-Comté), France.
|
|
*/
|
|
|
|
|
|
#include "accesspoint.hh"
|
|
#include "stock.hh"
|
|
#include "posexcept.hh"
|
|
|
|
using namespace std ;
|
|
using std::tr1::unordered_map ;
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
double AccessPoint::friis_constant_term() const
|
|
{
|
|
double wavelength =
|
|
static_cast<double>(PosUtil::LIGHT_SPEED) / frequency ;
|
|
return antenna_gain + 20 * log10(wavelength) - 20 * log10(4 * M_PI) ;
|
|
}
|
|
|
|
|
|
bool AccessPoint::
|
|
received_calibration_from_ap(const AccessPoint &trx) const
|
|
{
|
|
if (this == &trx)
|
|
return true ;
|
|
|
|
// If no reference point is associated with trx, no AP received
|
|
// any calibration from it:
|
|
const ReferencePoint *ref_trx ;
|
|
try
|
|
{
|
|
ref_trx = &Stock::get_reference_point(trx.coordinates) ;
|
|
}
|
|
catch (element_not_found &e)
|
|
{
|
|
return false ;
|
|
}
|
|
|
|
// Check if trx sent a calibration request:
|
|
const vector<CalibrationRequest*> &ref_requests =
|
|
ref_trx->get_requests(trx.mac_addr) ;
|
|
if (ref_requests.empty())
|
|
return false ;
|
|
|
|
// Check if the AP received at least one message sent by trx:
|
|
for (vector<CalibrationRequest*>::const_iterator cr =
|
|
ref_requests.begin() ; cr != ref_requests.end() ; ++cr)
|
|
{
|
|
const vector<const Measurement*> &measurements =
|
|
(*cr)->get_measurements(mac_addr) ;
|
|
if (! measurements.empty())
|
|
return true ;
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Operators *** */
|
|
|
|
|
|
AccessPoint& AccessPoint::operator=(const AccessPoint &source)
|
|
{
|
|
if (this == &source)
|
|
return *this ;
|
|
|
|
this->WifiDevice::operator=(source) ;
|
|
coordinates = source.coordinates ;
|
|
frequency = source.frequency ;
|
|
friis_index = source.friis_index ;
|
|
|
|
return *this ;
|
|
}
|
|
|
|
|
|
bool AccessPoint::operator==(const AccessPoint &source) const
|
|
{
|
|
if (this == &source)
|
|
return true ;
|
|
|
|
return
|
|
this->WifiDevice::operator==(source) &&
|
|
coordinates == source.coordinates &&
|
|
frequency == source.frequency &&
|
|
friis_index == source.friis_index ;
|
|
}
|
|
|
|
|
|
|
|
ostream &operator<<(ostream &os, const AccessPoint &ap)
|
|
{
|
|
os
|
|
<< "Coordinates: " << ap.coordinates << '\n'
|
|
<< "Frequency: " << ap.frequency << " Hz" << '\n'
|
|
<< "Friis index: " << ap.friis_index << '\n'
|
|
<< (WifiDevice) ap ;
|
|
|
|
return os ;
|
|
}
|