日期:2014-05-16  浏览次数:20807 次

嵌入式linux下串口采用xmodem协议 接受不成功
接受时总是无法接受完整的包而超出最大次数,最后退出程序, 请问是什么原因? 怎么改?

int xmodemReceive(int fd, char *dest, int destsz)
{
        unsigned char xbuff[38]; /* 1024 for XModem 1k + 3 head chars + 2 crc + nul */
        //unsigned char *p;
        int bufsz, crc = 0;
        unsigned char c, trychar = 'C';
        unsigned char packetno = 1;
        int len = 0;
        int retry, retrans = MAXRETRANS;
        for(;;)
        {
                    for( retry = 0; retry < 4; ++retry)
                    {
                        if (trychar)
                            port_outbyte(fd, trychar);
                    }
                    while(c != SOH){
                        c = port_inbyte(fd);
                        if(c == EOT || c == CAN)
                            break;
                    }//(DLY_1S)<<1);
                        if (last_error == 0)
                        {
                                switch (c)
                                {
                                        case SOH: