diff mtctest/sig_handler.c @ 159:c8e9b295e88f

mtctest: add time reporting for DTMF events
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 12:11:06 -0800
parents c731ec342ba0
children 55ad0f4bb33c
line wrap: on
line diff
--- a/mtctest/sig_handler.c	Wed Oct 12 08:45:39 2022 -0800
+++ b/mtctest/sig_handler.c	Wed Oct 12 12:11:06 2022 -0800
@@ -5,6 +5,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/time.h>
 #include <sys/socket.h>
 #include <stdio.h>
 #include <stdint.h>
@@ -16,6 +17,7 @@
 
 extern int disconnect_mode;
 extern struct sockaddr_storage dummy_rtp_endp;
+extern struct timeval cur_event_time;
 
 static void
 print_bearer_cap(bcap)
@@ -180,6 +182,27 @@
 }
 
 static void
+handle_dtmf_time()
+{
+	static struct timeval last_dtmf_time;
+	struct timeval delta;
+	unsigned ms;
+
+	if (timerisset(&last_dtmf_time) &&
+	    timercmp(&cur_event_time, &last_dtmf_time, >)) {
+		timersub(&cur_event_time, &last_dtmf_time, &delta);
+		if (delta.tv_sec >= 2)
+			printf("Time since last DTMF event: %u s\n",
+				(unsigned) delta.tv_sec);
+		else {
+			ms = delta.tv_sec * 1000 + delta.tv_usec / 1000;
+			printf("Time since last DTMF event: %u ms\n", ms);
+		}
+	}
+	bcopy(&cur_event_time, &last_dtmf_time, sizeof(struct timeval));
+}
+
+static void
 handle_signaling_msg(msg, msglen)
 	struct gsm_mncc *msg;
 	unsigned msglen;
@@ -230,6 +253,7 @@
 	case MNCC_START_DTMF_IND:
 		printf("MNCC_START_DTMF_IND: MS sending DTMF start\n");
 		print_fields(msg);
+		handle_dtmf_time();
 		if (msg->fields & MNCC_F_KEYPAD &&
 		    is_valid_dtmf_digit(msg->keypad)) {
 			printf("Responding with ACK\n");
@@ -244,6 +268,7 @@
 		return;
 	case MNCC_STOP_DTMF_IND:
 		printf("MNCC_STOP_DTMF_IND: MS sending DTMF stop\n");
+		handle_dtmf_time();
 		msg->msg_type = MNCC_STOP_DTMF_RSP;
 		send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
 		return;