/* * 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 "trilaterationalgorithm.hh" #include "minmax.hh" #include "mobile.hh" #include "configuration.hh" #include "posexcept.hh" using namespace std ; using std::tr1::unordered_map ; /* *** Constructors *** */ TrilaterationAlgorithm::TrilaterationAlgorithm(): request(NULL) { // Will be changed when other trilateration methods will be // implemented. if (! Configuration::is_configured("positioning.area-start") || ! Configuration::is_configured("positioning.area-stop")) throw missing_configuration( "You want to use MinMax, but either positioning.area-start or" " positioning.area-stop is not defined!") ; Point3D minmax_start( Configuration::string_value("positioning.area-start")) ; Point3D minmax_stop( Configuration::string_value("positioning.area-stop")) ; trilateration_method = new MinMax(minmax_start, minmax_stop) ; } TrilaterationAlgorithm::~TrilaterationAlgorithm() { delete trilateration_method ; } /* *** Operations *** */ double TrilaterationAlgorithm:: make_constant_term(const Measurement &measurement) { assert(request) ; const Mobile *mobile = request->get_mobile() ; assert(mobile) ; const AccessPoint *ap = measurement.get_ap() ; assert(ap) ; return ap->friis_constant_term() + mobile->get_antenna_gain() + mobile->get_trx_power() ; } Result TrilaterationAlgorithm::compute(const Request &_request) { request = &_request ; compute_ap_distance_circles() ; Point3D position(trilaterate()) ; return Result(request, name, position) ; } void TrilaterationAlgorithm::compute_ap_distance_circles() { ap_distances.clear() ; const unordered_map &measurements = request->get_measurements() ; for (unordered_map::const_iterator i = measurements.begin() ; i != measurements.end() ; ++i) ap_distances[i->second.get_ap()] = estimate_distance(i->second) ; }