AnsweredAssumed Answered

Phone APP can't read characteristic from QN902x peripheral device

Question asked by Leaf Lee on Jul 9, 2018
Latest reply on Nov 8, 2018 by Leaf Lee

I defined 2 characteristics with 1 service on my QN902x peripheral device, as below:

 

 

unsigned char attdata[20];

const struct atts_desc llf_att_db[5] = //'5' used in atts_svc_create_db()!!!!!!
{
[0]={ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), sizeof(llf_main_svc), sizeof(llf_main_svc), (uint8_t *)&llf_main_svc},

[1]={ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(llf_report_char), sizeof(llf_report_char), (uint8_t *)&llf_report_char},

[2]={LLF_ATT_CHAR_REPORT, PERM(RD, ENABLE), 20, 0, NULL}, //'2' is the index of reading!!!!!!

[3]={ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(llf_command_char), sizeof(llf_command_char), (uint8_t *)&llf_command_char},

[4]={LLF_ATT_CHAR_COMMAND, PERM(WR, ENABLE), 14, 0, NULL}, //'4' is the index of writing!!!!!!
};


const uint16_t llf_main_svc = LLF_MAIN_SVC;
const struct atts_char_desc llf_report_char = ATTS_CHAR(ATT_CHAR_PROP_RD, 0, LLF_ATT_CHAR_REPORT);
const struct atts_char_desc llf_command_char = ATTS_CHAR(ATT_CHAR_PROP_WR_NO_RESP, 0, LLF_ATT_CHAR_COMMAND);

 

 

"LLF_ATT_CHAR_REPORT",index=[2], is a characteristic for a counterpart device (phone) to read. I initialized it and updated it as below:

 

 

static int llf_enable_req_handler(ke_msg_id_t const msgid,
struct llf_enable_req const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
uint8_t ctemp;

// con_info=conhdl+appid+prfid
llf_env.con_info.appid = src_id;
llf_env.con_info.conhdl = param->conhdl;

if (gap_get_rec_idx(param->conhdl) == GAP_INVALID_CONIDX) //send error message to TASK_APP
{
prf_server_error_ind_send((prf_env_struct *)&llf_env, PRF_ERR_REQ_DISALLOWED,
LLF_ERROR_IND, LLF_ENABLE_REQ);
}
else
{
for(ctemp=0;ctemp<20;ctemp++) attdata[ctemp]=0; //prepare report char for phone!!!!!!
attsdb_att_set_value(llf_env.shdl+2, 20, attdata);
attsdb_svc_set_permission(llf_env.shdl, param->sec_lvl); //security requirement!!!!!!
ke_state_set(TASK_LLF, LLF_CONNECTED);
}

return (KE_MSG_CONSUMED);
}


static int gatt_write_cmd_ind_handler(ke_msg_id_t const msgid,
struct gatt_write_cmd_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
uint8_t ctemp;

if ((param->conhdl == llf_env.con_info.conhdl)&&(param->handle == llf_env.shdl + 4)&&(param->value[0]==0xaa))
{
attdata[0]=0xa5;
switch(param->value[1]){
case 0x01:
if(param->value[2]!=0xfe) break;
if(!pwmipfg) pwmgetidip();
if(!pwmipfg) {
attdata[1]=0x47;
attdata[2]=0xb8;
attsdb_att_set_value(llf_env.shdl+2, 3, attdata);
break;
}
attdata[1]=0x01;
attdata[2]=0xfe;
for(ctemp=0;ctemp<8;ctemp++) attdata[ctemp+3]=iddata[ctemp];
for(ctemp=0;ctemp<8;ctemp++) attdata[ctemp+11]=ipbddt[ctemp]; //6->7###
// attsdb_att_set_value(llf_env.shdl+2, 19, attdata);
attsdb_att_set_value(llf_env.shdl+2, 20, attdata);
// attsdb_att_set_value(param->handle, 8, (uint8_t *)&param->value[0]); //len='8'?
// atts_write_rsp_send(llf_env.con_info.conhdl, param->handle, PRF_ERR_OK); //no need rsp
break;
case 0x02:
if(param->value[2]!=0xfd) break;
attdata[1]=0x02;
attdata[2]=0xfd;
attdata[3]=pwmsigval();
// attsdb_att_set_value(llf_env.shdl+2, 4, attdata);
attsdb_att_set_value(llf_env.shdl+2, 20, attdata);
break;
case 0x10:
if(param->value[2]!=0xef) break;
pwmclose();
// attdata[1]=0x10;
// attdata[2]=0xef;
// attsdb_att_set_value(llf_env.shdl+2, 3, attdata);
break;
case 0x11:
if(param->value[2]!=0xee) break;
attdata[1]=0x11;
attdata[2]=0xee;
attdata[3]=pwmopenlock(param->value[3],param->value[4]);
// attsdb_att_set_value(llf_env.shdl+2, 4, attdata);
attsdb_att_set_value(llf_env.shdl+2, 20, attdata);
break;
case 0x12:
if(param->value[2]!=0xed) break;
attdata[1]=0x12;
attdata[2]=0xed;
//should check ID######
attdata[3]=pwmopensuper();
// attsdb_att_set_value(llf_env.shdl+2, 4, attdata);
attsdb_att_set_value(llf_env.shdl+2, 20, attdata);
break;

}
attsdb_att_set_value(param->handle, 14, (uint8_t *)&param->value[0]); //len='8'?
}
return (KE_MSG_CONSUMED);
}

 

 

The phone APP can read the characteristic of "LLF_ATT_CHAR_REPORT" after connection.

But once  the characteristic of "LLF_ATT_CHAR_REPORT" updated, The phone APP can not read the characteristic of "LLF_ATT_CHAR_REPORT" any more!

 

 

I really feel confused about it. Anyone met that situation?

Outcomes