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
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-01-11 19:40:45 +01:00
|
|
|
#ifndef _OWLPS_POSITIONING_REQUEST_HH_
|
|
|
|
#define _OWLPS_POSITIONING_REQUEST_HH_
|
|
|
|
|
2013-05-30 20:13:44 +02:00
|
|
|
#include "mobile.hh"
|
2010-01-11 19:40:45 +01:00
|
|
|
#include "measurement.hh"
|
2010-02-03 17:03:31 +01:00
|
|
|
#include "timestamp.hh"
|
2013-05-30 20:13:44 +02:00
|
|
|
#include "posutil.hh"
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2011-03-29 11:22:44 +02:00
|
|
|
#include <owlps.h>
|
|
|
|
|
2010-01-11 19:40:45 +01:00
|
|
|
#include <ctime>
|
2011-12-27 12:26:55 +01:00
|
|
|
#include <vector>
|
2013-05-30 20:13:44 +02:00
|
|
|
#include <unordered_map>
|
2010-01-11 19:40:45 +01:00
|
|
|
#include <ostream>
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Represents a request sent by a Mobile
|
2010-01-11 19:40:45 +01:00
|
|
|
class Request
|
|
|
|
{
|
|
|
|
protected:
|
2011-03-29 11:22:44 +02:00
|
|
|
/// Type of the request
|
|
|
|
uint_fast8_t type ;
|
2011-10-28 17:13:04 +02:00
|
|
|
/// Number of packets sent by the mobile for this request
|
2012-02-29 17:16:56 +01:00
|
|
|
pkt_id_t nb_packets ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// The mobile that sent the request
|
2013-10-02 20:38:45 +02:00
|
|
|
const Mobile *mobile ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Local date of the request on the mobile
|
2010-03-05 18:14:33 +01:00
|
|
|
Timestamp time_sent ;
|
2012-06-01 14:27:17 +02:00
|
|
|
/// Date at which we received the request from the aggregator
|
|
|
|
Timestamp time_received ;
|
2010-01-16 12:23:07 +01:00
|
|
|
/// List of Measurement of the request
|
2010-02-01 17:11:36 +01:00
|
|
|
/** Note that this is not a pointer list, values are actually stored.
|
2013-06-14 21:54:26 +02:00
|
|
|
The `string` parameter is the MAC address of the receiver CP. */
|
2013-05-30 20:13:44 +02:00
|
|
|
std::unordered_map<std::string, Measurement> measurements ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Real coordinates of the request (normally unavailable for a
|
2011-05-04 19:02:20 +02:00
|
|
|
/// standard positioning request)
|
|
|
|
Point3D *real_position ;
|
|
|
|
|
2011-05-09 16:21:36 +02:00
|
|
|
/** @name Write accessors */
|
|
|
|
//@{
|
2011-05-04 19:02:20 +02:00
|
|
|
void clear_real_position(void) ;
|
2011-05-09 16:21:36 +02:00
|
|
|
//@}
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2013-06-06 23:07:22 +02:00
|
|
|
/// Measurements' list type
|
|
|
|
/**
|
|
|
|
* This really is just an alias to work-around clang++ that doesn't
|
|
|
|
* handle the following syntax:
|
|
|
|
*
|
|
|
|
* Request(..., const std::unordered_map<std::string, Measurement>
|
|
|
|
* &_measurements = std::unordered_map<std::string,
|
|
|
|
* Measurement>()) ;
|
|
|
|
*/
|
2014-02-26 00:11:59 +01:00
|
|
|
using measurements_list = std::unordered_map<std::string, Measurement> ;
|
2013-06-06 23:07:22 +02:00
|
|
|
|
2010-01-11 19:40:45 +01:00
|
|
|
public:
|
2014-05-13 23:50:53 +02:00
|
|
|
Request(const Mobile *const _mobile = nullptr,
|
2010-03-05 18:14:33 +01:00
|
|
|
const Timestamp &_time_sent = Timestamp(),
|
2013-05-30 20:13:44 +02:00
|
|
|
const std::unordered_map<std::string, Measurement>
|
2013-06-06 23:07:22 +02:00
|
|
|
&_measurements = measurements_list()) ;
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2016-11-04 15:30:03 +01:00
|
|
|
explicit Request(const std::unordered_map<std::string, Measurement>
|
|
|
|
&_measurements);
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-05 18:14:33 +01:00
|
|
|
Request(const Timestamp &_time_sent,
|
2013-05-30 20:13:44 +02:00
|
|
|
const std::unordered_map<std::string, Measurement>
|
2013-06-06 23:07:22 +02:00
|
|
|
&_measurements = measurements_list()) ;
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2012-05-31 18:49:18 +02:00
|
|
|
Request(const Request &source) ;
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2010-02-16 19:31:25 +01:00
|
|
|
virtual ~Request(void) ;
|
2010-01-16 12:23:07 +01:00
|
|
|
|
|
|
|
/** @name Read accessors */
|
|
|
|
//@{
|
2011-10-28 17:13:04 +02:00
|
|
|
uint_fast8_t get_type(void) const ;
|
|
|
|
uint_fast16_t get_nb_packets(void) const ;
|
2013-10-02 20:38:45 +02:00
|
|
|
const Mobile* get_mobile(void) const ;
|
2010-03-05 18:14:33 +01:00
|
|
|
const Timestamp& get_time_sent(void) const ;
|
2012-06-01 14:27:17 +02:00
|
|
|
const Timestamp& get_time_received(void) const ;
|
2011-12-27 12:26:55 +01:00
|
|
|
/// Returns all the measurements
|
2013-05-30 20:13:44 +02:00
|
|
|
const std::unordered_map<std::string, Measurement>&
|
2010-02-02 17:34:58 +01:00
|
|
|
get_measurements(void) const ;
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Returns the measurement made by the CP `mac_receiver,` if any
|
2011-12-29 11:51:25 +01:00
|
|
|
const Measurement*
|
|
|
|
get_measurement(const std::string &mac_receiver) const ;
|
2011-05-04 19:02:20 +02:00
|
|
|
const Point3D* get_real_position(void) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Write accessors */
|
|
|
|
//@{
|
2011-10-28 17:13:04 +02:00
|
|
|
void set_type(const uint_fast8_t _type) ;
|
|
|
|
void set_nb_packets(const uint_fast16_t _nb_packets) ;
|
2013-10-02 20:38:45 +02:00
|
|
|
void set_mobile(const Mobile *const _mobile) ;
|
2010-03-05 18:14:33 +01:00
|
|
|
void set_time_sent(const Timestamp &_time_sent) ;
|
2012-06-01 14:27:17 +02:00
|
|
|
void received_now(void) ;
|
2013-05-30 20:13:44 +02:00
|
|
|
void set_measurements(const std::unordered_map
|
2010-01-11 19:40:45 +01:00
|
|
|
<std::string, Measurement> &_measurements) ;
|
2011-05-04 19:02:20 +02:00
|
|
|
void set_real_position(const Point3D &_real_position) ;
|
2011-12-02 11:44:01 +01:00
|
|
|
/// Reinitialises all attributes
|
2010-01-11 19:40:45 +01:00
|
|
|
void clear(void) ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2012-08-30 10:23:09 +02:00
|
|
|
/** @name Conversion accessors */
|
|
|
|
//@{
|
|
|
|
/// Converts to a CSV string
|
|
|
|
const std::string to_csv(void) const ;
|
|
|
|
//@}
|
|
|
|
|
2011-05-09 16:21:36 +02:00
|
|
|
/** @name Operations */
|
|
|
|
//@{
|
2012-03-02 11:48:40 +01:00
|
|
|
/// Computes the similarity of two Request
|
|
|
|
float similarity(const Request &source) const ;
|
2011-05-09 16:21:36 +02:00
|
|
|
//@}
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Operators */
|
|
|
|
//@{
|
2011-07-30 20:38:42 +02:00
|
|
|
Request& operator=(const Request &source) ;
|
2010-02-01 17:36:45 +01:00
|
|
|
bool operator==(const Request &comp) const ;
|
|
|
|
bool operator!=(const Request &comp) const ;
|
2010-03-05 17:24:18 +01:00
|
|
|
operator bool(void) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Displays a Request
|
2010-03-03 17:57:32 +01:00
|
|
|
friend std::ostream& operator<<(std::ostream &os, const Request &r) ;
|
2010-01-11 19:40:45 +01:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Read accessors *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2011-03-29 11:22:44 +02:00
|
|
|
|
2011-10-28 17:13:04 +02:00
|
|
|
inline uint_fast8_t Request::get_type() const
|
2011-03-29 11:22:44 +02:00
|
|
|
{
|
|
|
|
return type ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 17:13:04 +02:00
|
|
|
inline uint_fast16_t Request::get_nb_packets() const
|
|
|
|
{
|
|
|
|
return nb_packets ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 20:38:45 +02:00
|
|
|
inline const Mobile* Request::get_mobile() const
|
2010-01-11 19:40:45 +01:00
|
|
|
{
|
|
|
|
return mobile ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-05 18:14:33 +01:00
|
|
|
inline const Timestamp& Request::get_time_sent() const
|
2010-01-16 12:23:07 +01:00
|
|
|
{
|
2010-03-05 18:14:33 +01:00
|
|
|
return time_sent ;
|
2010-01-16 12:23:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-01 14:27:17 +02:00
|
|
|
inline const Timestamp& Request::get_time_received() const
|
|
|
|
{
|
|
|
|
return time_received ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-30 20:13:44 +02:00
|
|
|
inline const std::unordered_map<std::string, Measurement>&
|
2010-02-02 17:34:58 +01:00
|
|
|
Request::get_measurements(void) const
|
|
|
|
{
|
|
|
|
return measurements ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 19:02:20 +02:00
|
|
|
inline const Point3D* Request::get_real_position(void) const
|
|
|
|
{
|
|
|
|
return real_position ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-11 19:40:45 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Write accessors *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2011-10-28 17:13:04 +02:00
|
|
|
inline void Request::set_type(const uint_fast8_t _type)
|
2011-03-29 11:22:44 +02:00
|
|
|
{
|
|
|
|
type = _type ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 17:13:04 +02:00
|
|
|
inline void Request::set_nb_packets(const uint_fast16_t _nb_packets)
|
|
|
|
{
|
|
|
|
nb_packets = _nb_packets ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 20:38:45 +02:00
|
|
|
inline void Request::set_mobile(const Mobile *const _mobile)
|
2010-01-11 19:40:45 +01:00
|
|
|
{
|
2013-10-02 20:38:45 +02:00
|
|
|
mobile = _mobile ;
|
2010-01-11 19:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-05 18:14:33 +01:00
|
|
|
inline void Request::set_time_sent(const Timestamp &_time_sent)
|
2010-01-11 19:40:45 +01:00
|
|
|
{
|
2010-03-05 18:14:33 +01:00
|
|
|
time_sent = _time_sent ;
|
2010-01-11 19:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-01 14:27:17 +02:00
|
|
|
inline void Request::received_now()
|
|
|
|
{
|
|
|
|
time_received.now() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-22 09:34:17 +02:00
|
|
|
inline void Request::
|
2013-05-30 20:13:44 +02:00
|
|
|
set_measurements(const std::unordered_map<std::string, Measurement>
|
2010-06-22 09:34:17 +02:00
|
|
|
&_measurements)
|
2010-01-11 19:40:45 +01:00
|
|
|
{
|
|
|
|
measurements = _measurements ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2010-02-01 17:36:45 +01:00
|
|
|
inline bool Request::operator!=(const Request &comp) const
|
|
|
|
{
|
|
|
|
return !(*this == comp) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
2013-05-30 21:23:05 +02:00
|
|
|
* @returns `false` if the Request is empty.
|
|
|
|
* @returns `true` if at least one attribute (other than #type and
|
2011-10-28 17:13:04 +02:00
|
|
|
* #nb_packets) is initialised.
|
2010-01-11 19:40:45 +01:00
|
|
|
*/
|
|
|
|
inline Request::operator bool() const
|
|
|
|
{
|
|
|
|
return
|
2014-05-13 23:29:08 +02:00
|
|
|
mobile ||
|
2010-03-05 18:14:33 +01:00
|
|
|
time_sent ||
|
2013-05-29 23:44:27 +02:00
|
|
|
! measurements.empty() ;
|
2010-01-11 19:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 20:13:44 +02:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template<> struct hash<Request>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* The Mobile MAC address and the Timestamp shourd be sufficient to
|
|
|
|
* identify uniquely a Request, but we test everything.
|
|
|
|
*/
|
|
|
|
size_t operator()(const Request &source) const
|
|
|
|
{
|
|
|
|
size_t seed = 0 ;
|
|
|
|
|
|
|
|
PosUtil::hash_combine(seed, source.get_type()) ;
|
|
|
|
PosUtil::hash_combine(seed, source.get_nb_packets()) ;
|
|
|
|
PosUtil::hash_combine(seed, source.get_time_sent()) ;
|
|
|
|
PosUtil::hash_combine(seed, source.get_time_received()) ;
|
|
|
|
if (source.get_mobile())
|
|
|
|
PosUtil::hash_combine(seed, source.get_mobile()->get_mac_addr()) ;
|
|
|
|
if (source.get_real_position())
|
|
|
|
PosUtil::hash_combine(seed, source.get_real_position()) ;
|
|
|
|
|
|
|
|
return seed ;
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-11 19:40:45 +01:00
|
|
|
#endif // _OWLPS_POSITIONING_REQUEST_HH_
|