[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
|
||||
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
|
||||
° La liste des requêtes devrait être un unordered_set (et pas un
|
||||
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():
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "posutil.hh"
|
||||
#include "posexcept.hh"
|
||||
|
||||
|
||||
|
||||
/* Wi-Fi channel frequencies in MHz */
|
||||
/* Wi-Fi channel frequencies in Hz */
|
||||
#define CHANNEL_1 2412000000ul
|
||||
#define CHANNEL_2 2417000000ul
|
||||
#define CHANNEL_3 2422000000ul
|
||||
|
@ -21,12 +22,12 @@
|
|||
|
||||
|
||||
/**
|
||||
* @param channel A IEEE 802.11 channel.
|
||||
* @return The frequency in Hz or 0 if the channel is wrong.
|
||||
* Note that if \em channel is a frequency in Hz, this function will
|
||||
* consider it as a wrong value and return 0.
|
||||
* @param channel A IEEE 802.11 channel or frequency in Hz.
|
||||
* @return The frequency in Hz.
|
||||
* @throw malformed_input_data if \em channel is not a valid channel or
|
||||
* 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)
|
||||
{
|
||||
|
@ -74,5 +75,6 @@ unsigned long PosUtil::wifi_channel_to_hz(const unsigned int &channel)
|
|||
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 */
|
||||
//@{
|
||||
/// 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