1 second timer example


#1

How to define timer to start count when the adl_call_event_answer_OK ?

This is the timer method that im using:

adl_tmr_t *setTimer;
int8 Seconds;

void startTimerHandler ()	
{

}

void stopTimer(){
 adl_tmrUnSubscribe(setTimer,
			   (adl_tmrHandler_t)startTimerHandler,
			   ADL_TMR_TYPE_100MS);
}

//------------------------------------------------
s8 Call_Handler(u16 Event, u32 Call_ID)
{
    s8 sReturn;
    sReturn = ADL_CALL_FORWARD;                          
    switch (Event)
    {
        case ADL_CALL_EVENT_SETUP_OK_FROM_EXT:   break;
        case ADL_CALL_EVENT_SETUP_OK:            break;
        case ADL_CALL_EVENT_ANSWER_OK_FROM_EXT:  break;	
        case ADL_CALL_EVENT_ANSWER_OK:           break; 
        case ADL_CALL_EVENT_RING_VOICE:	  	 break;		
	case ADL_CALL_EVENT_ANSWER_OK:
        TRACE (( 2, "Call OK" ));
 	setTimer=(adl_tmr_t *)adl_tmrSubscribe,
        (FALSE,10,ADL_TMR_TYPE_100MS,
        (adl_tmrHandler_t)startTimerHandler); 
			 //Seconds++;			 
	break;
	case ADL_CALL_EVENT_HANGUP_OK:          
        TRACE (( 7, "Hangup OK" ));
        break;
    }  
    return sReturn;
}

// -------------------------- main ---------------------------------------------
void adl_main ( adl_InitType_e InitType )
{
  Seconds=0;
  adl_callSubscribe(Call_Handler);					
}

Question:
I know that this wont work so the question is how to trigger the timer to start the count when adl_call_event_answer_OK occour and how to define startTimerHandler ?


#2

Hi Mark,

You can subscribe to a cyclic timer from the event ADL_CALL_EVENT_ANSWER_OK. A cyclic timer would expire after the specified timeout interval and the timer callback function would automatically be called by the ADL library. You can use a global variable which can be incremented from the timer callback function each time the timer expires.

Hence, using this mechanism you can find out the duration for which the call existed. (I think this is the scenario that you want to achieve).

For instance,

case ADL_CALL_EVENT_ANSWER_OK:
TRACE (( 2, “Call OK” ));
setTimer=(adl_tmr_t *)adl_tmrSubscribe,
(TRUE,10,ADL_TMR_TYPE_100MS,
(adl_tmrHandler_t)startTimerHandler);


Now define the timer handler function as:
void startTimerHandler (u8 id)
{
myCount++; //The myCount is a global integer variable
}

When the call is hung up, you can unsubscribe from the timer that is subscribed in the ADL_CALL_EVENT_ANSWER_OK.

I hope this should solve your problem.

Best Regards,
Open AT Fan.


#3

“Subscribing” to a timer “starts” the timer;

“UnSubscribing” from a timer “stops” the timer.

Note that the return value from the unsubscribe call gives the length of time that was remaining until the timer would have expired…


#4

Everything is working except that i can not split the options.
I other words if i define multiple if’s non of them will be triggered.

e.g.
void startTimerHandler ()
{
myCount++;
}

if (myCount < 5)
{ something }
if (myCount > 5)
{ something else}

Beside this i can not display the myCount value so i dont know if the timer is counting or not.


#5

Are you sure that both sections of code are using the same myCount variable?
ie is it a proper global, or do you have 2 independent locals…?

Note also that the above code does nothing when myCount==5.

Why not?
Can’t you use a TRACE, or send an AT repsonse…?


#6

This is the code that im using.
I have tryed with different handlers to detect length of the call but i nothing happens. You get constant RING sign.

#include "adl_global.h"

const u16 wm_apmCustomStackSize = 1024;
adl_tmr_t *setTimer;
s8 myCount;
//-------------------------------------------------------
void timerHandler (u8 id)                      
{   
myCount++;
}

void stopTimer()
{
adl_tmrUnSubscribe(setTimer,(adl_tmrHandler_t)timerHandler,ADL_TMR_TYPE_100MS); 
}

s8 Call_Handler(u16 Event, u32 Call_ID)
{
s8 sReturn;
sReturn = ADL_CALL_FORWARD;                         

switch (Event)
{
case ADL_CALL_EVENT_ANSWER_OK:
TRACE (( 2, "Call OK" )); myCount= 0;
setTimer=(adl_tmr_t *)adl_tmrSubscribe,(TRUE,10,ADL_TMR_TYPE_100MS,(adl_tmrHandler_t)timerHandler);
break;
//-------------------------------------------------------------------------
case ADL_CALL_EVENT_HANGUP_OK: 
stopTimer();
if (myCount <  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - under -\r\n" )myCount=0;}
if (myCount == 5){ /* something */ }           
if (myCount >  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - over - \r\n" )myCount=0;}
break;   
//------------------------------------------------------------------------------------------     
case ADL_CALL_EVENT_RING_VOICE:
TRACE (( 7, "Ring OK" )); 
break;
} 
return sReturn;
}

void adl_main ( adl_InitType_e InitType )
{
myCount=0;
adl_callSubscribe(Call_Handler);                  
}

#7

What is this supposed to do? I would say that is not even correct syntax!?!

Best Regards,
Jan


#8
adl_atSendResponse ( ADL_AT_UNS, "\r\n - under -\r\n" )myCount=0;

Come on Jan, you know i could not compile this without ; sign.

Just to give me some notification if the call is accepted under some time.
I’v tryed also with TRACE, ADL_AT_RSP.


#9

So why you don’t just paste it from your source code???

I thought the compiler just created a program from it by error - you never know with gcc, do you?

So how does your trace output look like?


#10

Yes - so why would you post code that doesn’t even compile?! :unamused:

If your post contains “obvious” transcription errors like this, then who knows what others might be lurking in there?

There is really no point in posting code unless you use copy-and-paste.

Any manual typing is almost bound to introduce differences - you might even fix the problem that caused your real code to not work!

And please, lay it out legibly - and use the ‘Preview’ button to check it!


#11

Jan, awneil i must apologize myself. Im bit on the edge with this, becuse it look like some standard problem and im spinning in circle…

The TMT trace output looks like:


#12

You should be looking on CUS4 for your own Application Trace, shouldn’t you?


#13

I restarted the target few times set CUS4 on all, and this is what i get:


#14

These are internally generated by ADL.
Unfortunately, as is the way with Wavecom, I can’t see anywhere where these are documented. :angry:

However, they should be fairly self-explanatory:

Traces a non-cyclic timer subscription with value 10

You’ve subscribed to the ADL Call Service

You are repeatedly re-subscribing the timer - with the same handler.

Note that you can turn on timestamping in the Target Monitoring Tool - so that should show you whether your timer is going at the right rate.

So now you just need to add some (more) of your own TRACE to see what’s happening with your counter…


#15

I added few traces, accept those two in the original post, and the output is the same. Becuse im now realy stuck on this, can you copy - paste my orginal code, test it on your maschine and post edited code back ?

I dont know, but i can not find the error and regarding to number of views on this topic i guess that this thema is interesting to other forum members…

Anyway, thank you for your respond !


#16

Of course I can’t! :unamused:

It’s your code on your machine - I have no access to it! :unamused:

You need to post the code in the first place.
Be sure to post code that actually compiles without errors and warnings;
Be sure to post it by copying from your text file and pasting into the forum.

See above.


#17

dear awneil,
the code that im talking about is sended before few posts.
Accept that, time part is set in the voice handler and i correct error with ; signs.
This program is compiled without errors and this is whole program.

#include "adl_global.h"

const u16 wm_apmCustomStackSize = 1024;
adl_tmr_t *setTimer;
s8 myCount;
//-------------------------------------------------------
void timerHandler (u8 id)                     
{   TRACE (( 4, "Timer started" ));
myCount++;
}

void stopTimer()
{
adl_tmrUnSubscribe(setTimer,(adl_tmrHandler_t)timerHandler,ADL_TMR_TYPE_100MS);
}

s8 Call_Handler(u16 Event, u32 Call_ID)
{
s8 sReturn;
sReturn = ADL_CALL_FORWARD;                         

switch (Event)
{
case ADL_CALL_EVENT_ANSWER_OK:
TRACE (( 2, "Call OK" )); myCount= 0;
setTimer=(adl_tmr_t *)adl_tmrSubscribe,(TRUE,10,ADL_TMR_TYPE_100MS,(adl_tmrHandler_t)timerHandler);
break;
//-------------------------------------------------------------------------
case ADL_CALL_EVENT_HANGUP_OK:
stopTimer();
break;   
//------------------------------------------------------------------------------------------     
case ADL_CALL_EVENT_RING_VOICE:
TRACE (( 7, "Ring OK" ));
if (myCount <  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - under -\r\n" );myCount=0;}
if (myCount == 5){ /* something */ }           
if (myCount >  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - over - \r\n" );myCount=0;}
break;
}
return sReturn;
}

void adl_main ( adl_InitType_e InitType )
{
myCount=0;
adl_callSubscribe(Call_Handler);                 
}

When i enter voice handler all i get is continues RING and when i look into trace then i get this what i have writen before.


#18

The code you posted before didn’t even compile!

The code you have posted is almost unreadable - do your really format you code like that?

It doesn’t build either:

so what other little “details” have you “forgotten” in your post…? :unamused:


#19

Hello,

I think Marc is using Open AT v4.xx (that’s why the wm_apmCustomStack variable is not declared as it it not required in this version of Open AT).

From the problem that is faced by Marc, I feel that the problem lies in answering to the call. From the code, it can be seen that in the case ADL_CALL_EVENT_RING_VOICE, the call is not answered. Please note that to answer any incoming call, the API adl_callAnswer () should be used.

Hence, the code should look something like:

case ADL_CALL_EVENT_RING_VOICE:
TRACE (( 7, "Ring OK" ));
if (myCount <  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - under -\r\n" );myCount=0;}
if (myCount == 5){ /* something */ }           
if (myCount >  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - over - \r\n" );myCount=0;}
adl_callAnswer();
break;

When the call is hung up, the time for which the call was there could be conviently printed out from the event ADL_CALL_EVENT_HANGUP_OK. The statement:
TRACE((1,“The call was made for %d minutes”,myCount));
can be used to print the duration for which the call was there (in minutes).

It can be noted that if the user wants to hangup the call from withing the Open AT application, the API adl_callHangup () can also be used.

Marc, you can refer to the ADL user guide, for more information as to how to use the APIs and also find out which API suits your requirement.

Best Regards,
Open AT Fan.


#20

The version is 4.xx and i using VC++. I did not get any errors. When i place a call i get -under- and answer OK. So i change the < to > to see the difference but its the same. One RING, message, answer OK. It does not matter if its over or under 5 seconds, one RING and answer.

Btw.
How will the ADL_CALL_EVENT_RING_VOICE know when the call is over. I mean, when i get hangup i have to go back into ADL_CALL_EVENT_RING_VOICE handler to read the myCount value, but i can not becuse the call is over so i can not go back into this handler. This could be total wrong thinking or …?

I can not see the:
TRACE((1,“The call was made for %d minutes”,myCount)); in the trace.

Trace:

Terminal: