/************************************************************************** * Description: handles recurring task * Returns: none * Notes: none **************************************************************************/ static void bacnet_test_task(void) { static unsigned index = 0; uint32_t instance; float float_value; uint16_t adc_value; instance = Analog_Input_Index_To_Instance(index); if (!Analog_Input_Out_Of_Service(instance)) { adc_value = adc_result_12bit(index); float_value = adc_value; float_value /= 4095; Analog_Input_Present_Value_Set(instance, float_value); } index++; if (index >= MAX_ANALOG_INPUTS) { index = 0; } }
/************************************************************************** * Description: initializes the BACnet library * Returns: none * Notes: none **************************************************************************/ void bacnet_init(void) { unsigned i; Ringbuf_Init(&Receive_Queue, (uint8_t *) & Receive_Buffer, sizeof(struct mstp_rx_packet), MSTP_RECEIVE_PACKET_COUNT); dlmstp_init(NULL); /* initialize objects */ Device_Init(NULL); /* set up our confirmed service unrecognized service handler - required! */ apdu_set_unrecognized_service_handler_handler (handler_unrecognized_service); /* we need to handle who-is to support dynamic device binding */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, handler_who_has); /* Set the handlers for any confirmed services that we support. */ /* We must implement read property - it's required! */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, handler_read_property_multiple); apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, handler_reinitialize_device); apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, handler_write_property); /* handle communication so we can shut up when asked */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, handler_device_communication_control); /* start the cyclic 1 second timer for DCC */ timer_interval_start_seconds(&DCC_Timer, DCC_CYCLE_SECONDS); /* start the cyclic 1 second timer for COV */ timer_interval_start_seconds(&COV_Timer, COV_CYCLE_SECONDS); /* start the cyclic 1 second timer for TSM */ timer_interval_start_seconds(&TSM_Timer, TSM_CYCLE_SECONDS); for (i = 0; i < MAX_ANALOG_INPUTS; i++) { Analog_Input_Units_Set( Analog_Input_Index_To_Instance(i), UNITS_PERCENT); } }
/* for discovery, it must be consistent! */ bool Device_Object_List_Identifier( unsigned array_index, int *object_type, uint32_t * instance) { bool status = false; unsigned object_index = 0; unsigned object_count = 0; /* device object */ if (array_index == 1) { *object_type = OBJECT_DEVICE; *instance = Object_Instance_Number; status = true; } /* normalize the index since we know it is not the previous objects */ /* array index starts at 1 */ object_index = array_index - 1; /* 1 for the device object */ object_count = 1; /* FIXME: add objects as needed */ /* binary value objects */ if (!status) { object_index -= object_count; object_count = Binary_Value_Count(); /* is it a valid index for this object? */ if (object_index < object_count) { *object_type = OBJECT_BINARY_VALUE; *instance = Binary_Value_Index_To_Instance(object_index); status = true; } } /* analog input objects */ if (!status) { /* array index starts at 1, and 1 for the device object */ object_index -= object_count; object_count = Analog_Value_Count(); if (object_index < object_count) { *object_type = OBJECT_ANALOG_VALUE; *instance = Analog_Value_Index_To_Instance(object_index); status = true; } } /* analog input objects */ if (!status) { /* array index starts at 1, and 1 for the device object */ object_index -= object_count; object_count = Analog_Input_Count(); if (object_index < object_count) { *object_type = OBJECT_ANALOG_INPUT; *instance = Analog_Input_Index_To_Instance(object_index); status = true; } } /* binary input objects */ if (!status) { /* normalize the index since we know it is not the previous objects */ object_index -= object_count; object_count = Binary_Input_Count(); /* is it a valid index for this object? */ if (object_index < object_count) { *object_type = OBJECT_BINARY_INPUT; *instance = Binary_Input_Index_To_Instance(object_index); status = true; } } return status; }