/* * 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. * *********************************************************************** */ #ifndef _OWLPS_POSITIONING_POSUTIL_HH_ #define _OWLPS_POSITIONING_POSUTIL_HH_ class Measurement ; #include #include /// Utilitary class class PosUtil { public: /// The speed of light, in m/s static const unsigned long LIGHT_SPEED = 299792458 ; /** @name Maths */ //@{ /// Returns the radian value of \em degrees static double deg2rad(const double °rees) ; /// Returns the degree value of \em radians static double rad2deg(const double &radians) ; /// Checks if \em value is in the interval [center-width;center+width] static bool is_in_interval(float center, float bound, float value) ; //@} /** @name Measurements */ //@{ /// Mutually completes two Measurement lists with missing APs static void complete_with_dummy_measurements( std::tr1::unordered_map &measurements1, std::tr1::unordered_map &measurements2) ; /// Computes the similarity of two Measurement lists static float similarity( std::tr1::unordered_map &measurements1, std::tr1::unordered_map &measurements2) ; //@} /** @name Wi-Fi */ //@{ /// Converts a Wi-Fi channel to the corresponding frequency in Hz static unsigned long wifi_channel_to_hz(const unsigned long &channel) ; //@} /** @name Strings */ //@{ static void to_upper(std::string &str) ; static std::string int_to_mac(const uint32_t source) ; //@} } ; /* *** Maths *** */ /** * This function checks if \em value belongs to the symmetrical interval * [center-bound;center+bound]. * * @arg center The center of the interval. * @arg bound Half the width of the interval. * @arg value The value to check the presence in the interval. * * @returns \em true if value belongs to the interval. * @returns \em false if value does not belong to the interval. */ inline bool PosUtil:: is_in_interval(float center, float bound, float value) { if (bound == 0) return value == center ; assert(bound > 0) ; float interval_min = center - bound ; float interval_max = center + bound ; return interval_min <= value && value <= interval_max ; } /* *** Strings *** */ inline void PosUtil::to_upper(std::string &str) { boost::to_upper(str) ; } #ifdef NDEBUG # define assert_uppercase(STR) #else // NDEBUG # define assert_uppercase(STR) \ ({std::string str_up((STR)) ; \ PosUtil::to_upper(str_up) ; \ assert(str_up == (STR)) ; \ }) #endif // NDEBUG #endif // _OWLPS_POSITIONING_POSUTIL_HH_