owlps/owlps-positioning/src/measurement.hh

138 lines
2.9 KiB
C++
Raw Normal View History

#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:
/// Constructs a Measurement from an AccessPoint (or default constructor)
Measurement(const AccessPoint *_ap = NULL) ;
/// \brief Constructs a Measurement from an AccessPoint and a list
/// of signal strengths
Measurement(const AccessPoint *_ap,
const std::vector<int> &_ss_list) ;
/// Copy constructor
Measurement(const Measurement &m) ;
~Measurement(void) ; ///< Destructor
/** @name Read accessors */
//@{
/// #ap read accessor
AccessPoint* get_ap() const ;
/// #ss_list read accessor
const std::vector<int>& get_ss_list() const ;
/// #average_ss read accessor
double get_average_ss() const ;
//float get_ss_square_distance(const float &ss) const ;
//@}
/** @name Write accessors */
//@{
/// #ap write accessor
void set_ap(const AccessPoint *_ap) ;
/// Adds a signal strength to #ss_list
void add_ss(const int &ss_dbm) ;
/// #ss_list write accessor
void set_ss_list(const std::vector<int> &_ss_list) ;
/// Reinitialises the Measurement
void clear(void) ;
//@}
/** @name Operators */
//@{
const Measurement& operator=(const Measurement &m) ;
bool operator==(const Measurement &m) const ;
bool operator!=(const Measurement &m) const ;
operator bool(void) const ; ///< Cast to bool operator
//@}
/// 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 float Measurement::get_ss_square_distance(const float &ss) const
// {
// return ((ss - average_ss) * (ss - average_ss)) ;
// }
/* *** Write accessors *** */
inline void Measurement::set_ap(const AccessPoint *_ap)
{
ap = const_cast<AccessPoint*>(_ap) ;
}
/* *** 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.size() > 0 ;
}
#endif // _OWLPS_POSITIONING_MEASUREMENT_HH_