[Positioning] Fix AccessPoint & WifiDevice
AccessPoint: - Fix a bug with the frequency. - Add an accessor set_channel() that calls set_frequency(). WifiDevice: - Fix a bug with the antenna gain (which was converted with PosUtil::channel_to_frequency()). - Pass float arguments as values and not references.
This commit is contained in:
parent
efac35a515
commit
d8c604f3ba
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "wifidevice.hh"
|
||||
#include "point3d.hh"
|
||||
#include "posutil.hh"
|
||||
|
||||
#define AP_DEFAULT_CHANNEL 6
|
||||
#define AP_DEFAULT_ANTENNA_GAIN 5
|
||||
|
@ -17,20 +18,31 @@ protected:
|
|||
public:
|
||||
/// \brief Constructs an AccessPoint by defining all of its
|
||||
/// attributes (or default constructor)
|
||||
/**
|
||||
* @param _coordinates Coordinates.
|
||||
* @param _ip_addr IP address.
|
||||
* @param _mac_addr MAC address.
|
||||
* @param _antenna_gain Antenna gain in dBi.
|
||||
* @param _trx_power Transmit power in dBm.
|
||||
* @param channel Wi-Fi channel the AP is listening to (integer
|
||||
* between 1 and 14). It will be converted to a frequency in Hz.
|
||||
*/
|
||||
AccessPoint(const Point3D &_coordinates = Point3D(),
|
||||
const std::string &_ip_addr = "",
|
||||
const std::string &_mac_addr = "",
|
||||
const float &_antenna_gain = AP_DEFAULT_ANTENNA_GAIN,
|
||||
const float &_trx_power = WIFIDEVICE_DEFAULT_TRX_POWER,
|
||||
const unsigned int &_frequency = AP_DEFAULT_CHANNEL):
|
||||
const unsigned int &channel = AP_DEFAULT_CHANNEL):
|
||||
WifiDevice(_ip_addr, _mac_addr, _antenna_gain, _trx_power),
|
||||
coordinates(_coordinates), frequency(_frequency) {}
|
||||
coordinates(_coordinates),
|
||||
frequency(PosUtil::channel_to_frequency(channel)) {}
|
||||
|
||||
/// Constructs an AccessPoint from a WifiDevice, a Point3D and a frequency
|
||||
AccessPoint(const WifiDevice &wd,
|
||||
const Point3D &_coordinates,
|
||||
const unsigned int &_frequency = AP_DEFAULT_CHANNEL):
|
||||
WifiDevice(wd), coordinates(_coordinates), frequency(_frequency) {}
|
||||
const unsigned int &channel = AP_DEFAULT_CHANNEL):
|
||||
WifiDevice(wd), coordinates(_coordinates),
|
||||
frequency(PosUtil::channel_to_frequency(channel)) {}
|
||||
|
||||
/// Constructs an AccessPoint from a WifiDevice
|
||||
AccessPoint(const WifiDevice &wd):
|
||||
|
@ -54,6 +66,8 @@ public:
|
|||
//@{
|
||||
/// #coordinates write accessor
|
||||
void set_coordinates(const Point3D &_coordinates) ;
|
||||
/// Set #frequency with a Wi-Fi channel
|
||||
void set_channel(const unsigned int channel) ;
|
||||
/// #frequency write accessor
|
||||
void set_frequency(const unsigned int _frequency) ;
|
||||
//@}
|
||||
|
@ -96,6 +110,24 @@ inline void AccessPoint::set_coordinates(const Point3D &_coordinates)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param channel A Wi-Fi channel (integer between 1 and 14). It will
|
||||
* be converted into a frequency in Hz and affected to #frequency. If
|
||||
* it is not a Wi-Fi channel number, 0 will be affected to #frequency.
|
||||
*/
|
||||
inline void AccessPoint::set_channel(const unsigned int channel)
|
||||
{
|
||||
set_frequency(PosUtil::channel_to_frequency(channel)) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets #frequency with the value of the parameter \em _frequency. No
|
||||
* control is done, so you should pass a correct value.
|
||||
*
|
||||
* Note that set_channel() is more secure because a wrong channel
|
||||
* number will cause #frequency to be nullified.
|
||||
*/
|
||||
inline void AccessPoint::set_frequency(const unsigned int _frequency)
|
||||
{
|
||||
frequency = _frequency ;
|
||||
|
|
|
@ -9,12 +9,12 @@ using namespace std ;
|
|||
|
||||
WifiDevice::WifiDevice(const string &_ip_addr,
|
||||
const string &_mac_addr,
|
||||
const float &_antenna_gain,
|
||||
const float &_trx_power)
|
||||
const float _antenna_gain,
|
||||
const float _trx_power)
|
||||
{
|
||||
ip_addr = _ip_addr ;
|
||||
mac_addr = _mac_addr ;
|
||||
antenna_gain = PosUtil::channel_to_frequency(_antenna_gain) ;
|
||||
antenna_gain = _antenna_gain ;
|
||||
trx_power = _trx_power ;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef _OWLPS_POSITIONING_WIFIDEVICE_HH_
|
||||
#define _OWLPS_POSITIONING_WIFIDEVICE_HH_
|
||||
|
||||
#include "posutil.hh"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
|
@ -11,8 +9,8 @@
|
|||
|
||||
/// Represents a Wi-Fi enabled device
|
||||
/**
|
||||
* This class is virtual, you have to derive it to create new types of
|
||||
* Wi-Fi devices.
|
||||
* This class is virtual by design, you should derive it to create new
|
||||
* types of Wi-Fi devices.
|
||||
*/
|
||||
class WifiDevice
|
||||
{
|
||||
|
@ -26,12 +24,12 @@ 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) ;
|
||||
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)
|
||||
virtual ~WifiDevice(void) {} ///< Destructor (do nothing)
|
||||
|
||||
/** @name Read accessors */
|
||||
//@{
|
||||
|
@ -52,9 +50,9 @@ public:
|
|||
/// #mac_addr write accessor
|
||||
void set_mac_addr(const std::string &_mac_addr) ;
|
||||
/// #antenna_gain write accessor
|
||||
void set_antenna_gain(float &_antenna_gain) ;
|
||||
void set_antenna_gain(float _antenna_gain) ;
|
||||
/// #trx_power write accessor
|
||||
void set_trx_power(float &_trx_power) ;
|
||||
void set_trx_power(float _trx_power) ;
|
||||
//@}
|
||||
|
||||
/** @name Operators */
|
||||
|
@ -113,13 +111,13 @@ inline void WifiDevice::set_mac_addr(const std::string &_mac_addr)
|
|||
}
|
||||
|
||||
|
||||
inline void WifiDevice::set_antenna_gain(float &_antenna_gain)
|
||||
inline void WifiDevice::set_antenna_gain(float _antenna_gain)
|
||||
{
|
||||
antenna_gain = PosUtil::channel_to_frequency(_antenna_gain) ;
|
||||
antenna_gain = _antenna_gain ;
|
||||
}
|
||||
|
||||
|
||||
inline void WifiDevice::set_trx_power(float &_trx_power)
|
||||
inline void WifiDevice::set_trx_power(float _trx_power)
|
||||
{
|
||||
trx_power = _trx_power ;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue