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_Present_Value_Set(i, BINARY_NULL, j); } } return; }
/* 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; }
void test_task( void) { uint8_t data_register = 0; uint16_t id = 0; if (timer_interval_expired(&Test_Timer)) { timer_interval_reset(&Test_Timer); sprintf(Send_Buffer, "BACnet: 0000000\r\n"); MSTP_MAC_Address = input_address(); Send_Buffer[8] = (MSTP_MAC_Address & BIT0) ? '1' : '0'; Send_Buffer[9] = (MSTP_MAC_Address & BIT1) ? '1' : '0'; Send_Buffer[10] = (MSTP_MAC_Address & BIT2) ? '1' : '0'; Send_Buffer[11] = (MSTP_MAC_Address & BIT3) ? '1' : '0'; Send_Buffer[12] = (MSTP_MAC_Address & BIT4) ? '1' : '0'; Send_Buffer[13] = (MSTP_MAC_Address & BIT5) ? '1' : '0'; Send_Buffer[14] = (MSTP_MAC_Address & BIT6) ? '1' : '0'; serial_bytes_send((uint8_t *) Send_Buffer, 17); } if (serial_byte_get(&data_register)) { /* echo the character */ serial_byte_send(data_register); switch (data_register) { case '0': Binary_Output_Present_Value_Set(0, BINARY_INACTIVE, 0); Binary_Output_Present_Value_Set(1, BINARY_INACTIVE, 0); break; case '1': Binary_Output_Present_Value_Set(0, BINARY_ACTIVE, 0); Binary_Output_Present_Value_Set(1, BINARY_ACTIVE, 0); break; case '2': Binary_Output_Present_Value_Set(0, BINARY_NULL, 0); Binary_Output_Present_Value_Set(1, BINARY_NULL, 0); break; case '3': rs485_baud_rate_set(38400); break; case '5': rs485_baud_rate_set(57600); break; case '7': rs485_baud_rate_set(76800); break; case '9': rs485_baud_rate_set(9600); break; case 'e': seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2); sprintf(Send_Buffer, "\r\n%04X", id); serial_bytes_send((uint8_t *) Send_Buffer, strlen(Send_Buffer)); break; case 'b': sprintf(Send_Buffer, "\r\n%lubps", (unsigned long) rs485_baud_rate()); serial_bytes_send((uint8_t *) Send_Buffer, strlen(Send_Buffer)); break; case 'm': sprintf(Send_Buffer, "\r\nMax:%u", (unsigned) dlmstp_max_master()); serial_bytes_send((uint8_t *) Send_Buffer, strlen(Send_Buffer)); break; default: break; } serial_byte_send('\r'); serial_byte_send('\n'); serial_byte_transmit_complete(); } test_pin_toggle(); }
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; }