summaryrefslogtreecommitdiff
path: root/usbfxstest.c
diff options
context:
space:
mode:
authormarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2002-08-22 16:51:05 +0000
committermarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2002-08-22 16:51:05 +0000
commit1c9885532e2572eeb5a95fa240c501d5fb91459a (patch)
tree70202dba33ce0175c398bcaa09114f94b4fec8a8 /usbfxstest.c
parent9ba4e07b16bf5efa450f9ab3b9f1eaa937d54a82 (diff)
Version 0.3.0 from FTP
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@99 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'usbfxstest.c')
-rwxr-xr-xusbfxstest.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/usbfxstest.c b/usbfxstest.c
new file mode 100755
index 0000000..1174dda
--- /dev/null
+++ b/usbfxstest.c
@@ -0,0 +1,86 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "zap.h"
+#include <linux/zaptel.h>
+
+int main(int argc, char *argv[])
+{
+ ZAP *z;
+ ZT_PARAMS p;
+ char tmp[1024];
+ int len;
+ int res;
+ int firstpass=1;
+ int linear=0;
+ if (argc < 2) {
+ fprintf(stderr, "Usage: usbfxstest <device> [options]\n");
+ exit(1);
+ }
+ if (argc > 2) {
+ if (!strcasecmp(argv[2], "linear")) {
+ linear=1;
+ }
+ }
+ z = zap_open(argv[1], 0);
+ if (!z) {
+ fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
+ exit(1);
+ }
+ /* Ring phone until it goes off hook. This shows how you mix direct
+ and indirect calls */
+ for (;;) {
+ p.channo = 0;
+ res = ioctl(zap_fd(z), ZT_GET_PARAMS, &p);
+ if (res) {
+ fprintf(stderr, "Failed to get parameters: %s\n", strerror(errno));
+ exit(1);
+ }
+ if (p.rxisoffhook)
+ break;
+ if (firstpass)
+ res = zap_ringclid(z, "2565551212", "Nifty Cool");
+ else
+ res = zap_ring(z, 1);
+ }
+ if (linear) {
+ printf("Going linear!\n");
+ zap_setlinear(z, linear);
+ }
+ printf("Off Hook!\n");
+ len = 204;
+ for (;;) {
+ /* Record, play, and check for events */
+ res = zap_recchunk(z, tmp, len, ZAP_DTMFINT);
+ if (res == len) {
+ res = zap_playchunk(z, tmp, len, 0);
+ }
+ if (res < len) {
+ res = zap_getevent(z);
+ if (zap_dtmfwaiting(z)) {
+ zap_getdtmf(z, 1, NULL, 0, 1, 1, 0);
+ printf("Got DTMF: %s\n", zap_dtmfbuf(z));
+ zap_clrdtmfn(z);
+ } else if (res) {
+ switch(res) {
+ case ZAP_EVENT_ONHOOK:
+ printf("On Hook!\n");
+ break;
+ case ZAP_EVENT_RINGANSWER:
+ printf("Off hook!\n");
+ break;
+ case ZAP_EVENT_WINKFLASH:
+ printf("Flash!\n");
+ break;
+ default:
+ printf("Unknown event %d\n", res);
+ }
+ }
+ }
+ }
+ return 0;
+}