SICS-593: Return 0 from the AsconReading state to ensure that SICS

progresses through tasks.
This commit is contained in:
Ferdi Franceschini
2013-05-13 08:40:30 +10:00
parent 0ab6b5f67f
commit 0f2df4a8fe
6 changed files with 41 additions and 25 deletions

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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; */
}
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
/*

View File

@@ -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;
}