金牌会员
- 积分
- 1214
- 金钱
- 1214
- 注册时间
- 2016-5-19
- 在线时间
- 297 小时
|
1金钱
linelen = get_line(linebuff,redata+getlen+2*linenum,len);这句语句linenum为什么要*2
/**
* @brief 扫描周边的蓝牙设备,并存储到设备列表中。
* @param bltDev ,蓝牙设备列表指针
* @retval 是否扫描到设备,0表示扫描到,非0表示没有扫描到
*/
uint8_t parseBluetoothAddress(BLTDev *bltDev)
{
/* Address should look like "+ADDR:<NAP>:<UAP>:<LAP>",
* where actual address will look like "1234:56:abcdef".
*/
char* redata;
uint16_t len;
char linebuff[50];
uint16_t linelen;
uint16_t getlen=0;
uint8_t linenum=0;
uint8_t i;
char *p;
HC05_Send_CMD("AT+INQ\r\n",0);
redata =get_rebuff(&len);
if(redata[0] != 0 && strstr(redata, "+INQ:") != 0)
{
HC05_DEBUG("rebuf =%s",redata);
getNewLine:
while(getlen < len-2*linenum )
{
linelen = get_line(linebuff,redata+getlen+2*linenum,len);
if(linelen>50 && linelen != 0)
{
HC05_Send_CMD("AT+INQC\r\n",1);//退出前中断查询
return 1;
}
getlen += linelen;
linenum++;
p = skipPrefix(linebuff,linelen,"+INQ:");
if(p!=0)
{
uint8_t num ;
num = bltDev->num;
strBLTAddr(bltDev,':');
for(i=0;i<=num;i++)
{
if(strstr(linebuff,bltDev->unpraseAddr[i]) != NULL)
{
goto getNewLine; //!=null时,表示该地址与解码语句的地址相同
}
}
/*若蓝牙设备不在列表中,对地址进行解码*/
bltDev->addr[num].NAP = htoul(p);
p = strchr(p,':');
if (p == 0)
{
HC05_Send_CMD("AT+INQC\r\n",1);//退出前中断查询
return 1;
}
bltDev->addr[num].UAP = htoul(++p);
p = strchr(p,':');
if (p == 0)
{
HC05_Send_CMD("AT+INQC\r\n",1);//退出前中断查询
return 1;
}
bltDev->addr[num].LAP = htoul(++p);
/*存储蓝牙地址(字符串形式)*/
sprintf(bltDev->unpraseAddr[num],"%X:%X:%X",bltDev->addr[num].NAP,bltDev->addr[num].UAP,bltDev->addr[num].LAP);
bltDev->num++;
}
}
clean_rebuff();
HC05_Send_CMD("AT+INQC\r\n",1);//退出前中断查询
return 0;
}
else
{
clean_rebuff();
HC05_Send_CMD("AT+INQC\r\n",1);//退出前中断查询
return 1;
}
}
|
|