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

add Out_Of_Service and write value to uci for av

This commit is contained in:
Patrick Grimm 2013-11-02 22:56:20 +01:00
parent bf5c8a6514
commit 5d710a2baa
4 changed files with 64 additions and 16 deletions

View File

@ -128,6 +128,7 @@ void Analog_Value_Init(
const char *uciname;
int ucidisable;
const char *ucivalue;
int Out_Of_Service;
char description[64];
const char *ucidescription;
const char *ucidescription_default;
@ -222,6 +223,15 @@ void Analog_Value_Init(
} else {
AV_Descr[i].Units = UNITS_PERCENT;
}
Out_Of_Service = ucix_get_option_int(ctx, "bacnet_av", idx_c,
"Out_Of_Service", 1);
if (Out_Of_Service == 0) {
AV_Descr[i].Reliability = RELIABILITY_NO_FAULT_DETECTED;
AV_Descr[i].Out_Of_Service = 0;
} else {
AV_Descr[i].Reliability = RELIABILITY_COMMUNICATION_FAILURE;
AV_Descr[i].Out_Of_Service = 1;
}
ucivalue = ucix_get_option(ctx, "bacnet_av", idx_c,
"value");
@ -1068,6 +1078,10 @@ bool Analog_Value_Write_Property(
BACNET_APPLICATION_DATA_VALUE value;
ctx = ucix_init("bacnet_av");
const char *idx_c;
char cur_value[16];
float pvalue;
int i;
time_t cur_value_time;
char idx_cc[64];
@ -1145,6 +1159,14 @@ bool Analog_Value_Write_Property(
if (Analog_Value_Present_Value_Set(wp_data->object_instance,
value.type.Real, wp_data->priority)) {
status = true;
sprintf(cur_value,"%f",value.type.Real);
ucix_add_option(ctx, "bacnet_av", idx_c, "value",
cur_value);
cur_value_time = time(NULL);
ucix_add_option_int(ctx, "bacnet_av", idx_c, "value_time",
cur_value_time);
ucix_add_option_int(ctx, "bacnet_av", 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
@ -1171,6 +1193,21 @@ bool Analog_Value_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 = CurrentAV->Relinquish_Default;
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
if (CurrentAV->Priority_Array[i] != ANALOG_LEVEL_NULL) {
pvalue = CurrentAV->Priority_Array[i];
break;
}
}
sprintf(cur_value,"%f",pvalue);
ucix_add_option(ctx, "bacnet_av", idx_c, "value",
cur_value);
cur_value_time = time(NULL);
ucix_add_option_int(ctx, "bacnet_av", idx_c, "value_time",
cur_value_time);
ucix_add_option_int(ctx, "bacnet_av", idx_c, "write",
1);
} else {
status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY;

View File

@ -254,6 +254,7 @@ int main(
chk_mtime = 0;
chk_mtime = check_uci_update(section, ucimodtime_bacnet_av);
if(chk_mtime != 0) {
sleep(1);
ucimodtime_bacnet_av = chk_mtime;
printf("Config changed, reloading %s\n",section);
ctx = ucix_init(section);
@ -268,13 +269,13 @@ int main(
printf("section %s idx %s \n", section, cur->idx);
val_f = strtof(cur->value,NULL);
uci_idx = atoi(cur->idx);
if (val_f || !strcmp(cur->value, "0")) {
printf("idx %s ",cur->idx);
printf("value %s\n",cur->value);
pval_f = Analog_Value_Present_Value(uci_idx);
if ( val_f != pval_f ) {
Analog_Value_Present_Value_Set(uci_idx,val_f,16);
}
printf("idx %s ",cur->idx);
printf("value %s\n",cur->value);
pval_f = Analog_Value_Present_Value(uci_idx);
if ( val_f != pval_f ) {
Analog_Value_Present_Value_Set(uci_idx,val_f,16);
}
if (cur->Out_Of_Service == 0) {
if (Analog_Value_Out_Of_Service(uci_idx))
Analog_Value_Out_Of_Service_Set(uci_idx,0);
if (Analog_Value_Reliability(uci_idx))

View File

@ -27,6 +27,8 @@ struct uci_context* ucix_init_path(const char *path, const char *config_file);
/* value/name tuples */
struct value_tuple {
char value[16];
time_t value_time;
int Out_Of_Service;
char idx[18];
struct value_tuple *next;
};

View File

@ -261,12 +261,12 @@ time_t check_uci_update(const char *config, time_t mtime)
}
}
snprintf(path, sizeof(path), "/tmp/.uci/%s", config);
/* snprintf(path, sizeof(path), "/tmp/.uci/%s", config);
if( stat(path, &s) > -1 ) {
if( (f_mtime == 0) || (s.st_mtime > f_mtime) ) {
f_mtime = s.st_mtime;
}
}
} */
if( (mtime == 0) || (f_mtime > mtime) ) {
return f_mtime;
} else {
@ -284,15 +284,23 @@ void load_value(const char *sec_idx, struct uci_itr_ctx *itr)
return;
const char *value;
time_t value_time;
int Out_Of_Service;
value = ucix_get_option(itr->ctx, itr->section, sec_idx, "value");
if( (t = (value_tuple_t *)malloc(sizeof(value_tuple_t))) != NULL ) {
strncpy(t->idx, sec_idx, sizeof(t->idx));
if ( value != NULL ) {
strncpy(t->value, value, sizeof(t->value));
}
t->next = itr->list;
itr->list = t;
value_time = ucix_get_option_int(itr->ctx, itr->section, sec_idx,
"value_time",0);
Out_Of_Service = ucix_get_option_int(itr->ctx, itr->section, sec_idx,
"Out_Of_Service",1);
if( (t = (value_tuple_t *)malloc(sizeof(value_tuple_t))) != NULL ) {
strncpy(t->idx, sec_idx, sizeof(t->idx));
if ( value != NULL ) {
strncpy(t->value, value, sizeof(t->value));
}
t->value_time=value_time;
t->Out_Of_Service=Out_Of_Service;
t->next = itr->list;
itr->list = t;
}
}