From 5df3ff7678aec3a2fffd87e606710047443f6631 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 08:16:38 +0000 Subject: [PATCH] evil ass bug git-svn-id: http://svn.openzap.org/svn/openzap/trunk@260 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/fsk.c | 44 +++++++++++++++++------------- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/uart.c | 4 +-- libs/openzap/src/zap_analog.c | 5 ++++ libs/openzap/src/zap_callerid.c | 2 ++ libs/openzap/src/zap_io.c | 5 ++-- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/libs/openzap/src/fsk.c b/libs/openzap/src/fsk.c index d933166227..df3c834787 100644 --- a/libs/openzap/src/fsk.c +++ b/libs/openzap/src/fsk.c @@ -309,30 +309,36 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) switch (handle->state) { case FSK_STATE_DATA: - (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + { + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + } break; case FSK_STATE_CHANSEIZE: - if (handle->last_bit != handle->current_bit) { - - - handle->conscutive_state_bits++; - } else { - handle->conscutive_state_bits = 0; - } - if (handle->conscutive_state_bits > 15) { - handle->state = FSK_STATE_CARRIERSIG; - handle->conscutive_state_bits = 0; + { + if (handle->last_bit != handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_CARRIERSIG; + handle->conscutive_state_bits = 0; + } } break; case FSK_STATE_CARRIERSIG: - if (handle->current_bit) { - handle->conscutive_state_bits++; - } else { - handle->conscutive_state_bits = 0; - } - if (handle->conscutive_state_bits > 15) { - handle->state = FSK_STATE_DATA; - handle->conscutive_state_bits = 0; + { + if (handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_DATA; + handle->conscutive_state_bits = 0; + } } break; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 316b4d3af4..b68596770b 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -344,6 +344,7 @@ struct zap_channel { zap_filehandle_t fds[2]; zap_fsk_data_state_t fsk; uint8_t fsk_buf[80]; + uint32_t ring_count; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; diff --git a/libs/openzap/src/uart.c b/libs/openzap/src/uart.c index 05a80753ec..5e0dd85350 100644 --- a/libs/openzap/src/uart.c +++ b/libs/openzap/src/uart.c @@ -78,7 +78,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) handle = malloc(sizeof (*handle)); if (handle) { - memset(handle, 0, sizeof (handle)); + memset(handle, 0, sizeof (*handle)); /* fill the attributes member */ memcpy(&handle->attr, attr, sizeof (*attr)); @@ -111,8 +111,8 @@ void dsp_uart_bit_handler(void *x, int bit) handle->data >>= 1; handle->data |= 0x80 * !!bit; - handle->nbits++; + if (handle->nbits == 8) { handle->attr.bytehandler(handle->attr.bytehandler_arg, handle->data); handle->nbits = 0; diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 0ad28c92bd..adaa0ad2a0 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -426,7 +426,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); + zap_channel_command(chan, ZAP_COMMAND_TRACE_INPUT, "/tmp/wtf.ul"); zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + continue; } break; case ZAP_CHANNEL_STATE_RING: @@ -619,7 +621,10 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); + event->channel->ring_count = 1; zap_thread_create_detached(zap_analog_channel_run, event->channel); + } else { + event->channel->ring_count++; } } break; diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 3e8a790053..8940569ec0 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -182,6 +182,8 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ dsp_fsk_destroy(&state->fsk1200_handle); } + memset(state, 0, sizeof(*state)); + memset(buf, 0, bufsize); state->buf = buf; state->bufsize = bufsize; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8f5e0d08f6..b997a0156c 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1408,13 +1408,12 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { uint32_t type, mlen; char str[128], *sp; - - + while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { *(str+mlen) = '\0'; zap_copy_string(str, sp, ++mlen); zap_clean_string(str); - zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + zap_log(ZAP_LOG_ERROR, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); switch(type) { case MDMF_DDN: