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

add uci initial support for av mv and nc

This commit is contained in:
Patrick Grimm 2013-03-22 00:28:24 +01:00
parent 60bd7685d1
commit a50c10f49a
8 changed files with 1734 additions and 125 deletions

View File

@ -17,6 +17,8 @@ BACNET_HANDLER = ../../demo/handler
BACNET_LIB_DIR = ../../lib
BACNET_LIB_NAME = bacnet
BACNET_LIB_TARGET = $(BACNET_LIB_DIR)/lib$(BACNET_LIB_NAME).a
# UCI Library
UCI_LIB_DIR = /usr/local/lib
# Compiler Setup
INCLUDE1 = -I$(BACNET_PORT_DIR) -I$(BACNET_OBJECT) -I$(BACNET_HANDLER)
INCLUDE2 = -I$(BACNET_INCLUDE)
@ -26,15 +28,18 @@ PFLAGS = -pthread
TARGET_EXT =
LIBRARY1=-L$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME)
LIBRARY2=-lc,-lgcc,-lrt,-lm
LIBRARIES=$(LIBRARY1),$(LIBRARY2)
LIBRARY3=-L$(UCI_LIB_DIR),-luci
LIBRARIES=$(LIBRARY1),$(LIBRARY2),$(LIBRARY3)
endif
ifeq (${BACNET_PORT},bsd)
PFLAGS = -pthread
TARGET_EXT =
LIBRARY1=-L$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME)
LIBRARY2=-lc,-lgcc,-lm
LIBRARIES=$(LIBRARY1),$(LIBRARY2)
LIBRARY3=-L$(UCI_LIB_DIR),-luci
LIBRARIES=$(LIBRARY1),$(LIBRARY2),$(LIBRARY3)
endif
#TODO win32 UCI support?
ifeq (${BACNET_PORT},win32)
TARGET_EXT = .exe
LIBRARY1=-L$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME)

View File

@ -40,6 +40,7 @@
#include "device.h"
#include "handlers.h"
#include "av.h"
#include "ucix.h"
#ifndef MAX_ANALOG_VALUES
@ -55,6 +56,12 @@
ANALOG_VALUE_DESCR AV_Descr[MAX_ANALOG_VALUES];
/* Here is our Present Value */
static uint8_t Present_Value[MAX_ANALOG_VALUES];
static char Object_Name[MAX_ANALOG_VALUES][64];
static char Object_Description[MAX_ANALOG_VALUES][64];
/* These three arrays are used by the ReadPropertyMultiple handler */
static const int Analog_Value_Properties_Required[] = {
PROP_OBJECT_IDENTIFIER,
@ -110,6 +117,24 @@ void Analog_Value_Init(
void)
{
unsigned i, j;
const char description[64] = "";
const char *uciname;
const char *ucidescription;
const char *ucidescription_default;
int uciunit = 0;
int uciunit_default = 0;
int ucivalue = 0;
int ucivalue_default = 0;
const char int_to_string[64] = "";
struct uci_context *ctx;
//fprintf(stderr, "Analog_Value_Init\n");
ctx = ucix_init("bacnet_mv");
if(!ctx)
fprintf(stderr, "Failed to load config file");
ucidescription_default = ucix_get_option(ctx, "bacnet_mv", "default", "description");
uciunit_default = ucix_get_option_int(ctx, "bacnet_mv", "default", "si_unit", 0);
ucivalue_default = ucix_get_option_int(ctx, "bacnet_mv", "default", "value", 0);
for (i = 0; i < MAX_ANALOG_VALUES; i++) {
memset(&AV_Descr[i], 0x00, sizeof(ANALOG_VALUE_DESCR));
@ -117,11 +142,84 @@ void Analog_Value_Init(
for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
AV_Descr[i].Priority_Array[j] = ANALOG_LEVEL_NULL;
}
AV_Descr[i].Units = UNITS_PERCENT;
sprintf(int_to_string, "%lu", (unsigned long) i);
uciname = ucix_get_option(ctx, "bacnet_av", int_to_string, "name");
if (uciname != 0) {
//fprintf(stderr, "UCI Name %s \n",uciname);
for (j = 0; j < sizeof(Object_Name[i]); j++) {
if (uciname[j]) {
Object_Name[i][j] = uciname[j];
}
}
ucidescription = ucix_get_option(ctx, "bacnet_av", int_to_string, "description");
//fprintf(stderr, "UCI Description %s \n",ucidescription);
if (ucidescription != 0) {
sprintf(description, "%s", ucidescription);
} else if (ucidescription_default != 0) {
sprintf(description, "%s %lu", ucidescription_default , (unsigned long) i);
} else {
sprintf(description, "AV%lu no uci section configured", (unsigned long) i);
}
for (j = 0; j < sizeof(Object_Description[i]); j++) {
if (description[j]) {
Object_Description[i][j] = description[j];
}
}
uciunit = ucix_get_option_int(ctx, "bacnet_av", int_to_string, "si_unit", 0);
//fprintf(stderr, "UCI SI Unit %i \n",uciunit);
if (uciunit != 0) {
AV_Descr[i].Units = uciunit;
} else if (uciunit_default != 0) {
AV_Descr[i].Units = uciunit_default;
} else {
AV_Descr[i].Units = UNITS_PERCENT;
}
ucivalue = ucix_get_option_int(ctx, "bacnet_av", int_to_string, "value", 0);
//fprintf(stderr, "UCI Value %i \n",uciunit);
if (ucivalue != 0) {
AV_Descr[i].Priority_Array[15] = ucivalue;
Present_Value[i] = ucivalue;
} else if (ucivalue_default != 0) {
AV_Descr[i].Priority_Array[15] = ucivalue_default;
Present_Value[i] = ucivalue_default;
} else {
AV_Descr[i].Priority_Array[15] = 0;
Present_Value[i] = 0;
}
} else {
sprintf(int_to_string, "AV%lu_not_configured", (unsigned long) i);
//fprintf(stderr, "UCI Name %s \n",int_to_string);
for (j = 0; j < sizeof(Object_Name[i]); j++) {
if (int_to_string[j]) {
Object_Name[i][j] = int_to_string[j];
}
}
if (ucidescription_default != 0) {
sprintf(description, "%s %lu", ucidescription_default , (unsigned long) i);
} else {
sprintf(description, "MV%lu no uci section configured", (unsigned long) i);
}
for (j = 0; j < sizeof(Object_Description[i]); j++) {
if (description[j]) {
Object_Description[i][j] = description[j];
}
}
if (uciunit_default != 0) {
AV_Descr[i].Units = uciunit_default;
} else {
AV_Descr[i].Units = UNITS_PERCENT;
}
}
#if defined(INTRINSIC_REPORTING)
AV_Descr[i].Event_State = EVENT_STATE_NORMAL;
/* notification class not connected */
AV_Descr[i].Notification_Class = BACNET_MAX_INSTANCE;
//AV_Descr[i].Notification_Class = BACNET_MAX_INSTANCE;
AV_Descr[i].Notification_Class = 1;
AV_Descr[i].Event_Enable = 7;
AV_Descr[i].Limit_Enable = 3;
AV_Descr[i].High_Limit = 40;
AV_Descr[i].Low_Limit = 0;
/* initialize Event time stamps using wildcards
and set Acked_transitions */
for (j = 0; j < MAX_BACNET_EVENT_TRANSITION; j++) {
@ -218,7 +316,7 @@ float Analog_Value_Present_Value(
{
ANALOG_VALUE_DESCR *CurrentAV;
float value = 0;
unsigned index = 0;
unsigned index = 0; /* offset from instance lookup */
unsigned i = 0;
index = Analog_Value_Instance_To_Index(object_instance);
@ -238,18 +336,160 @@ float Analog_Value_Present_Value(
return value;
}
static char *Analog_Value_Description(
uint32_t object_instance)
{
unsigned index = 0; /* offset from instance lookup */
char *pName = NULL; /* return value */
index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) {
pName = Object_Description[index];
}
return pName;
}
bool Analog_Value_Description_Set(
uint32_t object_instance,
char *new_name)
{
unsigned index = 0; /* offset from instance lookup */
size_t i = 0; /* loop counter */
bool status = false; /* return value */
index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) {
status = true;
if (new_name) {
for (i = 0; i < sizeof(Object_Description[index]); i++) {
Object_Description[index][i] = new_name[i];
if (new_name[i] == 0) {
break;
}
}
} else {
for (i = 0; i < sizeof(Object_Description[index]); i++) {
Object_Description[index][i] = 0;
}
}
}
return status;
}
static bool Analog_Value_Description_Write(
uint32_t object_instance,
BACNET_CHARACTER_STRING *char_string,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
unsigned index = 0; /* offset from instance lookup */
size_t length = 0;
uint8_t encoding = 0;
bool status = false; /* return value */
index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) {
length = characterstring_length(char_string);
if (length <= sizeof(Object_Description[index])) {
encoding = characterstring_encoding(char_string);
if (encoding == CHARACTER_UTF8) {
status = characterstring_ansi_copy(
Object_Description[index],
sizeof(Object_Description[index]),
char_string);
if (!status) {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else {
struct uci_context *ctx;
const char index_c[32] = "";
sprintf(index_c, "%u", index);
ctx = ucix_init("bacnet_av");
if(ctx) {
ucix_add_option(ctx, "bacnet_av", index_c, "description", char_string->value);
ucix_commit(ctx, "bacnet_av");
ucix_cleanup(ctx);
} else {
fprintf(stderr, "Failed to open config file bacnet_av\n");
}
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
}
}
return status;
}
/* note: the object name must be unique within this device */
bool Analog_Value_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32] = ""; /* okay for single thread */
unsigned index = 0; /* offset from instance lookup */
bool status = false;
if (object_instance < MAX_ANALOG_VALUES) {
sprintf(text_string, "ANALOG VALUE %lu",
(unsigned long) object_instance);
status = characterstring_init_ansi(object_name, text_string);
index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) {
status = characterstring_init_ansi(object_name, Object_Name[index]);
}
return status;
}
static bool Analog_Value_Object_Name_Write(
uint32_t object_instance,
BACNET_CHARACTER_STRING *char_string,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
unsigned index = 0; /* offset from instance lookup */
size_t length = 0;
uint8_t encoding = 0;
bool status = false; /* return value */
index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) {
length = characterstring_length(char_string);
if (length <= sizeof(Object_Name[index])) {
encoding = characterstring_encoding(char_string);
if (encoding == CHARACTER_UTF8) {
status = characterstring_ansi_copy(
Object_Name[index],
sizeof(Object_Name[index]),
char_string);
if (!status) {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else {
struct uci_context *ctx;
const char index_c[32] = "";
sprintf(index_c, "%u", index);
ctx = ucix_init("bacnet_av");
if(ctx) {
ucix_add_option(ctx, "bacnet_av", index_c, "name", char_string->value);
ucix_commit(ctx, "bacnet_av");
ucix_cleanup(ctx);
} else {
fprintf(stderr, "Failed to open config file bacnet_av\n");
}
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
}
}
return status;
@ -291,12 +531,18 @@ int Analog_Value_Read_Property(
break;
case PROP_OBJECT_NAME:
case PROP_DESCRIPTION:
Analog_Value_Object_Name(rpdata->object_instance, &char_string);
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_DESCRIPTION:
characterstring_init_ansi(&char_string,
Analog_Value_Description(rpdata->object_instance));
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_ANALOG_VALUE);
@ -543,6 +789,8 @@ bool Analog_Value_Write_Property(
{
bool status = false; /* return value */
unsigned int object_index = 0;
int object_type = 0;
uint32_t object_instance = 0;
unsigned int priority = 0;
uint8_t level = ANALOG_LEVEL_NULL;
int len = 0;
@ -575,6 +823,44 @@ bool Analog_Value_Write_Property(
return false;
switch (wp_data->object_property) {
case PROP_OBJECT_NAME:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
/* All the object names in a device must be unique */
if (Device_Valid_Object_Name(&value.type.Character_String,
&object_type, &object_instance)) {
if ((object_type == wp_data->object_type) &&
(object_instance == wp_data->object_instance)) {
/* writing same name to same object */
status = true;
} else {
status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
}
} else {
status = Analog_Value_Object_Name_Write(
wp_data->object_instance,
&value.type.Character_String,
&wp_data->error_class,
&wp_data->error_code);
}
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
break;
case PROP_DESCRIPTION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = Analog_Value_Description_Write(
wp_data->object_instance,
&value.type.Character_String,
&wp_data->error_class,
&wp_data->error_code);
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
break;
case PROP_PRESENT_VALUE:
if (value.tag == BACNET_APPLICATION_TAG_REAL) {
/* Command priority 6 is reserved for use by Minimum On/Off
@ -752,11 +1038,9 @@ bool Analog_Value_Write_Property(
break;
#endif
case PROP_OBJECT_IDENTIFIER:
case PROP_OBJECT_NAME:
case PROP_OBJECT_TYPE:
case PROP_STATUS_FLAGS:
case PROP_EVENT_STATE:
case PROP_DESCRIPTION:
case PROP_PRIORITY_ARRAY:
#if defined(INTRINSIC_REPORTING)
case PROP_ACKED_TRANSITIONS:

View File

@ -88,6 +88,10 @@ extern "C" {
uint32_t object_instance,
BACNET_CHARACTER_STRING * object_name);
bool Analog_Value_Name_Set(
uint32_t object_instance,
char *new_name);
int Analog_Value_Read_Property(
BACNET_READ_PROPERTY_DATA * rpdata);
@ -119,6 +123,9 @@ extern "C" {
unsigned index,
BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data);
#endif
bool Analog_Value_Input_Description_Set(
uint32_t object_instance,
char *text_string);
void Analog_Value_Init(
void);

View File

@ -67,6 +67,7 @@
#if defined(BACFILE)
#include "bacfile.h"
#endif /* defined(BACFILE) */
#include "ucix.h"
#if defined(__BORLANDC__)
@ -303,7 +304,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Value_Lists */ ,
NULL /* COV */ ,
NULL /* COV Clear */ ,
NULL /* Intrinsic Reporting */ },
Multistate_Value_Intrinsic_Reporting },
#endif
{OBJECT_TRENDLOG,
Trend_Log_Init,
@ -690,6 +691,15 @@ bool Device_Set_Object_Name(
/* Make the change and update the database revision */
status = characterstring_copy(&My_Object_Name, object_name);
Device_Inc_Database_Revision();
struct uci_context *ctx;
ctx = ucix_init("bacnet_dev");
if(ctx) {
ucix_add_option(ctx, "bacnet_dev", "0", "name", object_name->value);
ucix_commit(ctx, "bacnet_dev");
ucix_cleanup(ctx);
} else {
fprintf(stderr, "Failed to open config file bacnet_dev\n");
}
}
return status;
@ -851,6 +861,15 @@ bool Device_Set_Description(
if (length < sizeof(Description)) {
memmove(Description, name, length);
Description[length] = 0;
struct uci_context *ctx;
ctx = ucix_init("bacnet_dev");
if(ctx) {
ucix_add_option(ctx, "bacnet_dev", "0", "description", name);
ucix_commit(ctx, "bacnet_dev");
ucix_cleanup(ctx);
} else {
fprintf(stderr, "Failed to open config file bacnet_dev\n");
}
status = true;
}
@ -872,6 +891,15 @@ bool Device_Set_Location(
if (length < sizeof(Location)) {
memmove(Location, name, length);
Location[length] = 0;
struct uci_context *ctx;
ctx = ucix_init("bacnet_dev");
if(ctx) {
ucix_add_option(ctx, "bacnet_dev", "0", "location", name);
ucix_commit(ctx, "bacnet_dev");
ucix_cleanup(ctx);
} else {
fprintf(stderr, "Failed to open config file bacnet_dev\n");
}
status = true;
}
@ -1812,6 +1840,50 @@ void Device_Init(
struct object_functions *pObject = NULL;
characterstring_init_ansi(&My_Object_Name, "SimpleServer");
struct uci_context *ctx;
static char *uci_name;
static char *uci_location;
static char *uci_description;
static char *uci_modelname;
//static int32_t uci_utc_offset;
//static bool uci_daylight_savings;
static char *uci_app_ver;
fprintf(stderr, "Device_Init\n");
ctx = ucix_init("bacnet_dev");
if(!ctx)
fprintf(stderr, "Failed to load config file bacnet_dev\n");
uci_name = ucix_get_option(ctx, "bacnet_dev", "0", "name");
if (uci_name != 0)
characterstring_init_ansi(&My_Object_Name, uci_name);
uci_location = ucix_get_option(ctx, "bacnet_dev", "0", "location");
if (uci_location != 0)
ucix_string_copy(&Location, sizeof(Location), uci_location);
uci_description = ucix_get_option(ctx, "bacnet_dev", "0", "description");
if (uci_description != 0)
ucix_string_copy(&Description, sizeof(Description), uci_description);
uci_modelname = ucix_get_option(ctx, "bacnet_dev", "0", "modelname");
if (uci_modelname != 0)
ucix_string_copy(&Model_Name, sizeof(Model_Name), uci_modelname);
//uci_utc_offset = ucix_get_option_int(ctx, "bacnet_dev", "0", "utc_offset", 0);
//if (uci_utc_offset != 0)
// UTC_Offset = uci_utc_offset;
//uci_daylight_savings = ucix_get_option_int(ctx, "bacnet_dev", "0", "daylight_savings", 0);
//if (uci_daylight_savings == 1)
// Daylight_Savings_Status = true;
uci_app_ver = ucix_get_option(ctx, "bacnet_dev", "0", "app_ver");
if (uci_app_ver != 0)
ucix_string_copy(&Application_Software_Version,
sizeof(Application_Software_Version), uci_app_ver);
ucix_cleanup(ctx);
if (object_table) {
Object_Table = object_table;
} else {

File diff suppressed because it is too large Load Diff

View File

@ -22,8 +22,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#ifndef MULTISTATE_VALUE_H
#define MULTISTATE_VALUE_H
#ifndef MULTI_STATE_VALUE_H
#define MULTI_STATE_VALUE_H
#include <stdbool.h>
#include <stdint.h>
@ -31,11 +31,49 @@
#include "bacerror.h"
#include "rp.h"
#include "wp.h"
#if defined(INTRINSIC_REPORTING)
#include "nc.h"
#include "alarm_ack.h"
#include "getevent.h"
#include "get_alarm_sum.h"
#endif /* INTRINSIC_REPORTING */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int max_multi_state_values;
typedef struct multistate_value_descr {
char Object_Name[64];
char Object_Description[64];
uint8_t Present_Value;
unsigned Event_State:3;
bool Out_Of_Service;
uint8_t Units;
char State_Text[254][64];
int number_of_states;
/* Here is our Priority Array. They are supposed to be Real, but */
/* we don't have that kind of memory, so we will use a single byte */
/* and load a Real for returning the value when asked. */
uint8_t Priority_Array[BACNET_MAX_PRIORITY];
unsigned Relinquish_Default;
#if defined(INTRINSIC_REPORTING)
uint32_t Time_Delay;
uint32_t Notification_Class;
uint8_t Alarm_Values[254];
unsigned Event_Enable:3;
unsigned Notify_Type:1;
ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION];
BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION];
/* time to generate event notification */
uint32_t Remaining_Time_Delay;
/* AckNotification informations */
ACK_NOTIFICATION Ack_notify_data;
#endif /* INTRINSIC_REPORTING */
} MULTI_STATE_VALUE_DESCR;
void Multistate_Value_Property_Lists(
const int **pRequired,
const int **pOptional,
@ -43,12 +81,15 @@ extern "C" {
bool Multistate_Value_Valid_Instance(
uint32_t object_instance);
unsigned Multistate_Value_Count(
void);
uint32_t Multistate_Value_Index_To_Instance(
unsigned index);
unsigned Multistate_Value_Instance_To_Index(
uint32_t instance);
uint32_t object_instance);
int Multistate_Value_Read_Property(
BACNET_READ_PROPERTY_DATA * rpdata);
@ -63,18 +104,22 @@ extern "C" {
bool Multistate_Value_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING * object_name);
bool Multistate_Value_Name_Set(
uint32_t object_instance,
char *new_name);
uint32_t Multistate_Value_Present_Value(
uint32_t object_instance);
bool Multistate_Value_Present_Value_Set(
uint32_t object_instance,
uint32_t value);
uint32_t value,
uint8_t priority);
uint32_t Multistate_Value_Present_Value(
uint32_t object_instance);
bool Multistate_Value_Out_Of_Service(
uint32_t object_instance);
void Multistate_Value_Out_Of_Service_Set(
uint32_t object_instance,
bool value);
@ -82,18 +127,38 @@ extern "C" {
bool Multistate_Value_Description_Set(
uint32_t object_instance,
char *text_string);
bool Multistate_Value_State_Text_Set(
uint32_t object_instance,
uint32_t state_index,
char *new_name);
bool Multistate_Value_Max_States_Set(
uint32_t instance,
uint32_t max_states_requested);
/* note: header of Intrinsic_Reporting function is required
even when INTRINSIC_REPORTING is not defined */
void Multistate_Value_Intrinsic_Reporting(
uint32_t object_instance);
#if defined(INTRINSIC_REPORTING)
int Multistate_Value_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
int Multistate_Value_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code);
int Multistate_Value_Alarm_Summary(
unsigned index,
BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data);
#endif
void Multistate_Value_Init(
void);
#ifdef TEST
#include "ctest.h"
void testMultistateValue(

View File

@ -40,6 +40,7 @@
#include "txbuf.h"
#include "wp.h"
#include "nc.h"
#include "ucix.h"
#ifndef MAX_NOTIFICATION_CLASSES
@ -49,6 +50,8 @@
#if defined(INTRINSIC_REPORTING)
static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES];
static char Object_Name[MAX_NOTIFICATION_CLASSES][64];
static char Object_Description[MAX_NOTIFICATION_CLASSES][64];
/* These three arrays are used by the ReadPropertyMultiple handler */
static const int Notification_Properties_Required[] = {
@ -89,15 +92,94 @@ void Notification_Class_Init(
void)
{
uint8_t NotifyIdx = 0;
unsigned j;
static bool initialized = false;
const char description[64] = "";
const char *uciname;
const char *ucidescription;
const char *ucidescription_default;
const char int_to_string[64] = "";
struct uci_context *ctx;
if (!initialized) {
initialized = true;
fprintf(stderr, "Notification_Class_Init\n");
ctx = ucix_init("bacnet_nc");
if(!ctx)
fprintf(stderr, "Failed to load config file");
for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) {
/* init with zeros */
memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO));
/* set the basic parameters */
NC_Info[NotifyIdx].Ack_Required = 0;
NC_Info[NotifyIdx].Priority[TRANSITION_TO_OFFNORMAL] = 255; /* The lowest priority for Normal message. */
NC_Info[NotifyIdx].Priority[TRANSITION_TO_FAULT] = 255; /* The lowest priority for Normal message. */
NC_Info[NotifyIdx].Priority[TRANSITION_TO_NORMAL] = 255; /* The lowest priority for Normal message. */
ucidescription_default = ucix_get_option(ctx, "bacnet_nc", "default", "description");
/* initialize all the analog output priority arrays to NULL */
for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) {
/* init with zeros */
memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO));
sprintf(int_to_string, "%lu", (unsigned long) NotifyIdx);
uciname = ucix_get_option(ctx, "bacnet_nc", int_to_string, "name");
if (uciname != 0) {
//fprintf(stderr, "UCI Name %s %s\n",uciname,int_to_string);
for (j = 0; j < sizeof(Object_Name[NotifyIdx]); j++) {
if (uciname[j]) {
Object_Name[NotifyIdx][j] = uciname[j];
}
}
ucidescription = ucix_get_option(ctx, "bacnet_nc", int_to_string, "description");
fprintf(stderr, "UCI Description %s \n",ucidescription);
if (ucidescription != 0) {
sprintf(description, "%s", ucidescription);
} else if (ucidescription_default != 0) {
sprintf(description, "%s %lu", ucidescription_default , (unsigned long) NotifyIdx);
} else {
sprintf(description, "NC%lu no uci section configured", (unsigned long) NotifyIdx);
}
//fprintf(stderr, "UCI Description %s \n",description);
for (j = 0; j < sizeof(Object_Description[NotifyIdx]); j++) {
if (description[j]) {
Object_Description[NotifyIdx][j] = description[j];
}
}
} else {
sprintf(int_to_string, "NC%lu_not_configured", (unsigned long) NotifyIdx);
//fprintf(stderr, "UCI Name %s \n",int_to_string);
for (j = 0; j < sizeof(Object_Name[NotifyIdx]); j++) {
if (int_to_string[j]) {
Object_Name[NotifyIdx][j] = int_to_string[j];
}
}
if (ucidescription_default != 0) {
sprintf(description, "%s %lu", ucidescription_default , (unsigned long) NotifyIdx);
} else {
sprintf(description, "NC%lu no uci section configured", (unsigned long) NotifyIdx);
}
for (j = 0; j < sizeof(Object_Description[NotifyIdx]); j++) {
if (description[j]) {
Object_Description[NotifyIdx][j] = description[j];
}
}
}
/* set the basic parameters */
NC_Info[NotifyIdx].Ack_Required = 0;
NC_Info[NotifyIdx].Priority[TRANSITION_TO_OFFNORMAL] = 255; /* The lowest priority for Normal message. */
NC_Info[NotifyIdx].Priority[TRANSITION_TO_FAULT] = 255; /* The lowest priority for Normal message. */
NC_Info[NotifyIdx].Priority[TRANSITION_TO_NORMAL] = 255; /* The lowest priority for Normal message. */
}
// if (NC_Info[0].Recipient_List[0]) {
NC_Info[0].Recipient_List[0].Transitions = 7; //bit string 1,1,1 To Alarm,To Fault,To Normal
NC_Info[0].Recipient_List[0].ValidDays = 127; //bit string 1,1,1,1,1,1,1 Mo,Di,Mi,Do,Fr,Sa,So
NC_Info[0].Recipient_List[0].FromTime.hour = 0;
NC_Info[0].Recipient_List[0].FromTime.min = 0;
NC_Info[0].Recipient_List[0].FromTime.sec = 0;
NC_Info[0].Recipient_List[0].FromTime.hundredths = 0;
NC_Info[0].Recipient_List[0].ToTime.hour = 23;
NC_Info[0].Recipient_List[0].ToTime.min = 59;
NC_Info[0].Recipient_List[0].ToTime.sec = 59;
NC_Info[0].Recipient_List[0].ToTime.hundredths = 99;
NC_Info[0].Recipient_List[0].Recipient.RecipientType =
RECIPIENT_TYPE_ADDRESS;
NC_Info[0].Recipient_List[0].Recipient._.Address.net = 65535;
//NC_Info[0].Recipient_List[0].Recipient._.Address.mac[0] = 0;
//NC_Info[0].Recipient_List[0].Recipient._.Address.mac_len = 0;
// }
ucix_cleanup(ctx);
}
return;
@ -150,18 +232,30 @@ unsigned Notification_Class_Instance_To_Index(
return index;
}
static char *Notification_Class_Description(
uint32_t object_instance)
{
unsigned index = 0; /* offset from instance lookup */
char *pName = NULL; /* return value */
index = Notification_Class_Instance_To_Index(object_instance);
if (index < MAX_NOTIFICATION_CLASSES) {
pName = Object_Description[index];
}
return pName;
}
bool Notification_Class_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32] = ""; /* okay for single thread */
unsigned int index;
bool status = false;
index = Notification_Class_Instance_To_Index(object_instance);
if (index < MAX_NOTIFICATION_CLASSES) {
sprintf(text_string, "NOTIFICATION CLASS %lu", (unsigned long) index);
status = characterstring_init_ansi(object_name, text_string);
status = characterstring_init_ansi(object_name, Object_Name[index]);
}
return status;
@ -200,13 +294,19 @@ int Notification_Class_Read_Property(
break;
case PROP_OBJECT_NAME:
case PROP_DESCRIPTION:
Notification_Class_Object_Name(rpdata->object_instance,
&char_string);
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_DESCRIPTION:
characterstring_init_ansi(&char_string,
Notification_Class_Description(rpdata->object_instance));
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
apdu_len =
encode_application_enumerated(&apdu[0],

View File

@ -59,6 +59,7 @@
#if defined(BACFILE)
#include "bacfile.h"
#endif /* defined(BACFILE) */
#include "ucix.h"
/** @file server/main.c Example server application using the BACnet Stack. */
@ -158,10 +159,22 @@ int main(
uint32_t elapsed_milliseconds = 0;
uint32_t address_binding_tmr = 0;
uint32_t recipient_scan_tmr = 0;
int uci_id = 0;
struct uci_context *ctx;
ctx = ucix_init("bacnet_dev");
if(!ctx)
fprintf(stderr, "Failed to load config file bacnet_dev\n");
uci_id = ucix_get_option_int(ctx, "bacnet_dev", "0", "id", 0);
if (uci_id != 0) {
Device_Set_Object_Instance_Number(uci_id);
} else {
/* allow the device ID to be set */
if (argc > 1)
Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0));
}
ucix_cleanup(ctx);
/* allow the device ID to be set */
if (argc > 1)
Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0));
printf("BACnet Server Demo\n" "BACnet Stack Version %s\n"
"BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version,
Device_Object_Instance_Number(), MAX_APDU);