Adding COV support.

This commit is contained in:
skarg
2007-12-28 19:53:34 +00:00
parent d1ad21a4cc
commit 9ab6d4165f
3 changed files with 68 additions and 10 deletions
+38 -7
View File
@@ -31,6 +31,7 @@
#include "txbuf.h" #include "txbuf.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacaddr.h"
#include "apdu.h" #include "apdu.h"
#include "npdu.h" #include "npdu.h"
#include "abort.h" #include "abort.h"
@@ -54,6 +55,7 @@
of an object that have been specified in the standard. */ of an object that have been specified in the standard. */
typedef struct BACnet_COV_Subscription { typedef struct BACnet_COV_Subscription {
bool valid; bool valid;
BACNET_ADDRESS dest;
uint32_t subscriberProcessIdentifier; uint32_t subscriberProcessIdentifier;
BACNET_OBJECT_ID monitoredObjectIdentifier; BACNET_OBJECT_ID monitoredObjectIdentifier;
bool issueConfirmedNotifications; /* optional */ bool issueConfirmedNotifications; /* optional */
@@ -70,6 +72,7 @@ void handler_cov_init(
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) { for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
COV_Subscriptions[index].valid = false; COV_Subscriptions[index].valid = false;
COV_Subscriptions[index].dest.mac_len = 0;
COV_Subscriptions[index].subscriberProcessIdentifier = 0; COV_Subscriptions[index].subscriberProcessIdentifier = 0;
COV_Subscriptions[index].monitoredObjectIdentifier.type = COV_Subscriptions[index].monitoredObjectIdentifier.type =
OBJECT_ANALOG_INPUT; OBJECT_ANALOG_INPUT;
@@ -101,12 +104,12 @@ static bool cov_list_subscribe(
if (cov_data->cancellationRequest) { if (cov_data->cancellationRequest) {
COV_Subscriptions[index].valid = false; COV_Subscriptions[index].valid = false;
} else { } else {
bacnet_address_copy(&COV_Subscriptions[index].dest, src);
COV_Subscriptions[index].issueConfirmedNotifications = COV_Subscriptions[index].issueConfirmedNotifications =
cov_data->issueConfirmedNotifications; cov_data->issueConfirmedNotifications;
COV_Subscriptions[index].lifetime = COV_Subscriptions[index].lifetime =
cov_data->lifetime; cov_data->lifetime;
} }
/* FIXME: update SRC address */
break; break;
} else { } else {
if (first_invalid_index < 0) { if (first_invalid_index < 0) {
@@ -118,9 +121,8 @@ static bool cov_list_subscribe(
(!cov_data->cancellationRequest)) { (!cov_data->cancellationRequest)) {
index = first_invalid_index; index = first_invalid_index;
found = true; found = true;
if (!cov_data->cancellationRequest) { COV_Subscriptions[index].valid = true;
COV_Subscriptions[index].valid = true; bacnet_address_copy(&COV_Subscriptions[index].dest, src);
}
COV_Subscriptions[index].monitoredObjectIdentifier.type = COV_Subscriptions[index].monitoredObjectIdentifier.type =
cov_data->monitoredObjectIdentifier.type; cov_data->monitoredObjectIdentifier.type;
COV_Subscriptions[index].monitoredObjectIdentifier.instance = COV_Subscriptions[index].monitoredObjectIdentifier.instance =
@@ -131,7 +133,6 @@ static bool cov_list_subscribe(
cov_data->issueConfirmedNotifications; cov_data->issueConfirmedNotifications;
COV_Subscriptions[index].lifetime = COV_Subscriptions[index].lifetime =
cov_data->lifetime; cov_data->lifetime;
/* FIXME: add SRC address */
} else { } else {
found = false; found = false;
} }
@@ -144,8 +145,38 @@ static bool cov_list_subscribe(
void handler_cov_task( void handler_cov_task(
uint32_t elapsed_milliseconds) uint32_t elapsed_milliseconds)
{ {
/* handle timeouts */ int index;
/* handle COV notifications */ int lifetime_milliseconds;
BACNET_OBJECT_ID object_id;
/* existing? - match Object ID and Process ID */
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
if (COV_Subscriptions[index].valid) {
/* handle timeouts */
lifetime_milliseconds = COV_Subscriptions[index].lifetime;
if (lifetime_milliseconds >= elapsed_milliseconds) {
COV_Subscriptions[index].lifetime -= elapsed_milliseconds;
} else {
COV_Subscriptions[index].lifetime = 0;
}
if (COV_Subscriptions[index].lifetime == 0) {
COV_Subscriptions[index].valid = false;
}
/* handle COV notifications */
object_id.type = COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_id.instance = COV_Subscriptions[index].monitoredObjectIdentifier.instance;
switch (object_id.type) {
case OBJECT_BINARY_INPUT:
if (Binary_Input_Change_Of_Value(object_id.instance)) {
/* FIXME: send confirmed or unconfirmed request */
}
break;
default:
break;
}
}
}
} }
static bool cov_subscribe( static bool cov_subscribe(
+28 -2
View File
@@ -40,6 +40,8 @@
static BACNET_BINARY_PV Present_Value[MAX_BINARY_INPUTS]; static BACNET_BINARY_PV Present_Value[MAX_BINARY_INPUTS];
/* out of service decouples physical input from Present_Value */ /* out of service decouples physical input from Present_Value */
static bool Out_Of_Service[MAX_BINARY_INPUTS]; static bool Out_Of_Service[MAX_BINARY_INPUTS];
/* Change of Value flag */
static bool Change_Of_Value[MAX_BINARY_INPUTS];
/* These three arrays are used by the ReadPropertyMultiple handler */ /* These three arrays are used by the ReadPropertyMultiple handler */
static const int Binary_Input_Properties_Required[] = { static const int Binary_Input_Properties_Required[] = {
@@ -168,6 +170,19 @@ static bool Binary_Input_Out_Of_Service(
return value; return value;
} }
bool Binary_Input_Change_Of_Value(
uint32_t object_instance)
{
bool status = false;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < MAX_BINARY_INPUTS) {
status = Change_Of_Value[index];
}
return status;
}
static void Binary_Input_Present_Value_Set( static void Binary_Input_Present_Value_Set(
uint32_t object_instance, uint32_t object_instance,
BACNET_BINARY_PV value) BACNET_BINARY_PV value)
@@ -176,8 +191,12 @@ static void Binary_Input_Present_Value_Set(
Binary_Input_Init(); Binary_Input_Init();
index = Binary_Input_Instance_To_Index(object_instance); index = Binary_Input_Instance_To_Index(object_instance);
if (index < MAX_BINARY_INPUTS) if (index < MAX_BINARY_INPUTS) {
if (Present_Value[index] != value) {
Change_Of_Value[index] = true;
}
Present_Value[index] = value; Present_Value[index] = value;
}
return; return;
} }
@@ -191,6 +210,9 @@ static void Binary_Input_Out_Of_Service_Set(
Binary_Input_Init(); Binary_Input_Init();
index = Binary_Input_Instance_To_Index(object_instance); index = Binary_Input_Instance_To_Index(object_instance);
if (index < MAX_BINARY_INPUTS) if (index < MAX_BINARY_INPUTS)
if (Out_Of_Service[index] != value) {
Change_Of_Value[index] = true;
}
Out_Of_Service[index] = value; Out_Of_Service[index] = value;
return; return;
@@ -257,7 +279,11 @@ int Binary_Input_Encode_Property_APDU(
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, false); if (Binary_Input_Out_Of_Service(object_instance)) {
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, true);
} else {
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, false);
}
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_STATE: case PROP_EVENT_STATE:
+2 -1
View File
@@ -45,7 +45,8 @@ extern "C" {
unsigned index); unsigned index);
char *Binary_Input_Name( char *Binary_Input_Name(
uint32_t object_instance); uint32_t object_instance);
bool Binary_Input_Change_Of_Value(
uint32_t object_instance);
int Binary_Input_Encode_Property_APDU( int Binary_Input_Encode_Property_APDU(
uint8_t * apdu, uint8_t * apdu,
uint32_t object_instance, uint32_t object_instance,