Corrected errant APDU timeout in epics demo.

This commit is contained in:
skarg
2010-08-26 14:23:00 +00:00
parent 968687b4f4
commit 0dcc38b020
+21 -5
View File
@@ -606,7 +606,7 @@ static uint8_t Read_Properties(
{ {
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
struct special_property_list_t PropertyListStruct; struct special_property_list_t PropertyListStruct;
uint i; unsigned int i;
if ((!Has_RPM && (Property_List_Index == 0)) || if ((!Has_RPM && (Property_List_Index == 0)) ||
(Property_List_Length == 0)) { (Property_List_Length == 0)) {
@@ -970,7 +970,10 @@ int main(
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds); elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds) { if (elapsed_seconds > timeout_seconds) {
fprintf(stderr, "\rError: APDU Timeout!\r\n"); fprintf(stderr,
"\rError: Unable to bind"
" after waiting %ld seconds.\r\n",
(long int)elapsed_seconds);
break; break;
} }
/* else, loop back and try again */ /* else, loop back and try again */
@@ -983,7 +986,8 @@ int main(
break; break;
case GET_ALL_REQUEST: case GET_ALL_REQUEST:
case GET_LIST_OF_ALL_REQUEST: /* differs in ArrayIndex only */ case GET_LIST_OF_ALL_REQUEST:
/* "list" differs in ArrayIndex only */
/* Update times; aids single-step debugging */ /* Update times; aids single-step debugging */
last_seconds = current_seconds; last_seconds = current_seconds;
StartNextObject(rpm_object, &myObject); StartNextObject(rpm_object, &myObject);
@@ -992,6 +996,7 @@ int main(
Send_Read_Property_Multiple_Request(buffer, MAX_PDU, Send_Read_Property_Multiple_Request(buffer, MAX_PDU,
Target_Device_Object_Instance, rpm_object); Target_Device_Object_Instance, rpm_object);
if (invoke_id > 0) { if (invoke_id > 0) {
elapsed_seconds = 0;
if (myState == GET_LIST_OF_ALL_REQUEST) if (myState == GET_LIST_OF_ALL_REQUEST)
myState = GET_LIST_OF_ALL_RESPONSE; myState = GET_LIST_OF_ALL_RESPONSE;
else else
@@ -1023,9 +1028,12 @@ int main(
assert(false); /* How can this be? */ assert(false); /* How can this be? */
invoke_id = 0; invoke_id = 0;
} }
elapsed_seconds = 0;
} else if (tsm_invoke_id_free(invoke_id)) { } else if (tsm_invoke_id_free(invoke_id)) {
elapsed_seconds = 0;
invoke_id = 0; invoke_id = 0;
if (Error_Detected) { /* The normal case for Device Object */ if (Error_Detected) {
/* The normal case for Device Object */
/* Was it because the Device can't do RPM? */ /* Was it because the Device can't do RPM? */
if (Last_Error_Code == if (Last_Error_Code ==
ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE) { ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE) {
@@ -1048,9 +1056,11 @@ int main(
fprintf(stderr, "\rError: TSM Timeout!\r\n"); fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
invoke_id = 0; invoke_id = 0;
elapsed_seconds = 0;
myState = GET_ALL_REQUEST; /* Let's try again */ myState = GET_ALL_REQUEST; /* Let's try again */
} else if (Error_Detected) { } else if (Error_Detected) {
/* Don't think we'll ever actually reach this point. */ /* Don't think we'll ever actually reach this point. */
elapsed_seconds = 0;
invoke_id = 0; invoke_id = 0;
myState = NEXT_OBJECT; /* Give up and move on to the next. */ myState = NEXT_OBJECT; /* Give up and move on to the next. */
Error_Count++; Error_Count++;
@@ -1063,6 +1073,7 @@ int main(
Error_Detected = false; Error_Detected = false;
/* Update times; aids single-step debugging */ /* Update times; aids single-step debugging */
last_seconds = current_seconds; last_seconds = current_seconds;
elapsed_seconds = 0;
invoke_id = invoke_id =
Read_Properties(Target_Device_Object_Instance, &myObject); Read_Properties(Target_Device_Object_Instance, &myObject);
if (invoke_id == 0) { if (invoke_id == 0) {
@@ -1095,6 +1106,7 @@ int main(
assert(false); /* How can this be? */ assert(false); /* How can this be? */
invoke_id = 0; invoke_id = 0;
} }
elapsed_seconds = 0;
/* Advance the property (or Array List) index */ /* Advance the property (or Array List) index */
if (Using_Walked_List) { if (Using_Walked_List) {
Walked_List_Index++; Walked_List_Index++;
@@ -1118,6 +1130,7 @@ int main(
myState = GET_PROPERTY_REQUEST; /* Go fetch next Property */ myState = GET_PROPERTY_REQUEST; /* Go fetch next Property */
} else if (tsm_invoke_id_free(invoke_id)) { } else if (tsm_invoke_id_free(invoke_id)) {
invoke_id = 0; invoke_id = 0;
elapsed_seconds = 0;
myState = GET_PROPERTY_REQUEST; myState = GET_PROPERTY_REQUEST;
if (Error_Detected) { if (Error_Detected) {
if (IsLongArray) { if (IsLongArray) {
@@ -1138,10 +1151,12 @@ int main(
} else if (tsm_invoke_id_failed(invoke_id)) { } else if (tsm_invoke_id_failed(invoke_id)) {
fprintf(stderr, "\rError: TSM Timeout!\r\n"); fprintf(stderr, "\rError: TSM Timeout!\r\n");
tsm_free_invoke_id(invoke_id); tsm_free_invoke_id(invoke_id);
elapsed_seconds = 0;
invoke_id = 0; invoke_id = 0;
myState = GET_PROPERTY_REQUEST; /* Let's try again, same Property */ myState = GET_PROPERTY_REQUEST; /* Let's try again, same Property */
} else if (Error_Detected) { } else if (Error_Detected) {
/* Don't think we'll ever actually reach this point. */ /* Don't think we'll ever actually reach this point. */
elapsed_seconds = 0;
invoke_id = 0; invoke_id = 0;
myState = NEXT_OBJECT; /* Give up and move on to the next. */ myState = NEXT_OBJECT; /* Give up and move on to the next. */
Error_Count++; Error_Count++;
@@ -1196,7 +1211,8 @@ int main(
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds); elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds) { if (elapsed_seconds > timeout_seconds) {
fprintf(stderr, "\rError: APDU Timeout!\r\n"); fprintf(stderr, "\rError: APDU Timeout! (%lds)\r\n",
(long int)elapsed_seconds);
break; break;
} }
} }