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