00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_TIME_CONVERTER_HXX_
00023 # define WIFI_TIME_CONVERTER_HXX_
00024
00025 extern "C"
00026 {
00027 # include <sys/time.h>
00028 }
00029
00030 # include "time_converter.hh"
00031
00032 namespace wifi
00033 {
00034
00035 template <class PHT, class Bottom>
00036 time_converter<PHT, Bottom>::
00037 time_converter(const pcap_time_type& local_pcap_time,
00038 const phy_time_type& local_phy_time,
00039 const tool::microseconds& global_time):
00040 super_type (),
00041 local_reference_ (local_pcap_time, local_phy_time),
00042 global_reference_ (global_time)
00043 {
00044 }
00045
00046 template <class PHT, class Bottom>
00047 time_converter<PHT, Bottom>::time_values::time_values()
00048 {
00049 }
00050
00051 template <class PHT, class Bottom>
00052 time_converter<PHT, Bottom>::
00053 time_values::time_values(const pcap_time_type& pcap_time,
00054 const phy_time_type& phy_time):
00055 pcap_time (pcap_time),
00056 phy_time (phy_time)
00057 {
00058 }
00059
00060 template <class PHT, class Bottom>
00061 typename time_converter<PHT, Bottom>::time_values
00062 time_converter<PHT, Bottom>::
00063 operator () (const tool::microseconds& global_time) const
00064 {
00065 const mpz_class dt = global_time - global_reference_;
00066 struct timeval dt_tv;
00067 {
00068 mpz_class dsec;
00069
00070 dt_tv.tv_usec = mpz_tdiv_q_ui(dsec.get_mpz_t(),
00071 mpz_class (abs(dt)).get_mpz_t(),
00072 1000000);
00073 assert(dsec.fits_uint_p());
00074
00075 dt_tv.tv_sec = dsec.get_ui();
00076 }
00077
00078 time_values r;
00079
00080 if (sgn(dt) < 0)
00081 timersub(&local_reference_.pcap_time, &dt_tv, &r.pcap_time);
00082 else
00083 timeradd(&local_reference_.pcap_time, &dt_tv, &r.pcap_time);
00084 r.phy_time = local_reference_.phy_time + dt;
00085 return r;
00086 }
00087
00088 }
00089
00090 #endif // ! WIFI_TIME_CONVERTER_HXX_