/************************************************************************************
*函数描述:
*参数: port串口号
* str要查找的字符串
* offset偏移量
* num要读取的字符个数
* flag<=0向后取,>0向前取
* time时间S
*返回值:返回得到的字符串
*************************************************************************************/
void rt_indexStr(rt_uint8_t port ,rt_uint8_t* str,rt_uint8_t * tempstr,rt_uint32_t offset,rt_uint32_t num,rt_bool_t flag,rt_uint32_t times)
{
rt_uint32_t waittickets = rt_tick_get();
rt_uint8_t buf[TEMPBUFLEN];
rt_uint16_t index=0,bufindex=0;
rt_uint16_t lens=rt_strlen((const char*)str);
rt_uint32_t i,j,h;
// rt_uint8_t * tempstr;
struct tunnel_ack_msg msg;
rt_mq_t mq = (rt_mq_t)(getgprsdatamsq());
//setgprsWaiting(port,mq);
//rt_kprintf("GET mq OK\x0d\x0a0\r\n");
rt_kprintf("rt_indexStr\x0d\x0a0\r\n");
while ((rt_tick_get() - waittickets) < rt_tick_from_millisecond(times*1000))
{
if(rt_mq_recv(mq, &msg, sizeof(struct tunnel_ack_msg), 1) == RT_EOK)
{
if(msg.size > 0)
{
if((bufindex + msg.size ) <= TEMPBUFLEN)
{
rt_memcpy( &buf[bufindex],msg.buf,msg.size);
bufindex+=msg.size;
}
else
{
rt_memcpy( &buf[0],&buf[(bufindex + msg.size ) - TEMPBUFLEN],TEMPBUFLEN - msg.size);//数据拷贝长度正确
bufindex = TEMPBUFLEN - msg.size;
rt_memcpy( &buf[bufindex],msg.buf,msg.size);
bufindex+=msg.size;
}
//msg.buf[msg.size] = 0;
//rt_kprintf(msg.buf);
// rt_kprintf("@\r\n");
for(i = 0;i < TEMPBUFLEN && index < lens;i++)
{
// rt_kprintf("msg.buf 0 %c\r\n",buf[i]);
if(rt_strncmp((const char*)&buf[i] ,(const char*)&str[index],1) == 0)
{
index++;
h=i;
}
else
{
index = 0;
}
}
if(index == lens)
{
rt_kprintf("index == lens\r\n",str);
if(flag<=0)//向后取
{
rt_kprintf("==========flag<=0==========\r\n");
//for(j=(h+offset);j<=(h+offset+num);j++)
for(j=0;j<num;j++)
{
rt_kprintf("buf %c\r\n",buf[h+offset+j]);
tempstr[j]=buf[h+offset+j];
rt_kprintf("%c--------%c\r\n",buf[h+offset+j],tempstr[j]);
}
}
else//向前取
{
rt_kprintf("===========flag>0=========\r\n");
//for(j=(h-lens-offset);j<=(h-lens-offset+num);h++)
for(j=0;j<num;j++)
{
tempstr[j]=buf[h-lens-offset+j];
rt_kprintf("%c--------%c\r\n",buf[h-lens-offset+j],tempstr[j]);
}
}
}
}
}
}
}