102 lines
2.0 KiB
C++
102 lines
2.0 KiB
C++
#include "posutil.hh"
|
|
|
|
|
|
|
|
/**
|
|
* @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.
|
|
*/
|
|
unsigned int PosUtil::channel_to_frequency(const int &channel)
|
|
{
|
|
switch (channel)
|
|
{
|
|
case 1:
|
|
case CHANNEL_1:
|
|
return CHANNEL_1 ;
|
|
case 2:
|
|
case CHANNEL_2:
|
|
return CHANNEL_2 ;
|
|
case 3:
|
|
case CHANNEL_3:
|
|
return CHANNEL_3 ;
|
|
case 4:
|
|
case CHANNEL_4:
|
|
return CHANNEL_4 ;
|
|
case 5:
|
|
case CHANNEL_5:
|
|
return CHANNEL_5 ;
|
|
case 6:
|
|
case CHANNEL_6:
|
|
return CHANNEL_6 ;
|
|
case 7:
|
|
case CHANNEL_7:
|
|
return CHANNEL_7 ;
|
|
case 8:
|
|
case CHANNEL_8:
|
|
return CHANNEL_8 ;
|
|
case 9:
|
|
case CHANNEL_9:
|
|
return CHANNEL_9 ;
|
|
case 10:
|
|
case CHANNEL_10:
|
|
return CHANNEL_10 ;
|
|
case 11:
|
|
case CHANNEL_11:
|
|
return CHANNEL_11 ;
|
|
case 12:
|
|
case CHANNEL_12:
|
|
return CHANNEL_12 ;
|
|
case 13:
|
|
case CHANNEL_13:
|
|
return CHANNEL_13 ;
|
|
case 14:
|
|
case CHANNEL_14:
|
|
return CHANNEL_14 ;
|
|
}
|
|
|
|
return 0 ; // Error: wrong channel value
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 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 ;
|
|
}
|
|
|
|
|
|
|
|
struct timespec PosUtil::ms_to_timespec(const uint64_t &tms)
|
|
{
|
|
struct timespec d ;
|
|
d.tv_sec = tms / 1000 ;
|
|
d.tv_nsec = (tms - d.tv_sec * 1000) * 1000000 ;
|
|
return d ;
|
|
}
|