93 lines
1.6 KiB
C++
93 lines
1.6 KiB
C++
#include "posutil.hh"
|
|
|
|
|
|
|
|
/*
|
|
* Returns the frequency in Hz corresponding to the 802.11 channel "channel"
|
|
* or 0 if the channel is wrong.
|
|
*/
|
|
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
|
|
}
|
|
|
|
|
|
|
|
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 ;
|
|
}
|
|
|
|
|
|
|
|
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 ;
|
|
}
|