static void Init_Service_Handlers( void) { Device_Init(NULL); /* we need to handle who-is * to support dynamic device binding to us */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* handle i-am to support binding to other devices */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement * It is required to send the proper reject message... */ apdu_set_unrecognized_service_handler_handler (handler_unrecognized_service); /* 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_PROPERTY, handler_read_property); /* handle the data coming back from confirmed requests */ apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, My_Write_Property_Ack_Handler); apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY, My_Read_Property_Ack_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); apdu_set_error_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); }
static void Init_Service_Handlers( void) { Device_Init(NULL); /* we need to handle who-is to support dynamic device binding to us */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* handle i-am to support binding to other devices */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ apdu_set_unrecognized_service_handler_handler (handler_unrecognized_service); /* we must implement read property - it's required! */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, handler_device_communication_control); /* handle the ack coming back */ apdu_set_confirmed_simple_ack_handler (SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, MyDeviceCommunicationControlSimpleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); }
int BacnetWriteProperty( int deviceInstanceNumber, int objectType, int objectInstanceNumber, int objectProperty, int objectPriority, int objectIndex, const char *tag, const char *value) { char msg[MAX_ERROR_STRING]; int isFailure = 1; if (!isWritePropertyHandlerRegistered) { /* handle the ack coming back */ apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, My_Write_Property_SimpleAck_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, My_Error_Handler); /* indicate that handlers are now registered */ isWritePropertyHandlerRegistered = true; } if (objectIndex == -1) { objectIndex = BACNET_ARRAY_ALL; } /* Loop for eary exit; */ do { /* Handle the tag/value pair */ uint8_t context_tag = 0; BACNET_APPLICATION_TAG property_tag; BACNET_APPLICATION_DATA_VALUE propertyValue; if (toupper(tag[0]) == 'C') { context_tag = strtol(&tag[1], NULL, 0); propertyValue.context_tag = context_tag; propertyValue.context_specific = true; } else { propertyValue.context_specific = false; } property_tag = strtol(tag, NULL, 0); if (property_tag >= MAX_BACNET_APPLICATION_TAG) { sprintf(msg, "Error: tag=%u - it must be less than %u", property_tag, MAX_BACNET_APPLICATION_TAG); LogError(msg); break; } if (!bacapp_parse_application_data(property_tag, value, &propertyValue)) { sprintf(msg, "Error: unable to parse the tag value"); LogError(msg); break; } propertyValue.next = NULL; /* Send out the message */ Request_Invoke_ID = Send_Write_Property_Request(deviceInstanceNumber, objectType, objectInstanceNumber, objectProperty, &propertyValue, objectPriority, objectIndex); Wait_For_Answer_Or_Timeout(100, waitAnswer); /* If we get here, then there were no explicit failures. However, there */ /* could have been implicit failures. Let's look at those also. */ isFailure = Error_Detected; } while (false); /* Clean up after ourselves. */ Error_Detected = false; return isFailure; }