[Positioning] PosUtil::wifi_channel_to_hz(): throw exception
posexcept: Add exception bad_channel. PosUtil::wifi_channel_to_hz() now throw bad_channel if the argument is not a valid channel nor a 802.11 frequency value in Hz.
This commit is contained in:
parent
338e4f7dcd
commit
6f0c0af5be
|
@ -31,10 +31,6 @@
|
||||||
les Waypoint. Si oui, faut-il aussi les enlever des listes dans
|
les Waypoint. Si oui, faut-il aussi les enlever des listes dans
|
||||||
Stock ? (Pour l'instant ils ne sont pas dans Stock.)
|
Stock ? (Pour l'instant ils ne sont pas dans Stock.)
|
||||||
|
|
||||||
- AccessPoint
|
|
||||||
° Lancer une exception si le canal Wi-Fi est mauvais (ou
|
|
||||||
directement dans PosUtil::channel_to_frequency() ?).
|
|
||||||
|
|
||||||
- ReferencePoint
|
- ReferencePoint
|
||||||
° La liste des requêtes devrait être un unordered_set (et pas un
|
° La liste des requêtes devrait être un unordered_set (et pas un
|
||||||
vector), pour garantir l'unicité des entrées.
|
vector), pour garantir l'unicité des entrées.
|
||||||
|
|
|
@ -51,6 +51,15 @@ bad_direction::bad_direction(const char direction) throw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bad_channel::bad_channel(const unsigned long channel) throw()
|
||||||
|
{
|
||||||
|
ostringstream message ;
|
||||||
|
message << "`" << channel
|
||||||
|
<< "` is not a valid channel value!" ;
|
||||||
|
explanation = message.str() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
null_input_medium::null_input_medium() throw():
|
null_input_medium::null_input_medium() throw():
|
||||||
posexcept("The input medium is not initialised!") {}
|
posexcept("The input medium is not initialised!") {}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,13 @@ public:
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
class bad_channel: public posexcept
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bad_channel(const unsigned long channel) throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
class null_input_medium: public posexcept
|
class null_input_medium: public posexcept
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "posutil.hh"
|
#include "posutil.hh"
|
||||||
|
#include "posexcept.hh"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Wi-Fi channel frequencies in MHz */
|
/* Wi-Fi channel frequencies in Hz */
|
||||||
#define CHANNEL_1 2412000000ul
|
#define CHANNEL_1 2412000000ul
|
||||||
#define CHANNEL_2 2417000000ul
|
#define CHANNEL_2 2417000000ul
|
||||||
#define CHANNEL_3 2422000000ul
|
#define CHANNEL_3 2422000000ul
|
||||||
|
@ -21,12 +22,12 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param channel A IEEE 802.11 channel.
|
* @param channel A IEEE 802.11 channel or frequency in Hz.
|
||||||
* @return The frequency in Hz or 0 if the channel is wrong.
|
* @return The frequency in Hz.
|
||||||
* Note that if \em channel is a frequency in Hz, this function will
|
* @throw malformed_input_data if \em channel is not a valid channel or
|
||||||
* consider it as a wrong value and return 0.
|
* frequency value.
|
||||||
*/
|
*/
|
||||||
unsigned long PosUtil::wifi_channel_to_hz(const unsigned int &channel)
|
unsigned long PosUtil::wifi_channel_to_hz(const unsigned long &channel)
|
||||||
{
|
{
|
||||||
switch (channel)
|
switch (channel)
|
||||||
{
|
{
|
||||||
|
@ -74,5 +75,6 @@ unsigned long PosUtil::wifi_channel_to_hz(const unsigned int &channel)
|
||||||
return CHANNEL_14 ;
|
return CHANNEL_14 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0 ; // Error: wrong channel value
|
// Error: wrong channel value
|
||||||
|
throw bad_channel(channel) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
/** @name Wi-Fi */
|
/** @name Wi-Fi */
|
||||||
//@{
|
//@{
|
||||||
/// Converts a Wi-Fi channel to the corresponding frequency in Hz
|
/// Converts a Wi-Fi channel to the corresponding frequency in Hz
|
||||||
static unsigned long wifi_channel_to_hz(const unsigned int &channel) ;
|
static unsigned long wifi_channel_to_hz(const unsigned long &channel) ;
|
||||||
//@}
|
//@}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue