Index: fxstest.c =================================================================== --- fxstest.c (revision 6837) +++ fxstest.c (working copy) @@ -53,8 +53,10 @@ int fd; int res; int x; - if (argc < 3) { - fprintf(stderr, "Usage: fxstest \n" + ZT_HOOK_DATA hook_data; + + if (argc < 3 || argc > 4) { + fprintf(stderr, "Usage: fxstest \n" " where cmd is one of:\n" " stats - reports voltages\n" " regdump - dumps ProSLIC registers\n" @@ -63,7 +65,8 @@ " ring - rings phone\n" " vmwi - toggles VMWI LED lamp\n" " hvdc - toggles VMWI HV lamp\n" - " neon - toggles VMWI NEON lamp\n"); + " neon - toggles VMWI NEON lamp\n" + " dtmf - callerID callerID\n"); exit(1); } fd = open(argv[1], O_RDWR); @@ -113,30 +116,83 @@ fprintf(stderr, "Phone is ringing...\n"); sleep(2); } - } else if (!strcasecmp(argv[2], "polarity")) { - fprintf(stderr, "Twiddling polarity...\n"); - /* Insure that the channel is in active mode */ - x = DAHDI_RING; - res = ioctl(fd, DAHDI_HOOK, &x); + } else if (!strcasecmp(argv[2], "dtmf")) { + char startChar; + char endChar; + char callerIDstr[255]=""; + + /* Set hook polarity */ + hook_data.polarity=1; + + /* Compose DTMF caller-ID */ + /* startChar='A'; */ /* Some swedish older callerid devices */ + startChar='D'; + /* endChar='#';*/ /* Danish callerid en character */ + endChar='C'; + if(argc==3){ + fprintf(stderr,"No caller ID available\n"); + strcpy(callerIDstr, ""); + } + else{ + fprintf(stderr, "Will try to send DTMF callerid %s\n", argv[3]); + strcpy(callerIDstr, argv[3]); + } + if (0!=strcmp(callerIDstr,"")){ + snprintf(hook_data.dtmfCidData, sizeof(hook_data.dtmfCidData), "TW%c%s%cW", startChar, callerIDstr, endChar); + fprintf(stderr, "Caller-ID Signalling is DTMF %c-start, string='%s'.\n", startChar, hook_data.dtmfCidData); + } else { + fprintf(stderr, "No Caller-ID available - send info code to device.\n"); + /* + * Note that Denmark uses a different code for missing number. + * Code "D3# means that there is technical reason for not + * providing the number. + * Code "B00C" means that the number is unavailable. + */ +/* if ((p->cid_signalling & CID_SIG_DTMF_DK) != 0) + snprintf(hook_data.dtmfCidData, sizeof(hook_data.dtmfCidData), "TwD3#w"); + else*/ + snprintf(hook_data.dtmfCidData, sizeof(hook_data.dtmfCidData), "TWB00CW"); + } + hook_data.x = DAHDI_RING; + if (ioctl(fd, DAHDI_HOOK, &hook_data) && (errno != EINPROGRESS)) { + fprintf(stderr, "Unable to ring phone: %s\n", strerror(errno)); + return -1; + } + sleep(5); + + } else if (!strcasecmp(argv[2], "polarity")) { + /* Setup defaults */ + hook_data.x = DAHDI_RING; + hook_data.polarity = 0; + *hook_data.dtmfCidData=0; + + fprintf(stderr, "Twiddling polarity...\n"); + + /* Insure that the channel is in active mode */ + hook_data.x = DAHDI_RING; + res = ioctl(fd, DAHDI_HOOK, &hook_data); usleep(100000); - x = 0; - res = ioctl(fd, DAHDI_HOOK, &x); + hook_data.x = DAHDI_ONHOOK; + res = ioctl(fd, DAHDI_HOOK, &hook_data); - x = 0; - res = ioctl(fd, DAHDI_SETPOLARITY, &x); + sleep(1); + + x=0; + res = ioctl(fd, DAHDI_SETPOLARITY, &x); + if (res) { fprintf(stderr, "Unable to polarity...\n"); } else { fprintf(stderr, "Polarity is forward...\n"); sleep(2); - x = 1; - ioctl(fd, DAHDI_SETPOLARITY, &x); + x=1; + res = ioctl(fd, DAHDI_SETPOLARITY, &x); fprintf(stderr, "Polarity is reversed...\n"); sleep(5); - x = 0; - ioctl(fd, DAHDI_SETPOLARITY, &x); + x=0; + res = ioctl(fd, DAHDI_SETPOLARITY, &x); fprintf(stderr, "Polarity is forward...\n"); - sleep(2); + sleep(1); } } else if (!strcasecmp(argv[2], "tones")) { int x = 0; Index: fxotune.c =================================================================== --- fxotune.c (revision 6837) +++ fxotune.c (working copy) @@ -781,12 +781,14 @@ int i = 0, freq = 0, acim = 0; int res = 0, x = 0; struct dahdi_bufferinfo bi; + struct dahdi_dialoperation dop; struct wctdm_echo_coefs coefs; short inbuf[TEST_DURATION]; /* changed from BUFFER_LENGTH - this buffer is for short values, so it should be allocated using the length of the test */ int lowest = 0; FILE *outfile = NULL; float acim_results[16]; struct silence_info sinfo; + ZT_HOOK_DATA hook_data; if (debug) { outfile = fopen("fxotune.vals", "w"); @@ -829,10 +831,18 @@ fprintf(stderr, "Unable to set buffer information!\n"); return -1; } + hook_data.x = DAHDI_OFFHOOK; + hook_data.polarity = 0; + *hook_data.dtmfCidData=0; + if (ioctl(whichdahdi, DAHDI_HOOK, &hook_data)) { + fprintf(stderr, "Cannot bring fd %d off hook", whichdahdi); + return -1; + } for (acim = 0; acim < 16; acim++) { float freq_results[15]; - + int needtoreset = 9; + coefs.acim = acim; if (ioctl(whichdahdi, WCTDM_SET_ECHOTUNE, &coefs)) { fprintf(stderr, "Unable to set impedance on fd %d\n", whichdahdi); @@ -849,8 +859,44 @@ fprintf(stderr, "Unable to get a clear line\n"); return -1; } - + /* Prepare line for data */ + if (needtoreset > 8) { + /* Do line hookstate reset */ + x = DAHDI_ONHOOK; + hook_data.x = DAHDI_ONHOOK; + hook_data.polarity = 0; + *hook_data.dtmfCidData=0; + if (ioctl(whichdahdi, DAHDI_HOOK, &hook_data)) { + fprintf(stderr, "Unable to hang up fd %d\n", whichdahdi); + return -1; + } + + sleep(2); + hook_data.x = DAHDI_OFFHOOK; + hook_data.polarity = 0; + *hook_data.dtmfCidData=0; + if (ioctl(whichdahdi, DAHDI_HOOK, &hook_data)) { + fprintf(stderr, "Cannot bring fd %d off hook", whichdahdi); + return -1; + } + sleep(2); // KD - Added to ensure that dial can actually takes place + + memset(&dop, 0, sizeof(dop)); + dop.op = DAHDI_DIAL_OP_REPLACE; + dop.dialstr[0] = 'T'; + strncpy(dop.dialstr + 1, dialstr, sizeof(dop.dialstr) - 1); + printf("."); + if (ioctl(whichdahdi, DAHDI_DIAL, &dop)) { + fprintf(stderr, "Unable to dial!\n"); + return -1; + } + sleep(2); + + needtoreset = 0; + } + + /* Flush buffers */ x = DAHDI_FLUSH_READ | DAHDI_FLUSH_WRITE | DAHDI_FLUSH_EVENT; if (ioctl(whichdahdi, DAHDI_FLUSH, &x)) {