1
0
mirror of https://github.com/stargieg/bacnet-stack synced 2025-10-26 23:35:52 +08:00

add uci init loop for bi

This commit is contained in:
Patrick Grimm 2014-02-23 01:54:36 +01:00
parent 4bba8ea862
commit 7815f3cc28
3 changed files with 249 additions and 132 deletions

View File

@ -31,22 +31,33 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "bacapp.h"
#include "bactext.h"
#include "cov.h"
#include "config.h" /* the custom stuff */
#include "device.h"
#include "handlers.h"
#include "bi.h"
#include "ucix.h"
/* number of demo objects */
#ifndef MAX_BINARY_INPUTS
#define MAX_BINARY_INPUTS 512
#define MAX_BINARY_INPUTS 65535
#endif
unsigned max_binary_inputs_int = 0;
/* When all the priorities are level null, the present value returns */
/* the Relinquish Default value */
#define BINARY_RELINQUISH_DEFAULT 0
/* we choose to have a NULL level in our system represented by */
/* a particular value. When the priorities are not in use, they */
/* will be relinquished (i.e. set to the NULL level). */
#define BINARY_LEVEL_NULL 255
BINARY_INPUT_DESCR BI_Descr[MAX_BINARY_INPUTS];
@ -105,6 +116,26 @@ void Binary_Input_Property_Lists(
return;
}
void Binary_Input_Load_UCI_List(const char *sec_idx,
struct bi_inst_itr_ctx *itr)
{
bi_inst_tuple_t *t = malloc(sizeof(bi_inst_tuple_t));
bool disable;
disable = ucix_get_option_int(itr->ctx, itr->section, sec_idx,
"disable", 0);
if (strcmp(sec_idx,"default") == 0)
return;
if (disable)
return;
if( (t = (bi_inst_tuple_t *)malloc(sizeof(bi_inst_tuple_t))) != NULL ) {
strncpy(t->idx, sec_idx, sizeof(t->idx));
t->next = itr->list;
itr->list = t;
}
return;
}
/*
* Things to do when starting up the stack for Binary Input.
* Should be called whenever we reset the device or power it up
@ -139,46 +170,62 @@ void Binary_Input_Init(
int ucialarm_value;
int ucipolarity_default;
int ucipolarity;
fprintf(stderr, "Binary_Input_Init\n");
const char *sec = "bacnet_bi";
char *section;
char *type;
struct bi_inst_itr_ctx itr_m;
section = "bacnet_bi";
#if PRINT_ENABLED
fprintf(stderr, "Binary_Input_Init\n");
#endif
if (!initialized) {
initialized = true;
ctx = ucix_init("bacnet_bi");
#if PRINT_ENABLED
if(!ctx)
fprintf(stderr, "Failed to load config file bacnet_bi\n");
ucidescription_default = ucix_get_option(ctx, "bacnet_bi", "default",
"description");
uciinactive_text_default = ucix_get_option(ctx, "bacnet_bi", "default",
"inactive");
uciactive_text_default = ucix_get_option(ctx, "bacnet_bi", "default",
"active");
ucinc_default = ucix_get_option_int(ctx, "bacnet_bi", "default",
"nc", -1);
ucievent_default = ucix_get_option_int(ctx, "bacnet_bi", "default",
"event", -1);
ucitime_delay_default = ucix_get_option_int(ctx, "bacnet_bi", "default",
"time_delay", -1);
ucialarm_value_default = ucix_get_option_int(ctx, "bacnet_bi", "default",
"alarm_value", -1);
ucipolarity_default = ucix_get_option_int(ctx, "bacnet_bi", "default",
"polarity", 0);
#endif
type = "bi";
bi_inst_tuple_t *cur = malloc(sizeof (bi_inst_tuple_t));
itr_m.list = NULL;
itr_m.section = section;
itr_m.ctx = ctx;
ucix_for_each_section_type(ctx, section, type,
(void *)Binary_Input_Load_UCI_List, &itr_m);
/* initialize all the values */
for (i = 0; i < MAX_BINARY_INPUTS; i++) {
memset(&BI_Descr[i], 0x00, sizeof(BINARY_INPUT_DESCR));
sprintf(idx_cc,"%d",i);
ucidescription_default = ucix_get_option(ctx, sec, "default",
"description");
uciinactive_text_default = ucix_get_option(ctx, sec, "default",
"inactive");
uciactive_text_default = ucix_get_option(ctx, sec, "default",
"active");
ucinc_default = ucix_get_option_int(ctx, sec, "default",
"nc", -1);
ucievent_default = ucix_get_option_int(ctx, sec, "default",
"event", -1);
ucitime_delay_default = ucix_get_option_int(ctx, sec, "default",
"time_delay", -1);
ucialarm_value_default = ucix_get_option_int(ctx, sec, "default",
"alarm_value", -1);
ucipolarity_default = ucix_get_option_int(ctx, sec, "default",
"polarity", 0);
i = 0;
for( cur = itr_m.list; cur; cur = cur->next ) {
strncpy(idx_cc, cur->idx, sizeof(idx_cc));
idx_c = idx_cc;
uciname = ucix_get_option(ctx, "bacnet_bi", idx_c, "name");
ucidisable = ucix_get_option_int(ctx, "bacnet_bi", idx_c,
"disable", 0);
if ((uciname != 0) && (ucidisable == 0)) {
BI_Descr[i].Disable=false;
memset(&BI_Descr[i], 0x00, sizeof(BINARY_INPUT_DESCR));
/* initialize all the priority arrays to NULL */
for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
BI_Descr[i].Priority_Array[j] = BINARY_NULL;
BI_Descr[i].Priority_Array[j] = BINARY_LEVEL_NULL;
}
max_binary_inputs = i+1;
BI_Descr[i].Instance=atoi(idx_cc);
BI_Descr[i].Disable=false;
sprintf(name, "%s", uciname);
ucix_string_copy(BI_Descr[i].Object_Name,
sizeof(BI_Descr[i].Object_Name), name);
@ -265,15 +312,16 @@ void Binary_Input_Init(
handler_get_alarm_summary_set(OBJECT_BINARY_INPUT,
Binary_Input_Alarm_Summary);
#endif
} else {
BI_Descr[i].Disable=true;
i++;
max_binary_inputs_int = i;
}
}
fprintf(stderr, "max_binary_inputs %i\n", max_binary_inputs);
#if PRINT_ENABLED
fprintf(stderr, "max_binary_inputs %i\n", max_binary_inputs_int);
#endif
if(ctx)
ucix_cleanup(ctx);
}
return;
}
@ -283,13 +331,16 @@ void Binary_Input_Init(
unsigned Binary_Input_Instance_To_Index(
uint32_t object_instance)
{
unsigned index = max_binary_inputs;
if (object_instance < max_binary_inputs) {
index = object_instance;
BINARY_INPUT_DESCR *CurrentBI;
int index,i;
index = max_binary_inputs_int;
for (i = 0; i < index; i++) {
CurrentBI = &BI_Descr[i];
if (CurrentBI->Instance == object_instance) {
return i;
}
}
return index;
return MAX_BINARY_INPUTS;
}
/* we simply have 0-n object instances. Yours might be */
@ -299,16 +350,10 @@ uint32_t Binary_Input_Index_To_Instance(
unsigned index)
{
BINARY_INPUT_DESCR *CurrentBI;
if (index < max_binary_inputs) {
CurrentBI = &BI_Descr[index];
if (CurrentBI->Disable == false) {
return index;
} else {
return false;
}
} else {
return false;
}
uint32_t instance;
CurrentBI = &BI_Descr[index];
instance = CurrentBI->Instance;
return instance;
}
/* we simply have 0-n object instances. Yours might be */
@ -316,7 +361,7 @@ uint32_t Binary_Input_Index_To_Instance(
unsigned Binary_Input_Count(
void)
{
return max_binary_inputs;
return max_binary_inputs_int;
}
/* we simply have 0-n object instances. Yours might be */
@ -328,14 +373,16 @@ bool Binary_Input_Valid_Instance(
BINARY_INPUT_DESCR *CurrentBI;
unsigned index = 0; /* offset from instance lookup */
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
CurrentBI = &BI_Descr[index];
if (CurrentBI->Disable == false) {
return true;
} else {
return false;
}
if (index == MAX_BINARY_INPUTS) {
#if PRINT_ENABLED
fprintf(stderr, "Binary_Input_Valid_Instance %i invalid index %i max %i\n",
object_instance,index,max_binary_inputs_int);
#endif
return false;
}
CurrentBI = &BI_Descr[index];
if (CurrentBI->Disable == false)
return true;
return false;
}
@ -344,18 +391,18 @@ BACNET_BINARY_PV Binary_Input_Present_Value(
uint32_t object_instance)
{
BINARY_INPUT_DESCR *CurrentBI;
BACNET_BINARY_PV value = BINARY_INACTIVE;
BACNET_BINARY_PV value = BINARY_RELINQUISH_DEFAULT;
unsigned index = 0;
unsigned i = 0;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
/* When all the priorities are level null, the present value returns */
/* the Relinquish Default value */
value = CurrentBI->Relinquish_Default;
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
if (CurrentBI->Priority_Array[i] != BINARY_NULL) {
if (CurrentBI->Priority_Array[i] != BINARY_LEVEL_NULL) {
value = CurrentBI->Priority_Array[i];
break;
}
@ -365,6 +412,30 @@ BACNET_BINARY_PV Binary_Input_Present_Value(
return value;
}
unsigned Binary_Input_Present_Value_Priority(
uint32_t object_instance)
{
BINARY_INPUT_DESCR *CurrentBI;
unsigned index = 0; /* instance to index conversion */
unsigned i = 0; /* loop counter */
unsigned priority = 0; /* return value */
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
if (CurrentBI->Priority_Array[priority] != BINARY_LEVEL_NULL) {
priority = i + 1;
break;
}
}
}
return priority;
}
bool Binary_Input_Out_Of_Service(
uint32_t object_instance)
{
@ -372,8 +443,8 @@ bool Binary_Input_Out_Of_Service(
unsigned index = 0; /* offset from instance lookup */
bool value = false;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
value = CurrentBI->Out_Of_Service;
}
@ -388,8 +459,8 @@ void Binary_Input_Out_Of_Service_Set(
BINARY_INPUT_DESCR *CurrentBI;
unsigned index = 0;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
if (CurrentBI->Out_Of_Service != value) {
CurrentBI->Change_Of_Value = true;
@ -407,8 +478,8 @@ uint8_t Binary_Input_Reliability(
unsigned index = 0; /* offset from instance lookup */
uint8_t value = 0;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
value = CurrentBI->Reliability;
}
@ -423,8 +494,8 @@ void Binary_Input_Reliability_Set(
BINARY_INPUT_DESCR *CurrentBI;
unsigned index = 0;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
CurrentBI->Reliability = value;
}
@ -439,8 +510,8 @@ static char *Binary_Input_Description(
unsigned index = 0; /* offset from instance lookup */
char *pName = NULL; /* return value */
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
pName = CurrentBI->Object_Description;
}
@ -457,8 +528,8 @@ bool Binary_Input_Description_Set(
size_t i = 0; /* loop counter */
bool status = false; /* return value */
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
status = true;
if (new_name) {
@ -492,8 +563,8 @@ static bool Binary_Input_Description_Write(
const char *idx_c;
char idx_cc[64];
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
length = characterstring_length(char_string);
if (length <= sizeof(CurrentBI->Object_Description)) {
@ -512,9 +583,11 @@ static bool Binary_Input_Description_Write(
if(ctx) {
ucix_add_option(ctx, "bacnet_bi", idx_c,
"description", char_string->value);
#if PRINT_ENABLED
} else {
fprintf(stderr,
"Failed to open config file bacnet_bi\n");
#endif
}
}
} else {
@ -539,9 +612,8 @@ bool Binary_Input_Object_Name(
unsigned index = 0; /* offset from instance lookup */
bool status = false;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
status = characterstring_init_ansi(object_name, CurrentBI->Object_Name);
}
@ -559,8 +631,8 @@ bool Binary_Input_Name_Set(
size_t i = 0; /* loop counter */
bool status = false; /* return value */
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
status = true;
/* FIXME: check to see if there is a matching name */
@ -595,8 +667,8 @@ static bool Binary_Input_Object_Name_Write(
const char *idx_c;
char idx_cc[64];
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
length = characterstring_length(char_string);
if (length <= sizeof(CurrentBI->Object_Name)) {
@ -638,10 +710,10 @@ bool Binary_Input_Change_Of_Value(
{
BINARY_INPUT_DESCR *CurrentBI;
bool status = false;
unsigned index;
unsigned index = 0;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
status = CurrentBI->Change_Of_Value;
}
@ -653,10 +725,10 @@ void Binary_Input_Change_Of_Value_Clear(
uint32_t object_instance)
{
BINARY_INPUT_DESCR *CurrentBI;
unsigned index;
unsigned index = 0;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
CurrentBI->Change_Of_Value = false;
}
@ -716,10 +788,10 @@ bool Binary_Input_Present_Value_Set(
unsigned index = 0; /* offset from instance lookup */
bool status = false;
if (value > 1)
value = BINARY_NULL;
value = BINARY_LEVEL_NULL;
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
CurrentBI->Present_Value = (uint8_t) value;
CurrentBI->Priority_Array[priority - 1] = (uint8_t) value;
@ -736,8 +808,8 @@ BACNET_POLARITY Binary_Input_Polarity(
BACNET_POLARITY polarity = POLARITY_NORMAL;
index = Binary_Input_Instance_To_Index(object_instance);
if (object_instance < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
polarity = CurrentBI->Polarity;
}
@ -755,8 +827,8 @@ bool Binary_Input_Polarity_Set(
const char *idx_c;
char idx_cc[64];
index = Binary_Input_Instance_To_Index(object_instance);
if (object_instance < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
CurrentBI->Polarity=polarity;
sprintf(idx_cc,"%d",index);
@ -787,8 +859,8 @@ static bool Binary_Input_Active_Text_Write(
const char *idx_c;
char idx_cc[64];
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
length = characterstring_length(char_string);
if (length <= sizeof(CurrentBI->Active_Text)) {
@ -837,8 +909,8 @@ static bool Binary_Input_Inactive_Text_Write(
const char *idx_c;
char idx_cc[64];
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs) {
if (Binary_Input_Valid_Instance(object_instance)) {
index = Binary_Input_Instance_To_Index(object_instance);
CurrentBI = &BI_Descr[index];
length = characterstring_length(char_string);
if (length <= sizeof(CurrentBI->Inactive_Text)) {
@ -884,7 +956,7 @@ int Binary_Input_Read_Property(
BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string;
BACNET_BINARY_PV present_value = 0;
unsigned object_index = 0;
unsigned index = 0;
unsigned i = 0;
uint8_t *apdu = NULL;
@ -894,12 +966,10 @@ int Binary_Input_Read_Property(
}
apdu = rpdata->application_data;
object_index = Binary_Input_Instance_To_Index(rpdata->object_instance);
if (object_index < max_binary_inputs)
CurrentBI = &BI_Descr[object_index];
else
return BACNET_STATUS_ERROR;
if (CurrentBI->Disable)
if (Binary_Input_Valid_Instance(rpdata->object_instance)) {
index = Binary_Input_Instance_To_Index(rpdata->object_instance);
CurrentBI = &BI_Descr[index];
} else
return BACNET_STATUS_ERROR;
//fprintf(stderr,"object_property: %i\n", rpdata->object_property);
@ -990,7 +1060,7 @@ int Binary_Input_Read_Property(
} else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */
if (CurrentBI->Priority_Array[i] == BINARY_NULL) {
if (CurrentBI->Priority_Array[i] == BINARY_LEVEL_NULL) {
len = encode_application_null(&apdu[apdu_len]);
} else {
present_value = CurrentBI->Priority_Array[i];
@ -1011,7 +1081,7 @@ int Binary_Input_Read_Property(
} else {
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (CurrentBI->Priority_Array[rpdata->array_index - 1]
== BINARY_NULL)
== BINARY_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
present_value =
@ -1175,16 +1245,19 @@ bool Binary_Input_Write_Property(
{
BINARY_INPUT_DESCR *CurrentBI;
bool status = false; /* return value */
unsigned int object_index = 0;
unsigned int index = 0;
int object_type = 0;
uint32_t object_instance = 0;
unsigned int priority = 0;
uint8_t level = BINARY_NULL;
uint8_t level = BINARY_LEVEL_NULL;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
ctx = ucix_init("bacnet_bi");
const char index_c[32] = "";
const char *idx_c;
BACNET_BINARY_PV pvalue = 0;
int i;
time_t cur_value_time;
char idx_cc[64];
/* decode the some of the request */
@ -1205,10 +1278,10 @@ bool Binary_Input_Write_Property(
return false;
}
object_index = Binary_Input_Instance_To_Index(wp_data->object_instance);
if (object_index < max_binary_inputs) {
CurrentBI = &BI_Descr[object_index];
sprintf(idx_cc,"%d",object_index);
if (Binary_Input_Valid_Instance(wp_data->object_instance)) {
index = Binary_Input_Instance_To_Index(wp_data->object_instance);
CurrentBI = &BI_Descr[index];
sprintf(idx_cc,"%d",index);
idx_c = idx_cc;
} else
return false;
@ -1265,6 +1338,13 @@ bool Binary_Input_Write_Property(
if (Binary_Input_Present_Value_Set(wp_data->object_instance,
value.type.Unsigned_Int, wp_data->priority)) {
status = true;
ucix_add_option_int(ctx, "bacnet_bi", idx_c, "value",
value.type.Unsigned_Int);
cur_value_time = time(NULL);
ucix_add_option_int(ctx, "bacnet_bi", idx_c, "value_time",
cur_value_time);
ucix_add_option_int(ctx, "bacnet_bi", idx_c, "write",
1);
} else if (wp_data->priority == 6) {
/* Command priority 6 is reserved for use by Minimum On/Off
algorithm and may not be used for other purposes in any
@ -1280,7 +1360,7 @@ bool Binary_Input_Write_Property(
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = BINARY_NULL;
level = BINARY_LEVEL_NULL;
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
@ -1291,6 +1371,20 @@ bool Binary_Input_Write_Property(
However, if Out of Service is TRUE, then don't set the
physical output. This comment may apply to the
main loop (i.e. check out of service before changing output) */
pvalue = CurrentBI->Relinquish_Default;
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
if (CurrentBI->Priority_Array[i] != BINARY_LEVEL_NULL) {
pvalue = CurrentBI->Priority_Array[i];
break;
}
}
ucix_add_option_int(ctx, "bacnet_bi", idx_c, "value",
pvalue);
cur_value_time = time(NULL);
ucix_add_option_int(ctx, "bacnet_bi", idx_c, "value_time",
cur_value_time);
ucix_add_option_int(ctx, "bacnet_bi", idx_c, "write",
1);
} else {
status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY;
@ -1481,16 +1575,16 @@ void Binary_Input_Intrinsic_Reporting(
BINARY_INPUT_DESCR *CurrentBI;
BACNET_EVENT_NOTIFICATION_DATA event_data;
BACNET_CHARACTER_STRING msgText;
unsigned int object_index;
unsigned int index;
uint8_t FromState = 0;
uint8_t ToState;
uint8_t PresentVal = 0;
bool SendNotify = false;
bool tonormal = true;
object_index = Binary_Input_Instance_To_Index(object_instance);
if (object_index < max_binary_inputs)
CurrentBI = &BI_Descr[object_index];
index = Binary_Input_Instance_To_Index(object_instance);
if (index < max_binary_inputs_int)
CurrentBI = &BI_Descr[index];
else
return;
@ -1717,8 +1811,7 @@ int Binary_Input_Event_Information(
/* check index */
if (index < max_binary_inputs) {
//CurrentBI = &BI_Descr[index];
if (Binary_Input_Valid_Instance(index)) {
/* Event_State not equal to NORMAL */
IsActiveEvent = (BI_Descr[index].Event_State != EVENT_STATE_NORMAL);
@ -1786,16 +1879,14 @@ int Binary_Input_Alarm_Ack(
BACNET_ERROR_CODE * error_code)
{
BINARY_INPUT_DESCR *CurrentBI;
unsigned int object_index;
unsigned int index;
object_index =
Binary_Input_Instance_To_Index(alarmack_data->
eventObjectIdentifier.instance);
if (object_index < max_binary_inputs)
CurrentBI = &BI_Descr[object_index];
else {
if (Binary_Input_Valid_Instance(alarmack_data->
eventObjectIdentifier.instance)) {
index = Binary_Input_Instance_To_Index(alarmack_data->
eventObjectIdentifier.instance);
CurrentBI = &BI_Descr[index];
} else {
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
return -1;
}
@ -1887,8 +1978,9 @@ int Binary_Input_Alarm_Summary(
BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data)
{
BINARY_INPUT_DESCR *CurrentBI;
/* check index */
if (index < max_binary_inputs) {
if (index < max_binary_inputs_int) {
CurrentBI = &BI_Descr[index];
/* Event_State is not equal to NORMAL and
Notify_Type property value is ALARM */

View File

@ -31,6 +31,7 @@
#include <stdint.h>
#include "bacdef.h"
#include "cov.h"
#include "bacerror.h"
#include "rp.h"
#include "wp.h"
#if defined(INTRINSIC_REPORTING)
@ -44,9 +45,8 @@
extern "C" {
#endif /* __cplusplus */
int max_binary_inputs;
typedef struct binary_input_descr {
uint32_t Instance;
char Object_Name[64];
char Object_Description[64];
BACNET_BINARY_PV Present_Value;
@ -77,6 +77,28 @@ int max_binary_inputs;
} BINARY_INPUT_DESCR;
/* value/name tuples */
struct bi_inst_tuple {
char idx[18];
struct bi_inst_tuple *next;
};
typedef struct bi_inst_tuple bi_inst_tuple_t;
/* structure to hold tuple-list and uci context during iteration */
struct bi_inst_itr_ctx {
struct bi_inst_tuple *list;
struct uci_context *ctx;
char *section;
};
void Binary_Input_Load_UCI_List(
const char *sec_idx,
struct bi_inst_itr_ctx *itr);
void Binary_Input_Property_Lists(
const int **pRequired,
const int **pOptional,
@ -168,6 +190,9 @@ int max_binary_inputs;
BACNET_BINARY_PV value,
uint8_t priority);
unsigned Binary_Input_Present_Value_Priority(
uint32_t object_instance);
/* note: header of Intrinsic_Reporting function is required
even when INTRINSIC_REPORTING is not defined */
void Binary_Input_Intrinsic_Reporting(

View File

@ -154,7 +154,6 @@ static object_functions_t My_Object_Table[] = {
Analog_Value_Change_Of_Value,
Analog_Value_Change_Of_Value_Clear,
Analog_Value_Intrinsic_Reporting},
#if 0
{OBJECT_BINARY_INPUT,
Binary_Input_Init,
Binary_Input_Count,
@ -170,6 +169,7 @@ static object_functions_t My_Object_Table[] = {
Binary_Input_Change_Of_Value,
Binary_Input_Change_Of_Value_Clear,
Binary_Input_Intrinsic_Reporting},
#if 0
{OBJECT_BINARY_OUTPUT,
Binary_Output_Init,
Binary_Output_Count,