Commit c73d8534 authored by Joanne Hugé's avatar Joanne Hugé

WIP

parent a20f85ef
...@@ -41,8 +41,6 @@ ...@@ -41,8 +41,6 @@
#define MESSAGE ((uint32_t)0x00FACADE) #define MESSAGE ((uint32_t)0x00FACADE)
#define NSEC_PER_SEC 1000000000 #define NSEC_PER_SEC 1000000000
#define DEBUG
static int process_socket_error_queue(int fd); static int process_socket_error_queue(int fd);
static void print_timestamps(struct msghdr *msg); static void print_timestamps(struct msghdr *msg);
static void process_timestamps(int sock); static void process_timestamps(int sock);
...@@ -54,7 +52,7 @@ static size_t tx_buffer_len = sizeof(tx_buffer); ...@@ -54,7 +52,7 @@ static size_t tx_buffer_len = sizeof(tx_buffer);
static int fd; static int fd;
static int so_timestamping_flags = static int so_timestamping_flags =
SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RAW_HARDWARE; SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE;
// Sets the interface // Sets the interface
static int set_if(char *network_if) { static int set_if(char *network_if) {
...@@ -94,8 +92,7 @@ void init_udp_etf(int use_etf, int use_timestamps, int packet_priority, ...@@ -94,8 +92,7 @@ void init_udp_etf(int use_etf, int use_timestamps, int packet_priority,
if (use_etf) { if (use_etf) {
sk_txtime.clockid = CLOCK_ID; sk_txtime.clockid = CLOCK_ID;
sk_txtime.flags = 1; sk_txtime.flags = 0;
sk_txtime.flags = SOF_TXTIME_REPORT_ERRORS;
if (setsockopt(fd, SOL_SOCKET, SO_TXTIME, &sk_txtime, sizeof(sk_txtime))) if (setsockopt(fd, SOL_SOCKET, SO_TXTIME, &sk_txtime, sizeof(sk_txtime)))
error(EXIT_FAILURE, errno, "setsockopt SO_TXTIME failed\n"); error(EXIT_FAILURE, errno, "setsockopt SO_TXTIME failed\n");
...@@ -132,7 +129,7 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, ...@@ -132,7 +129,7 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
struct pollfd poll_fd = { struct pollfd poll_fd = {
.fd = fd, .fd = fd,
}; };
int sendmsgerr, pollerr; int sendmsgerr;
memset(&sin, 0, sizeof(sin)); memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
...@@ -165,16 +162,13 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, ...@@ -165,16 +162,13 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
if (sendmsgerr < 0) if (sendmsgerr < 0)
error(EXIT_FAILURE, errno, "sendmsg failed, ret value: %d\n", sendmsgerr); error(EXIT_FAILURE, errno, "sendmsg failed, ret value: %d\n", sendmsgerr);
for(int i = 0; i < (use_timestamps + 1); i++) { if(use_timestamps) {
printf("Polling...\n"); #ifdef DEBUG
pollerr = poll(&poll_fd, 1, 0); printf("Polling for timestamps...\n");
// If the poll revents containts a POLLERR flag #endif
if (pollerr == 1 && (poll_fd.revents & POLLERR)) { poll(&poll_fd, 1, 0);
process_socket_error_queue(fd);
} else if(use_timestamps) {
process_timestamps(fd); process_timestamps(fd);
} }
}
} }
static void process_timestamps(int sock) { static void process_timestamps(int sock) {
...@@ -203,59 +197,6 @@ static void process_timestamps(int sock) { ...@@ -203,59 +197,6 @@ static void process_timestamps(int sock) {
} }
} }
/*
* Code from scheduled_tx_tools
*/
static int process_socket_error_queue(int fd) {
uint8_t msg_control[CMSG_SPACE(sizeof(struct sock_extended_err))];
unsigned char err_buffer[sizeof(tx_buffer)];
struct sock_extended_err *serr;
struct cmsghdr *cmsg;
__u64 tstamp = 0;
struct iovec iov = {.iov_base = err_buffer, .iov_len = sizeof(err_buffer)};
struct msghdr msg = {.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = msg_control,
.msg_controllen = sizeof(msg_control)};
#ifdef DEBUG
printf("process_socket_error_queue\n");
#endif
if (recvmsg(fd, &msg, MSG_ERRQUEUE) == -1) {
fprintf(stderr, "recvmsg failed");
return -1;
}
cmsg = CMSG_FIRSTHDR(&msg);
while (cmsg != NULL) {
serr = (void *)CMSG_DATA(cmsg);
if (serr->ee_origin == SO_EE_ORIGIN_TXTIME) {
tstamp = ((__u64)serr->ee_data << 32) + serr->ee_info;
switch (serr->ee_code) {
case SO_EE_CODE_TXTIME_INVALID_PARAM:
fprintf(stderr,
"packet with tstamp %llu dropped due to invalid params\n",
tstamp);
return 0;
case SO_EE_CODE_TXTIME_MISSED:
fprintf(stderr,
"packet with tstamp %llu dropped due to missed deadline\n",
tstamp);
return 0;
default:
return -1;
}
}
cmsg = CMSG_NXTHDR(&msg, cmsg);
}
return 0;
}
static void print_timestamps(struct msghdr *msg) { static void print_timestamps(struct msghdr *msg) {
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
...@@ -309,3 +250,57 @@ static void print_timestamps(struct msghdr *msg) { ...@@ -309,3 +250,57 @@ static void print_timestamps(struct msghdr *msg) {
printf("\n"); printf("\n");
} }
} }
/*
* Code from scheduled_tx_tools
*/
static int process_socket_error_queue(int fd) {
uint8_t msg_control[CMSG_SPACE(sizeof(struct sock_extended_err))];
unsigned char err_buffer[sizeof(tx_buffer)];
struct sock_extended_err *serr;
struct cmsghdr *cmsg;
__u64 tstamp = 0;
struct iovec iov = {.iov_base = err_buffer, .iov_len = sizeof(err_buffer)};
struct msghdr msg = {.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = msg_control,
.msg_controllen = sizeof(msg_control)};
#ifdef DEBUG
printf("process_socket_error_queue\n");
#endif
if (recvmsg(fd, &msg, MSG_ERRQUEUE) == -1) {
fprintf(stderr, "recvmsg failed");
return -1;
}
cmsg = CMSG_FIRSTHDR(&msg);
while (cmsg != NULL) {
serr = (void *)CMSG_DATA(cmsg);
if (serr->ee_origin == SO_EE_ORIGIN_TXTIME) {
tstamp = ((__u64)serr->ee_data << 32) + serr->ee_info;
switch (serr->ee_code) {
case SO_EE_CODE_TXTIME_INVALID_PARAM:
fprintf(stderr,
"packet with tstamp %llu dropped due to invalid params\n",
tstamp);
return 0;
case SO_EE_CODE_TXTIME_MISSED:
fprintf(stderr,
"packet with tstamp %llu dropped due to missed deadline\n",
tstamp);
return 0;
default:
return -1;
}
}
cmsg = CMSG_NXTHDR(&msg, cmsg);
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment