Bugfix/confirmed handlers empty service request (#885)

* Added reject in all confirmed service handlers, except GetEventInformation, when confirmed services with zero length occur which rejects with required parameters are missing message.

* Refactored errno use in service using debug_perror. Changed debug_perror usage to debug_fprintf. 

* Updated file and function headers in basic/service modules.

* Changed NDPU priority on confirmed messages to use requested NDPU priority.

* Renamed debug_aprintf to debug_printf_stdout for clarity.

* Convert most debug_fprintf usage to debug_print to reduce text bloat in AVR build
This commit is contained in:
Steve Karg
2025-01-05 10:09:39 -06:00
committed by GitHub
parent 1f41e2c933
commit 94b3809a58
135 changed files with 1166 additions and 1609 deletions
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
+1
View File
@@ -8,6 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <errno.h>
#include "blinkt.h" #include "blinkt.h"
#define BLINKT_DEFAULT_BRIGHTNESS 7 #define BLINKT_DEFAULT_BRIGHTNESS 7
-2
View File
@@ -99,8 +99,6 @@ static void Init_Service_Handlers(void)
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
apdu_set_unconfirmed_handler( apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_WRITE_GROUP, handler_write_group); SERVICE_UNCONFIRMED_WRITE_GROUP, handler_write_group);
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -14,7 +14,6 @@
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h> #include <locale.h>
#endif #endif
#include <errno.h>
#include <assert.h> #include <assert.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-2
View File
@@ -60,8 +60,6 @@ static void Init_Service_Handlers()
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control); handler_device_communication_control);
-2
View File
@@ -61,8 +61,6 @@ static void Init_Service_Handlers(void)
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
handler_device_communication_control); handler_device_communication_control);
-2
View File
@@ -185,8 +185,6 @@ static void Init_Service_Handlers(uint32_t first_object_instance)
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> #include <time.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
+1
View File
@@ -1,3 +1,4 @@
#include <errno.h>
#include <time.h> #include <time.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-2
View File
@@ -170,8 +170,6 @@ static void Init_Service_Handlers(void)
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
/* handle communication so we can shutup when asked */ /* handle communication so we can shutup when asked */
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
+16 -26
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -17,8 +16,10 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/ptransfer.h" #include "bacnet/ptransfer.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#define MYMAXSTR 32 #define MYMAXSTR 32
@@ -185,24 +186,24 @@ void handler_conf_private_trans(
error_class = ERROR_CLASS_OBJECT; error_class = ERROR_CLASS_OBJECT;
error_code = ERROR_CODE_UNKNOWN_OBJECT; error_code = ERROR_CODE_UNKNOWN_OBJECT;
#if PRINT_ENABLED debug_print("Received Confirmed Private Transfer Request!\n");
fprintf(stderr, "Received Confirmed Private Transfer Request!\n");
#endif
/* encode the NPDU portion of the response packet as it will be needed */ /* encode the NPDU portion of the response packet as it will be needed */
/* no matter what the outcome. */ /* no matter what the outcome. */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_len == 0) {
if (service_data->segmented_message) { len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("CPT: Missing Required Parameter. Sending Reject!\n");
goto CPT_ABORT;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("CPT: Segmented Message. Sending Abort!\n");
fprintf(stderr, "CPT: Segmented Message. Sending Abort!\n");
#endif
goto CPT_ABORT; goto CPT_ABORT;
} }
@@ -212,9 +213,7 @@ void handler_conf_private_trans(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("CPT: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "CPT: Bad Encoding. Sending Abort!\n");
#endif
goto CPT_ABORT; goto CPT_ABORT;
} }
@@ -234,9 +233,7 @@ void handler_conf_private_trans(
error = true; error = true;
error_class = ERROR_CLASS_SERVICES; error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_OTHER; error_code = ERROR_CODE_OTHER;
#if PRINT_ENABLED debug_print("CPT: Error servicing request!\n");
fprintf(stderr, "CPT: Error servicing request!\n");
#endif
} }
len = ptransfer_ack_encode_apdu( len = ptransfer_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data);
@@ -245,9 +242,7 @@ void handler_conf_private_trans(
error = true; error = true;
error_class = ERROR_CLASS_SERVICES; error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
#if PRINT_ENABLED debug_print("CPT: Not our Vendor ID or invalid service code!\n");
fprintf(stderr, "CPT: Not our Vendor ID or invalid service code!\n");
#endif
} }
if (error) { if (error) {
@@ -259,12 +254,7 @@ CPT_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
debug_perror("CPT: Failed to send PDU");
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
}
#endif
return; return;
} }
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <ctype.h> /* for tupper */ #include <ctype.h> /* for tupper */
#if defined(WIN32) || defined(__BORLANDC__) #if defined(WIN32) || defined(__BORLANDC__)
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */ #include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */ #include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h> #include <locale.h>
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h> #include <locale.h>
-1
View File
@@ -12,7 +12,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h> #include <locale.h>
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -18,7 +18,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <libconfig.h> /* read config files */ #include <libconfig.h> /* read config files */
-1
View File
@@ -9,7 +9,6 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
+12 -21
View File
@@ -12,7 +12,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <ctype.h> /* for toupper */ #include <ctype.h> /* for toupper */
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
@@ -58,6 +57,9 @@ BACNET_SUBSCRIBE_COV_DATA *COV_Subscribe_Data = NULL;
/* flags to signal early termination */ /* flags to signal early termination */
static bool Simple_Ack_Detected = false; static bool Simple_Ack_Detected = false;
static bool Cancel_Requested = false; static bool Cancel_Requested = false;
/* callback for printing the notifications */
static BACNET_COV_NOTIFICATION Confirmed_COV_Notification_Callback;
static BACNET_COV_NOTIFICATION Unconfirmed_COV_Notification_Callback;
static void MyErrorHandler( static void MyErrorHandler(
BACNET_ADDRESS *src, BACNET_ADDRESS *src,
@@ -99,21 +101,6 @@ MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, uint8_t reject_reason)
} }
} }
static void My_Unconfirmed_COV_Notification_Handler(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src)
{
handler_ucov_notification(service_request, service_len, src);
}
static void My_Confirmed_COV_Notification_Handler(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
{
handler_ccov_notification(service_request, service_len, src, service_data);
}
static void static void
MyWritePropertySimpleAckHandler(BACNET_ADDRESS *src, uint8_t invoke_id) MyWritePropertySimpleAckHandler(BACNET_ADDRESS *src, uint8_t invoke_id)
{ {
@@ -138,13 +125,17 @@ static void Init_Service_Handlers(void)
/* we must implement read property - it's required! */ /* we must implement read property - it's required! */
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property); SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property);
/* handle the data coming back from COV subscriptions */ /* handle the data coming back from confirmed COV subscriptions */
apdu_set_confirmed_handler( apdu_set_confirmed_handler(
SERVICE_CONFIRMED_COV_NOTIFICATION, SERVICE_CONFIRMED_COV_NOTIFICATION, handler_ccov_notification);
My_Confirmed_COV_Notification_Handler); /* add a callback for printing the data */
Confirmed_COV_Notification_Callback.callback = handler_ccov_data_print;
handler_ccov_notification_add(&Confirmed_COV_Notification_Callback);
Unconfirmed_COV_Notification_Callback.callback = handler_ucov_data_print;
handler_ucov_notification_add(&Unconfirmed_COV_Notification_Callback);
/* handle the data coming back from unconfirmed COV subscriptions */
apdu_set_unconfirmed_handler( apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
My_Unconfirmed_COV_Notification_Handler);
/* handle the Simple ack coming back from SubscribeCOV */ /* handle the Simple ack coming back from SubscribeCOV */
apdu_set_confirmed_simple_ack_handler( apdu_set_confirmed_simple_ack_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, MyWritePropertySimpleAckHandler); SERVICE_CONFIRMED_SUBSCRIBE_COV, MyWritePropertySimpleAckHandler);
+1 -1
View File
@@ -32,7 +32,7 @@
#endif #endif
/* print with flush by default */ /* print with flush by default */
#define PRINTF debug_aprintf #define PRINTF debug_printf_stdout
/* current version of the BACnet stack */ /* current version of the BACnet stack */
static const char *BACnet_Version = BACNET_VERSION_TEXT; static const char *BACnet_Version = BACNET_VERSION_TEXT;
+3 -3
View File
@@ -257,13 +257,13 @@ int main(int argc, char *argv[])
} }
} }
if (device_id > BACNET_MAX_INSTANCE) { if (device_id > BACNET_MAX_INSTANCE) {
debug_perror( debug_fprintf(
"device-instance=%u - not greater than %u\n", device_id, stderr, "device-instance=%u - not greater than %u\n", device_id,
BACNET_MAX_INSTANCE); BACNET_MAX_INSTANCE);
return 1; return 1;
} }
Device_Set_Object_Instance_Number(device_id); Device_Set_Object_Instance_Number(device_id);
debug_aprintf( debug_printf_stdout(
"BACnet Server-Discovery Demo\n" "BACnet Server-Discovery Demo\n"
"BACnet Stack Version %s\n" "BACnet Stack Version %s\n"
"BACnet Device ID: %u\n" "BACnet Device ID: %u\n"
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <ctype.h> /* for toupper */ #include <ctype.h> /* for toupper */
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */ #include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -15,7 +15,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#include <string.h> #include <string.h>
#include <errno.h>
#include <ctype.h> /* toupper */ #include <ctype.h> /* toupper */
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
-1
View File
@@ -14,7 +14,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <time.h> /* for time */ #include <time.h> /* for time */
#define PRINT_ENABLED 1 #define PRINT_ENABLED 1
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
+1 -1
View File
@@ -52,7 +52,7 @@ static int bvlc_encode_bvlc_result(uint8_t *pdu, BACNET_BVLC_RESULT result_code)
* @param mtu - the bytes of data to send * @param mtu - the bytes of data to send
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
static int bvlc_send_mpdu( static int bvlc_send_mpdu(
const uint8_t *dest_addr, /* the destination address */ const uint8_t *dest_addr, /* the destination address */
+9 -11
View File
@@ -1,10 +1,10 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2005 Steve Karg * @brief Initializes BACnet/IP interface (BSD/MAC OS X)
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 * @date 2005
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <stdint.h> /* for standard integer types uint8_t etc. */ #include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */ #include <stdbool.h> /* for the standard bool type. */
#include <ifaddrs.h> #include <ifaddrs.h>
@@ -15,8 +15,6 @@
#include "bacnet/basic/bbmd/h_bbmd.h" #include "bacnet/basic/bbmd/h_bbmd.h"
#include "bacport.h" #include "bacport.h"
/** @file bsd/bip-init.c @brief Initializes BACnet/IP interface (BSD/MAC OS X). */
/* unix sockets */ /* unix sockets */
static int BIP_Socket = -1; static int BIP_Socket = -1;
static int BIP_Broadcast_Socket = -1; static int BIP_Broadcast_Socket = -1;
@@ -257,7 +255,7 @@ uint8_t bip_get_subnet_prefix(void)
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip_send_mpdu( int bip_send_mpdu(
const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
@@ -409,7 +407,7 @@ uint16_t bip_receive(
* @param mtu - the bytes of data to send * @param mtu - the bytes of data to send
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip_send_pdu( int bip_send_pdu(
BACNET_ADDRESS *dest, BACNET_ADDRESS *dest,
+10 -9
View File
@@ -1,15 +1,16 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2016 Steve Karg * @brief Initializes BACnet/IPv6 interface (BSD/MAC OS X)
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 * @date 2016
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <ifaddrs.h> #include <ifaddrs.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> /* for standard integer types uint8_t etc. */ #include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */ #include <stdbool.h> /* for the standard bool type. */
#include <errno.h>
#include "bacnet/bacdcode.h" #include "bacnet/bacdcode.h"
#include "bacnet/config.h" #include "bacnet/config.h"
#include "bacnet/datalink/bip6.h" #include "bacnet/datalink/bip6.h"
@@ -244,7 +245,7 @@ bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr)
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip6_send_mpdu( int bip6_send_mpdu(
const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
@@ -286,7 +287,7 @@ int bip6_send_mpdu(
* @param pdu - the bytes of data to send * @param pdu - the bytes of data to send
* @param pdu_len - the number of bytes of data to send * @param pdu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip6_send_pdu(BACNET_ADDRESS *dest, int bip6_send_pdu(BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data, BACNET_NPDU_DATA *npdu_data,
-1
View File
@@ -11,7 +11,6 @@
#include <pthread.h> #include <pthread.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/bsc/bsc-event.h" #include "bacnet/datalink/bsc/bsc-event.h"
+8 -12
View File
@@ -1,11 +1,11 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net> * @brief Provides BSD-specific DataLink functions for MS/TP.
* Updated by Nikola Jelic 2011 <nikola.jelic@euroicc.com> * @author Steve Karg <skarg@users.sourceforge.net>
* * @author Nikola Jelic 2011 <nikola.jelic@euroicc.com>
* SPDX-License-Identifier: MIT * @date 2008
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@@ -27,12 +27,8 @@
/* port specific */ /* port specific */
#include "rs485.h" #include "rs485.h"
/** @file bsd/dlmstp.c Provides BSD-specific DataLink functions for MS/TP.
*/
/* Number of MS/TP Packets Rx/Tx */ /* Number of MS/TP Packets Rx/Tx */
uint16_t MSTP_Packets = 0; uint16_t MSTP_Packets = 0;
/* packet queues */ /* packet queues */
static DLMSTP_PACKET Receive_Packet; static DLMSTP_PACKET Receive_Packet;
/* mechanism to wait for a packet */ /* mechanism to wait for a packet */
+8 -10
View File
@@ -1,10 +1,10 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net> * @brief Provides BSD-specific DataLink functions for MS/TP.
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: MIT * @date 2008
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sys/time.h> #include <sys/time.h>
#include <errno.h>
/* BSD includes */ /* BSD includes */
#include <IOKit/serial/ioss.h> #include <IOKit/serial/ioss.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
@@ -29,9 +30,6 @@
/* OS Specific include */ /* OS Specific include */
#include "bacport.h" #include "bacport.h"
/** @file bsd/dlmstp_port.c Provides BSD-specific DataLink functions for MS/TP.
*/
#define BACNET_PDU_CONTROL_BYTE_OFFSET 1 #define BACNET_PDU_CONTROL_BYTE_OFFSET 1
#define BACNET_DATA_EXPECTING_REPLY_BIT 2 #define BACNET_DATA_EXPECTING_REPLY_BIT 2
#define BACNET_DATA_EXPECTING_REPLY(control) \ #define BACNET_DATA_EXPECTING_REPLY(control) \
+10 -12
View File
@@ -1,11 +1,10 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2005 Steve Karg * @brief Initializes BACnet/IP interface (Linux).
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 * @date 2005
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
/* linux Ethernet/IP specific */
#include <asm/types.h> #include <asm/types.h>
#include <netinet/ether.h> #include <netinet/ether.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -23,6 +22,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
/* BACnet specific */ /* BACnet specific */
#include "bacnet/bacdcode.h" #include "bacnet/bacdcode.h"
#include "bacnet/bacint.h" #include "bacnet/bacint.h"
@@ -31,8 +31,6 @@
#include "bacnet/basic/bbmd/h_bbmd.h" #include "bacnet/basic/bbmd/h_bbmd.h"
#include "bacport.h" #include "bacport.h"
/** @file linux/bip-init.c Initializes BACnet/IP interface (Linux). */
/* unix sockets */ /* unix sockets */
static int BIP_Socket = -1; static int BIP_Socket = -1;
static int BIP_Broadcast_Socket = -1; static int BIP_Broadcast_Socket = -1;
@@ -273,7 +271,7 @@ uint8_t bip_get_subnet_prefix(void)
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip_send_mpdu( int bip_send_mpdu(
const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
@@ -425,7 +423,7 @@ uint16_t bip_receive(
* @param mtu - the bytes of data to send * @param mtu - the bytes of data to send
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip_send_pdu( int bip_send_pdu(
BACNET_ADDRESS *dest, BACNET_ADDRESS *dest,
+10 -9
View File
@@ -1,15 +1,16 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2016 Steve Karg * @brief Initializes BACnet/IP interface (Linux).
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 * @date 2016
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <ifaddrs.h> #include <ifaddrs.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> /* for standard integer types uint8_t etc. */ #include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */ #include <stdbool.h> /* for the standard bool type. */
#include <errno.h>
#include "bacnet/bacdcode.h" #include "bacnet/bacdcode.h"
#include "bacnet/config.h" #include "bacnet/config.h"
#include "bacnet/datalink/bip6.h" #include "bacnet/datalink/bip6.h"
@@ -234,7 +235,7 @@ bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr)
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip6_send_mpdu( int bip6_send_mpdu(
const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
@@ -278,7 +279,7 @@ int bip6_send_mpdu(
* @param pdu - the bytes of data to send * @param pdu - the bytes of data to send
* @param pdu_len - the number of bytes of data to send * @param pdu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip6_send_pdu( int bip6_send_pdu(
BACNET_ADDRESS *dest, BACNET_ADDRESS *dest,
-1
View File
@@ -11,7 +11,6 @@
#include <pthread.h> #include <pthread.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/bsc/bsc-event.h" #include "bacnet/datalink/bsc/bsc-event.h"
+8 -11
View File
@@ -1,11 +1,11 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net> * @brief Provides Linux-specific DataLink functions for MS/TP.
* Updated by Nikola Jelic 2011 <nikola.jelic@euroicc.com> * @author Steve Karg <skarg@users.sourceforge.net>
* * @author Nikola Jelic 2011 <nikola.jelic@euroicc.com>
* SPDX-License-Identifier: MIT * @date 2008
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@@ -27,9 +27,6 @@
/* port specific */ /* port specific */
#include "rs485.h" #include "rs485.h"
/** @file linux/dlmstp.c Provides Linux-specific DataLink functions for MS/TP.
*/
/* Number of MS/TP Packets Rx/Tx */ /* Number of MS/TP Packets Rx/Tx */
uint16_t MSTP_Packets = 0; uint16_t MSTP_Packets = 0;
+8 -11
View File
@@ -1,10 +1,10 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net> * @brief Provides Linux-specific DataLink functions for MS/TP.
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: MIT * @date 2008
* * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*********************************************************************/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -27,10 +28,6 @@
/* OS Specific include */ /* OS Specific include */
#include "bacport.h" #include "bacport.h"
/** @file linux/dlmstp_port.c Provides Linux-specific DataLink functions for
* MS/TP.
*/
#define BACNET_PDU_CONTROL_BYTE_OFFSET 1 #define BACNET_PDU_CONTROL_BYTE_OFFSET 1
#define BACNET_DATA_EXPECTING_REPLY_BIT 2 #define BACNET_DATA_EXPECTING_REPLY_BIT 2
#define BACNET_DATA_EXPECTING_REPLY(control) \ #define BACNET_DATA_EXPECTING_REPLY(control) \
+2 -2
View File
@@ -413,7 +413,7 @@ uint8_t bip_get_subnet_prefix(void)
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip_send_mpdu( int bip_send_mpdu(
const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
@@ -563,7 +563,7 @@ uint16_t bip_receive(
* @param mtu - the bytes of data to send * @param mtu - the bytes of data to send
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip_send_pdu( int bip_send_pdu(
BACNET_ADDRESS *dest, BACNET_ADDRESS *dest,
+2 -2
View File
@@ -346,7 +346,7 @@ bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr)
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip6_send_mpdu( int bip6_send_mpdu(
const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
@@ -390,7 +390,7 @@ int bip6_send_mpdu(
* @param pdu - the bytes of data to send * @param pdu - the bytes of data to send
* @param pdu_len - the number of bytes of data to send * @param pdu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bip6_send_pdu( int bip6_send_pdu(
BACNET_ADDRESS *dest, BACNET_ADDRESS *dest,
-1
View File
@@ -10,7 +10,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <errno.h>
#include "bacnet/datalink/bsc/bsc-event.h" #include "bacnet/datalink/bsc/bsc-event.h"
#define DEBUG_BSC_EVENT 0 #define DEBUG_BSC_EVENT 0
+2 -2
View File
@@ -576,7 +576,7 @@ static void bbmd_read_fdt_ack_handler(
* @param mtu - the bytes of data to send * @param mtu - the bytes of data to send
* @param mtu_len - the number of bytes of data to send * @param mtu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bvlc_send_pdu( int bvlc_send_pdu(
const BACNET_ADDRESS *dest, const BACNET_ADDRESS *dest,
@@ -648,7 +648,7 @@ int bvlc_send_pdu(
* @param result_code - BVLC result code * @param result_code - BVLC result code
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
static int static int
bvlc_send_result(const BACNET_IP_ADDRESS *dest_addr, uint16_t result_code) bvlc_send_result(const BACNET_IP_ADDRESS *dest_addr, uint16_t result_code)
+4 -4
View File
@@ -285,7 +285,7 @@ static bool bbmd6_address_from_bacnet_address(
* @param pdu - the bytes of data to send * @param pdu - the bytes of data to send
* @param pdu_len - the number of bytes of data to send * @param pdu_len - the number of bytes of data to send
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
int bvlc6_send_pdu( int bvlc6_send_pdu(
const BACNET_ADDRESS *dest, const BACNET_ADDRESS *dest,
@@ -452,7 +452,7 @@ static void bbmd6_send_forward_npdu(
* @param result_code - BVLC result code * @param result_code - BVLC result code
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
static int bvlc6_send_result( static int bvlc6_send_result(
const BACNET_IP6_ADDRESS *dest_addr, const BACNET_IP6_ADDRESS *dest_addr,
@@ -476,7 +476,7 @@ static int bvlc6_send_result(
* @param vmac_dst - Destination-Virtual-Address * @param vmac_dst - Destination-Virtual-Address
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
static int bvlc6_send_address_resolution_ack( static int bvlc6_send_address_resolution_ack(
const BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst) const BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst)
@@ -500,7 +500,7 @@ static int bvlc6_send_address_resolution_ack(
* @param vmac_dst - Destination-Virtual-Address * @param vmac_dst - Destination-Virtual-Address
* *
* @return Upon successful completion, returns the number of bytes sent. * @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error. * Otherwise, -1 shall be returned to indicate the error.
*/ */
static int bvlc6_send_virtual_address_resolution_ack( static int bvlc6_send_virtual_address_resolution_ack(
const BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst) const BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst)
+17 -16
View File
@@ -610,8 +610,8 @@ static void bacnet_device_object_property_add(
device_data->Object_List, rp_data->object_type, device_data->Object_List, rp_data->object_type,
rp_data->object_instance); rp_data->object_instance);
if (!object_data) { if (!object_data) {
debug_perror( debug_fprintf(
"%s-%u object fail to add!\n", stderr, "%s-%u object fail to add!\n",
bactext_object_type_name(rp_data->object_type), bactext_object_type_name(rp_data->object_type),
rp_data->object_instance); rp_data->object_instance);
return; return;
@@ -619,8 +619,8 @@ static void bacnet_device_object_property_add(
property_data = bacnet_property_data_add( property_data = bacnet_property_data_add(
object_data->Property_List, rp_data->object_property); object_data->Property_List, rp_data->object_property);
if (!property_data) { if (!property_data) {
debug_perror( debug_fprintf(
"%s-%u %s property fail to add!\n", stderr, "%s-%u %s property fail to add!\n",
bactext_object_type_name(rp_data->object_type), bactext_object_type_name(rp_data->object_type),
rp_data->object_instance, rp_data->object_instance,
bactext_property_name(rp_data->object_property)); bactext_property_name(rp_data->object_property));
@@ -640,8 +640,8 @@ static void bacnet_device_object_property_add(
property_data->application_data, rp_data->application_data, property_data->application_data, rp_data->application_data,
rp_data->application_data_len); rp_data->application_data_len);
} else { } else {
debug_perror( debug_fprintf(
"%s-%u %s property fail to allocate!\n", stderr, "%s-%u %s property fail to allocate!\n",
bactext_object_type_name(rp_data->object_type), bactext_object_type_name(rp_data->object_type),
rp_data->object_instance, rp_data->object_instance,
bactext_property_name(rp_data->object_property)); bactext_property_name(rp_data->object_property));
@@ -794,7 +794,8 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data)
device_data->Discovery_State = device_data->Discovery_State =
BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST; BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST;
} else { } else {
debug_perror("%u object-list-size fail to queue!\n", device_id); debug_fprintf(
stderr, "%u object-list-size fail to queue!\n", device_id);
} }
break; break;
case BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST: case BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST:
@@ -824,9 +825,9 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data)
BACNET_DISCOVER_STATE_OBJECT_LIST_REQUEST; BACNET_DISCOVER_STATE_OBJECT_LIST_REQUEST;
return; return;
} else { } else {
debug_perror( debug_fprintf(
"%u object-list[%u] %s-%u fail to queue!\n", device_id, stderr, "%u object-list[%u] %s-%u fail to queue!\n",
device_data->Object_List_Index, device_id, device_data->Object_List_Index,
bactext_object_type_name(object_type), bactext_object_type_name(object_type),
(unsigned)object_instance); (unsigned)object_instance);
device_data->Object_List_Index--; device_data->Object_List_Index--;
@@ -862,9 +863,9 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data)
BACNET_DISCOVER_STATE_OBJECT_GET_PROPERTY_REQUEST; BACNET_DISCOVER_STATE_OBJECT_GET_PROPERTY_REQUEST;
device_data->Object_List_Index++; device_data->Object_List_Index++;
} else { } else {
debug_perror( debug_fprintf(
"%u object-list[%u] %s-%u fail to queue!\n", device_id, stderr, "%u object-list[%u] %s-%u fail to queue!\n",
device_data->Object_List_Index, device_id, device_data->Object_List_Index,
bactext_object_type_name(object_type), bactext_object_type_name(object_type),
(unsigned)object_instance); (unsigned)object_instance);
} }
@@ -886,8 +887,8 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data)
} }
break; break;
default: default:
debug_perror( debug_fprintf(
"%u unknown state %u!\n", device_id, stderr, "%u unknown state %u!\n", device_id,
device_data->Discovery_State); device_data->Discovery_State);
break; break;
} }
@@ -911,7 +912,7 @@ static void bacnet_discover_devices_task(void)
for (device_index = 0; device_index < device_count; device_index++) { for (device_index = 0; device_index < device_count; device_index++) {
device_data = Keylist_Data_Index(Device_List, device_index); device_data = Keylist_Data_Index(Device_List, device_index);
if (!device_data) { if (!device_data) {
debug_perror("device[%u] is NULL!\n", device_index); debug_fprintf(stderr, "device[%u] is NULL!\n", device_index);
continue; continue;
} }
if (Keylist_Index_Key(Device_List, device_index, &key)) { if (Keylist_Index_Key(Device_List, device_index, &key)) {
+3 -10
View File
@@ -7,7 +7,6 @@
*/ */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h" #include "bacnet/bacdcode.h"
@@ -169,19 +168,13 @@ int Send_Network_Layer_Message(
"Sending %s message to local BACnet network \n", "Sending %s message to local BACnet network \n",
bactext_network_layer_msg_name(network_message_type)); bactext_network_layer_msg_name(network_message_type));
} }
/* Now send the message */ /* Now send the message */
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
dst, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); dst, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
int wasErrno = errno; /* preserve the errno */ debug_perror("Failed to send message");
debug_printf(
"Failed to send %s message (%s)!\n",
bactext_network_layer_msg_name(network_message_type),
strerror(wasErrno));
} }
#endif
return bytes_sent; return bytes_sent;
} }
@@ -236,7 +229,7 @@ void Send_Reject_Message_To_Network(
iArgs[1] = dnet; iArgs[1] = dnet;
Send_Network_Layer_Message( Send_Network_Layer_Message(
NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst, iArgs); NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst, iArgs);
debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet); debug_printf("Reject Reason=%d, DNET=%u\n", reject_reason, dnet);
} }
/** Send an Initialize Routing Table message, built from an optional DNET[] /** Send an Initialize Routing Table message, built from an optional DNET[]
+8 -10
View File
@@ -21,17 +21,14 @@
#include "bacnet/rp.h" #include "bacnet/rp.h"
#include "bacnet/wp.h" #include "bacnet/wp.h"
#include "bacnet/cov.h" #include "bacnet/cov.h"
/* basic objects and services */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/keylist.h" #include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/debug.h"
/* me! */ /* me! */
#include "bacnet/basic/object/bi.h" #include "bacnet/basic/object/bi.h"
#include "bacnet/basic/sys/debug.h"
#if !defined(PRINT)
#define PRINT debug_perror
#endif
static const char *Default_Active_Text = "Active"; static const char *Default_Active_Text = "Active";
static const char *Default_Inactive_Text = "Inactive"; static const char *Default_Inactive_Text = "Inactive";
struct object_data { struct object_data {
@@ -1732,7 +1729,7 @@ int Binary_Input_Alarm_Summary(
struct object_data *pObject = Binary_Input_Object_Index(index); struct object_data *pObject = Binary_Input_Object_Index(index);
if (getalarm_data == NULL) { if (getalarm_data == NULL) {
PRINT( debug_printf(
"[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__, "[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__,
__LINE__, (void *)getalarm_data); __LINE__, (void *)getalarm_data);
return -2; return -2;
@@ -1919,7 +1916,8 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
pObject->Ack_notify_data.bSendAckNotify = false; pObject->Ack_notify_data.bSendAckNotify = false;
/* copy toState */ /* copy toState */
ToState = pObject->Ack_notify_data.EventState; ToState = pObject->Ack_notify_data.EventState;
PRINT("Binary-Input[%d]: Send AckNotification.\n", object_instance); debug_printf(
"Binary-Input[%d]: Send AckNotification.\n", object_instance);
characterstring_init_ansi(&msgText, "AckNotification"); characterstring_init_ansi(&msgText, "AckNotification");
/* Notify Type */ /* Notify Type */
@@ -1999,7 +1997,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
default: default:
break; break;
} /* switch (ToState) */ } /* switch (ToState) */
PRINT( debug_printf(
"Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n", "Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n",
object_instance, bactext_event_state_name(FromState), object_instance, bactext_event_state_name(FromState),
bactext_event_state_name(ToState)); bactext_event_state_name(ToState));
@@ -2112,7 +2110,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
} }
/* add data from notification class */ /* add data from notification class */
PRINT( debug_printf(
"Binary-Input[%d]: Notification Class[%d]-%s " "Binary-Input[%d]: Notification Class[%d]-%s "
"%u/%u/%u-%u:%u:%u.%u!\n", "%u/%u/%u-%u:%u:%u.%u!\n",
object_instance, event_data.notificationClass, object_instance, event_data.notificationClass,
@@ -2129,7 +2127,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Ack required */ /* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) { (event_data.ackRequired == true)) {
PRINT("Binary-Input[%d]: Ack Required!\n", object_instance); debug_printf("Binary-Input[%d]: Ack Required!\n", object_instance);
switch (event_data.toState) { switch (event_data.toState) {
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL] pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL]
+16 -18
View File
@@ -21,17 +21,14 @@
#include "bacnet/wp.h" #include "bacnet/wp.h"
#include "bacnet/rp.h" #include "bacnet/rp.h"
#include "bacnet/cov.h" #include "bacnet/cov.h"
/* basic objects and services */
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/sys/keylist.h" #include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/debug.h"
/* me! */ /* me! */
#include "bacnet/basic/object/bv.h" #include "bacnet/basic/object/bv.h"
#include "bacnet/basic/sys/debug.h"
#if !defined(PRINT)
#define PRINT debug_perror
#endif
static const char *Default_Active_Text = "Active"; static const char *Default_Active_Text = "Active";
static const char *Default_Inactive_Text = "Inactive"; static const char *Default_Inactive_Text = "Inactive";
struct object_data { struct object_data {
@@ -285,7 +282,7 @@ BACNET_BINARY_PV Binary_Value_Present_Value(uint32_t object_instance)
/** /**
* @brief For a given object instance-number, checks the present-value for COV * @brief For a given object instance-number, checks the present-value for COV
* @param pObject - specific object with valid data * @param pObject - specific object with valid data
* @param value - floating point analog value * @param value - binary value
*/ */
static void Binary_Value_Present_Value_COV_Detect( static void Binary_Value_Present_Value_COV_Detect(
struct object_data *pObject, BACNET_BINARY_PV value) struct object_data *pObject, BACNET_BINARY_PV value)
@@ -525,7 +522,7 @@ bool Binary_Value_Present_Value_Set(
* For a given object instance-number, sets the present-value * For a given object instance-number, sets the present-value
* *
* @param object_instance - object-instance number of the object * @param object_instance - object-instance number of the object
* @param value - floating point analog value * @param value - binary value
* @param error_class - the BACnet error class * @param error_class - the BACnet error class
* @param error_code - BACnet Error code * @param error_code - BACnet Error code
* *
@@ -592,7 +589,7 @@ bool Binary_Value_Object_Name(
if (pObject) { if (pObject) {
if (pObject->Object_Name == NULL) { if (pObject->Object_Name == NULL) {
snprintf( snprintf(
text, sizeof(text), "BINARY INPUT %lu", text, sizeof(text), "BINARY VALUE %lu",
(unsigned long)object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, text); status = characterstring_init_ansi(object_name, text);
} else { } else {
@@ -1273,7 +1270,7 @@ void Binary_Value_Write_Disable(uint32_t object_instance)
} }
/** /**
* @brief Creates a Binary Output object * @brief Creates a Binary Value object
* @param object_instance - object-instance number of the object * @param object_instance - object-instance number of the object
* @return the object-instance that was created, or BACNET_MAX_INSTANCE * @return the object-instance that was created, or BACNET_MAX_INSTANCE
*/ */
@@ -1345,7 +1342,7 @@ uint32_t Binary_Value_Create(uint32_t object_instance)
} }
/** /**
* Initializes the Binary Input object data * Deletes the Binary Value object data
*/ */
void Binary_Value_Cleanup(void) void Binary_Value_Cleanup(void)
{ {
@@ -1364,7 +1361,7 @@ void Binary_Value_Cleanup(void)
} }
/** /**
* Creates a Binary Input object * Deletes a Binary Value object
*/ */
bool Binary_Value_Delete(uint32_t object_instance) bool Binary_Value_Delete(uint32_t object_instance)
{ {
@@ -1381,7 +1378,7 @@ bool Binary_Value_Delete(uint32_t object_instance)
} }
/** /**
* Initializes the Binary Input object data * Initializes the Binary Value object data
*/ */
void Binary_Value_Init(void) void Binary_Value_Init(void)
{ {
@@ -1747,7 +1744,7 @@ int Binary_Value_Alarm_Summary(
struct object_data *pObject = Binary_Value_Object_Index(index); struct object_data *pObject = Binary_Value_Object_Index(index);
if (getalarm_data == NULL) { if (getalarm_data == NULL) {
PRINT( debug_printf(
"[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__, "[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__,
__LINE__, (void *)getalarm_data); __LINE__, (void *)getalarm_data);
return -2; return -2;
@@ -1942,7 +1939,8 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
pObject->Ack_notify_data.bSendAckNotify = false; pObject->Ack_notify_data.bSendAckNotify = false;
/* copy toState */ /* copy toState */
ToState = pObject->Ack_notify_data.EventState; ToState = pObject->Ack_notify_data.EventState;
PRINT("Binary-Input[%d]: Send AckNotification.\n", object_instance); debug_printf(
"Binary-Value[%d]: Send AckNotification.\n", object_instance);
characterstring_init_ansi(&msgText, "AckNotification"); characterstring_init_ansi(&msgText, "AckNotification");
/* Notify Type */ /* Notify Type */
@@ -2022,8 +2020,8 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
default: default:
break; break;
} /* switch (ToState) */ } /* switch (ToState) */
PRINT( debug_printf(
"Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n", "Binary-Value[%d]: Event_State goes from %.128s to %.128s.\n",
object_instance, bactext_event_state_name(FromState), object_instance, bactext_event_state_name(FromState),
bactext_event_state_name(ToState)); bactext_event_state_name(ToState));
/* Notify Type */ /* Notify Type */
@@ -2135,7 +2133,7 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
} }
/* add data from notification class */ /* add data from notification class */
PRINT( debug_printf(
"Binary-Value[%d]: Notification Class[%d]-%s " "Binary-Value[%d]: Notification Class[%d]-%s "
"%u/%u/%u-%u:%u:%u.%u!\n", "%u/%u/%u-%u:%u:%u.%u!\n",
object_instance, event_data.notificationClass, object_instance, event_data.notificationClass,
@@ -2152,7 +2150,7 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Ack required */ /* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) { (event_data.ackRequired == true)) {
PRINT("Binary-Value[%d]: Ack Required!\n", object_instance); debug_printf("Binary-Value[%d]: Ack Required!\n", object_instance);
switch (event_data.toState) { switch (event_data.toState) {
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL] pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL]
+3 -4
View File
@@ -20,14 +20,13 @@
#include "bacnet/bacapp.h" #include "bacnet/bacapp.h"
#include "bacnet/bactext.h" #include "bacnet/bactext.h"
#include "bacnet/proplist.h" #include "bacnet/proplist.h"
/* basic objects and services */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/sys/keylist.h"
/* me! */ /* me! */
#include "bacnet/basic/object/iv.h" #include "bacnet/basic/object/iv.h"
#include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/debug.h"
#define PRINTF debug_perror
/* Key List for storing the object data sorted by instance number */ /* Key List for storing the object data sorted by instance number */
static OS_Keylist Object_List = NULL; static OS_Keylist Object_List = NULL;
+4 -5
View File
@@ -19,6 +19,7 @@
#include "bacnet/datetime.h" #include "bacnet/datetime.h"
#include "bacnet/event.h" #include "bacnet/event.h"
#include "bacnet/wp.h" #include "bacnet/wp.h"
/* basic objects and services */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/nc.h" #include "bacnet/basic/object/nc.h"
#include "bacnet/basic/binding/address.h" #include "bacnet/basic/binding/address.h"
@@ -27,8 +28,6 @@
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
#define PRINTF debug_perror
#ifndef MAX_NOTIFICATION_CLASSES #ifndef MAX_NOTIFICATION_CLASSES
#define MAX_NOTIFICATION_CLASSES 2 #define MAX_NOTIFICATION_CLASSES 2
#endif #endif
@@ -682,7 +681,7 @@ void Notification_Class_common_reporting_function(
} }
/* send notifications for active recipients */ /* send notifications for active recipients */
PRINTF( debug_printf_stderr(
"Notification Class[%u]: send notifications\n", "Notification Class[%u]: send notifications\n",
event_data->notificationClass); event_data->notificationClass);
/* pointer to first recipient */ /* pointer to first recipient */
@@ -703,7 +702,7 @@ void Notification_Class_common_reporting_function(
if (pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_DEVICE) { if (pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_DEVICE) {
/* send notification to the specified device */ /* send notification to the specified device */
device_id = pBacDest->Recipient.type.device.instance; device_id = pBacDest->Recipient.type.device.instance;
PRINTF( debug_printf_stderr(
"Notification Class[%u]: send notification to %u\n", "Notification Class[%u]: send notification to %u\n",
event_data->notificationClass, (unsigned)device_id); event_data->notificationClass, (unsigned)device_id);
if (pBacDest->ConfirmedNotify == true) { if (pBacDest->ConfirmedNotify == true) {
@@ -713,7 +712,7 @@ void Notification_Class_common_reporting_function(
} }
} else if ( } else if (
pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_ADDRESS) { pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_ADDRESS) {
PRINTF( debug_printf_stderr(
"Notification Class[%u]: send notification to ADDR\n", "Notification Class[%u]: send notification to ADDR\n",
event_data->notificationClass); event_data->notificationClass);
/* send notification to the address indicated */ /* send notification to the address indicated */
+21 -53
View File
@@ -11,7 +11,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -22,9 +21,11 @@
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/alarm_ack.h" #include "bacnet/alarm_ack.h"
#include "bacnet/reject.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
@@ -64,9 +65,7 @@ void handler_alarm_ack(
{ {
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0; int bytes_sent = 0;
#endif
int ack_result = 0; int ack_result = 0;
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
@@ -75,51 +74,43 @@ void handler_alarm_ack(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("Alarm Ack: Missing Required Parameter. Sending Reject!\n");
goto AA_ABORT;
} else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("Alarm Ack: Segmented message. Sending Abort!\n");
fprintf(stderr, "Alarm Ack: Segmented message. Sending Abort!\n");
#endif
goto AA_ABORT; goto AA_ABORT;
} }
len = alarm_ack_decode_service_request(service_request, service_len, &data); len = alarm_ack_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
fprintf(stderr, "Alarm Ack: Unable to decode Request!\n"); debug_print("Alarm Ack: Unable to decode Request!\n");
} }
#endif
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* bad decoding - send an abort */
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("Alarm Ack: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "Alarm Ack: Bad Encoding. Sending Abort!\n");
#endif
goto AA_ABORT; goto AA_ABORT;
} }
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, stderr,
"Alarm Ack Operation: Received acknowledge for object id (%d, %lu) " "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) "
"from %s for process id %lu \n", "from %s for process id %lu \n",
data.eventObjectIdentifier.type, data.eventObjectIdentifier.type,
(unsigned long)data.eventObjectIdentifier.instance, (unsigned long)data.eventObjectIdentifier.instance,
data.ackSource.value, (unsigned long)data.ackProcessIdentifier); data.ackSource.value, (unsigned long)data.ackProcessIdentifier);
#endif
/* BACnet Testing Observed Incident oi00105
ACK of a non-existent object returned the incorrect error code
Revealed by BACnet Test Client v1.8.16 (
www.bac-test.com/bacnet-test-client-download ) BC 135.1: 9.1.3.3-A Any
discussions can be directed to edward@bac-test.com */
if (!Device_Valid_Object_Id( if (!Device_Valid_Object_Id(
data.eventObjectIdentifier.type, data.eventObjectIdentifier.type,
data.eventObjectIdentifier.instance)) { data.eventObjectIdentifier.instance)) {
@@ -130,18 +121,12 @@ void handler_alarm_ack(
} else if (Alarm_Ack[data.eventObjectIdentifier.type]) { } else if (Alarm_Ack[data.eventObjectIdentifier.type]) {
ack_result = ack_result =
Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code); Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code);
switch (ack_result) { switch (ack_result) {
case 1: case 1:
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM);
#if PRINT_ENABLED debug_print("Alarm Acknowledge: Sending Simple Ack!\n");
fprintf(
stderr,
"Alarm Acknowledge: "
"Sending Simple Ack!\n");
#endif
break; break;
case -1: case -1:
@@ -149,20 +134,16 @@ void handler_alarm_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
error_code); error_code);
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, "Alarm Acknowledge: error %s!\n", stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
#endif
break; break;
default: default:
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("Alarm Acknowledge: abort other!\n");
fprintf(stderr, "Alarm Acknowledge: abort other!\n");
#endif
break; break;
} }
} else { } else {
@@ -170,29 +151,16 @@ void handler_alarm_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
ERROR_CODE_NO_ALARM_CONFIGURED); ERROR_CODE_NO_ALARM_CONFIGURED);
#if PRINT_ENABLED debug_print("Alarm Acknowledge: No Alarm Configured!\n");
fprintf(
stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED));
#endif
} }
AA_ABORT: AA_ABORT:
pdu_len += len; pdu_len += len;
#if PRINT_ENABLED bytes_sent = datalink_send_pdu(
bytes_sent = src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#endif
datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf( debug_perror("Alarm Acknowledge: Failed to send PDU");
stderr,
"Alarm Acknowledge: "
"Failed to send PDU (%s)!\n",
strerror(errno));
} }
#endif
return; return;
} }
+20 -25
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -18,6 +17,7 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/arf.h" #include "bacnet/arf.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#if defined(BACFILE) #if defined(BACFILE)
@@ -25,6 +25,7 @@
#endif #endif
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/* /*
@@ -100,16 +101,20 @@ void handler_atomic_read_file(
#endif #endif
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("ARF: Missing Required Parameter. Sending Reject!\n");
goto ARF_ABORT;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("ARF: Segmented Message. Sending Abort!\n");
fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n");
#endif
goto ARF_ABORT; goto ARF_ABORT;
} }
len = arf_decode_service_request(service_request, service_len, &data); len = arf_decode_service_request(service_request, service_len, &data);
@@ -118,9 +123,7 @@ void handler_atomic_read_file(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("ARF: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
goto ARF_ABORT; goto ARF_ABORT;
} }
if (data.object_type == OBJECT_FILE) { if (data.object_type == OBJECT_FILE) {
@@ -130,12 +133,10 @@ void handler_atomic_read_file(
if (data.type.stream.requestedOctetCount <= if (data.type.stream.requestedOctetCount <=
octetstring_capacity(&data.fileData[0])) { octetstring_capacity(&data.fileData[0])) {
bacfile_read_stream_data(&data); bacfile_read_stream_data(&data);
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, "ARF: Stream offset %d, %d octets.\n", stderr, "ARF: Stream offset %d, %d octets.\n",
(int)data.type.stream.fileStartPosition, (int)data.type.stream.fileStartPosition,
(int)data.type.stream.requestedOctetCount); (int)data.type.stream.requestedOctetCount);
#endif
len = arf_ack_encode_apdu( len = arf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
@@ -143,12 +144,12 @@ void handler_atomic_read_file(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_fprintf(
fprintf( stderr,
stderr, "Too Big To Send (%d >= %d). Sending Abort!\n", "ARF: Too Big To Send (%d >= %d). "
"Sending Abort!\n",
(int)data.type.stream.requestedOctetCount, (int)data.type.stream.requestedOctetCount,
(int)octetstring_capacity(&data.fileData[0])); (int)octetstring_capacity(&data.fileData[0]));
#endif
} }
} else if (data.access == FILE_RECORD_ACCESS) { } else if (data.access == FILE_RECORD_ACCESS) {
if (data.type.record.fileStartRecord >= if (data.type.record.fileStartRecord >=
@@ -157,12 +158,10 @@ void handler_atomic_read_file(
error_code = ERROR_CODE_INVALID_FILE_START_POSITION; error_code = ERROR_CODE_INVALID_FILE_START_POSITION;
error = true; error = true;
} else if (bacfile_read_stream_data(&data)) { } else if (bacfile_read_stream_data(&data)) {
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, "ARF: fileStartRecord %d, %u RecordCount.\n", stderr, "ARF: fileStartRecord %d, %u RecordCount.\n",
(int)data.type.record.fileStartRecord, (int)data.type.record.fileStartRecord,
(unsigned)data.type.record.RecordCount); (unsigned)data.type.record.RecordCount);
#endif
len = arf_ack_encode_apdu( len = arf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
@@ -175,9 +174,7 @@ void handler_atomic_read_file(
error = true; error = true;
error_class = ERROR_CLASS_SERVICES; error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD; error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD;
#if PRINT_ENABLED debug_print("ARF: Record Access Requested. Sending Error!\n");
fprintf(stderr, "Record Access Requested. Sending Error!\n");
#endif
} }
} else { } else {
error = true; error = true;
@@ -193,11 +190,9 @@ ARF_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); debug_perror("ARF: Failed to send PDU");
} }
#endif
return; return;
} }
+17 -24
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -19,11 +18,13 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/awf.h" #include "bacnet/awf.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
#if defined(BACFILE) #if defined(BACFILE)
#include "bacnet/basic/object/bacfile.h" #include "bacnet/basic/object/bacfile.h"
@@ -75,21 +76,23 @@ void handler_atomic_write_file(
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
#if PRINT_ENABLED debug_print("Received AtomicWriteFile Request!\n");
fprintf(stderr, "Received AtomicWriteFile Request!\n");
#endif
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("AWF: Missing Required Parameter. Sending Reject!\n");
goto AWF_ABORT;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("AWF:Segmented Message. Sending Abort!\n");
fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif
goto AWF_ABORT; goto AWF_ABORT;
} }
len = awf_decode_service_request(service_request, service_len, &data); len = awf_decode_service_request(service_request, service_len, &data);
@@ -98,9 +101,7 @@ void handler_atomic_write_file(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("AWF: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
goto AWF_ABORT; goto AWF_ABORT;
} }
if (data.object_type == OBJECT_FILE) { if (data.object_type == OBJECT_FILE) {
@@ -108,12 +109,10 @@ void handler_atomic_write_file(
error = true; error = true;
} else if (data.access == FILE_STREAM_ACCESS) { } else if (data.access == FILE_STREAM_ACCESS) {
if (bacfile_write_stream_data(&data)) { if (bacfile_write_stream_data(&data)) {
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, "AWF: Stream offset %d, %d bytes\n", stderr, "AWF: Stream offset %d, %d bytes\n",
data.type.stream.fileStartPosition, data.type.stream.fileStartPosition,
(int)octetstring_length(&data.fileData[0])); (int)octetstring_length(&data.fileData[0]));
#endif
len = awf_ack_encode_apdu( len = awf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
@@ -124,12 +123,10 @@ void handler_atomic_write_file(
} }
} else if (data.access == FILE_RECORD_ACCESS) { } else if (data.access == FILE_RECORD_ACCESS) {
if (bacfile_write_record_data(&data)) { if (bacfile_write_record_data(&data)) {
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, "AWF: StartRecord %d, RecordCount %u\n", stderr, "AWF: StartRecord %d, RecordCount %u\n",
data.type.record.fileStartRecord, data.type.record.fileStartRecord,
data.type.record.returnedRecordCount); data.type.record.returnedRecordCount);
#endif
len = awf_ack_encode_apdu( len = awf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
@@ -142,9 +139,7 @@ void handler_atomic_write_file(
error = true; error = true;
error_class = ERROR_CLASS_SERVICES; error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD; error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD;
#if PRINT_ENABLED debug_print("AWF: Record Access Requested. Sending Error!\n");
fprintf(stderr, "Record Access Requested. Sending Error!\n");
#endif
} }
} else { } else {
error = true; error = true;
@@ -160,11 +155,9 @@ AWF_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); debug_perror("AWF: Failed to send PDU\n");
} }
#endif
return; return;
} }
+49 -36
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -17,6 +16,7 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/cov.h" #include "bacnet/cov.h"
#include "bacnet/bactext.h" #include "bacnet/bactext.h"
/* basic services, TSM, and datalink */ /* basic services, TSM, and datalink */
@@ -25,8 +25,6 @@
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/sys/debug.h"
#define PRINTF debug_perror
/* max number of COV properties decoded in a COV notification */ /* max number of COV properties decoded in a COV notification */
#ifndef MAX_COV_PROPERTIES #ifndef MAX_COV_PROPERTIES
#define MAX_COV_PROPERTIES 2 #define MAX_COV_PROPERTIES 2
@@ -74,6 +72,41 @@ void handler_ccov_notification_add(BACNET_COV_NOTIFICATION *cb)
} while (head); } while (head);
} }
/**
* @brief Print ConfirmedCOVNotification data
* @param cov_data - data decoded from the COV notification
*/
void handler_ccov_data_print(BACNET_COV_DATA *cov_data)
{
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
debug_printf_stderr("CCOV: PID=%u ", cov_data->subscriberProcessIdentifier);
debug_printf_stderr("instance=%u ", cov_data->initiatingDeviceIdentifier);
debug_printf_stderr(
"%s %u ",
bactext_object_type_name(cov_data->monitoredObjectIdentifier.type),
cov_data->monitoredObjectIdentifier.instance);
debug_printf_stderr("time remaining=%u seconds ", cov_data->timeRemaining);
debug_printf_stderr("\n");
pProperty_value = cov_data->listOfValues;
while (pProperty_value) {
debug_printf_stderr("CCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
debug_printf_stderr(
"%s ",
bactext_property_name(pProperty_value->propertyIdentifier));
} else {
debug_printf_stderr(
"proprietary %u ", pProperty_value->propertyIdentifier);
}
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
debug_printf_stderr("%u ", pProperty_value->propertyArrayIndex);
}
debug_printf_stderr("\n");
pProperty_value = pProperty_value->next;
}
}
/* */ /* */
/** Handler for an Confirmed COV Notification. /** Handler for an Confirmed COV Notification.
* @ingroup DSCOV * @ingroup DSCOV
@@ -97,7 +130,6 @@ void handler_ccov_notification(
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
BACNET_COV_DATA cov_data; BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES]; BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
int bytes_sent = 0; int bytes_sent = 0;
@@ -109,15 +141,21 @@ void handler_ccov_notification(
cov_data.listOfValues = &property_value[0]; cov_data.listOfValues = &property_value[0];
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
PRINTF("CCOV: Received Notification!\n"); debug_print("CCOV: Received Notification!\n");
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("CCOV: Missing Required Parameter. Sending Reject!\n");
goto CCOV_ABORT;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
PRINTF("CCOV: Segmented message. Sending Abort!\n"); debug_print("CCOV: Segmented message. Sending Abort!\n");
goto CCOV_ABORT; goto CCOV_ABORT;
} }
/* decode the service request only */ /* decode the service request only */
@@ -125,52 +163,27 @@ void handler_ccov_notification(
service_request, service_len, &cov_data); service_request, service_len, &cov_data);
if (len > 0) { if (len > 0) {
handler_ccov_notification_callback(&cov_data); handler_ccov_notification_callback(&cov_data);
PRINTF("CCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
PRINTF("instance=%u ", cov_data.initiatingDeviceIdentifier);
PRINTF(
"%s %u ",
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
cov_data.monitoredObjectIdentifier.instance);
PRINTF("time remaining=%u seconds ", cov_data.timeRemaining);
PRINTF("\n");
pProperty_value = &property_value[0];
while (pProperty_value) {
PRINTF("CCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
PRINTF(
"%s ",
bactext_property_name(pProperty_value->propertyIdentifier));
} else {
PRINTF("proprietary %u ", pProperty_value->propertyIdentifier);
}
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
PRINTF("%u ", pProperty_value->propertyArrayIndex);
}
PRINTF("\n");
pProperty_value = pProperty_value->next;
}
} }
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { if (len <= 0) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
PRINTF("CCOV: Bad Encoding. Sending Abort!\n"); debug_print("CCOV: Bad Encoding. Sending Abort!\n");
goto CCOV_ABORT; goto CCOV_ABORT;
} else { } else {
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_COV_NOTIFICATION); SERVICE_CONFIRMED_COV_NOTIFICATION);
PRINTF("CCOV: Sending Simple Ack!\n"); debug_print("CCOV: Sending Simple Ack!\n");
} }
CCOV_ABORT: CCOV_ABORT:
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
PRINTF("CCOV: Failed to send PDU (%s)!\n", strerror(errno)); debug_perror("CCOV: Failed to send PDU");
} }
(void)bytes_sent;
return; return;
} }
+3
View File
@@ -23,6 +23,9 @@ extern "C" {
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void handler_ccov_notification_add(BACNET_COV_NOTIFICATION *callback); void handler_ccov_notification_add(BACNET_COV_NOTIFICATION *callback);
BACNET_STACK_EXPORT
void handler_ccov_data_print(BACNET_COV_DATA *cov_data);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void handler_ccov_notification( void handler_ccov_notification(
uint8_t *service_request, uint8_t *service_request,
+16 -30
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -29,6 +28,7 @@
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
#ifndef MAX_COV_PROPERTIES #ifndef MAX_COV_PROPERTIES
@@ -820,24 +820,25 @@ void handler_cov_subscribe(
cov_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; cov_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
npdu_len = npdu_encode_pdu( npdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
len = BACNET_STATUS_REJECT;
cov_data.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
debug_print("CCOV: Missing Required Parameter. Sending Reject!\n");
error = true;
} else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED debug_print("SubscribeCOV: Segmented message. Sending Abort!\n");
fprintf(stderr, "SubscribeCOV: Segmented message. Sending Abort!\n");
#endif
error = true; error = true;
} else { } else {
len = cov_subscribe_decode_service_request( len = cov_subscribe_decode_service_request(
service_request, service_len, &cov_data); service_request, service_len, &cov_data);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n"); debug_print("SubscribeCOV: Unable to decode Request!\n");
} }
#endif
if (len < 0) { if (len < 0) {
error = true; error = true;
} else { } else {
@@ -849,54 +850,39 @@ void handler_cov_subscribe(
apdu_len = encode_simple_ack( apdu_len = encode_simple_ack(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_SUBSCRIBE_COV); SERVICE_CONFIRMED_SUBSCRIBE_COV);
#if PRINT_ENABLED debug_print("SubscribeCOV: Sending Simple Ack!\n");
fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n");
#endif
} else { } else {
len = BACNET_STATUS_ERROR; len = BACNET_STATUS_ERROR;
error = true; error = true;
#if PRINT_ENABLED debug_print("SubscribeCOV: Sending Error!\n");
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
#endif
} }
} }
} }
/* Error? */ /* Error? */
if (error) { if (error) {
if (len == BACNET_STATUS_ABORT) { if (len == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu( apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(cov_data.error_code), true); abort_convert_error_code(cov_data.error_code), true);
#if PRINT_ENABLED debug_print("SubscribeCOV: Sending Abort!\n");
fprintf(stderr, "SubscribeCOV: Sending Abort!\n");
#endif
} else if (len == BACNET_STATUS_ERROR) { } else if (len == BACNET_STATUS_ERROR) {
apdu_len = bacerror_encode_apdu( apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_SUBSCRIBE_COV, cov_data.error_class, SERVICE_CONFIRMED_SUBSCRIBE_COV, cov_data.error_class,
cov_data.error_code); cov_data.error_code);
#if PRINT_ENABLED debug_print("SubscribeCOV: Sending Error!\n");
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
#endif
} else if (len == BACNET_STATUS_REJECT) { } else if (len == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu( apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(cov_data.error_code)); reject_convert_error_code(cov_data.error_code));
#if PRINT_ENABLED debug_print("SubscribeCOV: Sending Reject!\n");
fprintf(stderr, "SubscribeCOV: Sending Reject!\n");
#endif
} }
} }
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED debug_perror("SubscribeCOV: Failed to send PDU");
fprintf(
stderr, "SubscribeCOV: Failed to send PDU (%s)!\n",
strerror(errno));
#endif
} }
return; return;
+18 -13
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -60,15 +59,22 @@ void handler_create_object(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("CreateObject: Received Request!\n"); debug_print("CreateObject: Received Request!\n");
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print(
"CreateObject: Missing Required Parameter. Sending Reject!\n");
status = false;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("CreateObject: Segmented message. Sending Abort!\n"); debug_print("CreateObject: Segmented message. Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -76,12 +82,12 @@ void handler_create_object(
len = create_object_decode_service_request( len = create_object_decode_service_request(
service_request, service_len, &data); service_request, service_len, &data);
if (len > 0) { if (len > 0) {
debug_perror( debug_printf_stderr(
"CreateObject: type=%lu instance=%lu\n", "CreateObject: type=%lu instance=%lu\n",
(unsigned long)data.object_type, (unsigned long)data.object_type,
(unsigned long)data.object_instance); (unsigned long)data.object_instance);
} else { } else {
debug_perror("CreateObject: Unable to decode request!\n"); debug_print("CreateObject: Unable to decode request!\n");
} }
if (len <= 0) { if (len <= 0) {
/* bad decoding or something we didn't understand */ /* bad decoding or something we didn't understand */
@@ -89,24 +95,24 @@ void handler_create_object(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
abort_convert_error_code(data.error_code), true); abort_convert_error_code(data.error_code), true);
debug_perror("CreateObject: Sending Abort!\n"); debug_print("CreateObject: Sending Abort!\n");
} else if (len == BACNET_STATUS_REJECT) { } else if (len == BACNET_STATUS_REJECT) {
len = reject_encode_apdu( len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
reject_convert_error_code(data.error_code)); reject_convert_error_code(data.error_code));
debug_perror("CreateObject: Sending Reject!\n"); debug_print("CreateObject: Sending Reject!\n");
} }
} else { } else {
if (Device_Create_Object(&data)) { if (Device_Create_Object(&data)) {
len = create_object_ack_encode( len = create_object_ack_encode(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
debug_perror("CreateObject: Sending ACK!\n"); debug_print("CreateObject: Sending ACK!\n");
} else { } else {
len = create_object_error_ack_encode( len = create_object_error_ack_encode(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
debug_perror("CreateObject: Sending Error!\n"); debug_print("CreateObject: Sending Error!\n");
} }
} }
} }
@@ -117,8 +123,7 @@ void handler_create_object(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
} }
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
debug_perror( debug_perror("CreateObject: Failed to send PDU");
"CreateObject: Failed to send PDU (%s)!\n", strerror(errno));
} }
return; return;
+25 -62
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h" #include "bacnet/bacdcode.h"
#include "bacnet/bacerror.h" #include "bacnet/bacerror.h"
@@ -22,6 +21,7 @@
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/* The byte length of a UTF-8 character can vary. /* The byte length of a UTF-8 character can vary.
@@ -97,47 +97,36 @@ void handler_device_communication_control(
/* encode the NPDU portion of the reply packet */ /* encode the NPDU portion of the reply packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
#if PRINT_ENABLED debug_print("DeviceCommunicationControl!\n");
fprintf(stderr, "DeviceCommunicationControl!\n"); if (service_len == 0) {
#endif
if (service_data->segmented_message) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(
stderr,
"DeviceCommunicationControl: "
"Sending Abort - segmented message.\n");
#endif
goto DCC_FAILURE;
}
if (!service_request || service_len == 0) {
len = reject_encode_apdu( len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER); REJECT_REASON_MISSING_REQUIRED_PARAMETER);
#if PRINT_ENABLED debug_print("DeviceCommunicationControl: "
fprintf(stderr, "DCC: Sending Reject!\n"); "Missing Required Parameter. Sending Reject!\n");
#endif goto DCC_FAILURE;
} else if (service_data->segmented_message) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_print("DeviceCommunicationControl: "
"Sending Abort - segmented message.\n");
goto DCC_FAILURE; goto DCC_FAILURE;
} }
/* decode the service request only */ /* decode the service request only */
len = dcc_decode_service_request( len = dcc_decode_service_request(
service_request, service_len, &timeDuration, &state, &password); service_request, service_len, &timeDuration, &state, &password);
#if PRINT_ENABLED
if (len > 0) { if (len > 0) {
fprintf( debug_fprintf(
stderr, stderr,
"DeviceCommunicationControl: " "DeviceCommunicationControl: "
"timeout=%u state=%u password=%s\n", "timeout=%u state=%u password=%s\n",
(unsigned)timeDuration, (unsigned)state, (unsigned)timeDuration, (unsigned)state,
characterstring_value(&password)); characterstring_value(&password));
} }
#endif
/* bad decoding or invalid service parameter /* bad decoding or invalid service parameter
send an abort or reject */ send an abort or reject */
if (len < 0) { if (len < 0) {
@@ -145,16 +134,12 @@ void handler_device_communication_control(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("DCC: Sending Abort!\n");
fprintf(stderr, "DCC: Sending Abort!\n");
#endif
} else if (len == BACNET_STATUS_REJECT) { } else if (len == BACNET_STATUS_REJECT) {
len = reject_encode_apdu( len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_PARAMETER_OUT_OF_RANGE); REJECT_REASON_PARAMETER_OUT_OF_RANGE);
#if PRINT_ENABLED debug_print("DCC: Sending Reject!\n");
fprintf(stderr, "DCC: Sending Reject!\n");
#endif
} }
goto DCC_FAILURE; goto DCC_FAILURE;
} }
@@ -167,12 +152,8 @@ void handler_device_communication_control(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SERVICES, ERROR_CODE_SERVICE_REQUEST_DENIED); ERROR_CLASS_SERVICES, ERROR_CODE_SERVICE_REQUEST_DENIED);
#if PRINT_ENABLED debug_print("DeviceCommunicationControl: "
fprintf( "Sending Error - DISABLE has been deprecated.\n");
stderr,
"DeviceCommunicationControl: "
"Sending Error - DISABLE has been deprecated.\n");
#endif
goto DCC_FAILURE; goto DCC_FAILURE;
} }
#endif #endif
@@ -180,12 +161,8 @@ void handler_device_communication_control(
len = reject_encode_apdu( len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_UNDEFINED_ENUMERATION); REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED debug_print("DeviceCommunicationControl: "
fprintf( "Sending Reject - undefined enumeration\n");
stderr,
"DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n");
#endif
} else { } else {
#ifdef BAC_ROUTING #ifdef BAC_ROUTING
/* Check to see if the current Device supports this service. */ /* Check to see if the current Device supports this service. */
@@ -201,24 +178,16 @@ void handler_device_communication_control(
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED debug_print("DeviceCommunicationControl: "
fprintf( "Sending Simple Ack!\n");
stderr,
"DeviceCommunicationControl: "
"Sending Simple Ack!\n");
#endif
dcc_set_status_duration(state, timeDuration); dcc_set_status_duration(state, timeDuration);
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SECURITY, ERROR_CODE_PASSWORD_FAILURE); ERROR_CLASS_SECURITY, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED debug_print("DeviceCommunicationControl: "
fprintf( "Sending Error - password failure.\n");
stderr,
"DeviceCommunicationControl: "
"Sending Error - password failure.\n");
#endif
} }
} }
DCC_FAILURE: DCC_FAILURE:
@@ -226,13 +195,7 @@ DCC_FAILURE:
len = datalink_send_pdu( len = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (len <= 0) { if (len <= 0) {
#if PRINT_ENABLED debug_perror("DeviceCommunicationControl: Failed to send PDU");
fprintf(
stderr,
"DeviceCommunicationControl: "
"Failed to send PDU (%s)!\n",
strerror(errno));
#endif
} }
return; return;
+18 -12
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -60,15 +59,23 @@ void handler_delete_object(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("DeleteObject: Received Request!\n"); debug_print("DeleteObject: Received Request!\n");
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("DeleteObject: Missing Required Parameter. "
"Sending Reject!\n");
status = false;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("DeleteObject: Segmented message. Sending Abort!\n"); debug_print("DeleteObject: Segmented message. "
"Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -76,19 +83,19 @@ void handler_delete_object(
len = delete_object_decode_service_request( len = delete_object_decode_service_request(
service_request, service_len, &data); service_request, service_len, &data);
if (len > 0) { if (len > 0) {
debug_perror( debug_printf_stderr(
"DeleteObject: type=%lu instance=%lu\n", "DeleteObject: type=%lu instance=%lu\n",
(unsigned long)data.object_type, (unsigned long)data.object_type,
(unsigned long)data.object_instance); (unsigned long)data.object_instance);
} else { } else {
debug_perror("DeleteObject: Unable to decode request!\n"); debug_print("DeleteObject: Unable to decode request!\n");
} }
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { if (len <= 0) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
debug_perror("DeleteObject: Bad Encoding. Sending Abort!\n"); debug_print("DeleteObject: Bad Encoding. Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -96,13 +103,13 @@ void handler_delete_object(
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DELETE_OBJECT); SERVICE_CONFIRMED_DELETE_OBJECT);
debug_perror("DeleteObject: Sending Simple Ack!\n"); debug_print("DeleteObject: Sending Simple Ack!\n");
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DELETE_OBJECT, data.error_class, SERVICE_CONFIRMED_DELETE_OBJECT, data.error_class,
data.error_code); data.error_code);
debug_perror("DeleteObject: Sending Error!\n"); debug_print("DeleteObject: Sending Error!\n");
} }
} }
} }
@@ -113,8 +120,7 @@ void handler_delete_object(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
} }
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
debug_perror( debug_perror("DeleteObject: Failed to send PDU");
"DeleteObject: Failed to send PDU (%s)!\n", strerror(errno));
} }
return; return;
+17 -24
View File
@@ -17,9 +17,11 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
/* basic services, TSM, and datalink */ /* basic services, TSM, and datalink */
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
static get_alarm_summary_function Get_Alarm_Summary[MAX_BACNET_OBJECT_TYPE]; static get_alarm_summary_function Get_Alarm_Summary[MAX_BACNET_OBJECT_TYPE];
@@ -54,20 +56,25 @@ void handler_get_alarm_summary(
(void)service_len; (void)service_len;
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("GetAlarmSummary: Missing Required Parameter. "
"Sending Reject!\n");
goto GET_ALARM_SUMMARY_ABORT;
} else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
apdu_len = abort_encode_apdu( apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("GetAlarmSummary: Segmented message. "
fprintf(stderr, "GetAlarmSummary: Segmented message. Sending Abort!\n"); "Sending Abort!\n");
#endif
goto GET_ALARM_SUMMARY_ABORT; goto GET_ALARM_SUMMARY_ABORT;
} }
/* init header */ /* init header */
apdu_len = get_alarm_summary_ack_encode_apdu_init( apdu_len = get_alarm_summary_ack_encode_apdu_init(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id); &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id);
@@ -92,11 +99,7 @@ void handler_get_alarm_summary(
} }
} }
} }
debug_print("GetAlarmSummary: Sending response!\n");
#if PRINT_ENABLED
fprintf(stderr, "GetAlarmSummary: Sending response!\n");
#endif
GET_ALARM_SUMMARY_ERROR: GET_ALARM_SUMMARY_ERROR:
if (error) { if (error) {
if (len == BACNET_STATUS_ABORT) { if (len == BACNET_STATUS_ABORT) {
@@ -104,32 +107,22 @@ GET_ALARM_SUMMARY_ERROR:
apdu_len = abort_encode_apdu( apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("GetAlarmSummary: Reply too big to fit into APDU!\n");
fprintf(
stderr, "GetAlarmSummary: Reply too big to fit into APDU!\n");
#endif
} else { } else {
apdu_len = bacerror_encode_apdu( apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_GET_ALARM_SUMMARY, ERROR_CLASS_PROPERTY, SERVICE_CONFIRMED_GET_ALARM_SUMMARY, ERROR_CLASS_PROPERTY,
ERROR_CODE_OTHER); ERROR_CODE_OTHER);
#if PRINT_ENABLED debug_print("GetAlarmSummary: Sending Error!\n");
fprintf(stderr, "GetAlarmSummary: Sending Error!\n");
#endif
} }
} }
GET_ALARM_SUMMARY_ABORT: GET_ALARM_SUMMARY_ABORT:
pdu_len += apdu_len; pdu_len += apdu_len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
/*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */ debug_perror("GetAlarmSummary: Failed to send PDU");
} }
#else
(void)bytes_sent;
#endif
return; return;
} }
+36 -35
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -18,17 +17,22 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/event.h" #include "bacnet/event.h"
#include "bacnet/getevent.h" #include "bacnet/getevent.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE]; static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE];
/** print eventState /**
* @brief print the data for a GetEventInformation service request
* @param data [in] The data to print
* @param device_id [in] The device id to print
*/ */
void ge_ack_print_data( void ge_ack_print_data(
BACNET_GET_EVENT_INFORMATION_DATA *data, uint32_t device_id) BACNET_GET_EVENT_INFORMATION_DATA *data, uint32_t device_id)
@@ -48,6 +52,11 @@ void ge_ack_print_data(
printf("\n%u\t Total\n", count); printf("\n%u\t Total\n", count);
} }
/**
* @brief Set the handler for the GetEventInformation service.
* @param object_type [in] The BACNET_OBJECT_TYPE to set the handler for.
* @param pFunction [in] The handler function to set.
*/
void handler_get_event_information_set( void handler_get_event_information_set(
BACNET_OBJECT_TYPE object_type, get_event_info_function pFunction) BACNET_OBJECT_TYPE object_type, get_event_info_function pFunction)
{ {
@@ -56,6 +65,19 @@ void handler_get_event_information_set(
} }
} }
/**
* @brief Handle a GetEventInformation service request.
* @details The GetEventInformation service is used by a client BACnet-user to
* obtain a summary of all "active event states". The term "active event states"
* refers to all event-initiating objects that have an Event_State property
* whose value is not equal to NORMAL,
* or have an Acked_Transitions property, which has at least one of the bits
* (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE.
* @param service_request [in] The contents of the service request.
* @param service_len [in] The length of the service_request.
* @param src [in] BACNET_ADDRESS of the source of the message
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
*/
void handler_get_event_information( void handler_get_event_information(
uint8_t *service_request, uint8_t *service_request,
uint16_t service_len, uint16_t service_len,
@@ -68,9 +90,7 @@ void handler_get_event_information(
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
bool error = false; bool error = false;
bool more_events = false; bool more_events = false;
#if PRINT_ENABLED
int bytes_sent = 0; int bytes_sent = 0;
#endif
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
@@ -84,7 +104,7 @@ void handler_get_event_information(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_data->segmented_message) {
@@ -92,15 +112,10 @@ void handler_get_event_information(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("GetEventInformation: "
fprintf( "Segmented message. Sending Abort!\n");
stderr,
"GetEventInformation: "
"Segmented message. Sending Abort!\n");
#endif
goto GET_EVENT_ABORT; goto GET_EVENT_ABORT;
} }
len = getevent_decode_service_request( len = getevent_decode_service_request(
service_request, service_len, &object_id); service_request, service_len, &object_id);
if (len < 0) { if (len < 0) {
@@ -108,9 +123,8 @@ void handler_get_event_information(
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("GetEventInformation: Bad Encoding. "
fprintf(stderr, "GetEventInformation: Bad Encoding. Sending Abort!\n"); "Sending Abort!\n");
#endif
goto GET_EVENT_ABORT; goto GET_EVENT_ABORT;
} }
len = getevent_ack_encode_apdu_init( len = getevent_ack_encode_apdu_init(
@@ -182,9 +196,7 @@ void handler_get_event_information(
error = true; error = true;
goto GET_EVENT_ERROR; goto GET_EVENT_ERROR;
} }
#if PRINT_ENABLED debug_print("Got a GetEventInformation request: Sending Ack!\n");
fprintf(stderr, "Got a GetEventInformation request: Sending Ack!\n");
#endif
GET_EVENT_ERROR: GET_EVENT_ERROR:
if (error) { if (error) {
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
@@ -195,33 +207,22 @@ GET_EVENT_ERROR:
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("GetEventInformation: "
fprintf( "Reply too big to fit into APDU!\n");
stderr,
"GetEventInformation: "
"Reply too big to fit into APDU!\n");
#endif
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
#if PRINT_ENABLED debug_print("GetEventInformation: Sending Error!\n");
fprintf(stderr, "GetEventInformation: Sending Error!\n");
#endif
} }
} }
GET_EVENT_ABORT: GET_EVENT_ABORT:
pdu_len += len; pdu_len += len;
#if PRINT_ENABLED bytes_sent = datalink_send_pdu(
bytes_sent = src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#endif
datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); debug_perror("GetEventInformation: Failed to send PDU");
} }
#endif
return; return;
} }
+36 -23
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -18,6 +17,7 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/list_element.h" #include "bacnet/list_element.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
@@ -59,15 +59,23 @@ void handler_add_list_element(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("AddListElement: Received Request!\n"); debug_print("AddListElement: Received Request!\n");
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("AddListElement: Missing Required Parameter. "
"Sending Reject!\n");
status = false;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("AddListElement: Segmented message. Sending Abort!\n"); debug_print("AddListElement: Segmented message. "
"Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -75,7 +83,7 @@ void handler_add_list_element(
len = list_element_decode_service_request( len = list_element_decode_service_request(
service_request, service_len, &list_element); service_request, service_len, &list_element);
if (len > 0) { if (len > 0) {
debug_perror( debug_printf_stderr(
"AddListElement: type=%lu instance=%lu property=%lu " "AddListElement: type=%lu instance=%lu property=%lu "
"index=%ld\n", "index=%ld\n",
(unsigned long)list_element.object_type, (unsigned long)list_element.object_type,
@@ -83,14 +91,14 @@ void handler_add_list_element(
(unsigned long)list_element.object_property, (unsigned long)list_element.object_property,
(long)list_element.array_index); (long)list_element.array_index);
} else { } else {
debug_perror("AddListElement: Unable to decode request!\n"); debug_print("AddListElement: Unable to decode request!\n");
} }
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { if (len <= 0) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
debug_perror("AddListElement: Bad Encoding. Sending Abort!\n"); debug_print("AddListElement: Bad Encoding. Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -98,13 +106,13 @@ void handler_add_list_element(
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ADD_LIST_ELEMENT); SERVICE_CONFIRMED_ADD_LIST_ELEMENT);
debug_perror("AddListElement: Sending Simple Ack!\n"); debug_print("AddListElement: Sending Simple Ack!\n");
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ADD_LIST_ELEMENT, SERVICE_CONFIRMED_ADD_LIST_ELEMENT,
list_element.error_class, list_element.error_code); list_element.error_class, list_element.error_code);
debug_perror("AddListElement: Sending Error!\n"); debug_print("AddListElement: Sending Error!\n");
} }
} }
} }
@@ -113,8 +121,7 @@ void handler_add_list_element(
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
debug_perror( debug_perror("AddListElement: Failed to send PDU");
"AddListElement: Failed to send PDU (%s)!\n", strerror(errno));
} }
return; return;
@@ -153,15 +160,22 @@ void handler_remove_list_element(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("RemoveListElement: Received Request!\n"); debug_print("RemoveListElement: Received Request!\n");
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("AddListElement: Missing Required Parameter. "
"Sending Reject!\n");
status = false;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("RemoveListElement: Segmented message. Sending Abort!\n"); debug_print("RemoveListElement: Segmented message. Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -169,7 +183,7 @@ void handler_remove_list_element(
len = list_element_decode_service_request( len = list_element_decode_service_request(
service_request, service_len, &list_element); service_request, service_len, &list_element);
if (len > 0) { if (len > 0) {
debug_perror( debug_printf_stderr(
"RemoveListElement: type=%lu instance=%lu " "RemoveListElement: type=%lu instance=%lu "
"property=%lu index=%ld\n", "property=%lu index=%ld\n",
(unsigned long)list_element.object_type, (unsigned long)list_element.object_type,
@@ -177,14 +191,14 @@ void handler_remove_list_element(
(unsigned long)list_element.object_property, (unsigned long)list_element.object_property,
(long)list_element.array_index); (long)list_element.array_index);
} else { } else {
debug_perror("RemoveListElement: Unable to decode request!\n"); debug_print("RemoveListElement: Unable to decode request!\n");
} }
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { if (len <= 0) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
debug_perror("RemoveListElement: Bad Encoding. Sending Abort!\n"); debug_print("RemoveListElement: Bad Encoding. Sending Abort!\n");
status = false; status = false;
} }
if (status) { if (status) {
@@ -192,13 +206,13 @@ void handler_remove_list_element(
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT); SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT);
debug_perror("RemoveListElement: Sending Simple Ack!\n"); debug_print("RemoveListElement: Sending Simple Ack!\n");
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT, SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT,
list_element.error_class, list_element.error_code); list_element.error_class, list_element.error_code);
debug_perror("RemoveListElement: Sending Error!\n"); debug_print("RemoveListElement: Sending Error!\n");
} }
} }
} }
@@ -207,8 +221,7 @@ void handler_remove_list_element(
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
debug_perror( debug_perror("RemoveListElement: Failed to send PDU");
"RemoveListElement: Failed to send PDU (%s)!\n", strerror(errno));
} }
return; return;
+19 -37
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -17,11 +16,13 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/lso.h" #include "bacnet/lso.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
void handler_lso( void handler_lso(
@@ -34,82 +35,63 @@ void handler_lso(
int len = 0; int len = 0;
int pdu_len = 0; int pdu_len = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
#if PRINT_ENABLED
int bytes_sent = 0; int bytes_sent = 0;
#endif
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("LSO: Missing Required Parameter. Sending Reject!\n");
goto LSO_ABORT;
} else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("LSO: Segmented message. Sending Abort!\n");
fprintf(stderr, "LSO: Segmented message. Sending Abort!\n");
#endif
goto LSO_ABORT; goto LSO_ABORT;
} }
len = lso_decode_service_request(service_request, service_len, &data); len = lso_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
fprintf(stderr, "LSO: Unable to decode Request!\n"); debug_print("LSO: Unable to decode Request!\n");
} }
#endif
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* bad decoding - send an abort */
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("LSO: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "LSO: Bad Encoding. Sending Abort!\n");
#endif
goto LSO_ABORT; goto LSO_ABORT;
} }
/* /*
** Process Life Safety Operation Here ** Process Life Safety Operation Here
*/ */
#if PRINT_ENABLED debug_fprintf(
fprintf(
stderr, stderr,
"Life Safety Operation: Received operation %d from process id %lu " "Life Safety Operation: Received operation %d from process id %lu "
"for object %lu\n", "for object %lu\n",
data.operation, (unsigned long)data.processId, data.operation, (unsigned long)data.processId,
(unsigned long)data.targetObject.instance); (unsigned long)data.targetObject.instance);
#endif
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION); SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
#if PRINT_ENABLED debug_print("Life Safety Operation: "
fprintf( "Sending Simple Ack!\n");
stderr,
"Life Safety Operation: "
"Sending Simple Ack!\n");
#endif
LSO_ABORT: LSO_ABORT:
pdu_len += len; pdu_len += len;
#if PRINT_ENABLED bytes_sent = datalink_send_pdu(
bytes_sent = src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#endif
datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf( debug_perror("Life Safety Operation: Failed to send PDU");
stderr,
"Life Safety Operation: "
"Failed to send PDU (%s)!\n",
strerror(errno));
} }
#endif
return; return;
} }
+4 -8
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -21,6 +20,7 @@
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/** Handler to be invoked when a Service request is received for which no /** Handler to be invoked when a Service request is received for which no
@@ -51,7 +51,7 @@ void handler_unrecognized_service(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
/* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */
@@ -63,12 +63,8 @@ void handler_unrecognized_service(
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent > 0) { if (bytes_sent > 0) {
#if PRINT_ENABLED debug_print("Sent Reject!\n");
fprintf(stderr, "Sent Reject!\n");
#endif
} else { } else {
#if PRINT_ENABLED debug_perror("Failed to Send Reject");
fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno));
#endif
} }
} }
+19 -34
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -24,6 +23,7 @@
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/** Handler for a Reinitialize Device (RD) request. /** Handler for a Reinitialize Device (RD) request.
@@ -60,45 +60,42 @@ void handler_reinitialize_device(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
#if PRINT_ENABLED debug_print("ReinitializeDevice!\n");
fprintf(stderr, "ReinitializeDevice!\n"); if (service_len == 0) {
#endif len = reject_encode_apdu(
if (service_data->segmented_message) { &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("ReinitializeDevice: Missing Required Parameter. "
"Sending Reject!\n");
goto RD_ABORT;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("ReinitializeDevice: Sending Abort - segmented message.\n");
fprintf(
stderr, "ReinitializeDevice: Sending Abort - segmented message.\n");
#endif
goto RD_ABORT; goto RD_ABORT;
} }
/* decode the service request only */ /* decode the service request only */
len = rd_decode_service_request( len = rd_decode_service_request(
service_request, service_len, &rd_data.state, &rd_data.password); service_request, service_len, &rd_data.state, &rd_data.password);
#if PRINT_ENABLED
if (len > 0) { if (len > 0) {
fprintf( debug_fprintf(
stderr, "ReinitializeDevice: state=%u password=%*s\n", stderr, "ReinitializeDevice: state=%u password=%*s\n",
(unsigned)rd_data.state, (unsigned)rd_data.state,
(int)characterstring_length(&rd_data.password), (int)characterstring_length(&rd_data.password),
characterstring_value(&rd_data.password)); characterstring_value(&rd_data.password));
} else { } else {
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); debug_print("ReinitializeDevice: Unable to decode request!\n");
} }
#endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len < 0) { if (len < 0) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("ReinitializeDevice: Sending Abort - could not decode.\n");
fprintf(
stderr, "ReinitializeDevice: Sending Abort - could not decode.\n");
#endif
goto RD_ABORT; goto RD_ABORT;
} }
/* check the data from the request */ /* check the data from the request */
@@ -106,11 +103,8 @@ void handler_reinitialize_device(
len = reject_encode_apdu( len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_UNDEFINED_ENUMERATION); REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED debug_print(
fprintf(
stderr,
"ReinitializeDevice: Sending Reject - undefined enumeration\n"); "ReinitializeDevice: Sending Reject - undefined enumeration\n");
#endif
} else { } else {
#ifdef BAC_ROUTING #ifdef BAC_ROUTING
/* Check to see if the current Device supports this service. */ /* Check to see if the current Device supports this service. */
@@ -121,22 +115,17 @@ void handler_reinitialize_device(
goto RD_ABORT; goto RD_ABORT;
} }
#endif #endif
if (Device_Reinitialize(&rd_data)) { if (Device_Reinitialize(&rd_data)) {
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE); SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED debug_print("ReinitializeDevice: Sending Simple Ack!\n");
fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n");
#endif
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE, rd_data.error_class, SERVICE_CONFIRMED_REINITIALIZE_DEVICE, rd_data.error_class,
rd_data.error_code); rd_data.error_code);
#if PRINT_ENABLED debug_print("ReinitializeDevice: Sending Error.\n");
fprintf(stderr, "ReinitializeDevice: Sending Error.\n");
#endif
} }
} }
RD_ABORT: RD_ABORT:
@@ -144,11 +133,7 @@ RD_ABORT:
len = datalink_send_pdu( len = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (len <= 0) { if (len <= 0) {
#if PRINT_ENABLED debug_perror("ReinitializeDevice: Failed to send PDU");
fprintf(
stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
strerror(errno));
#endif
} }
return; return;
+19 -44
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -28,6 +27,7 @@
#endif #endif
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/** @file h_rp.c Handles Read Property requests. */ /** @file h_rp.c Handles Read Property requests. */
@@ -77,28 +77,19 @@ void handler_read_property(
if (npdu_len <= 0) { if (npdu_len <= 0) {
/* If 0 or negative, there were problems with the data or encoding. */ /* If 0 or negative, there were problems with the data or encoding. */
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED debug_print("RP: npdu_encode_pdu error. Sending Abort!\n");
fprintf(stderr, "RP: npdu_encode_pdu error. Sending Abort!\n"); } else if (service_len == 0) {
#endif len = BACNET_STATUS_REJECT;
rpdata.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
debug_print("RP: Missing Required Parameter. Sending Reject!\n");
} else if (service_data->segmented_message) { } else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED debug_print("RP: Segmented message. Sending Abort!\n");
fprintf(stderr, "RP: Segmented message. Sending Abort!\n");
#endif
} else { } else {
len = rp_decode_service_request(service_request, service_len, &rpdata); len = rp_decode_service_request(service_request, service_len, &rpdata);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
fprintf(stderr, "RP: Unable to decode Request!\n"); debug_print("RP: Unable to decode Request!\n");
}
#endif
if (len < 0) {
/* bad decoding - skip to error/reject/abort handling */
error = true;
#if PRINT_ENABLED
fprintf(stderr, "RP: Bad Encoding.\n");
#endif
} else { } else {
/* When the object-type in the Object Identifier parameter /* When the object-type in the Object Identifier parameter
contains the value DEVICE and the instance in the 'Object contains the value DEVICE and the instance in the 'Object
@@ -147,65 +138,49 @@ void handler_read_property(
rpdata.error_code = rpdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED debug_print("RP: Message too large.\n");
fprintf(stderr, "RP: Message too large.\n");
#endif
} else { } else {
#if PRINT_ENABLED debug_print("RP: Sending Ack!\n");
fprintf(stderr, "RP: Sending Ack!\n");
#endif
error = false; error = false;
} }
} else { } else {
#if PRINT_ENABLED debug_print("RP: Device_Read_Property: ");
fprintf(stderr, "RP: Device_Read_Property: ");
if (len == BACNET_STATUS_ABORT) { if (len == BACNET_STATUS_ABORT) {
fprintf(stderr, "Abort!\n"); debug_print("Abort!\n");
} else if (len == BACNET_STATUS_ERROR) { } else if (len == BACNET_STATUS_ERROR) {
fprintf(stderr, "Error!\n"); debug_print("Error!\n");
} else if (len == BACNET_STATUS_REJECT) { } else if (len == BACNET_STATUS_REJECT) {
fprintf(stderr, "Reject!\n"); debug_print("Reject!\n");
} else { } else {
fprintf(stderr, "Unknown Len=%d\n", len); debug_print("Unknown Len!\n");
} }
#endif
} }
} }
} }
if (error) { if (error) {
if (len == BACNET_STATUS_ABORT) { if (len == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu( apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(rpdata.error_code), true); abort_convert_error_code(rpdata.error_code), true);
#if PRINT_ENABLED debug_print("RP: Sending Abort!\n");
fprintf(stderr, "RP: Sending Abort!\n");
#endif
} else if (len == BACNET_STATUS_ERROR) { } else if (len == BACNET_STATUS_ERROR) {
apdu_len = bacerror_encode_apdu( apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, rpdata.error_class, SERVICE_CONFIRMED_READ_PROPERTY, rpdata.error_class,
rpdata.error_code); rpdata.error_code);
#if PRINT_ENABLED debug_print("RP: Sending Error!\n");
fprintf(stderr, "RP: Sending Error!\n");
#endif
} else if (len == BACNET_STATUS_REJECT) { } else if (len == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu( apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(rpdata.error_code)); reject_convert_error_code(rpdata.error_code));
#if PRINT_ENABLED debug_print("RP: Sending Reject!\n");
fprintf(stderr, "RP: Sending Reject!\n");
#endif
} }
} }
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED debug_perror("RP: Failed to send PDU");
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
#endif
} }
return; return;
+2 -2
View File
@@ -24,8 +24,8 @@
#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
#define PRINTF debug_aprintf #define PRINTF debug_printf_stdout
#define PRINTF_ERR debug_perror #define PRINTF_ERR debug_printf_stderr
/** For debugging... /** For debugging...
* @param [in] data portion of the ACK * @param [in] data portion of the ACK
+53 -64
View File
@@ -12,7 +12,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -220,20 +219,19 @@ void handler_read_property_multiple(
int npdu_len = 0; int npdu_len = 0;
int error = 0; int error = 0;
if (service_data && (service_len > 0)) { if (service_data) {
/* jps_debug - see if we are utilizing all the buffer */
/* memset(&Handler_Transmit_Buffer[0], 0xff,
* sizeof(Handler_Transmit_Buffer)); */
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
npdu_len = npdu_encode_pdu( npdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_len == 0) {
if (service_data->segmented_message) { rpmdata.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
error = BACNET_STATUS_REJECT;
debug_print("RPM: Missing Required Parameter. Sending Reject!\n");
} else if (service_data->segmented_message) {
rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT; error = BACNET_STATUS_ABORT;
debug_fprintf(stderr, "RPM: Segmented message. Sending Abort!\r\n"); debug_print("RPM: Segmented message. Sending Abort!\r\n");
} else { } else {
/* decode apdu request & encode apdu reply /* decode apdu request & encode apdu reply
encode complex ack, invoke id, service choice */ encode complex ack, invoke id, service choice */
@@ -250,8 +248,10 @@ void handler_read_property_multiple(
decode_len += len; decode_len += len;
} else { } else {
/* bad encoding - skip to error/reject/abort handling */ /* bad encoding - skip to error/reject/abort handling */
debug_fprintf(stderr, "RPM: Bad Encoding.\n"); debug_print("RPM: Bad Encoding.\n");
error = len; error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; break;
} }
@@ -276,21 +276,19 @@ void handler_read_property_multiple(
rpmdata.object_instance = Network_Port_Index_To_Instance(0); rpmdata.object_instance = Network_Port_Index_To_Instance(0);
} }
#endif #endif
/* Stick this object id into the reply - if it will fit */ /* Stick this object id into the reply - if it will fit */
len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata); len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata);
copy_len = memcopy( copy_len = memcopy(
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len, &Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len,
len, MAX_APDU); len, MAX_APDU);
if (copy_len == 0) { if (copy_len == 0) {
debug_fprintf(stderr, "RPM: Response too big!\r\n"); debug_print("RPM: Response too big!\n");
rpmdata.error_code = rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT; error = BACNET_STATUS_ABORT;
berror = true; berror = true;
break; break;
} }
apdu_len += copy_len; apdu_len += copy_len;
/* do each property of this object of the RPM request */ /* do each property of this object of the RPM request */
for (;;) { for (;;) {
@@ -300,12 +298,12 @@ void handler_read_property_multiple(
&rpmdata); &rpmdata);
if (len < 0) { if (len < 0) {
/* bad encoding - skip to error/reject/abort handling */ /* bad encoding - skip to error/reject/abort handling */
debug_fprintf(stderr, "RPM: Bad Encoding.\n"); debug_print("RPM: Bad Encoding.\n");
error = len; error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; /* The berror flag ensures that both loops will break;
*/
/* be broken! */
} }
decode_len += len; decode_len += len;
/* handle the special properties */ /* handle the special properties */
@@ -325,8 +323,7 @@ void handler_read_property_multiple(
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
debug_fprintf( debug_print("RPM: Too full for property!\n");
stderr, "RPM: Too full for property!\r\n");
error = len; error = len;
/* The berror flag ensures that /* The berror flag ensures that
both loops will be broken! */ both loops will be broken! */
@@ -345,15 +342,15 @@ void handler_read_property_multiple(
&Temp_Buf[0], apdu_len, len, MAX_APDU); &Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) { if (copy_len == 0) {
debug_fprintf( debug_print(
stderr, "RPM: Too full to encode property!\n");
"RPM: Too full to encode property!\r\n");
rpmdata.error_code = rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT; error = BACNET_STATUS_ABORT;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; /* The berror flag ensures that both */ break;
/* loops will be broken! */
} }
apdu_len += len; apdu_len += len;
@@ -366,15 +363,14 @@ void handler_read_property_multiple(
&Temp_Buf[0], apdu_len, len, MAX_APDU); &Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) { if (copy_len == 0) {
debug_fprintf( debug_print("RPM: Too full to encode error!\n");
stderr,
"RPM: Too full to encode error!\r\n");
rpmdata.error_code = rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT; error = BACNET_STATUS_ABORT;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; /* The berror flag ensures that both */ break;
/* loops will be broken! */
} }
apdu_len += len; apdu_len += len;
} else { } else {
@@ -386,8 +382,7 @@ void handler_read_property_multiple(
&property_list, special_object_property); &property_list, special_object_property);
if (property_count == 0) { if (property_count == 0) {
/* This only happens with the OPTIONAL property /* Only happens with the OPTIONAL property */
*/
/* 135-2016bl-2. Clarify ReadPropertyMultiple /* 135-2016bl-2. Clarify ReadPropertyMultiple
response on OPTIONAL when empty. */ response on OPTIONAL when empty. */
/* If no optional properties are supported then /* If no optional properties are supported then
@@ -403,9 +398,8 @@ void handler_read_property_multiple(
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
debug_fprintf( debug_print(
stderr, "RPM: Too full for property!\n");
"RPM: Too full for property!\r\n");
error = len; error = len;
/* The berror flag ensures that /* The berror flag ensures that
both loops will be broken! */ both loops will be broken! */
@@ -426,14 +420,13 @@ void handler_read_property_multiple(
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
debug_fprintf( debug_print(
stderr, "RPM: Too full for property!\n");
"RPM: Too full for property!\r\n");
error = len; error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; /* The berror flag ensures that break;
*/
/* both loops will be broken! */
} }
} }
} }
@@ -446,13 +439,13 @@ void handler_read_property_multiple(
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
debug_fprintf( debug_print(
stderr, "RPM: Too full for individual property!\n");
"RPM: Too full for individual property!\r\n");
error = len; error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; /* The berror flag ensures that both loops */ break;
/* will be broken! */
} }
} }
@@ -466,21 +459,22 @@ void handler_read_property_multiple(
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], &Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, MAX_APDU); apdu_len, len, MAX_APDU);
if (copy_len == 0) { if (copy_len == 0) {
debug_fprintf( debug_print(
stderr, "RPM: Too full to encode object end!\n");
"RPM: Too full to encode object end!\r\n");
rpmdata.error_code = rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT; error = BACNET_STATUS_ABORT;
/* The berror flag ensures that
both loops will be broken! */
berror = true; berror = true;
break; /* The berror flag ensures that both loops */ break;
/* will be broken! */
} else { } else {
apdu_len += copy_len; apdu_len += copy_len;
} }
break; /* finished with this property list */ /* finished with this property list */
break;
} }
} /* for(;;) */ }
if (berror) { if (berror) {
break; break;
} }
@@ -488,8 +482,7 @@ void handler_read_property_multiple(
/* Reached the end so finish up */ /* Reached the end so finish up */
break; break;
} }
} /* for(;;) */ }
/* If not having an error so far, check the remaining space. */ /* If not having an error so far, check the remaining space. */
if (!berror) { if (!berror) {
if (apdu_len > service_data->max_resp) { if (apdu_len > service_data->max_resp) {
@@ -497,39 +490,35 @@ void handler_read_property_multiple(
rpmdata.error_code = rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT; error = BACNET_STATUS_ABORT;
debug_fprintf( debug_print("RPM: Message too large. Sending Abort!\n");
stderr, "RPM: Message too large. Sending Abort!\n");
} }
} }
} }
/* Error fallback. */ /* Error fallback. */
if (error) { if (error) {
if (error == BACNET_STATUS_ABORT) { if (error == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu( apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(rpmdata.error_code), true); abort_convert_error_code(rpmdata.error_code), true);
debug_fprintf(stderr, "RPM: Sending Abort!\n"); debug_print("RPM: Sending Abort!\n");
} else if (error == BACNET_STATUS_ERROR) { } else if (error == BACNET_STATUS_ERROR) {
apdu_len = bacerror_encode_apdu( apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROP_MULTIPLE, rpmdata.error_class, SERVICE_CONFIRMED_READ_PROP_MULTIPLE, rpmdata.error_class,
rpmdata.error_code); rpmdata.error_code);
debug_fprintf(stderr, "RPM: Sending Error!\n"); debug_print("RPM: Sending Error!\n");
} else if (error == BACNET_STATUS_REJECT) { } else if (error == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu( apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(rpmdata.error_code)); reject_convert_error_code(rpmdata.error_code));
debug_fprintf(stderr, "RPM: Sending Reject!\n"); debug_print("RPM: Sending Reject!\n");
} }
} }
pdu_len = apdu_len + npdu_len; pdu_len = apdu_len + npdu_len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
debug_fprintf( debug_perror("RPM: Failed to send PDU");
stderr, "RPM: Failed to send PDU (errno=%d)!\n", errno);
} }
} }
} }
+9 -11
View File
@@ -1,10 +1,10 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net> * @brief A basic ReadPropertyMultile-Ack service handler
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: MIT * @date 2008
* * @copyright SPDX-License-Identifier: MIT
*********************************************************************/ */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@@ -24,10 +24,8 @@
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
#define PRINTF debug_aprintf #define PRINTF debug_printf_stdout
#define PERROR debug_perror #define PERROR debug_printf_stderr
/** @file h_rpm_a.c Handles Read Property Multiple Acknowledgments. */
/** Decode the received RPM data and make a linked list of the results. /** Decode the received RPM data and make a linked list of the results.
* @ingroup DSRPM * @ingroup DSRPM
+25 -40
View File
@@ -1,15 +1,14 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net> * @brief Handles ReadRange-Request service
* * @author Peter Mc Shane <petermcs@users.sourceforge.net>
* SPDX-License-Identifier: MIT * @date 2009
* * @copyright SPDX-License-Identifier: MIT
*********************************************************************/ */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -18,15 +17,15 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/readrange.h" #include "bacnet/readrange.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/** @file h_rr.c Handles Read Range requests. */
static uint8_t Temp_Buf[MAX_APDU] = { 0 }; static uint8_t Temp_Buf[MAX_APDU] = { 0 };
/** /**
@@ -116,42 +115,39 @@ void handler_read_range(
int pdu_len = 0; int pdu_len = 0;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
bool error = false; bool error = false;
#if PRINT_ENABLED
int bytes_sent = 0; int bytes_sent = 0;
#endif
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
data.error_class = ERROR_CLASS_OBJECT; data.error_class = ERROR_CLASS_OBJECT;
data.error_code = ERROR_CODE_UNKNOWN_OBJECT; data.error_code = ERROR_CODE_UNKNOWN_OBJECT;
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) { if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("RR: Missing Required Parameter. Sending Reject!\n");
} else if (service_data->segmented_message) {
/* we don't support segmentation - send an abort */ /* we don't support segmentation - send an abort */
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("RR: Segmented message. Sending Abort!\n");
fprintf(stderr, "RR: Segmented message. Sending Abort!\n");
#endif
} else { } else {
memset(&data, 0, sizeof(data)); /* start with blank canvas */ memset(&data, 0, sizeof(data)); /* start with blank canvas */
len = rr_decode_service_request(service_request, service_len, &data); len = rr_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
fprintf(stderr, "RR: Unable to decode Request!\n"); debug_print("RR: Unable to decode Request!\n");
} }
#endif
if (len < 0) { if (len < 0) {
/* bad decoding - send an abort */ /* bad decoding - send an abort */
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("RR: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n");
#endif
} else { } else {
/* assume that there is an error */ /* assume that there is an error */
error = true; error = true;
@@ -164,9 +160,7 @@ void handler_read_range(
len = rr_ack_encode_apdu( len = rr_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data); &data);
#if PRINT_ENABLED debug_print("RR: Sending Ack!\n");
fprintf(stderr, "RR: Sending Ack!\n");
#endif
error = false; error = false;
} }
if (error) { if (error) {
@@ -177,33 +171,24 @@ void handler_read_range(
&Handler_Transmit_Buffer[pdu_len], &Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("RR: Reply too big to fit into APDU!\n");
fprintf(stderr, "RR: Reply too big to fit into APDU!\n");
#endif
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], &Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE, service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE,
data.error_class, data.error_code); data.error_class, data.error_code);
#if PRINT_ENABLED debug_print("RR: Sending Error!\n");
fprintf(stderr, "RR: Sending Error!\n");
#endif
} }
} }
} }
} }
pdu_len += len; pdu_len += len;
#if PRINT_ENABLED bytes_sent = datalink_send_pdu(
bytes_sent = src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#endif
datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); debug_perror("RR: Failed to send PDU");
} }
#endif
return; return;
} }
+44 -38
View File
@@ -1,15 +1,14 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net> * @brief Handles Unconfirmed COV Notifications.
* * @author Steve Karg <skarg@users.sourceforge.net>
* SPDX-License-Identifier: MIT * @date December 2010
* * @copyright SPDX-License-Identifier: MIT
*********************************************************************/ */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -23,9 +22,6 @@
#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
/** @file h_ucov.c Handles Unconfirmed COV Notifications. */
#define PRINTF debug_perror
#ifndef MAX_COV_PROPERTIES #ifndef MAX_COV_PROPERTIES
#define MAX_COV_PROPERTIES 2 #define MAX_COV_PROPERTIES 2
#endif #endif
@@ -72,6 +68,41 @@ void handler_ucov_notification_add(BACNET_COV_NOTIFICATION *cb)
} while (head); } while (head);
} }
/**
* @brief Print the UnconfirmedCOV data
* @param cov_data - data decoded from the COV notification
*/
void handler_ucov_data_print(BACNET_COV_DATA *cov_data)
{
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
debug_printf_stderr("UCOV: PID=%u ", cov_data->subscriberProcessIdentifier);
debug_printf_stderr("instance=%u ", cov_data->initiatingDeviceIdentifier);
debug_printf_stderr(
"%s %u ",
bactext_object_type_name(cov_data->monitoredObjectIdentifier.type),
cov_data->monitoredObjectIdentifier.instance);
debug_printf_stderr("time remaining=%u seconds ", cov_data->timeRemaining);
debug_printf_stderr("\n");
pProperty_value = cov_data->listOfValues;
while (pProperty_value) {
debug_printf_stderr("UCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
debug_printf_stderr(
"%s ",
bactext_property_name(pProperty_value->propertyIdentifier));
} else {
debug_printf_stderr(
"proprietary %u ", pProperty_value->propertyIdentifier);
}
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
debug_printf_stderr("%u ", pProperty_value->propertyArrayIndex);
}
debug_printf_stderr("\n");
pProperty_value = pProperty_value->next;
}
}
/* */ /* */
/** Handler for an Unconfirmed COV Notification. /** Handler for an Unconfirmed COV Notification.
* @ingroup DSCOV * @ingroup DSCOV
@@ -89,7 +120,6 @@ void handler_ucov_notification(
{ {
BACNET_COV_DATA cov_data; BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES]; BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
int len = 0; int len = 0;
/* src not needed for this application */ /* src not needed for this application */
@@ -98,37 +128,13 @@ void handler_ucov_notification(
than one property value is expected */ than one property value is expected */
bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES); bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES);
cov_data.listOfValues = &property_value[0]; cov_data.listOfValues = &property_value[0];
PRINTF("UCOV: Received Notification!\n"); debug_print("UCOV: Received Notification!\n");
/* decode the service request only */ /* decode the service request only */
len = cov_notify_decode_service_request( len = cov_notify_decode_service_request(
service_request, service_len, &cov_data); service_request, service_len, &cov_data);
if (len > 0) { if (len > 0) {
handler_ucov_notification_callback(&cov_data); handler_ucov_notification_callback(&cov_data);
PRINTF("UCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
PRINTF("instance=%u ", cov_data.initiatingDeviceIdentifier);
PRINTF(
"%s %u ",
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
cov_data.monitoredObjectIdentifier.instance);
PRINTF("time remaining=%u seconds ", cov_data.timeRemaining);
PRINTF("\n");
pProperty_value = &property_value[0];
while (pProperty_value) {
PRINTF("UCOV: ");
if (pProperty_value->propertyIdentifier < 512) {
PRINTF(
"%s ",
bactext_property_name(pProperty_value->propertyIdentifier));
} else {
PRINTF("proprietary %u ", pProperty_value->propertyIdentifier);
}
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
PRINTF("%u ", pProperty_value->propertyArrayIndex);
}
PRINTF("\n");
pProperty_value = pProperty_value->next;
}
} else { } else {
PRINTF("UCOV: Unable to decode service request!\n"); debug_print("UCOV: Unable to decode service request!\n");
} }
} }
+3
View File
@@ -27,6 +27,9 @@ extern "C" {
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void handler_ucov_notification_add(BACNET_COV_NOTIFICATION *callback); void handler_ucov_notification_add(BACNET_COV_NOTIFICATION *callback);
BACNET_STACK_EXPORT
void handler_ucov_data_print(BACNET_COV_DATA *cov_data);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
void handler_ucov_notification( void handler_ucov_notification(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src); uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src);
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
+18 -28
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -18,11 +17,13 @@
#include "bacnet/apdu.h" #include "bacnet/apdu.h"
#include "bacnet/npdu.h" #include "bacnet/npdu.h"
#include "bacnet/abort.h" #include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/wp.h" #include "bacnet/wp.h"
/* basic objects, services, TSM, and datalink */ /* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/** @file h_wp.c Handles Write Property requests. */ /** @file h_wp.c Handles Write Property requests. */
@@ -61,28 +62,28 @@ void handler_write_property(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
pdu_len = npdu_encode_pdu( pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
#if PRINT_ENABLED debug_print("WP: Received Request!\n");
fprintf(stderr, "WP: Received Request!\n"); if (service_len == 0) {
#endif len = reject_encode_apdu(
if (service_data->segmented_message) { &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
debug_print("WP: Missing Required Parameter. Sending Reject!\n");
bcontinue = false;
} else if (service_data->segmented_message) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED debug_print("WP: Segmented message. Sending Abort!\n");
fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
#endif
bcontinue = false; bcontinue = false;
} }
if (bcontinue) { if (bcontinue) {
/* decode the service request only */ /* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data); len = wp_decode_service_request(service_request, service_len, &wp_data);
#if PRINT_ENABLED
if (len > 0) { if (len > 0) {
fprintf( debug_fprintf(
stderr, stderr,
"WP: type=%lu instance=%lu property=%lu priority=%lu " "WP: type=%lu instance=%lu property=%lu priority=%lu "
"index=%ld\n", "index=%ld\n",
@@ -91,48 +92,37 @@ void handler_write_property(
(unsigned long)wp_data.object_property, (unsigned long)wp_data.object_property,
(unsigned long)wp_data.priority, (long)wp_data.array_index); (unsigned long)wp_data.priority, (long)wp_data.array_index);
} else { } else {
fprintf(stderr, "WP: Unable to decode Request!\n"); debug_print("WP: Unable to decode Request!\n");
} }
#endif
/* bad decoding or something we didn't understand - send an abort */ /* bad decoding or something we didn't understand - send an abort */
if (len <= 0) { if (len <= 0) {
len = abort_encode_apdu( len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true); ABORT_REASON_OTHER, true);
#if PRINT_ENABLED debug_print("WP: Bad Encoding. Sending Abort!\n");
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
#endif
bcontinue = false; bcontinue = false;
} }
if (bcontinue) { if (bcontinue) {
if (Device_Write_Property(&wp_data)) { if (Device_Write_Property(&wp_data)) {
len = encode_simple_ack( len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY); SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED debug_print("WP: Sending Simple Ack!\n");
fprintf(stderr, "WP: Sending Simple Ack!\n");
#endif
} else { } else {
len = bacerror_encode_apdu( len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, wp_data.error_class, SERVICE_CONFIRMED_WRITE_PROPERTY, wp_data.error_class,
wp_data.error_code); wp_data.error_code);
#if PRINT_ENABLED debug_print("WP: Sending Error!\n");
fprintf(stderr, "WP: Sending Error!\n");
#endif
} }
} }
} }
/* Send PDU */ /* Send PDU */
pdu_len += len; pdu_len += len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED debug_perror("WP: Failed to send PDU");
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
#endif
} }
return; return;
+24 -22
View File
@@ -1,15 +1,14 @@
/************************************************************************** /**
* * @file
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com> * @brief Handles WritePropertyMultiple-Request service
* * @author Krzysztof Malorny <malornykrzysztof@gmail.com>
* SPDX-License-Identifier: MIT * @date 2011
* * @copyright SPDX-License-Identifier: MIT
*********************************************************************/ */
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
@@ -28,9 +27,6 @@
#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h" #include "bacnet/datalink/datalink.h"
/** @file h_wpm.c Handles Write Property Multiple requests. */
#define PRINTF debug_perror
/** Decoding for an object property. /** Decoding for an object property.
* *
* @param apdu [in] The contents of the APDU buffer. * @param apdu [in] The contents of the APDU buffer.
@@ -68,7 +64,7 @@ static int write_property_multiple_decode(
&apdu[offset], apdu_len - offset, wp_data); &apdu[offset], apdu_len - offset, wp_data);
if (len > 0) { if (len > 0) {
offset += len; offset += len;
PRINTF( debug_printf_stderr(
"WPM: type=%lu instance=%lu property=%lu " "WPM: type=%lu instance=%lu property=%lu "
"priority=%lu index=%ld\n", "priority=%lu index=%ld\n",
(unsigned long)wp_data->object_type, (unsigned long)wp_data->object_type,
@@ -91,7 +87,7 @@ static int write_property_multiple_decode(
} }
} }
} else { } else {
PRINTF("WPM: Bad Encoding!\n"); debug_printf_stderr("WPM: Bad Encoding!\n");
return len; return len;
} }
/* Closing tag 1 - List of Properties */ /* Closing tag 1 - List of Properties */
@@ -106,7 +102,7 @@ static int write_property_multiple_decode(
} while (tag_number != 1); } while (tag_number != 1);
} }
} else { } else {
PRINTF("WPM: Bad Encoding!\n"); debug_printf_stderr("WPM: Bad Encoding!\n");
return len; return len;
} }
} while (offset < apdu_len); } while (offset < apdu_len);
@@ -146,10 +142,16 @@ void handler_write_property_multiple(
BACNET_ADDRESS my_address; BACNET_ADDRESS my_address;
int bytes_sent = 0; int bytes_sent = 0;
if (service_data->segmented_message) { if (service_len == 0) {
wp_data.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
len = BACNET_STATUS_REJECT;
debug_print("WPM: Missing Required Parameter. "
"Sending Reject!\n");
} else if (service_data->segmented_message) {
wp_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; wp_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
PRINTF("WPM: Segmented message. Sending Abort!\n"); debug_print("WPM: Segmented message. "
"Sending Abort!\n");
} else { } else {
/* first time - detect malformed request before writing any data */ /* first time - detect malformed request before writing any data */
len = write_property_multiple_decode( len = write_property_multiple_decode(
@@ -161,36 +163,36 @@ void handler_write_property_multiple(
} }
/* encode the confirmed reply */ /* encode the confirmed reply */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, service_data->priority);
npdu_len = npdu_encode_pdu( npdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (len > 0) { if (len > 0) {
apdu_len = wpm_ack_encode_apdu_init( apdu_len = wpm_ack_encode_apdu_init(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id); &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id);
PRINTF("WPM: Sending Ack!\n"); debug_print("WPM: Sending Ack!\n");
} else { } else {
/* handle any errors */ /* handle any errors */
if (len == BACNET_STATUS_ABORT) { if (len == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu( apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(wp_data.error_code), true); abort_convert_error_code(wp_data.error_code), true);
PRINTF("WPM: Sending Abort!\n"); debug_print("WPM: Sending Abort!\n");
} else if (len == BACNET_STATUS_ERROR) { } else if (len == BACNET_STATUS_ERROR) {
apdu_len = wpm_error_ack_encode_apdu( apdu_len = wpm_error_ack_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
&wp_data); &wp_data);
PRINTF("WPM: Sending Error!\n"); debug_print("WPM: Sending Error!\n");
} else if (len == BACNET_STATUS_REJECT) { } else if (len == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu( apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(wp_data.error_code)); reject_convert_error_code(wp_data.error_code));
PRINTF("WPM: Sending Reject!\n"); debug_print("WPM: Sending Reject!\n");
} }
} }
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu( bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
PRINTF("Failed to send PDU (%s)!\n", strerror(errno)); debug_perror("WPM: Failed to send PDU");
} }
} }
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
/* BACnet Stack API */ /* BACnet Stack API */
-1
View File
@@ -7,7 +7,6 @@
*********************************************************************/ *********************************************************************/
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <string.h> #include <string.h>
/* BACnet Stack defines - first */ /* BACnet Stack defines - first */
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"

Some files were not shown because too many files have changed in this diff Show More