Indented project.

This commit is contained in:
skarg
2011-08-17 02:27:11 +00:00
parent 7e503510c7
commit 3e1cb1847f
125 changed files with 3548 additions and 3353 deletions
+261 -232
View File
@@ -133,8 +133,7 @@ void Analog_Value_Init(
handler_get_event_information_set(OBJECT_ANALOG_VALUE,
Analog_Value_Event_Information);
/* Set handler for AcknowledgeAlarm function */
handler_alarm_ack_set(OBJECT_ANALOG_VALUE,
Analog_Value_Alarm_Ack);
handler_alarm_ack_set(OBJECT_ANALOG_VALUE, Analog_Value_Alarm_Ack);
#endif
}
}
@@ -196,8 +195,7 @@ bool Analog_Value_Present_Value_Set(
CurrentAV = &AV_Descr[index];
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) &&
(value >= 0.0) && (value <= 100.0))
{
(value >= 0.0) && (value <= 100.0)) {
CurrentAV->Priority_Array[priority - 1] = (uint8_t) value;
/* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no
@@ -240,7 +238,7 @@ float Analog_Value_Present_Value(
/* note: the object name must be unique within this device */
bool Analog_Value_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[32] = ""; /* okay for single thread */
bool status = false;
@@ -310,24 +308,26 @@ int Analog_Value_Read_Property(
bitstring_init(&bit_string);
#if defined(INTRINSIC_REPORTING)
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM,
CurrentAV->Event_State ? true : false);
CurrentAV->Event_State ? true : false);
#else
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
#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);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break;
case PROP_EVENT_STATE:
#if defined(INTRINSIC_REPORTING)
apdu_len = encode_application_enumerated(&apdu[0],
CurrentAV->Event_State);
apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAV->Event_State);
#else
apdu_len = encode_application_enumerated(&apdu[0],
EVENT_STATE_NORMAL);
apdu_len =
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
#endif
break;
@@ -337,7 +337,8 @@ int Analog_Value_Read_Property(
break;
case PROP_UNITS:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units);
apdu_len =
encode_application_enumerated(&apdu[0], CurrentAV->Units);
break;
case PROP_PRIORITY_ARRAY:
@@ -363,7 +364,7 @@ int Analog_Value_Read_Property(
apdu_len += len;
else {
rpdata->error_class = ERROR_CLASS_SERVICES;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = BACNET_STATUS_ERROR;
break;
}
@@ -371,11 +372,11 @@ int Analog_Value_Read_Property(
} else {
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (CurrentAV->Priority_Array[rpdata->array_index - 1]
== ANALOG_LEVEL_NULL)
== ANALOG_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
real_value = CurrentAV->Priority_Array
[rpdata->array_index - 1];
real_value =
CurrentAV->Priority_Array[rpdata->array_index - 1];
apdu_len =
encode_application_real(&apdu[0], real_value);
}
@@ -394,15 +395,19 @@ int Analog_Value_Read_Property(
#if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay);
apdu_len =
encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay);
break;
case PROP_NOTIFICATION_CLASS:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Notification_Class);
apdu_len =
encode_application_unsigned(&apdu[0],
CurrentAV->Notification_Class);
break;
case PROP_HIGH_LIMIT:
apdu_len = encode_application_real(&apdu[0], CurrentAV->High_Limit);
apdu_len =
encode_application_real(&apdu[0], CurrentAV->High_Limit);
break;
case PROP_LOW_LIMIT:
@@ -416,21 +421,26 @@ int Analog_Value_Read_Property(
case PROP_LIMIT_ENABLE:
bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, 0,
(CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE ) ? true : false );
(CurrentAV->
Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false);
bitstring_set_bit(&bit_string, 1,
(CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false );
(CurrentAV->
Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0],&bit_string);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break;
case PROP_EVENT_ENABLE:
bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false );
(CurrentAV->
Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_FAULT ) ? true : false );
(CurrentAV->
Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL ) ? true : false );
(CurrentAV->
Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break;
@@ -438,62 +448,69 @@ int Analog_Value_Read_Property(
case PROP_ACKED_TRANSITIONS:
bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked);
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break;
case PROP_NOTIFY_TYPE:
apdu_len = encode_application_enumerated(&apdu[0],
CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM);
apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM);
break;
case PROP_EVENT_TIME_STAMPS:
/* Array element zero is the number of elements in the array */
if (rpdata->array_index == 0)
apdu_len = encode_application_unsigned(&apdu[0],
MAX_BACNET_EVENT_TRANSITION);
apdu_len =
encode_application_unsigned(&apdu[0],
MAX_BACNET_EVENT_TRANSITION);
/* if no index was specified, then try to encode the entire list */
/* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {;
len = encode_opening_tag(&apdu[apdu_len],
TIME_STAMP_DATETIME);
len += encode_application_date(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].date);
len += encode_application_time(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].time);
len += encode_closing_tag(&apdu[apdu_len + len],
TIME_STAMP_DATETIME);
len =
encode_opening_tag(&apdu[apdu_len],
TIME_STAMP_DATETIME);
len +=
encode_application_date(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].date);
len +=
encode_application_time(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].time);
len +=
encode_closing_tag(&apdu[apdu_len + len],
TIME_STAMP_DATETIME);
/* add it if we have room */
if ((apdu_len + len) < MAX_APDU)
apdu_len += len;
else {
rpdata->error_class = ERROR_CLASS_SERVICES;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = BACNET_STATUS_ERROR;
break;
}
}
}
else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) {
apdu_len = encode_opening_tag(&apdu[apdu_len],
TIME_STAMP_DATETIME);
apdu_len += encode_application_date(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].date);
apdu_len += encode_application_time(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].time);
apdu_len += encode_closing_tag(&apdu[apdu_len],
TIME_STAMP_DATETIME);
}
else {
} else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) {
apdu_len =
encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
apdu_len +=
encode_application_date(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].date);
apdu_len +=
encode_application_time(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].time);
apdu_len +=
encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
} else {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = BACNET_STATUS_ERROR;
}
break;
@@ -501,17 +518,16 @@ int Analog_Value_Read_Property(
default:
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
apdu_len = BACNET_STATUS_ERROR;
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->object_property != PROP_EVENT_TIME_STAMPS) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR;
}
@@ -677,13 +693,12 @@ bool Analog_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code);
if (status) {
if(value.type.Bit_String.bits_used == 2) {
if (value.type.Bit_String.bits_used == 2) {
CurrentAV->Limit_Enable = value.type.Bit_String.value[0];
}
else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
status = false;
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
status = false;
}
}
break;
@@ -694,13 +709,12 @@ bool Analog_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code);
if (status) {
if(value.type.Bit_String.bits_used == 3) {
if (value.type.Bit_String.bits_used == 3) {
CurrentAV->Event_Enable = value.type.Bit_String.value[0];
}
else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
status = false;
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
status = false;
}
}
break;
@@ -711,13 +725,12 @@ bool Analog_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code);
if (status) {
if(value.type.Bit_String.bits_used > NOTIFY_EVENT) {
if (value.type.Bit_String.bits_used > NOTIFY_EVENT) {
CurrentAV->Event_Enable = value.type.Enumerated;
}
else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
status = false;
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
status = false;
}
}
break;
@@ -725,7 +738,7 @@ bool Analog_Value_Write_Property(
default:
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
break;
}
@@ -733,7 +746,8 @@ bool Analog_Value_Write_Property(
}
void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
void Analog_Value_Intrinsic_Reporting(
uint32_t object_instance)
{
#if defined(INTRINSIC_REPORTING)
BACNET_EVENT_NOTIFICATION_DATA event_data;
@@ -744,7 +758,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
uint8_t ToState;
float ExceededLimit = 0.0f;
float PresentVal = 0.0f;
bool SendNotify = false;
bool SendNotify = false;
object_index = Analog_Value_Instance_To_Index(object_instance);
@@ -755,7 +769,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* check limits */
if (!CurrentAV->Limit_Enable)
return; /* limits are not configured */
return; /* limits are not configured */
if (CurrentAV->Ack_notify_data.bSendAckNotify) {
@@ -766,8 +780,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED
fprintf(stderr, "Send Acknotification for (%s,%d).\n",
bactext_object_type_name(OBJECT_ANALOG_VALUE),
object_instance);
bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance);
#endif /* PRINT_ENABLED */
characterstring_init_ansi(&msgText, "AckNotification");
@@ -777,25 +790,23 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Send EventNotification. */
SendNotify = true;
}
else
{
} else {
/* actual Present_Value */
PresentVal = Analog_Value_Present_Value(object_instance);
FromState = CurrentAV->Event_State;
switch (CurrentAV->Event_State)
{
FromState = CurrentAV->Event_State;
switch (CurrentAV->Event_State) {
case EVENT_STATE_NORMAL:
/* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the High_Limit for a minimum
period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */
(a) the Present_Value must exceed the High_Limit for a minimum
period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->High_Limit) &&
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL))
{
if(!CurrentAV->Remaining_Time_Delay)
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
EVENT_HIGH_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT;
else
CurrentAV->Remaining_Time_Delay--;
@@ -803,15 +814,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
}
/* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */
(a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->Low_Limit) &&
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL))
{
if(!CurrentAV->Remaining_Time_Delay)
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
EVENT_LOW_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT;
else
CurrentAV->Remaining_Time_Delay--;
@@ -824,15 +836,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
case EVENT_STATE_HIGH_LIMIT:
/* Once exceeded, the Present_Value must fall below the High_Limit minus
the Deadband before a TO-NORMAL event is generated under these conditions:
(a) the Present_Value must fall below the High_Limit minus the Deadband
for a minimum period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband) &&
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL))
{
if(!CurrentAV->Remaining_Time_Delay)
(a) the Present_Value must fall below the High_Limit minus the Deadband
for a minimum period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband)
&& ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
EVENT_HIGH_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_NORMAL;
else
CurrentAV->Remaining_Time_Delay--;
@@ -846,15 +859,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Once the Present_Value has fallen below the Low_Limit,
the Present_Value must exceed the Low_Limit plus the Deadband
before a TO-NORMAL event is generated under these conditions:
(a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) &&
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL))
{
if(!CurrentAV->Remaining_Time_Delay)
(a) the Present_Value must exceed the Low_Limit plus the Deadband
for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband)
&& ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
EVENT_LOW_LIMIT_ENABLE) &&
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_NORMAL;
else
CurrentAV->Remaining_Time_Delay--;
@@ -865,41 +879,36 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
break;
default:
return; /* shouldn't happen */
} /* switch (FromState) */
return; /* shouldn't happen */
} /* switch (FromState) */
ToState = CurrentAV->Event_State;
if (FromState != ToState)
{
if (FromState != ToState) {
/* Event_State has changed.
Need to fill only the basic parameters of this type of event.
Other parameters will be filled in common function. */
switch (ToState)
{
switch (ToState) {
case EVENT_STATE_HIGH_LIMIT:
ExceededLimit = CurrentAV->High_Limit;
characterstring_init_ansi(&msgText,
"Goes to high limit");
characterstring_init_ansi(&msgText, "Goes to high limit");
break;
case EVENT_STATE_LOW_LIMIT:
ExceededLimit = CurrentAV->Low_Limit;
characterstring_init_ansi(&msgText,
"Goes to low limit");
characterstring_init_ansi(&msgText, "Goes to low limit");
break;
case EVENT_STATE_NORMAL:
if(FromState == EVENT_STATE_HIGH_LIMIT) {
if (FromState == EVENT_STATE_HIGH_LIMIT) {
ExceededLimit = CurrentAV->High_Limit;
characterstring_init_ansi(&msgText,
"Back to normal state from high limit");
}
else {
"Back to normal state from high limit");
} else {
ExceededLimit = CurrentAV->Low_Limit;
characterstring_init_ansi(&msgText,
"Back to normal state from low limit");
"Back to normal state from low limit");
}
break;
@@ -910,9 +919,9 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED
fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n",
bactext_object_type_name(OBJECT_ANALOG_VALUE),
object_instance, bactext_event_state_name(FromState),
bactext_event_state_name(ToState));
bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance,
bactext_event_state_name(FromState),
bactext_event_state_name(ToState));
#endif /* PRINT_ENABLED */
/* Notify Type */
@@ -924,8 +933,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
}
if (SendNotify)
{
if (SendNotify) {
/* Event Object Identifier */
event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE;
event_data.eventObjectIdentifier.instance = object_instance;
@@ -936,22 +944,21 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* fill Event_Time_Stamps */
switch (ToState)
{
switch (ToState) {
case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] =
event_data.timeStamp.value.dateTime;
event_data.timeStamp.value.dateTime;
break;
case EVENT_STATE_FAULT:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_FAULT] =
event_data.timeStamp.value.dateTime;
event_data.timeStamp.value.dateTime;
break;
case EVENT_STATE_NORMAL:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_NORMAL] =
event_data.timeStamp.value.dateTime;
event_data.timeStamp.value.dateTime;
break;
}
}
@@ -978,50 +985,57 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Event Values */
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* Value that exceeded a limit. */
event_data.notificationParams.outOfRange.exceedingValue = PresentVal;
event_data.notificationParams.outOfRange.exceedingValue =
PresentVal;
/* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams.outOfRange.statusFlags);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags,
STATUS_FLAG_IN_ALARM, CurrentAV->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags,
STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags,
STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags,
STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service);
bitstring_init(&event_data.notificationParams.outOfRange.
statusFlags);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_IN_ALARM,
CurrentAV->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAV->Out_Of_Service);
/* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = CurrentAV->Deadband;
event_data.notificationParams.outOfRange.deadband =
CurrentAV->Deadband;
/* Limit that was exceeded. */
event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit;
event_data.notificationParams.outOfRange.exceededLimit =
ExceededLimit;
}
/* add data from notification class */
Notification_Class_common_reporting_function(&event_data);
/* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true))
{
switch (event_data.toState)
{
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) {
switch (event_data.toState) {
case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT:
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = false;
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp =
event_data.timeStamp.value.dateTime;
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked = false;
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break;
case EVENT_STATE_FAULT:
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = false;
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp =
event_data.timeStamp.value.dateTime;
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
bIsAcked = false;
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
Time_Stamp = event_data.timeStamp.value.dateTime;
break;
case EVENT_STATE_NORMAL:
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = false;
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp =
event_data.timeStamp.value.dateTime;
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
bIsAcked = false;
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break;
}
}
@@ -1031,12 +1045,13 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if defined(INTRINSIC_REPORTING)
int Analog_Value_Event_Information(unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data)
int Analog_Value_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data)
{
bool IsNotAckedTransitions;
bool IsActiveEvent;
int i;
int i;
/* check index */
@@ -1046,62 +1061,74 @@ int Analog_Value_Event_Information(unsigned index,
/* Acked_Transitions property, which has at least one of the bits
(TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */
IsNotAckedTransitions = (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) |
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) |
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false);
}
else
return -1; /* end of list */
IsNotAckedTransitions =
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked ==
false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
bIsAcked ==
false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
bIsAcked == false);
} else
return -1; /* end of list */
if ((IsActiveEvent) || (IsNotAckedTransitions)) {
/* Object Identifier */
getevent_data->objectIdentifier.type = OBJECT_ANALOG_VALUE;
getevent_data->objectIdentifier.instance = Analog_Value_Index_To_Instance(index);
getevent_data->objectIdentifier.instance =
Analog_Value_Index_To_Instance(index);
/* Event State */
getevent_data->eventState = AV_Descr[index].Event_State;
/* Acknowledged Transitions */
bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_OFFNORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_FAULT,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
/* Event Time Stamps */
for (i = 0; i < 3; i++) {
getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME;
getevent_data->eventTimeStamps[i].value.dateTime =
AV_Descr[index].Event_Time_Stamps[i];
AV_Descr[index].Event_Time_Stamps[i];
}
/* Notify Type */
getevent_data->notifyType = AV_Descr[index].Notify_Type;
/* Event Enable */
bitstring_init(&getevent_data->eventEnable);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false );
(AV_Descr[index].
Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT ) ? true : false );
(AV_Descr[index].
Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL ) ? true : false );
(AV_Descr[index].
Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
/* Event Priorities */
Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class,
getevent_data->eventPriorities);
getevent_data->eventPriorities);
return 1; /* active event */
}
else
return 0; /* no active event at this index */
return 1; /* active event */
} else
return 0; /* no active event at this index */
}
int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code)
int Analog_Value_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code)
{
ANALOG_VALUE_DESCR *CurrentAV;
unsigned int object_index;
object_index = Analog_Value_Instance_To_Index(
alarmack_data->eventObjectIdentifier.instance);
object_index =
Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier.
instance);
if (object_index < MAX_ANALOG_VALUES)
CurrentAV = &AV_Descr[object_index];
@@ -1110,71 +1137,73 @@ int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data,
return -1;
}
switch (alarmack_data->eventStateAcked)
{
switch (alarmack_data->eventStateAcked) {
case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) {
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){
if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked == false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1;
}
if(datetime_compare(&CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0)
{
if (datetime_compare(&CurrentAV->
Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1;
}
/* Clean transitions flag. */
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true;
}
else {
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked = true;
} else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1;
}
break;
case EVENT_STATE_FAULT:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) {
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){
if (CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked ==
false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1;
}
if(datetime_compare(&CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0)
{
if (datetime_compare(&CurrentAV->
Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1;
}
/* Clean transitions flag. */
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true;
}
else {
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked =
true;
} else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1;
}
break;
case EVENT_STATE_NORMAL:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) {
if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){
if (CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked ==
false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1;
}
if(datetime_compare(&CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0)
{
if (datetime_compare(&CurrentAV->
Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1;
}
/* Clean transitions flag. */
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true;
}
else {
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked =
true;
} else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1;
}
@@ -1205,10 +1234,10 @@ bool WPValidateArgType(
BACNET_ERROR_CLASS * pErrorClass,
BACNET_ERROR_CODE * pErrorCode)
{
pValue=pValue;
ucExpectedTag=ucExpectedTag;
pErrorClass=pErrorClass;
pErrorCode=pErrorCode;
pValue = pValue;
ucExpectedTag = ucExpectedTag;
pErrorClass = pErrorClass;
pErrorCode = pErrorCode;
return false;
}