/* * This file is part of the Owl Positioning System (OwlPS). * OwlPS is a project of the University of Franche-Comte * (Université de Franche-Comté), France. * * Copyright © Université de Franche-Comté 2007-2012. * * Corresponding author: Matteo Cypriani * *********************************************************************** * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL: * http://www.cecill.info * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided * only with a limited warranty and the software's authors, the holder * of the economic rights, and the successive licensors have only * limited liability. * * In this respect, the user's attention is drawn to the risks * associated with loading, using, modifying and/or developing or * reproducing the software by the user in light of its specific status * of free software, that may mean that it is complicated to manipulate, * and that also therefore means that it is reserved for developers and * experienced professionals having in-depth computer knowledge. Users * are therefore encouraged to load and test the software's suitability * as regards their requirements in conditions enabling the security of * their systems and/or data to be ensured and, more generally, to use * and operate it in the same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. * *********************************************************************** */ #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() ; } if (expected_packets == 0) return 0 ; // 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 ; }