blob: 16458030387cd87d3c8c47b0dbd8506f2c75b8f1 [file] [log] [blame]
#include "lynq/lynq_call_api.h"
#include "mbtk_info_api.h"
static mbtk_info_handle_t* info_handle = NULL;
int lynq_volume_size = 0;
mbtk_audio_client_handle_type lynq_dtmf_handle;
mbtk_call_info_t lynq_reg[5]={0};
int *handle_ptr=null;
void (*incoming_call_cb_p)(int x)=NULL;
void lynq_call_state_change_cb(const void* data, int data_len)
{
mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
switch (reg->call_wait)
{
case MBTK_CLCC:
{
lynq_reg[reg->dir1].dir1 = reg->dir1;
lynq_reg[reg->dir1].dir = reg->dir;
lynq_reg[reg->dir1].state = reg->state;
lynq_reg[reg->dir1].mode = reg->mode;
lynq_reg[reg->dir1].mpty = reg->mpty;
memset(lynq_reg[reg->dir1].phone_number,0,strlen(reg->phone_number));
memcpy(lynq_reg[reg->dir1].phone_number,reg->phone_number,strlen(reg->phone_number));
lynq_reg[reg->dir1].type = reg->type;
printf("\r\nRING : %d, %d, %d, %d, %d, %s, %d, %d\r\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type,strlen(reg->phone_number));
if(handle_ptr != null)
{
if(*handle_ptr != reg->dir1)
{
*handle_ptr = reg->dir1;
printf("reg->dir1 : %d\r\n handle=%d\n", reg->dir1,*handle_ptr);
handle_ptr = NULL;
}
}
if(reg->dir == 1)
(*incoming_call_cb_p)(reg->dir1);
break;
}
case MBTK_DISCONNECTED:
memset(&(lynq_reg[reg->disconnected_id]),0,sizeof(lynq_reg[reg->disconnected_id]));
printf("\r\nRING : call dis connected: %d!\r\n", reg->disconnected_id);
printf("phone number : %s",lynq_reg[reg->disconnected_id].phone_number);
lynq_set_mute_mic(0);
break;
case MBTK_CPAS:
printf("\r\nCALL : Call state = %d\r\n", reg->pas);
/*
MBTK_CALL_RADY, //MT allows commands from TA/TE
MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE
MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions
MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active
MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress
MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state
MBTK_CALL_ACTIVE,
*/
switch (reg->pas)
{
case MBTK_CALL_RADY:
printf("CALL: call READY\r\n");
break;
case MBTK_CALL_UNAVAILABLE:
printf("CALL: call unavaliable\r\n");
break;
case MBTK_CALL_UNKNOWN:
printf("CALL: call unknown\r\n");
break;
case MBTK_CALL_RINGING:
printf("CALL: call ringing\r\n");
break;
case MBTK_CALL_PROGRESS:
printf("CALL: call progress\r\n");
break;
case MBTK_CALL_ASLEEP:
printf("CALL: call asleep\r\n");
break;
case MBTK_CALL_ACTIVE:
printf("CALL: call active\r\n");
break;
default:
printf("\r\n");
break;
}
break;
default:
printf("\r\nRING : None call_wait = %d\r\n", reg->call_wait);
break;
}
/*
if(reg->call_wait == ) //CLCC
{
printf("\r\nRING : %d, %d, %d, %d, %d, %s, %d\r\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
}
else if(reg->call_wait == 2) //Disconnected
{
printf("\r\nRING : call dis connected!\r\n");
}
else
{
printf("\r\nRING : None\r\n");
}
*/
}
void lynq_dtmf_cb(char dtmf)
{
printf("%s:%c\n", __FUNCTION__, dtmf);
}
int lynq_init_call(int uToken)
{
UNUSED(uToken);
mbtk_audio_ubus_client_init(&lynq_dtmf_handle, lynq_dtmf_cb);
if(info_handle == NULL)
{
info_handle = mbtk_info_handle_get();
if(info_handle)
{
int err = mbtk_call_state_change_cb_reg(info_handle, lynq_call_state_change_cb);
if(err) {
return -1;
} else {
return 0;
}
}
}
return -1;
}
int lynq_deinit_call(void)
{
if(info_handle)
{
return mbtk_info_handle_free(&info_handle);
}
else
{
return -1;
}
}
int lynq_call(int *handle, char addr[])
{
if(info_handle == NULL)
{
return -1;
}
if(strlen(addr)>=90)
{
printf("\ninput phone number over load!\n");
return -1;
}
char *buf = addr;
int err = mbtk_call_start(info_handle, buf);
if(err) {
return -1;
} else {
handle_ptr = handle;
return 0;
}
}
int lynq_call_answer()
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_call_answer(info_handle);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_call_hungup_all()
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_call_hang(info_handle);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_call_hungup(int *handle)
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_a_call_hang(info_handle, *handle);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_hangup_waiting_or_background(void)
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_waiting_or_background_call_hang(info_handle);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_hangup_foreground_resume_background(void)
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_foreground_resume_background_call_hang(info_handle);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_switch_waiting_or_holding_and_active(void)
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_call_answer(info_handle);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_wait_incoming_call(void *incoming_call_cb)
{
if(incoming_call_cb == NULL)
return -1;
incoming_call_cb_p = incoming_call_cb;
return 0;
}
int lynq_get_mute_mic (int *status)
{
if(status == NULL)
{
return -1;
}
int err = mbtk_mute_state_get(info_handle, status);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_set_mute_mic(const int enable)
{
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_mute_state_set(info_handle, enable);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_set_DTMF(const char callnum)
{
//0......9 A B C D * #
if(info_handle == NULL)
{
return -1;
}
char callnum_default[17]="0123456789ABCD*#";
if((strchr(callnum_default,callnum))==NULL)
{
printf("please input 0123456789ABCD*#\n");
return -1;
}
mbtk_call_dtmf_info_t dtmf_character;
dtmf_character.character = callnum;
dtmf_character.duration = 500;
int err = mbtk_dtmf_send(info_handle, &dtmf_character);
if(err) {
return -1;
} else {
return 0;
}
}
int lynq_get_current_call_state(int *handle,int *call_state,int*toa,int *direction,char addr[])
{
int flag=0;
int i;
for (i = 0; i < 5; i++)
{
if(lynq_reg[i].dir1 == *handle)
{
*direction = lynq_reg[i].dir;
*toa = lynq_reg[i].type;
memset(addr,0,sizeof(addr));
memcpy(addr, lynq_reg[i].phone_number, strlen(lynq_reg[i].phone_number));
int len = strlen(lynq_reg[i].phone_number);
addr[len]='\0';
switch (lynq_reg[i].state)
{
case MBTK_ACTIVE:
*call_state = LYNQ_CALL_ACTIVE;
break;
case MBTK_HELD:
*call_state = LYNQ_CALL_HOLDING;
break;
case MBTK_DIALING:
*call_state = LYNQ_CALL_DIALING;
break;
case MBTK_ALERTING:
*call_state = LYNQ_CALL_ALERTING;
break;
case MBTK_INCOMING:
*call_state = LYNQ_CALL_INCOMING;
break;
case MBTK_WAITING:
*call_state = LYNQ_CALL_WAITING;
break;
case MBTK_OFFERING:
*call_state = LYNQ_CALL_OFFERING;
break;
default:
break;
}
flag = 1;
break;
}
}
if(flag == 0)
{
return -1;
}
return 0;
/*
if(info_handle == NULL)
{
return -1;
}
int err = mbtk_call_reg_get(info_handle, &reg);
if(err) {
return -1;
} else {
printf("CLCC : %d, %d, %d, %d, %d, %s, %d", reg.dir1, reg.dir, reg.state, reg.mode, reg.mpty, reg.phone_number, reg.type);
*direction = reg.dir;
*toa = reg.type;
memcpy(addr, reg.phone_number, strlen(reg.phone_number));
switch (reg.state)
{
case MBTK_ACTIVE:
*call_state = LYNQ_CALL_ACTIVE;
break;
case MBTK_HELD:
*call_state = LYNQ_CALL_HOLDING;
break;
case MBTK_DIALING:
*call_state = LYNQ_CALL_DIALING;
break;
case MBTK_ALERTING:
*call_state = LYNQ_CALL_ALERTING;
break;
case MBTK_INCOMING:
*call_state = LYNQ_CALL_INCOMING;
break;
case MBTK_WAITING:
*call_state = LYNQ_CALL_WAITING;
break;
case MBTK_OFFERING:
*call_state = LYNQ_CALL_OFFERING;
break;
default:
break;
}
return 0;
}
*/
}
void lynq_audio_volume_cb(int volume)
{
lynq_volume_size = volume;
if(lynq_volume_size <= 0 || lynq_volume_size > 100)
{
}
else
{
//printf("%s:%d\n", __FUNCTION__, volume);
printf("%s:%d\n", __FUNCTION__, lynq_volume_size);
}
}
int lynq_set_speech_volume(const int volume)
{
if(volume <= 0 || volume >= 101)
{
printf("input error\n");
return -1;
}
else
{
int set_volume = 0;
set_volume = volume;
mbtk_audio_ubus_volume_set(set_volume);
return 0;
}
}
int lynq_get_speech_volume(int * volume)
{
mbtk_audio_ubus_volume_get(lynq_audio_volume_cb);
sleep(1);
*volume = lynq_volume_size;
return 0;
}