Removed the object-table function macros from each demo object header file since it was very difficult to maintain when new functions are added. Added device-client.c file which is a small device object just for simple clients. Updated most Makefiles of client demo applications to utilize device-client.c file.
Added two device object table functions for COV support. Corrected demo COV handler interaction with TSM, COV flags, and multiple subscriptions for the same object.
This commit is contained in:
@@ -53,6 +53,7 @@ typedef struct BACnet_COV_Subscription {
|
||||
uint32_t subscriberProcessIdentifier;
|
||||
BACNET_OBJECT_ID monitoredObjectIdentifier;
|
||||
bool issueConfirmedNotifications; /* optional */
|
||||
uint8_t invokeID; /* for confirmed COV */
|
||||
uint32_t lifetime; /* optional */
|
||||
bool send_requested;
|
||||
} BACNET_COV_SUBSCRIPTION;
|
||||
@@ -223,6 +224,7 @@ void handler_cov_init(
|
||||
OBJECT_ANALOG_INPUT;
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.instance = 0;
|
||||
COV_Subscriptions[index].issueConfirmedNotifications = false;
|
||||
COV_Subscriptions[index].invokeID = 0;
|
||||
COV_Subscriptions[index].lifetime = 0;
|
||||
COV_Subscriptions[index].send_requested = false;
|
||||
}
|
||||
@@ -261,6 +263,10 @@ static bool cov_list_subscribe(
|
||||
COV_Subscriptions[index].lifetime = cov_data->lifetime;
|
||||
COV_Subscriptions[index].send_requested = true;
|
||||
}
|
||||
if (COV_Subscriptions[index].invokeID) {
|
||||
tsm_free_invoke_id(COV_Subscriptions[index].invokeID);
|
||||
COV_Subscriptions[index].invokeID = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -283,6 +289,7 @@ static bool cov_list_subscribe(
|
||||
cov_data->subscriberProcessIdentifier;
|
||||
COV_Subscriptions[index].issueConfirmedNotifications =
|
||||
cov_data->issueConfirmedNotifications;
|
||||
COV_Subscriptions[index].invokeID = 0;
|
||||
COV_Subscriptions[index].lifetime = cov_data->lifetime;
|
||||
COV_Subscriptions[index].send_requested = true;
|
||||
} else if (!existing_entry) {
|
||||
@@ -335,6 +342,7 @@ static bool cov_send_request(
|
||||
if (cov_subscription->issueConfirmedNotifications) {
|
||||
invoke_id = tsm_next_free_invokeID();
|
||||
if (invoke_id) {
|
||||
cov_subscription->invokeID = invoke_id;
|
||||
len =
|
||||
ccov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
invoke_id, &cov_data);
|
||||
@@ -385,19 +393,13 @@ static bool cov_send_request(
|
||||
*
|
||||
* @param elapsed_seconds [in] How many seconds have elapsed since last called.
|
||||
*/
|
||||
void handler_cov_task(
|
||||
void handler_cov_timer_seconds(
|
||||
uint32_t elapsed_seconds)
|
||||
{
|
||||
int index = 0, index2 = 0;
|
||||
int index = 0;
|
||||
uint32_t lifetime_seconds = 0;
|
||||
uint16_t object_type = 0, object_type2 = 0;
|
||||
uint32_t object_instance = 0, object_instance2 = 0;
|
||||
bool status = false;
|
||||
BACNET_PROPERTY_VALUE value_list[2];
|
||||
|
||||
value_list[0].next = &value_list[1];
|
||||
value_list[1].next = NULL;
|
||||
/* existing? - match Object ID and Process ID */
|
||||
/* handle the subscription timeouts */
|
||||
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
|
||||
if (COV_Subscriptions[index].valid) {
|
||||
/* handle timeouts */
|
||||
@@ -413,44 +415,102 @@ void handler_cov_task(
|
||||
}
|
||||
if (COV_Subscriptions[index].lifetime == 0) {
|
||||
COV_Subscriptions[index].valid = false;
|
||||
if (COV_Subscriptions[index].issueConfirmedNotifications) {
|
||||
if (COV_Subscriptions[index].invokeID) {
|
||||
tsm_free_invoke_id(COV_Subscriptions[index].invokeID);
|
||||
COV_Subscriptions[index].invokeID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* handle COV notifications */
|
||||
object_type =
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handler_cov_task(void)
|
||||
{
|
||||
int index = 0;
|
||||
BACNET_OBJECT_TYPE object_type = MAX_BACNET_OBJECT_TYPE;
|
||||
uint32_t object_instance = 0;
|
||||
bool status = false;
|
||||
BACNET_PROPERTY_VALUE value_list[2];
|
||||
|
||||
/* configure the linked list for the two properties */
|
||||
value_list[0].next = &value_list[1];
|
||||
value_list[1].next = NULL;
|
||||
/* mark any subscriptions where the value has changed */
|
||||
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
|
||||
if (COV_Subscriptions[index].valid) {
|
||||
object_type = (BACNET_OBJECT_TYPE)
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.type;
|
||||
object_instance =
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.instance;
|
||||
status =
|
||||
Device_Encode_Value_List(object_type, object_instance,
|
||||
&value_list[0]);
|
||||
status = Device_COV(object_type, object_instance);
|
||||
if (status) {
|
||||
COV_Subscriptions[index].send_requested = true;
|
||||
}
|
||||
if (COV_Subscriptions[index].send_requested) {
|
||||
cov_send_request(&COV_Subscriptions[index], &value_list[0]);
|
||||
COV_Subscriptions[index].send_requested = false;
|
||||
}
|
||||
}
|
||||
/* clear the COV flag after checking all subscriptions (dup objects) */
|
||||
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
|
||||
if (COV_Subscriptions[index].valid) {
|
||||
object_type = (BACNET_OBJECT_TYPE)
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.type;
|
||||
object_instance =
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.instance;
|
||||
status = Device_COV(object_type, object_instance);
|
||||
if (status) {
|
||||
Device_COV_Clear(object_type, object_instance);
|
||||
}
|
||||
if (status && ((index + 1) < MAX_COV_SUBCRIPTIONS)) {
|
||||
/* if more than one subscription for this object instance */
|
||||
for (index2 = index + 1; index2 < MAX_COV_SUBCRIPTIONS;
|
||||
index2++) {
|
||||
object_type2 =
|
||||
COV_Subscriptions[index2].monitoredObjectIdentifier.
|
||||
type;
|
||||
object_instance2 =
|
||||
COV_Subscriptions[index2].monitoredObjectIdentifier.
|
||||
instance;
|
||||
if ((COV_Subscriptions[index].lifetime) &&
|
||||
(COV_Subscriptions[index].valid) &&
|
||||
(object_type == object_type2) &&
|
||||
(object_instance == object_instance2)) {
|
||||
cov_send_request(&COV_Subscriptions[index2],
|
||||
&value_list[0]);
|
||||
COV_Subscriptions[index2].send_requested = false;
|
||||
}
|
||||
}
|
||||
/* confirmed notification house keeping */
|
||||
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
|
||||
if (COV_Subscriptions[index].valid) {
|
||||
if (COV_Subscriptions[index].issueConfirmedNotifications) {
|
||||
if (COV_Subscriptions[index].invokeID) {
|
||||
if (tsm_invoke_id_free(COV_Subscriptions[index].invokeID)) {
|
||||
COV_Subscriptions[index].invokeID = 0;
|
||||
} else if (tsm_invoke_id_failed(
|
||||
COV_Subscriptions[index].invokeID)) {
|
||||
tsm_free_invoke_id(COV_Subscriptions[index].invokeID);
|
||||
COV_Subscriptions[index].invokeID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* send any COVs that are requested */
|
||||
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
|
||||
if (COV_Subscriptions[index].valid) {
|
||||
if (COV_Subscriptions[index].send_requested) {
|
||||
if (COV_Subscriptions[index].issueConfirmedNotifications) {
|
||||
if (COV_Subscriptions[index].invokeID != 0) {
|
||||
/* already sending - be patient! */
|
||||
continue;
|
||||
}
|
||||
if (!tsm_transaction_available()) {
|
||||
/* no free transactions - be patient! */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
object_type = (BACNET_OBJECT_TYPE)
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.type;
|
||||
object_instance =
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.instance;
|
||||
(void)Device_Encode_Value_List(object_type, object_instance,
|
||||
&value_list[0]);
|
||||
status = cov_send_request(
|
||||
&COV_Subscriptions[index],
|
||||
&value_list[0]);
|
||||
if (status) {
|
||||
COV_Subscriptions[index].send_requested = false;
|
||||
} else {
|
||||
/* must be out of PDU space - stop for now */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool cov_subscribe(
|
||||
@@ -460,10 +520,10 @@ static bool cov_subscribe(
|
||||
BACNET_ERROR_CODE * error_code)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
uint16_t object_type = 0;
|
||||
BACNET_OBJECT_TYPE object_type = MAX_BACNET_OBJECT_TYPE;
|
||||
uint32_t object_instance = 0;
|
||||
|
||||
object_type = cov_data->monitoredObjectIdentifier.type;
|
||||
object_type = (BACNET_OBJECT_TYPE)cov_data->monitoredObjectIdentifier.type;
|
||||
object_instance = cov_data->monitoredObjectIdentifier.instance;
|
||||
status = Device_Valid_Object_Id(object_type, object_instance);
|
||||
if (status) {
|
||||
@@ -518,7 +578,7 @@ void handler_cov_subscribe(
|
||||
bool error = false;
|
||||
|
||||
/* initialize a common abort code */
|
||||
cov_data.error_code = ABORT_REASON_SEGMENTATION_NOT_SUPPORTED;
|
||||
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);
|
||||
|
||||
@@ -45,20 +45,66 @@ void handler_unconfirmed_private_transfer(
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
BACNET_PRIVATE_TRANSFER_DATA private_data;
|
||||
BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */
|
||||
BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */
|
||||
int len = 0;
|
||||
uint8_t *application_data;
|
||||
int application_data_len;
|
||||
bool first_value = true;
|
||||
bool print_brace = false;
|
||||
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "Received Unconfirmed Private Transfer Request!\n");
|
||||
#endif
|
||||
(void) src;
|
||||
len =
|
||||
ptransfer_decode_service_request(service_request, service_len,
|
||||
&private_data);
|
||||
len = ptransfer_decode_service_request(
|
||||
service_request, service_len, &private_data);
|
||||
if (len >= 0) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"UnconfirmedPrivateTransfer: " "vendorID=%u serviceNumber=%u\n",
|
||||
private_data.vendorID, private_data.serviceNumber);
|
||||
printf("PrivateTransfer:vendorID=%u\r\n",
|
||||
(unsigned)private_data.vendorID);
|
||||
printf("PrivateTransfer:serviceNumber=%lu\r\n",
|
||||
(unsigned long)private_data.serviceNumber);
|
||||
#endif
|
||||
application_data = private_data.serviceParameters;
|
||||
application_data_len = private_data.serviceParametersLen;
|
||||
for (;;) {
|
||||
len =
|
||||
bacapp_decode_application_data(application_data,
|
||||
(uint8_t) application_data_len, &value);
|
||||
if (first_value && (len < application_data_len)) {
|
||||
first_value = false;
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stdout, "{");
|
||||
#endif
|
||||
print_brace = true;
|
||||
}
|
||||
/* private transfer doesn't provide any clues */
|
||||
object_value.object_type = MAX_BACNET_OBJECT_TYPE;
|
||||
object_value.object_instance = BACNET_MAX_INSTANCE;
|
||||
object_value.object_property = MAX_BACNET_PROPERTY_ID;
|
||||
object_value.array_index = BACNET_ARRAY_ALL;
|
||||
object_value.value = &value;
|
||||
bacapp_print_value(stdout, &object_value);
|
||||
if (len > 0) {
|
||||
if (len < application_data_len) {
|
||||
application_data += len;
|
||||
application_data_len -= len;
|
||||
/* there's more! */
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stdout, ",");
|
||||
#endif
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if PRINT_ENABLED
|
||||
if (print_brace)
|
||||
fprintf(stdout, "}");
|
||||
fprintf(stdout, "\r\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user