Add common functions for initializing the BACnet Application Value lists. Fixes problems with receiving Unconfirmed COV Notifications with more values to store than the stack has reserved in its value list.

This commit is contained in:
skarg
2019-01-31 14:51:46 +00:00
parent b3c9affd49
commit 585b0bae5b
5 changed files with 72 additions and 25 deletions
+1 -11
View File
@@ -69,7 +69,6 @@ void handler_ccov_notification(
BACNET_COV_DATA cov_data;
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
unsigned index = 0;
int len = 0;
int pdu_len = 0;
int bytes_sent = 0;
@@ -77,16 +76,7 @@ void handler_ccov_notification(
/* create linked list to store data if more
than one property value is expected */
pProperty_value = &property_value[0];
while (pProperty_value) {
index++;
if (index < MAX_COV_PROPERTIES) {
pProperty_value->next = &property_value[index];
} else {
pProperty_value->next = NULL;
}
pProperty_value = pProperty_value->next;
}
bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES);
cov_data.listOfValues = &property_value[0];
/* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address);
+7 -3
View File
@@ -47,6 +47,10 @@
#include "device.h"
#include "handlers.h"
#ifndef MAX_COV_PROPERTIES
#define MAX_COV_PROPERTIES 2
#endif
/** @file h_cov.c Handles Change of Value (COV) services. */
typedef struct BACnet_COV_Address {
@@ -616,7 +620,7 @@ bool handler_cov_fsm(
uint32_t object_instance = 0;
bool status = false;
bool send = false;
BACNET_PROPERTY_VALUE value_list[2];
BACNET_PROPERTY_VALUE value_list[MAX_COV_PROPERTIES];
/* states for transmitting */
static enum {
COV_STATE_IDLE = 0,
@@ -716,8 +720,8 @@ bool handler_cov_fsm(
fprintf(stderr, "COVtask: Sending...\n");
#endif
/* configure the linked list for the two properties */
value_list[0].next = &value_list[1];
value_list[1].next = NULL;
bacapp_property_value_list_init(&value_list[0],
MAX_COV_PROPERTIES);
status = Device_Encode_Value_List(object_type,
object_instance, &value_list[0]);
if (status) {
+1 -11
View File
@@ -66,22 +66,12 @@ void handler_ucov_notification(
BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES];
BACNET_PROPERTY_VALUE *pProperty_value = NULL;
int len = 0;
unsigned index = 0;
/* src not needed for this application */
src = src;
/* create linked list to store data if more
than one property value is expected */
pProperty_value = &property_value[0];
while (pProperty_value) {
index++;
if (index < MAX_COV_PROPERTIES) {
pProperty_value->next = &property_value[index];
} else {
pProperty_value->next = NULL;
}
pProperty_value = pProperty_value->next;
}
bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES);
cov_data.listOfValues = &property_value[0];
#if PRINT_ENABLED
fprintf(stderr, "UCOV: Received Notification!\n");
+8
View File
@@ -134,6 +134,14 @@ typedef struct BACnet_Object_Property_Value {
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void bacapp_value_list_init(
BACNET_APPLICATION_DATA_VALUE *value,
size_t count);
void bacapp_property_value_list_init(
BACNET_PROPERTY_VALUE *value,
size_t count);
int bacapp_encode_data(
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value);
+55
View File
@@ -1555,6 +1555,61 @@ bool bacapp_parse_application_data(
}
#endif
/**
* Initialize an array (or single) #BACNET_APPLICATION_DATA_VALUE
*
* @param value - one or more #BACNET_APPLICATION_DATA_VALUE elements
* @param count - number of #BACNET_APPLICATION_DATA_VALUE elements
*/
void bacapp_value_list_init(
BACNET_APPLICATION_DATA_VALUE *value,
size_t count)
{
size_t i = 0;
if (value && count) {
for (i = 0; i < count; i++) {
value->tag = BACNET_APPLICATION_TAG_NULL;
value->context_specific = 0;
value->context_tag = 0;
if ((i+1) < count) {
value->next = value + 1;
} else {
value->next = NULL;
}
value++;
}
}
}
/**
* Initialize an array (or single) #BACNET_PROPERTY_VALUE
*
* @param value - one or more #BACNET_PROPERTY_VALUE elements
* @param count - number of #BACNET_PROPERTY_VALUE elements
*/
void bacapp_property_value_list_init(
BACNET_PROPERTY_VALUE *value,
size_t count)
{
size_t i = 0;
if (value && count) {
for (i = 0; i < count; i++) {
value->propertyIdentifier = MAX_BACNET_PROPERTY_ID;
value->propertyArrayIndex = BACNET_ARRAY_ALL;
value->priority = BACNET_NO_PRIORITY;
bacapp_value_list_init(&value->value, 1);
if ((i+1) < count) {
value->next = value + 1;
} else {
value->next = NULL;
}
value++;
}
}
}
#ifdef TEST
#include <assert.h>
#include <string.h>