owlps/owlps-positioning/wifidevice.hh

140 lines
2.9 KiB
C++

#ifndef _OWLPS_POSITIONING_WIFIDEVICE_HH_
#define _OWLPS_POSITIONING_WIFIDEVICE_HH_
#include "posutil.hh"
#include <string>
#include <ostream>
#define WIFIDEVICE_DEFAULT_ANTENNA_GAIN 2
#define WIFIDEVICE_DEFAULT_TRX_POWER 20 // 20 dBm = 100 mW
/// Represents a Wi-Fi enabled device
/**
* This class is virtual, you have to derive it to create new types of
* Wi-Fi devices.
*/
class WifiDevice
{
protected:
std::string ip_addr ; ///< IP address
std::string mac_addr ; ///< MAC address
float antenna_gain ; ///< Antenna gain in dBi
float trx_power ; ///< Transmit power in dBm
public:
/// Constructs a WifiDevice by defining all (or none) of its attributes
WifiDevice(const std::string &_ip_addr = "",
const std::string &_mac_addr = "",
const float &_antenna_gain = WIFIDEVICE_DEFAULT_ANTENNA_GAIN,
const float &_trx_power = WIFIDEVICE_DEFAULT_TRX_POWER) ;
/// Copy constructor
WifiDevice(const WifiDevice &wd) ;
~WifiDevice(void) {} ///< Destructor (do nothing)
/** @name Read accessors */
//@{
/// #ip_addr read accessor
const std::string& get_ip_addr(void) const ;
/// #mac_addr read accessor
const std::string& get_mac_addr(void) const ;
/// #antenna_gain read accessor
float get_antenna_gain(void) const ;
/// #trx_power read accessor
float get_trx_power(void) const ;
//@}
/** @name Write accessors */
//@{
/// #ip_addr write accessor
void set_ip_addr(const std::string &_ip_addr) ;
/// #mac_addr write accessor
void set_mac_addr(const std::string &_mac_addr) ;
/// #antenna_gain write accessor
void set_antenna_gain(float &_antenna_gain) ;
/// #trx_power write accessor
void set_trx_power(float &_trx_power) ;
//@}
/** @name Operators */
//@{
const WifiDevice& operator=(const WifiDevice &wd) ;
bool operator==(const WifiDevice &wd) const ;
bool operator!=(const WifiDevice &wl) const ;
//@}
/// Displays a WifiDevice
friend std::ostream &operator<<(std::ostream &os, const WifiDevice &wd) ;
} ;
/* *** Read accessors *** */
inline const std::string& WifiDevice::get_ip_addr() const
{
return ip_addr ;
}
inline const std::string& WifiDevice::get_mac_addr() const
{
return mac_addr ;
}
inline float WifiDevice::get_antenna_gain() const
{
return antenna_gain ;
}
inline float WifiDevice::get_trx_power() const
{
return trx_power ;
}
/* *** Write accessors *** */
inline void WifiDevice::set_ip_addr(const std::string &_ip_addr)
{
ip_addr = _ip_addr ;
}
inline void WifiDevice::set_mac_addr(const std::string &_mac_addr)
{
mac_addr = _mac_addr ;
}
inline void WifiDevice::set_antenna_gain(float &_antenna_gain)
{
antenna_gain = PosUtil::channel_to_frequency(_antenna_gain) ;
}
inline void WifiDevice::set_trx_power(float &_trx_power)
{
trx_power = _trx_power ;
}
/* *** Operators *** */
inline bool WifiDevice::operator!=(const WifiDevice &wd) const
{
return !(*this == wd) ;
}
#endif // _OWLPS_POSITIONING_WIFIDEVICE_HH_