188 lines
6.3 KiB
C
188 lines
6.3 KiB
C
/**************************************************************************************************
|
||
* Copyright (c) Fenda Technologies Co., Ltd. 2020-2021. All rights reserved.
|
||
* Description: 来电接口
|
||
* Author: ball.caojianguang
|
||
* Create: 2020-5-21
|
||
**************************************************************************************************/
|
||
|
||
#include "ble_incoming_server.h"
|
||
|
||
#include "ble_data_transmission.h"
|
||
#include "ble_management_server.h"
|
||
#include "radio_ble_app.h"
|
||
#include "ui_port_fw.h"
|
||
#include "ui_event.h"
|
||
#include "sql_setting.h"
|
||
|
||
|
||
|
||
/***************************************************************************************************
|
||
4.15.1 -- 来电通知
|
||
***************************************************************************************************/
|
||
void Ble_IncomingNotify(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
uint16_t write_idx = 0;
|
||
protocol_data_info_t data_info = {0};
|
||
static IncomingCallInfo_t IncomingCallInfo_temp = {0};
|
||
|
||
if(sql_setting_get_ble_switch_message_notify() == 0)
|
||
{// app关闭了消息通知总开关
|
||
ble_printf("****** Message Notify Switch Is Turn off. ******\r\n");
|
||
return;
|
||
}
|
||
|
||
memset(&IncomingCallInfo_temp, 0, sizeof(IncomingCallInfo_t));
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
|
||
switch(data_info.type & 0x7f) {
|
||
case CALL_IN_TYPE:
|
||
data_info.len = 0;
|
||
break;
|
||
|
||
case CALLER_NUMBER_TYPE:
|
||
if(data_info.len < 32) {
|
||
memcpy(IncomingCallInfo_temp.tel, data_info.p_data, data_info.len);
|
||
} else {
|
||
memcpy(IncomingCallInfo_temp.tel, data_info.p_data, 31);
|
||
}
|
||
|
||
IncomingCallInfo_temp.state = CALL_STATE_RINGING; ////正在响铃
|
||
break;
|
||
|
||
case CALLER_NAME_TYPE:
|
||
if(data_info.len < 32) {
|
||
memcpy(IncomingCallInfo_temp.name, data_info.p_data, data_info.len);
|
||
} else {
|
||
memcpy(IncomingCallInfo_temp.name, data_info.p_data, 31);
|
||
}
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
|
||
}
|
||
|
||
in_data = data_info.p_data;
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
|
||
} while(in_len);
|
||
ble_printf("---->>>>>11111 incoming\n");
|
||
|
||
// ------TO BE ADDED 待添加UI来电提醒 -------
|
||
ui_port_send_sys_remind_event(EVENT_REMIND_CALL, IncomingCallInfo_temp.state, &IncomingCallInfo_temp, sizeof(IncomingCallInfo_t));
|
||
|
||
ble_printf("---->>>>>22222 incoming\n");
|
||
|
||
write_idx = user_set_protocol_error(out_data, INCOMING_SERVER, data_info.error);
|
||
*out_len = write_idx;
|
||
|
||
}
|
||
|
||
|
||
/***************************************************************************************************
|
||
4.15.2 -- 设备操作来电 ( 设备 ---> 手机 )
|
||
***************************************************************************************************/
|
||
void Ble_HandleIncomingUpload(uint8_t incomingOperat)
|
||
{
|
||
if(GetBandPhoneOS() == ANDROID_PHONE){
|
||
uint16_t write_idx = 0;
|
||
uint8_t buf_temp[INCOMING_TEMP_NUM_MAX] = {0};
|
||
|
||
buf_temp[write_idx++] = 0x03; //LTV
|
||
buf_temp[write_idx++] = INCOMMING_REJECT; //type
|
||
buf_temp[write_idx++] = incomingOperat; //value
|
||
BLE_SendFrameById(INCOMING_SERVER, DEVICE_HANDLE_INCOMING_ID, buf_temp, write_idx);
|
||
}else if(GetBandPhoneOS() == IOS_PHONE){
|
||
if(incomingOperat == INCOMMING_REJECT) {
|
||
ancsRejectCall();
|
||
}
|
||
}
|
||
}
|
||
|
||
/***************************************************************************************************
|
||
4.15.2 -- 手机回复设备操作来电 ( 手机 ---> 设备 )
|
||
***************************************************************************************************/
|
||
void BLE_IncomingControlACK(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
protocol_data_info_t data_info = {0};
|
||
// uint8_t IncomingControlACK[2];
|
||
memset(&data_info, 0, sizeof(protocol_data_info_t));
|
||
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
|
||
switch(data_info.type & 0x7f) { //无子节点
|
||
case INCOMMING_REJECT:
|
||
// IncomingControlACK[0] = *data_info.p_data++;
|
||
// IncomingControlACK[1] = *data_info.p_data;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
in_data = data_info.p_data;
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
} while(in_len);
|
||
|
||
*out_len = 0;
|
||
}
|
||
|
||
|
||
/***************************************************************************************************
|
||
5.1.3 -- APP同步静音/拒接/挂断/接听
|
||
***************************************************************************************************/
|
||
void Ble_SynchronizationIncoming(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
uint16_t write_idx = 0;
|
||
protocol_data_info_t data_info = {0};
|
||
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
|
||
switch(data_info.type & 0x7f) { //无子节点
|
||
case CALL_MODE_TYPE:
|
||
// ------TO BE ADDED 待添加UI操作通知 -------
|
||
ui_port_send_sys_remind_event(EVENT_REMIND_CALL, (IncomingCallStateType)(*data_info.p_data), NULL, 0);
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
|
||
}
|
||
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
|
||
} while(in_len);
|
||
|
||
write_idx = user_set_protocol_error(out_data, INCOMING_SERVER, data_info.error);
|
||
*out_len = write_idx;
|
||
}
|
||
|
||
|
||
// 所有涉及到来电的函数指针,这里的顺序和common id 顺序相同
|
||
const p_func_t IncomingServerFunc[INCOMING_SERVERE_MAX_ID] = {
|
||
user_null_func,
|
||
Ble_IncomingNotify, //5.1.1
|
||
BLE_IncomingControlACK, //5.1.2 主动上报 消息机制
|
||
Ble_SynchronizationIncoming //5.1.3
|
||
};
|