Corrected reading of ALL to not read with array index 0.

This commit is contained in:
skarg
2010-07-16 16:10:28 +00:00
parent 6fd0d9e13a
commit 6450255be6
+75 -79
View File
@@ -115,10 +115,10 @@ static const int *pPropList = NULL;
#define MINIMAL_PROPLIST_SIZE 4 #define MINIMAL_PROPLIST_SIZE 4
static int32_t MinimalPropList[MINIMAL_PROPLIST_SIZE] = static int32_t MinimalPropList[MINIMAL_PROPLIST_SIZE] =
{ {
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME, PROP_OBJECT_NAME,
PROP_OBJECT_TYPE, PROP_OBJECT_TYPE,
-1 -1
}; };
/* When we have to walk through an array of things, like ObjectIDs or /* When we have to walk through an array of things, like ObjectIDs or
@@ -149,9 +149,9 @@ static void MyErrorHandler(
(void) invoke_id; (void) invoke_id;
#if PRINT_ERRORS #if PRINT_ERRORS
if ( ShowValues ) if ( ShowValues )
fprintf(stderr, "-- BACnet Error: %s: %s\r\n", fprintf(stderr, "-- BACnet Error: %s: %s\r\n",
bactext_error_class_name(error_class), bactext_error_class_name(error_class),
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
#endif #endif
Error_Detected = true; Error_Detected = true;
Last_Error_Class = error_class; Last_Error_Class = error_class;
@@ -171,15 +171,15 @@ void MyAbortHandler(
#if PRINT_ERRORS #if PRINT_ERRORS
/* It is normal for this to fail, so don't print. */ /* It is normal for this to fail, so don't print. */
if ((myState != GET_ALL_RESPONSE) && !IsLongArray && ShowValues ) if ((myState != GET_ALL_RESPONSE) && !IsLongArray && ShowValues )
fprintf(stderr, "-- BACnet Abort: %s \r\n", fprintf(stderr, "-- BACnet Abort: %s \r\n",
bactext_abort_reason_name(abort_reason)); bactext_abort_reason_name(abort_reason));
#endif #endif
Error_Detected = true; Error_Detected = true;
Last_Error_Class = ERROR_CLASS_SERVICES; Last_Error_Class = ERROR_CLASS_SERVICES;
if ( abort_reason < MAX_BACNET_ABORT_REASON ) if ( abort_reason < MAX_BACNET_ABORT_REASON )
Last_Error_Code = (ERROR_CODE_ABORT_BUFFER_OVERFLOW -1) + abort_reason; Last_Error_Code = (ERROR_CODE_ABORT_BUFFER_OVERFLOW -1) + abort_reason;
else else
Last_Error_Code = ERROR_CODE_ABORT_OTHER; Last_Error_Code = ERROR_CODE_ABORT_OTHER;
} }
void MyRejectHandler( void MyRejectHandler(
@@ -192,14 +192,14 @@ void MyRejectHandler(
(void) invoke_id; (void) invoke_id;
#if PRINT_ERRORS #if PRINT_ERRORS
if ( ShowValues ) if ( ShowValues )
fprintf(stderr, "BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); fprintf(stderr, "BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason));
#endif #endif
Error_Detected = true; Error_Detected = true;
Last_Error_Class = ERROR_CLASS_SERVICES; Last_Error_Class = ERROR_CLASS_SERVICES;
if ( reject_reason < MAX_BACNET_REJECT_REASON ) if ( reject_reason < MAX_BACNET_REJECT_REASON )
Last_Error_Code = (ERROR_CODE_REJECT_BUFFER_OVERFLOW -1) + reject_reason; Last_Error_Code = (ERROR_CODE_REJECT_BUFFER_OVERFLOW -1) + reject_reason;
else else
Last_Error_Code = ERROR_CODE_REJECT_OTHER; Last_Error_Code = ERROR_CODE_REJECT_OTHER;
} }
void MyReadPropertyAckHandler( void MyReadPropertyAckHandler(
@@ -388,7 +388,7 @@ void PrintReadPropertyData(
value = rpm_property->value; value = rpm_property->value;
if (value == NULL) { if (value == NULL) {
/* Then we print the error information */ /* Then we print the error information */
fprintf(stderr, "? -- BACnet Error: %s: %s\r\n", fprintf(stderr, "? -- BACnet Error: %s: %s\r\n",
bactext_error_class_name((int) rpm_property->error.error_class), bactext_error_class_name((int) rpm_property->error.error_class),
bactext_error_code_name((int) rpm_property->error.error_code)); bactext_error_code_name((int) rpm_property->error.error_code));
return; return;
@@ -505,13 +505,13 @@ void PrintReadPropertyData(
* screen these out here, unless ShowValues is true. */ * screen these out here, unless ShowValues is true. */
switch (rpm_property->propertyIdentifier) { switch (rpm_property->propertyIdentifier) {
case PROP_DEVICE_ADDRESS_BINDING: case PROP_DEVICE_ADDRESS_BINDING:
/* Make it VTS3-friendly and don't show "Null" /* Make it VTS3-friendly and don't show "Null"
* as a value. */ * as a value. */
if ( value->tag == BACNET_APPLICATION_TAG_NULL ) { if ( value->tag == BACNET_APPLICATION_TAG_NULL ) {
fprintf(stdout, "?"); fprintf(stdout, "?");
break; break;
} }
/* Else, fall through for normal processing. */ /* Else, fall through for normal processing. */
case PROP_DAYLIGHT_SAVINGS_STATUS: case PROP_DAYLIGHT_SAVINGS_STATUS:
case PROP_LOCAL_DATE: case PROP_LOCAL_DATE:
case PROP_LOCAL_TIME: case PROP_LOCAL_TIME:
@@ -582,7 +582,7 @@ static uint8_t Read_Properties(
int i; int i;
if ( ( !Has_RPM && ( Property_List_Index == 0 ) ) || if ( ( !Has_RPM && ( Property_List_Index == 0 ) ) ||
( Property_List_Length == 0) ) ( Property_List_Length == 0) )
{ {
/* If we failed to get the Properties with RPM, just settle for what we /* If we failed to get the Properties with RPM, just settle for what we
* know is the fixed list of Required (only) properties. * know is the fixed list of Required (only) properties.
@@ -594,13 +594,13 @@ static uint8_t Read_Properties(
if (pPropList != NULL) { if (pPropList != NULL) {
Property_List_Length = PropertyListStruct.Required.count; Property_List_Length = PropertyListStruct.Required.count;
} else { } else {
fprintf(stdout, " -- Just Minimal Properties: \r\n" ); fprintf(stdout, " -- Just Minimal Properties: \r\n" );
pPropList = MinimalPropList; pPropList = MinimalPropList;
Property_List_Length = MINIMAL_PROPLIST_SIZE -1; Property_List_Length = MINIMAL_PROPLIST_SIZE -1;
} }
/* Copy this list for later one-by-one processing */ /* Copy this list for later one-by-one processing */
for ( i = 0; i < Property_List_Length; i++ ) for ( i = 0; i < Property_List_Length; i++ )
Property_List[i] = pPropList[i]; Property_List[i] = pPropList[i];
Property_List[i] = -1; /* Just to be sure we terminate */ Property_List[i] = -1; /* Just to be sure we terminate */
} else } else
pPropList = Property_List; pPropList = Property_List;
@@ -616,7 +616,7 @@ static uint8_t Read_Properties(
array_index = Walked_List_Index; array_index = Walked_List_Index;
} }
} else { } else {
fprintf(stdout, " "); fprintf(stdout, " ");
Print_Property_Identifier(prop); Print_Property_Identifier(prop);
fprintf(stdout, ": "); fprintf(stdout, ": ");
array_index = BACNET_ARRAY_ALL; array_index = BACNET_ARRAY_ALL;
@@ -766,41 +766,41 @@ int CheckCommandLineArgs(
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
char *anArg = argv[i]; char *anArg = argv[i];
if (anArg[0] == '-') { if (anArg[0] == '-') {
switch ( anArg[1] ) switch ( anArg[1] )
{ {
case 'v': case 'v':
ShowValues = true; ShowValues = true;
break; break;
case 'p': case 'p':
if ( ++i < argc ) if ( ++i < argc )
My_BIP_Port = (uint16_t) strtol(argv[i], NULL, 0); My_BIP_Port = (uint16_t) strtol(argv[i], NULL, 0);
/* Used strtol so sport can be either 0xBAC0 or 47808 */ /* Used strtol so sport can be either 0xBAC0 or 47808 */
break; break;
case 't': case 't':
if ( ++i < argc ) if ( ++i < argc )
{ {
uint8_t *mac = Target_Address.mac; uint8_t *mac = Target_Address.mac;
/* The %hhx specifies unsigned char */ /* The %hhx specifies unsigned char */
Target_Address.mac_len = sscanf( argv[i], Target_Address.mac_len = sscanf( argv[i],
"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if ( Target_Address.mac_len == 6 ) /* success */ if ( Target_Address.mac_len == 6 ) /* success */
{ {
Target_Address.net = 0; Target_Address.net = 0;
Target_Address.len = 0; /* No src address */ Target_Address.len = 0; /* No src address */
Provided_Targ_MAC = true; Provided_Targ_MAC = true;
break; break;
} }
else else
printf( "ERROR: invalid Target MAC %s \r\n", argv[i] ); printf( "ERROR: invalid Target MAC %s \r\n", argv[i] );
/* And fall through to PrintUsage */ /* And fall through to PrintUsage */
} }
/* Either break or fall through, as above */ /* Either break or fall through, as above */
/* break; */ /* break; */
default: default:
PrintUsage(); PrintUsage();
break; break;
} }
} else { } else {
/* decode the Target Device Instance parameter */ /* decode the Target Device Instance parameter */
Target_Device_Object_Instance = strtol(anArg, NULL, 0); Target_Device_Object_Instance = strtol(anArg, NULL, 0);
@@ -833,8 +833,7 @@ void StartNextObject( BACNET_READ_ACCESS_DATA *rpm_object, BACNET_OBJECT_ID *pNe
rpm_object->listOfProperties = rpm_property; rpm_object->listOfProperties = rpm_property;
assert(rpm_property); assert(rpm_property);
rpm_property->propertyIdentifier = PROP_ALL; rpm_property->propertyIdentifier = PROP_ALL;
/* Start with a count of the array size */ rpm_property->propertyArrayIndex = BACNET_ARRAY_ALL;
rpm_property->propertyArrayIndex = 0;
} }
/** Main function of the bacepics program. /** Main function of the bacepics program.
@@ -881,7 +880,7 @@ int main(
* My_BIP_Port will be non-zero in this case. * My_BIP_Port will be non-zero in this case.
*/ */
if ( My_BIP_Port > 0 ) if ( My_BIP_Port > 0 )
bip_set_port( My_BIP_Port ); bip_set_port( My_BIP_Port );
address_init(); address_init();
Init_Service_Handlers(); Init_Service_Handlers();
dlenv_init(); dlenv_init();
@@ -891,21 +890,21 @@ int main(
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
if ( My_BIP_Port > 0 ) if ( My_BIP_Port > 0 )
bip_set_port( 0xBAC0 ); /* Set back to std BACnet/IP port */ bip_set_port( 0xBAC0 ); /* Set back to std BACnet/IP port */
/* try to bind with the target device */ /* try to bind with the target device */
found = found =
address_bind_request(Target_Device_Object_Instance, &max_apdu, address_bind_request(Target_Device_Object_Instance, &max_apdu,
&Target_Address); &Target_Address);
if (!found) { if (!found) {
if ( Provided_Targ_MAC ) { if ( Provided_Targ_MAC ) {
/* Update by adding the MAC address */ /* Update by adding the MAC address */
if ( max_apdu == 0 ) if ( max_apdu == 0 )
max_apdu = MAX_APDU; /* Whatever set for this datalink. */ max_apdu = MAX_APDU; /* Whatever set for this datalink. */
address_add_binding( Target_Device_Object_Instance, max_apdu, address_add_binding( Target_Device_Object_Instance, max_apdu,
&Target_Address); &Target_Address);
} else { } else {
Send_WhoIs(Target_Device_Object_Instance, Send_WhoIs(Target_Device_Object_Instance,
Target_Device_Object_Instance); Target_Device_Object_Instance);
} }
} }
printf("List of Objects in test device:\r\n"); printf("List of Objects in test device:\r\n");
@@ -943,7 +942,7 @@ 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!\r\n");
break; break;
} }
/* else, loop back and try again */ /* else, loop back and try again */
@@ -960,13 +959,10 @@ int main(
case GET_LIST_OF_ALL_REQUEST: /* differs in ArrayIndex only */ case GET_LIST_OF_ALL_REQUEST: /* 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 );
/* Override the default and set the optional array index to "None" */
if (myState == GET_ALL_REQUEST)
rpm_object->listOfProperties->propertyArrayIndex = -1;
invoke_id = invoke_id =
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) {
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;
@@ -1002,20 +998,20 @@ int main(
} else if (tsm_invoke_id_free(invoke_id)) { } else if (tsm_invoke_id_free(invoke_id)) {
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 == ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE ) if ( Last_Error_Code == ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE )
{ {
Has_RPM = false; Has_RPM = false;
myState = GET_PROPERTY_REQUEST; myState = GET_PROPERTY_REQUEST;
} }
/* Try again, just to get a list of properties. */ /* Try again, just to get a list of properties. */
else if (myState == GET_ALL_RESPONSE) else if (myState == GET_ALL_RESPONSE)
myState = GET_LIST_OF_ALL_REQUEST; myState = GET_LIST_OF_ALL_REQUEST;
/* Else drop back to RP. */ /* Else drop back to RP. */
else else
{ {
myState = GET_PROPERTY_REQUEST; myState = GET_PROPERTY_REQUEST;
StartNextObject( rpm_object, &myObject ); StartNextObject( rpm_object, &myObject );
} }
} }
else if ( Has_RPM ) else if ( Has_RPM )
@@ -1153,11 +1149,11 @@ int main(
myObject.type = MAX_BACNET_OBJECT_TYPE; myObject.type = MAX_BACNET_OBJECT_TYPE;
} }
if ( Has_RPM ) if ( Has_RPM )
myState = GET_ALL_REQUEST; myState = GET_ALL_REQUEST;
else else
{ {
myState = GET_PROPERTY_REQUEST; myState = GET_PROPERTY_REQUEST;
StartNextObject( rpm_object, &myObject ); StartNextObject( rpm_object, &myObject );
} }
} while (myObject.type == OBJECT_DEVICE); } while (myObject.type == OBJECT_DEVICE);
@@ -1174,7 +1170,7 @@ 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!\r\n");
break; break;
} }
} }
@@ -1182,7 +1178,7 @@ int main(
} while (myObject.type < MAX_BACNET_OBJECT_TYPE); } while (myObject.type < MAX_BACNET_OBJECT_TYPE);
if ( Error_Count > 0 ) if ( Error_Count > 0 )
fprintf(stderr, "\r-- Found %d Errors \r\n", Error_Count ); fprintf(stderr, "\r-- Found %d Errors \r\n", Error_Count );
/* Closing brace for all Objects */ /* Closing brace for all Objects */
printf("} \r\n"); printf("} \r\n");