161 lines
3.2 KiB
C++
161 lines
3.2 KiB
C++
#ifndef _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
#define _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
|
|
#include "accesspoint.hh"
|
|
|
|
#include <vector>
|
|
#include <ostream>
|
|
#include <cmath>
|
|
|
|
/// Represents a list of signal strengths captured by one AccessPoint
|
|
class Measurement
|
|
{
|
|
protected:
|
|
/// The AccessPoint that performed the measurement
|
|
AccessPoint *ap ;
|
|
/// List of signal strengths captured (in dBm)
|
|
std::vector<int> ss_list ;
|
|
/// Average of all signal strength captured (dBm)
|
|
double average_ss ;
|
|
|
|
/** @name Operations */
|
|
//@{
|
|
/// Recalculates #average_ss from #ss_list
|
|
void update_average_ss(void) ;
|
|
//@}
|
|
|
|
|
|
public:
|
|
Measurement(const AccessPoint *_ap = NULL) ;
|
|
|
|
Measurement(const AccessPoint *_ap,
|
|
const std::vector<int> &_ss_list) ;
|
|
|
|
Measurement(const Measurement &source):
|
|
ap(source.ap), ss_list(source.ss_list),
|
|
average_ss(source.average_ss) {}
|
|
|
|
~Measurement(void) ;
|
|
|
|
/** @name Read accessors */
|
|
//@{
|
|
AccessPoint* get_ap() const ;
|
|
const std::vector<int>& get_ss_list() const ;
|
|
double get_average_ss() const ;
|
|
int get_ss_list_size() const ;
|
|
//@}
|
|
|
|
/** @name Write accessors */
|
|
//@{
|
|
void set_ap(const AccessPoint *_ap) ;
|
|
void set_ss_list(const std::vector<int> &_ss_list) ;
|
|
/// Adds a signal strength to #ss_list
|
|
void add_ss(const int &ss_dbm) ;
|
|
/// Adds several signal strengths to #ss_list
|
|
void add_ss_list(const std::vector<int> &_ss_list) ;
|
|
/// Merges a given Measurement into the current Measurement
|
|
void merge(const Measurement &source) ;
|
|
void clear(void) ;
|
|
//@}
|
|
|
|
/** @name Operations */
|
|
//@{
|
|
/// Computes the distance to another Measurement in SS space
|
|
float ss_square_distance(const Measurement &source) const ;
|
|
/// Computes the distance to another SS value
|
|
float ss_square_distance(const float &ss) const ;
|
|
//@}
|
|
|
|
/** @name Operators */
|
|
//@{
|
|
Measurement& operator=(const Measurement &m) ;
|
|
bool operator==(const Measurement &m) const ;
|
|
bool operator!=(const Measurement &m) const ;
|
|
operator bool(void) const ;
|
|
//@}
|
|
|
|
/// Displays a Measurement
|
|
friend std::ostream &operator<<(std::ostream &os, const Measurement &m) ;
|
|
} ;
|
|
|
|
|
|
|
|
/* *** Read accessors *** */
|
|
|
|
|
|
inline AccessPoint* Measurement::get_ap() const
|
|
{
|
|
return ap ;
|
|
}
|
|
|
|
|
|
inline const std::vector<int>& Measurement::get_ss_list() const
|
|
{
|
|
return ss_list ;
|
|
}
|
|
|
|
|
|
inline double Measurement::get_average_ss() const
|
|
{
|
|
return average_ss ;
|
|
}
|
|
|
|
|
|
inline int Measurement::get_ss_list_size() const
|
|
{
|
|
return ss_list.size() ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Write accessors *** */
|
|
|
|
|
|
inline void Measurement::set_ap(const AccessPoint *_ap)
|
|
{
|
|
ap = const_cast<AccessPoint*>(_ap) ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
inline float Measurement::
|
|
ss_square_distance(const Measurement &source) const
|
|
{
|
|
return ss_square_distance(source.average_ss) ;
|
|
}
|
|
|
|
|
|
inline float Measurement::ss_square_distance(const float &ss) const
|
|
{
|
|
return ((ss - average_ss) * (ss - average_ss)) ;
|
|
}
|
|
|
|
|
|
|
|
/* *** Operators *** */
|
|
|
|
|
|
inline bool Measurement::operator!=(const Measurement &m) const
|
|
{
|
|
return !(*this == m) ;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return \em false if the Measurement is empty.
|
|
* @return \em true if at least one attribute is initialised.
|
|
*/
|
|
inline Measurement::operator bool() const
|
|
{
|
|
return
|
|
ap != NULL ||
|
|
! ss_list.empty() ;
|
|
}
|
|
|
|
|
|
|
|
#endif // _OWLPS_POSITIONING_MEASUREMENT_HH_
|