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
|
|
|
#ifndef _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
|
|
#define _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
#include "capturepoint.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
|
|
|
|
2014-02-26 00:11:59 +01:00
|
|
|
using pkt_id_t = uint_fast16_t ;
|
|
|
|
using ss_t = int_fast16_t ;
|
2011-12-30 18:27:30 +01:00
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Represents a list of signal strengths captured by one CapturePoint
|
2008-04-11 10:11:29 +02:00
|
|
|
class Measurement
|
2010-05-21 10:35:15 +02:00
|
|
|
{
|
|
|
|
protected:
|
2013-06-14 21:54:26 +02:00
|
|
|
/// The CapturePoint that performed the measurement
|
2013-10-02 20:38:45 +02:00
|
|
|
const CapturePoint *cp ;
|
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
|
2013-10-02 20:38:45 +02:00
|
|
|
void update_average(const ss_t ss_dbm) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Counts the number of SS of source that are within the interval
|
|
|
|
/// [average_dbm-bound;average_dbm+bound]
|
2012-03-05 13:53:48 +01:00
|
|
|
unsigned int nb_in_interval(
|
2013-10-02 20:38:45 +02:00
|
|
|
const Measurement &source, const 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:
|
2016-11-04 15:30:03 +01:00
|
|
|
explicit Measurement(const CapturePoint *const _cp = nullptr):
|
2013-10-02 20:38:45 +02:00
|
|
|
cp(_cp), 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):
|
2013-06-14 21:54:26 +02:00
|
|
|
cp(source.cp), 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 */
|
|
|
|
//@{
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Returns the CapturePoint associated with the Measurement
|
2013-10-02 20:38:45 +02:00
|
|
|
const CapturePoint* get_cp(void) const ;
|
2013-05-30 21:23:05 +02:00
|
|
|
/// Returns the packet number `pkt_id`
|
2013-10-02 20:38:45 +02:00
|
|
|
ss_t get_ss(const pkt_id_t pkt_id) const ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the mean of the SS list, in dBm
|
2013-10-02 20:38:45 +02:00
|
|
|
float get_average_dbm(void) const ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the variance of the SS list
|
2013-10-02 20:38:45 +02:00
|
|
|
float get_variance_mw(void) const ;
|
2012-06-19 17:17:10 +02:00
|
|
|
/// Returns the standard deviation of the SS list (mW)
|
2013-10-02 20:38:45 +02:00
|
|
|
float get_std_deviation_mw(void) const ;
|
2012-06-19 17:56:10 +02:00
|
|
|
/// Returns the standard deviation of the SS list (dBm)
|
2013-10-02 20:38:45 +02:00
|
|
|
float get_std_deviation_dbm(void) const ;
|
2012-02-27 12:22:20 +01:00
|
|
|
/// Returns the number of SS in the SS list
|
2013-10-02 20:38:45 +02:00
|
|
|
int get_nb_ss(void) 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 */
|
|
|
|
//@{
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Associate the Measurement with a CapturePoint
|
2013-10-02 20:38:45 +02:00
|
|
|
void set_cp(const CapturePoint *const _cp) ;
|
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)
|
2013-10-02 20:50:39 +02:00
|
|
|
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
|
2013-10-02 20:50:39 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
2013-10-02 20:38:45 +02:00
|
|
|
inline const CapturePoint* Measurement::get_cp() const
|
2010-01-05 11:50:24 +01:00
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
return cp ;
|
2010-01-05 11:50:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-05-14 21:50:23 +02:00
|
|
|
return sqrtf(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
|
|
|
|
{
|
2014-05-14 21:50:23 +02:00
|
|
|
return sqrtf(variance_dbm) ;
|
2012-06-19 17:56:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2013-10-02 20:38:45 +02:00
|
|
|
inline void Measurement::set_cp(const CapturePoint *const _cp)
|
2010-01-05 11:50:24 +01:00
|
|
|
{
|
2013-10-02 20:38:45 +02:00
|
|
|
cp = _cp ;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 20:50:39 +02: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::
|
2013-10-02 20:50:39 +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
|
|
|
/**
|
2013-05-30 21:23:05 +02:00
|
|
|
* @returns `false` if the Measurement is empty.
|
|
|
|
* @returns `true` if at least one attribute is initialised.
|
2010-01-07 16:26:13 +01:00
|
|
|
*/
|
|
|
|
inline Measurement::operator bool() const
|
|
|
|
{
|
|
|
|
return
|
2014-05-13 23:29:08 +02:00
|
|
|
cp ||
|
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_
|