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
+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 */
+21 -53
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(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
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;
+25 -62
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: "
"Sending Error - DISABLE has been deprecated.\n");
#endif
debug_print("DeviceCommunicationControl: "
"Sending Error - DISABLE has been deprecated.\n");
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: "
"Sending Reject - undefined enumeration\n");
#endif
debug_print("DeviceCommunicationControl: "
"Sending Reject - undefined enumeration\n");
} 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: "
"Sending Simple Ack!\n");
#endif
debug_print("DeviceCommunicationControl: "
"Sending Simple Ack!\n");
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: "
"Sending Error - password failure.\n");
#endif
debug_print("DeviceCommunicationControl: "
"Sending Error - password failure.\n");
}
}
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;
}
+36 -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 */
@@ -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: "
"Segmented message. Sending Abort!\n");
#endif
debug_print("GetEventInformation: "
"Segmented message. Sending Abort!\n");
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: "
"Reply too big to fit into APDU!\n");
#endif
debug_print("GetEventInformation: "
"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_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(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
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;
+19 -37
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: "
"Sending Simple Ack!\n");
#endif
debug_print("Life Safety Operation: "
"Sending Simple Ack!\n");
LSO_ABORT:
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
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;
+19 -44
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);
debug_print("Unknown Len!\n");
}
#endif
}
}
}
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
+25 -40
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(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
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"
+10 -16
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2009 John Minack <minack@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send an Alarm Acknowledgment.
* @author John Minack <minack@users.sourceforge.net>
* @date 2009
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -26,9 +25,6 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_ack_alarm.c Send an Alarm Acknowledgment. */
#define PRINTF debug_perror
/** Sends an Confirmed Alarm Acknowledgment.
*
* @param pdu [in] the PDU buffer used for sending the message
@@ -78,15 +74,13 @@ uint8_t Send_Alarm_Acknowledgement_Address(
invoke_id, dest, &npdu_data, pdu, (uint16_t)pdu_len);
bytes_sent = datalink_send_pdu(dest, &npdu_data, pdu, pdu_len);
if (bytes_sent <= 0) {
PRINTF(
"Failed to Send Alarm Ack Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send Alarm Ack Request");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
PRINTF("Failed to Send Alarm Ack Request "
"(exceeds destination maximum APDU)!\n");
debug_printf_stderr("Failed to Send Alarm Ack Request "
"(exceeds destination maximum APDU)!\n");
}
}
+12 -25
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send part of an Atomic Read File Stream.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2006
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -22,10 +21,9 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/services.h"
/** @file s_arfs.c Send part of an Atomic Read File Stream. */
uint8_t Send_Atomic_Read_File_Stream(
uint32_t device_id,
uint32_t file_instance,
@@ -40,9 +38,7 @@ uint8_t Send_Atomic_Read_File_Stream(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_ATOMIC_READ_FILE_DATA data;
/* if we are forbidden to send, don't send! */
@@ -80,27 +76,18 @@ uint8_t Send_Atomic_Read_File_Stream(
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send AtomicReadFile Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send AtomicReadFile Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send AtomicReadFile Request "
"(payload exceeds destination maximum APDU)!\n");
#endif
}
}
+13 -31
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send part of an Atomic Write File Stream request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2006
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -22,10 +21,9 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/services.h"
/** @file s_awfs.c Send part of an Atomic Write File Stream request. */
uint8_t Send_Atomic_Write_File_Stream(
uint32_t device_id,
uint32_t file_instance,
@@ -40,16 +38,13 @@ uint8_t Send_Atomic_Write_File_Stream(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_ATOMIC_WRITE_FILE_DATA data;
/* if we are forbidden to send, don't send! */
if (!dcc_communication_enabled()) {
return 0;
}
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
@@ -82,41 +77,28 @@ uint8_t Send_Atomic_Write_File_Stream(
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr,
"Failed to Send AtomicWriteFile Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send AtomicWriteFile Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
pdu_len, max_apdu);
#endif
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send AtomicWriteFile Request "
"(payload [%d] exceeds octet string capacity)!\n",
pdu_len);
#endif
}
}
+12 -25
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send a ConfirmedEventNotification Request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include "bacnet/event.h"
#include "bacnet/dcc.h"
@@ -16,10 +15,9 @@
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/services.h"
/** @file s_cevent.c Send a ConfirmedEventNotification Request. */
/** Sends an Confirmed Alarm/Event Notification.
* @ingroup EVNOTFCN
*
@@ -38,9 +36,7 @@ uint8_t Send_CEvent_Notify_Address(
{
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
uint8_t invoke_id = 0;
@@ -69,27 +65,18 @@ uint8_t Send_CEvent_Notify_Address(
if ((uint16_t)pdu_len < pdu_size) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, dest, &npdu_data, pdu, (uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(dest, &npdu_data, pdu, pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(dest, &npdu_data, pdu, pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr,
"Failed to Send ConfirmedEventNotification Request (%s)!\n",
strerror(errno));
debug_perror(
"Failed to Send ConfirmedEventNotification Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send ConfirmedEventNotification Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+11 -20
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send a COVNotification or SubscribeCOV-Request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2008
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -21,11 +20,9 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
/** @file s_cov.c Send a Change of Value (COV) update or a Subscribe COV
* request. */
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** Encodes an Unconfirmed COV Notification.
* @ingroup DSCOV
@@ -151,21 +148,15 @@ uint8_t Send_COV_Subscribe(
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "Failed to Send SubscribeCOV Request (%s)!\n",
strerror(errno));
#endif
debug_perror("Failed to Send SubscribeCOV Request");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send SubscribeCOV Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+2 -6
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 */
@@ -104,15 +103,12 @@ uint8_t Send_Create_Object_Request_Data(
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_perror(
"%s service: Failed to Send %i/%i (%s)!\n",
bactext_confirmed_service_name(service), bytes_sent,
pdu_len, strerror(errno));
debug_perror("CreateObject: Failed to Send");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
debug_perror(
debug_printf_stderr(
"%s service: Failed to Send "
"(exceeds destination maximum APDU)!\n",
bactext_confirmed_service_name(service));
+16 -30
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send a Device Communication Control (DCC) request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2006
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -20,10 +19,9 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
/** @file s_dcc.c Send a Device Communication Control (DCC) request. */
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** Sends a Device Communication Control (DCC) request.
* @ingroup DMDCC
@@ -35,13 +33,12 @@
* @param password [in] Optional password, up to 20 chars.
* @return The invokeID of the transmitted message, or 0 on failure.
*/
uint8_t Send_Device_Communication_Control_Request(
uint32_t device_id,
uint16_t timeDuration, /* 0=optional */
uint16_t timeDuration,
BACNET_COMMUNICATION_ENABLE_DISABLE state,
const char *password)
{ /* NULL=optional */
{
BACNET_ADDRESS dest;
BACNET_ADDRESS my_address;
unsigned max_apdu = 0;
@@ -49,9 +46,7 @@ uint8_t Send_Device_Communication_Control_Request(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_CHARACTER_STRING password_string;
BACNET_NPDU_DATA npdu_data;
@@ -87,28 +82,19 @@ uint8_t Send_Device_Communication_Control_Request(
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr,
"Failed to Send DeviceCommunicationControl Request (%s)!\n",
strerror(errno));
debug_perror(
"Failed to Send DeviceCommunicationControl Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send DeviceCommunicationControl Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+3 -9
View File
@@ -3,15 +3,12 @@
* @brief DeleteObject service initiation
* @author Steve Karg <skarg@users.sourceforge.net>
* @date August 2023
* @section LICENSE
*
* SPDX-License-Identifier: MIT
* @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 */
@@ -102,15 +99,12 @@ uint8_t Send_Delete_Object_Request(
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_perror(
"%s service: Failed to Send %i/%i (%s)!\n",
bactext_confirmed_service_name(service), bytes_sent,
pdu_len, strerror(errno));
debug_perror("DeleteObject: Failed to Send");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
debug_perror(
debug_printf_stderr(
"%s service: Failed to Send "
"(exceeds destination maximum APDU)!\n",
bactext_confirmed_service_name(service));
+20 -17
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2016 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send an Error message
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2016
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -21,18 +20,20 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
/** Encodes an Error message
/**
* @brief Encodes an Error message
* @param buffer The buffer to build the message for sending.
* @param dest - Destination address to send the message
* @param src - Source address from which the message originates
* @param npdu_data - buffer to hold NPDU data encoded
* @param invoke_id - use to match up a reply
* @param reason - #BACNET_ABORT_REASON enumeration
* @param server - true or false
*
* @param service - BACNET_CONFIRMED_SERVICE enumeration
* @param error_class - #BACNET_ERROR_CLASS enumeration
* @param error_code - #BACNET_ERROR_CODE enumeration
* @return Size of the message sent (bytes), or a negative value on error.
*/
int error_encode_pdu(
@@ -60,13 +61,14 @@ int error_encode_pdu(
return pdu_len;
}
/** Sends an Abort message
/**
* @brief Sends a BACnet Error message
* @param buffer The buffer to build the message for sending.
* @param dest - Destination address to send the message
* @param invoke_id - use to match up a reply
* @param reason - #BACNET_ABORT_REASON enumeration
* @param server - true or false
*
* @param service - BACNET_CONFIRMED_SERVICE enumeration
* @param error_class - #BACNET_ERROR_CLASS enumeration
* @param error_code - #BACNET_ERROR_CODE enumeration
* @return Size of the message sent (bytes), or a negative value on error.
*/
int Send_Error_To_Network(
@@ -87,6 +89,7 @@ int Send_Error_To_Network(
buffer, dest, &src, &npdu_data, invoke_id, service, error_class,
error_code);
bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len);
debug_perror("BACnetError: Failed to send PDU");
return bytes_sent;
}
+11 -30
View File
@@ -1,25 +1,16 @@
/**
* @file
* @brief Get Alarm Summary Request
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2014
* @brief Get Alarm Summary Request
*
* @section LICENSE
*
* Copyright (C) 2014 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* SPDX-License-Identifier: MIT
*
* @section DESCRIPTION
*
* The Get Alarm Summary Request is used by a client BACnet-user to
* obtain a summary of "active alarms." The term "active alarm" refers to
* BACnet standard objects that have an Event_State property whose value is
* not equal to NORMAL and a Notify_Type property whose value is ALARM.
* @copyright SPDX-License-Identifier: MIT
* @details The Get Alarm Summary Request is used by a client BACnet-user to
* obtain a summary of "active alarms." The term "active alarm" refers to
* BACnet standard objects that have an Event_State property whose value is
* not equal to NORMAL and a Notify_Type property whose value is ALARM.
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -30,6 +21,7 @@
#include "bacnet/get_alarm_sum.h"
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
@@ -41,9 +33,7 @@ uint8_t Send_Get_Alarm_Summary_Address(BACNET_ADDRESS *dest, uint16_t max_apdu)
uint8_t invoke_id = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
/* is there a tsm available? */
invoke_id = tsm_next_free_invokeID();
@@ -63,27 +53,18 @@ uint8_t Send_Get_Alarm_Summary_Address(BACNET_ADDRESS *dest, uint16_t max_apdu)
tsm_set_confirmed_unsegmented_transaction(
invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send Get Alarm Summary Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send Get Alarm Summary Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send Get Alarm Summary Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+13 -33
View File
@@ -1,27 +1,18 @@
/**
* @file
* @brief Get Event Request
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2014
* @brief Get Event Request
*
* @section LICENSE
*
* Copyright (C) 2014 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* SPDX-License-Identifier: MIT
*
* @section DESCRIPTION
*
* 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.
* @copyright SPDX-License-Identifier: MIT
* @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.
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -34,6 +25,7 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
@@ -47,9 +39,7 @@ uint8_t Send_Get_Event_Information_Address(
uint8_t invoke_id = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
/* is there a tsm available? */
invoke_id = tsm_next_free_invokeID();
@@ -69,28 +59,18 @@ uint8_t Send_Get_Event_Information_Address(
tsm_set_confirmed_unsegmented_transaction(
invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr,
"Failed to Send Get Event Information Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send Get Event Information Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send Get Event Information Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+12 -26
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2015 bowe
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send a GetEventInformation request.
* @author Boris Weitsch <bow2@users.sourceforge.net>
* @date 2015
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,8 +22,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
/** @file s_getevent.c Send a GetEventInformation request. */
#include "bacnet/basic/sys/debug.h"
/** Send a GetEventInformation request to a remote network for a specific
* device, a range, or any device.
@@ -36,9 +34,7 @@ uint8_t Send_GetEvent(
{
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
uint8_t invoke_id = 0;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
@@ -57,28 +53,18 @@ uint8_t Send_GetEvent(
&Handler_Transmit_Buffer[pdu_len], invoke_id,
lastReceivedObjectIdentifier);
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
target_address, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send GetEventInformation Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send GetEventInformation Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send GetEventInformation Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
return invoke_id;
}
+11 -22
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send an I-Am message.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2008
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,8 +22,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
/** @file s_iam.c Send an I-Am message. */
#include "bacnet/basic/sys/debug.h"
/** Send a I-Am request to a remote network for a specific device.
* @param target_address [in] BACnet address of target router
@@ -61,9 +59,7 @@ void Send_I_Am_To_Network(
bytes_sent = datalink_send_pdu(
target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Am Request (%s)!\n", strerror(errno));
#endif
debug_perror("Failed to Send I-Am Request");
}
}
@@ -118,16 +114,12 @@ void Send_I_Am(uint8_t *buffer)
if (!dcc_communication_enabled())
return 0;
#endif
/* encode the data */
pdu_len = iam_encode_pdu(buffer, &dest, &npdu_data);
/* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno));
#endif
debug_perror("Failed to Send I-Am Reply");
}
}
@@ -196,15 +188,12 @@ void Send_I_Am_Unicast(uint8_t *buffer, const BACNET_ADDRESS *src)
if (!dcc_communication_enabled())
return 0;
#endif
/* encode the data */
pdu_len = iam_unicast_encode_pdu(buffer, src, &dest, &npdu_data);
/* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno));
#endif
debug_perror("Failed to Send I-Am Reply");
}
}
+9 -13
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send an I-Have (property) message.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2006
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -22,10 +21,9 @@
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/services.h"
/** @file s_ihave.c Send an I-Have (property) message. */
/** Broadcast an I Have message.
* @ingroup DMDOB
*
@@ -72,8 +70,6 @@ void Send_I_Have(
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno));
#endif
debug_perror("Failed to Send I-Have Reply");
}
}
+4 -12
View File
@@ -3,17 +3,12 @@
* @brief AddListElement and RemoveListElement service initiation
* @author Steve Karg <skarg@users.sourceforge.net>
* @date January 2023
* @section LICENSE
*
* Copyright (C) 2023 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
* @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 */
@@ -113,15 +108,12 @@ uint8_t Send_List_Element_Request_Data(
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_perror(
"%s service: Failed to Send %i/%i (%s)!\n",
bactext_confirmed_service_name(service), bytes_sent,
pdu_len, strerror(errno));
debug_perror("ListElement: Failed to Send");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
debug_perror(
debug_printf_stderr(
"%s service: Failed to Send "
"(exceeds destination maximum APDU)!\n",
bactext_confirmed_service_name(service));
@@ -259,7 +251,7 @@ uint8_t Send_Remove_List_Element_Request(
int apdu_len = 0, len = 0;
while (object_value) {
debug_perror(
debug_printf_stderr(
"RemoveListElement service: "
"%s tag=%d\n",
(object_value->context_specific ? "context" : "application"),
+19 -28
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2009 John Minack <minack@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send BACnet Life Safety Operation message.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2009
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -24,11 +23,15 @@
#include "bacnet/basic/services.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
/** @file s_lso.c Send BACnet Life Safety Operation message. */
/* returns the invoke ID for confirmed request, or zero on failure */
/**
* @brief Send a Life Safety Operation service message
* @ingroup BIBB-AE-LS-A
* @param device_id [in] ID of the destination device
* @param data [in] The data representing the Life Safety Operation
* @return invoke id of outgoing message, or 0 on failure.
*/
uint8_t
Send_Life_Safety_Operation_Data(uint32_t device_id, const BACNET_LSO_DATA *data)
{
@@ -39,15 +42,12 @@ Send_Life_Safety_Operation_Data(uint32_t device_id, const BACNET_LSO_DATA *data)
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) {
return 0;
}
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
@@ -72,27 +72,18 @@ Send_Life_Safety_Operation_Data(uint32_t device_id, const BACNET_LSO_DATA *data)
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send Life Safe Op Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send Life Safe Op Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send Life Safe Op Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+15 -29
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send BACnet ReinitializeDevice-Request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,12 +22,11 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
/** @file s_rd.c Send a Reinitialize Device request. */
/** Sends a Reinitialize Device (RD) request.
* @ingroup DMRD
*
/**
* @brief Sends a Reinitialize Device (RD) request.
* @ingroup BIBB-DM-RD-A
* @param device_id [in] The index to the device address in our address cache.
* @param state [in] Specifies the desired state of the device after
* reinitialization.
@@ -45,9 +43,7 @@ uint8_t Send_Reinitialize_Device_Request(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_CHARACTER_STRING password_string;
BACNET_NPDU_DATA npdu_data;
@@ -55,7 +51,6 @@ uint8_t Send_Reinitialize_Device_Request(
if (!dcc_communication_enabled()) {
return 0;
}
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
@@ -83,27 +78,18 @@ uint8_t Send_Reinitialize_Device_Request(
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send ReinitializeDevice Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send ReinitializeDevice Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send ReinitializeDevice Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+18 -28
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send a ReadRange-Request message
* @author Peter Mc Shane <petermcs@users.sourceforge.net>
* @date 2009
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -24,10 +23,14 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
/** @file s_readrange.c Send a ReadRange request. */
/* returns invoke id of 0 if device is not bound or no tsm available */
/**
* @brief Send a ReadRange-Request message
* @param device_id [in] ID of the destination device
* @param data [in] The data representing the ReadRange-Request
* @return invoke id of outgoing message, or 0 on failure.
*/
uint8_t Send_ReadRange_Request(
uint32_t device_id, /* destination device */
const BACNET_READ_RANGE_DATA *read_access_data)
@@ -39,22 +42,18 @@ uint8_t Send_ReadRange_Request(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) {
return 0;
}
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
if (status) {
invoke_id = tsm_next_free_invokeID();
}
if (invoke_id) {
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
@@ -79,27 +78,18 @@ uint8_t Send_ReadRange_Request(
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send ReadRange Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send ReadRange Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send ReadRange Request (exceeds destination "
"maximum APDU)!\n");
#endif
}
}
+18 -25
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send BACnet ReadProperty-Request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -18,17 +17,16 @@
#include "bacnet/dcc.h"
#include "bacnet/rp.h"
/* some demo stuff needed */
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/binding/address.h"
#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 s_rp.c Send Read Property request. */
/** Sends a Read Property request
* @ingroup DSRP
*
/**
* @brief Sends a Read Property request
* @ingroup BIBB-DS-RP-A
* @param dest [in] BACNET_ADDRESS of the destination device
* @param max_apdu [in]
* @param object_type [in] Type of the object whose property is to be read.
@@ -92,29 +90,24 @@ uint8_t Send_Read_Property_Request_Address(
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "Failed to Send ReadProperty Request (%s)!\n",
strerror(errno));
#endif
debug_perror("Failed to Send ReadProperty Request");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send ReadProperty Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
return invoke_id;
}
/** Sends a Read Property request.
* @ingroup DSRP
/**
* @brief Sends a Read Property request.
* @ingroup BIBB-DS-RP-A
*
* @param device_id [in] ID of the destination device
* @param object_type [in] Type of the object whose property is to be read.
+14 -29
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send Read Property Multiple request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2008
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,12 +22,11 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
/** @file s_rpm.c Send Read Property Multiple request. */
/** Sends a Read Property Multiple request.
* @ingroup DSRPM
*
/**
* @brief Sends a Read Property Multiple request.
* @ingroup BIBB-DS-RPM-A
* @param pdu [out] Buffer to build the outgoing message into
* @param max_pdu [in] Length of the pdu buffer.
* @param device_id [in] ID of the destination device
@@ -50,15 +48,12 @@ uint8_t Send_Read_Property_Multiple_Request(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
if (!dcc_communication_enabled()) {
return 0;
}
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
@@ -85,27 +80,17 @@ uint8_t Send_Read_Property_Multiple_Request(
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr,
"Failed to Send ReadPropertyMultiple Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send ReadPropertyMultiple Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send ReadPropertyMultiple Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+26 -45
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send TimeSync requests.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,12 +22,11 @@
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_ts.c Send TimeSync requests. */
#include "bacnet/basic/sys/debug.h"
/**
* Sends a TimeSync message to a specific destination
*
* @brief Sends a TimeSync message to a specific destination
* @ingroup BIBB-DM-TS-A
* @param dest - #BACNET_ADDRESS - the specific destination
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
@@ -38,16 +36,13 @@ void Send_TimeSync_Remote(
{
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
if (!dcc_communication_enabled()) {
return;
}
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
@@ -57,23 +52,16 @@ void Send_TimeSync_Remote(
len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime);
pdu_len += len;
/* send it out the datalink */
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send Time-Synchronization Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send Time-Synchronization Request");
}
#endif
}
/**
* Sends a TimeSync message as a broadcast
*
* @brief Sends a TimeSync message as a broadcast
* @ingroup BIBB-DM-TS-A
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
*/
@@ -86,8 +74,8 @@ void Send_TimeSync(const BACNET_DATE *bdate, const BACNET_TIME *btime)
}
/**
* Sends a UTC TimeSync message to a specific destination
*
* @brief Sends a UTC TimeSync message to a specific destination
* @ingroup BIBB-DM-UTC-A
* @param dest - #BACNET_ADDRESS - the specific destination
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
@@ -97,9 +85,7 @@ void Send_TimeSyncUTC_Remote(
{
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
@@ -116,23 +102,16 @@ void Send_TimeSyncUTC_Remote(
len = timesync_utc_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], bdate, btime);
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send UTC-Time-Synchronization Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send UTC-Time-Synchronization Request");
}
#endif
}
/**
* Sends a UTC TimeSync message as a broadcast
*
* @brief Sends a UTC TimeSync message as a broadcast
* @ingroup BIBB-DM-UTC-A
* @param bdate - #BACNET_DATE
* @param btime - #BACNET_TIME
*/
@@ -145,7 +124,8 @@ void Send_TimeSyncUTC(const BACNET_DATE *bdate, const BACNET_TIME *btime)
}
/**
* Sends a UTC TimeSync message using the local time from the device.
* @brief Sends a UTC TimeSync message using the local time from the device.
* @ingroup BIBB-DM-UTC-A
*/
void Send_TimeSyncUTC_Device(void)
{
@@ -166,7 +146,8 @@ void Send_TimeSyncUTC_Device(void)
}
/**
* Sends a TimeSync message using the local time from the device.
* @brief Sends a TimeSync message using the local time from the device.
* @ingroup BIBB-DM-TS-A
*/
void Send_TimeSync_Device(void)
{
+14 -13
View File
@@ -1,23 +1,21 @@
/**************************************************************************
*
* Copyright (C) 2008 John Minack
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send an Unconfirmed Event Notification.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2009
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include "bacnet/event.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/sys/debug.h"
/** @file s_uevent.c Send an Unconfirmed Event Notification. */
/** Sends an Unconfirmed Alarm/Event Notification.
* @ingroup EVNOTFCN
*
/**
* @brief Sends an Unconfirmed Alarm/Event Notification.
* @ingroup BIBB-AE-N-A
* @param buffer [in,out] The buffer to build the message in for sending.
* @param data [in] The information about the Event to be sent.
* @param dest [in] The destination address information (may be a broadcast).
@@ -43,6 +41,9 @@ int Send_UEvent_Notify(
pdu_len += len;
/* send the data */
bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len);
if (bytes_sent <= 0) {
debug_perror("Failed to Send EventNotification Request");
}
return bytes_sent;
}
+18 -20
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send an UnconfirmedPrivateTransfer-Request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2009
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,11 +22,17 @@
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/sys/debug.h"
/** @file s_upt.c Send an Unconfirmed Private Transfer request. */
/**
* @brief Sends an UnconfirmedPrivateTransfer-Request.
* @ingroup BIBB-PT-A
* @param dest [in] The destination address information (may be a broadcast).
* @param data [in] The information about the private transfer to be sent.
* @return Size of the message sent (bytes), or a negative value on error.
*/
int Send_UnconfirmedPrivateTransfer(
BACNET_ADDRESS *dest, const BACNET_PRIVATE_TRANSFER_DATA *private_data)
BACNET_ADDRESS *dest, const BACNET_PRIVATE_TRANSFER_DATA *data)
{
int len = 0;
int pdu_len = 0;
@@ -38,25 +43,18 @@ int Send_UnconfirmedPrivateTransfer(
if (!dcc_communication_enabled()) {
return bytes_sent;
}
datalink_get_my_address(&my_address);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], dest, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
len =
uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], private_data);
len = uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], data);
pdu_len += len;
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "Failed to Send UnconfirmedPrivateTransfer Request (%s)!\n",
strerror(errno));
#endif
debug_perror("Failed to Send UnconfirmedPrivateTransfer Request");
}
return bytes_sent;
+21 -37
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send BACnet Who-Has requests
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2006
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -21,13 +20,13 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_whohas.c Send Who-Has requests. */
/** Send a Who-Has request for a device which has a named Object.
* @ingroup DMDOB
/**
* @brief Send a Who-Has request for a device which has a named Object.
* @ingroup BIBB-DM-DOB-A
* If low_limit and high_limit both are -1, then the device ID range is
* unlimited. If low_limit and high_limit have the same non-negative value, then
* only that device will respond. Otherwise, low_limit must be less than
@@ -42,9 +41,7 @@ void Send_WhoHas_Name(
int len = 0;
int pdu_len = 0;
BACNET_ADDRESS dest;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_WHO_HAS_DATA data;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
@@ -69,21 +66,17 @@ void Send_WhoHas_Name(
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
/* send the data */
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno));
debug_perror("Failed to Send Who-Has Request");
}
#endif
}
/** Send a Who-Has request for a device which has a specific Object type and ID.
* @ingroup DMDOB
/**
* @brief Send a Who-Has request for a device which has a specific
* Object type and ID.
* @ingroup BIBB-DM-DOB-A
* If low_limit and high_limit both are -1, then the device ID range is
* unlimited. If low_limit and high_limit have the same non-negative value, then
* only that device will respond. Otherwise, low_limit must be less than
@@ -102,9 +95,7 @@ void Send_WhoHas_Object(
int len = 0;
int pdu_len = 0;
BACNET_ADDRESS dest;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_WHO_HAS_DATA data;
BACNET_NPDU_DATA npdu_data;
BACNET_ADDRESS my_address;
@@ -120,7 +111,6 @@ void Send_WhoHas_Object(
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(
&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
/* encode the APDU portion of the packet */
data.low_limit = low_limit;
data.high_limit = high_limit;
@@ -129,15 +119,9 @@ void Send_WhoHas_Object(
data.object.identifier.instance = object_instance;
len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
pdu_len += len;
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno));
debug_perror("Failed to Send Who-Has Request");
}
#endif
}
+30 -29
View File
@@ -1,41 +1,38 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send BACnet Who-Is request.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
#include "bacnet/bacdcode.h"
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/npdu.h"
#include "bacnet/apdu.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/dcc.h"
#include "bacnet/whois.h"
#include "bacnet/bacenum.h"
/* some demo stuff needed */
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_whois.c Send a Who-Is request. */
/** Send a Who-Is request to a remote network for a specific device, a range,
* or any device.
/**
* @brief Send a Who-Is request to a remote network for a specific device,
* a range, or any device.
* If low_limit and high_limit both are -1, then the range is unlimited.
* If low_limit and high_limit have the same non-negative value, then only
* that device will respond.
* Otherwise, low_limit must be less than high_limit.
* @ingroup BIBB-DM-DDB-A
* @param target_address [in] BACnet address of target router
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
@@ -61,21 +58,19 @@ void Send_WhoIs_To_Network(
pdu_len += len;
bytes_sent = datalink_send_pdu(
target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) {
fprintf(
stderr, "Failed to Send Who-Is Request (%s)!\n", strerror(errno));
debug_perror("Failed to Send Who-Is Request");
}
#else
(void)bytes_sent;
#endif
}
/** Send a global Who-Is request for a specific device, a range, or any device.
/**
* @brief Send a global Who-Is request for a specific device, a range,
* or any device.
* If low_limit and high_limit both are -1, then the range is unlimited.
* If low_limit and high_limit have the same non-negative value, then only
* that device will respond.
* Otherwise, low_limit must be less than high_limit.
* @ingroup BIBB-DM-DDB-A
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
@@ -93,11 +88,14 @@ void Send_WhoIs_Global(int32_t low_limit, int32_t high_limit)
Send_WhoIs_To_Network(&dest, low_limit, high_limit);
}
/** Send a local Who-Is request for a specific device, a range, or any device.
/**
* @brief Send a local Who-Is request for a specific device, a range,
* or any device.
* If low_limit and high_limit both are -1, then the range is unlimited.
* If low_limit and high_limit have the same non-negative value, then only
* that device will respond.
* Otherwise, low_limit must be less than high_limit.
* @ingroup BIBB-DM-DDB-A
* @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1
* @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1
*/
@@ -109,9 +107,10 @@ void Send_WhoIs_Local(int32_t low_limit, int32_t high_limit)
Send_WhoIs_To_Network(&dest, low_limit, high_limit);
}
/** Send a Who-Is request to a remote network for a specific device, a range,
* or any device.
* @ingroup DMDDB
/**
* @brief Send a Who-Is request to a remote network for a specific device,
* a range, or any device.
* @ingroup BIBB-DM-DDB-A
* If low_limit and high_limit both are -1, then the range is unlimited.
* If low_limit and high_limit have the same non-negative value, then only
* that device will respond.
@@ -130,8 +129,10 @@ void Send_WhoIs_Remote(
Send_WhoIs_To_Network(target_address, low_limit, high_limit);
}
/** Send a global Who-Is request for a specific device, a range, or any device.
* @ingroup DMDDB
/**
* @brief Send a global Who-Is request for a specific device, a range,
* or any device.
* @ingroup BIBB-DM-DDB-A
* This was the original Who-Is broadcast but the code was moved to the more
* descriptive Send_WhoIs_Global when Send_WhoIs_Local and Send_WhoIsRemote was
* added.
+21 -27
View File
@@ -1,13 +1,12 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/**
* @file
* @brief Send BACnet WriteProperty-Request
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -21,12 +20,17 @@
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_wp.c Send a Write Property request. */
/** returns the invoke ID for confirmed request, or zero on failure */
/**
* @brief Send a WriteProperty-Request service message
* @ingroup BIBB-DS-WP-A
* @param device_id [in] ID of the destination device
* @param data [in] The data representing the Life Safety Operation
* @return invoke id of outgoing message, or zero on failure.
*/
uint8_t Send_Write_Property_Request_Data(
uint32_t device_id,
BACNET_OBJECT_TYPE object_type,
@@ -51,7 +55,6 @@ uint8_t Send_Write_Property_Request_Data(
if (!dcc_communication_enabled()) {
return 0;
}
/* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest);
/* is there a tsm available? */
@@ -89,30 +92,24 @@ uint8_t Send_Write_Property_Request_Data(
bytes_sent = datalink_send_pdu(
&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "Failed to Send WriteProperty Request (%s)!\n",
strerror(errno));
#endif
debug_perror("Failed to Send WriteProperty Request");
}
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send WriteProperty Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
return invoke_id;
}
/** Sends a Write Property request.
* @ingroup DSWP
*
/**
* @brief Sends a Write Property request.
* @ingroup BIBB-DS-WP-A
* @param device_id [in] ID of the destination device
* @param object_type [in] Type of the object whose property is to be written.
* @param object_instance [in] Instance # of the object to be written.
@@ -138,15 +135,12 @@ uint8_t Send_Write_Property_Request(
int apdu_len = 0, len = 0;
while (object_value) {
#if PRINT_ENABLED_DEBUG
fprintf(
stderr,
debug_printf(
"WriteProperty service: "
"%s tag=%d\n",
(object_value->context_specific ? "context" : "application"),
(int)(object_value->context_specific ? object_value->context_tag
: object_value->tag));
#endif
len = bacapp_encode_data(&application_data[apdu_len], object_value);
if ((len + apdu_len) < MAX_APDU) {
apdu_len += len;
+10 -27
View File
@@ -1,18 +1,12 @@
/**
* @file
* @brief Send Write Property Multiple request
* @author Daniel Blazevic <daniel.blazevic@gmail.com>
* @date 2013
* @brief Send Write Property Multiple request
*
* @section LICENSE
*
* Copyright (C) 2013 Daniel Blazevic <daniel.blazevic@gmail.com>
*
* SPDX-License-Identifier: MIT
* @copyright SPDX-License-Identifier: MIT
*/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
@@ -23,15 +17,16 @@
#include "bacnet/dcc.h"
#include "bacnet/wpm.h"
/* some demo stuff needed */
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/** @file s_wpm.c Send Write Property Multiple request. */
/** Sends a Write Property Multiple request.
/**
* @brief Sends a Write Property Multiple request.
* @ingroup BIBB-DS-WPM-A
* @param pdu [out] Buffer to build the outgoing message into
* @param max_pdu [in] Length of the pdu buffer.
* @param device_id [in] ID of the destination device
@@ -53,9 +48,7 @@ uint8_t Send_Write_Property_Multiple_Request(
bool status = false;
int len = 0;
int pdu_len = 0;
#if PRINT_ENABLED
int bytes_sent = 0;
#endif
BACNET_NPDU_DATA npdu_data;
/* if we are forbidden to send, don't send! */
@@ -88,27 +81,17 @@ uint8_t Send_Write_Property_Multiple_Request(
if ((unsigned)pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(
invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len);
#if PRINT_ENABLED
bytes_sent =
#endif
datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
#if PRINT_ENABLED
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len);
if (bytes_sent <= 0) {
fprintf(
stderr,
"Failed to Send WritePropertyMultiple Request (%s)!\n",
strerror(errno));
debug_perror("Failed to Send WritePropertyMultiple Request");
}
#endif
} else {
tsm_free_invoke_id(invoke_id);
invoke_id = 0;
#if PRINT_ENABLED
fprintf(
debug_fprintf(
stderr,
"Failed to Send WritePropertyMultiple Request "
"(exceeds destination maximum APDU)!\n");
#endif
}
}
+9 -6
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"
@@ -20,9 +19,17 @@
/* some demo stuff needed */
#include "bacnet/basic/binding/address.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/tsm/tsm.h"
#include "bacnet/datalink/datalink.h"
/**
* @brief Sends a WriteGroup-Request
* @ingroup BIBB-DS-WG-A
* @param dest [in] BACNET_ADDRESS of the destination device
* @param data [in] The data representing the WriteGroup-Request
* @return bytes sent, or a negative value on error
*/
int Send_Write_Group(BACNET_ADDRESS *dest, const BACNET_WRITE_GROUP_DATA *data)
{
int len = 0;
@@ -51,11 +58,7 @@ int Send_Write_Group(BACNET_ADDRESS *dest, const BACNET_WRITE_GROUP_DATA *data)
bytes_sent = datalink_send_pdu(
dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(
stderr, "Failed to Send WriteGroup-Request (%s)!\n",
strerror(errno));
#endif
debug_perror("Failed to Send WriteGroup-Request");
}
return bytes_sent;
+53 -10
View File
@@ -7,9 +7,12 @@
*/
#include <stdint.h> /* for standard integer types uint8_t etc. */
#include <stdbool.h> /* for the standard bool type. */
#include <stdarg.h>
#if PRINT_ENABLED || DEBUG_ENABLED
#include <stdio.h> /* Standard I/O */
#include <stdlib.h> /* Standard Library */
#include <stdarg.h>
#include <errno.h>
#endif
#if DEBUG_ENABLED
#include <string.h>
#include <ctype.h>
@@ -72,6 +75,17 @@ void debug_printf(const char *format, ...)
}
#endif
/**
* @brief Print with a printf string that does nothing
* @param format - printf format string
* @param ... - variable arguments
* @note useful when used with defines such as DEBUG_PRINTF
*/
void debug_printf_disabled(const char *format, ...)
{
(void)format;
}
/**
* @brief print format with HEX dump of a buffer
* @param offset - starting address to print to the left side
@@ -140,7 +154,7 @@ void debug_printf_hex(
* PRINT_ENABLED is non-zero
* @return number of characters printed
*/
int debug_aprintf(const char *format, ...)
int debug_printf_stdout(const char *format, ...)
{
int length = 0;
#if PRINT_ENABLED
@@ -183,13 +197,25 @@ int debug_fprintf(FILE *stream, const char *format, ...)
}
/**
* @brief Print with a perror string
* @brief Print with a fprintf string that does nothing
* @param format - printf format string
* @param ... - variable arguments
* @note This function is only available if
* PRINT_ENABLED is non-zero
* @note useful when used with defines such as DEBUG_PRINTF
*/
void debug_perror(const char *format, ...)
int debug_fprintf_disabled(FILE *stream, const char *format, ...)
{
(void)stream;
(void)format;
return 0;
}
/**
* @brief debug printf to stderr when PRINT_ENABLED is non-zero
* @param format - printf format string
* @param ... - variable arguments
* @note This function is only available if PRINT_ENABLED is non-zero
*/
void debug_printf_stderr(const char *format, ...)
{
#if PRINT_ENABLED
va_list ap;
@@ -203,13 +229,30 @@ void debug_perror(const char *format, ...)
#endif
}
#if PRINT_ENABLED
/**
* @brief Print with a printf string that does nothing
* @brief debug printf to stderr when PRINT_ENABLED is non-zero
* @param format - printf format string
* @param ... - variable arguments
* @note useful when used with defines such as PRINTF
* @note This function is only available if PRINT_ENABLED is non-zero
*/
void debug_printf_disabled(const char *format, ...)
void debug_print(const char *message)
{
(void)format;
fprintf(stderr, "%s", message);
fflush(stderr);
}
#endif
#if PRINT_ENABLED
/**
* @brief Prints a textual description of the error code currently
* stored in the system variable errno to stderr.
* @param s - pointer to a null-terminated string with explanatory message
* @note This function is only available if PRINT_ENABLED is non-zero
*/
void debug_perror(const char *message)
{
perror(message);
fflush(stderr);
}
#endif
+34 -3
View File
@@ -28,11 +28,19 @@ extern "C" {
BACNET_STACK_EXPORT
void debug_printf(const char *format, ...);
BACNET_STACK_EXPORT
int debug_aprintf(const char *format, ...);
void debug_printf_disabled(const char *format, ...);
BACNET_STACK_EXPORT
int debug_printf_stdout(const char *format, ...);
BACNET_STACK_EXPORT
int debug_fprintf(FILE *stream, const char *format, ...);
BACNET_STACK_EXPORT
void debug_perror(const char *format, ...);
int debug_fprintf_disabled(FILE *stream, const char *format, ...);
BACNET_STACK_EXPORT
void debug_printf_stderr(const char *format, ...);
BACNET_STACK_EXPORT
void debug_printf_hex(
uint32_t offset,
@@ -41,8 +49,31 @@ void debug_printf_hex(
const char *format,
...);
#if PRINT_ENABLED
BACNET_STACK_EXPORT
void debug_printf_disabled(const char *format, ...);
void debug_print(const char *message);
#else
#define debug_print(message) ((void)0)
#endif
#if PRINT_ENABLED
BACNET_STACK_EXPORT
void debug_perror(const char *message);
#else
#define debug_perror(message) ((void)0)
#endif
#if PRINT_ENABLED
#define DEBUG_FPRINTF debug_fprintf
#else
#define DEBUG_FPRINTF debug_fprintf_disabled
#endif
#if DEBUG_ENABLED
#define DEBUG_PRINTF debug_printf
#else
#define DEBUG_PRINTF debug_printf_disabled
#endif
#ifdef __cplusplus
}
+1 -1
View File
@@ -22,7 +22,7 @@
#include "bacnet/basic/object/sc_netport.h"
#include "bacnet/basic/object/bacfile.h"
#define PRINTF debug_perror
#define PRINTF debug_printf_stderr
#define DEBUG_BSC_DATALINK 0
#if DEBUG_BSC_DATALINK == 1
#define DEBUG_PRINTF debug_printf
+2 -2
View File
@@ -13,8 +13,8 @@
#include "bacnet/basic/sys/debug.h"
#include <stdlib.h>
#define PRINTF debug_aprintf
#define PRINTF_ERR debug_perror
#define PRINTF debug_printf_stdout
#define PRINTF_ERR debug_printf_stderr
/**
* @brief Map websocket return code to BACnet/SC return code