Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pulse dialing support to ftmod_analog #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ftmod/ftmod_analog/ftdm_analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct ftdm_analog_data {

/* Analog flags to be set in the sflags (signaling flags) channel memeber */
#define AF_POLARITY_REVERSE (1 << 0)
#define AF_PULSE_INCOMING (1 << 1)

static void *ftdm_analog_run(ftdm_thread_t *me, void *obj);
typedef struct ftdm_analog_data ftdm_analog_data_t;
Expand Down
22 changes: 22 additions & 0 deletions src/ftmod/ftmod_analog/ftmod_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,16 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj)


if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE || ftdmchan->state == FTDM_CHANNEL_STATE_COLLECT) {

if (ftdm_test_sflag(ftdmchan, AF_PULSE_INCOMING)) {

if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE) {
ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_COLLECT);
collecting = 1;
}
last_digit = elapsed;
}

if ((dlen = ftdm_channel_dequeue_dtmf(ftdmchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {

if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE) {
Expand Down Expand Up @@ -1161,6 +1171,18 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e
ftdm_set_sflag(event->channel, AF_POLARITY_REVERSE);
}
break;
case FTDM_OOB_PULSE_START:
{
ftdm_log_chan_msg(event->channel, FTDM_LOG_DEBUG, "Incoming pulse event!\n");
ftdm_set_sflag(event->channel, AF_PULSE_INCOMING);
}
break;
case FTDM_OOB_PULSE_END:
{
ftdm_log_chan_msg(event->channel, FTDM_LOG_DEBUG, "Incoming pulse event completed\n");
ftdm_clear_sflag(event->channel, AF_PULSE_INCOMING);
}
break;
default:
{
ftdm_log_chan(event->channel, FTDM_LOG_DEBUG, "Ignoring event [%s] in state [%s]\n", ftdm_oob_event2str(event->enum_id), ftdm_channel_state2str(event->channel->state));
Expand Down
27 changes: 24 additions & 3 deletions src/ftmod/ftmod_zt/ftmod_zt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,19 @@ FIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event)
return k ? FTDM_SUCCESS : FTDM_FAIL;
}

static __inline__ int handle_pulse_event(ftdm_channel_t *fchan, zt_event_t zt_event_id)
{
if ((zt_event_id & ZT_EVENT_PULSEDIGIT)) {
int digit = (zt_event_id & (~ZT_EVENT_PULSEDIGIT));
char tmp_pulse[2] = { digit, 0 };
ftdm_log_chan(fchan, FTDM_LOG_DEBUG, "PULSEDIGIT [%c]\n", (char)digit);
ftdm_channel_queue_dtmf(fchan, tmp_pulse);
return 0;
} else {
return -1;
}
}

static __inline__ int handle_dtmf_event(ftdm_channel_t *fchan, zt_event_t zt_event_id)
{
if ((zt_event_id & ZT_EVENT_DTMFUP)) {
Expand Down Expand Up @@ -1234,6 +1247,12 @@ static __inline__ ftdm_status_t zt_channel_process_event(ftdm_channel_t *fchan,
*event_id = FTDM_OOB_POLARITY_REVERSE;
}
break;
case ZT_EVENT_PULSE_START:
{
ftdm_log_chan_msg(fchan, FTDM_LOG_DEBUG, "Received start of pulse sequence (ZT_EVENT_PULSE_START)\n");
*event_id = FTDM_OOB_PULSE_START;
}
break;
case ZT_EVENT_NONE:
{
ftdm_log_chan_msg(fchan, FTDM_LOG_DEBUG, "No event\n");
Expand All @@ -1242,11 +1261,13 @@ static __inline__ ftdm_status_t zt_channel_process_event(ftdm_channel_t *fchan,
break;
default:
{
if (handle_dtmf_event(fchan, zt_event_id)) {
if (!handle_pulse_event(fchan, zt_event_id)) {
*event_id = FTDM_OOB_PULSE_END;
} else if (!handle_dtmf_event(fchan, zt_event_id)) {
*event_id = FTDM_OOB_NOOP;
} else {
ftdm_log_chan(fchan, FTDM_LOG_WARNING, "Unhandled event %d\n", zt_event_id);
*event_id = FTDM_OOB_INVALID;
} else {
*event_id = FTDM_OOB_NOOP;
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions src/ftmod/ftmod_zt/ftmod_zt.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ typedef enum {
ZT_EVENT_TIMER_PING = 16,
ZT_EVENT_POLARITY = 17,
ZT_EVENT_RINGBEGIN = 18,
ZT_EVENT_PULSEDIGIT = (1 << 16),
ZT_EVENT_DTMFDOWN = (1 << 17),
ZT_EVENT_DTMFUP = (1 << 18),
} zt_event_t;
Expand Down
4 changes: 3 additions & 1 deletion src/include/private/ftdm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ typedef enum {
FTDM_OOB_ALARM_CLEAR,
FTDM_OOB_CAS_BITS_CHANGE,
FTDM_OOB_POLARITY_REVERSE,
FTDM_OOB_PULSE_START,
FTDM_OOB_PULSE_END,
FTDM_OOB_INVALID
} ftdm_oob_event_t;
#define OOB_STRINGS "NOOP", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "CAS_BITS_CHANGE", "POLARITY_REVERSE", "INVALID"
#define OOB_STRINGS "NOOP", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "CAS_BITS_CHANGE", "POLARITY_REVERSE", "PULSE_START", "PULSE_END", "INVALID"
FTDM_STR2ENUM_P(ftdm_str2ftdm_oob_event, ftdm_oob_event2str, ftdm_oob_event_t)

/*! \brief Event types */
Expand Down