From 0f2df4a8fed703c682ae98603065e46e573b813c Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Mon, 13 May 2013 08:40:30 +1000 Subject: [PATCH] SICS-593: Return 0 from the AsconReading state to ensure that SICS progresses through tasks. --- site_ansto/hardsup/sct_galilprot.c | 22 +++++++++++++++++++--- site_ansto/hardsup/sct_lfprot.c | 8 ++++---- site_ansto/hardsup/sct_modbusprot.c | 4 ++-- site_ansto/hardsup/sct_orhvpsprot.c | 12 ++++++------ site_ansto/hardsup/sct_protek608.c | 10 +++++----- site_ansto/hardsup/sct_rfamp.c | 10 +++++----- 6 files changed, 41 insertions(+), 25 deletions(-) diff --git a/site_ansto/hardsup/sct_galilprot.c b/site_ansto/hardsup/sct_galilprot.c index f4a5e244..b22823be 100644 --- a/site_ansto/hardsup/sct_galilprot.c +++ b/site_ansto/hardsup/sct_galilprot.c @@ -41,6 +41,21 @@ int GalilReading(Ascon *a) { char chr, ch[2]; ret = AsconReadChar(a->fd, &chr); + if (ret > 0) { + a->start = DoubleTime(); + } else if (ret < 0) { + AsconError(a, "ASC5", errno) + return 0; + } else if (ret == 0) { + if (a->timeout > 0) { + if (DoubleTime() - a->start > a->timeout) { + AsconError(a, "read timeout", 0); + /* a->state = AsconTimeout; */ + } + } + return 0; + } + switch (chr) { case ' ': return AsconStdHandler(a); @@ -52,12 +67,12 @@ int GalilReading(Ascon *a) { a->state = AsconWriteStart; a->responseValid=0; a->wrPos = 0; - return 1; + return 0; break; case ':': DynStringReplace(a->rdBuffer, "OK",0); a->state = AsconReadDone; - return 1; + return 0; break; default: /* Check for first digit of errorcode followed by error message */ @@ -68,9 +83,10 @@ int GalilReading(Ascon *a) { DynStringInsert(a->rdBuffer, ch, 0); a->state = AsconReadDone; AsconError(a, GetCharArray(a->rdBuffer), 0); - return 1; + return 0; } } + /* Return 1 to read next char befor progressing to next task */ return 1; } diff --git a/site_ansto/hardsup/sct_lfprot.c b/site_ansto/hardsup/sct_lfprot.c index ed105d93..db4d7506 100644 --- a/site_ansto/hardsup/sct_lfprot.c +++ b/site_ansto/hardsup/sct_lfprot.c @@ -161,10 +161,10 @@ int LFGenReading(Ascon *a) } if (a->timeout > 0) { - if (DoubleTime() - a->start > 0.05) { //a->timeout) { + if (DoubleTime() - a->start > 0.05) { AsconError(a, "read timeout", 0); - a->state = AsconTimeout; - return 1; + /* a->state = AsconTimeout; */ + return 0; } } ret = AsconReadChar(a->fd, &chr); @@ -210,7 +210,7 @@ int LFGenReading(Ascon *a) free(lfchar); //DynStringConcatChar(a->rdBuffer, '\0'); - return 1; + return 0; } int LFGenProtHandler(Ascon *a) diff --git a/site_ansto/hardsup/sct_modbusprot.c b/site_ansto/hardsup/sct_modbusprot.c index dc70c57f..788316dc 100644 --- a/site_ansto/hardsup/sct_modbusprot.c +++ b/site_ansto/hardsup/sct_modbusprot.c @@ -234,7 +234,7 @@ int ModbusReading(Ascon *a) { DynStringClear(a->rdBuffer); DynStringConcatBytes(a->rdBuffer, temp, rlen); a->state = AsconReadDone; - return 1; + return 0; } } ret = AsconReadChar(a->fd, &chr); @@ -249,7 +249,7 @@ int ModbusReading(Ascon *a) { if (a->timeout > 0) { if (DoubleTime() - a->start > a->timeout) { AsconError(a, "read timeout", 0); - a->state = AsconTimeout; + /* a->state = AsconTimeout; */ } } } diff --git a/site_ansto/hardsup/sct_orhvpsprot.c b/site_ansto/hardsup/sct_orhvpsprot.c index 46f82a7f..34fd8d8c 100644 --- a/site_ansto/hardsup/sct_orhvpsprot.c +++ b/site_ansto/hardsup/sct_orhvpsprot.c @@ -296,7 +296,7 @@ int OrdHVPSReading(Ascon *a) { if (DynStringConcatChar(a->rdBuffer, chr) == 0) { a->state = AsconReadDone; AsconError(a, "DynStringConcatChar failed:", ENOMEM); - return 1; + return 0; break; } } @@ -307,20 +307,20 @@ int OrdHVPSReading(Ascon *a) { if (a->timeout > 0) { if (DoubleTime() - a->start > a->timeout) { AsconError(a, "read timeout", 0); - a->state = AsconTimeout; - return 1; + /* a->state = AsconTimeout; */ + return 0; } else { - return 1; + return 0; } } } rsp_len = GetDynStringLength(a->rdBuffer); if (OrdFmtReply(GetCharArray(a->rdBuffer), rsp_len, response, errmsg) >= 0) { DynStringReplace(a->rdBuffer,response,0); - return 1; + return 0; } else { AsconError(a, errmsg, 0); - return 1; + return 0; } } diff --git a/site_ansto/hardsup/sct_protek608.c b/site_ansto/hardsup/sct_protek608.c index ad9d3536..713c782c 100644 --- a/site_ansto/hardsup/sct_protek608.c +++ b/site_ansto/hardsup/sct_protek608.c @@ -353,7 +353,7 @@ int Protek608Reading(Ascon *a) snprintf(errMsg, ERRLEN, "PROTEK608: Unexpected value %X for last byte:", chr); AsconError(a, errMsg, 0); } - return 1; + return 0; } transByteStatus = translateByte(a->private, chr, (a->readState)++, field); if (transByteStatus == 1) { @@ -392,22 +392,22 @@ int Protek608Reading(Ascon *a) if (ret < 0) { AsconError(a, "PROTEK608: AsconReadChar failed:", errno); - return 1; + return 0; } if (DS_AllocFailed || transByteFailed) { a->state = AsconReadDone; a->readState = 0; data->first = 1; AsconError(a, errMsg, errNum); - return 1; + return 0; } if (a->timeout > 0) { if (DoubleTime() - a->start > a->timeout) { AsconError(a, "PROTEK608: read timeout", 0); - a->state = AsconTimeout; + /* a->state = AsconTimeout; */ } } - return 1; + return 0; } /* diff --git a/site_ansto/hardsup/sct_rfamp.c b/site_ansto/hardsup/sct_rfamp.c index 062cb4e2..7f2d39ca 100644 --- a/site_ansto/hardsup/sct_rfamp.c +++ b/site_ansto/hardsup/sct_rfamp.c @@ -279,7 +279,7 @@ int RFAmpReading (Ascon *a) } a->state = AsconReadDone; } - return 1; + return 0; } if (0 == DynStringConcatChar(a->rdBuffer, chr)) { strcpy(errMsg, "ANSRFAMP: DynStringConcatChar failed:"); @@ -295,7 +295,7 @@ int RFAmpReading (Ascon *a) } if (rdChRet < 0) { AsconError(a, "ANSRFAMP: AsconReadChar failed:", errno); - return 1; + return 0; } if (GetReplyFailed) { a->state = AsconReadDone; @@ -303,15 +303,15 @@ int RFAmpReading (Ascon *a) a->readState = 0; data->transactInProg = txNormalRead; AsconError(a, errMsg, errNum); - return 1; + return 0; } if (a->timeout > 0) { if (DoubleTime() - a->start > a->timeout) { - a->state = AsconTimeout; + /* a->state = AsconTimeout; */ AsconError(a, "ANSRFAMP: read timeout", 0); } } - return 1; + return 0; }