[asterisk-users] Setting a threshold for asterisk to take ZAP line off hook ?

Maxim Vexler hq4ever at gmail.com
Wed Jul 19 02:55:56 MST 2006


On 7/18/06, Mojo with Horan & Company, LLC <mojo at horanappraisals.com> wrote:
> I think when a PSTN line says 'Ring' it's simply for aesthetics... The
> line is 'answered' the instant * connects to it for two-way audio...
> (well not that instant but somewhere in the connection process.  When
> you are hearing ringing from the PSTN through a zap card, the rings are
> coming from the phone company and are just sound.  * doesn't decode that
> and act on it yet.)
>
> Maxim Vexler wrote:
> > On 7/16/06, Martin Joseph <ast at stillnewt.org> wrote:
> >> On Jul 16, 2006, at 11:36 AM, Maxim Vexler wrote:
> >>
> >>> Hello list
> >>>
> >>> I'm trying to setup asterisk as an answering machine.
> >>>
> >>> How can I set asterisk to Answer() incoming call ONLY after specified
> >>> count of ring cycles ?
> >>>
> >>> In the current situation I have the PBX connected to a home line,
> >>> where POTS device are also connected on the same circuit. What I'm
> >>> trying to do is allow a grace period where a POTS device could be
> >>> picked up and those stop the ring indication on the line by this
> >>> causing asterisk to not answer the call.
> >>>
> >>> In present situation even if the incoming phone call is taken off hook
> >>> by a POST device asterisk still starts playing its incoming call IVR
> >>> after the specified(where?) number of seconds.
> >>>
> >> I don't think you can do that, since asterisk has no way to know when
> >> the shared PSTN line is answered by your analog phones...
> >>
> >> I don't think asterisk "counts" the rings, as much as it waits for
> >> "answered" status, which it is never going to see in your current
> >> configuration.
> >>
> >> I am a relative newb though,  so maybe someone else here has a
> >> brilliant idea for you?
> >>
> >>
> >> _______________________________________________
> >> --Bandwidth and Colocation provided by Easynews.com --
> >>
> >> asterisk-users mailing list
> >> To UNSUBSCRIBE or update options visit:
> >>    http://lists.digium.com/mailman/listinfo/asterisk-users
> >>
> >
> > You have a point but no way am I going to accept that as an answer.
> >
> > Here's the log off such case :
> >
> > Jul 16 21:59:20 DEBUG[4387] chan_zap.c: Monitor doohicky got event
> > Ring Begin on channel 1
> > Jul 16 21:59:21 DEBUG[4387] chan_zap.c: Monitor doohicky got event
> > Ring/Answered on channel 1
> > Jul 16 21:59:21 DEBUG[4387] dsp.c: dsp busy pattern set to 0,0
> > Jul 16 21:59:21 VERBOSE[4411] logger.c:     -- Starting simple switch
> > on 'Zap/1-1'
> > Jul 16 21:59:21 DEBUG[4373] devicestate.c: Changing state for Zap/1 -
> > state 2 (In use)
> > Jul 16 21:59:21 DEBUG[4412] app_queue.c: Device 'Zap/1' changed to
> > state '2' (In use)
> > Jul 16 21:59:29 WARNING[4411] chan_zap.c: CallerID returned with error
> > on channel 'Zap/1-1'
> > Jul 16 21:59:29 DEBUG[4411] pbx.c: Launching 'Answer'
> > Jul 16 21:59:29 VERBOSE[4411] logger.c:     -- Executing
> > Answer("Zap/1-1", "") in new stack
> > Jul 16 21:59:29 DEBUG[4411] chan_zap.c: Took Zap/1-1 off hook
> > Jul 16 21:59:29 DEBUG[4411] chan_zap.c: Enabled echo cancellation on channel 1
> > Jul 16 21:59:29 DEBUG[4411] chan_zap.c: No echo training requested
> > Jul 16 21:59:29 DEBUG[4411] pbx.c: Launching 'Set'
> >
> > As you can see, the first two events are "event Ring" and "event Ring/Answered".
> > What I need is the driver of chan_zap.c counting 5 "event Ring" before
> > starting Ring/Answered.
> >
> > It can't be that hard (I think).
> > Thank you for your answer.
> >
>
> --
> Mojo <mojo at horanappraisals.com>
> Office Manger, Horan & Company, LLC
> (907) 747-6666 x112
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users
>

Well, I did managed to get it to work some how with the attached patch.
My problems with this code are :

a. It will destroy all active calls because I'm using zap_restart().

I really need to find a better way to destroy only the active channel
instead of the whole zaptel stock.

b. I don't know how this might be related, but since I've started to
use this patch some calls simply won't get disconnected by asterisk
after remote party hangup. Note that I'm using busydetect on this
channel (It's x100p.com clone).

Please note that when asterisk does not disconnect the call with busy
detect, I'm seeing this in the "full" log (attached) the following :
Jul 19 12:39:39 DEBUG[24397] channel.c: Scheduling timer at 160 sample intervals
where as with "normal" calls this does not appear.

This only occurs if I let asterisk Answer the call and instantly
hangup my cell phone (which I'm using to test this). If on the other
hand I listen to the IVR for a few seconds and then hangup my cell
phone asterisk will take the channel On Hook using busydetect as
expected.
Meaning that I am able to reproduce this behaviour (bug?) by letting
chan_zap take the call off hook followed by instant remote party (cell
phone) hangup.


diff -Naur asterisk-1.2.7.1.dfsg/channels/chan_zap.c
asterisk-1.2.7.1.dfsg-anspatch/channels/chan_zap.c
--- asterisk-1.2.7.1.dfsg/channels/chan_zap.c   2006-04-04
21:28:14.000000000 +0300
+++ asterisk-1.2.7.1.dfsg-anspatch/channels/chan_zap.c  2006-07-19
12:25:11.000000000 +0300
@@ -6231,6 +6231,8 @@
        struct ast_channel *chan;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+       static int ring_count=-1;
+       static time_t last_event=0;
        /* Handle an event on a given channel for the monitor thread. */
        switch(event) {
        case ZT_EVENT_NONE:
@@ -6414,6 +6416,35 @@
                                "interface %d\n", i->channel);
                }
        }
+       case ZT_EVENT_RINGBEGIN:
+       /*
+               ast_log(LOG_DEBUG, "FUNC handle_init_event(): I'm at
ZT_EVENT_RINGBEGIN\n");
+               ast_log(LOG_DEBUG, "FUNC handle_init_event():
ring_count = %d\n", ring_count);
+       */
+               if (ring_count >= 0) {
+                       if ((time(NULL) - last_event) < 10) {
+                               if (ring_count > 3) {
+                                       /* Sequance finished, cleanup nicely */
+                                       ring_count=-1;
+                                       last_event=0;
+                                       /* NOTE: Sequance is finished
by NOT calling zap_restart()
+                                                allowing zaptel to
continue with event 2 - Answer
+                                       */
+                               } else {
+                                       /* Not enough rings event, try
harder next time */
+                                       ring_count++;
+                                       last_event=time(NULL);
+                                       zap_restart();
+                                       }
+                       } else {
+                               /* Cleanup after previous sequance was
interupted */
+                               ring_count=0;
+                               last_event=time(NULL);
+                               zap_restart();
+                       }
+               /* no ring? start new ringing sequance */
+               } else { ring_count++; last_event=time(NULL); zap_restart(); }
+               break;
        return 0;
 }

Thank you.

-- 
Cheers,
Maxim Vexler

"Free as in Freedom" - Do u GNU ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: full
Type: application/octet-stream
Size: 15607 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20060719/3b94720d/full.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: answer_machine.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20060719/3b94720d/answer_machine.bin


More information about the asterisk-users mailing list