diff --git a/site_ansto/hardsup/sct_lfprot.c b/site_ansto/hardsup/sct_lfprot.c index 3d34dd1a..5e48fa07 100644 --- a/site_ansto/hardsup/sct_lfprot.c +++ b/site_ansto/hardsup/sct_lfprot.c @@ -139,29 +139,58 @@ int LFGenReading(Ascon *a) { int ret; char chr=0; - BYTE *lfChr; + BYTE *lfchar, HEAD, LEN; //BYTE HEAD, LEN, CTRL, CRC=0, *Data=NULL; DynStringClear(a->rdBuffer); ret = AsconReadChar(a->fd, &chr); - if (chr == 0) { - if (a->timeout > 0) { - if (DoubleTime() - a->start > a->timeout) { - AsconError(a, "read timeout", 0); - a->state = AsconTimeout; - } - } + 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; } - - LFConcatChar(a->rdBuffer, chr); - - while ((ret = AsconReadChar(a->fd, &chr)) > 0) { - LFConcatChar(a->rdBuffer, chr); + ret = AsconReadChar(a->fd, &chr); + if(ret<0) { + AsconError(a, "AsconReadChar failed:", errno); + return 1; } + LEN = (BYTE)chr; + if(LEN<2) { + AsconError(a, "Reading Error from the device", 0); + return 1; + } + lfchar = malloc(sizeof(BYTE)*(LEN+2)); + int ind=0; + lfchar[ind] = HEAD; ind++; + lfchar[ind] = LEN; ind++; + while(indfd, &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; + } + lfchar[ind] = (BYTE)chr; ind++; + } + int i; + for(i=0; irdBuffer, lfchar[i]); + } + a->state = AsconReadDone; + free(lfchar); //DynStringConcatChar(a->rdBuffer, '\0'); + return 1; } int LFGenProtHandler(Ascon *a)