Changed the API to pass the NPDU data down through the datalink layer in order to make the dlmstp work since it needs data-expecting-reply information. Of course, this affected all the demos, all the unit tests, and most of the demo handlers. Corrected some TSM leaks in confirmed messages. Refactored the AtomicReadFile and AtomicWriteFile demos by moving the Send_ functions to the demo/handlers directory and using the s_whois common handler. Added some common defines for the BACnet version and revision since several modules were using the info. Hopefully I didn't break too many things.

This commit is contained in:
skarg
2006-08-13 00:54:05 +00:00
parent 185d02a9ff
commit 5bb205dc03
46 changed files with 793 additions and 638 deletions
+87 -47
View File
@@ -56,7 +56,7 @@ void handler_write_property(uint8_t * service_request,
BACNET_WRITE_PROPERTY_DATA wp_data;
int len = 0;
int pdu_len = 0;
BACNET_ADDRESS my_address;
BACNET_NPDU_DATA npdu_data;
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
int bytes_sent = 0;
@@ -64,6 +64,7 @@ void handler_write_property(uint8_t * service_request,
/* decode the service request only */
len = wp_decode_service_request(service_request,
service_len, &wp_data);
#if PRINT_ENABLED
fprintf(stderr, "Received Write-Property Request!\n");
if (len > 0)
fprintf(stderr, "type=%u instance=%u property=%u index=%d\n",
@@ -72,192 +73,231 @@ void handler_write_property(uint8_t * service_request,
wp_data.object_property, wp_data.array_index);
else
fprintf(stderr, "Unable to decode Write-Property Request!\n");
/* prepare a reply */
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len == -1) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
if (len <= 0) {
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, ABORT_REASON_OTHER);
#if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n");
#endif
} else if (service_data->segmented_message) {
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
#if PRINT_ENABLED
fprintf(stderr, "Sending Abort!\n");
#endif
} else {
switch (wp_data.object_type) {
case OBJECT_DEVICE:
if (Device_Write_Property(&wp_data, &error_class, &error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for Device!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Error for Device!\n");
#endif
}
break;
case OBJECT_ANALOG_INPUT:
case OBJECT_BINARY_INPUT:
error_class = ERROR_CLASS_PROPERTY;
error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error!\n");
#endif
break;
case OBJECT_BINARY_OUTPUT:
if (Binary_Output_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for BO!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BO!\n");
#endif
}
break;
case OBJECT_BINARY_VALUE:
if (Binary_Value_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for BV!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for BV!\n");
#endif
}
break;
case OBJECT_ANALOG_OUTPUT:
if (Analog_Output_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for AO!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AO!\n");
#endif
}
break;
case OBJECT_ANALOG_VALUE:
if (Analog_Value_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for AV!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for AV!\n");
#endif
}
break;
case OBJECT_LIFE_SAFETY_POINT:
if (Life_Safety_Point_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for LSP!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for LSP!\n");
#endif
}
break;
case OBJECT_MULTI_STATE_OUTPUT:
if (Multistate_Output_Write_Property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for MSO!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for MSO!\n");
#endif
}
break;
#if BACFILE
case OBJECT_FILE:
if (bacfile_write_property(&wp_data, &error_class,
&error_code)) {
pdu_len +=
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
encode_simple_ack(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr,
"Sending Write Property Simple Ack for File!\n");
#endif
} else {
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for File!\n");
#endif
}
break;
#endif
default:
pdu_len +=
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
pdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Unknown Object Error!\n");
#endif
break;
}
}
bytes_sent = datalink_send_pdu(src, /* destination address */
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
#endif
return;
}