diff --git a/bacnet-stack/demo/dcc/main.c b/bacnet-stack/demo/dcc/main.c index 7398c345..257b26f3 100644 --- a/bacnet-stack/demo/dcc/main.c +++ b/bacnet-stack/demo/dcc/main.c @@ -259,12 +259,19 @@ int main(int argc, char *argv[]) Communication_Password); } else if (tsm_invoke_id_free(invoke_id)) break; + else if (tsm_invoke_id_failed(invoke_id)) + { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + /* try again or abort? */ + break; + } } else { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { - printf("\rError: APDU Timeout!"); + printf("\rError: APDU Timeout!\r\n"); break; } } diff --git a/bacnet-stack/demo/object/ai.c b/bacnet-stack/demo/object/ai.c index c37c47f3..de6b6b8e 100644 --- a/bacnet-stack/demo/object/ai.c +++ b/bacnet-stack/demo/object/ai.c @@ -121,7 +121,13 @@ int Analog_Input_Encode_Property_APDU(uint8_t * apdu, case PROP_UNITS: apdu_len = encode_tagged_enumerated(&apdu[0], UNITS_PERCENT); break; - /* test case for signed encoding and decoding negative value correctly */ + case 9997: + apdu_len = encode_tagged_real(&apdu[0], 90.510); + break; + case 9998: + apdu_len = encode_tagged_unsigned(&apdu[0], 90); + break; + /* test case for signed encoding-decoding negative value correctly */ case 9999: apdu_len = encode_tagged_signed(&apdu[0], -200); break; diff --git a/bacnet-stack/demo/readfile/readfile.c b/bacnet-stack/demo/readfile/readfile.c index 8519f145..3264d59a 100644 --- a/bacnet-stack/demo/readfile/readfile.c +++ b/bacnet-stack/demo/readfile/readfile.c @@ -286,12 +286,19 @@ int main(int argc, char *argv[]) requestedOctetCount); Current_Invoke_ID = invoke_id; } + else if (tsm_invoke_id_failed(invoke_id)) + { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + /* try again or abort? */ + break; + } } else { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { - printf("\rError: APDU Timeout!"); + fprintf(stderr, "\rError: APDU Timeout!\r\n"); break; } } diff --git a/bacnet-stack/demo/readprop/readprop.c b/bacnet-stack/demo/readprop/readprop.c index 589cfa92..37578e04 100644 --- a/bacnet-stack/demo/readprop/readprop.c +++ b/bacnet-stack/demo/readprop/readprop.c @@ -226,12 +226,19 @@ int main(int argc, char *argv[]) Target_Object_Index); } else if (tsm_invoke_id_free(invoke_id)) break; + else if (tsm_invoke_id_failed(invoke_id)) + { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + /* try again or abort? */ + break; + } } else { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { - printf("\rError: APDU Timeout!"); + printf("\rError: APDU Timeout!\r\n"); break; } } diff --git a/bacnet-stack/demo/reinit/main.c b/bacnet-stack/demo/reinit/main.c index da05ac10..843ef052 100644 --- a/bacnet-stack/demo/reinit/main.c +++ b/bacnet-stack/demo/reinit/main.c @@ -245,11 +245,21 @@ int main(int argc, char *argv[]) Reinitialize_Password); } else if (tsm_invoke_id_free(invoke_id)) break; + else if (tsm_invoke_id_failed(invoke_id)) + { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + /* try again or abort? */ + break; + } } else { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) + { + fprintf(stderr, "\rError: APDU Timeout!\r\n"); break; + } } /* keep track of time for next check */ last_seconds = current_seconds; diff --git a/bacnet-stack/demo/writefile/writefile.c b/bacnet-stack/demo/writefile/writefile.c index 30f6b505..ca6205e7 100644 --- a/bacnet-stack/demo/writefile/writefile.c +++ b/bacnet-stack/demo/writefile/writefile.c @@ -264,12 +264,19 @@ int main(int argc, char *argv[]) &fileData); Current_Invoke_ID = invoke_id; } + else if (tsm_invoke_id_failed(invoke_id)) + { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + /* try again or abort? */ + break; + } } else { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { - printf("\rError: APDU Timeout!"); + fprintf(stderr, "\rError: APDU Timeout!\r\n"); break; } } diff --git a/bacnet-stack/demo/writeprop/writeprop.c b/bacnet-stack/demo/writeprop/writeprop.c index 88eceba1..203cb839 100644 --- a/bacnet-stack/demo/writeprop/writeprop.c +++ b/bacnet-stack/demo/writeprop/writeprop.c @@ -323,12 +323,19 @@ int main(int argc, char *argv[]) Target_Object_Property_Index); } else if (tsm_invoke_id_free(invoke_id)) break; + else if (tsm_invoke_id_failed(invoke_id)) + { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + /* try again or abort? */ + break; + } } else { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { - printf("\rError: APDU Timeout!"); + printf("\rError: APDU Timeout!\r\n"); break; } } diff --git a/bacnet-stack/tsm.c b/bacnet-stack/tsm.c index 7e04a227..cd99aada 100644 --- a/bacnet-stack/tsm.c +++ b/bacnet-stack/tsm.c @@ -237,7 +237,9 @@ void tsm_timer_milliseconds(uint16_t milliseconds) &TSM_List[i].npdu_data, &TSM_List[i].apdu[0], TSM_List[i].apdu_len); } else { - TSM_List[i].InvokeID = 0; + /* note: the invoke id has not been cleared yet + and this indicates a failed message: + IDLE and a valid invoke id */ TSM_List[i].state = TSM_STATE_IDLE; } } @@ -269,6 +271,25 @@ bool tsm_invoke_id_free(uint8_t invokeID) return status; } +/* see if the invoke ID has failed get a confirmation */ +bool tsm_invoke_id_failed(uint8_t invokeID) +{ + bool status = false; + uint8_t index; + + index = tsm_find_invokeID_index(invokeID); + if (index < MAX_TSM_TRANSACTIONS) + { + /* a valid invoke ID and the state is IDLE is a + message that failed to confirm */ + if (TSM_List[index].state == TSM_STATE_IDLE) + status = true; + } + + return status; +} + + #ifdef TEST #include #include diff --git a/bacnet-stack/tsm.h b/bacnet-stack/tsm.h index 4b7ce5b5..3b3a4f62 100644 --- a/bacnet-stack/tsm.h +++ b/bacnet-stack/tsm.h @@ -109,7 +109,8 @@ extern "C" { uint8_t * apdu, uint16_t * apdu_len); bool tsm_invoke_id_free(uint8_t invokeID); - + bool tsm_invoke_id_failed(uint8_t invokeID); + #ifdef __cplusplus } #endif /* __cplusplus */