2012-02-06 16:44:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Owl Positioning System (OwlPS).
|
|
|
|
* OwlPS is a project of the University of Franche-Comté
|
|
|
|
* (Université de Franche-Comté), France.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-12-11 13:52:21 +01:00
|
|
|
#ifndef _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
|
|
#define _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
|
|
|
|
|
|
#include "accesspoint.hh"
|
2008-04-11 10:11:29 +02:00
|
|
|
|
2011-10-28 17:13:04 +02:00
|
|
|
#include <map>
|
2010-01-06 01:18:14 +01:00
|
|
|
#include <ostream>
|
|
|
|
#include <cmath>
|
2008-04-11 10:11:29 +02:00
|
|
|
|
2011-12-30 19:52:51 +01:00
|
|
|
typedef uint_fast16_t pkt_id_t ;
|
2011-12-30 18:27:30 +01:00
|
|
|
typedef int_fast16_t ss_t ;
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Represents a list of signal strengths captured by one AccessPoint
|
2008-04-11 10:11:29 +02:00
|
|
|
class Measurement
|
2010-05-21 10:35:15 +02:00
|
|
|
{
|
|
|
|
protected:
|
2010-01-16 12:23:07 +01:00
|
|
|
/// The AccessPoint that performed the measurement
|
2009-12-11 13:52:21 +01:00
|
|
|
AccessPoint *ap ;
|
2010-02-05 11:02:24 +01:00
|
|
|
/// List of signal strengths captured (in dBm)
|
2011-12-30 19:52:51 +01:00
|
|
|
std::map<pkt_id_t, ss_t> ss_list ;
|
2012-02-03 11:55:24 +01:00
|
|
|
/// Average of all the captured signal strengths (dBm)
|
2012-02-09 14:49:36 +01:00
|
|
|
float average_dbm ;
|
2012-02-03 11:55:24 +01:00
|
|
|
/// Average of all the captured signal strengths (mW)
|
2012-02-09 14:49:36 +01:00
|
|
|
float average_mw ;
|
2012-06-19 17:13:27 +02:00
|
|
|
/// Variance of all the captured signal strengths (mW)
|
|
|
|
float variance_mw ;
|
2012-06-19 17:56:10 +02:00
|
|
|
/// Variance of all the captured signal strengths (dBm)
|
|
|
|
float variance_dbm ;
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2012-02-03 11:55:24 +01:00
|
|
|
private:
|
2012-06-19 17:17:10 +02:00
|
|
|
/// Intermediate variable used to compute the variance (mW)
|
2012-06-19 17:13:27 +02:00
|
|
|
float variance_mw_m2 ;
|
2012-06-19 17:56:10 +02:00
|
|
|
/// Intermediate variable used to compute the variance (dBm)
|
|
|
|
float variance_dbm_m2 ;
|
2012-06-19 17:17:10 +02:00
|
|
|
/// Number of elements taken into account in the variance computation
|
|
|
|
unsigned int variance_size ;
|
2012-02-03 11:55:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2010-02-05 11:02:24 +01:00
|
|
|
/** @name Operations */
|
|
|
|
//@{
|
2012-02-03 11:55:24 +01:00
|
|
|
/// Recalculates entirely the average and variance from #ss_list
|
|
|
|
void recalculate_average(void) ;
|
|
|
|
/// Update the average and variance with a new SS
|
|
|
|
void update_average(ss_t ss_dbm) ;
|
2012-03-05 13:53:48 +01:00
|
|
|
/// \brief Counts the number of SS of source that are within the
|
|
|
|
/// interval [average_dbm-bound;average_dbm+bound]
|
|
|
|
unsigned int nb_in_interval(
|
|
|
|
const Measurement &source, float bound) const ;
|
2010-02-05 11:02:24 +01:00
|
|
|
//@}
|
|
|
|
|
2009-05-29 13:46:49 +02:00
|
|
|
|
2010-05-21 10:35:15 +02:00
|
|
|
public:
|
2011-10-28 17:13:04 +02:00
|
|
|
Measurement(const AccessPoint *_ap = NULL):
|
2012-02-03 11:55:24 +01:00
|
|
|
ap(const_cast<AccessPoint*>(_ap)), average_dbm(0),
|
2012-06-19 17:56:10 +02:00
|
|
|
average_mw(0), variance_mw(0), variance_dbm(0),
|
|
|
|
variance_mw_m2(0), variance_dbm_m2(0), variance_size(0) {}
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
Measurement(const Measurement &source):
|
|
|
|
ap(source.ap), ss_list(source.ss_list),
|
2012-02-03 11:55:24 +01:00
|
|
|
average_dbm(source.average_dbm), average_mw(source.average_mw),
|
2012-06-19 17:56:10 +02:00
|
|
|
variance_mw(source.variance_mw), variance_dbm(source.variance_dbm),
|
|
|
|
variance_mw_m2(0), variance_dbm_m2(0), variance_size(0) {}
|
2010-03-05 17:24:18 +01:00
|
|
|
|
|
|
|
~Measurement(void) ;
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Read accessors */
|
|
|
|
//@{
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the AccessPoint associated with the Measurement
|
2009-12-11 13:52:21 +01:00
|
|
|
AccessPoint* get_ap() const ;
|
2012-02-28 12:17:20 +01:00
|
|
|
/// Returns the packet number \em pkt_id
|
|
|
|
ss_t get_ss(pkt_id_t pkt_id) const ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the mean of the SS list, in dBm
|
2012-02-09 14:49:36 +01:00
|
|
|
float get_average_dbm() const ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the variance of the SS list
|
2012-06-19 17:13:27 +02:00
|
|
|
float get_variance_mw() const ;
|
2012-06-19 17:17:10 +02:00
|
|
|
/// Returns the standard deviation of the SS list (mW)
|
2012-06-19 17:13:27 +02:00
|
|
|
float get_std_deviation_mw() const ;
|
2012-06-19 17:56:10 +02:00
|
|
|
/// Returns the standard deviation of the SS list (dBm)
|
|
|
|
float get_std_deviation_dbm() const ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the number of SS in the SS list
|
2012-02-03 11:58:31 +01:00
|
|
|
int get_nb_ss() const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Write accessors */
|
|
|
|
//@{
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Associate the Measurement with an AccessPoint
|
2009-12-11 17:56:31 +01:00
|
|
|
void set_ap(const AccessPoint *_ap) ;
|
2012-02-03 11:55:24 +01:00
|
|
|
/// Adds a signal strength (in dBm) to #ss_list
|
2011-12-30 19:52:51 +01:00
|
|
|
void add_ss(const pkt_id_t packet_id, const ss_t ss_dbm) ;
|
2012-02-03 11:55:24 +01:00
|
|
|
/// Adds several signal strengths (in dBm) to #ss_list
|
2011-12-30 19:52:51 +01:00
|
|
|
void add_ss_list(const std::map<pkt_id_t, ss_t> &_ss_list) ;
|
2010-06-02 12:37:43 +02:00
|
|
|
/// Merges a given Measurement into the current Measurement
|
|
|
|
void merge(const Measurement &source) ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Reset all the attributes
|
2010-01-07 16:34:31 +01:00
|
|
|
void clear(void) ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2009-12-11 17:56:31 +01:00
|
|
|
|
2010-06-02 12:37:43 +02:00
|
|
|
/** @name Operations */
|
|
|
|
//@{
|
2012-03-02 10:54:34 +01:00
|
|
|
/// Computes the similarity with another Measurement in the SS space
|
|
|
|
float similarity(const Measurement &source) const ;
|
2012-02-13 14:36:56 +01:00
|
|
|
/// Computes the distance to another Measurement's SS average
|
2010-06-02 12:37:43 +02:00
|
|
|
float ss_square_distance(const Measurement &source) const ;
|
2012-02-03 11:55:24 +01:00
|
|
|
/// Computes the distance to another SS value (in dBm)
|
|
|
|
float ss_square_distance(const float &ss_dbm) const ;
|
2012-06-19 17:13:27 +02:00
|
|
|
/// Computes the distance to another Measurement's variance (mW)
|
|
|
|
float variance_mw_square_distance(const Measurement &source) const ;
|
|
|
|
/// Computes the distance to another variance value in mW
|
|
|
|
float variance_mw_square_distance(const float &var) const ;
|
2010-06-02 12:37:43 +02:00
|
|
|
//@}
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Operators */
|
|
|
|
//@{
|
2011-07-30 20:38:42 +02:00
|
|
|
Measurement& operator=(const Measurement &m) ;
|
2010-01-07 16:26:13 +01:00
|
|
|
bool operator==(const Measurement &m) const ;
|
|
|
|
bool operator!=(const Measurement &m) const ;
|
2010-03-05 17:24:18 +01:00
|
|
|
operator bool(void) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2009-12-11 13:52:21 +01:00
|
|
|
|
2011-10-28 17:13:04 +02:00
|
|
|
/** @name Conversion accessors */
|
|
|
|
//@{
|
|
|
|
/// Converts to a CSV string
|
|
|
|
const std::string to_csv(void) const ;
|
|
|
|
//@}
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Displays a Measurement
|
2010-01-04 17:10:42 +01:00
|
|
|
friend std::ostream &operator<<(std::ostream &os, const Measurement &m) ;
|
2009-12-11 13:52:21 +01:00
|
|
|
} ;
|
|
|
|
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Read accessors *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline AccessPoint* Measurement::get_ap() const
|
|
|
|
{
|
|
|
|
return ap ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-09 14:49:36 +01:00
|
|
|
inline float Measurement::get_average_dbm() const
|
2012-02-03 11:55:24 +01:00
|
|
|
{
|
|
|
|
return average_dbm ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 17:13:27 +02:00
|
|
|
inline float Measurement::get_variance_mw() const
|
2010-01-05 11:50:24 +01:00
|
|
|
{
|
2012-06-19 17:13:27 +02:00
|
|
|
return variance_mw ;
|
2010-01-05 11:50:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 17:13:27 +02:00
|
|
|
inline float Measurement::get_std_deviation_mw() const
|
2012-02-27 12:22:20 +01:00
|
|
|
{
|
2012-06-19 17:13:27 +02:00
|
|
|
return sqrt(variance_mw) ;
|
2012-02-27 12:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-19 17:56:10 +02:00
|
|
|
inline float Measurement::get_std_deviation_dbm() const
|
|
|
|
{
|
|
|
|
return sqrt(variance_dbm) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-03 11:58:31 +01:00
|
|
|
inline int Measurement::get_nb_ss() const
|
2010-06-10 15:57:03 +02:00
|
|
|
{
|
|
|
|
return ss_list.size() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-05 11:50:24 +01:00
|
|
|
|
2010-02-05 11:02:24 +01:00
|
|
|
/* *** Write accessors *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline void Measurement::set_ap(const AccessPoint *_ap)
|
|
|
|
{
|
2010-01-18 14:19:57 +01:00
|
|
|
ap = const_cast<AccessPoint*>(_ap) ;
|
2010-01-05 11:50:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-02 12:37:43 +02:00
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
inline float Measurement::
|
|
|
|
ss_square_distance(const Measurement &source) const
|
|
|
|
{
|
2012-02-03 11:55:24 +01:00
|
|
|
return ss_square_distance(source.average_dbm) ;
|
2010-06-02 12:37:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-03 11:55:24 +01:00
|
|
|
inline float Measurement::ss_square_distance(const float &ss_dbm) const
|
2010-06-02 12:37:43 +02:00
|
|
|
{
|
2012-02-03 11:55:24 +01:00
|
|
|
return ((ss_dbm - average_dbm) * (ss_dbm - average_dbm)) ;
|
2010-06-02 12:37:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-13 14:36:56 +01:00
|
|
|
inline float Measurement::
|
2012-06-19 17:13:27 +02:00
|
|
|
variance_mw_square_distance(const Measurement &source) const
|
2012-02-13 14:36:56 +01:00
|
|
|
{
|
2012-06-19 17:13:27 +02:00
|
|
|
return variance_mw_square_distance(source.variance_mw) ;
|
2012-02-13 14:36:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline float Measurement::
|
2012-06-19 17:13:27 +02:00
|
|
|
variance_mw_square_distance(const float &var) const
|
2012-02-13 14:36:56 +01:00
|
|
|
{
|
2012-06-19 17:13:27 +02:00
|
|
|
return ((var - variance_mw) * (var - variance_mw)) ;
|
2012-02-13 14:36:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 12:37:43 +02:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2010-01-05 11:50:24 +01:00
|
|
|
|
|
|
|
|
2010-01-07 16:26:13 +01:00
|
|
|
inline bool Measurement::operator!=(const Measurement &m) const
|
2010-01-05 11:50:24 +01:00
|
|
|
{
|
|
|
|
return !(*this == m) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* @return \em false if the Measurement is empty.
|
|
|
|
* @return \em true if at least one attribute is initialised.
|
2010-01-07 16:26:13 +01:00
|
|
|
*/
|
|
|
|
inline Measurement::operator bool() const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
ap != NULL ||
|
2011-05-11 09:47:29 +02:00
|
|
|
! ss_list.empty() ;
|
2010-01-07 16:26:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-05 11:50:24 +01:00
|
|
|
|
2009-12-11 13:52:21 +01:00
|
|
|
#endif // _OWLPS_POSITIONING_MEASUREMENT_HH_
|