kopia lustrzana https://github.com/sq5bpf/k5prog
Merge pull request #20 from wutje/fix_out_of_sync
Fix 3 rx handling bugs; timeout, short read, out-of-syncmain
commit
4e6ebbc760
31
k5prog.c
31
k5prog.c
|
@ -229,6 +229,13 @@ int read_timeout(int fd, unsigned char *buf, int maxlen, int timeout)
|
|||
|
||||
ret=select(fd+1,&rfd,0,0,&tv);
|
||||
|
||||
if (ret==0) {
|
||||
if(timeout) /* Only print if we requested a timeout */
|
||||
fprintf(stderr,"read_timeout\n");
|
||||
/* error albo timeout */
|
||||
break;
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd,&rfd)) {
|
||||
nr=read(fd,buf,maxlen);
|
||||
|
||||
|
@ -237,16 +244,8 @@ int read_timeout(int fd, unsigned char *buf, int maxlen, int timeout)
|
|||
if (nr>=0) maxlen=maxlen-nr;
|
||||
if (maxlen==0) break;
|
||||
}
|
||||
|
||||
|
||||
if (ret==0) {
|
||||
fprintf(stderr,"read_timeout\n");
|
||||
/* error albo timeout */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (verbose>2) {
|
||||
if (verbose>2 && len > 0) {
|
||||
printf("RXRXRX:\n");
|
||||
hdump(buf2,len);
|
||||
}
|
||||
|
@ -427,9 +426,20 @@ struct k5_command *k5_receive(int fd,int tmout) {
|
|||
return(0);
|
||||
}
|
||||
|
||||
/* During plugging in etc we can receive a single byte.
|
||||
* Handle this case here. */
|
||||
if (len != sizeof(buf))
|
||||
{
|
||||
fprintf(stderr,"k5_receive: got %d expected %ld\n", len, sizeof(buf));
|
||||
return(0);
|
||||
}
|
||||
|
||||
if ((buf[0]!=0xab)||(buf[1]!=0xcd)) {
|
||||
fprintf(stderr,"k5_receive: bad magic number\n");
|
||||
/* Assume we are out of sync and flush rx buffer by reading everything.
|
||||
* This works because the boot message is repeated. */
|
||||
while(len > 0)
|
||||
len =read_timeout(fd,(unsigned char *)&buf,sizeof(buf),0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
@ -564,7 +574,8 @@ int wait_flash_message(int fd,int ntimes) {
|
|||
cmd=k5_receive(fd,10000);
|
||||
|
||||
if (!cmd) {
|
||||
printf("wait_flash_message: timeout\n");
|
||||
/* No need to print, k5_receive already printed why it failed */
|
||||
//printf("wait_flash_message: timeout\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue