Replace sys/time.h with <chrono> for portability/modernization.
This commit is contained in:
committed by
Bastian Bloessl
parent
a15d6bb34f
commit
28be829378
+3
-3
@@ -51,11 +51,11 @@ if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
|
||||
endif()
|
||||
|
||||
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
SET(CMAKE_CXX_STANDARD 14)
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
SET(CMAKE_CXX_STANDARD 14)
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
SET(CMAKE_CXX_STANDARD 14)
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
ELSE()
|
||||
message(WARNING "C++ standard could not be set because compiler is not GNU, Clang or MSVC.")
|
||||
ENDIF()
|
||||
|
||||
+7
-4
@@ -16,8 +16,8 @@
|
||||
*/
|
||||
#include <foo/packet_pad2.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef FOO_UHD
|
||||
#include <uhd/types/time_spec.hpp>
|
||||
#endif
|
||||
@@ -65,9 +65,12 @@ int work (int noutput_items, gr_vector_int& ninput_items,
|
||||
#ifdef FOO_UHD
|
||||
if(d_delay) {
|
||||
static const pmt::pmt_t time_key = pmt::string_to_symbol("tx_time");
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
uhd::time_spec_t now = uhd::time_spec_t(t.tv_sec + t.tv_usec / 1000000.0)
|
||||
double t_now(
|
||||
std::chrono::duration<double>(std::chrono::system_clock::now()
|
||||
.time_since_epoch()
|
||||
).count()
|
||||
);
|
||||
uhd::time_spec_t now = uhd::time_spec_t(t_now)
|
||||
+ uhd::time_spec_t(d_delay_sec);
|
||||
|
||||
const pmt::pmt_t time_value = pmt::make_tuple(
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
*/
|
||||
#include "packet_pad_impl.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include <iostream>
|
||||
#include <sys/time.h>
|
||||
#ifdef FOO_UHD
|
||||
#include <uhd/types/time_spec.hpp>
|
||||
#endif
|
||||
@@ -58,9 +58,12 @@ packet_pad_impl::add_sob(uint64_t item) {
|
||||
#ifdef FOO_UHD
|
||||
if(d_delay) {
|
||||
static const pmt::pmt_t time_key = pmt::string_to_symbol("tx_time");
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
uhd::time_spec_t now = uhd::time_spec_t(t.tv_sec + t.tv_usec / 1000000.0)
|
||||
double t_now(
|
||||
std::chrono::duration<double>(std::chrono::system_clock::now()
|
||||
.time_since_epoch()
|
||||
).count()
|
||||
);
|
||||
uhd::time_spec_t now = uhd::time_spec_t(t_now)
|
||||
+ uhd::time_spec_t(d_delay_sec);
|
||||
|
||||
const pmt::pmt_t time_value = pmt::make_tuple(
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include <gnuradio/block_detail.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sys/time.h>
|
||||
|
||||
using namespace gr::foo;
|
||||
|
||||
@@ -55,8 +55,13 @@ void
|
||||
wireshark_connector_impl::handle_pdu(pmt::pmt_t pdu) {
|
||||
|
||||
// get current time
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
auto tp_now = std::chrono::system_clock::now();
|
||||
auto tp_now_sec = std::chrono::floor<std::chrono::seconds>(tp_now);
|
||||
auto duration_us = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
tp_now - tp_now_sec
|
||||
);
|
||||
auto ts_sec = tp_now_sec.time_since_epoch().count();
|
||||
auto ts_usec = duration_us.count();
|
||||
|
||||
const char *buf = reinterpret_cast<const char*>(pmt::blob_data(pmt::cdr(pdu)));
|
||||
std::size_t len = pmt::blob_length(pmt::cdr(pdu));
|
||||
@@ -78,8 +83,8 @@ wireshark_connector_impl::handle_pdu(pmt::pmt_t pdu) {
|
||||
len + sizeof(radiotap_hdr) + sizeof(pcap_hdr)));
|
||||
|
||||
pcap_hdr *hdr = reinterpret_cast<pcap_hdr*>(d_msg);
|
||||
hdr->ts_sec = t.tv_sec;
|
||||
hdr->ts_usec = t.tv_usec;
|
||||
hdr->ts_sec = ts_sec;
|
||||
hdr->ts_usec = ts_usec;
|
||||
hdr->incl_len = len + sizeof(radiotap_hdr);
|
||||
hdr->orig_len = len + sizeof(radiotap_hdr);
|
||||
offset += sizeof(struct pcap_hdr);
|
||||
@@ -132,8 +137,8 @@ wireshark_connector_impl::handle_pdu(pmt::pmt_t pdu) {
|
||||
len + sizeof(pcap_hdr)));
|
||||
|
||||
pcap_hdr *hdr = reinterpret_cast<pcap_hdr*>(d_msg);
|
||||
hdr->ts_sec = t.tv_sec;
|
||||
hdr->ts_usec = t.tv_usec;
|
||||
hdr->ts_sec = ts_sec;
|
||||
hdr->ts_usec = ts_usec;
|
||||
hdr->incl_len = len;
|
||||
hdr->orig_len = len;
|
||||
offset += sizeof(pcap_hdr);
|
||||
@@ -204,7 +209,7 @@ wireshark_connector_impl::general_work(int noutput, gr_vector_int& ninput_items,
|
||||
memcpy(out, d_msg + d_msg_offset, to_copy);
|
||||
|
||||
dout << "WIRESHARK: d_msg_offset: " << d_msg_offset <<
|
||||
" to_copy: " << to_copy <<
|
||||
" to_copy: " << to_copy <<
|
||||
" d_msg_len " << d_msg_len << std::endl;
|
||||
|
||||
d_msg_offset += to_copy;
|
||||
|
||||
Reference in New Issue
Block a user