r3676 | jgn | 2012-07-26 09:46:53 +1000 (Thu, 26 Jul 2012) | 1 line

This commit is contained in:
Jing Chen
2012-07-26 09:46:53 +10:00
committed by Douglas Clowes
parent f1fc1e59e5
commit 710d76def7

View File

@@ -142,52 +142,52 @@ int LFGenReading(Ascon *a)
BYTE *lfchar, HEAD, LEN;
//BYTE HEAD, LEN, CTRL, CRC=0, *Data=NULL;
DynStringClear(a->rdBuffer);
ret = AsconReadChar(a->fd, &chr);
if(ret<0) {
AsconError(a, "AsconReadChar failed:", errno);
return 1;
}
HEAD = (BYTE)chr;
if(HEAD!=0x96) {
AsconError(a, "Reading Error from the device", 0);
return 1;
}
// Read HEAD info
do {
ret = AsconReadChar(a->fd, &chr);
if(ret<0) {
AsconError(a, "AsconReadChar failed:", errno);
return 0;
}
HEAD = (BYTE)chr;
} while (HEAD!=0x96);
// read LEN info
ret = AsconReadChar(a->fd, &chr);
if(ret<0) {
AsconError(a, "AsconReadChar failed:", errno);
return 1;
return 0;
}
LEN = (BYTE)chr;
if(LEN<2) {
AsconError(a, "Reading Error from the device", 0);
return 1;
AsconError(a, "Reading Error from the device, wrong LEN info", 0);
a->state = AsconReadDone;
return 0;
}
lfchar = malloc(sizeof(BYTE)*(LEN+2));
int ind=0;
lfchar[ind] = HEAD; ind++;
lfchar[ind] = LEN; ind++;
// read all other chars
while(ind<LEN+2) {
ret = AsconReadChar(a->fd, &chr);
if (ret < 0) {
if (a->timeout > 0) {
if (DoubleTime() - a->start > a->timeout) {
AsconError(a, "read timeout", 0);
a->state = AsconTimeout;
return 1;
}
}
return 1;
AsconError(a, "AsconReadChar failed:", errno);
a->state = AsconReadDone;
return 0;
}
lfchar[ind] = (BYTE)chr; ind++;
}
DynStringClear(a->rdBuffer);
int i;
for(i=0; i<ind; i++) {
LFConcatChar(a->rdBuffer, lfchar[i]);
}
a->state = AsconReadDone;
free(lfchar);
//DynStringConcatChar(a->rdBuffer, '\0');
return 1;