bool Analog_Value_Present_Value_Set( uint32_t object_instance, float value, uint8_t priority) { unsigned index = 0; bool status = false; priority = priority; index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { if (priority && (priority <= BACNET_MAX_PRIORITY) && (priority != 6 /* reserved */ ) && (value >= 0.0) && (value <= 100.0)) { Present_Value[index] = value; /* Note: you could set the physical output here if we are the highest priority. 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) */ status = true; } } return status; }
float Analog_Value_Present_Value( uint32_t object_instance) { float value = 0; unsigned index = 0; index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { value = AV_Descr[index].Present_Value; } return value; }
float Analog_Value_Present_Value( uint32_t object_instance) { float value = ANALOG_RELINQUISH_DEFAULT; unsigned index = 0; index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { value = Present_Value[index]; } return value; }
/** * For a given object instance-number, sets the present-value at a given * priority 1..16. * * @param object_instance - object-instance number of the object * @param value - floating point analog value * @param priority - priority 1..16 * * @return true if values are within range and present-value is set. */ bool Analog_Value_Present_Value_Set( uint32_t object_instance, float value, uint8_t priority) { unsigned index = 0; bool status = false; index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { AV_Descr[index].Present_Value = value; status = true; } 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; bool status = false; index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { sprintf(text_string, "AV-%lu", object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; }
/* returns true if successful */ bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; if (!Analog_Value_Valid_Instance(wp_data->object_instance)) { *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_UNKNOWN_OBJECT; return false; } /* decode the some of the request */ len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; return false; } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); AV_Present_Value[object_index] = value.type.Real; status = true; } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } return status; }
float Analog_Value_Present_Value( uint32_t object_instance) { float value = ANALOG_RELINQUISH_DEFAULT; unsigned index = 0; unsigned i = 0; Analog_Value_Init(); index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { for (i = 0; i < BACNET_MAX_PRIORITY; i++) { if (Analog_Value_Level[index][i] != ANALOG_LEVEL_NULL) { value = Analog_Value_Level[index][i]; break; } } } return value; }
/* returns true if successful */ bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA xdata * wp_data, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; if (!Analog_Value_Valid_Instance(wp_data->object_instance)) { *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_UNKNOWN_OBJECT; return false; } /* decode the some of the request */ len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; return false; } if ((wp_data->object_property != PROP_PRIORITY_ARRAY) && (wp_data->array_index != BACNET_ARRAY_ALL)) { /* only array properties can have array options */ *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); AV_Present_Value[object_index] = value.type.Real; // wirte_bacnet_value_to_buf(AV,wp_data->priority,object_index); status = true; } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_NAME: case PROP_OBJECT_TYPE: case PROP_STATUS_FLAGS: case PROP_EVENT_STATE: case PROP_OUT_OF_SERVICE: case PROP_DESCRIPTION: case PROP_PRIORITY_ARRAY: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_UNKNOWN_PROPERTY; break; } return status; }
/* return apdu len, or -1 on error */ int Analog_Value_Encode_Property_APDU( uint8_t * apdu, uint32_t object_instance, BACNET_PROPERTY_ID property, uint32_t array_index, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING xdata bit_string; BACNET_CHARACTER_STRING xdata char_string; unsigned object_index; switch (property) { case PROP_OBJECT_IDENTIFIER: apdu_len = encode_application_object_id(&apdu[0], OBJECT_ANALOG_VALUE, object_instance); break; case PROP_OBJECT_NAME: characterstring_init_ansi(&char_string, // vars[object_instance].label Analog_Value_Name(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); break; case PROP_PRESENT_VALUE: object_index = Analog_Value_Instance_To_Index(object_instance); apdu_len = encode_application_real(&apdu[0], AV_Present_Value[object_index]); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); 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, false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: apdu_len = encode_application_boolean(&apdu[0], false); break; case PROP_UNITS: apdu_len = encode_application_enumerated(&apdu[0], UNITS_PERCENT); break; default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_UNKNOWN_PROPERTY; apdu_len = -1; break; } /* only array properties can have array options */ if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; } return apdu_len; }
/* returns true if successful */ bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { bool status = false; /* return value */ unsigned int object_index = 0; unsigned int priority = 0; uint8_t level = ANALOG_LEVEL_NULL; int len = 0; BACNET_APPLICATION_DATA_VALUE value; Analog_Value_Init(); if (!Analog_Value_Valid_Instance(wp_data->object_instance)) { *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_UNKNOWN_OBJECT; return false; } /* decode the some of the request */ len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { priority = wp_data->priority; /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ if (priority && (priority <= BACNET_MAX_PRIORITY) && (priority != 6 /* reserved */ ) && (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { level = (uint8_t) value.type.Real; object_index = Analog_Value_Instance_To_Index (wp_data->object_instance); priority--; Present_Value[object_index] = level; /* Note: you could set the physical output here if we are the highest priority. 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) */ status = true; } else if (priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } #if 0 } else if (value.tag == BACNET_APPLICATION_TAG_NULL) { level = ANALOG_LEVEL_NULL; object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; Present_Value[object_index][priority] = level; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no priorities are set. 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) */ status = true; } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } #endif } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; #if 0 case PROP_OUT_OF_SERVICE: if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); Analog_Value_Out_Of_Service[object_index] = value.type.Boolean; status = true; } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; #endif default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } return status; }
/* return apdu len, or -1 on error */ int Analog_Value_Encode_Property_APDU( uint8_t * apdu, uint32_t object_instance, BACNET_PROPERTY_ID property, int32_t array_index, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) { int len = 0; int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; float real_value = (float) 1.414; unsigned object_index = 0; unsigned i = 0; bool state = false; Analog_Value_Init(); switch (property) { case PROP_OBJECT_IDENTIFIER: apdu_len = encode_application_object_id(&apdu[0], OBJECT_ANALOG_VALUE, object_instance); break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: characterstring_init_ansi(&char_string, Analog_Value_Name(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); break; case PROP_PRESENT_VALUE: real_value = Analog_Value_Present_Value(object_instance); apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); 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, false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: #if 0 object_index = Analog_Value_Instance_To_Index(object_instance); state = Analog_Value_Out_Of_Service[object_index]; #endif apdu_len = encode_application_boolean(&apdu[0], false); break; case PROP_UNITS: apdu_len = encode_application_enumerated(&apdu[0], UNITS_PERCENT); break; #if 0 case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ if (array_index == 0) apdu_len = encode_application_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (array_index == BACNET_ARRAY_ALL) { object_index = Analog_Value_Instance_To_Index(object_instance); for (i = 0; i < BACNET_MAX_PRIORITY; i++) { /* FIXME: check if we have room before adding it to APDU */ if (Present_Value[object_index][i] == ANALOG_LEVEL_NULL) len = encode_application_null(&apdu[apdu_len]); else { real_value = Present_Value[object_index][i]; len = encode_application_real(&apdu[apdu_len], real_value); } /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) apdu_len += len; else { *error_class = ERROR_CLASS_SERVICES; *error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; apdu_len = -1; break; } } } else { object_index = Analog_Value_Instance_To_Index(object_instance); if (array_index <= BACNET_MAX_PRIORITY) { if (Present_Value[object_index][array_index - 1] == ANALOG_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { real_value = Present_Value[object_index][array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_INVALID_ARRAY_INDEX; apdu_len = -1; } } break; case PROP_RELINQUISH_DEFAULT: real_value = ANALOG_RELINQUISH_DEFAULT; apdu_len = encode_application_real(&apdu[0], real_value); break; #endif default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_UNKNOWN_PROPERTY; apdu_len = -1; break; } return apdu_len; }
void Analog_Value_Intrinsic_Reporting( uint32_t object_instance) { #if defined(INTRINSIC_REPORTING) BACNET_EVENT_NOTIFICATION_DATA event_data; BACNET_CHARACTER_STRING msgText; ANALOG_VALUE_DESCR *CurrentAV; unsigned int object_index; uint8_t FromState = 0; uint8_t ToState; float ExceededLimit = 0.0f; float PresentVal = 0.0f; bool SendNotify = false; object_index = Analog_Value_Instance_To_Index(object_instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; else return; /* check limits */ if (!CurrentAV->Limit_Enable) return; /* limits are not configured */ if (CurrentAV->Ack_notify_data.bSendAckNotify) { /* clean bSendAckNotify flag */ CurrentAV->Ack_notify_data.bSendAckNotify = false; /* copy toState */ ToState = CurrentAV->Ack_notify_data.EventState; #if PRINT_ENABLED fprintf(stderr, "Send Acknotification for (%s,%d).\n", bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance); #endif /* PRINT_ENABLED */ characterstring_init_ansi(&msgText, "AckNotification"); /* Notify Type */ event_data.notifyType = NOTIFY_ACK_NOTIFICATION; /* Send EventNotification. */ SendNotify = true; } else { /* actual Present_Value */ PresentVal = Analog_Value_Present_Value(object_instance); 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. */ 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->Event_State = EVENT_STATE_HIGH_LIMIT; else CurrentAV->Remaining_Time_Delay--; break; } /* 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. */ 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->Event_State = EVENT_STATE_LOW_LIMIT; else CurrentAV->Remaining_Time_Delay--; break; } /* value of the object is still in the same event state */ CurrentAV->Remaining_Time_Delay = CurrentAV->Time_Delay; break; 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) CurrentAV->Event_State = EVENT_STATE_NORMAL; else CurrentAV->Remaining_Time_Delay--; break; } /* value of the object is still in the same event state */ CurrentAV->Remaining_Time_Delay = CurrentAV->Time_Delay; break; case EVENT_STATE_LOW_LIMIT: /* 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) CurrentAV->Event_State = EVENT_STATE_NORMAL; else CurrentAV->Remaining_Time_Delay--; break; } /* value of the object is still in the same event state */ CurrentAV->Remaining_Time_Delay = CurrentAV->Time_Delay; break; default: return; /* shouldn't happen */ } /* switch (FromState) */ ToState = CurrentAV->Event_State; 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) { case EVENT_STATE_HIGH_LIMIT: ExceededLimit = CurrentAV->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"); break; case EVENT_STATE_NORMAL: if (FromState == EVENT_STATE_HIGH_LIMIT) { ExceededLimit = CurrentAV->High_Limit; characterstring_init_ansi(&msgText, "Back to normal state from high limit"); } else { ExceededLimit = CurrentAV->Low_Limit; characterstring_init_ansi(&msgText, "Back to normal state from low limit"); } break; default: ExceededLimit = 0; break; } /* switch (ToState) */ #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)); #endif /* PRINT_ENABLED */ /* Notify Type */ event_data.notifyType = CurrentAV->Notify_Type; /* Send EventNotification. */ SendNotify = true; } } if (SendNotify) { /* Event Object Identifier */ event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE; event_data.eventObjectIdentifier.instance = object_instance; /* Time Stamp */ event_data.timeStamp.tag = TIME_STAMP_DATETIME; Device_getCurrentDateTime(&event_data.timeStamp.value.dateTime); if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { /* fill Event_Time_Stamps */ switch (ToState) { case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: CurrentAV->Event_Time_Stamps[TRANSITION_TO_FAULT] = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: CurrentAV->Event_Time_Stamps[TRANSITION_TO_NORMAL] = event_data.timeStamp.value.dateTime; break; } } /* Notification Class */ event_data.notificationClass = CurrentAV->Notification_Class; /* Event Type */ event_data.eventType = EVENT_OUT_OF_RANGE; /* Message Text */ event_data.messageText = &msgText; /* Notify Type */ /* filled before */ /* From State */ if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) event_data.fromState = FromState; /* To State */ event_data.toState = CurrentAV->Event_State; /* Event Values */ if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { /* Value that exceeded a limit. */ 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); /* Deadband used for limit checking. */ event_data.notificationParams.outOfRange.deadband = CurrentAV->Deadband; /* Limit that was exceeded. */ 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) { 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; 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; 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; break; } } } #endif /* defined(INTRINSIC_REPORTING) */ }
/* returns true if successful */ bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; ANALOG_VALUE_DESCR *CurrentAV; /* decode the some of the request */ len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; return false; } if ((wp_data->object_property != PROP_PRIORITY_ARRAY) && (wp_data->object_property != PROP_EVENT_TIME_STAMPS) && (wp_data->array_index != BACNET_ARRAY_ALL)) { /* only array properties can have array options */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; } object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; else return false; switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ if (Analog_Value_Present_Value_Set(wp_data->object_instance, value.type.Real, wp_data->priority)) { status = true; } 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 object. */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } break; case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Out_Of_Service = value.type.Boolean; } break; case PROP_UNITS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Units = value.type.Enumerated; } break; #if defined(INTRINSIC_REPORTING) case PROP_TIME_DELAY: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Time_Delay = value.type.Unsigned_Int; CurrentAV->Remaining_Time_Delay = CurrentAV->Time_Delay; } break; case PROP_NOTIFICATION_CLASS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Notification_Class = value.type.Unsigned_Int; } break; case PROP_HIGH_LIMIT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->High_Limit = value.type.Real; } break; case PROP_LOW_LIMIT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Low_Limit = value.type.Real; } break; case PROP_DEADBAND: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Deadband = value.type.Real; } break; case PROP_LIMIT_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, &wp_data->error_class, &wp_data->error_code); if (status) { 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; } } break; case PROP_EVENT_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, &wp_data->error_class, &wp_data->error_code); if (status) { 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; } } break; case PROP_NOTIFY_TYPE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, &wp_data->error_class, &wp_data->error_code); if (status) { switch ((BACNET_NOTIFY_TYPE) value.type.Enumerated) { case NOTIFY_EVENT: CurrentAV->Notify_Type = 1; break; case NOTIFY_ALARM: CurrentAV->Notify_Type = 0; break; default: wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false; break; } } 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: #if defined(INTRINSIC_REPORTING) case PROP_ACKED_TRANSITIONS: case PROP_EVENT_TIME_STAMPS: #endif wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; case PROP_RELINQUISH_DEFAULT: case PROP_PRIORITY_ARRAY: default: wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; break; } return status; }
/* return apdu len, or BACNET_STATUS_ERROR on error */ int Analog_Value_Read_Property( BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; float real_value = (float) 1.414; unsigned object_index = 0; unsigned i = 0; bool state = false; uint8_t *apdu = NULL; ANALOG_VALUE_DESCR *CurrentAV; if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } apdu = rpdata->application_data; object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; else return BACNET_STATUS_ERROR; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: apdu_len = encode_application_object_id(&apdu[0], OBJECT_ANALOG_VALUE, rpdata->object_instance); 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_OBJECT_TYPE: apdu_len = encode_application_enumerated(&apdu[0], OBJECT_ANALOG_VALUE); break; case PROP_PRESENT_VALUE: real_value = Analog_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); #if defined(INTRINSIC_REPORTING) bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, 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); 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); #else apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); #endif break; case PROP_OUT_OF_SERVICE: state = CurrentAV->Out_Of_Service; apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_UNITS: apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units); break; #if defined(INTRINSIC_REPORTING) case PROP_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); break; case PROP_HIGH_LIMIT: apdu_len = encode_application_real(&apdu[0], CurrentAV->High_Limit); break; case PROP_LOW_LIMIT: apdu_len = encode_application_real(&apdu[0], CurrentAV->Low_Limit); break; case PROP_DEADBAND: apdu_len = encode_application_real(&apdu[0], CurrentAV->Deadband); break; case PROP_LIMIT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, 0, (CurrentAV-> Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false); bitstring_set_bit(&bit_string, 1, (CurrentAV-> Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false); 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); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, (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); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_ACKED_TRANSITIONS: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, 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); 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); /* 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); /* 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; 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 { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; apdu_len = BACNET_STATUS_ERROR; } break; #endif default: rpdata->error_class = ERROR_CLASS_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) && (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; apdu_len = BACNET_STATUS_ERROR; } return apdu_len; }
/* returns true if successful */ bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */ #if 0 unsigned int object_index = 0; unsigned int priority = 0; #endif BACNET_APPLICATION_DATA_VALUE value; int len = 0; /* decode the some of the request */ len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; return false; } if ((wp_data->object_property != PROP_PRIORITY_ARRAY) && (wp_data->array_index != BACNET_ARRAY_ALL)) { /* only array properties can have array options */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, &wp_data->error_class, &wp_data->error_code); if (status) { status = Analog_Value_Present_Value_Set(wp_data->object_instance, value.type.Real, wp_data->priority); if (!status) { 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 object. */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } } break; case PROP_OUT_OF_SERVICE: #if 0 status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); Analog_Value_Out_Of_Service[object_index] = value.type.Boolean; } break; #endif case PROP_UNITS: #if 0 status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); Analog_Value_Units[object_index] = value.type.Unsigned_Int; } break; #endif case PROP_PRIORITY_ARRAY: case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_NAME: case PROP_OBJECT_TYPE: case PROP_STATUS_FLAGS: case PROP_EVENT_STATE: case PROP_DESCRIPTION: wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; case PROP_RELINQUISH_DEFAULT: default: wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; break; } /* not using len at this time */ len = len; return status; }
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); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; else { *error_code = ERROR_CODE_UNKNOWN_OBJECT; return -1; } 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) { *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) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* Clean transitions flag. */ 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) { *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) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* Clean transitions flag. */ 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) { *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) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* Clean transitions flag. */ CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } break; default: return -2; } /* Need to send AckNotification. */ CurrentAV->Ack_notify_data.bSendAckNotify = true; CurrentAV->Ack_notify_data.EventState = alarmack_data->eventStateAcked; /* Return OK */ return 1; }
/* returns true if successful */ bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */ unsigned int object_index = 0; unsigned int priority = 0; uint8_t level = ANALOG_LEVEL_NULL; int len = 0; BACNET_APPLICATION_DATA_VALUE value; if (!Analog_Value_Valid_Instance(wp_data->object_instance)) { wp_data->error_class = ERROR_CLASS_OBJECT; wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; return false; } /* decode the some of the request */ len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; return false; } if ((wp_data->object_property != PROP_PRIORITY_ARRAY) && (wp_data->array_index != BACNET_ARRAY_ALL)) { /* only array properties can have array options */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { priority = wp_data->priority; /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ if (priority && (priority <= BACNET_MAX_PRIORITY) && (priority != 6 /* reserved */ ) && (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { level = (uint8_t) value.type.Real; object_index = Analog_Value_Instance_To_Index (wp_data->object_instance); priority--; Present_Value[object_index] = level; /* Note: you could set the physical output here if we are the highest priority. 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) */ status = true; } else if (priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } #if 0 } else if (value.tag == BACNET_APPLICATION_TAG_NULL) { level = ANALOG_LEVEL_NULL; object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; Present_Value[object_index][priority] = level; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no priorities are set. 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) */ status = true; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } #endif } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; #if 0 case PROP_OUT_OF_SERVICE: if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); Analog_Value_Out_Of_Service[object_index] = value.type.Boolean; status = true; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; #endif case PROP_OUT_OF_SERVICE: case PROP_UNITS: case PROP_RELINQUISH_DEFAULT: 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: wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; default: wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; break; } return status; }
/* return apdu len, or -1 on error */ int Analog_Value_Read_Property( BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; float real_value = (float) 1.414; #if 0 int len = 0; unsigned object_index = 0; unsigned i = 0; bool state = false; #endif uint8_t *apdu = NULL; if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: apdu_len = encode_application_object_id(&apdu[0], OBJECT_ANALOG_VALUE, rpdata->object_instance); 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_OBJECT_TYPE: apdu_len = encode_application_enumerated(&apdu[0], OBJECT_ANALOG_VALUE); break; case PROP_PRESENT_VALUE: real_value = Analog_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); 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, false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: #if 0 object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); state = Analog_Value_Out_Of_Service[object_index]; #endif apdu_len = encode_application_boolean(&apdu[0], false); break; case PROP_UNITS: apdu_len = encode_application_enumerated(&apdu[0], UNITS_PERCENT); break; #if 0 case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) apdu_len = encode_application_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); for (i = 0; i < BACNET_MAX_PRIORITY; i++) { /* FIXME: check if we have room before adding it to APDU */ if (Present_Value[object_index][i] == ANALOG_LEVEL_NULL) len = encode_application_null(&apdu[apdu_len]); else { real_value = Present_Value[object_index][i]; len = encode_application_real(&apdu[apdu_len], real_value); } /* 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; apdu_len = BACNET_STATUS_ERROR; break; } } } else { object_index = Analog_Value_Instance_To_Index(object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (Present_Value[object_index][rpdata->array_index - 1] == ANALOG_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { real_value = Present_Value[object_index][rpdata->array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; apdu_len = BACNET_STATUS_ERROR; } } break; case PROP_RELINQUISH_DEFAULT: real_value = ANALOG_RELINQUISH_DEFAULT; apdu_len = encode_application_real(&apdu[0], real_value); break; #endif default: rpdata->error_class = ERROR_CLASS_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) && #if 0 (rpdata->object_property != PROP_PRIORITY_ARRAY) && #endif (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; } return apdu_len; }