/* * 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(PosUtil::LIGHT_SPEED) / frequency ; return antenna_gain + 20 * log10(wavelength) - 20 * log10(4 * M_PI) ; } /** * @param trx The transmitter AP. * @returns The percentage of calibration packets sent by \em trx and * received by the AP. * @returns 0 if no packet were received from \em trx. */ float AccessPoint:: received_calibration_from_ap(const AccessPoint &trx) const { if (this == &trx) return 100 ; // 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 0 ; } // Check if trx sent a calibration request: const vector &ref_requests = ref_trx->get_requests(trx.mac_addr) ; if (ref_requests.empty()) return 0 ; // Count the number of messages sent by trx and the number of // messages actually received by the AP: unsigned int received_packets = 0, expected_packets = 0 ; for (vector::const_iterator cr = ref_requests.begin() ; cr != ref_requests.end() ; ++cr) { const Measurement *const measurement = (*cr)->get_measurement(mac_addr) ; if (! measurement) continue ; received_packets += measurement->get_nb_ss() ; expected_packets += (*cr)->get_nb_packets() ; } // Compute the score (percent): float score = received_packets * 100.0 / expected_packets ; return score ; } /* *** 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 ; }