prj_client更新:
一、自动扫描
void app_menu_cb(ke_msg_id_t const msgid, void *param)
{
ke_state_t state = (ke_state_get(TASK_APP));
if (APP_INIT == state)
{
switch (msgid)
{
case GAP_READY_EVT:
case GAP_RESET_REQ_CMP_EVT:
app_env.menu_id = menu_start;
app_menu_show();
break;
case GAP_READ_VER_REQ_CMP_EVT:
QPRINTF("*\r\n");
QPRINTF("* Version:\r\n");
QPRINTF("* AP%sHL%1x.%1x.%1xLL%1x.%1x.%1x\r\n",
QN_APP_VER,
((struct gap_read_ver_req_cmp_evt *)param)->host_ver,
((struct gap_read_ver_req_cmp_evt *)param)->host_subver>>8&0xFF,
((struct gap_read_ver_req_cmp_evt *)param)->host_subver&0xFF,
((struct gap_read_ver_req_cmp_evt *)param)->lmp_ver,
((struct gap_read_ver_req_cmp_evt *)param)->lmp_subver>>8&0xFF,
((struct gap_read_ver_req_cmp_evt *)param)->lmp_subver&0xFF);
break;
case GAP_READ_BDADDR_REQ_CMP_EVT:
QPRINTF("* BD Address:\r\n");
QPRINTF("* %02x%02x%02x%02x%02x%02x\r\n",
((struct gap_read_bdaddr_req_cmp_evt *)param)->addr.addr[5],
((struct gap_read_bdaddr_req_cmp_evt *)param)->addr.addr[4],
((struct gap_read_bdaddr_req_cmp_evt *)param)->addr.addr[3],
((struct gap_read_bdaddr_req_cmp_evt *)param)->addr.addr[2],
((struct gap_read_bdaddr_req_cmp_evt *)param)->addr.addr[1],
((struct gap_read_bdaddr_req_cmp_evt *)param)->addr.addr[0]);
QPRINTF("*\r\n");
// QPRINTF("* By Derek\r\n");
QPRINTF("* @ %11s, %8s\r\n",
__DATE__,
__TIME__);
QPRINTF("*------------------------\r\n");
// app_env.menu_id = menu_main;
// app_menu_show();
//Leo
printf("Scanning....\r\n");
app_env.input[0]='1';
app_env.menu_id=menu_gap;
app_menu_hdl();
break;
二、只有一个设备时自动建立连接
int app_gap_dev_inq_cmp_handler(ke_msg_id_t const msgid,
struct gap_event_common_cmd_complete const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
QPRINTF("Total %d devices found.\r\n", app_env.inq_idx);
ke_state_set(TASK_APP, APP_IDLE);
app_task_msg_hdl(msgid, param);
//Leo
app_env.menu_id = menu_gap_create_connection;
app_menu_show();
<span style="white-space:pre"> app_menu_hdl();</span>
return(KE_MSG_CONSUMED);
}
static void app_menu_show_gap_inq_record(void)
{
if (app_env.inq_idx > 0)
{
QPRINTF("\r\n");
QPRINTF("Inquiry device record:\r\n");
for (uint8_t i = 0; i < app_env.inq_idx; i++)
{
QPRINTF("%d. %02X%02X%02X%02X%02X%02X\r\n", i,
app_env.inq_addr[i].addr[5],
app_env.inq_addr[i].addr[4],
app_env.inq_addr[i].addr[3],
app_env.inq_addr[i].addr[2],
app_env.inq_addr[i].addr[1],
app_env.inq_addr[i].addr[0]);
}
QPRINTF("Please input the device index:\r\n");
}
else
{
QPRINTF("Inquiry device record is NULL.\r\n");
app_env.menu_id = menu_gap;
}
//Leo
if(app_env.inq_idx==1)
{
app_env.input[0]='0';
app_menu_hdl();
}
}
三、连接上以后自动enable qppc
int app_gap_change_param_req_cmp_handler(ke_msg_id_t const msgid, struct gap_change_param_req_cmp_evt const *param,
ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
if (param->status == CO_ERROR_NO_ERROR)
{
QPRINTF("Update parameter complete, interval: 0x%x, latency: 0x%x, sup to: 0x%x.\r\n",
param->con_interval, param->con_latency, param->sup_to);
}
else
{
QPRINTF("Update parameter failed.\r\n");
}
app_task_msg_hdl(msgid, param);
//Leo
app_env.menu_id = menu_qppc;
app_env.input[0]='1';
app_menu_hdl();
return (KE_MSG_CONSUMED);
}
四、enable qppc OK,待输入2发送命令
int app_qppc_enable_cfm_handler(ke_msg_id_t const msgid,
struct qppc_enable_cfm *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
QPRINTF("QPPC enable confirmation status: 0x%x.\r\n", param->status);
//Leo
app_menu_show();
五、接收消息:
int app_qppc_data_ind_handler(ke_msg_id_t const msgid,
struct qppc_data_ind *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
// uint8_t idx = KE_IDX_GET(src_id);
// if ((data_pack%200) == 0 && (data_pack != 0))
// {
// QPRINTF("(%d)Received %d bytes data[%02X] from characteristic %d\r\n", idx, param->length, param->data[0], param->char_code);
// }
/*
(0)Received 20 bytes data[C9] from characteristic 5
(0)Received 20 bytes data[C9] from characteristic 2
(0)Received 20 bytes data[C9] from characteristic 3
(0)Received 20 bytes data[C9] from characteristic 4
(0)Received 20 bytes data[C9] from characteristic 1
*/
//Leo_success_code
static int8_t i;
printf("**Updated****app_qppc_data_ind_handler(),param->length=%d£¬characteristic %d\r\n",param->length,param->char_code);
for(i=0;i<param->length;i++)
{
printf("app_env.input[%d]= %d\r\n",i,param->data[i]);
}
//
app_task_msg_hdl(msgid, param);
// data_pack ++;
return (KE_MSG_CONSUMED);
}