Exemplo n.º 1
0
void Binary_Output_Init(
    void)
{
    unsigned i, j;

    /* initialize all the analog output priority arrays to NULL */
    for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
        seeprom_bytes_read(NV_SEEPROM_BINARY_OUTPUT(i, NV_SEEPROM_BO_POLARITY),
            &Polarity[i], 1);
        if (Polarity[i] >= MAX_POLARITY) {
            Binary_Output_Polarity_Set(i, POLARITY_NORMAL);
        }
        seeprom_bytes_read(NV_SEEPROM_BINARY_OUTPUT(i,
                NV_SEEPROM_BO_OUT_OF_SERVICE), &Out_Of_Service[i], 1);
        if (Out_Of_Service[i] > 1) {
            Binary_Output_Out_Of_Service_Set(i, false);
        }
        for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
            seeprom_bytes_read(NV_SEEPROM_BINARY_OUTPUT(i,
                    NV_SEEPROM_BO_PRIORITY_ARRAY_1 + j),
                &Binary_Output_Level[i][j], 1);
        }
    }

    return;
}
Exemplo n.º 2
0
Arquivo: bo.c Projeto: empeeoh/BACnet
void Binary_Output_Init(
    void)
{
    unsigned i, j;

    /* initialize all the analog output priority arrays to NULL */
    for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
        Binary_Output_Polarity_Set(i, POLARITY_NORMAL);
        Binary_Output_Out_Of_Service_Set(i, false);
        for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
            Binary_Output_Level[i][j] = BINARY_NULL;
        }
    }

    return;
}
Exemplo n.º 3
0
Arquivo: bo.c Projeto: empeeoh/BACnet
/* returns true if successful */
bool Binary_Output_Write_Property(
    BACNET_WRITE_PROPERTY_DATA * wp_data)
{
    bool status = false;        /* return value */
    unsigned int priority = 0;
    BACNET_BINARY_PV level = BINARY_NULL;
    int len = 0;
    BACNET_APPLICATION_DATA_VALUE value;

    /* 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_ENUMERATED,
                &wp_data->error_class, &wp_data->error_code);
            if (status) {
                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.Enumerated <= MAX_BINARY_PV)) {
                    level = (BACNET_BINARY_PV) value.type.Enumerated;
                    priority--;
                    Binary_Output_Present_Value_Set(wp_data->object_instance,
                        level, priority);
                } 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. */
                    status = false;
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
                    wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
                } else {
                    status = false;
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
                    wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
                }
            } else {
                status =
                    WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
                    &wp_data->error_class, &wp_data->error_code);
                if (status) {
                    level = BINARY_NULL;
                    priority = wp_data->priority;
                    if (priority && (priority <= BACNET_MAX_PRIORITY)) {
                        priority--;
                        Binary_Output_Present_Value_Set
                            (wp_data->object_instance, level, priority);
                    } else if (priority == 6) {
                        status = false;
                        /* 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 {
                        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) {
                Binary_Output_Out_Of_Service_Set(wp_data->object_instance,
                    value.type.Boolean);
            }
            break;
        case PROP_POLARITY:
            status =
                WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED,
                &wp_data->error_class, &wp_data->error_code);
            if (status) {
                if (value.type.Enumerated < MAX_POLARITY) {
                    Binary_Output_Polarity_Set(wp_data->object_instance,
                        (BACNET_POLARITY) value.type.Enumerated);
                } else {
                    status = false;
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
                    wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
                }
            }
            break;
        case PROP_OBJECT_IDENTIFIER:
        case PROP_OBJECT_NAME:
        case PROP_OBJECT_TYPE:
        case PROP_STATUS_FLAGS:
        case PROP_RELIABILITY:
        case PROP_EVENT_STATE:
        case PROP_PRIORITY_ARRAY:
        case PROP_RELINQUISH_DEFAULT:
        case PROP_ACTIVE_TEXT:
        case PROP_INACTIVE_TEXT:
            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;
    }
    /* not using len at this time */
    len = len;

    return status;
}
Exemplo n.º 4
0
static time_t uci_Update(
	time_t ucimodtime,
	BACNET_OBJECT_TYPE update_object_type,
	int ucirewrite
	)
{
	char *section;
	char *type;
	time_t chk_mtime = 0;
	struct uci_context *ctx;
	int uci_idx;
	/* update Value from uci */
	section = NULL;
	type = NULL;
	if (false) {
		section = NULL;
		type = NULL;
#if defined(AI)
	} else if (update_object_type == OBJECT_ANALOG_INPUT) {
		section = "bacnet_ai";
		type = "ai";
#endif
#if defined(AO)
	} else if (update_object_type == OBJECT_ANALOG_OUTPUT) {
		section = "bacnet_ao";
		type = "ao";
#endif
#if defined(AV)
	} else if (update_object_type == OBJECT_ANALOG_VALUE) {
		section = "bacnet_av";
		type = "av";
#endif
#if defined(BI)
	} else if (update_object_type == OBJECT_BINARY_INPUT) {
		section = "bacnet_bi";
		type = "bi";
#endif
#if defined(BO)
	} else if (update_object_type == OBJECT_BINARY_OUTPUT) {
		section = "bacnet_bo";
		type = "bo";
#endif
#if defined(BV)
	} else if (update_object_type == OBJECT_BINARY_VALUE) {
		section = "bacnet_bv";
		type = "bv";
#endif
#if defined(MI)
	} else if (update_object_type == OBJECT_MULTI_STATE_INPUT) {
		section = "bacnet_mi";
		type = "mi";
#endif
#if defined(MO)
	} else if (update_object_type == OBJECT_MULTI_STATE_OUTPUT) {
		section = "bacnet_mo";
		type = "mo";
#endif
#if defined(MSV)
	} else if (update_object_type == OBJECT_MULTI_STATE_VALUE) {
		section = "bacnet_mv";
		type = "mv";
#endif
	} else {
		return 0;
	}
	if ( ucirewrite == 0) {
		chk_mtime = ucimodtime;
#if PRINT_ENABLED
		printf("rewrite type: %s\n", type);
#endif
	} else {
		chk_mtime = check_uci_update(section, ucimodtime);
	}
	if(chk_mtime != 0) {
		sleep(1);
		ucimodtime = chk_mtime;
#if PRINT_ENABLED
		printf("Config changed, reloading %s\n",section);
#endif
		ctx = ucix_init(section);
		struct uci_itr_ctx itr;
		value_tuple_t *cur;
		itr.list = NULL;
		itr.section = section;
		itr.ctx = ctx;
		ucix_for_each_section_type(ctx, section, type,
			(void *)load_value, &itr);
		for( cur = itr.list; cur; cur = cur->next ) {
			uci_idx = atoi(cur->idx);
#if PRINT_ENABLED
			printf("section %s idx %i \n", section, uci_idx);
#endif
			if (false) {
			}
/* update Analog Input from uci */
#if defined(AI)
			else if (update_object_type == OBJECT_ANALOG_INPUT) {
				float ai_val, ai_pval;
				ai_val = strtof(cur->value,NULL);
				ai_pval = Analog_Input_Present_Value(uci_idx);
				if ( ai_val != ai_pval ) {
					Analog_Input_Present_Value_Set(uci_idx,ai_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Analog_Input_Out_Of_Service(uci_idx))
						Analog_Input_Out_Of_Service_Set(uci_idx,0);
					if (Analog_Input_Reliability(uci_idx))
						Analog_Input_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Analog_Input_Out_Of_Service_Set(uci_idx,1);
					Analog_Input_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Analog Output from uci */
#if defined(AO)
			else if (update_object_type == OBJECT_ANALOG_OUTPUT) {
				float ao_val, ao_pval;
				ao_val = strtof(cur->value,NULL);
				ao_pval = Analog_Output_Present_Value(uci_idx);
				if ( ao_val != ao_pval ) {
					Analog_Output_Present_Value_Set(uci_idx,ao_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Analog_Output_Out_Of_Service(uci_idx))
						Analog_Output_Out_Of_Service_Set(uci_idx,0);
					if (Analog_Output_Reliability(uci_idx))
						Analog_Output_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Analog_Output_Out_Of_Service_Set(uci_idx,1);
					Analog_Output_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Analog Value from uci */
#if defined(AV)
			else if (update_object_type == OBJECT_ANALOG_VALUE) {
				float av_val, av_pval;
				av_val = strtof(cur->value,NULL);
				av_pval = Analog_Value_Present_Value(uci_idx);
				if ( av_val != av_pval ) {
					Analog_Value_Present_Value_Set(uci_idx,av_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Analog_Value_Out_Of_Service(uci_idx))
						Analog_Value_Out_Of_Service_Set(uci_idx,0);
					if (Analog_Value_Reliability(uci_idx))
						Analog_Value_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Analog_Value_Out_Of_Service_Set(uci_idx,1);
					Analog_Value_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Binary Input from uci */
#if defined(BI)
			else if (update_object_type == OBJECT_BINARY_INPUT) {
				int bi_val, bi_pval;
				bi_val = atoi(cur->value);
				bi_pval = Binary_Input_Present_Value(uci_idx);
				if ( bi_val != bi_pval ) {
					Binary_Input_Present_Value_Set(uci_idx,bi_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Binary_Input_Out_Of_Service(uci_idx))
						Binary_Input_Out_Of_Service_Set(uci_idx,0);
					if (Binary_Input_Reliability(uci_idx))
						Binary_Input_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Binary_Input_Out_Of_Service_Set(uci_idx,1);
					Binary_Input_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Binary Output from uci */
#if defined(BO)
			else if (update_object_type == OBJECT_BINARY_OUTPUT) {
				int bo_val, bo_pval;
				bo_val = atoi(cur->value);
				bo_pval = Binary_Output_Present_Value(uci_idx);
				if ( bo_val != bo_pval ) {
					Binary_Output_Present_Value_Set(uci_idx,bo_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Binary_Output_Out_Of_Service(uci_idx))
						Binary_Output_Out_Of_Service_Set(uci_idx,0);
					if (Binary_Output_Reliability(uci_idx))
						Binary_Output_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Binary_Output_Out_Of_Service_Set(uci_idx,1);
					Binary_Output_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Binary Value from uci */
#if defined(BV)
			else if (update_object_type == OBJECT_BINARY_VALUE) {
				int bv_val, bv_pval;
				bv_val = atoi(cur->value);
				bv_pval = Binary_Value_Present_Value(uci_idx);
				if ( bv_val != bv_pval ) {
					Binary_Value_Present_Value_Set(uci_idx,bv_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Binary_Value_Out_Of_Service(uci_idx))
						Binary_Value_Out_Of_Service_Set(uci_idx,0);
					if (Binary_Value_Reliability(uci_idx))
						Binary_Value_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Binary_Value_Out_Of_Service_Set(uci_idx,1);
					Binary_Value_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Multistate Input from uci */
#if defined(MSI)
			else if (update_object_type == OBJECT_MULTI_STATE_INPUT) {
				int msi_val, msi_pval;
				msi_val = atoi(cur->value);
				msi_pval = Multistate_Input_Present_Value(uci_idx);
				if ( msi_val != msi_pval ) {
					Multistate_Input_Present_Value_Set(uci_idx,msi_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Multistate_Input_Out_Of_Service(uci_idx))
						Multistate_Input_Out_Of_Service_Set(uci_idx,0);
					if (Multistate_Input_Reliability(uci_idx))
						Multistate_Input_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Multistate_Input_Out_Of_Service_Set(uci_idx,1);
					Multistate_Input_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Multistate Output from uci */
#if defined(MSO)
			else if (update_object_type == OBJECT_MULTI_STATE_OUTPUT) {
				int mso_val, mso_pval;
				mso_val = atoi(cur->value);
				mso_pval = Multistate_Output_Present_Value(uci_idx);
				if ( mso_val != mso_pval ) {
					Multistate_Output_Present_Value_Set(uci_idx,mso_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Multistate_Output_Out_Of_Service(uci_idx))
						Multistate_Output_Out_Of_Service_Set(uci_idx,0);
					if (Multistate_Output_Reliability(uci_idx))
						Multistate_Output_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Multistate_Output_Out_Of_Service_Set(uci_idx,1);
					Multistate_Output_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
/* update Multistate Value from uci */
#if defined(MSV)
			else if (update_object_type == OBJECT_MULTI_STATE_VALUE) {
				int msv_val, msv_pval;
				msv_val = atoi(cur->value);
				msv_pval = Multistate_Value_Present_Value(uci_idx);
				if ( msv_val != msv_pval ) {
					Multistate_Value_Present_Value_Set(uci_idx,msv_val,16);
				}
				if (cur->Out_Of_Service == 0) {
					if (Multistate_Value_Out_Of_Service(uci_idx))
						Multistate_Value_Out_Of_Service_Set(uci_idx,0);
					if (Multistate_Value_Reliability(uci_idx))
						Multistate_Value_Reliability_Set(uci_idx,
							RELIABILITY_NO_FAULT_DETECTED);
				} else {
#if PRINT_ENABLED
					printf("idx %s ",cur->idx);
					printf("Out_Of_Service\n");
#endif
					Multistate_Value_Out_Of_Service_Set(uci_idx,1);
					Multistate_Value_Reliability_Set(uci_idx,
						RELIABILITY_COMMUNICATION_FAILURE);
				}
			}
#endif
		}
		ucix_cleanup(ctx);
	}
	/* update end */
	return ucimodtime;
}