167 lines
3.4 KiB
C++
167 lines
3.4 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
|
|
#ifndef _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
#define _OWLPS_POSITIONING_MEASUREMENT_HH_
|
|
|
|
#include "accesspoint.hh"
|
|
|
|
#include <map>
|
|
#include <ostream>
|
|
#include <cmath>
|
|
|
|
typedef uint_fast16_t pkt_id_t ;
|
|
typedef int_fast16_t ss_t ;
|
|
|
|
/// 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::map<pkt_id_t, ss_t> 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):
|
|
ap(const_cast<AccessPoint*>(_ap)), average_ss(0) {}
|
|
|
|
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 ;
|
|
double get_average_ss() const ;
|
|
int get_ss_list_size() const ;
|
|
//@}
|
|
|
|
/** @name Write accessors */
|
|
//@{
|
|
void set_ap(const AccessPoint *_ap) ;
|
|
/// Adds a signal strength to #ss_list
|
|
void add_ss(const pkt_id_t packet_id, const ss_t ss_dbm) ;
|
|
/// Adds several signal strengths to #ss_list
|
|
void add_ss_list(const std::map<pkt_id_t, ss_t> &_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 ;
|
|
//@}
|
|
|
|
/** @name Conversion accessors */
|
|
//@{
|
|
/// Converts to a CSV string
|
|
const std::string to_csv(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 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_
|