2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
2016-11-03 05:10:34 +01:00
|
|
|
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
|
2013-05-29 18:43:35 +02:00
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-12-11 13:52:21 +01:00
|
|
|
#include "posutil.hh"
|
2010-06-23 17:32:35 +02:00
|
|
|
#include "posexcept.hh"
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
#include "stock.hh"
|
2011-12-30 12:21:59 +01:00
|
|
|
#include "configuration.hh"
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
#include "measurement.hh"
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2011-05-09 14:20:57 +02:00
|
|
|
#include <owlps.h>
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2011-07-13 14:56:06 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-13 14:56:06 +02:00
|
|
|
/* *** Maths *** */
|
|
|
|
|
|
|
|
|
2013-10-02 20:50:39 +02:00
|
|
|
double PosUtil::deg2rad(const double degrees)
|
2012-04-30 09:55:32 +02:00
|
|
|
{
|
|
|
|
return degrees / (180.0 / M_PI) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 20:50:39 +02:00
|
|
|
double PosUtil::rad2deg(const double radians)
|
2011-07-13 14:56:06 +02:00
|
|
|
{
|
|
|
|
return radians * (180.0 / M_PI) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
/* *** Measurements *** */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-14 21:54:26 +02:00
|
|
|
* CPs that have not captured a Request must not have too much weight in
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
* the computation. Thus, in the measurements lists we compare, we add
|
2013-06-14 21:54:26 +02:00
|
|
|
* missing CPs with a very low SS value.
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
*
|
2013-06-14 21:54:26 +02:00
|
|
|
* Both lists can be completed, depending of the CPs they contain.
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
* Both lists must initially contain at least one measurement.
|
|
|
|
*/
|
|
|
|
void PosUtil::complete_with_dummy_measurements(
|
|
|
|
unordered_map<string, Measurement> &measurements1,
|
|
|
|
unordered_map<string, Measurement> &measurements2)
|
|
|
|
{
|
|
|
|
assert(! measurements1.empty()) ;
|
|
|
|
assert(! measurements2.empty()) ;
|
|
|
|
|
|
|
|
Measurement dummy ;
|
2011-12-30 12:21:59 +01:00
|
|
|
dummy.add_ss(1, Configuration::int_value("positioning.smallest-ss")) ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = measurements1.begin() ; i != measurements1.end() ; ++i)
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
if (measurements2.find(i->first) == measurements2.end())
|
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
dummy.set_cp(&Stock::get_cp(i->first)) ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
measurements2[i->first] = dummy ;
|
|
|
|
}
|
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = measurements2.begin() ; i != measurements2.end() ; ++i)
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
if (measurements1.find(i->first) == measurements1.end())
|
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
dummy.set_cp(&Stock::get_cp(i->first)) ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
measurements1[i->first] = dummy ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Both lists must have the same size and contain the same keys:
|
2012-03-02 11:48:40 +01:00
|
|
|
* you should call complete_with_dummy_measurements() before this
|
|
|
|
* function.
|
2012-02-08 17:57:00 +01:00
|
|
|
*
|
2012-03-02 11:48:40 +01:00
|
|
|
* The similarity between the two lists is computed by averaging the
|
|
|
|
* similarities between the elements of both lists, two by two, calling
|
|
|
|
* Measurement::similarity().
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
*/
|
2012-03-02 11:48:40 +01:00
|
|
|
float PosUtil::similarity(
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
unordered_map<string, Measurement> &measurements1,
|
|
|
|
unordered_map<string, Measurement> &measurements2)
|
|
|
|
{
|
2012-02-08 17:57:00 +01:00
|
|
|
assert(! measurements1.empty()) ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
assert(measurements1.size() == measurements2.size()) ;
|
|
|
|
|
2012-03-02 11:48:40 +01:00
|
|
|
float similarity = 0 ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i1 = measurements1.begin() ; i1 != measurements1.end() ; ++i1)
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
{
|
2013-10-02 22:22:20 +02:00
|
|
|
auto i2 = measurements2.find(i1->first) ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
assert(i2 != measurements2.end()) ;
|
2012-03-02 11:48:40 +01:00
|
|
|
similarity += i1->second.similarity(i2->second) ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
}
|
|
|
|
|
2012-03-02 11:48:40 +01:00
|
|
|
return similarity / measurements1.size() ;
|
[Positioning] Some ReferencePoint code -> PosUtil
ReferencePoint::complete_with_dummy_measurements(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::complete_with_dummy_measurements(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
ReferencePoint::compute_ss_square_distance(
map<string, Measurement>,
map<string, Measurement>)
becomes PosUtil::ss_square_distance(
unordered_map<string, Measurement>,
unordered_map<string, Measurement>)
map<string, Measurement> ReferencePoint::get_all_measurements_sorted()
is now private, returns an unordered_map instead of a map, and is
renamed ReferencePoint::get_all_measurements().
Note that we now use unordered_maps for these functions. The use of
sorted lists (maps) was useless, as stated in the commit message of
e9eab687 (Wed Jun 2 12:37:43 2010 +0200).
2011-05-09 15:19:01 +02:00
|
|
|
}
|
|
|
|
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2010-03-05 10:05:12 +01:00
|
|
|
|
2011-05-09 14:20:57 +02:00
|
|
|
/* *** Wi-Fi *** */
|
2010-03-05 10:05:12 +01:00
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
2011-05-09 14:20:57 +02:00
|
|
|
* @param channel A IEEE 802.11 channel or frequency in MHz or in Hz.
|
2013-05-30 21:23:05 +02:00
|
|
|
* @returns The frequency in Hz.
|
2013-06-17 20:42:08 +02:00
|
|
|
* @throw bad_channel if `channel` is not a valid channel or
|
2010-06-23 17:32:35 +02:00
|
|
|
* frequency value.
|
2009-12-11 13:52:21 +01:00
|
|
|
*/
|
2010-06-23 17:32:35 +02:00
|
|
|
unsigned long PosUtil::wifi_channel_to_hz(const unsigned long &channel)
|
2009-12-11 13:52:21 +01:00
|
|
|
{
|
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case 1:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_1:
|
|
|
|
case OWL_80211_HZ_CHANNEL_1:
|
|
|
|
return OWL_80211_HZ_CHANNEL_1 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 2:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_2:
|
|
|
|
case OWL_80211_HZ_CHANNEL_2:
|
|
|
|
return OWL_80211_HZ_CHANNEL_2 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 3:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_3:
|
|
|
|
case OWL_80211_HZ_CHANNEL_3:
|
|
|
|
return OWL_80211_HZ_CHANNEL_3 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 4:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_4:
|
|
|
|
case OWL_80211_HZ_CHANNEL_4:
|
|
|
|
return OWL_80211_HZ_CHANNEL_4 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 5:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_5:
|
|
|
|
case OWL_80211_HZ_CHANNEL_5:
|
|
|
|
return OWL_80211_HZ_CHANNEL_5 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 6:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_6:
|
|
|
|
case OWL_80211_HZ_CHANNEL_6:
|
|
|
|
return OWL_80211_HZ_CHANNEL_6 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 7:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_7:
|
|
|
|
case OWL_80211_HZ_CHANNEL_7:
|
|
|
|
return OWL_80211_HZ_CHANNEL_7 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 8:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_8:
|
|
|
|
case OWL_80211_HZ_CHANNEL_8:
|
|
|
|
return OWL_80211_HZ_CHANNEL_8 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 9:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_9:
|
|
|
|
case OWL_80211_HZ_CHANNEL_9:
|
|
|
|
return OWL_80211_HZ_CHANNEL_9 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 10:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_10:
|
|
|
|
case OWL_80211_HZ_CHANNEL_10:
|
|
|
|
return OWL_80211_HZ_CHANNEL_10 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 11:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_11:
|
|
|
|
case OWL_80211_HZ_CHANNEL_11:
|
|
|
|
return OWL_80211_HZ_CHANNEL_11 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 12:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_12:
|
|
|
|
case OWL_80211_HZ_CHANNEL_12:
|
|
|
|
return OWL_80211_HZ_CHANNEL_12 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 13:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_13:
|
|
|
|
case OWL_80211_HZ_CHANNEL_13:
|
|
|
|
return OWL_80211_HZ_CHANNEL_13 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
case 14:
|
2011-05-09 14:20:57 +02:00
|
|
|
case OWL_80211_MHZ_CHANNEL_14:
|
|
|
|
case OWL_80211_HZ_CHANNEL_14:
|
|
|
|
return OWL_80211_HZ_CHANNEL_14 ;
|
2009-12-11 13:52:21 +01:00
|
|
|
}
|
|
|
|
|
2010-06-23 17:32:35 +02:00
|
|
|
// Error: wrong channel value
|
|
|
|
throw bad_channel(channel) ;
|
2009-12-11 13:52:21 +01:00
|
|
|
}
|
2011-07-21 14:37:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Strings *** */
|
|
|
|
|
|
|
|
|
|
|
|
string PosUtil::int_to_mac(const uint32_t source)
|
|
|
|
{
|
|
|
|
uint8_t bytes[6] ;
|
|
|
|
memset(bytes, 0, 6) ;
|
|
|
|
for (int i = 0 ; i < 4 ; ++i)
|
|
|
|
bytes[i+2] = reinterpret_cast<const uint8_t*>(&source)[i] ;
|
|
|
|
char mac_cstr[OWL_ETHER_ADDR_STRLEN] ;
|
|
|
|
owl_mac_bytes_to_string_r(bytes, mac_cstr) ;
|
|
|
|
string mac(mac_cstr) ;
|
|
|
|
to_upper(mac) ;
|
|
|
|
return mac ;
|
|
|
|
}
|