Added COV notification callbacks (#208)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -40,11 +40,62 @@
|
|||||||
#include "bacnet/basic/tsm/tsm.h"
|
#include "bacnet/basic/tsm/tsm.h"
|
||||||
#include "bacnet/datalink/datalink.h"
|
#include "bacnet/datalink/datalink.h"
|
||||||
|
|
||||||
|
/** @file h_ccov.c Handles Confirmed COV Notifications. */
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTF(...) fprintf(stderr,__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* max number of COV properties decoded in a COV notification */
|
||||||
#ifndef MAX_COV_PROPERTIES
|
#ifndef MAX_COV_PROPERTIES
|
||||||
#define MAX_COV_PROPERTIES 2
|
#define MAX_COV_PROPERTIES 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @file h_ccov.c Handles Confirmed COV Notifications. */
|
/* COV notification callbacks list */
|
||||||
|
static BACNET_COV_NOTIFICATION Confirmed_COV_Notification_Head;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief call the COV notification callbacks
|
||||||
|
* @param cov_data - data decoded from the COV notification
|
||||||
|
*/
|
||||||
|
static void handler_ccov_notification_callback(
|
||||||
|
BACNET_COV_DATA *cov_data)
|
||||||
|
{
|
||||||
|
BACNET_COV_NOTIFICATION *head;
|
||||||
|
|
||||||
|
head = &Confirmed_COV_Notification_Head;
|
||||||
|
do {
|
||||||
|
if (head->callback) {
|
||||||
|
head->callback(cov_data);
|
||||||
|
}
|
||||||
|
head = head->next;
|
||||||
|
} while (head);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a Confirmed COV notification callback
|
||||||
|
* @param cb - COV notification callback to be added
|
||||||
|
*/
|
||||||
|
void handler_ccov_notification_add(
|
||||||
|
BACNET_COV_NOTIFICATION *cb)
|
||||||
|
{
|
||||||
|
BACNET_COV_NOTIFICATION *head;
|
||||||
|
|
||||||
|
head = &Confirmed_COV_Notification_Head;
|
||||||
|
do {
|
||||||
|
if (head->next == cb) {
|
||||||
|
/* already here! */
|
||||||
|
break;
|
||||||
|
} else if (!head->next) {
|
||||||
|
/* first available free node */
|
||||||
|
head->next = cb;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
head = head->next;
|
||||||
|
} while (head);
|
||||||
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
/** Handler for an Confirmed COV Notification.
|
/** Handler for an Confirmed COV Notification.
|
||||||
@@ -68,9 +119,7 @@ void handler_ccov_notification(uint8_t *service_request,
|
|||||||
BACNET_NPDU_DATA npdu_data;
|
BACNET_NPDU_DATA npdu_data;
|
||||||
BACNET_COV_DATA cov_data;
|
BACNET_COV_DATA cov_data;
|
||||||
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
|
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
|
||||||
#if PRINT_ENABLED
|
|
||||||
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
|
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
|
||||||
#endif
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
@@ -85,74 +134,62 @@ void handler_ccov_notification(uint8_t *service_request,
|
|||||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||||
pdu_len = npdu_encode_pdu(
|
pdu_len = npdu_encode_pdu(
|
||||||
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
|
&Handler_Transmit_Buffer[0], src, &my_address, &npdu_data);
|
||||||
#if PRINT_ENABLED
|
PRINTF("CCOV: Received Notification!\n");
|
||||||
fprintf(stderr, "CCOV: Received Notification!\n");
|
|
||||||
#endif
|
|
||||||
if (service_data->segmented_message) {
|
if (service_data->segmented_message) {
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||||
true);
|
true);
|
||||||
#if PRINT_ENABLED
|
PRINTF("CCOV: Segmented message. Sending Abort!\n");
|
||||||
fprintf(stderr, "CCOV: Segmented message. Sending Abort!\n");
|
|
||||||
#endif
|
|
||||||
goto CCOV_ABORT;
|
goto CCOV_ABORT;
|
||||||
}
|
}
|
||||||
/* decode the service request only */
|
/* decode the service request only */
|
||||||
len = cov_notify_decode_service_request(
|
len = cov_notify_decode_service_request(
|
||||||
service_request, service_len, &cov_data);
|
service_request, service_len, &cov_data);
|
||||||
#if PRINT_ENABLED
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
fprintf(stderr, "CCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
|
handler_ccov_notification_callback(&cov_data);
|
||||||
fprintf(stderr, "instance=%u ", cov_data.initiatingDeviceIdentifier);
|
PRINTF("CCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
|
||||||
fprintf(stderr, "%s %u ",
|
PRINTF("instance=%u ", cov_data.initiatingDeviceIdentifier);
|
||||||
|
PRINTF("%s %u ",
|
||||||
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
|
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
|
||||||
cov_data.monitoredObjectIdentifier.instance);
|
cov_data.monitoredObjectIdentifier.instance);
|
||||||
fprintf(stderr, "time remaining=%u seconds ", cov_data.timeRemaining);
|
PRINTF("time remaining=%u seconds ", cov_data.timeRemaining);
|
||||||
fprintf(stderr, "\n");
|
PRINTF("\n");
|
||||||
pProperty_value = &property_value[0];
|
pProperty_value = &property_value[0];
|
||||||
while (pProperty_value) {
|
while (pProperty_value) {
|
||||||
fprintf(stderr, "CCOV: ");
|
PRINTF("CCOV: ");
|
||||||
if (pProperty_value->propertyIdentifier < 512) {
|
if (pProperty_value->propertyIdentifier < 512) {
|
||||||
fprintf(stderr, "%s ",
|
PRINTF("%s ",
|
||||||
bactext_property_name(pProperty_value->propertyIdentifier));
|
bactext_property_name(pProperty_value->propertyIdentifier));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "proprietary %u ",
|
PRINTF("proprietary %u ",
|
||||||
pProperty_value->propertyIdentifier);
|
pProperty_value->propertyIdentifier);
|
||||||
}
|
}
|
||||||
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
|
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
|
||||||
fprintf(stderr, "%u ", pProperty_value->propertyArrayIndex);
|
PRINTF("%u ", pProperty_value->propertyArrayIndex);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
PRINTF("\n");
|
||||||
pProperty_value = pProperty_value->next;
|
pProperty_value = pProperty_value->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* bad decoding or something we didn't understand - send an abort */
|
/* bad decoding or something we didn't understand - send an abort */
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||||
#if PRINT_ENABLED
|
PRINTF("CCOV: Bad Encoding. Sending Abort!\n");
|
||||||
fprintf(stderr, "CCOV: Bad Encoding. Sending Abort!\n");
|
|
||||||
#endif
|
|
||||||
goto CCOV_ABORT;
|
goto CCOV_ABORT;
|
||||||
} else {
|
} else {
|
||||||
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id, SERVICE_CONFIRMED_COV_NOTIFICATION);
|
service_data->invoke_id, SERVICE_CONFIRMED_COV_NOTIFICATION);
|
||||||
#if PRINT_ENABLED
|
PRINTF("CCOV: Sending Simple Ack!\n");
|
||||||
fprintf(stderr, "CCOV: Sending Simple Ack!\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
CCOV_ABORT:
|
CCOV_ABORT:
|
||||||
pdu_len += len;
|
pdu_len += len;
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(
|
||||||
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
|
src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
#if PRINT_ENABLED
|
|
||||||
if (bytes_sent <= 0) {
|
if (bytes_sent <= 0) {
|
||||||
fprintf(stderr, "CCOV: Failed to send PDU (%s)!\n", strerror(errno));
|
PRINTF("CCOV: Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
bytes_sent = bytes_sent;
|
bytes_sent = bytes_sent;
|
||||||
#endif
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,14 @@
|
|||||||
#include "bacnet/bacdef.h"
|
#include "bacnet/bacdef.h"
|
||||||
#include "bacnet/bacenum.h"
|
#include "bacnet/bacenum.h"
|
||||||
#include "bacnet/apdu.h"
|
#include "bacnet/apdu.h"
|
||||||
|
#include "bacnet/cov.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void handler_ccov_notification_add(
|
||||||
|
BACNET_COV_NOTIFICATION *callback);
|
||||||
|
|
||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
void handler_ccov_notification(
|
void handler_ccov_notification(
|
||||||
|
|||||||
@@ -38,11 +38,61 @@
|
|||||||
#include "bacnet/basic/services.h"
|
#include "bacnet/basic/services.h"
|
||||||
#include "bacnet/basic/tsm/tsm.h"
|
#include "bacnet/basic/tsm/tsm.h"
|
||||||
|
|
||||||
|
/** @file h_ucov.c Handles Unconfirmed COV Notifications. */
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTF(...) fprintf(stderr,__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MAX_COV_PROPERTIES
|
#ifndef MAX_COV_PROPERTIES
|
||||||
#define MAX_COV_PROPERTIES 2
|
#define MAX_COV_PROPERTIES 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @file h_ucov.c Handles Unconfirmed COV Notifications. */
|
/* COV notification callbacks list */
|
||||||
|
static BACNET_COV_NOTIFICATION Unconfirmed_COV_Notification_Head;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief call the COV notification callbacks
|
||||||
|
* @param cov_data - data decoded from the COV notification
|
||||||
|
*/
|
||||||
|
static void handler_ucov_notification_callback(
|
||||||
|
BACNET_COV_DATA *cov_data)
|
||||||
|
{
|
||||||
|
BACNET_COV_NOTIFICATION *head;
|
||||||
|
|
||||||
|
head = &Unconfirmed_COV_Notification_Head;
|
||||||
|
do {
|
||||||
|
if (head->callback) {
|
||||||
|
head->callback(cov_data);
|
||||||
|
}
|
||||||
|
head = head->next;
|
||||||
|
} while (head);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a Confirmed COV notification callback
|
||||||
|
* @param cb - COV notification callback to be added
|
||||||
|
*/
|
||||||
|
void handler_ucov_notification_add(
|
||||||
|
BACNET_COV_NOTIFICATION *cb)
|
||||||
|
{
|
||||||
|
BACNET_COV_NOTIFICATION *head;
|
||||||
|
|
||||||
|
head = &Unconfirmed_COV_Notification_Head;
|
||||||
|
do {
|
||||||
|
if (head->next == cb) {
|
||||||
|
/* already here! */
|
||||||
|
break;
|
||||||
|
} else if (!head->next) {
|
||||||
|
/* first available free node */
|
||||||
|
head->next = cb;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
head = head->next;
|
||||||
|
} while (head);
|
||||||
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
/** Handler for an Unconfirmed COV Notification.
|
/** Handler for an Unconfirmed COV Notification.
|
||||||
@@ -61,10 +111,8 @@ void handler_ucov_notification(
|
|||||||
{
|
{
|
||||||
BACNET_COV_DATA cov_data;
|
BACNET_COV_DATA cov_data;
|
||||||
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
|
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
|
||||||
#if PRINT_ENABLED
|
|
||||||
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
|
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
/* src not needed for this application */
|
/* src not needed for this application */
|
||||||
(void)src;
|
(void)src;
|
||||||
@@ -72,42 +120,37 @@ void handler_ucov_notification(
|
|||||||
than one property value is expected */
|
than one property value is expected */
|
||||||
bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES);
|
bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES);
|
||||||
cov_data.listOfValues = &property_value[0];
|
cov_data.listOfValues = &property_value[0];
|
||||||
#if PRINT_ENABLED
|
PRINTF("UCOV: Received Notification!\n");
|
||||||
fprintf(stderr, "UCOV: Received Notification!\n");
|
|
||||||
#endif
|
|
||||||
/* decode the service request only */
|
/* decode the service request only */
|
||||||
#if PRINT_ENABLED
|
|
||||||
len =
|
len =
|
||||||
#endif
|
|
||||||
cov_notify_decode_service_request(
|
cov_notify_decode_service_request(
|
||||||
service_request, service_len, &cov_data);
|
service_request, service_len, &cov_data);
|
||||||
#if PRINT_ENABLED
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
fprintf(stderr, "UCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
|
handler_ucov_notification_callback(&cov_data);
|
||||||
fprintf(stderr, "instance=%u ", cov_data.initiatingDeviceIdentifier);
|
PRINTF("UCOV: PID=%u ", cov_data.subscriberProcessIdentifier);
|
||||||
fprintf(stderr, "%s %u ",
|
PRINTF("instance=%u ", cov_data.initiatingDeviceIdentifier);
|
||||||
|
PRINTF("%s %u ",
|
||||||
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
|
bactext_object_type_name(cov_data.monitoredObjectIdentifier.type),
|
||||||
cov_data.monitoredObjectIdentifier.instance);
|
cov_data.monitoredObjectIdentifier.instance);
|
||||||
fprintf(stderr, "time remaining=%u seconds ", cov_data.timeRemaining);
|
PRINTF("time remaining=%u seconds ", cov_data.timeRemaining);
|
||||||
fprintf(stderr, "\n");
|
PRINTF("\n");
|
||||||
pProperty_value = &property_value[0];
|
pProperty_value = &property_value[0];
|
||||||
while (pProperty_value) {
|
while (pProperty_value) {
|
||||||
fprintf(stderr, "UCOV: ");
|
PRINTF("UCOV: ");
|
||||||
if (pProperty_value->propertyIdentifier < 512) {
|
if (pProperty_value->propertyIdentifier < 512) {
|
||||||
fprintf(stderr, "%s ",
|
PRINTF("%s ",
|
||||||
bactext_property_name(pProperty_value->propertyIdentifier));
|
bactext_property_name(pProperty_value->propertyIdentifier));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "proprietary %u ",
|
PRINTF("proprietary %u ",
|
||||||
pProperty_value->propertyIdentifier);
|
pProperty_value->propertyIdentifier);
|
||||||
}
|
}
|
||||||
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
|
if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) {
|
||||||
fprintf(stderr, "%u ", pProperty_value->propertyArrayIndex);
|
PRINTF("%u ", pProperty_value->propertyArrayIndex);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
PRINTF("\n");
|
||||||
pProperty_value = pProperty_value->next;
|
pProperty_value = pProperty_value->next;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "UCOV: Unable to decode service request!\n");
|
PRINTF("UCOV: Unable to decode service request!\n");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,14 @@
|
|||||||
#include "bacnet/bacdef.h"
|
#include "bacnet/bacdef.h"
|
||||||
#include "bacnet/bacenum.h"
|
#include "bacnet/bacenum.h"
|
||||||
#include "bacnet/apdu.h"
|
#include "bacnet/apdu.h"
|
||||||
|
#include "bacnet/cov.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void handler_ucov_notification_add(
|
||||||
|
BACNET_COV_NOTIFICATION *callback);
|
||||||
|
|
||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
void handler_ucov_notification(
|
void handler_ucov_notification(
|
||||||
|
|||||||
+9
-1
@@ -53,11 +53,19 @@ typedef struct BACnet_Subscribe_COV_Data {
|
|||||||
struct BACnet_Subscribe_COV_Data *next;
|
struct BACnet_Subscribe_COV_Data *next;
|
||||||
} BACNET_SUBSCRIBE_COV_DATA;
|
} BACNET_SUBSCRIBE_COV_DATA;
|
||||||
|
|
||||||
|
/* generic callback for COV notifications */
|
||||||
|
typedef void (*BACnet_COV_Notification_Callback)
|
||||||
|
(BACNET_COV_DATA *cov_data);
|
||||||
|
struct BACnet_COV_Notification;
|
||||||
|
typedef struct BACnet_COV_Notification {
|
||||||
|
struct BACnet_COV_Notification *next;
|
||||||
|
BACnet_COV_Notification_Callback callback;
|
||||||
|
} BACNET_COV_NOTIFICATION;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
BACNET_STACK_EXPORT
|
|
||||||
int ucov_notify_encode_apdu(
|
int ucov_notify_encode_apdu(
|
||||||
uint8_t * apdu,
|
uint8_t * apdu,
|
||||||
unsigned max_apdu_len,
|
unsigned max_apdu_len,
|
||||||
|
|||||||
Reference in New Issue
Block a user