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 <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
+1
View File
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include "blinkt.h"
#define BLINKT_DEFAULT_BRIGHTNESS 7
-2
View File
@@ -99,8 +99,6 @@ static void Init_Service_Handlers(void)
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_WRITE_GROUP, handler_write_group);
/* handle communication so we can shutup when asked */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -14,7 +14,6 @@
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
#endif
#include <errno.h>
#include <assert.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-2
View File
@@ -60,8 +60,6 @@ static void Init_Service_Handlers()
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_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);
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe);
apdu_set_unconfirmed_handler(
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_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);
apdu_set_confirmed_handler(
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 */
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
+1
View File
@@ -1,3 +1,4 @@
#include <errno.h>
#include <time.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-2
View File
@@ -170,8 +170,6 @@ static void Init_Service_Handlers(void)
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync);
apdu_set_confirmed_handler(
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 */
apdu_set_confirmed_handler(
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
+16 -26
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -17,8 +16,10 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/ptransfer.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#define MYMAXSTR 32
@@ -185,24 +186,24 @@ void handler_conf_private_trans(
error_class = ERROR_CLASS_OBJECT;
error_code = ERROR_CODE_UNKNOWN_OBJECT;
#if PRINT_ENABLED
fprintf(stderr, "Received Confirmed Private Transfer Request!\n");
#endif
debug_print("Received Confirmed Private Transfer Request!\n");
/* encode the NPDU portion of the response packet as it will be needed */
/* no matter what the outcome. */
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(
&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("CPT: Missing Required Parameter. Sending Reject!\n");
goto CPT_ABORT;
} 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);
#if PRINT_ENABLED
fprintf(stderr, "CPT: Segmented Message. Sending Abort!\n");
#endif
debug_print("CPT: Segmented Message. Sending Abort!\n");
goto CPT_ABORT;
}
@@ -212,9 +213,7 @@ void handler_conf_private_trans(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "CPT: Bad Encoding. Sending Abort!\n");
#endif
debug_print("CPT: Bad Encoding. Sending Abort!\n");
goto CPT_ABORT;
}
@@ -234,9 +233,7 @@ void handler_conf_private_trans(
error = true;
error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_OTHER;
#if PRINT_ENABLED
fprintf(stderr, "CPT: Error servicing request!\n");
#endif
debug_print("CPT: Error servicing request!\n");
}
len = ptransfer_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data);
@@ -245,9 +242,7 @@ void handler_conf_private_trans(
error = true;
error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
#if PRINT_ENABLED
fprintf(stderr, "CPT: Not our Vendor ID or invalid service code!\n");
#endif
debug_print("CPT: Not our Vendor ID or invalid service code!\n");
}
if (error) {
@@ -259,12 +254,7 @@ CPT_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
}
#endif
debug_perror("CPT: Failed to send PDU");
return;
}
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#include <ctype.h> /* for tupper */
#if defined(WIN32) || defined(__BORLANDC__)
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
-1
View File
@@ -12,7 +12,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h> /* for time */
#include <errno.h>
#include <assert.h>
#include <fcntl.h>
#include <libconfig.h> /* read config files */
-1
View File
@@ -9,7 +9,6 @@
* SPDX-License-Identifier: MIT
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
+12 -21
View File
@@ -12,7 +12,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#include <ctype.h> /* for toupper */
#define PRINT_ENABLED 1
@@ -58,6 +57,9 @@ BACNET_SUBSCRIBE_COV_DATA *COV_Subscribe_Data = NULL;
/* flags to signal early termination */
static bool Simple_Ack_Detected = 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(
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
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! */
apdu_set_confirmed_handler(
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(
SERVICE_CONFIRMED_COV_NOTIFICATION,
My_Confirmed_COV_Notification_Handler);
SERVICE_CONFIRMED_COV_NOTIFICATION, handler_ccov_notification);
/* 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(
SERVICE_UNCONFIRMED_COV_NOTIFICATION,
My_Unconfirmed_COV_Notification_Handler);
SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification);
/* handle the Simple ack coming back from SubscribeCOV */
apdu_set_confirmed_simple_ack_handler(
SERVICE_CONFIRMED_SUBSCRIBE_COV, MyWritePropertySimpleAckHandler);
+1 -1
View File
@@ -32,7 +32,7 @@
#endif
/* print with flush by default */
#define PRINTF debug_aprintf
#define PRINTF debug_printf_stdout
/* current version of the BACnet stack */
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) {
debug_perror(
"device-instance=%u - not greater than %u\n", device_id,
debug_fprintf(
stderr, "device-instance=%u - not greater than %u\n", device_id,
BACNET_MAX_INSTANCE);
return 1;
}
Device_Set_Object_Instance_Number(device_id);
debug_aprintf(
debug_printf_stdout(
"BACnet Server-Discovery Demo\n"
"BACnet Stack Version %s\n"
"BACnet Device ID: %u\n"
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#include <ctype.h> /* for toupper */
#define PRINT_ENABLED 1
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -15,7 +15,6 @@
#include <stdlib.h>
#include <time.h> /* for time */
#include <string.h>
#include <errno.h>
#include <ctype.h> /* toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -14,7 +14,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <time.h> /* for time */
#define PRINT_ENABLED 1
/* 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_len - the number of bytes of data to send
* @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(
const uint8_t *dest_addr, /* the destination address */
+9 -11
View File
@@ -1,10 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg
*
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*
*********************************************************************/
/**
* @file
* @brief Initializes BACnet/IP interface (BSD/MAC OS X)
* @author Steve Karg <skarg@users.sourceforge.net>
* @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 <stdbool.h> /* for the standard bool type. */
#include <ifaddrs.h>
@@ -15,8 +15,6 @@
#include "bacnet/basic/bbmd/h_bbmd.h"
#include "bacport.h"
/** @file bsd/bip-init.c @brief Initializes BACnet/IP interface (BSD/MAC OS X). */
/* unix sockets */
static int BIP_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
*
* @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(
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_len - the number of bytes of data to send
* @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(
BACNET_ADDRESS *dest,
+10 -9
View File
@@ -1,15 +1,16 @@
/**************************************************************************
*
* Copyright (C) 2016 Steve Karg
*
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*
*********************************************************************/
/**
* @file
* @brief Initializes BACnet/IPv6 interface (BSD/MAC OS X)
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2016
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <errno.h>
#include "bacnet/bacdcode.h"
#include "bacnet/config.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
*
* @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(
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_len - the number of bytes of data to send
* @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,
BACNET_NPDU_DATA *npdu_data,
-1
View File
@@ -11,7 +11,6 @@
#include <pthread.h>
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/bsc/bsc-event.h"
+8 -12
View File
@@ -1,11 +1,11 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
* Updated by Nikola Jelic 2011 <nikola.jelic@euroicc.com>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Provides BSD-specific DataLink functions for MS/TP.
* @author Steve Karg <skarg@users.sourceforge.net>
* @author Nikola Jelic 2011 <nikola.jelic@euroicc.com>
* @date 2008
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@@ -27,12 +27,8 @@
/* port specific */
#include "rs485.h"
/** @file bsd/dlmstp.c Provides BSD-specific DataLink functions for MS/TP.
*/
/* Number of MS/TP Packets Rx/Tx */
uint16_t MSTP_Packets = 0;
/* packet queues */
static DLMSTP_PACKET Receive_Packet;
/* mechanism to wait for a packet */
+8 -10
View File
@@ -1,10 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Provides BSD-specific DataLink functions for MS/TP.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2008
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@@ -12,6 +12,7 @@
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include <errno.h>
/* BSD includes */
#include <IOKit/serial/ioss.h>
/* BACnet Stack defines - first */
@@ -29,9 +30,6 @@
/* OS Specific include */
#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_DATA_EXPECTING_REPLY_BIT 2
#define BACNET_DATA_EXPECTING_REPLY(control) \
+10 -12
View File
@@ -1,11 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg
*
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*
*********************************************************************/
/* linux Ethernet/IP specific */
/**
* @file
* @brief Initializes BACnet/IP interface (Linux).
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <asm/types.h>
#include <netinet/ether.h>
#include <netinet/in.h>
@@ -23,6 +22,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
/* BACnet specific */
#include "bacnet/bacdcode.h"
#include "bacnet/bacint.h"
@@ -31,8 +31,6 @@
#include "bacnet/basic/bbmd/h_bbmd.h"
#include "bacport.h"
/** @file linux/bip-init.c Initializes BACnet/IP interface (Linux). */
/* unix sockets */
static int BIP_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
*
* @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(
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_len - the number of bytes of data to send
* @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(
BACNET_ADDRESS *dest,
+10 -9
View File
@@ -1,15 +1,16 @@
/**************************************************************************
*
* Copyright (C) 2016 Steve Karg
*
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*
*********************************************************************/
/**
* @file
* @brief Initializes BACnet/IP interface (Linux).
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2016
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <errno.h>
#include "bacnet/bacdcode.h"
#include "bacnet/config.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
*
* @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(
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_len - the number of bytes of data to send
* @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,
-1
View File
@@ -11,7 +11,6 @@
#include <pthread.h>
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/bsc/bsc-event.h"
+8 -11
View File
@@ -1,11 +1,11 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
* Updated by Nikola Jelic 2011 <nikola.jelic@euroicc.com>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Provides Linux-specific DataLink functions for MS/TP.
* @author Steve Karg <skarg@users.sourceforge.net>
* @author Nikola Jelic 2011 <nikola.jelic@euroicc.com>
* @date 2008
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@@ -27,9 +27,6 @@
/* port specific */
#include "rs485.h"
/** @file linux/dlmstp.c Provides Linux-specific DataLink functions for MS/TP.
*/
/* Number of MS/TP Packets Rx/Tx */
uint16_t MSTP_Packets = 0;
+8 -11
View File
@@ -1,10 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Provides Linux-specific DataLink functions for MS/TP.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2008
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@@ -12,6 +12,7 @@
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -27,10 +28,6 @@
/* OS Specific include */
#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_DATA_EXPECTING_REPLY_BIT 2
#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
*
* @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(
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_len - the number of bytes of data to send
* @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(
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
*
* @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(
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_len - the number of bytes of data to send
* @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,
-1
View File
@@ -10,7 +10,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include "bacnet/datalink/bsc/bsc-event.h"
#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_len - the number of bytes of data to send
* @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(
const BACNET_ADDRESS *dest,
@@ -648,7 +648,7 @@ int bvlc_send_pdu(
* @param result_code - BVLC result code
*
* @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_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_len - the number of bytes of data to send
* @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(
const BACNET_ADDRESS *dest,
@@ -452,7 +452,7 @@ static void bbmd6_send_forward_npdu(
* @param result_code - BVLC result code
*
* @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(
const BACNET_IP6_ADDRESS *dest_addr,
@@ -476,7 +476,7 @@ static int bvlc6_send_result(
* @param vmac_dst - Destination-Virtual-Address
*
* @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(
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
*
* @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(
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,
rp_data->object_instance);
if (!object_data) {
debug_perror(
"%s-%u object fail to add!\n",
debug_fprintf(
stderr, "%s-%u object fail to add!\n",
bactext_object_type_name(rp_data->object_type),
rp_data->object_instance);
return;
@@ -619,8 +619,8 @@ static void bacnet_device_object_property_add(
property_data = bacnet_property_data_add(
object_data->Property_List, rp_data->object_property);
if (!property_data) {
debug_perror(
"%s-%u %s property fail to add!\n",
debug_fprintf(
stderr, "%s-%u %s property fail to add!\n",
bactext_object_type_name(rp_data->object_type),
rp_data->object_instance,
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,
rp_data->application_data_len);
} else {
debug_perror(
"%s-%u %s property fail to allocate!\n",
debug_fprintf(
stderr, "%s-%u %s property fail to allocate!\n",
bactext_object_type_name(rp_data->object_type),
rp_data->object_instance,
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 =
BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST;
} 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;
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;
return;
} else {
debug_perror(
"%u object-list[%u] %s-%u fail to queue!\n", device_id,
device_data->Object_List_Index,
debug_fprintf(
stderr, "%u object-list[%u] %s-%u fail to queue!\n",
device_id, device_data->Object_List_Index,
bactext_object_type_name(object_type),
(unsigned)object_instance);
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;
device_data->Object_List_Index++;
} else {
debug_perror(
"%u object-list[%u] %s-%u fail to queue!\n", device_id,
device_data->Object_List_Index,
debug_fprintf(
stderr, "%u object-list[%u] %s-%u fail to queue!\n",
device_id, device_data->Object_List_Index,
bactext_object_type_name(object_type),
(unsigned)object_instance);
}
@@ -886,8 +887,8 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data)
}
break;
default:
debug_perror(
"%u unknown state %u!\n", device_id,
debug_fprintf(
stderr, "%u unknown state %u!\n", device_id,
device_data->Discovery_State);
break;
}
@@ -911,7 +912,7 @@ static void bacnet_discover_devices_task(void)
for (device_index = 0; device_index < device_count; device_index++) {
device_data = Keylist_Data_Index(Device_List, device_index);
if (!device_data) {
debug_perror("device[%u] is NULL!\n", device_index);
debug_fprintf(stderr, "device[%u] is NULL!\n", device_index);
continue;
}
if (Keylist_Index_Key(Device_List, device_index, &key)) {
+3 -10
View File
@@ -7,7 +7,6 @@
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h"
@@ -169,19 +168,13 @@ int Send_Network_Layer_Message(
"Sending %s message to local BACnet network \n",
bactext_network_layer_msg_name(network_message_type));
}
/* Now send the message */
bytes_sent = datalink_send_pdu(
dst, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
int wasErrno = errno; /* preserve the errno */
debug_printf(
"Failed to send %s message (%s)!\n",
bactext_network_layer_msg_name(network_message_type),
strerror(wasErrno));
debug_perror("Failed to send message");
}
#endif
return bytes_sent;
}
@@ -236,7 +229,7 @@ void Send_Reject_Message_To_Network(
iArgs[1] = dnet;
Send_Network_Layer_Message(
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[]
+8 -10
View File
@@ -21,17 +21,14 @@
#include "bacnet/rp.h"
#include "bacnet/wp.h"
#include "bacnet/cov.h"
/* basic objects and services */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/debug.h"
/* me! */
#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_Inactive_Text = "Inactive";
struct object_data {
@@ -1732,7 +1729,7 @@ int Binary_Input_Alarm_Summary(
struct object_data *pObject = Binary_Input_Object_Index(index);
if (getalarm_data == NULL) {
PRINT(
debug_printf(
"[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__,
__LINE__, (void *)getalarm_data);
return -2;
@@ -1919,7 +1916,8 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
pObject->Ack_notify_data.bSendAckNotify = false;
/* copy toState */
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");
/* Notify Type */
@@ -1999,7 +1997,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
default:
break;
} /* switch (ToState) */
PRINT(
debug_printf(
"Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n",
object_instance, bactext_event_state_name(FromState),
bactext_event_state_name(ToState));
@@ -2112,7 +2110,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
}
/* add data from notification class */
PRINT(
debug_printf(
"Binary-Input[%d]: Notification Class[%d]-%s "
"%u/%u/%u-%u:%u:%u.%u!\n",
object_instance, event_data.notificationClass,
@@ -2129,7 +2127,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(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) {
case EVENT_STATE_OFFNORMAL:
pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL]
+16 -18
View File
@@ -21,17 +21,14 @@
#include "bacnet/wp.h"
#include "bacnet/rp.h"
#include "bacnet/cov.h"
/* basic objects and services */
#include "bacnet/basic/services.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/debug.h"
/* me! */
#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_Inactive_Text = "Inactive";
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
* @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(
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
*
* @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_code - BACnet Error code
*
@@ -592,7 +589,7 @@ bool Binary_Value_Object_Name(
if (pObject) {
if (pObject->Object_Name == NULL) {
snprintf(
text, sizeof(text), "BINARY INPUT %lu",
text, sizeof(text), "BINARY VALUE %lu",
(unsigned long)object_instance);
status = characterstring_init_ansi(object_name, text);
} 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
* @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)
{
@@ -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)
{
@@ -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)
{
@@ -1747,7 +1744,7 @@ int Binary_Value_Alarm_Summary(
struct object_data *pObject = Binary_Value_Object_Index(index);
if (getalarm_data == NULL) {
PRINT(
debug_printf(
"[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__,
__LINE__, (void *)getalarm_data);
return -2;
@@ -1942,7 +1939,8 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
pObject->Ack_notify_data.bSendAckNotify = false;
/* copy toState */
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");
/* Notify Type */
@@ -2022,8 +2020,8 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
default:
break;
} /* switch (ToState) */
PRINT(
"Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n",
debug_printf(
"Binary-Value[%d]: Event_State goes from %.128s to %.128s.\n",
object_instance, bactext_event_state_name(FromState),
bactext_event_state_name(ToState));
/* Notify Type */
@@ -2135,7 +2133,7 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
}
/* add data from notification class */
PRINT(
debug_printf(
"Binary-Value[%d]: Notification Class[%d]-%s "
"%u/%u/%u-%u:%u:%u.%u!\n",
object_instance, event_data.notificationClass,
@@ -2152,7 +2150,7 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(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) {
case EVENT_STATE_OFFNORMAL:
pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL]
+3 -4
View File
@@ -20,14 +20,13 @@
#include "bacnet/bacapp.h"
#include "bacnet/bactext.h"
#include "bacnet/proplist.h"
/* basic objects and services */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/sys/keylist.h"
/* me! */
#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 */
static OS_Keylist Object_List = NULL;
+4 -5
View File
@@ -19,6 +19,7 @@
#include "bacnet/datetime.h"
#include "bacnet/event.h"
#include "bacnet/wp.h"
/* basic objects and services */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/nc.h"
#include "bacnet/basic/binding/address.h"
@@ -27,8 +28,6 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
#define PRINTF debug_perror
#ifndef MAX_NOTIFICATION_CLASSES
#define MAX_NOTIFICATION_CLASSES 2
#endif
@@ -682,7 +681,7 @@ void Notification_Class_common_reporting_function(
}
/* send notifications for active recipients */
PRINTF(
debug_printf_stderr(
"Notification Class[%u]: send notifications\n",
event_data->notificationClass);
/* pointer to first recipient */
@@ -703,7 +702,7 @@ void Notification_Class_common_reporting_function(
if (pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_DEVICE) {
/* send notification to the specified device */
device_id = pBacDest->Recipient.type.device.instance;
PRINTF(
debug_printf_stderr(
"Notification Class[%u]: send notification to %u\n",
event_data->notificationClass, (unsigned)device_id);
if (pBacDest->ConfirmedNotify == true) {
@@ -713,7 +712,7 @@ void Notification_Class_common_reporting_function(
}
} else if (
pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_ADDRESS) {
PRINTF(
debug_printf_stderr(
"Notification Class[%u]: send notification to ADDR\n",
event_data->notificationClass);
/* send notification to the address indicated */
+20 -52
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -22,9 +21,11 @@
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/alarm_ack.h"
#include "bacnet/reject.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/services.h"
#include "bacnet/datalink/datalink.h"
@@ -64,9 +65,7 @@ void handler_alarm_ack(
{
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
int ack_result = 0;
BACNET_ADDRESS my_address;
BACNET_NPDU_DATA npdu_data;
@@ -75,51 +74,43 @@ void handler_alarm_ack(
/* encode the NPDU portion of the packet */
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(
&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 */
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Ack: Segmented message. Sending Abort!\n");
#endif
debug_print("Alarm Ack: Segmented message. Sending Abort!\n");
goto AA_ABORT;
}
len = alarm_ack_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
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) {
/* bad decoding - send an abort */
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Ack: Bad Encoding. Sending Abort!\n");
#endif
debug_print("Alarm Ack: Bad Encoding. Sending Abort!\n");
goto AA_ABORT;
}
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Alarm Ack Operation: Received acknowledge for object id (%d, %lu) "
"from %s for process id %lu \n",
data.eventObjectIdentifier.type,
(unsigned long)data.eventObjectIdentifier.instance,
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(
data.eventObjectIdentifier.type,
data.eventObjectIdentifier.instance)) {
@@ -130,18 +121,12 @@ void handler_alarm_ack(
} else if (Alarm_Ack[data.eventObjectIdentifier.type]) {
ack_result =
Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code);
switch (ack_result) {
case 1:
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM);
#if PRINT_ENABLED
fprintf(
stderr,
"Alarm Acknowledge: "
"Sending Simple Ack!\n");
#endif
debug_print("Alarm Acknowledge: Sending Simple Ack!\n");
break;
case -1:
@@ -149,20 +134,16 @@ void handler_alarm_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
error_code);
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(error_code));
#endif
break;
default:
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: abort other!\n");
#endif
debug_print("Alarm Acknowledge: abort other!\n");
break;
}
} else {
@@ -170,29 +151,16 @@ void handler_alarm_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
ERROR_CODE_NO_ALARM_CONFIGURED);
#if PRINT_ENABLED
fprintf(
stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED));
#endif
debug_print("Alarm Acknowledge: No Alarm Configured!\n");
}
AA_ABORT:
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(
stderr,
"Alarm Acknowledge: "
"Failed to send PDU (%s)!\n",
strerror(errno));
debug_perror("Alarm Acknowledge: Failed to send PDU");
}
#endif
return;
}
+20 -25
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -18,6 +17,7 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/arf.h"
/* basic objects, services, TSM, and datalink */
#if defined(BACFILE)
@@ -25,6 +25,7 @@
#endif
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/*
@@ -100,16 +101,20 @@ void handler_atomic_read_file(
#endif
/* encode the NPDU portion of the packet */
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(
&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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n");
#endif
debug_print("ARF: Segmented Message. Sending Abort!\n");
goto ARF_ABORT;
}
len = arf_decode_service_request(service_request, service_len, &data);
@@ -118,9 +123,7 @@ void handler_atomic_read_file(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
debug_print("ARF: Bad Encoding. Sending Abort!\n");
goto ARF_ABORT;
}
if (data.object_type == OBJECT_FILE) {
@@ -130,12 +133,10 @@ void handler_atomic_read_file(
if (data.type.stream.requestedOctetCount <=
octetstring_capacity(&data.fileData[0])) {
bacfile_read_stream_data(&data);
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr, "ARF: Stream offset %d, %d octets.\n",
(int)data.type.stream.fileStartPosition,
(int)data.type.stream.requestedOctetCount);
#endif
len = arf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data);
@@ -143,12 +144,12 @@ void handler_atomic_read_file(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(
stderr, "Too Big To Send (%d >= %d). Sending Abort!\n",
debug_fprintf(
stderr,
"ARF: Too Big To Send (%d >= %d). "
"Sending Abort!\n",
(int)data.type.stream.requestedOctetCount,
(int)octetstring_capacity(&data.fileData[0]));
#endif
}
} else if (data.access == FILE_RECORD_ACCESS) {
if (data.type.record.fileStartRecord >=
@@ -157,12 +158,10 @@ void handler_atomic_read_file(
error_code = ERROR_CODE_INVALID_FILE_START_POSITION;
error = true;
} else if (bacfile_read_stream_data(&data)) {
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr, "ARF: fileStartRecord %d, %u RecordCount.\n",
(int)data.type.record.fileStartRecord,
(unsigned)data.type.record.RecordCount);
#endif
len = arf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data);
@@ -175,9 +174,7 @@ void handler_atomic_read_file(
error = true;
error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD;
#if PRINT_ENABLED
fprintf(stderr, "Record Access Requested. Sending Error!\n");
#endif
debug_print("ARF: Record Access Requested. Sending Error!\n");
}
} else {
error = true;
@@ -193,11 +190,9 @@ ARF_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("ARF: Failed to send PDU");
}
#endif
return;
}
+17 -24
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -19,11 +18,13 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/awf.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
#if defined(BACFILE)
#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_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
#if PRINT_ENABLED
fprintf(stderr, "Received AtomicWriteFile Request!\n");
#endif
debug_print("Received AtomicWriteFile Request!\n");
/* encode the NPDU portion of the packet */
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(
&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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "Segmented Message. Sending Abort!\n");
#endif
debug_print("AWF:Segmented Message. Sending Abort!\n");
goto AWF_ABORT;
}
len = awf_decode_service_request(service_request, service_len, &data);
@@ -98,9 +101,7 @@ void handler_atomic_write_file(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "Bad Encoding. Sending Abort!\n");
#endif
debug_print("AWF: Bad Encoding. Sending Abort!\n");
goto AWF_ABORT;
}
if (data.object_type == OBJECT_FILE) {
@@ -108,12 +109,10 @@ void handler_atomic_write_file(
error = true;
} else if (data.access == FILE_STREAM_ACCESS) {
if (bacfile_write_stream_data(&data)) {
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr, "AWF: Stream offset %d, %d bytes\n",
data.type.stream.fileStartPosition,
(int)octetstring_length(&data.fileData[0]));
#endif
len = awf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data);
@@ -124,12 +123,10 @@ void handler_atomic_write_file(
}
} else if (data.access == FILE_RECORD_ACCESS) {
if (bacfile_write_record_data(&data)) {
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr, "AWF: StartRecord %d, RecordCount %u\n",
data.type.record.fileStartRecord,
data.type.record.returnedRecordCount);
#endif
len = awf_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data);
@@ -142,9 +139,7 @@ void handler_atomic_write_file(
error = true;
error_class = ERROR_CLASS_SERVICES;
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD;
#if PRINT_ENABLED
fprintf(stderr, "Record Access Requested. Sending Error!\n");
#endif
debug_print("AWF: Record Access Requested. Sending Error!\n");
}
} else {
error = true;
@@ -160,11 +155,9 @@ AWF_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("AWF: Failed to send PDU\n");
}
#endif
return;
}
+49 -36
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -17,6 +16,7 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/cov.h"
#include "bacnet/bactext.h"
/* basic services, TSM, and datalink */
@@ -25,8 +25,6 @@
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
#define PRINTF debug_perror
/* max number of COV properties decoded in a COV notification */
#ifndef MAX_COV_PROPERTIES
#define MAX_COV_PROPERTIES 2
@@ -74,6 +72,41 @@ void handler_ccov_notification_add(BACNET_COV_NOTIFICATION *cb)
} 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.
* @ingroup DSCOV
@@ -97,7 +130,6 @@ void handler_ccov_notification(
BACNET_NPDU_DATA npdu_data;
BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
@@ -109,15 +141,21 @@ void handler_ccov_notification(
cov_data.listOfValues = &property_value[0];
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
PRINTF("CCOV: Received Notification!\n");
if (service_data->segmented_message) {
debug_print("CCOV: Received Notification!\n");
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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
PRINTF("CCOV: Segmented message. Sending Abort!\n");
debug_print("CCOV: Segmented message. Sending Abort!\n");
goto CCOV_ABORT;
}
/* decode the service request only */
@@ -125,52 +163,27 @@ void handler_ccov_notification(
service_request, service_len, &cov_data);
if (len > 0) {
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 */
if (len <= 0) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
PRINTF("CCOV: Bad Encoding. Sending Abort!\n");
debug_print("CCOV: Bad Encoding. Sending Abort!\n");
goto CCOV_ABORT;
} else {
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_COV_NOTIFICATION);
PRINTF("CCOV: Sending Simple Ack!\n");
debug_print("CCOV: Sending Simple Ack!\n");
}
CCOV_ABORT:
pdu_len += len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
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;
}
+3
View File
@@ -23,6 +23,9 @@ extern "C" {
BACNET_STACK_EXPORT
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
void handler_ccov_notification(
uint8_t *service_request,
+16 -30
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -29,6 +28,7 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
#ifndef MAX_COV_PROPERTIES
@@ -820,24 +820,25 @@ void handler_cov_subscribe(
cov_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
/* encode the NPDU portion of the packet */
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(
&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 */
len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Segmented message. Sending Abort!\n");
#endif
debug_print("SubscribeCOV: Segmented message. Sending Abort!\n");
error = true;
} else {
len = cov_subscribe_decode_service_request(
service_request, service_len, &cov_data);
#if PRINT_ENABLED
if (len <= 0) {
fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n");
debug_print("SubscribeCOV: Unable to decode Request!\n");
}
#endif
if (len < 0) {
error = true;
} else {
@@ -849,54 +850,39 @@ void handler_cov_subscribe(
apdu_len = encode_simple_ack(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_SUBSCRIBE_COV);
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n");
#endif
debug_print("SubscribeCOV: Sending Simple Ack!\n");
} else {
len = BACNET_STATUS_ERROR;
error = true;
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
#endif
debug_print("SubscribeCOV: Sending Error!\n");
}
}
}
/* Error? */
if (error) {
if (len == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(cov_data.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Abort!\n");
#endif
debug_print("SubscribeCOV: Sending Abort!\n");
} else if (len == BACNET_STATUS_ERROR) {
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_SUBSCRIBE_COV, cov_data.error_class,
cov_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
#endif
debug_print("SubscribeCOV: Sending Error!\n");
} else if (len == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(cov_data.error_code));
#if PRINT_ENABLED
fprintf(stderr, "SubscribeCOV: Sending Reject!\n");
#endif
debug_print("SubscribeCOV: Sending Reject!\n");
}
}
pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "SubscribeCOV: Failed to send PDU (%s)!\n",
strerror(errno));
#endif
debug_perror("SubscribeCOV: Failed to send PDU");
}
return;
+18 -13
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -60,15 +59,22 @@ void handler_create_object(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("CreateObject: Received Request!\n");
if (service_data->segmented_message) {
debug_print("CreateObject: Received Request!\n");
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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("CreateObject: Segmented message. Sending Abort!\n");
debug_print("CreateObject: Segmented message. Sending Abort!\n");
status = false;
}
if (status) {
@@ -76,12 +82,12 @@ void handler_create_object(
len = create_object_decode_service_request(
service_request, service_len, &data);
if (len > 0) {
debug_perror(
debug_printf_stderr(
"CreateObject: type=%lu instance=%lu\n",
(unsigned long)data.object_type,
(unsigned long)data.object_instance);
} else {
debug_perror("CreateObject: Unable to decode request!\n");
debug_print("CreateObject: Unable to decode request!\n");
}
if (len <= 0) {
/* bad decoding or something we didn't understand */
@@ -89,24 +95,24 @@ void handler_create_object(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
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) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
reject_convert_error_code(data.error_code));
debug_perror("CreateObject: Sending Reject!\n");
debug_print("CreateObject: Sending Reject!\n");
}
} else {
if (Device_Create_Object(&data)) {
len = create_object_ack_encode(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data);
debug_perror("CreateObject: Sending ACK!\n");
debug_print("CreateObject: Sending ACK!\n");
} else {
len = create_object_error_ack_encode(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&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);
}
if (bytes_sent <= 0) {
debug_perror(
"CreateObject: Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("CreateObject: Failed to send PDU");
}
return;
+21 -58
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h"
#include "bacnet/bacerror.h"
@@ -22,6 +21,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/* 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 */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "DeviceCommunicationControl!\n");
#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) {
debug_print("DeviceCommunicationControl!\n");
if (service_len == 0) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_MISSING_REQUIRED_PARAMETER);
#if PRINT_ENABLED
fprintf(stderr, "DCC: Sending Reject!\n");
#endif
debug_print("DeviceCommunicationControl: "
"Missing Required Parameter. Sending Reject!\n");
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;
}
/* decode the service request only */
len = dcc_decode_service_request(
service_request, service_len, &timeDuration, &state, &password);
#if PRINT_ENABLED
if (len > 0) {
fprintf(
debug_fprintf(
stderr,
"DeviceCommunicationControl: "
"timeout=%u state=%u password=%s\n",
(unsigned)timeDuration, (unsigned)state,
characterstring_value(&password));
}
#endif
/* bad decoding or invalid service parameter
send an abort or reject */
if (len < 0) {
@@ -145,16 +134,12 @@ void handler_device_communication_control(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "DCC: Sending Abort!\n");
#endif
debug_print("DCC: Sending Abort!\n");
} else if (len == BACNET_STATUS_REJECT) {
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_PARAMETER_OUT_OF_RANGE);
#if PRINT_ENABLED
fprintf(stderr, "DCC: Sending Reject!\n");
#endif
debug_print("DCC: Sending Reject!\n");
}
goto DCC_FAILURE;
}
@@ -167,12 +152,8 @@ void handler_device_communication_control(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SERVICES, ERROR_CODE_SERVICE_REQUEST_DENIED);
#if PRINT_ENABLED
fprintf(
stderr,
"DeviceCommunicationControl: "
debug_print("DeviceCommunicationControl: "
"Sending Error - DISABLE has been deprecated.\n");
#endif
goto DCC_FAILURE;
}
#endif
@@ -180,12 +161,8 @@ void handler_device_communication_control(
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED
fprintf(
stderr,
"DeviceCommunicationControl: "
debug_print("DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n");
#endif
} else {
#ifdef BAC_ROUTING
/* Check to see if the current Device supports this service. */
@@ -201,24 +178,16 @@ void handler_device_communication_control(
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
#if PRINT_ENABLED
fprintf(
stderr,
"DeviceCommunicationControl: "
debug_print("DeviceCommunicationControl: "
"Sending Simple Ack!\n");
#endif
dcc_set_status_duration(state, timeDuration);
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
ERROR_CLASS_SECURITY, ERROR_CODE_PASSWORD_FAILURE);
#if PRINT_ENABLED
fprintf(
stderr,
"DeviceCommunicationControl: "
debug_print("DeviceCommunicationControl: "
"Sending Error - password failure.\n");
#endif
}
}
DCC_FAILURE:
@@ -226,13 +195,7 @@ DCC_FAILURE:
len = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (len <= 0) {
#if PRINT_ENABLED
fprintf(
stderr,
"DeviceCommunicationControl: "
"Failed to send PDU (%s)!\n",
strerror(errno));
#endif
debug_perror("DeviceCommunicationControl: Failed to send PDU");
}
return;
+18 -12
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -60,15 +59,23 @@ void handler_delete_object(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("DeleteObject: Received Request!\n");
if (service_data->segmented_message) {
debug_print("DeleteObject: Received Request!\n");
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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("DeleteObject: Segmented message. Sending Abort!\n");
debug_print("DeleteObject: Segmented message. "
"Sending Abort!\n");
status = false;
}
if (status) {
@@ -76,19 +83,19 @@ void handler_delete_object(
len = delete_object_decode_service_request(
service_request, service_len, &data);
if (len > 0) {
debug_perror(
debug_printf_stderr(
"DeleteObject: type=%lu instance=%lu\n",
(unsigned long)data.object_type,
(unsigned long)data.object_instance);
} 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 */
if (len <= 0) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
debug_perror("DeleteObject: Bad Encoding. Sending Abort!\n");
debug_print("DeleteObject: Bad Encoding. Sending Abort!\n");
status = false;
}
if (status) {
@@ -96,13 +103,13 @@ void handler_delete_object(
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DELETE_OBJECT);
debug_perror("DeleteObject: Sending Simple Ack!\n");
debug_print("DeleteObject: Sending Simple Ack!\n");
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_DELETE_OBJECT, data.error_class,
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);
}
if (bytes_sent <= 0) {
debug_perror(
"DeleteObject: Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("DeleteObject: Failed to send PDU");
}
return;
+17 -24
View File
@@ -17,9 +17,11 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
/* basic services, TSM, and datalink */
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
static get_alarm_summary_function Get_Alarm_Summary[MAX_BACNET_OBJECT_TYPE];
@@ -54,20 +56,25 @@ void handler_get_alarm_summary(
(void)service_len;
/* encode the NPDU portion of the packet */
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(
&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 */
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "GetAlarmSummary: Segmented message. Sending Abort!\n");
#endif
debug_print("GetAlarmSummary: Segmented message. "
"Sending Abort!\n");
goto GET_ALARM_SUMMARY_ABORT;
}
/* init header */
apdu_len = get_alarm_summary_ack_encode_apdu_init(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id);
@@ -92,11 +99,7 @@ void handler_get_alarm_summary(
}
}
}
#if PRINT_ENABLED
fprintf(stderr, "GetAlarmSummary: Sending response!\n");
#endif
debug_print("GetAlarmSummary: Sending response!\n");
GET_ALARM_SUMMARY_ERROR:
if (error) {
if (len == BACNET_STATUS_ABORT) {
@@ -104,32 +107,22 @@ GET_ALARM_SUMMARY_ERROR:
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(
stderr, "GetAlarmSummary: Reply too big to fit into APDU!\n");
#endif
debug_print("GetAlarmSummary: Reply too big to fit into APDU!\n");
} else {
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_GET_ALARM_SUMMARY, ERROR_CLASS_PROPERTY,
ERROR_CODE_OTHER);
#if PRINT_ENABLED
fprintf(stderr, "GetAlarmSummary: Sending Error!\n");
#endif
debug_print("GetAlarmSummary: Sending Error!\n");
}
}
GET_ALARM_SUMMARY_ABORT:
pdu_len += apdu_len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
/*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */
debug_perror("GetAlarmSummary: Failed to send PDU");
}
#else
(void)bytes_sent;
#endif
return;
}
+33 -32
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -18,17 +17,22 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/event.h"
#include "bacnet/getevent.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
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(
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);
}
/**
* @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(
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(
uint8_t *service_request,
uint16_t service_len,
@@ -68,9 +90,7 @@ void handler_get_event_information(
BACNET_NPDU_DATA npdu_data;
bool error = false;
bool more_events = false;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
BACNET_ADDRESS my_address;
@@ -84,7 +104,7 @@ void handler_get_event_information(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) {
@@ -92,15 +112,10 @@ void handler_get_event_information(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(
stderr,
"GetEventInformation: "
debug_print("GetEventInformation: "
"Segmented message. Sending Abort!\n");
#endif
goto GET_EVENT_ABORT;
}
len = getevent_decode_service_request(
service_request, service_len, &object_id);
if (len < 0) {
@@ -108,9 +123,8 @@ void handler_get_event_information(
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "GetEventInformation: Bad Encoding. Sending Abort!\n");
#endif
debug_print("GetEventInformation: Bad Encoding. "
"Sending Abort!\n");
goto GET_EVENT_ABORT;
}
len = getevent_ack_encode_apdu_init(
@@ -182,9 +196,7 @@ void handler_get_event_information(
error = true;
goto GET_EVENT_ERROR;
}
#if PRINT_ENABLED
fprintf(stderr, "Got a GetEventInformation request: Sending Ack!\n");
#endif
debug_print("Got a GetEventInformation request: Sending Ack!\n");
GET_EVENT_ERROR:
if (error) {
pdu_len = npdu_encode_pdu(
@@ -195,33 +207,22 @@ GET_EVENT_ERROR:
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(
stderr,
"GetEventInformation: "
debug_print("GetEventInformation: "
"Reply too big to fit into APDU!\n");
#endif
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
#if PRINT_ENABLED
fprintf(stderr, "GetEventInformation: Sending Error!\n");
#endif
debug_print("GetEventInformation: Sending Error!\n");
}
}
GET_EVENT_ABORT:
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("GetEventInformation: Failed to send PDU");
}
#endif
return;
}
+36 -23
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -18,6 +17,7 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/list_element.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h"
@@ -59,15 +59,23 @@ void handler_add_list_element(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("AddListElement: Received Request!\n");
if (service_data->segmented_message) {
debug_print("AddListElement: Received Request!\n");
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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("AddListElement: Segmented message. Sending Abort!\n");
debug_print("AddListElement: Segmented message. "
"Sending Abort!\n");
status = false;
}
if (status) {
@@ -75,7 +83,7 @@ void handler_add_list_element(
len = list_element_decode_service_request(
service_request, service_len, &list_element);
if (len > 0) {
debug_perror(
debug_printf_stderr(
"AddListElement: type=%lu instance=%lu property=%lu "
"index=%ld\n",
(unsigned long)list_element.object_type,
@@ -83,14 +91,14 @@ void handler_add_list_element(
(unsigned long)list_element.object_property,
(long)list_element.array_index);
} 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 */
if (len <= 0) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
debug_perror("AddListElement: Bad Encoding. Sending Abort!\n");
debug_print("AddListElement: Bad Encoding. Sending Abort!\n");
status = false;
}
if (status) {
@@ -98,13 +106,13 @@ void handler_add_list_element(
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ADD_LIST_ELEMENT);
debug_perror("AddListElement: Sending Simple Ack!\n");
debug_print("AddListElement: Sending Simple Ack!\n");
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_ADD_LIST_ELEMENT,
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(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_perror(
"AddListElement: Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("AddListElement: Failed to send PDU");
}
return;
@@ -153,15 +160,22 @@ void handler_remove_list_element(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
debug_perror("RemoveListElement: Received Request!\n");
if (service_data->segmented_message) {
debug_print("RemoveListElement: Received Request!\n");
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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
debug_perror("RemoveListElement: Segmented message. Sending Abort!\n");
debug_print("RemoveListElement: Segmented message. Sending Abort!\n");
status = false;
}
if (status) {
@@ -169,7 +183,7 @@ void handler_remove_list_element(
len = list_element_decode_service_request(
service_request, service_len, &list_element);
if (len > 0) {
debug_perror(
debug_printf_stderr(
"RemoveListElement: type=%lu instance=%lu "
"property=%lu index=%ld\n",
(unsigned long)list_element.object_type,
@@ -177,14 +191,14 @@ void handler_remove_list_element(
(unsigned long)list_element.object_property,
(long)list_element.array_index);
} 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 */
if (len <= 0) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
debug_perror("RemoveListElement: Bad Encoding. Sending Abort!\n");
debug_print("RemoveListElement: Bad Encoding. Sending Abort!\n");
status = false;
}
if (status) {
@@ -192,13 +206,13 @@ void handler_remove_list_element(
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT);
debug_perror("RemoveListElement: Sending Simple Ack!\n");
debug_print("RemoveListElement: Sending Simple Ack!\n");
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT,
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(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_perror(
"RemoveListElement: Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("RemoveListElement: Failed to send PDU");
}
return;
+17 -35
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -17,11 +16,13 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/lso.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
void handler_lso(
@@ -34,82 +35,63 @@ void handler_lso(
int len = 0;
int pdu_len = 0;
BACNET_NPDU_DATA npdu_data;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_ADDRESS my_address;
/* encode the NPDU portion of the packet */
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(
&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 */
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "LSO: Segmented message. Sending Abort!\n");
#endif
debug_print("LSO: Segmented message. Sending Abort!\n");
goto LSO_ABORT;
}
len = lso_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0) {
fprintf(stderr, "LSO: Unable to decode Request!\n");
debug_print("LSO: Unable to decode Request!\n");
}
#endif
if (len < 0) {
/* bad decoding - send an abort */
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "LSO: Bad Encoding. Sending Abort!\n");
#endif
debug_print("LSO: Bad Encoding. Sending Abort!\n");
goto LSO_ABORT;
}
/*
** Process Life Safety Operation Here
*/
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Life Safety Operation: Received operation %d from process id %lu "
"for object %lu\n",
data.operation, (unsigned long)data.processId,
(unsigned long)data.targetObject.instance);
#endif
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
#if PRINT_ENABLED
fprintf(
stderr,
"Life Safety Operation: "
debug_print("Life Safety Operation: "
"Sending Simple Ack!\n");
#endif
LSO_ABORT:
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(
stderr,
"Life Safety Operation: "
"Failed to send PDU (%s)!\n",
strerror(errno));
debug_perror("Life Safety Operation: Failed to send PDU");
}
#endif
return;
}
+4 -8
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -21,6 +20,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** 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 */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
@@ -63,12 +63,8 @@ void handler_unrecognized_service(
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent > 0) {
#if PRINT_ENABLED
fprintf(stderr, "Sent Reject!\n");
#endif
debug_print("Sent Reject!\n");
} else {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno));
#endif
debug_perror("Failed to Send Reject");
}
}
+19 -34
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -24,6 +23,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** Handler for a Reinitialize Device (RD) request.
@@ -60,45 +60,42 @@ void handler_reinitialize_device(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice!\n");
#endif
if (service_data->segmented_message) {
debug_print("ReinitializeDevice!\n");
if (service_len == 0) {
len = reject_encode_apdu(
&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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(
stderr, "ReinitializeDevice: Sending Abort - segmented message.\n");
#endif
debug_print("ReinitializeDevice: Sending Abort - segmented message.\n");
goto RD_ABORT;
}
/* decode the service request only */
len = rd_decode_service_request(
service_request, service_len, &rd_data.state, &rd_data.password);
#if PRINT_ENABLED
if (len > 0) {
fprintf(
debug_fprintf(
stderr, "ReinitializeDevice: state=%u password=%*s\n",
(unsigned)rd_data.state,
(int)characterstring_length(&rd_data.password),
characterstring_value(&rd_data.password));
} 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 */
if (len < 0) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(
stderr, "ReinitializeDevice: Sending Abort - could not decode.\n");
#endif
debug_print("ReinitializeDevice: Sending Abort - could not decode.\n");
goto RD_ABORT;
}
/* check the data from the request */
@@ -106,11 +103,8 @@ void handler_reinitialize_device(
len = reject_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
REJECT_REASON_UNDEFINED_ENUMERATION);
#if PRINT_ENABLED
fprintf(
stderr,
debug_print(
"ReinitializeDevice: Sending Reject - undefined enumeration\n");
#endif
} else {
#ifdef BAC_ROUTING
/* Check to see if the current Device supports this service. */
@@ -121,22 +115,17 @@ void handler_reinitialize_device(
goto RD_ABORT;
}
#endif
if (Device_Reinitialize(&rd_data)) {
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n");
#endif
debug_print("ReinitializeDevice: Sending Simple Ack!\n");
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_REINITIALIZE_DEVICE, rd_data.error_class,
rd_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Sending Error.\n");
#endif
debug_print("ReinitializeDevice: Sending Error.\n");
}
}
RD_ABORT:
@@ -144,11 +133,7 @@ RD_ABORT:
len = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (len <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
strerror(errno));
#endif
debug_perror("ReinitializeDevice: Failed to send PDU");
}
return;
+20 -45
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -28,6 +27,7 @@
#endif
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** @file h_rp.c Handles Read Property requests. */
@@ -77,28 +77,19 @@ void handler_read_property(
if (npdu_len <= 0) {
/* If 0 or negative, there were problems with the data or encoding. */
len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED
fprintf(stderr, "RP: npdu_encode_pdu error. Sending Abort!\n");
#endif
debug_print("RP: npdu_encode_pdu error. Sending Abort!\n");
} else if (service_len == 0) {
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) {
/* we don't support segmentation - send an abort */
len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED
fprintf(stderr, "RP: Segmented message. Sending Abort!\n");
#endif
debug_print("RP: Segmented message. Sending Abort!\n");
} else {
len = rp_decode_service_request(service_request, service_len, &rpdata);
#if PRINT_ENABLED
if (len <= 0) {
fprintf(stderr, "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
debug_print("RP: Unable to decode Request!\n");
} else {
/* When the object-type in the Object Identifier parameter
contains the value DEVICE and the instance in the 'Object
@@ -147,65 +138,49 @@ void handler_read_property(
rpdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
len = BACNET_STATUS_ABORT;
#if PRINT_ENABLED
fprintf(stderr, "RP: Message too large.\n");
#endif
debug_print("RP: Message too large.\n");
} else {
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Ack!\n");
#endif
debug_print("RP: Sending Ack!\n");
error = false;
}
} else {
#if PRINT_ENABLED
fprintf(stderr, "RP: Device_Read_Property: ");
debug_print("RP: Device_Read_Property: ");
if (len == BACNET_STATUS_ABORT) {
fprintf(stderr, "Abort!\n");
debug_print("Abort!\n");
} else if (len == BACNET_STATUS_ERROR) {
fprintf(stderr, "Error!\n");
debug_print("Error!\n");
} else if (len == BACNET_STATUS_REJECT) {
fprintf(stderr, "Reject!\n");
debug_print("Reject!\n");
} else {
fprintf(stderr, "Unknown Len=%d\n", len);
}
#endif
debug_print("Unknown Len!\n");
}
}
}
}
if (error) {
if (len == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
abort_convert_error_code(rpdata.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Abort!\n");
#endif
debug_print("RP: Sending Abort!\n");
} else if (len == BACNET_STATUS_ERROR) {
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROPERTY, rpdata.error_class,
rpdata.error_code);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Error!\n");
#endif
debug_print("RP: Sending Error!\n");
} else if (len == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
reject_convert_error_code(rpdata.error_code));
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Reject!\n");
#endif
debug_print("RP: Sending Reject!\n");
}
}
pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
#endif
debug_perror("RP: Failed to send PDU");
}
return;
+2 -2
View File
@@ -24,8 +24,8 @@
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
#define PRINTF debug_aprintf
#define PRINTF_ERR debug_perror
#define PRINTF debug_printf_stdout
#define PRINTF_ERR debug_printf_stderr
/** For debugging...
* @param [in] data portion of the ACK
+53 -64
View File
@@ -12,7 +12,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -220,20 +219,19 @@ void handler_read_property_multiple(
int npdu_len = 0;
int error = 0;
if (service_data && (service_len > 0)) {
/* 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 */
if (service_data) {
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (service_data->segmented_message) {
if (service_len == 0) {
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;
error = BACNET_STATUS_ABORT;
debug_fprintf(stderr, "RPM: Segmented message. Sending Abort!\r\n");
debug_print("RPM: Segmented message. Sending Abort!\r\n");
} else {
/* decode apdu request & encode apdu reply
encode complex ack, invoke id, service choice */
@@ -250,8 +248,10 @@ void handler_read_property_multiple(
decode_len += len;
} else {
/* bad encoding - skip to error/reject/abort handling */
debug_fprintf(stderr, "RPM: Bad Encoding.\n");
debug_print("RPM: Bad Encoding.\n");
error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break;
}
@@ -276,21 +276,19 @@ void handler_read_property_multiple(
rpmdata.object_instance = Network_Port_Index_To_Instance(0);
}
#endif
/* Stick this object id into the reply - if it will fit */
len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata);
copy_len = memcopy(
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len,
len, MAX_APDU);
if (copy_len == 0) {
debug_fprintf(stderr, "RPM: Response too big!\r\n");
debug_print("RPM: Response too big!\n");
rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
berror = true;
break;
}
apdu_len += copy_len;
/* do each property of this object of the RPM request */
for (;;) {
@@ -300,12 +298,12 @@ void handler_read_property_multiple(
&rpmdata);
if (len < 0) {
/* bad encoding - skip to error/reject/abort handling */
debug_fprintf(stderr, "RPM: Bad Encoding.\n");
debug_print("RPM: Bad Encoding.\n");
error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break; /* The berror flag ensures that both loops will
*/
/* be broken! */
break;
}
decode_len += len;
/* handle the special properties */
@@ -325,8 +323,7 @@ void handler_read_property_multiple(
if (len > 0) {
apdu_len += len;
} else {
debug_fprintf(
stderr, "RPM: Too full for property!\r\n");
debug_print("RPM: Too full for property!\n");
error = len;
/* The berror flag ensures that
both loops will be broken! */
@@ -345,15 +342,15 @@ void handler_read_property_multiple(
&Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) {
debug_fprintf(
stderr,
"RPM: Too full to encode property!\r\n");
debug_print(
"RPM: Too full to encode property!\n");
rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break; /* The berror flag ensures that both */
/* loops will be broken! */
break;
}
apdu_len += len;
@@ -366,15 +363,14 @@ void handler_read_property_multiple(
&Temp_Buf[0], apdu_len, len, MAX_APDU);
if (copy_len == 0) {
debug_fprintf(
stderr,
"RPM: Too full to encode error!\r\n");
debug_print("RPM: Too full to encode error!\n");
rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break; /* The berror flag ensures that both */
/* loops will be broken! */
break;
}
apdu_len += len;
} else {
@@ -386,8 +382,7 @@ void handler_read_property_multiple(
&property_list, special_object_property);
if (property_count == 0) {
/* This only happens with the OPTIONAL property
*/
/* Only happens with the OPTIONAL property */
/* 135-2016bl-2. Clarify ReadPropertyMultiple
response on OPTIONAL when empty. */
/* If no optional properties are supported then
@@ -403,9 +398,8 @@ void handler_read_property_multiple(
if (len > 0) {
apdu_len += len;
} else {
debug_fprintf(
stderr,
"RPM: Too full for property!\r\n");
debug_print(
"RPM: Too full for property!\n");
error = len;
/* The berror flag ensures that
both loops will be broken! */
@@ -426,14 +420,13 @@ void handler_read_property_multiple(
if (len > 0) {
apdu_len += len;
} else {
debug_fprintf(
stderr,
"RPM: Too full for property!\r\n");
debug_print(
"RPM: Too full for property!\n");
error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break; /* The berror flag ensures that
*/
/* both loops will be broken! */
break;
}
}
}
@@ -446,13 +439,13 @@ void handler_read_property_multiple(
if (len > 0) {
apdu_len += len;
} else {
debug_fprintf(
stderr,
"RPM: Too full for individual property!\r\n");
debug_print(
"RPM: Too full for individual property!\n");
error = len;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break; /* The berror flag ensures that both loops */
/* will be broken! */
break;
}
}
@@ -466,21 +459,22 @@ void handler_read_property_multiple(
&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, MAX_APDU);
if (copy_len == 0) {
debug_fprintf(
stderr,
"RPM: Too full to encode object end!\r\n");
debug_print(
"RPM: Too full to encode object end!\n");
rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
/* The berror flag ensures that
both loops will be broken! */
berror = true;
break; /* The berror flag ensures that both loops */
/* will be broken! */
break;
} else {
apdu_len += copy_len;
}
break; /* finished with this property list */
/* finished with this property list */
break;
}
}
} /* for(;;) */
if (berror) {
break;
}
@@ -488,8 +482,7 @@ void handler_read_property_multiple(
/* Reached the end so finish up */
break;
}
} /* for(;;) */
}
/* If not having an error so far, check the remaining space. */
if (!berror) {
if (apdu_len > service_data->max_resp) {
@@ -497,39 +490,35 @@ void handler_read_property_multiple(
rpmdata.error_code =
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
debug_fprintf(
stderr, "RPM: Message too large. Sending Abort!\n");
debug_print("RPM: Message too large. Sending Abort!\n");
}
}
}
/* Error fallback. */
if (error) {
if (error == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
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) {
apdu_len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_READ_PROP_MULTIPLE, rpmdata.error_class,
rpmdata.error_code);
debug_fprintf(stderr, "RPM: Sending Error!\n");
debug_print("RPM: Sending Error!\n");
} else if (error == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
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;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_fprintf(
stderr, "RPM: Failed to send PDU (errno=%d)!\n", errno);
debug_perror("RPM: Failed to send PDU");
}
}
}
+9 -11
View File
@@ -1,10 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief A basic ReadPropertyMultile-Ack service handler
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2008
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
@@ -24,10 +24,8 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
#define PRINTF debug_aprintf
#define PERROR debug_perror
/** @file h_rpm_a.c Handles Read Property Multiple Acknowledgments. */
#define PRINTF debug_printf_stdout
#define PERROR debug_printf_stderr
/** Decode the received RPM data and make a linked list of the results.
* @ingroup DSRPM
+24 -39
View File
@@ -1,15 +1,14 @@
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Handles ReadRange-Request service
* @author Peter Mc Shane <petermcs@users.sourceforge.net>
* @date 2009
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -18,15 +17,15 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/readrange.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** @file h_rr.c Handles Read Range requests. */
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
/**
@@ -116,42 +115,39 @@ void handler_read_range(
int pdu_len = 0;
BACNET_NPDU_DATA npdu_data;
bool error = false;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_ADDRESS my_address;
data.error_class = ERROR_CLASS_OBJECT;
data.error_code = ERROR_CODE_UNKNOWN_OBJECT;
/* encode the NPDU portion of the packet */
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(
&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 */
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "RR: Segmented message. Sending Abort!\n");
#endif
debug_print("RR: Segmented message. Sending Abort!\n");
} else {
memset(&data, 0, sizeof(data)); /* start with blank canvas */
len = rr_decode_service_request(service_request, service_len, &data);
#if PRINT_ENABLED
if (len <= 0) {
fprintf(stderr, "RR: Unable to decode Request!\n");
debug_print("RR: Unable to decode Request!\n");
}
#endif
if (len < 0) {
/* bad decoding - send an abort */
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n");
#endif
debug_print("RR: Bad Encoding. Sending Abort!\n");
} else {
/* assume that there is an error */
error = true;
@@ -164,9 +160,7 @@ void handler_read_range(
len = rr_ack_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
&data);
#if PRINT_ENABLED
fprintf(stderr, "RR: Sending Ack!\n");
#endif
debug_print("RR: Sending Ack!\n");
error = false;
}
if (error) {
@@ -177,33 +171,24 @@ void handler_read_range(
&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "RR: Reply too big to fit into APDU!\n");
#endif
debug_print("RR: Reply too big to fit into APDU!\n");
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE,
data.error_class, data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "RR: Sending Error!\n");
#endif
debug_print("RR: Sending Error!\n");
}
}
}
}
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
debug_perror("RR: Failed to send PDU");
}
#endif
return;
}
+44 -38
View File
@@ -1,15 +1,14 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Handles Unconfirmed COV Notifications.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date December 2010
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -23,9 +22,6 @@
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
/** @file h_ucov.c Handles Unconfirmed COV Notifications. */
#define PRINTF debug_perror
#ifndef MAX_COV_PROPERTIES
#define MAX_COV_PROPERTIES 2
#endif
@@ -72,6 +68,41 @@ void handler_ucov_notification_add(BACNET_COV_NOTIFICATION *cb)
} 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.
* @ingroup DSCOV
@@ -89,7 +120,6 @@ void handler_ucov_notification(
{
BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
int len = 0;
/* src not needed for this application */
@@ -98,37 +128,13 @@ void handler_ucov_notification(
than one property value is expected */
bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES);
cov_data.listOfValues = &property_value[0];
PRINTF("UCOV: Received Notification!\n");
debug_print("UCOV: Received Notification!\n");
/* decode the service request only */
len = cov_notify_decode_service_request(
service_request, service_len, &cov_data);
if (len > 0) {
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 {
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
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
void handler_ucov_notification(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src);
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
+18 -28
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -18,11 +17,13 @@
#include "bacnet/apdu.h"
#include "bacnet/npdu.h"
#include "bacnet/abort.h"
#include "bacnet/reject.h"
#include "bacnet/wp.h"
/* basic objects, services, TSM, and datalink */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** @file h_wp.c Handles Write Property requests. */
@@ -61,28 +62,28 @@ void handler_write_property(
/* encode the NPDU portion of the packet */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
#if PRINT_ENABLED
fprintf(stderr, "WP: Received Request!\n");
#endif
if (service_data->segmented_message) {
debug_print("WP: Received Request!\n");
if (service_len == 0) {
len = reject_encode_apdu(
&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(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
#endif
debug_print("WP: Segmented message. Sending Abort!\n");
bcontinue = false;
}
if (bcontinue) {
/* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
#if PRINT_ENABLED
if (len > 0) {
fprintf(
debug_fprintf(
stderr,
"WP: type=%lu instance=%lu property=%lu priority=%lu "
"index=%ld\n",
@@ -91,48 +92,37 @@ void handler_write_property(
(unsigned long)wp_data.object_property,
(unsigned long)wp_data.priority, (long)wp_data.array_index);
} 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 */
if (len <= 0) {
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
#endif
debug_print("WP: Bad Encoding. Sending Abort!\n");
bcontinue = false;
}
if (bcontinue) {
if (Device_Write_Property(&wp_data)) {
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Simple Ack!\n");
#endif
debug_print("WP: Sending Simple Ack!\n");
} else {
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, wp_data.error_class,
wp_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Error!\n");
#endif
debug_print("WP: Sending Error!\n");
}
}
}
/* Send PDU */
pdu_len += len;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
#endif
debug_perror("WP: Failed to send PDU");
}
return;
+24 -22
View File
@@ -1,15 +1,14 @@
/**************************************************************************
*
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Handles WritePropertyMultiple-Request service
* @author Krzysztof Malorny <malornykrzysztof@gmail.com>
* @date 2011
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
@@ -28,9 +27,6 @@
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** @file h_wpm.c Handles Write Property Multiple requests. */
#define PRINTF debug_perror
/** Decoding for an object property.
*
* @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);
if (len > 0) {
offset += len;
PRINTF(
debug_printf_stderr(
"WPM: type=%lu instance=%lu property=%lu "
"priority=%lu index=%ld\n",
(unsigned long)wp_data->object_type,
@@ -91,7 +87,7 @@ static int write_property_multiple_decode(
}
}
} else {
PRINTF("WPM: Bad Encoding!\n");
debug_printf_stderr("WPM: Bad Encoding!\n");
return len;
}
/* Closing tag 1 - List of Properties */
@@ -106,7 +102,7 @@ static int write_property_multiple_decode(
} while (tag_number != 1);
}
} else {
PRINTF("WPM: Bad Encoding!\n");
debug_printf_stderr("WPM: Bad Encoding!\n");
return len;
}
} while (offset < apdu_len);
@@ -146,10 +142,16 @@ void handler_write_property_multiple(
BACNET_ADDRESS my_address;
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;
len = BACNET_STATUS_ABORT;
PRINTF("WPM: Segmented message. Sending Abort!\n");
debug_print("WPM: Segmented message. "
"Sending Abort!\n");
} else {
/* first time - detect malformed request before writing any data */
len = write_property_multiple_decode(
@@ -161,36 +163,36 @@ void handler_write_property_multiple(
}
/* encode the confirmed reply */
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(
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
if (len > 0) {
apdu_len = wpm_ack_encode_apdu_init(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id);
PRINTF("WPM: Sending Ack!\n");
debug_print("WPM: Sending Ack!\n");
} else {
/* handle any errors */
if (len == BACNET_STATUS_ABORT) {
apdu_len = abort_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
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) {
apdu_len = wpm_error_ack_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
&wp_data);
PRINTF("WPM: Sending Error!\n");
debug_print("WPM: Sending Error!\n");
} else if (len == BACNET_STATUS_REJECT) {
apdu_len = reject_encode_apdu(
&Handler_Transmit_Buffer[npdu_len], service_data->invoke_id,
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;
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
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 <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -7,7 +7,6 @@
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"

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