summaryrefslogtreecommitdiff
path: root/timertest.c
diff options
context:
space:
mode:
authormarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2003-03-20 07:00:04 +0000
committermarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2003-03-20 07:00:04 +0000
commit4561ffccd62f4a2f356fc3306dfd1a087adbfd74 (patch)
tree0b62402659f80a8c4d5a4275ffe36e4ac3e9307c /timertest.c
parentb722b4412c37e15bfe011166a81f187e8e058ef2 (diff)
Add timer testing program
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@159 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'timertest.c')
-rwxr-xr-xtimertest.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/timertest.c b/timertest.c
new file mode 100755
index 0000000..5849e21
--- /dev/null
+++ b/timertest.c
@@ -0,0 +1,49 @@
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <errno.h>
+#include "zaptel.h"
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ int x = 8000;
+ int res;
+ fd_set fds;
+ struct timeval orig, now;
+ fd = open("/dev/zap/timer", O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "Unable to open timer: %s\n", strerror(errno));
+ exit(1);
+ }
+ printf("Opened timer...\n");
+ if (ioctl(fd, ZT_TIMERCONFIG, &x)) {
+ fprintf(stderr, "Unable to set timer: %s\n", strerror(errno));
+ exit(1);
+ }
+ printf("Set timer duration to %d samples (%d ms)\n", x, x/8);
+ printf("Waiting...\n");
+ gettimeofday(&orig, NULL);
+ for(;;) {
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ res = select(fd + 1, NULL, NULL, &fds, NULL);
+ if (res != 1) {
+ fprintf(stderr, "Unexpected result %d: %s\n", res, strerror(errno));
+ exit(1);
+ }
+ x = -1;
+ if (ioctl(fd, ZT_TIMERACK, &x)) {
+ fprintf(stderr, "Unable to ack timer: %s\n", strerror(errno));
+ exit(1);
+ }
+ gettimeofday(&now, NULL);
+ printf("Timer Expired (%d ms)!\n", (now.tv_sec - orig.tv_sec) * 1000 + (now.tv_usec - orig.tv_usec) / 1000);
+ }
+ exit(0);
+}