From d21f55b9efda1942aee859d09eeb5f1ce4fbd899 Mon Sep 17 00:00:00 2001 From: Patrick Grimm Date: Wed, 25 Sep 2013 00:35:54 +0200 Subject: [PATCH] add support for Reliability, Out_Of_Service, Change_Of_Value. TODO COV_Increment --- demo/object/av.c | 61 +++++++++++++++++++++++++++++++++++++---------- demo/object/av.h | 5 ++-- demo/object/bi.c | 44 +++++++++++++++++++++++++++------- demo/object/bi.h | 22 +++++++++++++---- demo/object/msv.c | 16 +++++++++++++ 5 files changed, 121 insertions(+), 27 deletions(-) diff --git a/demo/object/av.c b/demo/object/av.c index cbdd3fb..7740a9c 100644 --- a/demo/object/av.c +++ b/demo/object/av.c @@ -150,6 +150,8 @@ void Analog_Value_Init( const char *ucilow_limit; const char *ucidead_limit_default; const char *ucidead_limit; + const char *ucicov_increment; + const char *ucicov_increment_default; const char *sec = "bacnet_av"; fprintf(stderr, "Analog_Value_Init\n"); if (!initialized) { @@ -178,6 +180,8 @@ void Analog_Value_Init( "low_limit"); ucidead_limit_default = ucix_get_option(ctx, sec, "default", "dead_limit"); + ucicov_increment_default = ucix_get_option(ctx, sec, "default", + "cov_increment"); for (i = 0; i < MAX_ANALOG_VALUES; i++) { memset(&AV_Descr[i], 0x00, sizeof(ANALOG_VALUE_DESCR)); @@ -235,6 +239,18 @@ void Analog_Value_Init( AV_Descr[i].Relinquish_Default = 0; //TODO read uci + ucicov_increment = ucix_get_option(ctx, "bacnet_av", idx_c, + "cov_increment"); + if (ucicov_increment == NULL) { + if (ucicov_increment_default == NULL) { + ucicov_increment = 0; + } else { + ucicov_increment = ucicov_increment_default; + } + } + AV_Descr[i].COV_Increment = strtof(ucicov_increment, + (char **) NULL); + #if defined(INTRINSIC_REPORTING) ucinc = ucix_get_option_int(ctx, "bacnet_av", idx_c, "nc", ucinc_default); @@ -743,7 +759,7 @@ int Analog_Value_Read_Property( int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; - float real_value = (float) 1.414; + float present_value = 0; unsigned object_index = 0; unsigned i = 0; bool state = false; @@ -788,8 +804,8 @@ int Analog_Value_Read_Property( break; case PROP_PRESENT_VALUE: - real_value = Analog_Value_Present_Value(rpdata->object_instance); - apdu_len = encode_application_real(&apdu[0], real_value); + present_value = Analog_Value_Present_Value(rpdata->object_instance); + apdu_len = encode_application_real(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -802,8 +818,15 @@ int Analog_Value_Read_Property( #endif 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_OUT_OF_SERVICE, - CurrentAV->Out_Of_Service); +// bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, +// CurrentAV->Out_Of_Service); + if (Analog_Value_Out_Of_Service(rpdata->object_instance)) { + bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, + CurrentAV->Out_Of_Service); + } else { + bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, + false); + } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -825,10 +848,15 @@ int Analog_Value_Read_Property( break; case PROP_RELIABILITY: - apdu_len = encode_application_boolean(&apdu[0], + apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Reliability); break; + case PROP_COV_INCREMENT: + apdu_len = encode_application_real(&apdu[0], + CurrentAV->COV_Increment); + break; + case PROP_UNITS: apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units); @@ -847,10 +875,10 @@ int Analog_Value_Read_Property( if (CurrentAV->Priority_Array[i] == ANALOG_LEVEL_NULL) len = encode_application_null(&apdu[apdu_len]); else { - real_value = CurrentAV->Priority_Array[i]; + present_value = CurrentAV->Priority_Array[i]; len = encode_application_real(&apdu[apdu_len], - real_value); + present_value); } /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -868,10 +896,10 @@ int Analog_Value_Read_Property( == ANALOG_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { - real_value = + present_value = CurrentAV->Priority_Array[rpdata->array_index - 1]; apdu_len = - encode_application_real(&apdu[0], real_value); + encode_application_real(&apdu[0], present_value); } } else { rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -882,8 +910,8 @@ int Analog_Value_Read_Property( break; case PROP_RELINQUISH_DEFAULT: - real_value = CurrentAV->Relinquish_Default; - apdu_len = encode_application_real(&apdu[0], real_value); + present_value = CurrentAV->Relinquish_Default; + apdu_len = encode_application_real(&apdu[0], present_value); break; #if defined(INTRINSIC_REPORTING) @@ -1172,6 +1200,15 @@ bool Analog_Value_Write_Property( } break; + case PROP_COV_INCREMENT: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, + &wp_data->error_class, &wp_data->error_code); + if (status) { + CurrentAV->COV_Increment = value.type.Real; + } + break; + case PROP_UNITS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, diff --git a/demo/object/av.h b/demo/object/av.h index 929eaf3..1da5b69 100644 --- a/demo/object/av.h +++ b/demo/object/av.h @@ -2,6 +2,7 @@ * * Copyright (C) 2006 Steve Karg * Copyright (C) 2011 Krzysztof Malorny +* Copyright (C) 2013 Patrick Grimm * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -29,7 +30,6 @@ #include #include #include "bacdef.h" -#include "bacerror.h" //TODO rm ? #include "cov.h" #include "wp.h" #include "rp.h" @@ -53,8 +53,9 @@ int max_analog_values; //uint8_t Present_Value; unsigned Event_State:3; bool Out_Of_Service; - uint8_t Reliability; bool Change_Of_Value; + uint8_t Reliability; + float COV_Increment; bool Disable; uint8_t Units; /* Here is our Priority Array. They are supposed to be Real, but */ diff --git a/demo/object/bi.c b/demo/object/bi.c index 584bdb1..601d983 100644 --- a/demo/object/bi.c +++ b/demo/object/bi.c @@ -78,6 +78,7 @@ static const int Binary_Input_Properties_Optional[] = { PROP_NOTIFY_TYPE, PROP_EVENT_TIME_STAMPS, #endif + PROP_RELIABILITY, -1 }; @@ -166,8 +167,8 @@ void Binary_Input_Init( /* 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); - idx_c = idx_cc; + sprintf(idx_cc,"%d",i); + 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); @@ -205,7 +206,7 @@ void Binary_Input_Init( sprintf(inactive_text, "inactive"); } characterstring_init_ansi(&BI_Descr[i].Inactive_Text, inactive_text); - + uciactive_text = ucix_get_option(ctx, "bacnet_bi", idx_c, "active"); if (uciactive_text != 0) { @@ -216,14 +217,18 @@ void Binary_Input_Init( sprintf(active_text, "active"); } characterstring_init_ansi(&BI_Descr[i].Active_Text, active_text); - + ucivalue = ucix_get_option_int(ctx, "bacnet_bi", idx_c, "value", 0); BI_Descr[i].Priority_Array[15] = ucivalue; - BI_Descr[i].Relinquish_Default = 1; //TODO read uci + + BI_Descr[i].Relinquish_Default = 0; //TODO read uci + ucipolarity = ucix_get_option_int(ctx, "bacnet_bi", idx_c, "polarity", ucipolarity_default); - BI_Descr[i].Alarm_Value = ucipolarity; + + BI_Descr[i].Polarity = ucipolarity; + #if defined(INTRINSIC_REPORTING) ucinc = ucix_get_option_int(ctx, "bacnet_bi", idx_c, @@ -373,7 +378,7 @@ bool Binary_Input_Out_Of_Service( return value; } -static void Binary_Input_Out_Of_Service_Set( +void Binary_Input_Out_Of_Service_Set( uint32_t object_instance, bool value) { @@ -909,7 +914,7 @@ int Binary_Input_Read_Property( bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); if (Binary_Input_Out_Of_Service(rpdata->object_instance)) { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - true); + CurrentBI->Out_Of_Service); } else { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, false); @@ -935,6 +940,11 @@ int Binary_Input_Read_Property( Binary_Input_Out_Of_Service(rpdata->object_instance)); break; + case PROP_RELIABILITY: + apdu_len = encode_application_enumerated(&apdu[0], + CurrentBI->Reliability); + break; + case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) { @@ -1265,6 +1275,24 @@ bool Binary_Input_Write_Property( } break; + case PROP_RELIABILITY: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); + if (status) { + CurrentBI->Reliability = value.type.Enumerated; + } + break; + + case PROP_RELINQUISH_DEFAULT: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); + if (status) { + CurrentBI->Relinquish_Default = value.type.Boolean; + } + break; + case PROP_POLARITY: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, diff --git a/demo/object/bi.h b/demo/object/bi.h index 692cdd0..942bdb4 100644 --- a/demo/object/bi.h +++ b/demo/object/bi.h @@ -2,6 +2,8 @@ * * Copyright (C) 2006 Steve Karg * +* Copyright (C) 2013 Patrick Grimm +* * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -52,13 +54,13 @@ int max_binary_inputs; unsigned Event_State:3; bool Out_Of_Service; bool Change_Of_Value; + uint8_t Reliability; bool Disable; BACNET_CHARACTER_STRING Inactive_Text; BACNET_CHARACTER_STRING Active_Text; - BACNET_POLARITY polarity; /* Here is our Priority Array.*/ BACNET_BINARY_PV Priority_Array[BACNET_MAX_PRIORITY]; - unsigned Relinquish_Default; + BACNET_BINARY_PV Relinquish_Default; #if defined(INTRINSIC_REPORTING) uint32_t Time_Delay; uint32_t Notification_Class; @@ -131,6 +133,17 @@ int max_binary_inputs; bool Binary_Input_Out_Of_Service( uint32_t object_instance); + void Binary_Input_Out_Of_Service_Set( + uint32_t object_instance, + bool value); + + uint8_t Binary_Input_Reliability( + uint32_t object_instance); + + void Binary_Input_Reliability_Set( + uint32_t object_instance, + uint8_t value); + bool Binary_Input_Encode_Value_List( uint32_t object_instance, BACNET_PROPERTY_VALUE * value_list); @@ -147,9 +160,6 @@ int max_binary_inputs; bool Binary_Input_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); - void Binary_Input_Init( - void); - BACNET_BINARY_PV Binary_Input_Present_Value( uint32_t object_instance); @@ -177,6 +187,8 @@ int max_binary_inputs; BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data); #endif + void Binary_Input_Init( + void); #ifdef TEST #include "ctest.h" diff --git a/demo/object/msv.c b/demo/object/msv.c index 05af861..09c498b 100644 --- a/demo/object/msv.c +++ b/demo/object/msv.c @@ -913,6 +913,12 @@ int Multistate_Value_Read_Property( apdu_len = encode_application_boolean(&apdu[0], state); break; + case PROP_RELIABILITY: + apdu_len = encode_application_enumerated(&apdu[0], + CurrentMSV->Reliability); + break; + + case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) { @@ -1274,6 +1280,16 @@ bool Multistate_Value_Write_Property( } break; + case PROP_RELIABILITY: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); + if (status) { + CurrentMSV->Reliability = value.type.Enumerated; + fprintf(stderr,"PROP_RELIABILITY %i\n",value.type.Enumerated); + } + break; + case PROP_STATE_TEXT: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (wp_data->array_index == 0) {