add timeout parameter in protocol

r3694 | jgn | 2012-08-07 12:03:23 +1000 (Tue, 07 Aug 2012) | 1 line
This commit is contained in:
Jing Chen
2012-08-07 12:03:23 +10:00
committed by Douglas Clowes
parent 1993aa2c11
commit 15fdda1deb

View File

@@ -143,20 +143,30 @@ int LFGenReading(Ascon *a)
//BYTE HEAD, LEN, CTRL, CRC=0, *Data=NULL;
// Read HEAD info
usleep(1000*50);
ret = AsconReadChar(a->fd, &chr);
while (ret>0) {
HEAD = (BYTE)chr;
if (HEAD!=0x96) {
ret = AsconReadChar(a->fd, &chr);
continue;
} else {
break;
}
a->start = DoubleTime();
if(ret<0) {
AsconError(a, "AsconReadChar failed in Head Info reading in LFGenReading:", 0);
//a->state = AsconReadDone;
return 0;
} else {
while (ret>=0) {
if(ret>0) {
HEAD = (BYTE)chr;
if (HEAD==0x96) {
break;
}
}
if (a->timeout > 0) {
if (DoubleTime() - a->start > 0.05) { //a->timeout) {
AsconError(a, "read timeout", 0);
a->state = AsconTimeout;
return 1;
}
}
ret = AsconReadChar(a->fd, &chr);
}
}