Get rid of the SS - 0x100 problems
In the listener & aggregator, the signal strength is stored as an unsigned byte. To display the actual (negative) value, one must substract 256 (0x100) to the unsigned value. This commit changes several things: - Use the decimal (256) instead of the hexadecimal value (0x100). - Don't substract 256 when copying the value to another unsigned byte (aggregator). - Be careful with the type length. In the positioning server, a SS could be copied to a signed byte, while (theoretically) the negative value can exceed the capacity of the signed byte. measurement.hh now defines a type ss_t to store a signal strength value with the good size (it is currently an int_fast16_t).
This commit is contained in:
parent
5bef966d14
commit
4dc45acff7
|
@ -514,7 +514,7 @@ int read_loop(int sockfd)
|
||||||
mobile_ip_str,
|
mobile_ip_str,
|
||||||
request_time_str,
|
request_time_str,
|
||||||
capture_time_str,
|
capture_time_str,
|
||||||
request.ss_dbm - 0x100,
|
request.ss_dbm - 256,
|
||||||
request.x_position,
|
request.x_position,
|
||||||
request.y_position,
|
request.y_position,
|
||||||
request.z_position,
|
request.z_position,
|
||||||
|
@ -664,8 +664,7 @@ void* monitor_requests(void *NULL_value)
|
||||||
memcpy(info.ap_mac_addr_bytes,
|
memcpy(info.ap_mac_addr_bytes,
|
||||||
request_info_ptr->ap_mac_addr_bytes,
|
request_info_ptr->ap_mac_addr_bytes,
|
||||||
ETHER_ADDR_LEN) ;
|
ETHER_ADDR_LEN) ;
|
||||||
info.ss_dbm =
|
info.ss_dbm = request_info_ptr->ss_dbm ;
|
||||||
request_info_ptr->ss_dbm - 0x100 ;
|
|
||||||
sendto(sockfd, &info, sizeof(info),
|
sendto(sockfd, &info, sizeof(info),
|
||||||
0, (struct sockaddr *)&serv, serv_len) ;
|
0, (struct sockaddr *)&serv, serv_len) ;
|
||||||
|
|
||||||
|
@ -675,7 +674,7 @@ void* monitor_requests(void *NULL_value)
|
||||||
mac_str) ;
|
mac_str) ;
|
||||||
fprintf(fd, ";%s;%d",
|
fprintf(fd, ";%s;%d",
|
||||||
mac_str,
|
mac_str,
|
||||||
request_info_ptr->ss_dbm - 0x100) ;
|
request_info_ptr->ss_dbm - 256) ;
|
||||||
|
|
||||||
// Delete request
|
// Delete request
|
||||||
request_info_ptr = request_info_ptr->next ;
|
request_info_ptr = request_info_ptr->next ;
|
||||||
|
@ -1297,7 +1296,7 @@ void print_request_info(request_info_list *info)
|
||||||
"\tAP MAC: %s\n"
|
"\tAP MAC: %s\n"
|
||||||
"\tSignal strength: %d dBm\n",
|
"\tSignal strength: %d dBm\n",
|
||||||
ap_mac_str,
|
ap_mac_str,
|
||||||
info->ss_dbm - 0x100
|
info->ss_dbm - 256
|
||||||
) ;
|
) ;
|
||||||
}
|
}
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
|
@ -1056,7 +1056,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
request_time_str,
|
request_time_str,
|
||||||
capture_time_str,
|
capture_time_str,
|
||||||
rtap_fields[RTAP_ANTENNASIGNALDBM] ?
|
rtap_fields[RTAP_ANTENNASIGNALDBM] ?
|
||||||
request.ss_dbm - 0x100 : 0,
|
request.ss_dbm - 256 : 0,
|
||||||
owl_ntohf(request.x_position),
|
owl_ntohf(request.x_position),
|
||||||
owl_ntohf(request.y_position),
|
owl_ntohf(request.y_position),
|
||||||
owl_ntohf(request.z_position),
|
owl_ntohf(request.z_position),
|
||||||
|
@ -1152,7 +1152,7 @@ void extract_radiotap_data(const u_char *packet,
|
||||||
rtap_fields[RTAP_ANTENNASIGNALDBM] = owl_true;
|
rtap_fields[RTAP_ANTENNASIGNALDBM] = owl_true;
|
||||||
if (VERBOSE_INFO)
|
if (VERBOSE_INFO)
|
||||||
printf("Antenna signal: %d dBm\n",
|
printf("Antenna signal: %d dBm\n",
|
||||||
request->ss_dbm - 0x100);
|
request->ss_dbm - 256);
|
||||||
rtap_position += RTAP_L_ANTENNASIGNALDBM ;
|
rtap_position += RTAP_L_ANTENNASIGNALDBM ;
|
||||||
break ;
|
break ;
|
||||||
case RTAP_ANTENNANOISEDBM:
|
case RTAP_ANTENNANOISEDBM:
|
||||||
|
|
|
@ -42,11 +42,11 @@ const string InputLogCSV::request_to_csv(const Request &request) const
|
||||||
for (unordered_map<string, Measurement>::const_iterator i
|
for (unordered_map<string, Measurement>::const_iterator i
|
||||||
= measurements.begin() ; i != measurements.end() ; ++i)
|
= measurements.begin() ; i != measurements.end() ; ++i)
|
||||||
{
|
{
|
||||||
const vector<int> &ss_list = i->second.get_ss_list() ;
|
const vector<ss_t> &ss_list = i->second.get_ss_list() ;
|
||||||
const string &ap_mac = i->second.get_ap() != NULL
|
const string &ap_mac = i->second.get_ap() != NULL
|
||||||
? i->second.get_ap()->get_mac_addr()
|
? i->second.get_ap()->get_mac_addr()
|
||||||
: "" ;
|
: "" ;
|
||||||
for (vector<int>::const_iterator i = ss_list.begin() ;
|
for (vector<ss_t>::const_iterator i = ss_list.begin() ;
|
||||||
i != ss_list.end() ; ++i)
|
i != ss_list.end() ; ++i)
|
||||||
{
|
{
|
||||||
csv_line << ';' << ap_mac ;
|
csv_line << ';' << ap_mac ;
|
||||||
|
|
|
@ -167,14 +167,14 @@ bool InputUDPSocket::fill_current_request()
|
||||||
// Substracting 256 is not mandatory here since it is done
|
// Substracting 256 is not mandatory here since it is done
|
||||||
// automatically when casting from unsigned to signed, but
|
// automatically when casting from unsigned to signed, but
|
||||||
// I write it anyway for the sake of clarity.
|
// I write it anyway for the sake of clarity.
|
||||||
int_fast8_t ss = request_info.ss_dbm - 0x100 ;
|
ss_t ss = request_info.ss_dbm - 256 ;
|
||||||
|
|
||||||
if (Configuration::is_configured("verbose"))
|
if (Configuration::is_configured("verbose"))
|
||||||
cout
|
cout
|
||||||
<< "\t* Packet received from the aggregator:"
|
<< "\t* Packet received from the aggregator:"
|
||||||
<< "\n\t\tAP MAC: " << mac_ap
|
<< "\n\t\tAP MAC: " << mac_ap
|
||||||
<< "\n\t\tSignal: "
|
<< "\n\t\tSignal: "
|
||||||
<< static_cast<int_fast16_t>(ss) << " dBm"
|
<< ss << " dBm"
|
||||||
<< '\n' ;
|
<< '\n' ;
|
||||||
|
|
||||||
if (! Configuration::bool_value("positioning.accept-new-aps") &&
|
if (! Configuration::bool_value("positioning.accept-new-aps") &&
|
||||||
|
|
|
@ -16,7 +16,7 @@ Measurement::Measurement(const AccessPoint *_ap):
|
||||||
|
|
||||||
|
|
||||||
Measurement::Measurement(const AccessPoint *_ap,
|
Measurement::Measurement(const AccessPoint *_ap,
|
||||||
const vector<int> &_ss_list):
|
const vector<ss_t> &_ss_list):
|
||||||
ap(const_cast<AccessPoint*>(_ap)), ss_list(_ss_list)
|
ap(const_cast<AccessPoint*>(_ap)), ss_list(_ss_list)
|
||||||
{
|
{
|
||||||
ss_list.reserve(10) ;
|
ss_list.reserve(10) ;
|
||||||
|
@ -41,7 +41,7 @@ Measurement::~Measurement()
|
||||||
/**
|
/**
|
||||||
* @param ss_dbm The signal strength to add to #ss_list (in dBm).
|
* @param ss_dbm The signal strength to add to #ss_list (in dBm).
|
||||||
*/
|
*/
|
||||||
void Measurement::add_ss(const int &ss_dbm)
|
void Measurement::add_ss(const ss_t &ss_dbm)
|
||||||
{
|
{
|
||||||
double total_ss_mwatts =
|
double total_ss_mwatts =
|
||||||
pow(10, static_cast<double>(ss_dbm) / 10.0) + // New SS in mW
|
pow(10, static_cast<double>(ss_dbm) / 10.0) + // New SS in mW
|
||||||
|
@ -54,14 +54,14 @@ void Measurement::add_ss(const int &ss_dbm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Measurement::set_ss_list(const std::vector<int> &_ss_list)
|
void Measurement::set_ss_list(const std::vector<ss_t> &_ss_list)
|
||||||
{
|
{
|
||||||
ss_list = _ss_list ;
|
ss_list = _ss_list ;
|
||||||
update_average_ss() ;
|
update_average_ss() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Measurement::add_ss_list(const std::vector<int> &_ss_list)
|
void Measurement::add_ss_list(const std::vector<ss_t> &_ss_list)
|
||||||
{
|
{
|
||||||
ss_list.insert(ss_list.end(), _ss_list.begin(), _ss_list.end()) ;
|
ss_list.insert(ss_list.end(), _ss_list.begin(), _ss_list.end()) ;
|
||||||
update_average_ss() ;
|
update_average_ss() ;
|
||||||
|
@ -69,8 +69,8 @@ void Measurement::add_ss_list(const std::vector<int> &_ss_list)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge consists of adding the SS values of \em source to #ss_list. It is
|
* Merge consists of adding the SS values of \em source to #ss_list. It
|
||||||
* possible only if the #ap of the two Measurement are identical.
|
* is possible only if the #ap of the two Measurement are identical.
|
||||||
* @throw cannot_merge if the AP of the two Measurement are different.
|
* @throw cannot_merge if the AP of the two Measurement are different.
|
||||||
*/
|
*/
|
||||||
void Measurement::merge(const Measurement &source)
|
void Measurement::merge(const Measurement &source)
|
||||||
|
@ -110,7 +110,7 @@ void Measurement::update_average_ss()
|
||||||
|
|
||||||
double total_ss_mwatts = 0 ;
|
double total_ss_mwatts = 0 ;
|
||||||
|
|
||||||
for (vector<int>::const_iterator i = ss_list.begin() ;
|
for (vector<ss_t>::const_iterator i = ss_list.begin() ;
|
||||||
i != ss_list.end() ; ++i)
|
i != ss_list.end() ; ++i)
|
||||||
// Add the current value in mW to the total
|
// Add the current value in mW to the total
|
||||||
total_ss_mwatts += pow(10, static_cast<double>(*i) / 10.0) ;
|
total_ss_mwatts += pow(10, static_cast<double>(*i) / 10.0) ;
|
||||||
|
@ -161,7 +161,7 @@ ostream &operator<<(ostream &os, const Measurement &m)
|
||||||
if (m.ss_list.empty())
|
if (m.ss_list.empty())
|
||||||
os << "No values" ;
|
os << "No values" ;
|
||||||
else
|
else
|
||||||
for (vector<int>::const_iterator i = m.ss_list.begin() ;
|
for (vector<ss_t>::const_iterator i = m.ss_list.begin() ;
|
||||||
i != m.ss_list.end() ; ++i)
|
i != m.ss_list.end() ; ++i)
|
||||||
{
|
{
|
||||||
os << *i ;
|
os << *i ;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
typedef int_fast16_t ss_t ;
|
||||||
|
|
||||||
/// Represents a list of signal strengths captured by one AccessPoint
|
/// Represents a list of signal strengths captured by one AccessPoint
|
||||||
class Measurement
|
class Measurement
|
||||||
{
|
{
|
||||||
|
@ -14,7 +16,7 @@ protected:
|
||||||
/// The AccessPoint that performed the measurement
|
/// The AccessPoint that performed the measurement
|
||||||
AccessPoint *ap ;
|
AccessPoint *ap ;
|
||||||
/// List of signal strengths captured (in dBm)
|
/// List of signal strengths captured (in dBm)
|
||||||
std::vector<int> ss_list ;
|
std::vector<ss_t> ss_list ;
|
||||||
/// Average of all signal strength captured (dBm)
|
/// Average of all signal strength captured (dBm)
|
||||||
double average_ss ;
|
double average_ss ;
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ public:
|
||||||
Measurement(const AccessPoint *_ap = NULL) ;
|
Measurement(const AccessPoint *_ap = NULL) ;
|
||||||
|
|
||||||
Measurement(const AccessPoint *_ap,
|
Measurement(const AccessPoint *_ap,
|
||||||
const std::vector<int> &_ss_list) ;
|
const std::vector<ss_t> &_ss_list) ;
|
||||||
|
|
||||||
Measurement(const Measurement &source):
|
Measurement(const Measurement &source):
|
||||||
ap(source.ap), ss_list(source.ss_list),
|
ap(source.ap), ss_list(source.ss_list),
|
||||||
|
@ -40,7 +42,7 @@ public:
|
||||||
/** @name Read accessors */
|
/** @name Read accessors */
|
||||||
//@{
|
//@{
|
||||||
AccessPoint* get_ap() const ;
|
AccessPoint* get_ap() const ;
|
||||||
const std::vector<int>& get_ss_list() const ;
|
const std::vector<ss_t>& get_ss_list() const ;
|
||||||
double get_average_ss() const ;
|
double get_average_ss() const ;
|
||||||
int get_ss_list_size() const ;
|
int get_ss_list_size() const ;
|
||||||
//@}
|
//@}
|
||||||
|
@ -48,11 +50,11 @@ public:
|
||||||
/** @name Write accessors */
|
/** @name Write accessors */
|
||||||
//@{
|
//@{
|
||||||
void set_ap(const AccessPoint *_ap) ;
|
void set_ap(const AccessPoint *_ap) ;
|
||||||
void set_ss_list(const std::vector<int> &_ss_list) ;
|
void set_ss_list(const std::vector<ss_t> &_ss_list) ;
|
||||||
/// Adds a signal strength to #ss_list
|
/// Adds a signal strength to #ss_list
|
||||||
void add_ss(const int &ss_dbm) ;
|
void add_ss(const ss_t &ss_dbm) ;
|
||||||
/// Adds several signal strengths to #ss_list
|
/// Adds several signal strengths to #ss_list
|
||||||
void add_ss_list(const std::vector<int> &_ss_list) ;
|
void add_ss_list(const std::vector<ss_t> &_ss_list) ;
|
||||||
/// Merges a given Measurement into the current Measurement
|
/// Merges a given Measurement into the current Measurement
|
||||||
void merge(const Measurement &source) ;
|
void merge(const Measurement &source) ;
|
||||||
void clear(void) ;
|
void clear(void) ;
|
||||||
|
@ -89,7 +91,7 @@ inline AccessPoint* Measurement::get_ap() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const std::vector<int>& Measurement::get_ss_list() const
|
inline const std::vector<ss_t>& Measurement::get_ss_list() const
|
||||||
{
|
{
|
||||||
return ss_list ;
|
return ss_list ;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue