[Positioning] Fix some errors
Fix some errors revealed during writing of unit tests. Building: Fix wrong #ifndef in building.hh. Measurement: New default constructor. PosUtil: - Remove nanosecond-precision functions. - Add timespec_round_to_ms() to lower the precision of a struct timespec to millisecond. - Add timespec_equals to compare two struct timespec (maybe an operator==() would be better?).
This commit is contained in:
parent
f4c825c2d9
commit
7c6492645d
|
@ -1,4 +1,7 @@
|
|||
|
||||
- const_iterator
|
||||
Utiliser const_iterator quand on ne modifie pas la valeur pointée.
|
||||
|
||||
- InputCSV
|
||||
° Différencier une requête normale d'une requête de calibration, en
|
||||
utilisant les champs de direction.
|
||||
|
@ -33,6 +36,9 @@
|
|||
- Request
|
||||
Constructeur par recopie, operator==(), etc.
|
||||
|
||||
- PosUtil
|
||||
Remplacer timespec_equals() par operator==(timespec, timespec) ?
|
||||
|
||||
- AccessPoint
|
||||
Attribut float friis_index ?
|
||||
|
||||
|
@ -47,3 +53,4 @@
|
|||
Espaces de noms ? 109
|
||||
Réserver l'espace mémoire des vector avec reserve(). 217
|
||||
Utiliser hash_map plutôt que map s'il n'y a pas besoin de trier. 252
|
||||
Copie de conteneur vers un flux (cas de certains operator<<). 275
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||
#define _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||
#ifndef _OWLPS_POSITIONING_BUILDING_HH_
|
||||
#define _OWLPS_POSITIONING_BUILDING_HH_
|
||||
|
||||
class Area ;
|
||||
class Waypoint ;
|
||||
|
@ -121,4 +121,4 @@ inline bool Building::operator!=(const Building &b) const
|
|||
|
||||
|
||||
|
||||
#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||
#endif // _OWLPS_POSITIONING_BUILDING_HH_
|
||||
|
|
|
@ -113,7 +113,7 @@ const Request& InputCSV::get_next_request()
|
|||
}
|
||||
try
|
||||
{
|
||||
current_request.set_timestamp(PosUtil::ns_to_timespec
|
||||
current_request.set_timestamp(PosUtil::ms_to_timespec
|
||||
(lexical_cast<uint64_t>(*ti))) ;
|
||||
}
|
||||
catch (bad_lexical_cast &e)
|
||||
|
|
|
@ -8,6 +8,14 @@ using namespace std ;
|
|||
/* *** Constructors *** */
|
||||
|
||||
|
||||
Measurement::Measurement(const AccessPoint *_ap)
|
||||
{
|
||||
ap = const_cast<AccessPoint*>(_ap) ;
|
||||
ss_list.reserve(10) ;
|
||||
average_ss = 0 ;
|
||||
}
|
||||
|
||||
|
||||
Measurement::Measurement(const AccessPoint *_ap,
|
||||
const vector<int> &_ss_list)
|
||||
{
|
||||
|
|
|
@ -22,10 +22,12 @@ protected:
|
|||
void update_average_ss(void) ;
|
||||
|
||||
public:
|
||||
/// Constructs a Measurement from an AccessPoint (or default constructor)
|
||||
Measurement(const AccessPoint *_ap = NULL) ;
|
||||
/// \brief Constructs a Measurement from an AccessPoint and a list
|
||||
/// of signal strengths (or default constructor)
|
||||
Measurement(const AccessPoint *_ap = NULL,
|
||||
const std::vector<int> &_ss_list = std::vector<int>()) ;
|
||||
/// of signal strengths
|
||||
Measurement(const AccessPoint *_ap,
|
||||
const std::vector<int> &_ss_list) ;
|
||||
/// Copy constructor
|
||||
Measurement(const Measurement &m) ;
|
||||
|
||||
|
|
|
@ -61,6 +61,30 @@ unsigned int PosUtil::channel_to_frequency(const int &channel)
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* d.tv_nsec precision is set to ms, but the value is still in ns.
|
||||
* @param d The date to round.
|
||||
*/
|
||||
void PosUtil::timespec_round_to_ms(struct timespec &d)
|
||||
{
|
||||
d.tv_nsec = d.tv_nsec / 1000000 * 1000000 ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \em true if the two dates are equals.
|
||||
* @return \em false if they are different.
|
||||
*/
|
||||
bool PosUtil::timespec_equals(const struct timespec &d1,
|
||||
const struct timespec &d2)
|
||||
{
|
||||
return
|
||||
d1.tv_sec == d2.tv_sec &&
|
||||
d1.tv_nsec == d2.tv_nsec ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t PosUtil::timespec_to_ms(const struct timespec &d)
|
||||
{
|
||||
return d.tv_sec * 1000 + d.tv_nsec / 1000000 ;
|
||||
|
@ -75,20 +99,3 @@ struct timespec PosUtil::ms_to_timespec(const uint64_t &tms)
|
|||
d.tv_nsec = (tms - d.tv_sec * 1000) * 1000000 ;
|
||||
return d ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t PosUtil::timespec_to_ns(const struct timespec &d)
|
||||
{
|
||||
return d.tv_sec * 1000000000 + d.tv_nsec ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct timespec PosUtil::ns_to_timespec(const uint64_t &tns)
|
||||
{
|
||||
struct timespec d ;
|
||||
d.tv_sec = tns / 1000000000 ;
|
||||
d.tv_nsec = tns - d.tv_sec * 1000000000 ;
|
||||
return d ;
|
||||
}
|
||||
|
|
|
@ -32,14 +32,15 @@ public:
|
|||
|
||||
/** @name Time & Dates */
|
||||
//@{
|
||||
/// Lowers the precision of a \em timespec to ms
|
||||
static void timespec_round_to_ms(struct timespec &d) ;
|
||||
/// Compares two struct timespec
|
||||
static bool timespec_equals(const struct timespec &d1,
|
||||
const struct timespec &d2) ;
|
||||
/// Converts a struct timespec into a value in milliseconds
|
||||
static uint64_t timespec_to_ms(const struct timespec &d) ;
|
||||
/// Converts a time value in milliseconds into a struct timespec
|
||||
static struct timespec ms_to_timespec(const uint64_t &tms) ;
|
||||
/// Converts a struct timespec into a value in nanoseconds
|
||||
static uint64_t timespec_to_ns(const struct timespec &d) ;
|
||||
/// Converts a time value in nanoseconds into a struct timespec
|
||||
static struct timespec ns_to_timespec(const uint64_t &tns) ;
|
||||
//@}
|
||||
} ;
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ ostream &operator<<(ostream &os, const Request &r)
|
|||
{
|
||||
// Timestamp
|
||||
os
|
||||
<< "At " << PosUtil::timespec_to_ns(r.timestamp) << "; " ;
|
||||
<< "At " << PosUtil::timespec_to_ms(r.timestamp) << "; " ;
|
||||
|
||||
// MAC address
|
||||
os
|
||||
|
|
|
@ -18,7 +18,8 @@ protected:
|
|||
/// Local date of the request on the mobile
|
||||
struct timespec timestamp ;
|
||||
/// List of Measurement of the request
|
||||
/** Note that this is not a pointer list, values are actually stored. */
|
||||
/** Note that this is not a pointer list, values are actually stored.
|
||||
The \em string parameter is the MAC address of the AP. */
|
||||
std::tr1::unordered_map<std::string, Measurement> measurements ;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue