📄 ag_ring.c
字号:
#include "ag_private.h"
#include "ag.h"
#include <string.h>
/*
agSendCallerId
Used in the hands free profile, optionally send the calling number
*/
static void agSendCallerId(void)
{
/* Only send caller id if the remote device supports it */
if ((AGState.hfSupportedFeatures >> 2) & 0x01)
{
/* TODO the <type> field probably isn't being set correctly*/
const char *clip_str = "\r\n+CLIP: 01223 123456, 128\r\n";
(void)agSendATmessage(clip_str, strlen(clip_str));
}
}
/*
ringInd
Send a ring indication to the client - either on or off.
*/
static void ringInd(void)
{
const char *ring = "\r\nRING\r\n";
if(agSendATmessage(ring, strlen(ring)))
{
if (!AGState.ringContinuous)
AGState.rings_outstanding--;
}
/* For hands free devices if called id is supported send some number */
if (agIsCurrentlyHandsFree())
{
/* TODO let the calling num be supplied by the driver */
agSendCallerId();
}
}
/*
sendNextRing
Called to turn the ring signal off after RING_DURATION (if
RING_DURATION is not D_NEVER of course.)
*/
static Delay sendNextRing(TimerHandle h)
{
h=h;
if (AGState.ringContinuous)
{
/* if continuous ring enabled just start off another ring */
ringInd();
return AGState.RingDuration;
}
else if (AGState.rings_outstanding > 1)
{
ringInd();
return AGState.RingDuration;
}
else if (AGState.rings_outstanding == 1)
{
ringInd();
return D_NEVER;
}
else
{
return D_NEVER;
}
}
/*
agStopRings
Only applies for the handsfree really as that must send out rings
until the call is accepted or rejected, this function allows the
ringing to be stopped.
*/
void agStopRings()
{
AGState.rings_outstanding = 0;
AGState.ringContinuous = 0;
}
/*
agRingReqAction
This function is called by the parse code if a RING command is
received from the Connection Manager to pass the message up to the
client.
*/
void agRingReqAction(timeout_t repetition_rate, uint8 number_rings)
{
if (agRfcommConnectedQuery())
{
/* If we're connected to a hf device we need to send call_setup indicator */
if (agIsCurrentlyHandsFree())
agSendCallSetupInd(call_setup_incoming_call);
AGState.RingDuration = D_SEC(repetition_rate);
AGState.rings_outstanding = number_rings;
/* send out a one or more ring messages */
if (AGState.rings_outstanding > 0)
{
/* number of rings must be more than 1 otherwise do nothing */
ringInd();
if (AGState.rings_outstanding > 0)
(void) TimerAdd(AGState.RingDuration, sendNextRing);
}
else if (AGState.rings_outstanding == 0)
{
/* Continuous ring until call answered or rejected */
AGState.ringContinuous = 1;
ringInd();
(void) TimerAdd(AGState.RingDuration, sendNextRing);
}
}
else
{
agSendErrorToClient(AgErrorUnexpectedPrimitive, 0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -