注册 登录
编程论坛 QT论坛

求助帮忙分析代码

flyingucla 发布于 2012-05-10 21:28, 631 次点击
int i,wlen,rlen;
   char command='\0';
   char txbuff[6];
   char revbuff[7];
   QByteArray rev = " ";
   for(command=0x10;command<=0x20;command++)
   {
           //printf("\n command:%#x",command);
           if( (command == 0x1b)| (command == 0x1c) )
               continue;
           memset(txbuff,'\0',sizeof(txbuff));
           txbuff[0]=0xAA;
           txbuff[1]=0xFF;
           txbuff[2]=command;
           txbuff[3]=0xFF;
           txbuff[3]= txbuff[3]^txbuff[2];
           txbuff[4]=0xFF;
           txbuff[5]='\0';
           fflush(stdout);
           wlen = m_tty.tty_write(sel_fd,txbuff,6);
           fflush(stdout);
           memset(revbuff,'\0',sizeof(revbuff));
           rlen = m_tty.tty_read(sel_fd,revbuff,7);
           fflush(stdout);
           if(rlen < 0)
           {
               printf("read serial error!\n");
               rlen = m_tty.tty_read(sel_fd,revbuff,7);      
           }
           rev = " ";
           for(i=2;i<4;i++)
               rev.append(revbuff[i]);
           char str[3]= {'\0'};
           char value = '\0';  
           char *temp = rev.data();
           i=0;
           for(i=0;i<3;i++){
               str[i]= *temp;
               temp++;
           }
           value = (str[1] << 4)|str[2];
           char d[2] = {'\0'};
           sprintf(d,"%x",value);
           for(i=2;i<5;i++)
           {
             printf(" %x",revbuff[i]);
           }
           revbuff[6]=0;
           for(i=2;i<4;i++)
           {
               revbuff[5]=revbuff[5]^revbuff[i];
           }
这段代码看不太明白,各位大侠帮忙分析一下,谢谢
3 回复
#2
flyingucla2012-05-11 16:01
回复 楼主 flyingucla
哪位好心人能按步骤一行一行的解释一下,小弟不胜感激
#3
long00422012-07-09 11:30
你的代码好坑爹啊,看着头疼不想看。
#4
King_Arrival2014-06-19 20:11
你这代码有底层有高层看着有地区有点坑
1