2012-02-06 16:44:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Owl Positioning System (OwlPS).
|
2012-11-03 14:52:33 +01:00
|
|
|
* OwlPS is a project of the University of Franche-Comte
|
2012-02-06 16:44:09 +01:00
|
|
|
* (Université de Franche-Comté), France.
|
2012-11-03 14:52:33 +01:00
|
|
|
*
|
|
|
|
* Copyright © Université de Franche-Comté 2007-2012.
|
|
|
|
*
|
|
|
|
* Corresponding author: Matteo Cypriani <mcy@lm7.fr>
|
|
|
|
*
|
|
|
|
***********************************************************************
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
***********************************************************************
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-01-11 19:40:45 +01:00
|
|
|
#include "request.hh"
|
2012-08-30 10:23:09 +02:00
|
|
|
#include "calibrationrequest.hh"
|
|
|
|
#include "referencepoint.hh"
|
2010-01-11 19:40:45 +01:00
|
|
|
#include "mobile.hh"
|
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
using std::tr1::unordered_map ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Constructors *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2012-06-01 14:27:17 +02:00
|
|
|
Request::Request(
|
|
|
|
const Mobile *_mobile,
|
|
|
|
const Timestamp &_time_sent,
|
|
|
|
const std::tr1::unordered_map<std::string, Measurement> &_measurements
|
|
|
|
):
|
|
|
|
type(OWL_REQUEST_UNDEFINED), nb_packets(1),
|
|
|
|
mobile(const_cast<Mobile*>(_mobile)), time_sent(_time_sent),
|
|
|
|
measurements(_measurements), real_position(NULL)
|
|
|
|
{
|
|
|
|
received_now() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Request::Request(const std::tr1::unordered_map<std::string, Measurement>
|
|
|
|
&_measurements):
|
|
|
|
type(OWL_REQUEST_UNDEFINED), nb_packets(1),
|
|
|
|
mobile(NULL), measurements(_measurements), real_position(NULL)
|
|
|
|
{
|
|
|
|
received_now() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Request::Request(
|
|
|
|
const Timestamp &_time_sent,
|
|
|
|
const std::tr1::unordered_map<std::string, Measurement> &_measurements
|
|
|
|
):
|
|
|
|
type(OWL_REQUEST_UNDEFINED), nb_packets(1),
|
|
|
|
mobile(NULL), time_sent(_time_sent),
|
|
|
|
measurements(_measurements), real_position(NULL)
|
|
|
|
{
|
|
|
|
received_now() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-31 18:49:18 +02:00
|
|
|
Request::Request(const Request &source):
|
|
|
|
type(source.type), nb_packets(source.nb_packets),
|
|
|
|
mobile(source.mobile), time_sent(source.time_sent),
|
2012-06-01 14:27:17 +02:00
|
|
|
time_received(source.time_received),
|
2012-05-31 18:49:18 +02:00
|
|
|
measurements(source.measurements), real_position(NULL)
|
|
|
|
{
|
|
|
|
if (source.real_position)
|
|
|
|
real_position = new Point3D(*source.real_position) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Note that the value pointed by #mobile is not deleted.
|
|
|
|
*/
|
|
|
|
Request::~Request()
|
|
|
|
{
|
|
|
|
measurements.clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-27 12:26:55 +01:00
|
|
|
/* *** Read accessors *** */
|
|
|
|
|
|
|
|
|
2011-12-29 11:51:25 +01:00
|
|
|
/**
|
|
|
|
* @param mac_receiver The MAC address of the receiver AP.
|
|
|
|
* @returns A pointer on the found measurement, or NULL if no
|
|
|
|
* measurement was made by this AP.
|
|
|
|
*/
|
|
|
|
const Measurement*
|
|
|
|
Request::get_measurement(const string &mac_receiver) const
|
2011-12-27 12:26:55 +01:00
|
|
|
{
|
2011-12-29 11:51:25 +01:00
|
|
|
unordered_map<string, Measurement>::const_iterator m =
|
|
|
|
measurements.find(mac_receiver) ;
|
|
|
|
if (m != measurements.end())
|
|
|
|
return &m->second ;
|
|
|
|
return NULL ;
|
2011-12-27 12:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Write accessors *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2011-05-04 19:02:20 +02:00
|
|
|
inline void Request::clear_real_position()
|
|
|
|
{
|
|
|
|
if (real_position)
|
|
|
|
{
|
|
|
|
delete real_position ;
|
|
|
|
real_position = NULL ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Request::set_real_position(const Point3D &_real_position)
|
|
|
|
{
|
|
|
|
if (real_position)
|
|
|
|
*real_position = _real_position ;
|
|
|
|
else
|
|
|
|
real_position = new Point3D(_real_position) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
2011-10-28 17:13:04 +02:00
|
|
|
* - #nb_packets is set to 1 (this is the default value when
|
|
|
|
* constructing a Request).
|
2010-01-16 12:23:07 +01:00
|
|
|
* - #mobile is NULLified, but the value it pointed to is not deleted.
|
2012-06-01 14:27:17 +02:00
|
|
|
* - The fields of #time_sent and #time_received are initialised to 0.
|
2010-01-16 12:23:07 +01:00
|
|
|
* - #measurements is cleared.
|
|
|
|
*/
|
2010-01-11 19:40:45 +01:00
|
|
|
void Request::clear()
|
|
|
|
{
|
2011-03-29 11:22:44 +02:00
|
|
|
type = OWL_REQUEST_UNDEFINED ;
|
2011-10-28 17:13:04 +02:00
|
|
|
nb_packets = 1 ;
|
2010-01-11 19:40:45 +01:00
|
|
|
mobile = NULL ;
|
2010-03-05 18:14:33 +01:00
|
|
|
time_sent.clear() ;
|
2012-06-01 14:27:17 +02:00
|
|
|
time_received.clear() ;
|
2010-01-11 19:40:45 +01:00
|
|
|
measurements.clear() ;
|
2011-05-04 19:02:20 +02:00
|
|
|
clear_real_position() ;
|
2010-01-11 19:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-09 16:21:36 +02:00
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
2012-03-02 11:48:40 +01:00
|
|
|
float Request::similarity(const Request &source) const
|
2011-05-09 16:21:36 +02:00
|
|
|
{
|
|
|
|
unordered_map<string, Measurement>
|
2012-03-02 11:48:40 +01:00
|
|
|
source_measurements(source.measurements) ;
|
|
|
|
unordered_map<string, Measurement>
|
|
|
|
my_measurements(measurements) ;
|
2011-05-09 16:21:36 +02:00
|
|
|
|
|
|
|
PosUtil::complete_with_dummy_measurements(
|
|
|
|
my_measurements, source_measurements) ;
|
|
|
|
|
2012-03-02 11:48:40 +01:00
|
|
|
return PosUtil::similarity(
|
2011-05-09 16:21:36 +02:00
|
|
|
my_measurements, source_measurements) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2011-07-30 20:38:42 +02:00
|
|
|
Request& Request::operator=(const Request &source)
|
2010-02-01 17:36:45 +01:00
|
|
|
{
|
|
|
|
if (this == &source)
|
|
|
|
return *this ;
|
|
|
|
|
2011-03-29 11:22:44 +02:00
|
|
|
type = source.type ;
|
2011-10-28 17:13:04 +02:00
|
|
|
nb_packets = source.nb_packets ;
|
2010-02-01 17:36:45 +01:00
|
|
|
mobile = source.mobile ;
|
2010-03-05 18:14:33 +01:00
|
|
|
time_sent = source.time_sent ;
|
2012-06-01 14:27:17 +02:00
|
|
|
time_received = source.time_received ;
|
2010-02-01 17:36:45 +01:00
|
|
|
measurements = source.measurements ;
|
|
|
|
|
2011-05-04 19:02:20 +02:00
|
|
|
clear_real_position() ;
|
|
|
|
if (source.real_position)
|
|
|
|
real_position = new Point3D(*source.real_position) ;
|
|
|
|
|
2010-02-01 17:36:45 +01:00
|
|
|
return *this ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-05 18:14:33 +01:00
|
|
|
bool Request::operator==(const Request &source) const
|
2010-02-01 17:36:45 +01:00
|
|
|
{
|
2010-03-05 18:14:33 +01:00
|
|
|
if (this == &source)
|
2010-02-01 17:36:45 +01:00
|
|
|
return true ;
|
|
|
|
|
2011-05-04 19:02:20 +02:00
|
|
|
bool real_position_equal =
|
|
|
|
real_position &&
|
|
|
|
source.real_position &&
|
|
|
|
*real_position == *source.real_position ;
|
|
|
|
|
2010-02-01 17:36:45 +01:00
|
|
|
return
|
2011-05-04 19:02:20 +02:00
|
|
|
real_position_equal &&
|
2011-03-29 11:22:44 +02:00
|
|
|
type == source.type &&
|
2011-10-28 17:13:04 +02:00
|
|
|
nb_packets == source.nb_packets &&
|
2010-03-05 18:14:33 +01:00
|
|
|
mobile == source.mobile &&
|
|
|
|
time_sent == source.time_sent &&
|
2012-06-01 14:27:17 +02:00
|
|
|
time_received == source.time_received &&
|
2010-03-05 18:14:33 +01:00
|
|
|
measurements == source.measurements ;
|
2010-02-01 17:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-30 10:23:09 +02:00
|
|
|
const string Request::to_csv() const
|
|
|
|
{
|
|
|
|
ostringstream csv_line ;
|
|
|
|
|
|
|
|
if (mobile != NULL)
|
|
|
|
csv_line << mobile->get_mac_addr() ;
|
|
|
|
|
|
|
|
csv_line
|
|
|
|
<< ';' << static_cast<uint_fast16_t>(type)
|
|
|
|
<< ';' << nb_packets
|
|
|
|
<< ';' << time_sent
|
|
|
|
<< ';' ;
|
|
|
|
|
|
|
|
const CalibrationRequest *calibration_request =
|
|
|
|
dynamic_cast<const CalibrationRequest*>(this) ;
|
|
|
|
if (calibration_request == NULL)
|
|
|
|
csv_line << "0;0;0;0" ;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
csv_line
|
|
|
|
<< calibration_request->get_reference_point()->get_x() << ';'
|
|
|
|
<< calibration_request->get_reference_point()->get_y() << ';'
|
|
|
|
<< calibration_request->get_reference_point()->get_z() << ';'
|
|
|
|
<< static_cast<int>(calibration_request->get_direction()) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unordered_map<string, Measurement>::const_iterator i
|
|
|
|
= measurements.begin() ; i != measurements.end() ; ++i)
|
2012-08-30 10:27:52 +02:00
|
|
|
csv_line << ';' << i->second.to_csv() ;
|
2012-08-30 10:23:09 +02:00
|
|
|
|
|
|
|
return csv_line.str() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-03 17:57:32 +01:00
|
|
|
ostream& operator<<(ostream &os, const Request &r)
|
2010-01-11 19:40:45 +01:00
|
|
|
{
|
|
|
|
// Timestamp
|
2012-06-01 14:27:17 +02:00
|
|
|
os << "At " << r.time_sent
|
|
|
|
<< " (received at " << r.time_received << "; " ;
|
2011-05-04 19:02:20 +02:00
|
|
|
|
|
|
|
if (r.real_position)
|
|
|
|
os << " Real coordinates : " << *r.real_position << "; " ;
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
// MAC address
|
2012-06-01 14:27:17 +02:00
|
|
|
os << "Type: " << static_cast<uint_fast16_t>(r.type)
|
|
|
|
<< ", Number of packets sent: " << r.nb_packets
|
|
|
|
<< ", Mobile: "
|
|
|
|
<< (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile")
|
|
|
|
<< ":" ;
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
// List of Measurements
|
2010-02-26 13:09:45 +01:00
|
|
|
if (r.measurements.empty())
|
2010-01-11 19:40:45 +01:00
|
|
|
os << " No values" ;
|
|
|
|
else
|
|
|
|
for (unordered_map<string, Measurement>::const_iterator i
|
2010-01-13 15:29:44 +01:00
|
|
|
= r.measurements.begin() ; i != r.measurements.end() ; ++i)
|
2011-05-04 19:02:20 +02:00
|
|
|
os << '\n' << i->first << ": " << i->second ;
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
return os ;
|
|
|
|
}
|
2010-06-07 15:09:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Mobile MAC address and the Timestamp are sufficient to identify
|
|
|
|
* uniquely a Request.
|
|
|
|
*/
|
|
|
|
size_t hash_value(const Request &source)
|
|
|
|
{
|
|
|
|
size_t seed = 0 ;
|
|
|
|
|
2011-03-29 11:22:44 +02:00
|
|
|
boost::hash_combine(seed, source.type) ;
|
2011-10-28 17:13:04 +02:00
|
|
|
boost::hash_combine(seed, source.nb_packets) ;
|
2010-06-07 15:09:22 +02:00
|
|
|
boost::hash_combine(seed, source.time_sent) ;
|
2012-06-01 14:27:17 +02:00
|
|
|
boost::hash_combine(seed, source.time_received) ;
|
2011-05-04 19:02:20 +02:00
|
|
|
if (source.mobile)
|
2010-06-07 15:09:22 +02:00
|
|
|
boost::hash_combine(seed, source.mobile->get_mac_addr()) ;
|
2011-05-04 19:02:20 +02:00
|
|
|
if (source.real_position)
|
|
|
|
boost::hash_combine(seed, source.real_position) ;
|
2010-06-07 15:09:22 +02:00
|
|
|
|
|
|
|
return seed ;
|
|
|
|
}
|