void channel_read_adsi_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int len) { int i; int xlen; int16_t pcm_buf[1024]; char *s; int outframes; for (i = 0; i < len; i++) pcm_buf[i] = alaw_to_linear(buf[i]); /*endfor*/ outframes = afWriteFrames(rxhandle, AF_DEFAULT_TRACK, pcm_buf, len); if (outframes != len) { printf("Failed to write %d samples\n", len); exit(2); } dtmf_rx(&chan_stuff[chan].dtmf_state, pcm_buf, len); xlen = dtmf_rx_get(&chan_stuff[chan].dtmf_state, chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr, 100 - chan_stuff[chan].dtmf_ptr); if (xlen > 0) { s = chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr; while (*s) { if (*s == '#') { uc_set_channel_read_callback(uc, 0, NULL, 0); uc_set_channel_write_callback(uc, 0, NULL, 0); if (uc_call_control(uc, UC_OP_DROPCALL, chan_stuff[chan].crn, (void *) UC_CAUSE_NORMAL_CLEARING)) printf ("A Drop Call failed\n"); /*endif*/ break; } /*endif*/ s++; } /*endwhile*/ printf("Got '%s'\n", chan_stuff[chan].dtmf); chan_stuff[chan].dtmf_ptr += xlen; } /*endif*/ adsi_rx(&(chan_stuff[chan].adsi_rx), pcm_buf, len); }
void channel_read_fax_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int len) { int i; int xlen; char *s; int outframes; #if 0 outframes = afWriteFrames(rxhandle, AF_DEFAULT_TRACK, buf, len >> 1); if (outframes != len) { printf("Failed to write %d samples\n", len); exit(2); } #endif dtmf_rx(&chan_stuff[chan].dtmf_state, (int16_t *) buf, len); xlen = dtmf_rx_get(&chan_stuff[chan].dtmf_state, chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr, 100 - chan_stuff[chan].dtmf_ptr); if (xlen > 0) { s = chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr; while (*s) { if (*s == '#') { uc_set_channel_read_callback(uc, 0, NULL, 0); uc_set_channel_write_callback(uc, 0, NULL, 0); if (uc_call_control(uc, UC_OP_DROPCALL, chan_stuff[chan].crn, (void *) UC_CAUSE_NORMAL_CLEARING)) printf ("A Drop Call failed\n"); /*endif*/ break; } /*endif*/ s++; } /*endwhile*/ printf("Got '%s'\n", chan_stuff[chan].dtmf); chan_stuff[chan].dtmf_ptr += xlen; } /*endif*/ t30_rx(&(chan_stuff[chan].fax), (int16_t *) buf, len); }
static void handle_uc_event(uc_t *uc, void *user_data, uc_event_t *e) { int chan; chan = (int) user_data; printf ("-- %s (%d)\n", uc_event2str(e->e), chan); switch (e->e) { case UC_EVENT_DEVICEFAIL: break; case UC_EVENT_PROTOCOLFAIL: printf("-- Protocol failure on channel %d, cause %d\n", e->gen.channel, e->gen.data); break; case UC_EVENT_SIGCHANSTATUS: printf("-- Signalling channel status - %s\n", e->sigchanstatus.ok ? "Up" : "Down"); break; case UC_EVENT_ALARM: printf("-- Alarm - 0x%X 0x%X\n", e->alarm.raised, e->alarm.cleared); break; case UC_EVENT_FARBLOCKED: printf("-- Channel far end blocked! :-(\n"); chan_stuff[chan].xxx &= ~1; break; case UC_EVENT_FARUNBLOCKED: printf("-- Channel far end unblocked! :-)\n"); chan_stuff[chan].xxx |= 1; if (chan_stuff[chan].xxx == 3) { if (caller_mode) initiate_call(uc, chan, e); /*endif*/ } /*endif*/ break; case UC_EVENT_LOCALBLOCKED: printf("-- Channel local end blocked! :-(\n"); chan_stuff[chan].xxx &= ~2; break; case UC_EVENT_LOCALUNBLOCKED: printf("-- Channel local end unblocked! :-)\n"); chan_stuff[chan].xxx |= 2; if (chan_stuff[chan].xxx == 3) { if (caller_mode) initiate_call(uc, chan, e); /*endif*/ } /*endif*/ break; case UC_EVENT_DIALING: printf("-- Dialing on channel %d\n", e->gen.channel); break; case UC_EVENT_ACCEPTED: printf("-- Accepted on channel %d\n", e->gen.channel); if (uc_call_control(uc, UC_OP_ANSWERCALL, e->gen.crn, (void *) -1)) fprintf(stderr, "Answer Call failed\n"); /*endif*/ break; case UC_EVENT_DETECTED: printf("-- Detected on channel %d\n", e->gen.channel); break; case UC_EVENT_ALERTING: printf("-- Alerting on channel %d\n", e->gen.channel); /* This is just a notification of call progress. We need take no action at this point. */ break; case UC_EVENT_FARDISCONNECTED: printf("-- Far end disconnected on channel %d\n", e->fardisconnected.channel); /* Kill any outstanding audio processing */ uc_set_channel_read_callback(uc, 0, NULL, 0); uc_set_channel_write_callback(uc, 0, NULL, 0); if (uc_call_control(uc, UC_OP_DROPCALL, e->fardisconnected.crn, (void *) UC_CAUSE_NORMAL_CLEARING)) fprintf(stderr, "C Drop Call failed\n"); /*endif*/ break; case UC_EVENT_DROPCALL: printf("-- Drop call on channel %d\n", e->gen.channel); if (uc_call_control(uc, UC_OP_RELEASECALL, e->gen.crn, NULL)) fprintf(stderr, "uc_ReleaseCall failed\n"); /*endif*/ break; case UC_EVENT_RELEASECALL: printf("-- Released on channel %d\n", e->gen.channel); if (caller_mode) initiate_call(uc, chan, e); /*endif*/ break; case UC_EVENT_OFFERED: printf("-- Offered on channel %d, CRN %d (ANI: %s, DNIS: %s)\n", e->offered.channel, e->offered.crn, e->offered.parms.originating_number, e->offered.parms.destination_number); if (!caller_mode) { switch (chan_stuff[chan].cause) { case 0: if (uc_call_control(uc, UC_OP_ACCEPTCALL, e->offered.crn, (void *) -1)) fprintf(stderr, "uc_AcceptCall failed\n"); /*endif*/ break; case 1: if (uc_call_control(uc, UC_OP_ANSWERCALL, e->offered.crn, (void *) -1)) fprintf(stderr, "uc_AnswerCall failed\n"); /*endif*/ break; case 2: if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_USER_BUSY)) fprintf(stderr, "E Drop Call failed\n"); /*endif*/ break; case 3: if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_UNASSIGNED_NUMBER)) fprintf(stderr, "F Drop Call failed\n"); /*endif*/ break; case 4: if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_NETWORK_CONGESTION)) fprintf(stderr, "G Drop Call failed\n"); /*endif*/ break; case 5: if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_DEST_OUT_OF_ORDER)) fprintf(stderr, "H Drop Call failed\n"); /*endif*/ break; } /*endswitch*/ if (++chan_stuff[chan].cause > 5) chan_stuff[chan].cause = 0; /*endif*/ } /*endif*/ break; case UC_EVENT_ANSWERED: printf("-- Answered on channel %d\n", e->gen.channel); uc_set_channel_read_callback(uc, 0, channel_read_adsi_channel, (void *) chan); printf("XXX read callback set\n"); uc_set_channel_write_callback(uc, 0, channel_write_adsi_channel, (void *) chan); printf("XXX write callback set\n"); adsi_tx_init(&(chan_stuff[chan].adsi_tx), ADSI_STANDARD_CLASS); printf("XXX ADSI inited\n"); dtmf_rx_init(&chan_stuff[chan].dtmf_state, NULL, NULL); printf("XXX DTMF inited\n"); break; case UC_EVENT_CONNECTED: printf("-- Connected on channel %d\n", e->gen.channel); if (uc_call_control(uc, UC_OP_DROPCALL, e->offered.crn, (void *) UC_CAUSE_NORMAL_CLEARING)) printf ("I Drop Call failed\n"); /*endif*/ break; default: fprintf(stderr, "--!! Unknown signaling event %d\n", e->e); break; } /*endswitch*/ }