diff --git a/owlps-positioning/TODO b/owlps-positioning/TODO index e8c44fb..d148df6 100644 --- a/owlps-positioning/TODO +++ b/owlps-positioning/TODO @@ -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. diff --git a/owlps-positioning/src/posexcept.cc b/owlps-positioning/src/posexcept.cc index 717187a..1f1fcde 100644 --- a/owlps-positioning/src/posexcept.cc +++ b/owlps-positioning/src/posexcept.cc @@ -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!") {} diff --git a/owlps-positioning/src/posexcept.hh b/owlps-positioning/src/posexcept.hh index 27ba7cc..80a78fc 100644 --- a/owlps-positioning/src/posexcept.hh +++ b/owlps-positioning/src/posexcept.hh @@ -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: diff --git a/owlps-positioning/src/posutil.cc b/owlps-positioning/src/posutil.cc index 060d4ef..1b2b3b0 100644 --- a/owlps-positioning/src/posutil.cc +++ b/owlps-positioning/src/posutil.cc @@ -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) ; } diff --git a/owlps-positioning/src/posutil.hh b/owlps-positioning/src/posutil.hh index aa66643..fd1e274 100644 --- a/owlps-positioning/src/posutil.hh +++ b/owlps-positioning/src/posutil.hh @@ -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) ; //@} } ;